← All problems
Problem 655
Divisible Palindromes: count palindromes < 10^32 divisible by 10000019. Uses residue-class DP building palindromes from center outward.
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n^2)O(n^2)
Space complexity O(n^2)O(1)
Approach Flow solution Brute-force or constructive search
Verdict Optimal
Flow source
# Project Euler 655
# Divisible Palindromes: count palindromes < 10^32 divisible by 10000019.
# Uses residue-class DP building palindromes from center outward.
import euler.nt { mod_pow }
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
function mod_inv(a: i64, m: i64) -> i64 {
return mod_pow(a, m - 2, m)
}
function main() -> i32 {
let max_len: i64 = 32
let m: i64 = 10000019
# Precompute powers of 10 mod m
let pow10: ptr<i64> = calloc(max_len + 1, 8)
pow10[0] = 1
for i in 1..(max_len + 1) {
pow10[i] = pow10[i - 1] * 10 % m
}
let inv10: i64 = mod_inv(10, m)
let dp: ptr<i64> = calloc(m, 8)
let tmp: ptr<i64> = calloc(m, 8)
let window: ptr<i64> = calloc(10, 8)
if dp == null || tmp == null || window == null { return 1 }
let mut total: i64 = 0
# Length 1: digits 1..9 (exclude 0)
for d in 1..10 {
if d % m == 0 { total = total + 1 }
}
# Even lengths: start from empty string (length 0)
for i in 0..m { dp[i] = 0 }
dp[0] = 1
let mut cur_len: i64 = 0
while cur_len + 2 <= max_len {
let new_len: i64 = cur_len + 2
let c: i64 = (pow10[new_len - 1] + 1) % m
let prev_zero: i64 = dp[0]
# tmp[j] = dp[j * inv10 mod m]
let mut src: i64 = 0
for j in 0..m {
tmp[j] = dp[src]
src = src + inv10
if src >= m { src = src - m }
}
# Fast update: visit residues in order 0, c, 2c, ... (mod m)
# Along this cycle, digit-sum is a cyclic sliding window of size 10
let mut idx: i64 = (-10 * c) % m
if idx < 0 { idx = idx + m }
let mut s: i64 = 0
for t in 0..10 {
let v: i64 = tmp[idx]
window[t] = v
s = s + v
idx = idx + c
if idx >= m { idx = idx - m }
}
let mut idx2: i64 = 0
let mut pos: i64 = 0
for _i in 0..m {
let v: i64 = tmp[idx2]
let old: i64 = window[pos]
s = s + v - old
window[pos] = v
pos = pos + 1
if pos == 10 { pos = 0 }
dp[idx2] = s
idx2 = idx2 + c
if idx2 >= m { idx2 = idx2 - m }
}
total = total + dp[0] - prev_zero
cur_len = new_len
}
# Odd lengths: start from 1-digit center (0..9)
for i in 0..m { dp[i] = 0 }
for d in 0..10 {
dp[d % m] = dp[d % m] + 1
}
cur_len = 1
while cur_len + 2 <= max_len {
let new_len: i64 = cur_len + 2
let c: i64 = (pow10[new_len - 1] + 1) % m
let prev_zero: i64 = dp[0]
let mut src: i64 = 0
for j in 0..m {
tmp[j] = dp[src]
src = src + inv10
if src >= m { src = src - m }
}
let mut idx: i64 = (-10 * c) % m
if idx < 0 { idx = idx + m }
let mut s: i64 = 0
for t in 0..10 {
let v: i64 = tmp[idx]
window[t] = v
s = s + v
idx = idx + c
if idx >= m { idx = idx - m }
}
let mut idx2: i64 = 0
let mut pos: i64 = 0
for _i in 0..m {
let v: i64 = tmp[idx2]
let old: i64 = window[pos]
s = s + v - old
window[pos] = v
pos = pos + 1
if pos == 10 { pos = 0 }
dp[idx2] = s
idx2 = idx2 + c
if idx2 >= m { idx2 = idx2 - m }
}
total = total + dp[0] - prev_zero
cur_len = new_len
}
printf("%lld\n", total)
free(window)
free(tmp)
free(dp)
free(pow10)
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; }
int64_t gcd_i64_i64(int64_t a0, int64_t b0);
int64_t lcm_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64(int64_t n);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t n);
int64_t mod_inv_i64_i64(int64_t a, int64_t m);
int32_t main(void);
int64_t gcd_i64_i64(int64_t a0, int64_t b0) {
int64_t a = a0;
int64_t b = b0;
while (b != 0) {
int64_t t = FLOW_CHECKED_MOD((a), (b));
a = b;
b = t;
}
return a;
}
int64_t lcm_i64_i64(int64_t a, int64_t b) {
if ((a == 0 || b == 0)) {
return 0;
}
return (FLOW_CHECKED_DIV((a), (gcd_i64_i64(a, b))) * b);
}
int64_t isqrt_i64(int64_t n) {
if (n < 2) {
return n;
}
int64_t x = n;
int64_t y = FLOW_CHECKED_DIV(((x + 1)), (2));
while (y < x) {
x = y;
y = FLOW_CHECKED_DIV(((x + FLOW_CHECKED_DIV((n), (x)))), (2));
}
return x;
}
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod) {
int64_t a = FLOW_CHECKED_MOD((a0), (mod));
int64_t b = FLOW_CHECKED_MOD((b0), (mod));
int64_t result = 0;
while (b > 0) {
if (FLOW_CHECKED_MOD((b), (2)) == 1) {
result = FLOW_CHECKED_MOD(((result + a)), (mod));
}
a = FLOW_CHECKED_MOD(((a * 2)), (mod));
b = FLOW_CHECKED_DIV((b), (2));
}
return result;
}
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
if (mod == 1) {
return 0;
}
int64_t result = 1;
int64_t b = FLOW_CHECKED_MOD((base), (mod));
int64_t e = exp;
while (e > 0) {
if (FLOW_CHECKED_MOD((e), (2)) == 1) {
result = mulmod_i64_i64_i64(result, b, mod);
}
b = mulmod_i64_i64_i64(b, b, mod);
e = FLOW_CHECKED_DIV((e), (2));
}
return result;
}
bool is_prime_i64(int64_t n) {
if (n < 2) {
return 0;
}
if (n < 4) {
return 1;
}
if ((FLOW_CHECKED_MOD((n), (2)) == 0 || FLOW_CHECKED_MOD((n), (3)) == 0)) {
return 0;
}
int64_t i = 5;
while ((i * i) <= n) {
if ((FLOW_CHECKED_MOD((n), (i)) == 0 || FLOW_CHECKED_MOD((n), ((i + 2))) == 0)) {
return 0;
}
i = (i + 6);
}
return 1;
}
int64_t mod_inv_i64_i64(int64_t a, int64_t m) {
return mod_pow_i64_i64_i64(a, (m - 2), m);
}
int32_t main(void) {
int64_t max_len = 32;
int64_t m = 10000019;
int64_t* pow10 = (int64_t*)(calloc((max_len + 1), 8));
pow10[0] = 1;
int32_t __flow_step_1 = 1;
for (int32_t i = 1; (1 <= (max_len + 1)) ? i < (max_len + 1) : i > (max_len + 1); i += (1 <= (max_len + 1)) ? 1 : -1) {
pow10[i] = FLOW_CHECKED_MOD(((pow10[(i - 1)] * 10)), (m));
}
int64_t inv10 = mod_inv_i64_i64(10, m);
int64_t* dp = (int64_t*)(calloc(m, 8));
int64_t* tmp = (int64_t*)(calloc(m, 8));
int64_t* window = (int64_t*)(calloc(10, 8));
if (((dp == NULL || tmp == NULL) || window == NULL)) {
return 1;
}
int64_t total = 0;
int32_t __flow_step_2 = 1;
for (int32_t d = 1; (1 <= 10) ? d < 10 : d > 10; d += (1 <= 10) ? 1 : -1) {
if (FLOW_CHECKED_MOD((d), (m)) == 0) {
total = (total + 1);
}
}
int32_t __flow_step_3 = 1;
for (int32_t i = 0; (0 <= m) ? i < m : i > m; i += (0 <= m) ? 1 : -1) {
dp[i] = 0;
}
dp[0] = 1;
int64_t cur_len = 0;
while ((cur_len + 2) <= max_len) {
int64_t new_len = (cur_len + 2);
int64_t c = FLOW_CHECKED_MOD(((pow10[(new_len - 1)] + 1)), (m));
int64_t prev_zero = dp[0];
int64_t src = 0;
int32_t __flow_step_4 = 1;
for (int32_t j = 0; (0 <= m) ? j < m : j > m; j += (0 <= m) ? 1 : -1) {
tmp[j] = dp[src];
src = (src + inv10);
if (src >= m) {
src = (src - m);
}
}
int64_t idx = FLOW_CHECKED_MOD((((-10) * c)), (m));
if (idx < 0) {
idx = (idx + m);
}
int64_t s = 0;
int32_t __flow_step_5 = 1;
for (int32_t t = 0; (0 <= 10) ? t < 10 : t > 10; t += (0 <= 10) ? 1 : -1) {
int64_t v = tmp[idx];
window[t] = v;
s = (s + v);
idx = (idx + c);
if (idx >= m) {
idx = (idx - m);
}
}
int64_t idx2 = 0;
int64_t pos = 0;
int32_t __flow_step_6 = 1;
for (int32_t _i = 0; (0 <= m) ? _i < m : _i > m; _i += (0 <= m) ? 1 : -1) {
int64_t v = tmp[idx2];
int64_t old = window[pos];
s = ((s + v) - old);
window[pos] = v;
pos = (pos + 1);
if (pos == 10) {
pos = 0;
}
dp[idx2] = s;
idx2 = (idx2 + c);
if (idx2 >= m) {
idx2 = (idx2 - m);
}
}
total = ((total + dp[0]) - prev_zero);
cur_len = new_len;
}
int32_t __flow_step_7 = 1;
for (int32_t i = 0; (0 <= m) ? i < m : i > m; i += (0 <= m) ? 1 : -1) {
dp[i] = 0;
}
int32_t __flow_step_8 = 1;
for (int32_t d = 0; (0 <= 10) ? d < 10 : d > 10; d += (0 <= 10) ? 1 : -1) {
dp[FLOW_CHECKED_MOD((d), (m))] = (dp[FLOW_CHECKED_MOD((d), (m))] + 1);
}
cur_len = 1;
while ((cur_len + 2) <= max_len) {
int64_t new_len = (cur_len + 2);
int64_t c = FLOW_CHECKED_MOD(((pow10[(new_len - 1)] + 1)), (m));
int64_t prev_zero = dp[0];
int64_t src = 0;
int32_t __flow_step_9 = 1;
for (int32_t j = 0; (0 <= m) ? j < m : j > m; j += (0 <= m) ? 1 : -1) {
tmp[j] = dp[src];
src = (src + inv10);
if (src >= m) {
src = (src - m);
}
}
int64_t idx = FLOW_CHECKED_MOD((((-10) * c)), (m));
if (idx < 0) {
idx = (idx + m);
}
int64_t s = 0;
int32_t __flow_step_10 = 1;
for (int32_t t = 0; (0 <= 10) ? t < 10 : t > 10; t += (0 <= 10) ? 1 : -1) {
int64_t v = tmp[idx];
window[t] = v;
s = (s + v);
idx = (idx + c);
if (idx >= m) {
idx = (idx - m);
}
}
int64_t idx2 = 0;
int64_t pos = 0;
int32_t __flow_step_11 = 1;
for (int32_t _i = 0; (0 <= m) ? _i < m : _i > m; _i += (0 <= m) ? 1 : -1) {
int64_t v = tmp[idx2];
int64_t old = window[pos];
s = ((s + v) - old);
window[pos] = v;
pos = (pos + 1);
if (pos == 10) {
pos = 0;
}
dp[idx2] = s;
idx2 = (idx2 + c);
if (idx2 >= m) {
idx2 = (idx2 - m);
}
}
total = ((total + dp[0]) - prev_zero);
cur_len = new_len;
}
printf("%lld\n", total);
free(window);
free(tmp);
free(dp);
free(pow10);
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 @gcd(%arg0: i64, %arg1: i64) -> i64 {
%0 = llvm.mlir.constant(1 : i64) : i64
%1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %1 : i64, !llvm.ptr
%2 = llvm.mlir.constant(1 : i64) : i64
%3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %3 : i64, !llvm.ptr
cf.br ^bb0
^bb0:
%4 = llvm.load %3 : !llvm.ptr -> i64
%5 = arith.constant 0 : i32
%7 = arith.extsi %5 : i32 to i64
%6 = arith.cmpi ne, %4, %7 : i64
cf.cond_br %6, ^bb1, ^bb2
^bb1:
%8 = llvm.load %1 : !llvm.ptr -> i64
%9 = llvm.load %3 : !llvm.ptr -> i64
%10 = arith.remsi %8, %9 : i64
%11 = llvm.load %3 : !llvm.ptr -> i64
llvm.store %11, %1 : i64, !llvm.ptr
llvm.store %10, %3 : i64, !llvm.ptr
cf.br ^bb0
^bb2:
%12 = llvm.load %1 : !llvm.ptr -> i64
func.return %12 : i64
}
func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
%13 = arith.constant 0 : i32
%15 = arith.extsi %13 : i32 to i64
%14 = arith.cmpi eq, %arg0, %15 : i64
%16 = scf.if %14 -> (i1) {
%17 = arith.constant true
scf.yield %17 : i1
} else {
%18 = arith.constant 0 : i32
%20 = arith.extsi %18 : i32 to i64
%19 = arith.cmpi eq, %arg1, %20 : i64
scf.yield %19 : i1
}
cf.cond_br %16, ^bb3, ^bb4
^bb3:
%21 = arith.constant 0 : i32
%22 = arith.extsi %21 : i32 to i64
func.return %22 : i64
^bb4:
cf.br ^bb5
^bb5:
%23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
%24 = arith.divsi %arg0, %23 : i64
%25 = arith.muli %24, %arg1 : i64
func.return %25 : i64
}
func.func @isqrt(%arg0: i64) -> i64 {
%26 = arith.constant 2 : i32
%28 = arith.extsi %26 : i32 to i64
%27 = arith.cmpi slt, %arg0, %28 : i64
cf.cond_br %27, ^bb6, ^bb7
^bb6:
func.return %arg0 : i64
^bb7:
cf.br ^bb8
^bb8:
%29 = llvm.mlir.constant(1 : i64) : i64
%30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %30 : i64, !llvm.ptr
%31 = llvm.load %30 : !llvm.ptr -> i64
%32 = arith.constant 1 : i32
%34 = arith.extsi %32 : i32 to i64
%33 = arith.addi %31, %34 : i64
%35 = arith.constant 2 : i32
%37 = arith.extsi %35 : i32 to i64
%36 = arith.divsi %33, %37 : i64
%38 = llvm.mlir.constant(1 : i64) : i64
%39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
llvm.store %36, %39 : i64, !llvm.ptr
cf.br ^bb9
^bb9:
%40 = llvm.load %39 : !llvm.ptr -> i64
%41 = llvm.load %30 : !llvm.ptr -> i64
%42 = arith.cmpi slt, %40, %41 : i64
cf.cond_br %42, ^bb10, ^bb11
^bb10:
%43 = llvm.load %39 : !llvm.ptr -> i64
llvm.store %43, %30 : i64, !llvm.ptr
%44 = llvm.load %30 : !llvm.ptr -> i64
%45 = llvm.load %30 : !llvm.ptr -> i64
%46 = arith.divsi %arg0, %45 : i64
%47 = arith.addi %44, %46 : i64
%48 = arith.constant 2 : i32
%50 = arith.extsi %48 : i32 to i64
%49 = arith.divsi %47, %50 : i64
llvm.store %49, %39 : i64, !llvm.ptr
cf.br ^bb9
^bb11:
%51 = llvm.load %30 : !llvm.ptr -> i64
func.return %51 : i64
}
func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%52 = arith.remsi %arg0, %arg2 : i64
%53 = llvm.mlir.constant(1 : i64) : i64
%54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
llvm.store %52, %54 : i64, !llvm.ptr
%55 = arith.remsi %arg1, %arg2 : i64
%56 = llvm.mlir.constant(1 : i64) : i64
%57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
llvm.store %55, %57 : i64, !llvm.ptr
%58 = arith.constant 0 : i32
%59 = arith.extsi %58 : i32 to i64
%60 = llvm.mlir.constant(1 : i64) : i64
%61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
llvm.store %59, %61 : i64, !llvm.ptr
cf.br ^bb12
^bb12:
%62 = llvm.load %57 : !llvm.ptr -> i64
%63 = arith.constant 0 : i32
%65 = arith.extsi %63 : i32 to i64
%64 = arith.cmpi sgt, %62, %65 : i64
cf.cond_br %64, ^bb13, ^bb14
^bb13:
%66 = llvm.load %57 : !llvm.ptr -> i64
%67 = arith.constant 2 : i32
%69 = arith.extsi %67 : i32 to i64
%68 = arith.remsi %66, %69 : i64
%70 = arith.constant 1 : i32
%72 = arith.extsi %70 : i32 to i64
%71 = arith.cmpi eq, %68, %72 : i64
cf.cond_br %71, ^bb15, ^bb16
^bb15:
%73 = llvm.load %61 : !llvm.ptr -> i64
%74 = llvm.load %54 : !llvm.ptr -> i64
%75 = arith.addi %73, %74 : i64
%76 = arith.remsi %75, %arg2 : i64
llvm.store %76, %61 : i64, !llvm.ptr
cf.br ^bb17
^bb16:
cf.br ^bb17
^bb17:
%77 = llvm.load %54 : !llvm.ptr -> i64
%78 = arith.constant 2 : i32
%80 = arith.extsi %78 : i32 to i64
%79 = arith.muli %77, %80 : i64
%81 = arith.remsi %79, %arg2 : i64
llvm.store %81, %54 : i64, !llvm.ptr
%82 = llvm.load %57 : !llvm.ptr -> i64
%83 = arith.constant 2 : i32
%85 = arith.extsi %83 : i32 to i64
%84 = arith.divsi %82, %85 : i64
llvm.store %84, %57 : i64, !llvm.ptr
cf.br ^bb12
^bb14:
%86 = llvm.load %61 : !llvm.ptr -> i64
func.return %86 : i64
}
func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%87 = arith.constant 1 : i32
%89 = arith.extsi %87 : i32 to i64
%88 = arith.cmpi eq, %arg2, %89 : i64
cf.cond_br %88, ^bb18, ^bb19
^bb18:
%90 = arith.constant 0 : i32
%91 = arith.extsi %90 : i32 to i64
func.return %91 : i64
^bb19:
cf.br ^bb20
^bb20:
%92 = arith.constant 1 : i32
%93 = arith.extsi %92 : i32 to i64
%94 = llvm.mlir.constant(1 : i64) : i64
%95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
llvm.store %93, %95 : i64, !llvm.ptr
%96 = arith.remsi %arg0, %arg2 : i64
%97 = llvm.mlir.constant(1 : i64) : i64
%98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
llvm.store %96, %98 : i64, !llvm.ptr
%99 = llvm.mlir.constant(1 : i64) : i64
%100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %100 : i64, !llvm.ptr
cf.br ^bb21
^bb21:
%101 = llvm.load %100 : !llvm.ptr -> i64
%102 = arith.constant 0 : i32
%104 = arith.extsi %102 : i32 to i64
%103 = arith.cmpi sgt, %101, %104 : i64
cf.cond_br %103, ^bb22, ^bb23
^bb22:
%105 = llvm.load %100 : !llvm.ptr -> i64
%106 = arith.constant 2 : i32
%108 = arith.extsi %106 : i32 to i64
%107 = arith.remsi %105, %108 : i64
%109 = arith.constant 1 : i32
%111 = arith.extsi %109 : i32 to i64
%110 = arith.cmpi eq, %107, %111 : i64
cf.cond_br %110, ^bb24, ^bb25
^bb24:
%113 = llvm.load %95 : !llvm.ptr -> i64
%114 = llvm.load %98 : !llvm.ptr -> i64
%112 = func.call @mulmod(%113, %114, %arg2) : (i64, i64, i64) -> i64
llvm.store %112, %95 : i64, !llvm.ptr
cf.br ^bb26
^bb25:
cf.br ^bb26
^bb26:
%116 = llvm.load %98 : !llvm.ptr -> i64
%117 = llvm.load %98 : !llvm.ptr -> i64
%115 = func.call @mulmod(%116, %117, %arg2) : (i64, i64, i64) -> i64
llvm.store %115, %98 : i64, !llvm.ptr
%118 = llvm.load %100 : !llvm.ptr -> i64
%119 = arith.constant 2 : i32
%121 = arith.extsi %119 : i32 to i64
%120 = arith.divsi %118, %121 : i64
llvm.store %120, %100 : i64, !llvm.ptr
cf.br ^bb21
^bb23:
%122 = llvm.load %95 : !llvm.ptr -> i64
func.return %122 : i64
}
func.func @is_prime(%arg0: i64) -> i1 {
%123 = arith.constant 2 : i32
%125 = arith.extsi %123 : i32 to i64
%124 = arith.cmpi slt, %arg0, %125 : i64
cf.cond_br %124, ^bb27, ^bb28
^bb27:
%126 = arith.constant 0 : i1
func.return %126 : i1
^bb28:
cf.br ^bb29
^bb29:
%127 = arith.constant 4 : i32
%129 = arith.extsi %127 : i32 to i64
%128 = arith.cmpi slt, %arg0, %129 : i64
cf.cond_br %128, ^bb30, ^bb31
^bb30:
%130 = arith.constant 1 : i1
func.return %130 : i1
^bb31:
cf.br ^bb32
^bb32:
%131 = arith.constant 2 : i32
%133 = arith.extsi %131 : i32 to i64
%132 = arith.remsi %arg0, %133 : i64
%134 = arith.constant 0 : i32
%136 = arith.extsi %134 : i32 to i64
%135 = arith.cmpi eq, %132, %136 : i64
%137 = scf.if %135 -> (i1) {
%138 = arith.constant true
scf.yield %138 : i1
} else {
%139 = arith.constant 3 : i32
%141 = arith.extsi %139 : i32 to i64
%140 = arith.remsi %arg0, %141 : i64
%142 = arith.constant 0 : i32
%144 = arith.extsi %142 : i32 to i64
%143 = arith.cmpi eq, %140, %144 : i64
scf.yield %143 : i1
}
cf.cond_br %137, ^bb33, ^bb34
^bb33:
%145 = arith.constant 0 : i1
func.return %145 : i1
^bb34:
cf.br ^bb35
^bb35:
%146 = arith.constant 5 : i32
%147 = arith.extsi %146 : i32 to i64
%148 = llvm.mlir.constant(1 : i64) : i64
%149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
llvm.store %147, %149 : i64, !llvm.ptr
cf.br ^bb36
^bb36:
%150 = llvm.load %149 : !llvm.ptr -> i64
%151 = llvm.load %149 : !llvm.ptr -> i64
%152 = arith.muli %150, %151 : i64
%153 = arith.cmpi sle, %152, %arg0 : i64
cf.cond_br %153, ^bb37, ^bb38
^bb37:
%154 = llvm.load %149 : !llvm.ptr -> i64
%155 = arith.remsi %arg0, %154 : i64
%156 = arith.constant 0 : i32
%158 = arith.extsi %156 : i32 to i64
%157 = arith.cmpi eq, %155, %158 : i64
%159 = scf.if %157 -> (i1) {
%160 = arith.constant true
scf.yield %160 : i1
} else {
%161 = llvm.load %149 : !llvm.ptr -> i64
%162 = arith.constant 2 : i32
%164 = arith.extsi %162 : i32 to i64
%163 = arith.addi %161, %164 : i64
%165 = arith.remsi %arg0, %163 : i64
%166 = arith.constant 0 : i32
%168 = arith.extsi %166 : i32 to i64
%167 = arith.cmpi eq, %165, %168 : i64
scf.yield %167 : i1
}
cf.cond_br %159, ^bb39, ^bb40
^bb39:
%169 = arith.constant 0 : i1
func.return %169 : i1
^bb40:
cf.br ^bb41
^bb41:
%170 = llvm.load %149 : !llvm.ptr -> i64
%171 = arith.constant 6 : i32
%173 = arith.extsi %171 : i32 to i64
%172 = arith.addi %170, %173 : i64
llvm.store %172, %149 : i64, !llvm.ptr
cf.br ^bb36
^bb38:
%174 = arith.constant 1 : i1
func.return %174 : i1
}
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
func.func @mod_inv(%arg0: i64, %arg1: i64) -> i64 {
%176 = arith.constant 2 : i32
%178 = arith.extsi %176 : i32 to i64
%177 = arith.subi %arg1, %178 : i64
%175 = func.call @mod_pow(%arg0, %177, %arg1) : (i64, i64, i64) -> i64
func.return %175 : i64
}
func.func @main() -> i32 {
%179 = arith.constant 32 : i32
%180 = arith.extsi %179 : i32 to i64
%181 = arith.constant 10000019 : i32
%182 = arith.extsi %181 : i32 to i64
%184 = arith.constant 1 : i32
%186 = arith.extsi %184 : i32 to i64
%185 = arith.addi %180, %186 : i64
%187 = arith.constant 8 : i32
%188 = arith.extsi %187 : i32 to i64
%183 = func.call @calloc(%185, %188) : (i64, i64) -> !llvm.ptr
%189 = arith.constant 1 : i32
%190 = arith.constant 0 : i32
%191 = arith.extsi %189 : i32 to i64
%192 = arith.extsi %190 : i32 to i64
%193 = llvm.getelementptr %183[%192] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %191, %193 : i64, !llvm.ptr
%194 = arith.constant 1 : i32
%195 = arith.constant 1 : i32
%197 = arith.extsi %195 : i32 to i64
%196 = arith.addi %180, %197 : i64
%198 = arith.index_cast %194 : i32 to index
%199 = arith.index_cast %196 : i32 to index
%201 = arith.constant 1 : index
%202 = arith.constant -1 : index
%203 = arith.cmpi sle, %198, %199 : index
%200 = arith.select %203, %201, %202 : index
cf.br ^bb42(%198 : index)
^bb42(%204: index):
%205 = arith.cmpi slt, %204, %199 : index
%206 = arith.cmpi sgt, %204, %199 : index
%207 = arith.select %203, %205, %206 : i1
cf.cond_br %207, ^bb43(%204 : index), ^bb44(%204 : index)
^bb43(%208: index):
%210 = arith.constant 1 : i32
%212 = arith.index_cast %208 : index to i32
%211 = arith.subi %212, %210 : i32
%213 = arith.extsi %211 : i32 to i64
%214 = llvm.getelementptr %183[%213] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%209 = llvm.load %214 : !llvm.ptr -> i64
%215 = arith.constant 10 : i32
%217 = arith.extsi %215 : i32 to i64
%216 = arith.muli %209, %217 : i64
%218 = arith.remsi %216, %182 : i64
%219 = arith.index_cast %208 : index to i64
%220 = llvm.getelementptr %183[%219] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %218, %220 : i64, !llvm.ptr
%221 = arith.addi %208, %200 : index
cf.br ^bb42(%221 : index)
^bb44(%222: index):
%224 = arith.constant 10 : i32
%225 = arith.extsi %224 : i32 to i64
%223 = func.call @mod_inv(%225, %182) : (i64, i64) -> i64
%227 = arith.constant 8 : i32
%228 = arith.extsi %227 : i32 to i64
%226 = func.call @calloc(%182, %228) : (i64, i64) -> !llvm.ptr
%230 = arith.constant 8 : i32
%231 = arith.extsi %230 : i32 to i64
%229 = func.call @calloc(%182, %231) : (i64, i64) -> !llvm.ptr
%233 = arith.constant 10 : i32
%234 = arith.constant 8 : i32
%235 = arith.extsi %233 : i32 to i64
%236 = arith.extsi %234 : i32 to i64
%232 = func.call @calloc(%235, %236) : (i64, i64) -> !llvm.ptr
%237 = llvm.mlir.zero : !llvm.ptr
%238 = llvm.icmp "eq" %226, %237 : !llvm.ptr
%239 = scf.if %238 -> (i1) {
%240 = arith.constant true
scf.yield %240 : i1
} else {
%241 = llvm.mlir.zero : !llvm.ptr
%242 = llvm.icmp "eq" %229, %241 : !llvm.ptr
scf.yield %242 : i1
}
%243 = scf.if %239 -> (i1) {
%244 = arith.constant true
scf.yield %244 : i1
} else {
%245 = llvm.mlir.zero : !llvm.ptr
%246 = llvm.icmp "eq" %232, %245 : !llvm.ptr
scf.yield %246 : i1
}
cf.cond_br %243, ^bb45, ^bb46
^bb45:
%247 = arith.constant 1 : i32
func.return %247 : i32
^bb46:
cf.br ^bb47
^bb47:
%248 = arith.constant 0 : i32
%249 = arith.extsi %248 : i32 to i64
%250 = llvm.mlir.constant(1 : i64) : i64
%251 = llvm.alloca %250 x i64 : (i64) -> !llvm.ptr
llvm.store %249, %251 : i64, !llvm.ptr
%252 = arith.constant 1 : i32
%253 = arith.constant 10 : i32
%254 = arith.index_cast %252 : i32 to index
%255 = arith.index_cast %253 : i32 to index
%257 = arith.constant 1 : index
%258 = arith.constant -1 : index
%259 = arith.cmpi sle, %254, %255 : index
%256 = arith.select %259, %257, %258 : index
cf.br ^bb48(%254 : index)
^bb48(%260: index):
%261 = arith.cmpi slt, %260, %255 : index
%262 = arith.cmpi sgt, %260, %255 : index
%263 = arith.select %259, %261, %262 : i1
cf.cond_br %263, ^bb49(%260 : index), ^bb50(%260 : index)
^bb49(%264: index):
%266 = arith.index_cast %264 : index to i32
%267 = arith.trunci %182 : i64 to i32
%265 = arith.remsi %266, %267 : i32
%268 = arith.constant 0 : i32
%269 = arith.cmpi eq, %265, %268 : i32
cf.cond_br %269, ^bb51, ^bb52
^bb51:
%270 = llvm.load %251 : !llvm.ptr -> i64
%271 = arith.constant 1 : i32
%273 = arith.extsi %271 : i32 to i64
%272 = arith.addi %270, %273 : i64
llvm.store %272, %251 : i64, !llvm.ptr
cf.br ^bb53
^bb52:
cf.br ^bb53
^bb53:
%274 = arith.addi %264, %256 : index
cf.br ^bb48(%274 : index)
^bb50(%275: index):
%276 = arith.constant 0 : i32
%277 = arith.index_cast %276 : i32 to index
%278 = arith.index_cast %182 : i32 to index
%280 = arith.constant 1 : index
%281 = arith.constant -1 : index
%282 = arith.cmpi sle, %277, %278 : index
%279 = arith.select %282, %280, %281 : index
cf.br ^bb54(%277 : index)
^bb54(%283: index):
%284 = arith.cmpi slt, %283, %278 : index
%285 = arith.cmpi sgt, %283, %278 : index
%286 = arith.select %282, %284, %285 : i1
cf.cond_br %286, ^bb55(%283 : index), ^bb56(%283 : index)
^bb55(%287: index):
%288 = arith.constant 0 : i32
%289 = arith.extsi %288 : i32 to i64
%290 = arith.index_cast %287 : index to i64
%291 = llvm.getelementptr %226[%290] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %289, %291 : i64, !llvm.ptr
%292 = arith.addi %287, %279 : index
cf.br ^bb54(%292 : index)
^bb56(%293: index):
%294 = arith.constant 1 : i32
%295 = arith.constant 0 : i32
%296 = arith.extsi %294 : i32 to i64
%297 = arith.extsi %295 : i32 to i64
%298 = llvm.getelementptr %226[%297] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %296, %298 : i64, !llvm.ptr
%299 = arith.constant 0 : i32
%300 = arith.extsi %299 : i32 to i64
%301 = llvm.mlir.constant(1 : i64) : i64
%302 = llvm.alloca %301 x i64 : (i64) -> !llvm.ptr
llvm.store %300, %302 : i64, !llvm.ptr
cf.br ^bb57
^bb57:
%303 = llvm.load %302 : !llvm.ptr -> i64
%304 = arith.constant 2 : i32
%306 = arith.extsi %304 : i32 to i64
%305 = arith.addi %303, %306 : i64
%307 = arith.cmpi sle, %305, %180 : i64
cf.cond_br %307, ^bb58, ^bb59
^bb58:
%308 = llvm.load %302 : !llvm.ptr -> i64
%309 = arith.constant 2 : i32
%311 = arith.extsi %309 : i32 to i64
%310 = arith.addi %308, %311 : i64
%313 = arith.constant 1 : i32
%315 = arith.extsi %313 : i32 to i64
%314 = arith.subi %310, %315 : i64
%316 = llvm.getelementptr %183[%314] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%312 = llvm.load %316 : !llvm.ptr -> i64
%317 = arith.constant 1 : i32
%319 = arith.extsi %317 : i32 to i64
%318 = arith.addi %312, %319 : i64
%320 = arith.remsi %318, %182 : i64
%322 = arith.constant 0 : i32
%323 = arith.extsi %322 : i32 to i64
%324 = llvm.getelementptr %226[%323] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%321 = llvm.load %324 : !llvm.ptr -> i64
%325 = arith.constant 0 : i32
%326 = arith.extsi %325 : i32 to i64
%327 = llvm.mlir.constant(1 : i64) : i64
%328 = llvm.alloca %327 x i64 : (i64) -> !llvm.ptr
llvm.store %326, %328 : i64, !llvm.ptr
%329 = arith.constant 0 : i32
%330 = arith.index_cast %329 : i32 to index
%331 = arith.index_cast %182 : i32 to index
%333 = arith.constant 1 : index
%334 = arith.constant -1 : index
%335 = arith.cmpi sle, %330, %331 : index
%332 = arith.select %335, %333, %334 : index
cf.br ^bb60(%330 : index)
^bb60(%336: index):
%337 = arith.cmpi slt, %336, %331 : index
%338 = arith.cmpi sgt, %336, %331 : index
%339 = arith.select %335, %337, %338 : i1
cf.cond_br %339, ^bb61(%336 : index), ^bb62(%336 : index)
^bb61(%340: index):
%342 = llvm.load %328 : !llvm.ptr -> i64
%343 = llvm.getelementptr %226[%342] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%341 = llvm.load %343 : !llvm.ptr -> i64
%344 = arith.index_cast %340 : index to i64
%345 = llvm.getelementptr %229[%344] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %341, %345 : i64, !llvm.ptr
%346 = llvm.load %328 : !llvm.ptr -> i64
%347 = arith.addi %346, %223 : i64
llvm.store %347, %328 : i64, !llvm.ptr
%348 = llvm.load %328 : !llvm.ptr -> i64
%349 = arith.cmpi sge, %348, %182 : i64
cf.cond_br %349, ^bb63, ^bb64
^bb63:
%350 = llvm.load %328 : !llvm.ptr -> i64
%351 = arith.subi %350, %182 : i64
llvm.store %351, %328 : i64, !llvm.ptr
cf.br ^bb65
^bb64:
cf.br ^bb65
^bb65:
%352 = arith.addi %340, %332 : index
cf.br ^bb60(%352 : index)
^bb62(%353: index):
%354 = arith.constant 10 : i32
%356 = arith.constant 0 : i32
%355 = arith.subi %356, %354 : i32
%358 = arith.extsi %355 : i32 to i64
%357 = arith.muli %358, %320 : i64
%359 = arith.remsi %357, %182 : i64
%360 = llvm.mlir.constant(1 : i64) : i64
%361 = llvm.alloca %360 x i64 : (i64) -> !llvm.ptr
llvm.store %359, %361 : i64, !llvm.ptr
%362 = llvm.load %361 : !llvm.ptr -> i64
%363 = arith.constant 0 : i32
%365 = arith.extsi %363 : i32 to i64
%364 = arith.cmpi slt, %362, %365 : i64
cf.cond_br %364, ^bb66, ^bb67
^bb66:
%366 = llvm.load %361 : !llvm.ptr -> i64
%367 = arith.addi %366, %182 : i64
llvm.store %367, %361 : i64, !llvm.ptr
cf.br ^bb68
^bb67:
cf.br ^bb68
^bb68:
%368 = arith.constant 0 : i32
%369 = arith.extsi %368 : i32 to i64
%370 = llvm.mlir.constant(1 : i64) : i64
%371 = llvm.alloca %370 x i64 : (i64) -> !llvm.ptr
llvm.store %369, %371 : i64, !llvm.ptr
%372 = arith.constant 0 : i32
%373 = arith.constant 10 : i32
%374 = arith.index_cast %372 : i32 to index
%375 = arith.index_cast %373 : i32 to index
%377 = arith.constant 1 : index
%378 = arith.constant -1 : index
%379 = arith.cmpi sle, %374, %375 : index
%376 = arith.select %379, %377, %378 : index
cf.br ^bb69(%374 : index)
^bb69(%380: index):
%381 = arith.cmpi slt, %380, %375 : index
%382 = arith.cmpi sgt, %380, %375 : index
%383 = arith.select %379, %381, %382 : i1
cf.cond_br %383, ^bb70(%380 : index), ^bb71(%380 : index)
^bb70(%384: index):
%386 = llvm.load %361 : !llvm.ptr -> i64
%387 = llvm.getelementptr %229[%386] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%385 = llvm.load %387 : !llvm.ptr -> i64
%388 = arith.index_cast %384 : index to i64
%389 = llvm.getelementptr %232[%388] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %385, %389 : i64, !llvm.ptr
%390 = llvm.load %371 : !llvm.ptr -> i64
%391 = arith.addi %390, %385 : i64
llvm.store %391, %371 : i64, !llvm.ptr
%392 = llvm.load %361 : !llvm.ptr -> i64
%393 = arith.addi %392, %320 : i64
llvm.store %393, %361 : i64, !llvm.ptr
%394 = llvm.load %361 : !llvm.ptr -> i64
%395 = arith.cmpi sge, %394, %182 : i64
cf.cond_br %395, ^bb72, ^bb73
^bb72:
%396 = llvm.load %361 : !llvm.ptr -> i64
%397 = arith.subi %396, %182 : i64
llvm.store %397, %361 : i64, !llvm.ptr
cf.br ^bb74
^bb73:
cf.br ^bb74
^bb74:
%398 = arith.addi %384, %376 : index
cf.br ^bb69(%398 : index)
^bb71(%399: index):
%400 = arith.constant 0 : i32
%401 = arith.extsi %400 : i32 to i64
%402 = llvm.mlir.constant(1 : i64) : i64
%403 = llvm.alloca %402 x i64 : (i64) -> !llvm.ptr
llvm.store %401, %403 : i64, !llvm.ptr
%404 = arith.constant 0 : i32
%405 = arith.extsi %404 : i32 to i64
%406 = llvm.mlir.constant(1 : i64) : i64
%407 = llvm.alloca %406 x i64 : (i64) -> !llvm.ptr
llvm.store %405, %407 : i64, !llvm.ptr
%408 = arith.constant 0 : i32
%409 = arith.index_cast %408 : i32 to index
%410 = arith.index_cast %182 : i32 to index
%412 = arith.constant 1 : index
%413 = arith.constant -1 : index
%414 = arith.cmpi sle, %409, %410 : index
%411 = arith.select %414, %412, %413 : index
cf.br ^bb75(%409 : index)
^bb75(%415: index):
%416 = arith.cmpi slt, %415, %410 : index
%417 = arith.cmpi sgt, %415, %410 : index
%418 = arith.select %414, %416, %417 : i1
cf.cond_br %418, ^bb76(%415 : index), ^bb77(%415 : index)
^bb76(%419: index):
%421 = llvm.load %403 : !llvm.ptr -> i64
%422 = llvm.getelementptr %229[%421] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%420 = llvm.load %422 : !llvm.ptr -> i64
%424 = llvm.load %407 : !llvm.ptr -> i64
%425 = llvm.getelementptr %232[%424] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%423 = llvm.load %425 : !llvm.ptr -> i64
%426 = llvm.load %371 : !llvm.ptr -> i64
%427 = arith.addi %426, %420 : i64
%428 = arith.subi %427, %423 : i64
llvm.store %428, %371 : i64, !llvm.ptr
%429 = llvm.load %407 : !llvm.ptr -> i64
%430 = llvm.getelementptr %232[%429] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %420, %430 : i64, !llvm.ptr
%431 = llvm.load %407 : !llvm.ptr -> i64
%432 = arith.constant 1 : i32
%434 = arith.extsi %432 : i32 to i64
%433 = arith.addi %431, %434 : i64
llvm.store %433, %407 : i64, !llvm.ptr
%435 = llvm.load %407 : !llvm.ptr -> i64
%436 = arith.constant 10 : i32
%438 = arith.extsi %436 : i32 to i64
%437 = arith.cmpi eq, %435, %438 : i64
cf.cond_br %437, ^bb78, ^bb79
^bb78:
%439 = arith.constant 0 : i32
%440 = arith.extsi %439 : i32 to i64
llvm.store %440, %407 : i64, !llvm.ptr
cf.br ^bb80
^bb79:
cf.br ^bb80
^bb80:
%441 = llvm.load %371 : !llvm.ptr -> i64
%442 = llvm.load %403 : !llvm.ptr -> i64
%443 = llvm.getelementptr %226[%442] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %441, %443 : i64, !llvm.ptr
%444 = llvm.load %403 : !llvm.ptr -> i64
%445 = arith.addi %444, %320 : i64
llvm.store %445, %403 : i64, !llvm.ptr
%446 = llvm.load %403 : !llvm.ptr -> i64
%447 = arith.cmpi sge, %446, %182 : i64
cf.cond_br %447, ^bb81, ^bb82
^bb81:
%448 = llvm.load %403 : !llvm.ptr -> i64
%449 = arith.subi %448, %182 : i64
llvm.store %449, %403 : i64, !llvm.ptr
cf.br ^bb83
^bb82:
cf.br ^bb83
^bb83:
%450 = arith.addi %419, %411 : index
cf.br ^bb75(%450 : index)
^bb77(%451: index):
%452 = llvm.load %251 : !llvm.ptr -> i64
%454 = arith.constant 0 : i32
%455 = arith.extsi %454 : i32 to i64
%456 = llvm.getelementptr %226[%455] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%453 = llvm.load %456 : !llvm.ptr -> i64
%457 = arith.addi %452, %453 : i64
%458 = arith.subi %457, %321 : i64
llvm.store %458, %251 : i64, !llvm.ptr
llvm.store %310, %302 : i64, !llvm.ptr
cf.br ^bb57
^bb59:
%459 = arith.constant 0 : i32
%460 = arith.index_cast %459 : i32 to index
%461 = arith.index_cast %182 : i32 to index
%463 = arith.constant 1 : index
%464 = arith.constant -1 : index
%465 = arith.cmpi sle, %460, %461 : index
%462 = arith.select %465, %463, %464 : index
cf.br ^bb84(%460 : index)
^bb84(%466: index):
%467 = arith.cmpi slt, %466, %461 : index
%468 = arith.cmpi sgt, %466, %461 : index
%469 = arith.select %465, %467, %468 : i1
cf.cond_br %469, ^bb85(%466 : index), ^bb86(%466 : index)
^bb85(%470: index):
%471 = arith.constant 0 : i32
%472 = arith.extsi %471 : i32 to i64
%473 = arith.index_cast %470 : index to i64
%474 = llvm.getelementptr %226[%473] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %472, %474 : i64, !llvm.ptr
%475 = arith.addi %470, %462 : index
cf.br ^bb84(%475 : index)
^bb86(%476: index):
%477 = arith.constant 0 : i32
%478 = arith.constant 10 : i32
%479 = arith.index_cast %477 : i32 to index
%480 = arith.index_cast %478 : i32 to index
%482 = arith.constant 1 : index
%483 = arith.constant -1 : index
%484 = arith.cmpi sle, %479, %480 : index
%481 = arith.select %484, %482, %483 : index
cf.br ^bb87(%479 : index)
^bb87(%485: index):
%486 = arith.cmpi slt, %485, %480 : index
%487 = arith.cmpi sgt, %485, %480 : index
%488 = arith.select %484, %486, %487 : i1
cf.cond_br %488, ^bb88(%485 : index), ^bb89(%485 : index)
^bb88(%489: index):
%492 = arith.index_cast %489 : index to i32
%493 = arith.trunci %182 : i64 to i32
%491 = arith.remsi %492, %493 : i32
%494 = arith.extsi %491 : i32 to i64
%495 = llvm.getelementptr %226[%494] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%490 = llvm.load %495 : !llvm.ptr -> i64
%496 = arith.constant 1 : i32
%498 = arith.extsi %496 : i32 to i64
%497 = arith.addi %490, %498 : i64
%500 = arith.index_cast %489 : index to i32
%501 = arith.trunci %182 : i64 to i32
%499 = arith.remsi %500, %501 : i32
%502 = arith.extsi %499 : i32 to i64
%503 = llvm.getelementptr %226[%502] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %497, %503 : i64, !llvm.ptr
%504 = arith.addi %489, %481 : index
cf.br ^bb87(%504 : index)
^bb89(%505: index):
%506 = arith.constant 1 : i32
%507 = arith.extsi %506 : i32 to i64
llvm.store %507, %302 : i64, !llvm.ptr
cf.br ^bb90
^bb90:
%508 = llvm.load %302 : !llvm.ptr -> i64
%509 = arith.constant 2 : i32
%511 = arith.extsi %509 : i32 to i64
%510 = arith.addi %508, %511 : i64
%512 = arith.cmpi sle, %510, %180 : i64
cf.cond_br %512, ^bb91, ^bb92
^bb91:
%513 = llvm.load %302 : !llvm.ptr -> i64
%514 = arith.constant 2 : i32
%516 = arith.extsi %514 : i32 to i64
%515 = arith.addi %513, %516 : i64
%518 = arith.constant 1 : i32
%520 = arith.extsi %518 : i32 to i64
%519 = arith.subi %515, %520 : i64
%521 = llvm.getelementptr %183[%519] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%517 = llvm.load %521 : !llvm.ptr -> i64
%522 = arith.constant 1 : i32
%524 = arith.extsi %522 : i32 to i64
%523 = arith.addi %517, %524 : i64
%525 = arith.remsi %523, %182 : i64
%527 = arith.constant 0 : i32
%528 = arith.extsi %527 : i32 to i64
%529 = llvm.getelementptr %226[%528] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%526 = llvm.load %529 : !llvm.ptr -> i64
%530 = arith.constant 0 : i32
%531 = arith.extsi %530 : i32 to i64
%532 = llvm.mlir.constant(1 : i64) : i64
%533 = llvm.alloca %532 x i64 : (i64) -> !llvm.ptr
llvm.store %531, %533 : i64, !llvm.ptr
%534 = arith.constant 0 : i32
%535 = arith.index_cast %534 : i32 to index
%536 = arith.index_cast %182 : i32 to index
%538 = arith.constant 1 : index
%539 = arith.constant -1 : index
%540 = arith.cmpi sle, %535, %536 : index
%537 = arith.select %540, %538, %539 : index
cf.br ^bb93(%535 : index)
^bb93(%541: index):
%542 = arith.cmpi slt, %541, %536 : index
%543 = arith.cmpi sgt, %541, %536 : index
%544 = arith.select %540, %542, %543 : i1
cf.cond_br %544, ^bb94(%541 : index), ^bb95(%541 : index)
^bb94(%545: index):
%547 = llvm.load %533 : !llvm.ptr -> i64
%548 = llvm.getelementptr %226[%547] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%546 = llvm.load %548 : !llvm.ptr -> i64
%549 = arith.index_cast %545 : index to i64
%550 = llvm.getelementptr %229[%549] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %546, %550 : i64, !llvm.ptr
%551 = llvm.load %533 : !llvm.ptr -> i64
%552 = arith.addi %551, %223 : i64
llvm.store %552, %533 : i64, !llvm.ptr
%553 = llvm.load %533 : !llvm.ptr -> i64
%554 = arith.cmpi sge, %553, %182 : i64
cf.cond_br %554, ^bb96, ^bb97
^bb96:
%555 = llvm.load %533 : !llvm.ptr -> i64
%556 = arith.subi %555, %182 : i64
llvm.store %556, %533 : i64, !llvm.ptr
cf.br ^bb98
^bb97:
cf.br ^bb98
^bb98:
%557 = arith.addi %545, %537 : index
cf.br ^bb93(%557 : index)
^bb95(%558: index):
%559 = arith.constant 10 : i32
%561 = arith.constant 0 : i32
%560 = arith.subi %561, %559 : i32
%563 = arith.extsi %560 : i32 to i64
%562 = arith.muli %563, %525 : i64
%564 = arith.remsi %562, %182 : i64
%565 = llvm.mlir.constant(1 : i64) : i64
%566 = llvm.alloca %565 x i64 : (i64) -> !llvm.ptr
llvm.store %564, %566 : i64, !llvm.ptr
%567 = llvm.load %566 : !llvm.ptr -> i64
%568 = arith.constant 0 : i32
%570 = arith.extsi %568 : i32 to i64
%569 = arith.cmpi slt, %567, %570 : i64
cf.cond_br %569, ^bb99, ^bb100
^bb99:
%571 = llvm.load %566 : !llvm.ptr -> i64
%572 = arith.addi %571, %182 : i64
llvm.store %572, %566 : i64, !llvm.ptr
cf.br ^bb101
^bb100:
cf.br ^bb101
^bb101:
%573 = arith.constant 0 : i32
%574 = arith.extsi %573 : i32 to i64
%575 = llvm.mlir.constant(1 : i64) : i64
%576 = llvm.alloca %575 x i64 : (i64) -> !llvm.ptr
llvm.store %574, %576 : i64, !llvm.ptr
%577 = arith.constant 0 : i32
%578 = arith.constant 10 : i32
%579 = arith.index_cast %577 : i32 to index
%580 = arith.index_cast %578 : i32 to index
%582 = arith.constant 1 : index
%583 = arith.constant -1 : index
%584 = arith.cmpi sle, %579, %580 : index
%581 = arith.select %584, %582, %583 : index
cf.br ^bb102(%579 : index)
^bb102(%585: index):
%586 = arith.cmpi slt, %585, %580 : index
%587 = arith.cmpi sgt, %585, %580 : index
%588 = arith.select %584, %586, %587 : i1
cf.cond_br %588, ^bb103(%585 : index), ^bb104(%585 : index)
^bb103(%589: index):
%591 = llvm.load %566 : !llvm.ptr -> i64
%592 = llvm.getelementptr %229[%591] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%590 = llvm.load %592 : !llvm.ptr -> i64
%593 = arith.index_cast %589 : index to i64
%594 = llvm.getelementptr %232[%593] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %590, %594 : i64, !llvm.ptr
%595 = llvm.load %576 : !llvm.ptr -> i64
%596 = arith.addi %595, %590 : i64
llvm.store %596, %576 : i64, !llvm.ptr
%597 = llvm.load %566 : !llvm.ptr -> i64
%598 = arith.addi %597, %525 : i64
llvm.store %598, %566 : i64, !llvm.ptr
%599 = llvm.load %566 : !llvm.ptr -> i64
%600 = arith.cmpi sge, %599, %182 : i64
cf.cond_br %600, ^bb105, ^bb106
^bb105:
%601 = llvm.load %566 : !llvm.ptr -> i64
%602 = arith.subi %601, %182 : i64
llvm.store %602, %566 : i64, !llvm.ptr
cf.br ^bb107
^bb106:
cf.br ^bb107
^bb107:
%603 = arith.addi %589, %581 : index
cf.br ^bb102(%603 : index)
^bb104(%604: index):
%605 = arith.constant 0 : i32
%606 = arith.extsi %605 : i32 to i64
%607 = llvm.mlir.constant(1 : i64) : i64
%608 = llvm.alloca %607 x i64 : (i64) -> !llvm.ptr
llvm.store %606, %608 : i64, !llvm.ptr
%609 = arith.constant 0 : i32
%610 = arith.extsi %609 : i32 to i64
%611 = llvm.mlir.constant(1 : i64) : i64
%612 = llvm.alloca %611 x i64 : (i64) -> !llvm.ptr
llvm.store %610, %612 : i64, !llvm.ptr
%613 = arith.constant 0 : i32
%614 = arith.index_cast %613 : i32 to index
%615 = arith.index_cast %182 : i32 to index
%617 = arith.constant 1 : index
%618 = arith.constant -1 : index
%619 = arith.cmpi sle, %614, %615 : index
%616 = arith.select %619, %617, %618 : index
cf.br ^bb108(%614 : index)
^bb108(%620: index):
%621 = arith.cmpi slt, %620, %615 : index
%622 = arith.cmpi sgt, %620, %615 : index
%623 = arith.select %619, %621, %622 : i1
cf.cond_br %623, ^bb109(%620 : index), ^bb110(%620 : index)
^bb109(%624: index):
%626 = llvm.load %608 : !llvm.ptr -> i64
%627 = llvm.getelementptr %229[%626] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%625 = llvm.load %627 : !llvm.ptr -> i64
%629 = llvm.load %612 : !llvm.ptr -> i64
%630 = llvm.getelementptr %232[%629] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%628 = llvm.load %630 : !llvm.ptr -> i64
%631 = llvm.load %576 : !llvm.ptr -> i64
%632 = arith.addi %631, %625 : i64
%633 = arith.subi %632, %628 : i64
llvm.store %633, %576 : i64, !llvm.ptr
%634 = llvm.load %612 : !llvm.ptr -> i64
%635 = llvm.getelementptr %232[%634] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %625, %635 : i64, !llvm.ptr
%636 = llvm.load %612 : !llvm.ptr -> i64
%637 = arith.constant 1 : i32
%639 = arith.extsi %637 : i32 to i64
%638 = arith.addi %636, %639 : i64
llvm.store %638, %612 : i64, !llvm.ptr
%640 = llvm.load %612 : !llvm.ptr -> i64
%641 = arith.constant 10 : i32
%643 = arith.extsi %641 : i32 to i64
%642 = arith.cmpi eq, %640, %643 : i64
cf.cond_br %642, ^bb111, ^bb112
^bb111:
%644 = arith.constant 0 : i32
%645 = arith.extsi %644 : i32 to i64
llvm.store %645, %612 : i64, !llvm.ptr
cf.br ^bb113
^bb112:
cf.br ^bb113
^bb113:
%646 = llvm.load %576 : !llvm.ptr -> i64
%647 = llvm.load %608 : !llvm.ptr -> i64
%648 = llvm.getelementptr %226[%647] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %646, %648 : i64, !llvm.ptr
%649 = llvm.load %608 : !llvm.ptr -> i64
%650 = arith.addi %649, %525 : i64
llvm.store %650, %608 : i64, !llvm.ptr
%651 = llvm.load %608 : !llvm.ptr -> i64
%652 = arith.cmpi sge, %651, %182 : i64
cf.cond_br %652, ^bb114, ^bb115
^bb114:
%653 = llvm.load %608 : !llvm.ptr -> i64
%654 = arith.subi %653, %182 : i64
llvm.store %654, %608 : i64, !llvm.ptr
cf.br ^bb116
^bb115:
cf.br ^bb116
^bb116:
%655 = arith.addi %624, %616 : index
cf.br ^bb108(%655 : index)
^bb110(%656: index):
%657 = llvm.load %251 : !llvm.ptr -> i64
%659 = arith.constant 0 : i32
%660 = arith.extsi %659 : i32 to i64
%661 = llvm.getelementptr %226[%660] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%658 = llvm.load %661 : !llvm.ptr -> i64
%662 = arith.addi %657, %658 : i64
%663 = arith.subi %662, %526 : i64
llvm.store %663, %251 : i64, !llvm.ptr
llvm.store %515, %302 : i64, !llvm.ptr
cf.br ^bb90
^bb92:
%664 = llvm.mlir.addressof @str_0 : !llvm.ptr
%665 = llvm.load %251 : !llvm.ptr -> i64
%666 = llvm.call @printf(%664, %665) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%232) : (!llvm.ptr) -> ()
func.call @free(%229) : (!llvm.ptr) -> ()
func.call @free(%226) : (!llvm.ptr) -> ()
func.call @free(%183) : (!llvm.ptr) -> ()
%671 = arith.constant 0 : i32
func.return %671 : i32
}
}