Problem 277
Smallest a1 > 10^15 beginning with given modified-Collatz prefix.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n^2) | O(n) |
| Space complexity | O(n) | O(n) |
| Approach | Flow solution | Memoised Collatz iteration |
| Verdict | Suboptimal |
Flow source
# Project Euler 277
# Smallest a1 > 10^15 beginning with given modified-Collatz prefix.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
function is_good(x0: i64, seq: ptr<i8>, length: i64) -> bool {
let mut x: i64 = x0
let mut i: i64 = 0
while i < length {
let s: i32 = seq[i] as i32
let mod: i64 = x % 3
match mod {
0 => {
if s != 68 { return false }
x = x / 3
}
1 => {
if s != 85 { return false }
x = (4 * x + 2) / 3
}
_ => {
if s != 100 { return false }
x = (2 * x - 1) / 3
}
}
i = i + 1
}
return true
}
function main() -> i32 {
# UDDDUdddDDUDDddDdDddDDUDDdUUDd
let n: i64 = 30
let seq: ptr<i8> = calloc(n, 1)
if seq == null { return 1 }
let codes: ptr<i8> = calloc(n, 1)
# fill via integer ASCII
let src: ptr<i32> = calloc(n, 4)
src[0]=85; src[1]=68; src[2]=68; src[3]=68; src[4]=85
src[5]=100; src[6]=100; src[7]=100; src[8]=68; src[9]=68
src[10]=85; src[11]=68; src[12]=68; src[13]=100; src[14]=100
src[15]=68; src[16]=100; src[17]=68; src[18]=100; src[19]=100
src[20]=68; src[21]=68; src[22]=85; src[23]=68; src[24]=68
src[25]=100; src[26]=85; src[27]=85; src[28]=68; src[29]=100
let mut i: i64 = 0
while i < n {
seq[i] = src[i] as i8
i = i + 1
}
let mut current: i64 = 1000000000000000
let mut step: i64 = 1
let mut length: i64 = 1
while length <= n {
let mut iterations: i64 = 0
while !is_good(current, seq, length) {
current = current + step
iterations = iterations + 1
if iterations > 100 {
free(seq); free(src); free(codes)
return 1
}
}
step = step * 3
length = length + 1
}
printf("%lld\n", current)
free(seq); free(src); free(codes)
return 0
}
Generated C
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
while (flow_temp_head) {
flow_temp_node* n = flow_temp_head;
flow_temp_head = n->next;
free(n);
}
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
if (!node) return NULL;
node->next = flow_temp_head;
flow_temp_head = node;
if (!flow_temp_atexit_set) {
flow_temp_atexit_set = 1;
atexit(flow_temp_free_all);
}
return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
char* r = (char*)flow_temp_alloc(la + lb + 1);
if (!r) return NULL;
if (la) memcpy(r, a, la);
if (lb) memcpy(r + la, b, lb);
r[la + lb] = '\0';
return r;
}
#define __flow_in_arr(arr, val) __extension__ ({ \
int _found = 0; \
size_t _n = sizeof(arr)/sizeof((arr)[0]); \
for (size_t _i = 0; _i < _n; _i++) { \
if ((arr)[_i] == (val)) { _found = 1; break; } \
} _found; })
/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
abort();
#if defined(__GNUC__) || defined(__clang__)
__builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")
#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#include <math.h>
void* _ui_state = NULL;
static inline float i32_to_f32(int32_t v) { return (float)v; }
/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }
bool is_good_i64_ptr_i8_i64(int64_t x0, int8_t* seq, int64_t length);
int32_t main(void);
bool is_good_i64_ptr_i8_i64(int64_t x0, int8_t* seq, int64_t length) {
int64_t x = x0;
int64_t i = 0;
while (i < length) {
int32_t s = ((int32_t)(seq[i]));
int64_t mod = FLOW_CHECKED_MOD((x), (3));
{ // match block
if ((mod) == 0) {
if (s != 68) {
return 0;
}
x = FLOW_CHECKED_DIV((x), (3));
} else if ((mod) == 1) {
if (s != 85) {
return 0;
}
x = FLOW_CHECKED_DIV((((4 * x) + 2)), (3));
} else { // exhaustive
if (s != 100) {
return 0;
}
x = FLOW_CHECKED_DIV((((2 * x) - 1)), (3));
}
} // end match
i = (i + 1);
}
return 1;
}
int32_t main(void) {
int64_t n = 30;
int8_t* seq = (int8_t*)(calloc(n, 1));
if (seq == NULL) {
return 1;
}
int8_t* codes = (int8_t*)(calloc(n, 1));
int32_t* src = (int32_t*)(calloc(n, 4));
src[0] = 85;
src[1] = 68;
src[2] = 68;
src[3] = 68;
src[4] = 85;
src[5] = 100;
src[6] = 100;
src[7] = 100;
src[8] = 68;
src[9] = 68;
src[10] = 85;
src[11] = 68;
src[12] = 68;
src[13] = 100;
src[14] = 100;
src[15] = 68;
src[16] = 100;
src[17] = 68;
src[18] = 100;
src[19] = 100;
src[20] = 68;
src[21] = 68;
src[22] = 85;
src[23] = 68;
src[24] = 68;
src[25] = 100;
src[26] = 85;
src[27] = 85;
src[28] = 68;
src[29] = 100;
int64_t i = 0;
while (i < n) {
seq[i] = ((int8_t)(src[i]));
i = (i + 1);
}
int64_t current = 1000000000000000;
int64_t step = 1;
int64_t length = 1;
while (length <= n) {
int64_t iterations = 0;
while ((!(is_good_i64_ptr_i8_i64(current, seq, length)))) {
current = (current + step);
iterations = (iterations + 1);
if (iterations > 100) {
free(seq);
free(src);
free(codes);
return 1;
}
}
step = (step * 3);
length = (length + 1);
}
printf("%lld\n", current);
free(seq);
free(src);
free(codes);
return 0;
}
Generated MLIR
module {
llvm.func @printf(!llvm.ptr, ...) -> i32
llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
func.func @is_good(%arg0: i64, %arg1: !llvm.ptr, %arg2: i64) -> i1 {
%0 = llvm.mlir.constant(1 : i64) : i64
%1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %1 : i64, !llvm.ptr
%2 = arith.constant 0 : i32
%3 = arith.extsi %2 : i32 to i64
%4 = llvm.mlir.constant(1 : i64) : i64
%5 = llvm.alloca %4 x i64 : (i64) -> !llvm.ptr
llvm.store %3, %5 : i64, !llvm.ptr
cf.br ^bb0
^bb0:
%6 = llvm.load %5 : !llvm.ptr -> i64
%7 = arith.cmpi slt, %6, %arg2 : i64
cf.cond_br %7, ^bb1, ^bb2
^bb1:
%9 = llvm.load %5 : !llvm.ptr -> i64
%10 = llvm.getelementptr %arg1[%9] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%8 = llvm.load %10 : !llvm.ptr -> i8
%11 = arith.extsi %8 : i8 to i32
%12 = llvm.load %1 : !llvm.ptr -> i64
%13 = arith.constant 3 : i32
%15 = arith.extsi %13 : i32 to i64
%14 = arith.remsi %12, %15 : i64
%16 = arith.constant 0 : i32
%17 = arith.cmpi eq, %14, %16 : i64
cf.cond_br %17, ^bb3, ^bb4
^bb3:
%18 = arith.constant 68 : i32
%19 = arith.cmpi ne, %11, %18 : i32
cf.cond_br %19, ^bb10, ^bb11
^bb10:
%20 = arith.constant 0 : i1
func.return %20 : i1
^bb11:
cf.br ^bb12
^bb12:
%21 = llvm.load %1 : !llvm.ptr -> i64
%22 = arith.constant 3 : i32
%24 = arith.extsi %22 : i32 to i64
%23 = arith.divsi %21, %24 : i64
llvm.store %23, %1 : i64, !llvm.ptr
cf.br ^bb9
^bb4:
%25 = arith.constant 1 : i32
%26 = arith.cmpi eq, %14, %25 : i64
cf.cond_br %26, ^bb5, ^bb6
^bb5:
%27 = arith.constant 85 : i32
%28 = arith.cmpi ne, %11, %27 : i32
cf.cond_br %28, ^bb13, ^bb14
^bb13:
%29 = arith.constant 0 : i1
func.return %29 : i1
^bb14:
cf.br ^bb15
^bb15:
%30 = arith.constant 4 : i32
%31 = llvm.load %1 : !llvm.ptr -> i64
%33 = arith.extsi %30 : i32 to i64
%32 = arith.muli %33, %31 : i64
%34 = arith.constant 2 : i32
%36 = arith.extsi %34 : i32 to i64
%35 = arith.addi %32, %36 : i64
%37 = arith.constant 3 : i32
%39 = arith.extsi %37 : i32 to i64
%38 = arith.divsi %35, %39 : i64
llvm.store %38, %1 : i64, !llvm.ptr
cf.br ^bb9
^bb6:
%40 = arith.constant 1 : i1
cf.cond_br %40, ^bb7, ^bb8
^bb7:
%41 = arith.constant 100 : i32
%42 = arith.cmpi ne, %11, %41 : i32
cf.cond_br %42, ^bb16, ^bb17
^bb16:
%43 = arith.constant 0 : i1
func.return %43 : i1
^bb17:
cf.br ^bb18
^bb18:
%44 = arith.constant 2 : i32
%45 = llvm.load %1 : !llvm.ptr -> i64
%47 = arith.extsi %44 : i32 to i64
%46 = arith.muli %47, %45 : i64
%48 = arith.constant 1 : i32
%50 = arith.extsi %48 : i32 to i64
%49 = arith.subi %46, %50 : i64
%51 = arith.constant 3 : i32
%53 = arith.extsi %51 : i32 to i64
%52 = arith.divsi %49, %53 : i64
llvm.store %52, %1 : i64, !llvm.ptr
cf.br ^bb9
^bb8:
cf.br ^bb9
^bb9:
%54 = llvm.load %5 : !llvm.ptr -> i64
%55 = arith.constant 1 : i32
%57 = arith.extsi %55 : i32 to i64
%56 = arith.addi %54, %57 : i64
llvm.store %56, %5 : i64, !llvm.ptr
cf.br ^bb0
^bb2:
%58 = arith.constant 1 : i1
func.return %58 : i1
}
func.func @main() -> i32 {
%59 = arith.constant 30 : i32
%60 = arith.extsi %59 : i32 to i64
%62 = arith.constant 1 : i32
%63 = arith.extsi %62 : i32 to i64
%61 = func.call @calloc(%60, %63) : (i64, i64) -> !llvm.ptr
%64 = llvm.mlir.zero : !llvm.ptr
%65 = llvm.icmp "eq" %61, %64 : !llvm.ptr
cf.cond_br %65, ^bb19, ^bb20
^bb19:
%66 = arith.constant 1 : i32
func.return %66 : i32
^bb20:
cf.br ^bb21
^bb21:
%68 = arith.constant 1 : i32
%69 = arith.extsi %68 : i32 to i64
%67 = func.call @calloc(%60, %69) : (i64, i64) -> !llvm.ptr
%71 = arith.constant 4 : i32
%72 = arith.extsi %71 : i32 to i64
%70 = func.call @calloc(%60, %72) : (i64, i64) -> !llvm.ptr
%73 = arith.constant 85 : i32
%74 = arith.constant 0 : i32
%75 = arith.extsi %74 : i32 to i64
%76 = llvm.getelementptr %70[%75] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %73, %76 : i32, !llvm.ptr
%77 = arith.constant 68 : i32
%78 = arith.constant 1 : i32
%79 = arith.extsi %78 : i32 to i64
%80 = llvm.getelementptr %70[%79] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %77, %80 : i32, !llvm.ptr
%81 = arith.constant 68 : i32
%82 = arith.constant 2 : i32
%83 = arith.extsi %82 : i32 to i64
%84 = llvm.getelementptr %70[%83] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %81, %84 : i32, !llvm.ptr
%85 = arith.constant 68 : i32
%86 = arith.constant 3 : i32
%87 = arith.extsi %86 : i32 to i64
%88 = llvm.getelementptr %70[%87] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %85, %88 : i32, !llvm.ptr
%89 = arith.constant 85 : i32
%90 = arith.constant 4 : i32
%91 = arith.extsi %90 : i32 to i64
%92 = llvm.getelementptr %70[%91] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %89, %92 : i32, !llvm.ptr
%93 = arith.constant 100 : i32
%94 = arith.constant 5 : i32
%95 = arith.extsi %94 : i32 to i64
%96 = llvm.getelementptr %70[%95] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %93, %96 : i32, !llvm.ptr
%97 = arith.constant 100 : i32
%98 = arith.constant 6 : i32
%99 = arith.extsi %98 : i32 to i64
%100 = llvm.getelementptr %70[%99] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %97, %100 : i32, !llvm.ptr
%101 = arith.constant 100 : i32
%102 = arith.constant 7 : i32
%103 = arith.extsi %102 : i32 to i64
%104 = llvm.getelementptr %70[%103] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %101, %104 : i32, !llvm.ptr
%105 = arith.constant 68 : i32
%106 = arith.constant 8 : i32
%107 = arith.extsi %106 : i32 to i64
%108 = llvm.getelementptr %70[%107] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %105, %108 : i32, !llvm.ptr
%109 = arith.constant 68 : i32
%110 = arith.constant 9 : i32
%111 = arith.extsi %110 : i32 to i64
%112 = llvm.getelementptr %70[%111] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %109, %112 : i32, !llvm.ptr
%113 = arith.constant 85 : i32
%114 = arith.constant 10 : i32
%115 = arith.extsi %114 : i32 to i64
%116 = llvm.getelementptr %70[%115] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %113, %116 : i32, !llvm.ptr
%117 = arith.constant 68 : i32
%118 = arith.constant 11 : i32
%119 = arith.extsi %118 : i32 to i64
%120 = llvm.getelementptr %70[%119] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %117, %120 : i32, !llvm.ptr
%121 = arith.constant 68 : i32
%122 = arith.constant 12 : i32
%123 = arith.extsi %122 : i32 to i64
%124 = llvm.getelementptr %70[%123] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %121, %124 : i32, !llvm.ptr
%125 = arith.constant 100 : i32
%126 = arith.constant 13 : i32
%127 = arith.extsi %126 : i32 to i64
%128 = llvm.getelementptr %70[%127] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %125, %128 : i32, !llvm.ptr
%129 = arith.constant 100 : i32
%130 = arith.constant 14 : i32
%131 = arith.extsi %130 : i32 to i64
%132 = llvm.getelementptr %70[%131] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %129, %132 : i32, !llvm.ptr
%133 = arith.constant 68 : i32
%134 = arith.constant 15 : i32
%135 = arith.extsi %134 : i32 to i64
%136 = llvm.getelementptr %70[%135] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %133, %136 : i32, !llvm.ptr
%137 = arith.constant 100 : i32
%138 = arith.constant 16 : i32
%139 = arith.extsi %138 : i32 to i64
%140 = llvm.getelementptr %70[%139] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %137, %140 : i32, !llvm.ptr
%141 = arith.constant 68 : i32
%142 = arith.constant 17 : i32
%143 = arith.extsi %142 : i32 to i64
%144 = llvm.getelementptr %70[%143] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %141, %144 : i32, !llvm.ptr
%145 = arith.constant 100 : i32
%146 = arith.constant 18 : i32
%147 = arith.extsi %146 : i32 to i64
%148 = llvm.getelementptr %70[%147] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %145, %148 : i32, !llvm.ptr
%149 = arith.constant 100 : i32
%150 = arith.constant 19 : i32
%151 = arith.extsi %150 : i32 to i64
%152 = llvm.getelementptr %70[%151] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %149, %152 : i32, !llvm.ptr
%153 = arith.constant 68 : i32
%154 = arith.constant 20 : i32
%155 = arith.extsi %154 : i32 to i64
%156 = llvm.getelementptr %70[%155] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %153, %156 : i32, !llvm.ptr
%157 = arith.constant 68 : i32
%158 = arith.constant 21 : i32
%159 = arith.extsi %158 : i32 to i64
%160 = llvm.getelementptr %70[%159] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %157, %160 : i32, !llvm.ptr
%161 = arith.constant 85 : i32
%162 = arith.constant 22 : i32
%163 = arith.extsi %162 : i32 to i64
%164 = llvm.getelementptr %70[%163] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %161, %164 : i32, !llvm.ptr
%165 = arith.constant 68 : i32
%166 = arith.constant 23 : i32
%167 = arith.extsi %166 : i32 to i64
%168 = llvm.getelementptr %70[%167] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %165, %168 : i32, !llvm.ptr
%169 = arith.constant 68 : i32
%170 = arith.constant 24 : i32
%171 = arith.extsi %170 : i32 to i64
%172 = llvm.getelementptr %70[%171] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %169, %172 : i32, !llvm.ptr
%173 = arith.constant 100 : i32
%174 = arith.constant 25 : i32
%175 = arith.extsi %174 : i32 to i64
%176 = llvm.getelementptr %70[%175] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %173, %176 : i32, !llvm.ptr
%177 = arith.constant 85 : i32
%178 = arith.constant 26 : i32
%179 = arith.extsi %178 : i32 to i64
%180 = llvm.getelementptr %70[%179] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %177, %180 : i32, !llvm.ptr
%181 = arith.constant 85 : i32
%182 = arith.constant 27 : i32
%183 = arith.extsi %182 : i32 to i64
%184 = llvm.getelementptr %70[%183] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %181, %184 : i32, !llvm.ptr
%185 = arith.constant 68 : i32
%186 = arith.constant 28 : i32
%187 = arith.extsi %186 : i32 to i64
%188 = llvm.getelementptr %70[%187] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %185, %188 : i32, !llvm.ptr
%189 = arith.constant 100 : i32
%190 = arith.constant 29 : i32
%191 = arith.extsi %190 : i32 to i64
%192 = llvm.getelementptr %70[%191] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %189, %192 : i32, !llvm.ptr
%193 = arith.constant 0 : i32
%194 = arith.extsi %193 : i32 to i64
%195 = llvm.mlir.constant(1 : i64) : i64
%196 = llvm.alloca %195 x i64 : (i64) -> !llvm.ptr
llvm.store %194, %196 : i64, !llvm.ptr
cf.br ^bb22
^bb22:
%197 = llvm.load %196 : !llvm.ptr -> i64
%198 = arith.cmpi slt, %197, %60 : i64
cf.cond_br %198, ^bb23, ^bb24
^bb23:
%200 = llvm.load %196 : !llvm.ptr -> i64
%201 = llvm.getelementptr %70[%200] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%199 = llvm.load %201 : !llvm.ptr -> i32
%202 = arith.trunci %199 : i32 to i8
%203 = llvm.load %196 : !llvm.ptr -> i64
%204 = llvm.getelementptr %61[%203] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %202, %204 : i8, !llvm.ptr
%205 = llvm.load %196 : !llvm.ptr -> i64
%206 = arith.constant 1 : i32
%208 = arith.extsi %206 : i32 to i64
%207 = arith.addi %205, %208 : i64
llvm.store %207, %196 : i64, !llvm.ptr
cf.br ^bb22
^bb24:
%209 = arith.constant 999995705032704 : i32
%210 = arith.extsi %209 : i32 to i64
%211 = llvm.mlir.constant(1 : i64) : i64
%212 = llvm.alloca %211 x i64 : (i64) -> !llvm.ptr
llvm.store %210, %212 : i64, !llvm.ptr
%213 = arith.constant 1 : i32
%214 = arith.extsi %213 : i32 to i64
%215 = llvm.mlir.constant(1 : i64) : i64
%216 = llvm.alloca %215 x i64 : (i64) -> !llvm.ptr
llvm.store %214, %216 : i64, !llvm.ptr
%217 = arith.constant 1 : i32
%218 = arith.extsi %217 : i32 to i64
%219 = llvm.mlir.constant(1 : i64) : i64
%220 = llvm.alloca %219 x i64 : (i64) -> !llvm.ptr
llvm.store %218, %220 : i64, !llvm.ptr
cf.br ^bb25
^bb25:
%221 = llvm.load %220 : !llvm.ptr -> i64
%222 = arith.cmpi sle, %221, %60 : i64
cf.cond_br %222, ^bb26, ^bb27
^bb26:
%223 = arith.constant 0 : i32
%224 = arith.extsi %223 : i32 to i64
%225 = llvm.mlir.constant(1 : i64) : i64
%226 = llvm.alloca %225 x i64 : (i64) -> !llvm.ptr
llvm.store %224, %226 : i64, !llvm.ptr
cf.br ^bb28
^bb28:
%228 = llvm.load %212 : !llvm.ptr -> i64
%229 = llvm.load %220 : !llvm.ptr -> i64
%227 = func.call @is_good(%228, %61, %229) : (i64, !llvm.ptr, i64) -> i1
%231 = arith.constant 1 : i1
%230 = arith.xori %227, %231 : i1
cf.cond_br %230, ^bb29, ^bb30
^bb29:
%233 = llvm.load %212 : !llvm.ptr -> i64
%234 = llvm.load %216 : !llvm.ptr -> i64
%235 = arith.addi %233, %234 : i64
llvm.store %235, %212 : i64, !llvm.ptr
%236 = llvm.load %226 : !llvm.ptr -> i64
%237 = arith.constant 1 : i32
%239 = arith.extsi %237 : i32 to i64
%238 = arith.addi %236, %239 : i64
llvm.store %238, %226 : i64, !llvm.ptr
%240 = llvm.load %226 : !llvm.ptr -> i64
%241 = arith.constant 100 : i32
%243 = arith.extsi %241 : i32 to i64
%242 = arith.cmpi sgt, %240, %243 : i64
cf.cond_br %242, ^bb31, ^bb32
^bb31:
func.call @free(%61) : (!llvm.ptr) -> ()
func.call @free(%70) : (!llvm.ptr) -> ()
func.call @free(%67) : (!llvm.ptr) -> ()
%247 = arith.constant 1 : i32
func.return %247 : i32
^bb32:
cf.br ^bb33
^bb33:
cf.br ^bb28
^bb30:
%248 = llvm.load %216 : !llvm.ptr -> i64
%249 = arith.constant 3 : i32
%251 = arith.extsi %249 : i32 to i64
%250 = arith.muli %248, %251 : i64
llvm.store %250, %216 : i64, !llvm.ptr
%252 = llvm.load %220 : !llvm.ptr -> i64
%253 = arith.constant 1 : i32
%255 = arith.extsi %253 : i32 to i64
%254 = arith.addi %252, %255 : i64
llvm.store %254, %220 : i64, !llvm.ptr
cf.br ^bb25
^bb27:
%256 = llvm.mlir.addressof @str_0 : !llvm.ptr
%257 = llvm.load %212 : !llvm.ptr -> i64
%258 = llvm.call @printf(%256, %257) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%61) : (!llvm.ptr) -> ()
func.call @free(%70) : (!llvm.ptr) -> ()
func.call @free(%67) : (!llvm.ptr) -> ()
%262 = arith.constant 0 : i32
func.return %262 : i32
}
}