Problem 284
Base-14 digit-sum of steady squares with <= 10000 digits.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n) | O(n * d) |
| Space complexity | O(n^2) | O(d) |
| Approach | Flow solution | Digit DP in base b |
| Verdict | Unknown |
Flow source
# Project Euler 284
# Base-14 digit-sum of steady squares with <= 10000 digits.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
# Little-endian base-10^9 limbs for value/quotient; track length in base14 digits separately.
# Simpler: store value and quotient as base-14 digit arrays.
function dig_add_into(a: ptr<i64>, alen: i64, b: ptr<i64>, blen: i64) -> i64 {
let BASE: i64 = 14
let mut carry: i64 = 0
let mut i: i64 = 0
let n: i64 = alen
if blen > n { n = blen }
while i < n || carry != 0 {
let mut s: i64 = carry
if i < alen { s = s + a[i] }
if i < blen { s = s + b[i] }
a[i] = s % BASE
carry = s / BASE
i = i + 1
}
return i
}
function dig_mul_small(a: ptr<i64>, alen: i64, m: i64, out: ptr<i64>) -> i64 {
let BASE: i64 = 14
let mut carry: i64 = 0
let mut i: i64 = 0
while i < alen || carry != 0 {
let mut s: i64 = carry
if i < alen { s = s + a[i] * m }
out[i] = s % BASE
carry = s / BASE
i = i + 1
}
return i
}
function dig_copy(src: ptr<i64>, n: i64, dst: ptr<i64>) -> void {
let mut i: i64 = 0
while i < n {
dst[i] = src[i]
i = i + 1
}
}
function dig_div_base(a: ptr<i64>, alen: i64) -> i64 {
# divide by BASE=14: shift down one digit
let mut i: i64 = 0
while i + 1 < alen {
a[i] = a[i + 1]
i = i + 1
}
if alen > 0 {
a[alen - 1] = 0
return alen - 1
}
return 0
}
function main() -> i32 {
let BASE: i64 = 14
let max_digits: i64 = 10000
let CAP: i64 = max_digits + 8
let inv: ptr<i64> = calloc(14, 8)
inv[1]=1; inv[3]=5; inv[5]=3; inv[9]=11; inv[11]=9; inv[13]=13
let v0: ptr<i64> = calloc(CAP, 8)
let v1: ptr<i64> = calloc(CAP, 8)
let q0: ptr<i64> = calloc(CAP, 8)
let q1: ptr<i64> = calloc(CAP, 8)
let tmp: ptr<i64> = calloc(CAP + 4, 8)
let tmp2: ptr<i64> = calloc(CAP + 4, 8)
if v0 == null || v1 == null || q0 == null || q1 == null { return 1 }
v0[0] = 7; v1[0] = 8
q0[0] = 3; q1[0] = 4
let mut vlen0: i64 = 1
let mut vlen1: i64 = 1
let mut qlen0: i64 = 1
let mut qlen1: i64 = 1
let mut ds0: i64 = 7
let mut ds1: i64 = 8
let mut lead0: i64 = 7
let mut lead1: i64 = 8
let mut total: i64 = 1
let mut length: i64 = 1
while length <= max_digits {
if lead0 != 0 { total = total + ds0 }
if lead1 != 0 { total = total + ds1 }
if length == max_digits { break }
# lift 0
let coef0: i64 = (2 * v0[0] - 1) % BASE
if coef0 < 0 { coef0 = coef0 + BASE }
let mut ld0: i64 = ((-(q0[0] % BASE)) * inv[coef0]) % BASE
if ld0 < 0 { ld0 = ld0 + BASE }
# next_quotient = (q + (2v-1)*ld + ld*ld * 14^{len}) / 14
# Build (2v-1)*ld into tmp
let mut tlen: i64 = dig_mul_small(v0, vlen0, 2, tmp)
# subtract 1
let mut i: i64 = 0
tmp[0] = tmp[0] - 1
while tmp[i] < 0 {
tmp[i] = tmp[i] + BASE
i = i + 1
tmp[i] = tmp[i] - 1
}
tlen = dig_mul_small(tmp, tlen, ld0, tmp2)
# tmp2 = (2v-1)*ld; add q0
dig_copy(q0, qlen0, tmp)
let mut alen: i64 = qlen0
# zero rest of tmp
i = alen
while i < CAP + 4 { tmp[i] = 0; i = i + 1 }
alen = dig_add_into(tmp, alen, tmp2, tlen)
# add ld*ld at position length (i.e. * 14^length)
let addv: i64 = ld0 * ld0
let mut pos: i64 = length
let mut carry: i64 = addv
while carry != 0 {
let s: i64 = tmp[pos] + carry
tmp[pos] = s % BASE
carry = s / BASE
pos = pos + 1
if pos > alen { alen = pos }
}
# divide by BASE
qlen0 = dig_div_base(tmp, alen)
dig_copy(tmp, qlen0, q0)
if qlen0 == 0 { q0[0] = 0; qlen0 = 1 }
# next value: append ld0
v0[vlen0] = ld0
vlen0 = vlen0 + 1
lead0 = ld0
ds0 = ds0 + ld0
# lift 1 (same)
let coef1: i64 = (2 * v1[0] - 1) % BASE
if coef1 < 0 { coef1 = coef1 + BASE }
let mut ld1: i64 = ((-(q1[0] % BASE)) * inv[coef1]) % BASE
if ld1 < 0 { ld1 = ld1 + BASE }
tlen = dig_mul_small(v1, vlen1, 2, tmp)
tmp[0] = tmp[0] - 1
i = 0
while tmp[i] < 0 {
tmp[i] = tmp[i] + BASE
i = i + 1
tmp[i] = tmp[i] - 1
}
tlen = dig_mul_small(tmp, tlen, ld1, tmp2)
dig_copy(q1, qlen1, tmp)
alen = qlen1
i = alen
while i < CAP + 4 { tmp[i] = 0; i = i + 1 }
alen = dig_add_into(tmp, alen, tmp2, tlen)
let addv1: i64 = ld1 * ld1
pos = length
carry = addv1
while carry != 0 {
let s2: i64 = tmp[pos] + carry
tmp[pos] = s2 % BASE
carry = s2 / BASE
pos = pos + 1
if pos > alen { alen = pos }
}
qlen1 = dig_div_base(tmp, alen)
dig_copy(tmp, qlen1, q1)
if qlen1 == 0 { q1[0] = 0; qlen1 = 1 }
v1[vlen1] = ld1
vlen1 = vlen1 + 1
lead1 = ld1
ds1 = ds1 + ld1
length = length + 1
}
# print total in base 14
if total == 0 {
printf("0\n")
} else {
let digs: ptr<i64> = calloc(64, 8)
let mut nd: i64 = 0
let mut x: i64 = total
while x > 0 {
digs[nd] = x % BASE
x = x / BASE
nd = nd + 1
}
let mut j: i64 = nd - 1
while j >= 0 {
let d: i64 = digs[j]
if d < 10 {
printf("%c", (48 + d) as i32)
} else {
printf("%c", (87 + d) as i32) # a=97=87+10
}
j = j - 1
}
printf("\n")
free(digs)
}
free(v0); free(v1); free(q0); free(q1); free(tmp); free(tmp2); free(inv)
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 dig_add_into_ptr_i64_i64_ptr_i64_i64(int64_t* a, int64_t alen, int64_t* b, int64_t blen);
int64_t dig_mul_small_ptr_i64_i64_i64_ptr_i64(int64_t* a, int64_t alen, int64_t m, int64_t* out);
void dig_copy_ptr_i64_i64_ptr_i64(int64_t* src, int64_t n, int64_t* dst);
int64_t dig_div_base_ptr_i64_i64(int64_t* a, int64_t alen);
int32_t main(void);
int64_t dig_add_into_ptr_i64_i64_ptr_i64_i64(int64_t* a, int64_t alen, int64_t* b, int64_t blen) {
int64_t BASE = 14;
int64_t carry = 0;
int64_t i = 0;
int64_t n = alen;
if (blen > n) {
n = blen;
}
while ((i < n || carry != 0)) {
int64_t s = carry;
if (i < alen) {
s = (s + a[i]);
}
if (i < blen) {
s = (s + b[i]);
}
a[i] = FLOW_CHECKED_MOD((s), (BASE));
carry = FLOW_CHECKED_DIV((s), (BASE));
i = (i + 1);
}
return i;
}
int64_t dig_mul_small_ptr_i64_i64_i64_ptr_i64(int64_t* a, int64_t alen, int64_t m, int64_t* out) {
int64_t BASE = 14;
int64_t carry = 0;
int64_t i = 0;
while ((i < alen || carry != 0)) {
int64_t s = carry;
if (i < alen) {
s = (s + (a[i] * m));
}
out[i] = FLOW_CHECKED_MOD((s), (BASE));
carry = FLOW_CHECKED_DIV((s), (BASE));
i = (i + 1);
}
return i;
}
void dig_copy_ptr_i64_i64_ptr_i64(int64_t* src, int64_t n, int64_t* dst) {
int64_t i = 0;
while (i < n) {
dst[i] = src[i];
i = (i + 1);
}
}
int64_t dig_div_base_ptr_i64_i64(int64_t* a, int64_t alen) {
int64_t i = 0;
while ((i + 1) < alen) {
a[i] = a[(i + 1)];
i = (i + 1);
}
if (alen > 0) {
a[(alen - 1)] = 0;
return (alen - 1);
}
return 0;
}
int32_t main(void) {
int64_t BASE = 14;
int64_t max_digits = 10000;
int64_t CAP = (max_digits + 8);
int64_t* inv = (int64_t*)(calloc(14, 8));
inv[1] = 1;
inv[3] = 5;
inv[5] = 3;
inv[9] = 11;
inv[11] = 9;
inv[13] = 13;
int64_t* v0 = (int64_t*)(calloc(CAP, 8));
int64_t* v1 = (int64_t*)(calloc(CAP, 8));
int64_t* q0 = (int64_t*)(calloc(CAP, 8));
int64_t* q1 = (int64_t*)(calloc(CAP, 8));
int64_t* tmp = (int64_t*)(calloc((CAP + 4), 8));
int64_t* tmp2 = (int64_t*)(calloc((CAP + 4), 8));
if ((((v0 == NULL || v1 == NULL) || q0 == NULL) || q1 == NULL)) {
return 1;
}
v0[0] = 7;
v1[0] = 8;
q0[0] = 3;
q1[0] = 4;
int64_t vlen0 = 1;
int64_t vlen1 = 1;
int64_t qlen0 = 1;
int64_t qlen1 = 1;
int64_t ds0 = 7;
int64_t ds1 = 8;
int64_t lead0 = 7;
int64_t lead1 = 8;
int64_t total = 1;
int64_t length = 1;
while (length <= max_digits) {
if (lead0 != 0) {
total = (total + ds0);
}
if (lead1 != 0) {
total = (total + ds1);
}
if (length == max_digits) {
break;
}
int64_t coef0 = FLOW_CHECKED_MOD((((2 * v0[0]) - 1)), (BASE));
if (coef0 < 0) {
coef0 = (coef0 + BASE);
}
int64_t ld0 = FLOW_CHECKED_MOD((((-FLOW_CHECKED_MOD((q0[0]), (BASE))) * inv[coef0])), (BASE));
if (ld0 < 0) {
ld0 = (ld0 + BASE);
}
int64_t tlen = dig_mul_small_ptr_i64_i64_i64_ptr_i64(v0, vlen0, 2, tmp);
int64_t i = 0;
tmp[0] = (tmp[0] - 1);
while (tmp[i] < 0) {
tmp[i] = (tmp[i] + BASE);
i = (i + 1);
tmp[i] = (tmp[i] - 1);
}
tlen = dig_mul_small_ptr_i64_i64_i64_ptr_i64(tmp, tlen, ld0, tmp2);
dig_copy_ptr_i64_i64_ptr_i64(q0, qlen0, tmp);
int64_t alen = qlen0;
i = alen;
while (i < (CAP + 4)) {
tmp[i] = 0;
i = (i + 1);
}
alen = dig_add_into_ptr_i64_i64_ptr_i64_i64(tmp, alen, tmp2, tlen);
int64_t addv = (ld0 * ld0);
int64_t pos = length;
int64_t carry = addv;
while (carry != 0) {
int64_t s = (tmp[pos] + carry);
tmp[pos] = FLOW_CHECKED_MOD((s), (BASE));
carry = FLOW_CHECKED_DIV((s), (BASE));
pos = (pos + 1);
if (pos > alen) {
alen = pos;
}
}
qlen0 = dig_div_base_ptr_i64_i64(tmp, alen);
dig_copy_ptr_i64_i64_ptr_i64(tmp, qlen0, q0);
if (qlen0 == 0) {
q0[0] = 0;
qlen0 = 1;
}
v0[vlen0] = ld0;
vlen0 = (vlen0 + 1);
lead0 = ld0;
ds0 = (ds0 + ld0);
int64_t coef1 = FLOW_CHECKED_MOD((((2 * v1[0]) - 1)), (BASE));
if (coef1 < 0) {
coef1 = (coef1 + BASE);
}
int64_t ld1 = FLOW_CHECKED_MOD((((-FLOW_CHECKED_MOD((q1[0]), (BASE))) * inv[coef1])), (BASE));
if (ld1 < 0) {
ld1 = (ld1 + BASE);
}
tlen = dig_mul_small_ptr_i64_i64_i64_ptr_i64(v1, vlen1, 2, tmp);
tmp[0] = (tmp[0] - 1);
i = 0;
while (tmp[i] < 0) {
tmp[i] = (tmp[i] + BASE);
i = (i + 1);
tmp[i] = (tmp[i] - 1);
}
tlen = dig_mul_small_ptr_i64_i64_i64_ptr_i64(tmp, tlen, ld1, tmp2);
dig_copy_ptr_i64_i64_ptr_i64(q1, qlen1, tmp);
alen = qlen1;
i = alen;
while (i < (CAP + 4)) {
tmp[i] = 0;
i = (i + 1);
}
alen = dig_add_into_ptr_i64_i64_ptr_i64_i64(tmp, alen, tmp2, tlen);
int64_t addv1 = (ld1 * ld1);
pos = length;
carry = addv1;
while (carry != 0) {
int64_t s2 = (tmp[pos] + carry);
tmp[pos] = FLOW_CHECKED_MOD((s2), (BASE));
carry = FLOW_CHECKED_DIV((s2), (BASE));
pos = (pos + 1);
if (pos > alen) {
alen = pos;
}
}
qlen1 = dig_div_base_ptr_i64_i64(tmp, alen);
dig_copy_ptr_i64_i64_ptr_i64(tmp, qlen1, q1);
if (qlen1 == 0) {
q1[0] = 0;
qlen1 = 1;
}
v1[vlen1] = ld1;
vlen1 = (vlen1 + 1);
lead1 = ld1;
ds1 = (ds1 + ld1);
length = (length + 1);
}
if (total == 0) {
printf("0\n");
} else {
int64_t* digs = (int64_t*)(calloc(64, 8));
int64_t nd = 0;
int64_t x = total;
while (x > 0) {
digs[nd] = FLOW_CHECKED_MOD((x), (BASE));
x = FLOW_CHECKED_DIV((x), (BASE));
nd = (nd + 1);
}
int64_t j = (nd - 1);
while (j >= 0) {
int64_t d = digs[j];
if (d < 10) {
printf("%c", ((int32_t)((48 + d))));
} else {
printf("%c", ((int32_t)((87 + d))));
}
j = (j - 1);
}
printf("\n");
free(digs);
}
free(v0);
free(v1);
free(q0);
free(q1);
free(tmp);
free(tmp2);
free(inv);
return 0;
}
Generated MLIR
module {
llvm.func @printf(!llvm.ptr, ...) -> i32
llvm.mlir.global internal constant @str_0("0\n\00") {addr_space = 0 : i32} : !llvm.array<3 x i8>
llvm.mlir.global internal constant @str_1("%c\00") {addr_space = 0 : i32} : !llvm.array<3 x i8>
llvm.mlir.global internal constant @str_2("\n\00") {addr_space = 0 : i32} : !llvm.array<2 x i8>
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
func.func @dig_add_into(%arg0: !llvm.ptr, %arg1: i64, %arg2: !llvm.ptr, %arg3: i64) -> i64 {
%0 = arith.constant 14 : i32
%1 = arith.extsi %0 : i32 to i64
%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
%6 = arith.constant 0 : i32
%7 = arith.extsi %6 : i32 to i64
%8 = llvm.mlir.constant(1 : i64) : i64
%9 = llvm.alloca %8 x i64 : (i64) -> !llvm.ptr
llvm.store %7, %9 : i64, !llvm.ptr
%10 = arith.cmpi sgt, %arg3, %arg1 : i64
%11 = scf.if %10 -> (i64) {
scf.yield %arg3 : i64
} else {
scf.yield %arg1 : i64
}
cf.br ^bb0
^bb0:
%12 = llvm.load %9 : !llvm.ptr -> i64
%13 = arith.cmpi slt, %12, %11 : i64
%14 = scf.if %13 -> (i1) {
%15 = arith.constant true
scf.yield %15 : i1
} else {
%16 = llvm.load %5 : !llvm.ptr -> i64
%17 = arith.constant 0 : i32
%19 = arith.extsi %17 : i32 to i64
%18 = arith.cmpi ne, %16, %19 : i64
scf.yield %18 : i1
}
cf.cond_br %14, ^bb1, ^bb2
^bb1:
%20 = llvm.load %5 : !llvm.ptr -> i64
%21 = llvm.mlir.constant(1 : i64) : i64
%22 = llvm.alloca %21 x i64 : (i64) -> !llvm.ptr
llvm.store %20, %22 : i64, !llvm.ptr
%23 = llvm.load %9 : !llvm.ptr -> i64
%24 = arith.cmpi slt, %23, %arg1 : i64
cf.cond_br %24, ^bb3, ^bb4
^bb3:
%25 = llvm.load %22 : !llvm.ptr -> i64
%27 = llvm.load %9 : !llvm.ptr -> i64
%28 = llvm.getelementptr %arg0[%27] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%26 = llvm.load %28 : !llvm.ptr -> i64
%29 = arith.addi %25, %26 : i64
llvm.store %29, %22 : i64, !llvm.ptr
cf.br ^bb5
^bb4:
cf.br ^bb5
^bb5:
%30 = llvm.load %9 : !llvm.ptr -> i64
%31 = arith.cmpi slt, %30, %arg3 : i64
cf.cond_br %31, ^bb6, ^bb7
^bb6:
%32 = llvm.load %22 : !llvm.ptr -> i64
%34 = llvm.load %9 : !llvm.ptr -> i64
%35 = llvm.getelementptr %arg2[%34] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%33 = llvm.load %35 : !llvm.ptr -> i64
%36 = arith.addi %32, %33 : i64
llvm.store %36, %22 : i64, !llvm.ptr
cf.br ^bb8
^bb7:
cf.br ^bb8
^bb8:
%37 = llvm.load %22 : !llvm.ptr -> i64
%38 = arith.remsi %37, %1 : i64
%39 = llvm.load %9 : !llvm.ptr -> i64
%40 = llvm.getelementptr %arg0[%39] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %38, %40 : i64, !llvm.ptr
%41 = llvm.load %22 : !llvm.ptr -> i64
%42 = arith.divsi %41, %1 : i64
llvm.store %42, %5 : i64, !llvm.ptr
%43 = llvm.load %9 : !llvm.ptr -> i64
%44 = arith.constant 1 : i32
%46 = arith.extsi %44 : i32 to i64
%45 = arith.addi %43, %46 : i64
llvm.store %45, %9 : i64, !llvm.ptr
cf.br ^bb0
^bb2:
%47 = llvm.load %9 : !llvm.ptr -> i64
func.return %47 : i64
}
func.func @dig_mul_small(%arg0: !llvm.ptr, %arg1: i64, %arg2: i64, %arg3: !llvm.ptr) -> i64 {
%48 = arith.constant 14 : i32
%49 = arith.extsi %48 : i32 to i64
%50 = arith.constant 0 : i32
%51 = arith.extsi %50 : i32 to i64
%52 = llvm.mlir.constant(1 : i64) : i64
%53 = llvm.alloca %52 x i64 : (i64) -> !llvm.ptr
llvm.store %51, %53 : i64, !llvm.ptr
%54 = arith.constant 0 : i32
%55 = arith.extsi %54 : i32 to i64
%56 = llvm.mlir.constant(1 : i64) : i64
%57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
llvm.store %55, %57 : i64, !llvm.ptr
cf.br ^bb9
^bb9:
%58 = llvm.load %57 : !llvm.ptr -> i64
%59 = arith.cmpi slt, %58, %arg1 : i64
%60 = scf.if %59 -> (i1) {
%61 = arith.constant true
scf.yield %61 : i1
} else {
%62 = llvm.load %53 : !llvm.ptr -> i64
%63 = arith.constant 0 : i32
%65 = arith.extsi %63 : i32 to i64
%64 = arith.cmpi ne, %62, %65 : i64
scf.yield %64 : i1
}
cf.cond_br %60, ^bb10, ^bb11
^bb10:
%66 = llvm.load %53 : !llvm.ptr -> i64
%67 = llvm.mlir.constant(1 : i64) : i64
%68 = llvm.alloca %67 x i64 : (i64) -> !llvm.ptr
llvm.store %66, %68 : i64, !llvm.ptr
%69 = llvm.load %57 : !llvm.ptr -> i64
%70 = arith.cmpi slt, %69, %arg1 : i64
cf.cond_br %70, ^bb12, ^bb13
^bb12:
%71 = llvm.load %68 : !llvm.ptr -> i64
%73 = llvm.load %57 : !llvm.ptr -> i64
%74 = llvm.getelementptr %arg0[%73] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%72 = llvm.load %74 : !llvm.ptr -> i64
%75 = arith.muli %72, %arg2 : i64
%76 = arith.addi %71, %75 : i64
llvm.store %76, %68 : i64, !llvm.ptr
cf.br ^bb14
^bb13:
cf.br ^bb14
^bb14:
%77 = llvm.load %68 : !llvm.ptr -> i64
%78 = arith.remsi %77, %49 : i64
%79 = llvm.load %57 : !llvm.ptr -> i64
%80 = llvm.getelementptr %arg3[%79] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %78, %80 : i64, !llvm.ptr
%81 = llvm.load %68 : !llvm.ptr -> i64
%82 = arith.divsi %81, %49 : i64
llvm.store %82, %53 : i64, !llvm.ptr
%83 = llvm.load %57 : !llvm.ptr -> i64
%84 = arith.constant 1 : i32
%86 = arith.extsi %84 : i32 to i64
%85 = arith.addi %83, %86 : i64
llvm.store %85, %57 : i64, !llvm.ptr
cf.br ^bb9
^bb11:
%87 = llvm.load %57 : !llvm.ptr -> i64
func.return %87 : i64
}
func.func @dig_copy(%arg0: !llvm.ptr, %arg1: i64, %arg2: !llvm.ptr) -> () {
%88 = arith.constant 0 : i32
%89 = arith.extsi %88 : i32 to i64
%90 = llvm.mlir.constant(1 : i64) : i64
%91 = llvm.alloca %90 x i64 : (i64) -> !llvm.ptr
llvm.store %89, %91 : i64, !llvm.ptr
cf.br ^bb15
^bb15:
%92 = llvm.load %91 : !llvm.ptr -> i64
%93 = arith.cmpi slt, %92, %arg1 : i64
cf.cond_br %93, ^bb16, ^bb17
^bb16:
%95 = llvm.load %91 : !llvm.ptr -> i64
%96 = llvm.getelementptr %arg0[%95] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%94 = llvm.load %96 : !llvm.ptr -> i64
%97 = llvm.load %91 : !llvm.ptr -> i64
%98 = llvm.getelementptr %arg2[%97] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %94, %98 : i64, !llvm.ptr
%99 = llvm.load %91 : !llvm.ptr -> i64
%100 = arith.constant 1 : i32
%102 = arith.extsi %100 : i32 to i64
%101 = arith.addi %99, %102 : i64
llvm.store %101, %91 : i64, !llvm.ptr
cf.br ^bb15
^bb17:
func.return
}
func.func @dig_div_base(%arg0: !llvm.ptr, %arg1: i64) -> i64 {
%103 = arith.constant 0 : i32
%104 = arith.extsi %103 : i32 to i64
%105 = llvm.mlir.constant(1 : i64) : i64
%106 = llvm.alloca %105 x i64 : (i64) -> !llvm.ptr
llvm.store %104, %106 : i64, !llvm.ptr
cf.br ^bb18
^bb18:
%107 = llvm.load %106 : !llvm.ptr -> i64
%108 = arith.constant 1 : i32
%110 = arith.extsi %108 : i32 to i64
%109 = arith.addi %107, %110 : i64
%111 = arith.cmpi slt, %109, %arg1 : i64
cf.cond_br %111, ^bb19, ^bb20
^bb19:
%113 = llvm.load %106 : !llvm.ptr -> i64
%114 = arith.constant 1 : i32
%116 = arith.extsi %114 : i32 to i64
%115 = arith.addi %113, %116 : i64
%117 = llvm.getelementptr %arg0[%115] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%112 = llvm.load %117 : !llvm.ptr -> i64
%118 = llvm.load %106 : !llvm.ptr -> i64
%119 = llvm.getelementptr %arg0[%118] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %112, %119 : i64, !llvm.ptr
%120 = llvm.load %106 : !llvm.ptr -> i64
%121 = arith.constant 1 : i32
%123 = arith.extsi %121 : i32 to i64
%122 = arith.addi %120, %123 : i64
llvm.store %122, %106 : i64, !llvm.ptr
cf.br ^bb18
^bb20:
%124 = arith.constant 0 : i32
%126 = arith.extsi %124 : i32 to i64
%125 = arith.cmpi sgt, %arg1, %126 : i64
cf.cond_br %125, ^bb21, ^bb22
^bb21:
%127 = arith.constant 0 : i32
%128 = arith.constant 1 : i32
%130 = arith.extsi %128 : i32 to i64
%129 = arith.subi %arg1, %130 : i64
%131 = arith.extsi %127 : i32 to i64
%132 = llvm.getelementptr %arg0[%129] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %131, %132 : i64, !llvm.ptr
%133 = arith.constant 1 : i32
%135 = arith.extsi %133 : i32 to i64
%134 = arith.subi %arg1, %135 : i64
func.return %134 : i64
^bb22:
cf.br ^bb23
^bb23:
%136 = arith.constant 0 : i32
%137 = arith.extsi %136 : i32 to i64
func.return %137 : i64
}
func.func @main() -> i32 {
%138 = arith.constant 14 : i32
%139 = arith.extsi %138 : i32 to i64
%140 = arith.constant 10000 : i32
%141 = arith.extsi %140 : i32 to i64
%142 = arith.constant 8 : i32
%144 = arith.extsi %142 : i32 to i64
%143 = arith.addi %141, %144 : i64
%146 = arith.constant 14 : i32
%147 = arith.constant 8 : i32
%148 = arith.extsi %146 : i32 to i64
%149 = arith.extsi %147 : i32 to i64
%145 = func.call @calloc(%148, %149) : (i64, i64) -> !llvm.ptr
%150 = arith.constant 1 : i32
%151 = arith.constant 1 : i32
%152 = arith.extsi %150 : i32 to i64
%153 = arith.extsi %151 : i32 to i64
%154 = llvm.getelementptr %145[%153] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %152, %154 : i64, !llvm.ptr
%155 = arith.constant 5 : i32
%156 = arith.constant 3 : i32
%157 = arith.extsi %155 : i32 to i64
%158 = arith.extsi %156 : i32 to i64
%159 = llvm.getelementptr %145[%158] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %157, %159 : i64, !llvm.ptr
%160 = arith.constant 3 : i32
%161 = arith.constant 5 : i32
%162 = arith.extsi %160 : i32 to i64
%163 = arith.extsi %161 : i32 to i64
%164 = llvm.getelementptr %145[%163] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %162, %164 : i64, !llvm.ptr
%165 = arith.constant 11 : i32
%166 = arith.constant 9 : i32
%167 = arith.extsi %165 : i32 to i64
%168 = arith.extsi %166 : i32 to i64
%169 = llvm.getelementptr %145[%168] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %167, %169 : i64, !llvm.ptr
%170 = arith.constant 9 : i32
%171 = arith.constant 11 : i32
%172 = arith.extsi %170 : i32 to i64
%173 = arith.extsi %171 : i32 to i64
%174 = llvm.getelementptr %145[%173] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %172, %174 : i64, !llvm.ptr
%175 = arith.constant 13 : i32
%176 = arith.constant 13 : i32
%177 = arith.extsi %175 : i32 to i64
%178 = arith.extsi %176 : i32 to i64
%179 = llvm.getelementptr %145[%178] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %177, %179 : i64, !llvm.ptr
%181 = arith.constant 8 : i32
%182 = arith.extsi %181 : i32 to i64
%180 = func.call @calloc(%143, %182) : (i64, i64) -> !llvm.ptr
%184 = arith.constant 8 : i32
%185 = arith.extsi %184 : i32 to i64
%183 = func.call @calloc(%143, %185) : (i64, i64) -> !llvm.ptr
%187 = arith.constant 8 : i32
%188 = arith.extsi %187 : i32 to i64
%186 = func.call @calloc(%143, %188) : (i64, i64) -> !llvm.ptr
%190 = arith.constant 8 : i32
%191 = arith.extsi %190 : i32 to i64
%189 = func.call @calloc(%143, %191) : (i64, i64) -> !llvm.ptr
%193 = arith.constant 4 : i32
%195 = arith.extsi %193 : i32 to i64
%194 = arith.addi %143, %195 : i64
%196 = arith.constant 8 : i32
%197 = arith.extsi %196 : i32 to i64
%192 = func.call @calloc(%194, %197) : (i64, i64) -> !llvm.ptr
%199 = arith.constant 4 : i32
%201 = arith.extsi %199 : i32 to i64
%200 = arith.addi %143, %201 : i64
%202 = arith.constant 8 : i32
%203 = arith.extsi %202 : i32 to i64
%198 = func.call @calloc(%200, %203) : (i64, i64) -> !llvm.ptr
%204 = llvm.mlir.zero : !llvm.ptr
%205 = llvm.icmp "eq" %180, %204 : !llvm.ptr
%206 = scf.if %205 -> (i1) {
%207 = arith.constant true
scf.yield %207 : i1
} else {
%208 = llvm.mlir.zero : !llvm.ptr
%209 = llvm.icmp "eq" %183, %208 : !llvm.ptr
scf.yield %209 : i1
}
%210 = scf.if %206 -> (i1) {
%211 = arith.constant true
scf.yield %211 : i1
} else {
%212 = llvm.mlir.zero : !llvm.ptr
%213 = llvm.icmp "eq" %186, %212 : !llvm.ptr
scf.yield %213 : i1
}
%214 = scf.if %210 -> (i1) {
%215 = arith.constant true
scf.yield %215 : i1
} else {
%216 = llvm.mlir.zero : !llvm.ptr
%217 = llvm.icmp "eq" %189, %216 : !llvm.ptr
scf.yield %217 : i1
}
cf.cond_br %214, ^bb24, ^bb25
^bb24:
%218 = arith.constant 1 : i32
func.return %218 : i32
^bb25:
cf.br ^bb26
^bb26:
%219 = arith.constant 7 : i32
%220 = arith.constant 0 : i32
%221 = arith.extsi %219 : i32 to i64
%222 = arith.extsi %220 : i32 to i64
%223 = llvm.getelementptr %180[%222] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %221, %223 : i64, !llvm.ptr
%224 = arith.constant 8 : i32
%225 = arith.constant 0 : i32
%226 = arith.extsi %224 : i32 to i64
%227 = arith.extsi %225 : i32 to i64
%228 = llvm.getelementptr %183[%227] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %226, %228 : i64, !llvm.ptr
%229 = arith.constant 3 : i32
%230 = arith.constant 0 : i32
%231 = arith.extsi %229 : i32 to i64
%232 = arith.extsi %230 : i32 to i64
%233 = llvm.getelementptr %186[%232] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %231, %233 : i64, !llvm.ptr
%234 = arith.constant 4 : i32
%235 = arith.constant 0 : i32
%236 = arith.extsi %234 : i32 to i64
%237 = arith.extsi %235 : i32 to i64
%238 = llvm.getelementptr %189[%237] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %236, %238 : i64, !llvm.ptr
%239 = arith.constant 1 : i32
%240 = arith.extsi %239 : i32 to i64
%241 = llvm.mlir.constant(1 : i64) : i64
%242 = llvm.alloca %241 x i64 : (i64) -> !llvm.ptr
llvm.store %240, %242 : i64, !llvm.ptr
%243 = arith.constant 1 : i32
%244 = arith.extsi %243 : i32 to i64
%245 = llvm.mlir.constant(1 : i64) : i64
%246 = llvm.alloca %245 x i64 : (i64) -> !llvm.ptr
llvm.store %244, %246 : i64, !llvm.ptr
%247 = arith.constant 1 : i32
%248 = arith.extsi %247 : i32 to i64
%249 = llvm.mlir.constant(1 : i64) : i64
%250 = llvm.alloca %249 x i64 : (i64) -> !llvm.ptr
llvm.store %248, %250 : i64, !llvm.ptr
%251 = arith.constant 1 : i32
%252 = arith.extsi %251 : i32 to i64
%253 = llvm.mlir.constant(1 : i64) : i64
%254 = llvm.alloca %253 x i64 : (i64) -> !llvm.ptr
llvm.store %252, %254 : i64, !llvm.ptr
%255 = arith.constant 7 : i32
%256 = arith.extsi %255 : i32 to i64
%257 = llvm.mlir.constant(1 : i64) : i64
%258 = llvm.alloca %257 x i64 : (i64) -> !llvm.ptr
llvm.store %256, %258 : i64, !llvm.ptr
%259 = arith.constant 8 : i32
%260 = arith.extsi %259 : i32 to i64
%261 = llvm.mlir.constant(1 : i64) : i64
%262 = llvm.alloca %261 x i64 : (i64) -> !llvm.ptr
llvm.store %260, %262 : i64, !llvm.ptr
%263 = arith.constant 7 : i32
%264 = arith.extsi %263 : i32 to i64
%265 = llvm.mlir.constant(1 : i64) : i64
%266 = llvm.alloca %265 x i64 : (i64) -> !llvm.ptr
llvm.store %264, %266 : i64, !llvm.ptr
%267 = arith.constant 8 : i32
%268 = arith.extsi %267 : i32 to i64
%269 = llvm.mlir.constant(1 : i64) : i64
%270 = llvm.alloca %269 x i64 : (i64) -> !llvm.ptr
llvm.store %268, %270 : i64, !llvm.ptr
%271 = arith.constant 1 : i32
%272 = arith.extsi %271 : i32 to i64
%273 = llvm.mlir.constant(1 : i64) : i64
%274 = llvm.alloca %273 x i64 : (i64) -> !llvm.ptr
llvm.store %272, %274 : i64, !llvm.ptr
%275 = arith.constant 1 : i32
%276 = arith.extsi %275 : i32 to i64
%277 = llvm.mlir.constant(1 : i64) : i64
%278 = llvm.alloca %277 x i64 : (i64) -> !llvm.ptr
llvm.store %276, %278 : i64, !llvm.ptr
cf.br ^bb27
^bb27:
%279 = llvm.load %278 : !llvm.ptr -> i64
%280 = arith.cmpi sle, %279, %141 : i64
cf.cond_br %280, ^bb28, ^bb29
^bb28:
%281 = llvm.load %266 : !llvm.ptr -> i64
%282 = arith.constant 0 : i32
%284 = arith.extsi %282 : i32 to i64
%283 = arith.cmpi ne, %281, %284 : i64
cf.cond_br %283, ^bb30, ^bb31
^bb30:
%285 = llvm.load %274 : !llvm.ptr -> i64
%286 = llvm.load %258 : !llvm.ptr -> i64
%287 = arith.addi %285, %286 : i64
llvm.store %287, %274 : i64, !llvm.ptr
cf.br ^bb32
^bb31:
cf.br ^bb32
^bb32:
%288 = llvm.load %270 : !llvm.ptr -> i64
%289 = arith.constant 0 : i32
%291 = arith.extsi %289 : i32 to i64
%290 = arith.cmpi ne, %288, %291 : i64
cf.cond_br %290, ^bb33, ^bb34
^bb33:
%292 = llvm.load %274 : !llvm.ptr -> i64
%293 = llvm.load %262 : !llvm.ptr -> i64
%294 = arith.addi %292, %293 : i64
llvm.store %294, %274 : i64, !llvm.ptr
cf.br ^bb35
^bb34:
cf.br ^bb35
^bb35:
%295 = llvm.load %278 : !llvm.ptr -> i64
%296 = arith.cmpi eq, %295, %141 : i64
cf.cond_br %296, ^bb36, ^bb37
^bb36:
cf.br ^bb29
^bb37:
cf.br ^bb38
^bb38:
%297 = arith.constant 2 : i32
%299 = arith.constant 0 : i32
%300 = arith.extsi %299 : i32 to i64
%301 = llvm.getelementptr %180[%300] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%298 = llvm.load %301 : !llvm.ptr -> i64
%303 = arith.extsi %297 : i32 to i64
%302 = arith.muli %303, %298 : i64
%304 = arith.constant 1 : i32
%306 = arith.extsi %304 : i32 to i64
%305 = arith.subi %302, %306 : i64
%307 = arith.remsi %305, %139 : i64
%308 = arith.constant 0 : i32
%310 = arith.extsi %308 : i32 to i64
%309 = arith.cmpi slt, %307, %310 : i64
%311 = scf.if %309 -> (i64) {
%312 = arith.addi %307, %139 : i64
scf.yield %312 : i64
} else {
scf.yield %307 : i64
}
%314 = arith.constant 0 : i32
%315 = arith.extsi %314 : i32 to i64
%316 = llvm.getelementptr %186[%315] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%313 = llvm.load %316 : !llvm.ptr -> i64
%317 = arith.remsi %313, %139 : i64
%319 = arith.constant 0 : i64
%318 = arith.subi %319, %317 : i64
%321 = llvm.getelementptr %145[%311] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%320 = llvm.load %321 : !llvm.ptr -> i64
%322 = arith.muli %318, %320 : i64
%323 = arith.remsi %322, %139 : i64
%324 = llvm.mlir.constant(1 : i64) : i64
%325 = llvm.alloca %324 x i64 : (i64) -> !llvm.ptr
llvm.store %323, %325 : i64, !llvm.ptr
%326 = llvm.load %325 : !llvm.ptr -> i64
%327 = arith.constant 0 : i32
%329 = arith.extsi %327 : i32 to i64
%328 = arith.cmpi slt, %326, %329 : i64
cf.cond_br %328, ^bb39, ^bb40
^bb39:
%330 = llvm.load %325 : !llvm.ptr -> i64
%331 = arith.addi %330, %139 : i64
llvm.store %331, %325 : i64, !llvm.ptr
cf.br ^bb41
^bb40:
cf.br ^bb41
^bb41:
%333 = llvm.load %242 : !llvm.ptr -> i64
%334 = arith.constant 2 : i32
%335 = arith.extsi %334 : i32 to i64
%332 = func.call @dig_mul_small(%180, %333, %335, %192) : (!llvm.ptr, i64, i64, !llvm.ptr) -> i64
%336 = llvm.mlir.constant(1 : i64) : i64
%337 = llvm.alloca %336 x i64 : (i64) -> !llvm.ptr
llvm.store %332, %337 : i64, !llvm.ptr
%338 = arith.constant 0 : i32
%339 = arith.extsi %338 : i32 to i64
%340 = llvm.mlir.constant(1 : i64) : i64
%341 = llvm.alloca %340 x i64 : (i64) -> !llvm.ptr
llvm.store %339, %341 : i64, !llvm.ptr
%343 = arith.constant 0 : i32
%344 = arith.extsi %343 : i32 to i64
%345 = llvm.getelementptr %192[%344] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%342 = llvm.load %345 : !llvm.ptr -> i64
%346 = arith.constant 1 : i32
%348 = arith.extsi %346 : i32 to i64
%347 = arith.subi %342, %348 : i64
%349 = arith.constant 0 : i32
%350 = arith.extsi %349 : i32 to i64
%351 = llvm.getelementptr %192[%350] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %347, %351 : i64, !llvm.ptr
cf.br ^bb42
^bb42:
%353 = llvm.load %341 : !llvm.ptr -> i64
%354 = llvm.getelementptr %192[%353] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%352 = llvm.load %354 : !llvm.ptr -> i64
%355 = arith.constant 0 : i32
%357 = arith.extsi %355 : i32 to i64
%356 = arith.cmpi slt, %352, %357 : i64
cf.cond_br %356, ^bb43, ^bb44
^bb43:
%359 = llvm.load %341 : !llvm.ptr -> i64
%360 = llvm.getelementptr %192[%359] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%358 = llvm.load %360 : !llvm.ptr -> i64
%361 = arith.addi %358, %139 : i64
%362 = llvm.load %341 : !llvm.ptr -> i64
%363 = llvm.getelementptr %192[%362] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %361, %363 : i64, !llvm.ptr
%364 = llvm.load %341 : !llvm.ptr -> i64
%365 = arith.constant 1 : i32
%367 = arith.extsi %365 : i32 to i64
%366 = arith.addi %364, %367 : i64
llvm.store %366, %341 : i64, !llvm.ptr
%369 = llvm.load %341 : !llvm.ptr -> i64
%370 = llvm.getelementptr %192[%369] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%368 = llvm.load %370 : !llvm.ptr -> i64
%371 = arith.constant 1 : i32
%373 = arith.extsi %371 : i32 to i64
%372 = arith.subi %368, %373 : i64
%374 = llvm.load %341 : !llvm.ptr -> i64
%375 = llvm.getelementptr %192[%374] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %372, %375 : i64, !llvm.ptr
cf.br ^bb42
^bb44:
%377 = llvm.load %337 : !llvm.ptr -> i64
%378 = llvm.load %325 : !llvm.ptr -> i64
%376 = func.call @dig_mul_small(%192, %377, %378, %198) : (!llvm.ptr, i64, i64, !llvm.ptr) -> i64
llvm.store %376, %337 : i64, !llvm.ptr
%380 = llvm.load %250 : !llvm.ptr -> i64
func.call @dig_copy(%186, %380, %192) : (!llvm.ptr, i64, !llvm.ptr) -> ()
%381 = llvm.load %250 : !llvm.ptr -> i64
%382 = llvm.mlir.constant(1 : i64) : i64
%383 = llvm.alloca %382 x i64 : (i64) -> !llvm.ptr
llvm.store %381, %383 : i64, !llvm.ptr
%384 = llvm.load %383 : !llvm.ptr -> i64
llvm.store %384, %341 : i64, !llvm.ptr
cf.br ^bb45
^bb45:
%385 = llvm.load %341 : !llvm.ptr -> i64
%386 = arith.constant 4 : i32
%388 = arith.extsi %386 : i32 to i64
%387 = arith.addi %143, %388 : i64
%389 = arith.cmpi slt, %385, %387 : i64
cf.cond_br %389, ^bb46, ^bb47
^bb46:
%390 = arith.constant 0 : i32
%391 = llvm.load %341 : !llvm.ptr -> i64
%392 = arith.extsi %390 : i32 to i64
%393 = llvm.getelementptr %192[%391] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %392, %393 : i64, !llvm.ptr
%394 = llvm.load %341 : !llvm.ptr -> i64
%395 = arith.constant 1 : i32
%397 = arith.extsi %395 : i32 to i64
%396 = arith.addi %394, %397 : i64
llvm.store %396, %341 : i64, !llvm.ptr
cf.br ^bb45
^bb47:
%399 = llvm.load %383 : !llvm.ptr -> i64
%400 = llvm.load %337 : !llvm.ptr -> i64
%398 = func.call @dig_add_into(%192, %399, %198, %400) : (!llvm.ptr, i64, !llvm.ptr, i64) -> i64
llvm.store %398, %383 : i64, !llvm.ptr
%401 = llvm.load %325 : !llvm.ptr -> i64
%402 = llvm.load %325 : !llvm.ptr -> i64
%403 = arith.muli %401, %402 : i64
%404 = llvm.load %278 : !llvm.ptr -> i64
%405 = llvm.mlir.constant(1 : i64) : i64
%406 = llvm.alloca %405 x i64 : (i64) -> !llvm.ptr
llvm.store %404, %406 : i64, !llvm.ptr
%407 = llvm.mlir.constant(1 : i64) : i64
%408 = llvm.alloca %407 x i64 : (i64) -> !llvm.ptr
llvm.store %403, %408 : i64, !llvm.ptr
cf.br ^bb48
^bb48:
%409 = llvm.load %408 : !llvm.ptr -> i64
%410 = arith.constant 0 : i32
%412 = arith.extsi %410 : i32 to i64
%411 = arith.cmpi ne, %409, %412 : i64
cf.cond_br %411, ^bb49, ^bb50
^bb49:
%414 = llvm.load %406 : !llvm.ptr -> i64
%415 = llvm.getelementptr %192[%414] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%413 = llvm.load %415 : !llvm.ptr -> i64
%416 = llvm.load %408 : !llvm.ptr -> i64
%417 = arith.addi %413, %416 : i64
%418 = arith.remsi %417, %139 : i64
%419 = llvm.load %406 : !llvm.ptr -> i64
%420 = llvm.getelementptr %192[%419] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %418, %420 : i64, !llvm.ptr
%421 = arith.divsi %417, %139 : i64
llvm.store %421, %408 : i64, !llvm.ptr
%422 = llvm.load %406 : !llvm.ptr -> i64
%423 = arith.constant 1 : i32
%425 = arith.extsi %423 : i32 to i64
%424 = arith.addi %422, %425 : i64
llvm.store %424, %406 : i64, !llvm.ptr
%426 = llvm.load %406 : !llvm.ptr -> i64
%427 = llvm.load %383 : !llvm.ptr -> i64
%428 = arith.cmpi sgt, %426, %427 : i64
cf.cond_br %428, ^bb51, ^bb52
^bb51:
%429 = llvm.load %406 : !llvm.ptr -> i64
llvm.store %429, %383 : i64, !llvm.ptr
cf.br ^bb53
^bb52:
cf.br ^bb53
^bb53:
cf.br ^bb48
^bb50:
%431 = llvm.load %383 : !llvm.ptr -> i64
%430 = func.call @dig_div_base(%192, %431) : (!llvm.ptr, i64) -> i64
llvm.store %430, %250 : i64, !llvm.ptr
%433 = llvm.load %250 : !llvm.ptr -> i64
func.call @dig_copy(%192, %433, %186) : (!llvm.ptr, i64, !llvm.ptr) -> ()
%434 = llvm.load %250 : !llvm.ptr -> i64
%435 = arith.constant 0 : i32
%437 = arith.extsi %435 : i32 to i64
%436 = arith.cmpi eq, %434, %437 : i64
cf.cond_br %436, ^bb54, ^bb55
^bb54:
%438 = arith.constant 0 : i32
%439 = arith.constant 0 : i32
%440 = arith.extsi %438 : i32 to i64
%441 = arith.extsi %439 : i32 to i64
%442 = llvm.getelementptr %186[%441] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %440, %442 : i64, !llvm.ptr
%443 = arith.constant 1 : i32
%444 = arith.extsi %443 : i32 to i64
llvm.store %444, %250 : i64, !llvm.ptr
cf.br ^bb56
^bb55:
cf.br ^bb56
^bb56:
%445 = llvm.load %325 : !llvm.ptr -> i64
%446 = llvm.load %242 : !llvm.ptr -> i64
%447 = llvm.getelementptr %180[%446] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %445, %447 : i64, !llvm.ptr
%448 = llvm.load %242 : !llvm.ptr -> i64
%449 = arith.constant 1 : i32
%451 = arith.extsi %449 : i32 to i64
%450 = arith.addi %448, %451 : i64
llvm.store %450, %242 : i64, !llvm.ptr
%452 = llvm.load %325 : !llvm.ptr -> i64
llvm.store %452, %266 : i64, !llvm.ptr
%453 = llvm.load %258 : !llvm.ptr -> i64
%454 = llvm.load %325 : !llvm.ptr -> i64
%455 = arith.addi %453, %454 : i64
llvm.store %455, %258 : i64, !llvm.ptr
%456 = arith.constant 2 : i32
%458 = arith.constant 0 : i32
%459 = arith.extsi %458 : i32 to i64
%460 = llvm.getelementptr %183[%459] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%457 = llvm.load %460 : !llvm.ptr -> i64
%462 = arith.extsi %456 : i32 to i64
%461 = arith.muli %462, %457 : i64
%463 = arith.constant 1 : i32
%465 = arith.extsi %463 : i32 to i64
%464 = arith.subi %461, %465 : i64
%466 = arith.remsi %464, %139 : i64
%467 = arith.constant 0 : i32
%469 = arith.extsi %467 : i32 to i64
%468 = arith.cmpi slt, %466, %469 : i64
%470 = scf.if %468 -> (i64) {
%471 = arith.addi %466, %139 : i64
scf.yield %471 : i64
} else {
scf.yield %466 : i64
}
%473 = arith.constant 0 : i32
%474 = arith.extsi %473 : i32 to i64
%475 = llvm.getelementptr %189[%474] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%472 = llvm.load %475 : !llvm.ptr -> i64
%476 = arith.remsi %472, %139 : i64
%478 = arith.constant 0 : i64
%477 = arith.subi %478, %476 : i64
%480 = llvm.getelementptr %145[%470] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%479 = llvm.load %480 : !llvm.ptr -> i64
%481 = arith.muli %477, %479 : i64
%482 = arith.remsi %481, %139 : i64
%483 = llvm.mlir.constant(1 : i64) : i64
%484 = llvm.alloca %483 x i64 : (i64) -> !llvm.ptr
llvm.store %482, %484 : i64, !llvm.ptr
%485 = llvm.load %484 : !llvm.ptr -> i64
%486 = arith.constant 0 : i32
%488 = arith.extsi %486 : i32 to i64
%487 = arith.cmpi slt, %485, %488 : i64
cf.cond_br %487, ^bb57, ^bb58
^bb57:
%489 = llvm.load %484 : !llvm.ptr -> i64
%490 = arith.addi %489, %139 : i64
llvm.store %490, %484 : i64, !llvm.ptr
cf.br ^bb59
^bb58:
cf.br ^bb59
^bb59:
%492 = llvm.load %246 : !llvm.ptr -> i64
%493 = arith.constant 2 : i32
%494 = arith.extsi %493 : i32 to i64
%491 = func.call @dig_mul_small(%183, %492, %494, %192) : (!llvm.ptr, i64, i64, !llvm.ptr) -> i64
llvm.store %491, %337 : i64, !llvm.ptr
%496 = arith.constant 0 : i32
%497 = arith.extsi %496 : i32 to i64
%498 = llvm.getelementptr %192[%497] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%495 = llvm.load %498 : !llvm.ptr -> i64
%499 = arith.constant 1 : i32
%501 = arith.extsi %499 : i32 to i64
%500 = arith.subi %495, %501 : i64
%502 = arith.constant 0 : i32
%503 = arith.extsi %502 : i32 to i64
%504 = llvm.getelementptr %192[%503] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %500, %504 : i64, !llvm.ptr
%505 = arith.constant 0 : i32
%506 = arith.extsi %505 : i32 to i64
llvm.store %506, %341 : i64, !llvm.ptr
cf.br ^bb60
^bb60:
%508 = llvm.load %341 : !llvm.ptr -> i64
%509 = llvm.getelementptr %192[%508] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%507 = llvm.load %509 : !llvm.ptr -> i64
%510 = arith.constant 0 : i32
%512 = arith.extsi %510 : i32 to i64
%511 = arith.cmpi slt, %507, %512 : i64
cf.cond_br %511, ^bb61, ^bb62
^bb61:
%514 = llvm.load %341 : !llvm.ptr -> i64
%515 = llvm.getelementptr %192[%514] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%513 = llvm.load %515 : !llvm.ptr -> i64
%516 = arith.addi %513, %139 : i64
%517 = llvm.load %341 : !llvm.ptr -> i64
%518 = llvm.getelementptr %192[%517] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %516, %518 : i64, !llvm.ptr
%519 = llvm.load %341 : !llvm.ptr -> i64
%520 = arith.constant 1 : i32
%522 = arith.extsi %520 : i32 to i64
%521 = arith.addi %519, %522 : i64
llvm.store %521, %341 : i64, !llvm.ptr
%524 = llvm.load %341 : !llvm.ptr -> i64
%525 = llvm.getelementptr %192[%524] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%523 = llvm.load %525 : !llvm.ptr -> i64
%526 = arith.constant 1 : i32
%528 = arith.extsi %526 : i32 to i64
%527 = arith.subi %523, %528 : i64
%529 = llvm.load %341 : !llvm.ptr -> i64
%530 = llvm.getelementptr %192[%529] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %527, %530 : i64, !llvm.ptr
cf.br ^bb60
^bb62:
%532 = llvm.load %337 : !llvm.ptr -> i64
%533 = llvm.load %484 : !llvm.ptr -> i64
%531 = func.call @dig_mul_small(%192, %532, %533, %198) : (!llvm.ptr, i64, i64, !llvm.ptr) -> i64
llvm.store %531, %337 : i64, !llvm.ptr
%535 = llvm.load %254 : !llvm.ptr -> i64
func.call @dig_copy(%189, %535, %192) : (!llvm.ptr, i64, !llvm.ptr) -> ()
%536 = llvm.load %254 : !llvm.ptr -> i64
llvm.store %536, %383 : i64, !llvm.ptr
%537 = llvm.load %383 : !llvm.ptr -> i64
llvm.store %537, %341 : i64, !llvm.ptr
cf.br ^bb63
^bb63:
%538 = llvm.load %341 : !llvm.ptr -> i64
%539 = arith.constant 4 : i32
%541 = arith.extsi %539 : i32 to i64
%540 = arith.addi %143, %541 : i64
%542 = arith.cmpi slt, %538, %540 : i64
cf.cond_br %542, ^bb64, ^bb65
^bb64:
%543 = arith.constant 0 : i32
%544 = llvm.load %341 : !llvm.ptr -> i64
%545 = arith.extsi %543 : i32 to i64
%546 = llvm.getelementptr %192[%544] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %545, %546 : i64, !llvm.ptr
%547 = llvm.load %341 : !llvm.ptr -> i64
%548 = arith.constant 1 : i32
%550 = arith.extsi %548 : i32 to i64
%549 = arith.addi %547, %550 : i64
llvm.store %549, %341 : i64, !llvm.ptr
cf.br ^bb63
^bb65:
%552 = llvm.load %383 : !llvm.ptr -> i64
%553 = llvm.load %337 : !llvm.ptr -> i64
%551 = func.call @dig_add_into(%192, %552, %198, %553) : (!llvm.ptr, i64, !llvm.ptr, i64) -> i64
llvm.store %551, %383 : i64, !llvm.ptr
%554 = llvm.load %484 : !llvm.ptr -> i64
%555 = llvm.load %484 : !llvm.ptr -> i64
%556 = arith.muli %554, %555 : i64
%557 = llvm.load %278 : !llvm.ptr -> i64
llvm.store %557, %406 : i64, !llvm.ptr
llvm.store %556, %408 : i64, !llvm.ptr
cf.br ^bb66
^bb66:
%558 = llvm.load %408 : !llvm.ptr -> i64
%559 = arith.constant 0 : i32
%561 = arith.extsi %559 : i32 to i64
%560 = arith.cmpi ne, %558, %561 : i64
cf.cond_br %560, ^bb67, ^bb68
^bb67:
%563 = llvm.load %406 : !llvm.ptr -> i64
%564 = llvm.getelementptr %192[%563] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%562 = llvm.load %564 : !llvm.ptr -> i64
%565 = llvm.load %408 : !llvm.ptr -> i64
%566 = arith.addi %562, %565 : i64
%567 = arith.remsi %566, %139 : i64
%568 = llvm.load %406 : !llvm.ptr -> i64
%569 = llvm.getelementptr %192[%568] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %567, %569 : i64, !llvm.ptr
%570 = arith.divsi %566, %139 : i64
llvm.store %570, %408 : i64, !llvm.ptr
%571 = llvm.load %406 : !llvm.ptr -> i64
%572 = arith.constant 1 : i32
%574 = arith.extsi %572 : i32 to i64
%573 = arith.addi %571, %574 : i64
llvm.store %573, %406 : i64, !llvm.ptr
%575 = llvm.load %406 : !llvm.ptr -> i64
%576 = llvm.load %383 : !llvm.ptr -> i64
%577 = arith.cmpi sgt, %575, %576 : i64
cf.cond_br %577, ^bb69, ^bb70
^bb69:
%578 = llvm.load %406 : !llvm.ptr -> i64
llvm.store %578, %383 : i64, !llvm.ptr
cf.br ^bb71
^bb70:
cf.br ^bb71
^bb71:
cf.br ^bb66
^bb68:
%580 = llvm.load %383 : !llvm.ptr -> i64
%579 = func.call @dig_div_base(%192, %580) : (!llvm.ptr, i64) -> i64
llvm.store %579, %254 : i64, !llvm.ptr
%582 = llvm.load %254 : !llvm.ptr -> i64
func.call @dig_copy(%192, %582, %189) : (!llvm.ptr, i64, !llvm.ptr) -> ()
%583 = llvm.load %254 : !llvm.ptr -> i64
%584 = arith.constant 0 : i32
%586 = arith.extsi %584 : i32 to i64
%585 = arith.cmpi eq, %583, %586 : i64
cf.cond_br %585, ^bb72, ^bb73
^bb72:
%587 = arith.constant 0 : i32
%588 = arith.constant 0 : i32
%589 = arith.extsi %587 : i32 to i64
%590 = arith.extsi %588 : i32 to i64
%591 = llvm.getelementptr %189[%590] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %589, %591 : i64, !llvm.ptr
%592 = arith.constant 1 : i32
%593 = arith.extsi %592 : i32 to i64
llvm.store %593, %254 : i64, !llvm.ptr
cf.br ^bb74
^bb73:
cf.br ^bb74
^bb74:
%594 = llvm.load %484 : !llvm.ptr -> i64
%595 = llvm.load %246 : !llvm.ptr -> i64
%596 = llvm.getelementptr %183[%595] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %594, %596 : i64, !llvm.ptr
%597 = llvm.load %246 : !llvm.ptr -> i64
%598 = arith.constant 1 : i32
%600 = arith.extsi %598 : i32 to i64
%599 = arith.addi %597, %600 : i64
llvm.store %599, %246 : i64, !llvm.ptr
%601 = llvm.load %484 : !llvm.ptr -> i64
llvm.store %601, %270 : i64, !llvm.ptr
%602 = llvm.load %262 : !llvm.ptr -> i64
%603 = llvm.load %484 : !llvm.ptr -> i64
%604 = arith.addi %602, %603 : i64
llvm.store %604, %262 : i64, !llvm.ptr
%605 = llvm.load %278 : !llvm.ptr -> i64
%606 = arith.constant 1 : i32
%608 = arith.extsi %606 : i32 to i64
%607 = arith.addi %605, %608 : i64
llvm.store %607, %278 : i64, !llvm.ptr
cf.br ^bb27
^bb29:
%609 = llvm.load %274 : !llvm.ptr -> i64
%610 = arith.constant 0 : i32
%612 = arith.extsi %610 : i32 to i64
%611 = arith.cmpi eq, %609, %612 : i64
cf.cond_br %611, ^bb75, ^bb76
^bb75:
%613 = llvm.mlir.addressof @str_0 : !llvm.ptr
%614 = llvm.call @printf(%613) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr) -> i32
cf.br ^bb77
^bb76:
%616 = arith.constant 64 : i32
%617 = arith.constant 8 : i32
%618 = arith.extsi %616 : i32 to i64
%619 = arith.extsi %617 : i32 to i64
%615 = func.call @calloc(%618, %619) : (i64, i64) -> !llvm.ptr
%620 = arith.constant 0 : i32
%621 = arith.extsi %620 : i32 to i64
%622 = llvm.mlir.constant(1 : i64) : i64
%623 = llvm.alloca %622 x i64 : (i64) -> !llvm.ptr
llvm.store %621, %623 : i64, !llvm.ptr
%624 = llvm.load %274 : !llvm.ptr -> i64
%625 = llvm.mlir.constant(1 : i64) : i64
%626 = llvm.alloca %625 x i64 : (i64) -> !llvm.ptr
llvm.store %624, %626 : i64, !llvm.ptr
cf.br ^bb78
^bb78:
%627 = llvm.load %626 : !llvm.ptr -> i64
%628 = arith.constant 0 : i32
%630 = arith.extsi %628 : i32 to i64
%629 = arith.cmpi sgt, %627, %630 : i64
cf.cond_br %629, ^bb79, ^bb80
^bb79:
%631 = llvm.load %626 : !llvm.ptr -> i64
%632 = arith.remsi %631, %139 : i64
%633 = llvm.load %623 : !llvm.ptr -> i64
%634 = llvm.getelementptr %615[%633] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %632, %634 : i64, !llvm.ptr
%635 = llvm.load %626 : !llvm.ptr -> i64
%636 = arith.divsi %635, %139 : i64
llvm.store %636, %626 : i64, !llvm.ptr
%637 = llvm.load %623 : !llvm.ptr -> i64
%638 = arith.constant 1 : i32
%640 = arith.extsi %638 : i32 to i64
%639 = arith.addi %637, %640 : i64
llvm.store %639, %623 : i64, !llvm.ptr
cf.br ^bb78
^bb80:
%641 = llvm.load %623 : !llvm.ptr -> i64
%642 = arith.constant 1 : i32
%644 = arith.extsi %642 : i32 to i64
%643 = arith.subi %641, %644 : i64
%645 = llvm.mlir.constant(1 : i64) : i64
%646 = llvm.alloca %645 x i64 : (i64) -> !llvm.ptr
llvm.store %643, %646 : i64, !llvm.ptr
cf.br ^bb81
^bb81:
%647 = llvm.load %646 : !llvm.ptr -> i64
%648 = arith.constant 0 : i32
%650 = arith.extsi %648 : i32 to i64
%649 = arith.cmpi sge, %647, %650 : i64
cf.cond_br %649, ^bb82, ^bb83
^bb82:
%652 = llvm.load %646 : !llvm.ptr -> i64
%653 = llvm.getelementptr %615[%652] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%651 = llvm.load %653 : !llvm.ptr -> i64
%654 = arith.constant 10 : i32
%656 = arith.extsi %654 : i32 to i64
%655 = arith.cmpi slt, %651, %656 : i64
cf.cond_br %655, ^bb84, ^bb85
^bb84:
%657 = llvm.mlir.addressof @str_1 : !llvm.ptr
%658 = arith.constant 48 : i32
%660 = arith.extsi %658 : i32 to i64
%659 = arith.addi %660, %651 : i64
%661 = arith.trunci %659 : i64 to i32
%662 = llvm.call @printf(%657, %661) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i32) -> i32
cf.br ^bb86
^bb85:
%663 = llvm.mlir.addressof @str_1 : !llvm.ptr
%664 = arith.constant 87 : i32
%666 = arith.extsi %664 : i32 to i64
%665 = arith.addi %666, %651 : i64
%667 = arith.trunci %665 : i64 to i32
%668 = llvm.call @printf(%663, %667) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i32) -> i32
cf.br ^bb86
^bb86:
%669 = llvm.load %646 : !llvm.ptr -> i64
%670 = arith.constant 1 : i32
%672 = arith.extsi %670 : i32 to i64
%671 = arith.subi %669, %672 : i64
llvm.store %671, %646 : i64, !llvm.ptr
cf.br ^bb81
^bb83:
%673 = llvm.mlir.addressof @str_2 : !llvm.ptr
%674 = llvm.call @printf(%673) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr) -> i32
func.call @free(%615) : (!llvm.ptr) -> ()
cf.br ^bb77
^bb77:
func.call @free(%180) : (!llvm.ptr) -> ()
func.call @free(%183) : (!llvm.ptr) -> ()
func.call @free(%186) : (!llvm.ptr) -> ()
func.call @free(%189) : (!llvm.ptr) -> ()
func.call @free(%192) : (!llvm.ptr) -> ()
func.call @free(%198) : (!llvm.ptr) -> ()
func.call @free(%145) : (!llvm.ptr) -> ()
%683 = arith.constant 0 : i32
func.return %683 : i32
}
}