; ModuleID = 'BoolBasicTest' source_filename = "bool_basic" @heap_address = internal global i64 -4294967353 declare void @builtin_assert(i64) declare void @builtin_range_check(i64) declare i64 @prophet_u32_sqrt(i64) declare i64 @prophet_u32_div(i64, i64) declare i64 @prophet_u32_mod(i64, i64) declare ptr @prophet_u32_array_sort(ptr, i64) declare i64 @vector_new(i64) declare void @get_context_data(i64, i64) declare void @get_tape_data(i64, i64) declare void @set_tape_data(i64, i64) declare void @get_storage(ptr, ptr) declare void @set_storage(ptr, ptr) declare void @poseidon_hash(ptr, ptr, i64) declare void @contract_call(ptr, i64) declare void @prophet_printf(i64, i64) define void @memcpy(ptr %0, ptr %1, i64 %2) { entry: %index_alloca = alloca i64, align 8 %len_alloca = alloca i64, align 8 %dest_ptr_alloca = alloca ptr, align 8 %src_ptr_alloca = alloca ptr, align 8 store ptr %0, ptr %src_ptr_alloca, align 8 %src_ptr = load ptr, ptr %src_ptr_alloca, align 8 store ptr %1, ptr %dest_ptr_alloca, align 8 %dest_ptr = load ptr, ptr %dest_ptr_alloca, align 8 store i64 %2, ptr %len_alloca, align 4 %len = load i64, ptr %len_alloca, align 4 store i64 0, ptr %index_alloca, align 4 br label %cond cond: ; preds = %body, %entry %index_value = load i64, ptr %index_alloca, align 4 %loop_cond = icmp ult i64 %index_value, %len br i1 %loop_cond, label %body, label %done body: ; preds = %cond %src_index_access = getelementptr i64, ptr %src_ptr, i64 %index_value %3 = load i64, ptr %src_index_access, align 4 %dest_index_access = getelementptr i64, ptr %dest_ptr, i64 %index_value store i64 %3, ptr %dest_index_access, align 4 %next_index = add i64 %index_value, 1 store i64 %next_index, ptr %index_alloca, align 4 br label %cond done: ; preds = %cond ret void } define i64 @memcmp_eq(ptr %0, ptr %1, i64 %2) { entry: %index_alloca = alloca i64, align 8 %len_alloca = alloca i64, align 8 %right_ptr_alloca = alloca ptr, align 8 %left_ptr_alloca = alloca ptr, align 8 store ptr %0, ptr %left_ptr_alloca, align 8 %left_ptr = load ptr, ptr %left_ptr_alloca, align 8 store ptr %1, ptr %right_ptr_alloca, align 8 %right_ptr = load ptr, ptr %right_ptr_alloca, align 8 store i64 %2, ptr %len_alloca, align 4 %len = load i64, ptr %len_alloca, align 4 store i64 0, ptr %index_alloca, align 4 br label %cond cond: ; preds = %body, %entry %index_value = load i64, ptr %index_alloca, align 4 %loop_check = icmp ult i64 %index_value, %len br i1 %loop_check, label %body, label %done body: ; preds = %cond %left_elem_ptr = getelementptr i64, ptr %left_ptr, i64 %index_value %left_elem = load i64, ptr %left_elem_ptr, align 4 %right_elem_ptr = getelementptr i64, ptr %right_ptr, i64 %index_value %right_elem = load i64, ptr %right_elem_ptr, align 4 %compare = icmp eq i64 %left_elem, %right_elem %next_index = add i64 %index_value, 1 store i64 %next_index, ptr %index_alloca, align 4 br i1 %compare, label %cond, label %done done: ; preds = %body, %cond %result_phi = phi i64 [ 1, %cond ], [ 0, %body ] ret i64 %result_phi } define i64 @memcmp_ugt(ptr %0, ptr %1, i64 %2) { entry: %index_alloca = alloca i64, align 8 %len_alloca = alloca i64, align 8 %right_ptr_alloca = alloca ptr, align 8 %left_ptr_alloca = alloca ptr, align 8 store ptr %0, ptr %left_ptr_alloca, align 8 %left_ptr = load ptr, ptr %left_ptr_alloca, align 8 store ptr %1, ptr %right_ptr_alloca, align 8 %right_ptr = load ptr, ptr %right_ptr_alloca, align 8 store i64 %2, ptr %len_alloca, align 4 %len = load i64, ptr %len_alloca, align 4 store i64 0, ptr %index_alloca, align 4 br label %cond cond: ; preds = %body, %entry %index_value = load i64, ptr %index_alloca, align 4 %loop_check = icmp ult i64 %index_value, %len br i1 %loop_check, label %body, label %done body: ; preds = %cond %left_elem_ptr = getelementptr i64, ptr %left_ptr, i64 %index_value %left_elem = load i64, ptr %left_elem_ptr, align 4 %right_elem_ptr = getelementptr i64, ptr %right_ptr, i64 %index_value %right_elem = load i64, ptr %right_elem_ptr, align 4 %compare = icmp ugt i64 %left_elem, %right_elem %next_index = add i64 %index_value, 1 store i64 %next_index, ptr %index_alloca, align 4 br i1 %compare, label %cond, label %done done: ; preds = %body, %cond %result_phi = phi i64 [ 1, %cond ], [ 0, %body ] ret i64 %result_phi } define i64 @memcmp_uge(ptr %0, ptr %1, i64 %2) { entry: %index_alloca = alloca i64, align 8 %len_alloca = alloca i64, align 8 %right_ptr_alloca = alloca ptr, align 8 %left_ptr_alloca = alloca ptr, align 8 store ptr %0, ptr %left_ptr_alloca, align 8 %left_ptr = load ptr, ptr %left_ptr_alloca, align 8 store ptr %1, ptr %right_ptr_alloca, align 8 %right_ptr = load ptr, ptr %right_ptr_alloca, align 8 store i64 %2, ptr %len_alloca, align 4 %len = load i64, ptr %len_alloca, align 4 store i64 0, ptr %index_alloca, align 4 br label %cond cond: ; preds = %body, %entry %index_value = load i64, ptr %index_alloca, align 4 %loop_check = icmp ult i64 %index_value, %len br i1 %loop_check, label %body, label %done body: ; preds = %cond %left_elem_ptr = getelementptr i64, ptr %left_ptr, i64 %index_value %left_elem = load i64, ptr %left_elem_ptr, align 4 %right_elem_ptr = getelementptr i64, ptr %right_ptr, i64 %index_value %right_elem = load i64, ptr %right_elem_ptr, align 4 %compare = icmp uge i64 %left_elem, %right_elem %next_index = add i64 %index_value, 1 store i64 %next_index, ptr %index_alloca, align 4 br i1 %compare, label %cond, label %done done: ; preds = %body, %cond %result_phi = phi i64 [ 1, %cond ], [ 0, %body ] ret i64 %result_phi } define void @u32_div_mod(i64 %0, i64 %1, ptr %2, ptr %3) { entry: %remainder_alloca = alloca ptr, align 8 %quotient_alloca = alloca ptr, align 8 %divisor_alloca = alloca i64, align 8 %dividend_alloca = alloca i64, align 8 store i64 %0, ptr %dividend_alloca, align 4 %dividend = load i64, ptr %dividend_alloca, align 4 store i64 %1, ptr %divisor_alloca, align 4 %divisor = load i64, ptr %divisor_alloca, align 4 store ptr %2, ptr %quotient_alloca, align 8 %quotient = load ptr, ptr %quotient_alloca, align 8 store ptr %3, ptr %remainder_alloca, align 8 %remainder = load ptr, ptr %remainder_alloca, align 8 %4 = call i64 @prophet_u32_mod(i64 %dividend, i64 %divisor) call void @builtin_range_check(i64 %4) %5 = add i64 %4, 1 %6 = sub i64 %divisor, %5 call void @builtin_range_check(i64 %6) %7 = call i64 @prophet_u32_div(i64 %dividend, i64 %divisor) call void @builtin_range_check(ptr %quotient) %8 = mul i64 %7, %divisor %9 = add i64 %8, %4 %10 = icmp eq i64 %9, %dividend %11 = zext i1 %10 to i64 call void @builtin_assert(i64 %11) store i64 %7, ptr %quotient, align 4 store i64 %4, ptr %remainder, align 4 ret void } define i64 @u32_power(i64 %0, i64 %1) { entry: %exponent_alloca = alloca i64, align 8 %base_alloca = alloca i64, align 8 store i64 %0, ptr %base_alloca, align 4 %base = load i64, ptr %base_alloca, align 4 store i64 %1, ptr %exponent_alloca, align 4 %exponent = load i64, ptr %exponent_alloca, align 4 br label %loop loop: ; preds = %loop, %entry %2 = phi i64 [ 0, %entry ], [ %inc, %loop ] %3 = phi i64 [ 1, %entry ], [ %multmp, %loop ] %inc = add i64 %2, 1 %multmp = mul i64 %3, %base %loopcond = icmp ule i64 %inc, %exponent br i1 %loopcond, label %loop, label %exit exit: ; preds = %loop call void @builtin_range_check(i64 %3) ret i64 %3 } define void @testBoolDeclareUninitialized() { entry: %a = alloca i64, align 8 store i64 0, ptr %a, align 4 %0 = load i64, ptr %a, align 4 call void @prophet_printf(i64 %0, i64 3) ret void } define void @testBoolDeclareInitialized() { entry: %a = alloca i64, align 8 store i64 1, ptr %a, align 4 %0 = load i64, ptr %a, align 4 call void @prophet_printf(i64 %0, i64 3) ret void } define void @testBoolDeclareThenInitialized() { entry: %a = alloca i64, align 8 store i64 0, ptr %a, align 4 store i64 1, ptr %a, align 4 %0 = load i64, ptr %a, align 4 call void @prophet_printf(i64 %0, i64 3) ret void } define void @testBoolInitializedByOther() { entry: %b = alloca i64, align 8 %a = alloca i64, align 8 store i64 1, ptr %a, align 4 %0 = load i64, ptr %a, align 4 store i64 %0, ptr %b, align 4 %1 = load i64, ptr %b, align 4 call void @prophet_printf(i64 %1, i64 3) ret void } define void @testBoolAsParameter(i64 %0) { entry: %x = alloca i64, align 8 store i64 %0, ptr %x, align 4 %1 = load i64, ptr %x, align 4 call void @prophet_printf(i64 %1, i64 3) ret void } define i64 @testBoolAsReturnValue() { entry: %a = alloca i64, align 8 store i64 1, ptr %a, align 4 %0 = load i64, ptr %a, align 4 ret i64 %0 } define i64 @testBoolAsReturnConstValue() { entry: ret i64 1 } define void @testBoolAndOperation() { entry: %c = alloca i64, align 8 %b = alloca i64, align 8 %a = alloca i64, align 8 store i64 1, ptr %a, align 4 store i64 0, ptr %b, align 4 %0 = load i64, ptr %a, align 4 %1 = load i64, ptr %b, align 4 %2 = and i64 %0, %1 store i64 %2, ptr %c, align 4 %3 = load i64, ptr %c, align 4 call void @prophet_printf(i64 %3, i64 3) ret void } define void @testBoolOrOperation() { entry: %c = alloca i64, align 8 %b = alloca i64, align 8 %a = alloca i64, align 8 store i64 1, ptr %a, align 4 store i64 0, ptr %b, align 4 %0 = load i64, ptr %a, align 4 %1 = load i64, ptr %b, align 4 %2 = or i64 %0, %1 store i64 %2, ptr %c, align 4 %3 = load i64, ptr %c, align 4 call void @prophet_printf(i64 %3, i64 3) ret void } define void @testBoolEqualOperation() { entry: %c = alloca i64, align 8 %b = alloca i64, align 8 %a = alloca i64, align 8 store i64 1, ptr %a, align 4 store i64 0, ptr %b, align 4 %0 = load i64, ptr %a, align 4 %1 = load i64, ptr %b, align 4 %2 = icmp eq i64 %0, %1 store i1 %2, ptr %c, align 1 %3 = load i64, ptr %c, align 4 call void @prophet_printf(i64 %3, i64 3) ret void } define void @testBoolNotEqualOperation() { entry: %c = alloca i64, align 8 %b = alloca i64, align 8 %a = alloca i64, align 8 store i64 1, ptr %a, align 4 store i64 0, ptr %b, align 4 %0 = load i64, ptr %a, align 4 %1 = load i64, ptr %b, align 4 %2 = icmp ne i64 %0, %1 store i1 %2, ptr %c, align 1 %3 = load i64, ptr %c, align 4 call void @prophet_printf(i64 %3, i64 3) ret void } define void @testBoolStateChange() { entry: %a = alloca i64, align 8 store i64 0, ptr %a, align 4 %0 = load i64, ptr %a, align 4 %1 = icmp eq i64 %0, 0 store i1 %1, ptr %a, align 1 %2 = load i64, ptr %a, align 4 call void @prophet_printf(i64 %2, i64 3) ret void } define void @testBoolIfStatement() { entry: %a = alloca i64, align 8 store i64 1, ptr %a, align 4 %0 = load i64, ptr %a, align 4 %1 = trunc i64 %0 to i1 br i1 %1, label %then, label %else then: ; preds = %entry call void @prophet_printf(i64 1, i64 3) br label %endif else: ; preds = %entry call void @prophet_printf(i64 0, i64 3) br label %endif endif: ; preds = %else, %then ret void } define void @testBoolComplexCondition() { entry: %b = alloca i64, align 8 %a = alloca i64, align 8 store i64 1, ptr %a, align 4 store i64 0, ptr %b, align 4 %0 = load i64, ptr %a, align 4 %1 = load i64, ptr %b, align 4 %2 = icmp eq i64 %1, 0 %3 = zext i1 %2 to i64 %4 = and i64 %0, %3 %5 = trunc i64 %4 to i1 br i1 %5, label %then, label %else then: ; preds = %entry call void @prophet_printf(i64 1, i64 3) br label %endif else: ; preds = %entry call void @prophet_printf(i64 0, i64 3) br label %endif endif: ; preds = %else, %then ret void } define void @function_dispatch(i64 %0, i64 %1, ptr %2) { entry: %input_alloca = alloca ptr, align 8 store ptr %2, ptr %input_alloca, align 8 %input = load ptr, ptr %input_alloca, align 8 switch i64 %0, label %missing_function [ i64 545713831, label %func_0_dispatch i64 221470895, label %func_1_dispatch i64 440254908, label %func_2_dispatch i64 2809465727, label %func_3_dispatch i64 427194971, label %func_4_dispatch i64 2396581718, label %func_5_dispatch i64 2005518468, label %func_6_dispatch i64 3600410652, label %func_7_dispatch i64 112580652, label %func_8_dispatch i64 2552612239, label %func_9_dispatch i64 1656297549, label %func_10_dispatch i64 3577672189, label %func_11_dispatch i64 4013971707, label %func_12_dispatch i64 2069354807, label %func_13_dispatch ] missing_function: ; preds = %entry unreachable func_0_dispatch: ; preds = %entry call void @testBoolDeclareUninitialized() call void @set_tape_data(i64 0, i64 0) ret void func_1_dispatch: ; preds = %entry call void @testBoolDeclareInitialized() call void @set_tape_data(i64 0, i64 0) ret void func_2_dispatch: ; preds = %entry call void @testBoolDeclareThenInitialized() call void @set_tape_data(i64 0, i64 0) ret void func_3_dispatch: ; preds = %entry call void @testBoolInitializedByOther() call void @set_tape_data(i64 0, i64 0) ret void func_4_dispatch: ; preds = %entry %input_start = ptrtoint ptr %input to i64 %3 = inttoptr i64 %input_start to ptr %decode_value = load i64, ptr %3, align 4 call void @testBoolAsParameter(i64 %decode_value) call void @set_tape_data(i64 0, i64 0) ret void func_5_dispatch: ; preds = %entry %4 = call i64 @testBoolAsReturnValue() %5 = call i64 @vector_new(i64 2) %heap_start = sub i64 %5, 2 %heap_to_ptr = inttoptr i64 %heap_start to ptr %encode_value_ptr = getelementptr i64, ptr %heap_to_ptr, i64 0 store i64 %4, ptr %encode_value_ptr, align 4 %encode_value_ptr1 = getelementptr i64, ptr %heap_to_ptr, i64 1 store i64 1, ptr %encode_value_ptr1, align 4 call void @set_tape_data(i64 %heap_start, i64 2) ret void func_6_dispatch: ; preds = %entry %6 = call i64 @testBoolAsReturnConstValue() %7 = call i64 @vector_new(i64 2) %heap_start2 = sub i64 %7, 2 %heap_to_ptr3 = inttoptr i64 %heap_start2 to ptr %encode_value_ptr4 = getelementptr i64, ptr %heap_to_ptr3, i64 0 store i64 %6, ptr %encode_value_ptr4, align 4 %encode_value_ptr5 = getelementptr i64, ptr %heap_to_ptr3, i64 1 store i64 1, ptr %encode_value_ptr5, align 4 call void @set_tape_data(i64 %heap_start2, i64 2) ret void func_7_dispatch: ; preds = %entry call void @testBoolAndOperation() call void @set_tape_data(i64 0, i64 0) ret void func_8_dispatch: ; preds = %entry call void @testBoolOrOperation() call void @set_tape_data(i64 0, i64 0) ret void func_9_dispatch: ; preds = %entry call void @testBoolEqualOperation() call void @set_tape_data(i64 0, i64 0) ret void func_10_dispatch: ; preds = %entry call void @testBoolNotEqualOperation() call void @set_tape_data(i64 0, i64 0) ret void func_11_dispatch: ; preds = %entry call void @testBoolStateChange() call void @set_tape_data(i64 0, i64 0) ret void func_12_dispatch: ; preds = %entry call void @testBoolIfStatement() call void @set_tape_data(i64 0, i64 0) ret void func_13_dispatch: ; preds = %entry call void @testBoolComplexCondition() call void @set_tape_data(i64 0, i64 0) ret void } define void @main() { entry: %0 = call i64 @vector_new(i64 13) %heap_start = sub i64 %0, 13 %heap_to_ptr = inttoptr i64 %heap_start to ptr call void @get_tape_data(i64 %heap_start, i64 13) %function_selector = load i64, ptr %heap_to_ptr, align 4 %1 = call i64 @vector_new(i64 14) %heap_start1 = sub i64 %1, 14 %heap_to_ptr2 = inttoptr i64 %heap_start1 to ptr call void @get_tape_data(i64 %heap_start1, i64 14) %input_length = load i64, ptr %heap_to_ptr2, align 4 %2 = add i64 %input_length, 14 %3 = call i64 @vector_new(i64 %2) %heap_start3 = sub i64 %3, %2 %heap_to_ptr4 = inttoptr i64 %heap_start3 to ptr call void @get_tape_data(i64 %heap_start3, i64 %2) call void @function_dispatch(i64 %function_selector, i64 %input_length, ptr %heap_to_ptr4) ret void }