← All problems
Problem 305
sum_{k=1..13} f(3^k) where f(n) is start of n-th occurrence of str(n) in Champernowne.
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n^3)?
Space complexity O(n^2)?
Approach Flow solution Not curated
Verdict Unknown
Flow source
# Project Euler 305
# sum_{k=1..13} f(3^k) where f(n) is start of n-th occurrence of str(n) in Champernowne.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
function ipow10(e: i64) -> i64 {
let mut r: i64 = 1
let mut i: i64 = 0
while i < e { r = r * 10; i = i + 1 }
return r
}
function num_digits(n0: i64) -> i64 {
let mut n: i64 = n0
if n == 0 { return 1 }
let mut d: i64 = 0
while n > 0 { d = d + 1; n = n / 10 }
return d
}
function digit_at(n0: i64, pos_from_left: i64, nd: i64) -> i64 {
# pos 0 = MSD
let mut n: i64 = n0
let mut p: i64 = nd - 1 - pos_from_left
let mut i: i64 = 0
while i < p { n = n / 10; i = i + 1 }
return n % 10
}
function build_kmp(pat: ptr<i8>, m: i64, pi: ptr<i32>, trans: ptr<i32>) -> i32 {
# trans[state*10+dig] = next_state + (inc<<16)
pi[0] = 0
let mut j: i64 = 0
let mut i: i64 = 1
while i < m {
while j > 0 && pat[i] != pat[j] { j = pi[j - 1] as i64 }
if pat[i] == pat[j] { j = j + 1 }
pi[i] = j as i32
i = i + 1
}
let mut state: i64 = 0
while state < m {
let mut dig: i64 = 0
while dig < 10 {
let mut s: i64 = state
while s > 0 && (pat[s] as i64) != dig { s = pi[s - 1] as i64 }
if (pat[s] as i64) == dig { s = s + 1 }
let mut inc: i64 = 0
if s == m {
inc = 1
s = pi[m - 1] as i64
}
trans[state * 10 + dig] = (s + (inc << 16)) as i32
dig = dig + 1
}
state = state + 1
}
return 0
}
function step(trans: ptr<i32>, state: i64, dig: i64) -> i64 {
return trans[state * 10 + dig] as i64
}
function count_arith(lo: i64, hi: i64, mod: i64, rem: i64) -> i64 {
if hi < lo { return 0 }
let mut first: i64 = lo + ((rem - (lo % mod) + mod) % mod)
if first > hi { return 0 }
return (hi - first) / mod + 1
}
function prefix_to_N(P: i64, outN: ptr<i64>, outRem: ptr<i64>) -> i32 {
if P <= 0 { outN[0] = 0; outRem[0] = 0; return 0 }
let mut cum: i64 = 0
let mut d: i64 = 1
let mut start: i64 = 1
while true {
let block_count: i64 = 9 * start
let block_len: i64 = block_count * d
if cum + block_len < P {
cum = cum + block_len
d = d + 1
start = start * 10
} else {
let need: i64 = P - cum
let full: i64 = need / d
let rem: i64 = need % d
outN[0] = start - 1 + full
outRem[0] = rem
return 0
}
}
return 0
}
# For speed/clarity on this problem, compute f(n) using binary search on starts
# with counting via building S prefixes by scanning numbers (OK for needed ranges).
# 3^13=1594323, f is ~1e13 so we need the analytic counter.
# Port PatternCounter essentials below.
function internal_len_d(d: i64, m: i64, trans: ptr<i32>) -> i64 {
let dp_count: ptr<i64> = calloc(m, 8)
let dp_match: ptr<i64> = calloc(m, 8)
let mut dig: i64 = 1
while dig <= 9 {
let st: i64 = step(trans, 0, dig)
let ns: i64 = st & 65535
let inc: i64 = st >> 16
dp_count[ns] = dp_count[ns] + 1
dp_match[ns] = dp_match[ns] + inc
dig = dig + 1
}
let mut pos: i64 = 1
while pos < d {
let newc: ptr<i64> = calloc(m, 8)
let newm: ptr<i64> = calloc(m, 8)
let mut st: i64 = 0
while st < m {
let c: i64 = dp_count[st]
if c != 0 {
let cm: i64 = dp_match[st]
dig = 0
while dig < 10 {
let tr: i64 = step(trans, st, dig)
let ns: i64 = tr & 65535
let inc: i64 = tr >> 16
newc[ns] = newc[ns] + c
newm[ns] = newm[ns] + cm + c * inc
dig = dig + 1
}
}
st = st + 1
}
free(dp_count); free(dp_match)
dp_count = newc; dp_match = newm
pos = pos + 1
}
let mut res: i64 = 0
let mut st: i64 = 0
while st < m { res = res + dp_match[st]; st = st + 1 }
free(dp_count); free(dp_match)
return res
}
function internal_upto(N: i64, m: i64, trans: ptr<i32>, ilen: ptr<i64>) -> i64 {
if N <= 0 { return 0 }
let D: i64 = num_digits(N)
let mut res: i64 = 0
let mut d: i64 = 1
while d < D {
res = res + ilen[d]
d = d + 1
}
let dpCt: ptr<i64> = calloc(m, 8)
let dpMt: ptr<i64> = calloc(m, 8)
let dpCl: ptr<i64> = calloc(m, 8)
let dpMl: ptr<i64> = calloc(m, 8)
dpCt[0] = 1
let mut pos: i64 = 0
while pos < D {
let lim: i64 = digit_at(N, pos, D)
let newCt: ptr<i64> = calloc(m, 8)
let newMt: ptr<i64> = calloc(m, 8)
let newCl: ptr<i64> = calloc(m, 8)
let newMl: ptr<i64> = calloc(m, 8)
let mind: i64 = 0
if pos == 0 { mind = 1 }
let mut st: i64 = 0
while st < m {
let c: i64 = dpCt[st]
if c != 0 {
let cm: i64 = dpMt[st]
let mut dig: i64 = mind
while dig <= lim {
let tr: i64 = step(trans, st, dig)
let ns: i64 = tr & 65535
let inc: i64 = tr >> 16
if dig == lim {
newCt[ns] = newCt[ns] + c
newMt[ns] = newMt[ns] + cm + c * inc
} else {
newCl[ns] = newCl[ns] + c
newMl[ns] = newMl[ns] + cm + c * inc
}
dig = dig + 1
}
}
st = st + 1
}
st = 0
while st < m {
let c: i64 = dpCl[st]
if c != 0 {
let cm: i64 = dpMl[st]
let mut dig: i64 = mind
if pos != 0 { dig = 0 }
while dig <= 9 {
let tr: i64 = step(trans, st, dig)
let ns: i64 = tr & 65535
let inc: i64 = tr >> 16
newCl[ns] = newCl[ns] + c
newMl[ns] = newMl[ns] + cm + c * inc
dig = dig + 1
}
}
st = st + 1
}
free(dpCt); free(dpMt); free(dpCl); free(dpMl)
dpCt = newCt; dpMt = newMt; dpCl = newCl; dpMl = newMl
pos = pos + 1
}
let mut st: i64 = 0
while st < m {
res = res + dpMt[st] + dpMl[st]
st = st + 1
}
free(dpCt); free(dpMt); free(dpCl); free(dpMl)
return res
}
function fill_pat(n: i64, pat: ptr<i8>, m: i64) -> i32 {
let mut i: i64 = 0
while i < m {
pat[i] = digit_at(n, i, m) as i8
i = i + 1
}
return 0
}
function boundary_upto(N: i64, m: i64, pat: ptr<i8>) -> i64 {
if m <= 1 || N <= 1 { return 0 }
let mut total: i64 = 0
let max_d: i64 = num_digits(N - 1)
let mut k: i64 = 1
while k < m {
# p1 = pat[0..k), p2 = pat[k..m)
if pat[k] == 0 { k = k + 1; continue }
let mut suf_val: i64 = 0
let mut i: i64 = 0
while i < k { suf_val = suf_val * 10 + (pat[i] as i64); i = i + 1 }
let L: i64 = m - k
let mut pre_val: i64 = 0
i = 0
while i < L { pre_val = pre_val * 10 + (pat[k + i] as i64); i = i + 1 }
let mod: i64 = ipow10(k)
let mut d: i64 = 1
while d <= max_d {
let x_lo: i64 = 1
if d > 1 { x_lo = ipow10(d - 1) }
let mut x_hi: i64 = ipow10(d) - 2
if x_hi > N - 1 { x_hi = N - 1 }
if x_hi >= x_lo && d >= L {
let y_lo: i64 = pre_val * ipow10(d - L)
let y_hi: i64 = (pre_val + 1) * ipow10(d - L) - 1
let mut lo: i64 = x_lo
if y_lo - 1 > lo { lo = y_lo - 1 }
let mut hi: i64 = x_hi
if y_hi - 1 < hi { hi = y_hi - 1 }
if hi >= lo { total = total + count_arith(lo, hi, mod, suf_val) }
}
d = d + 1
}
# digit-increase transitions
let mut all9: i64 = 1
i = 0
while i < k {
if pat[i] != 9 { all9 = 0 }
i = i + 1
}
if all9 == 1 {
let mut ok: i64 = 1
if pat[k] != 1 { ok = 0 }
i = 1
while i < L {
if pat[k + i] != 0 { ok = 0 }
i = i + 1
}
if ok == 1 {
let dmax: i64 = num_digits(N) - 1
let mut dmin: i64 = 1
if L - 1 > dmin { dmin = L - 1 }
if dmax >= dmin { total = total + (dmax - dmin + 1) }
}
}
k = k + 1
}
return total
}
function brute_count(upto: i64, m: i64, trans: ptr<i32>) -> i64 {
let mut state: i64 = 0
let mut total: i64 = 0
let mut n: i64 = 1
while n <= upto {
let nd: i64 = num_digits(n)
let mut p: i64 = 0
while p < nd {
let dig: i64 = digit_at(n, p, nd)
let tr: i64 = step(trans, state, dig)
state = tr & 65535
total = total + (tr >> 16)
p = p + 1
}
n = n + 1
}
return total
}
function f_of_n(n: i64) -> i64 {
let m: i64 = num_digits(n)
let pat: ptr<i8> = calloc(m, 1)
fill_pat(n, pat, m)
let pi: ptr<i32> = calloc(m, 4)
let trans: ptr<i32> = calloc(m * 10, 4)
build_kmp(pat, m, pi, trans)
let A: i64 = 1
if m >= 2 { A = ipow10(m - 2) }
let ilen: ptr<i64> = calloc(21, 8)
let mut d: i64 = 1
while d <= 20 {
ilen[d] = internal_len_d(d, m, trans)
d = d + 1
}
let brute_A: i64 = brute_count(A, m, trans)
let internal_A: i64 = internal_upto(A, m, trans, ilen)
let boundary_A: i64 = boundary_upto(A, m, pat)
# binary search
let target: i64 = n
let mut lo: i64 = 1
let mut hi: i64 = 1
while true {
# count_starts_leq(hi) = matches in prefix hi+m-1
let P: i64 = hi + m - 1
let outN: ptr<i64> = calloc(1, 8)
let outRem: ptr<i64> = calloc(1, 8)
prefix_to_N(P, outN, outRem)
let Nf: i64 = outN[0]
let rem: i64 = outRem[0]
let mut cnt: i64 = 0
if Nf <= A { cnt = brute_count(Nf, m, trans) }
else { cnt = brute_A + (internal_upto(Nf, m, trans, ilen) - internal_A) + (boundary_upto(Nf, m, pat) - boundary_A) }
if rem > 0 {
# append rem digits of Nf+1 after matching through tail of length m-1
let mut state: i64 = 0
# feed last up to m-1 digits of C(Nf)
let need: i64 = m - 1
let digs: ptr<i8> = calloc(need + rem + 8, 1)
let mut dn: i64 = 0
let mut x: i64 = Nf
while dn < need && x >= 1 {
let nd: i64 = num_digits(x)
let tmp: ptr<i8> = calloc(nd, 1)
let mut p: i64 = 0
while p < nd { tmp[p] = digit_at(x, p, nd) as i8; p = p + 1 }
# prepend tmp to digs content: shift
let mut shift: i64 = dn - 1
while shift >= 0 {
digs[shift + nd] = digs[shift]
shift = shift - 1
}
p = 0
while p < nd { digs[p] = tmp[p]; p = p + 1 }
dn = dn + nd
free(tmp)
x = x - 1
}
if dn > need {
# keep last need
let mut p: i64 = 0
while p < need { digs[p] = digs[dn - need + p]; p = p + 1 }
dn = need
}
let nxt: i64 = Nf + 1
let nd2: i64 = num_digits(nxt)
let mut p: i64 = 0
while p < rem {
digs[dn + p] = digit_at(nxt, p, nd2) as i8
p = p + 1
}
let tlen: i64 = dn
let total_len: i64 = dn + rem
p = 0
while p < total_len {
let tr: i64 = step(trans, state, digs[p] as i64)
state = tr & 65535
if (tr >> 16) == 1 && p >= tlen { cnt = cnt + 1 }
p = p + 1
}
free(digs)
}
free(outN); free(outRem)
if cnt >= target { break }
hi = hi * 2
if hi <= 0 { hi = 9223372036854775807; break }
}
lo = 1
while lo < hi {
let mid: i64 = lo + (hi - lo) / 2
let P: i64 = mid + m - 1
let outN: ptr<i64> = calloc(1, 8)
let outRem: ptr<i64> = calloc(1, 8)
prefix_to_N(P, outN, outRem)
let Nf: i64 = outN[0]
let rem: i64 = outRem[0]
let mut cnt: i64 = 0
if Nf <= A { cnt = brute_count(Nf, m, trans) }
else { cnt = brute_A + (internal_upto(Nf, m, trans, ilen) - internal_A) + (boundary_upto(Nf, m, pat) - boundary_A) }
if rem > 0 {
let mut state: i64 = 0
let need: i64 = m - 1
let digs: ptr<i8> = calloc(need + rem + 8, 1)
let mut dn: i64 = 0
let mut x: i64 = Nf
while dn < need && x >= 1 {
let nd: i64 = num_digits(x)
let tmp: ptr<i8> = calloc(nd, 1)
let mut p: i64 = 0
while p < nd { tmp[p] = digit_at(x, p, nd) as i8; p = p + 1 }
let mut shift: i64 = dn - 1
while shift >= 0 { digs[shift + nd] = digs[shift]; shift = shift - 1 }
p = 0
while p < nd { digs[p] = tmp[p]; p = p + 1 }
dn = dn + nd
free(tmp)
x = x - 1
}
if dn > need {
let mut p: i64 = 0
while p < need { digs[p] = digs[dn - need + p]; p = p + 1 }
dn = need
}
let nxt: i64 = Nf + 1
let nd2: i64 = num_digits(nxt)
let mut p: i64 = 0
while p < rem { digs[dn + p] = digit_at(nxt, p, nd2) as i8; p = p + 1 }
let tlen: i64 = dn
let total_len: i64 = dn + rem
p = 0
while p < total_len {
let tr: i64 = step(trans, state, digs[p] as i64)
state = tr & 65535
if (tr >> 16) == 1 && p >= tlen { cnt = cnt + 1 }
p = p + 1
}
free(digs)
}
free(outN); free(outRem)
if cnt >= target { hi = mid } else { lo = mid + 1 }
}
free(pat); free(pi); free(trans); free(ilen)
return lo
}
function main() -> i32 {
let mut total: i64 = 0
let mut k: i64 = 1
let mut pw: i64 = 3
while k <= 13 {
total = total + f_of_n(pw)
pw = pw * 3
k = k + 1
}
printf("%lld\n", total)
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 ipow10_i64(int64_t e);
int64_t num_digits_i64(int64_t n0);
int64_t digit_at_i64_i64_i64(int64_t n0, int64_t pos_from_left, int64_t nd);
int32_t build_kmp_ptr_i8_i64_ptr_i32_ptr_i32(int8_t* pat, int64_t m, int32_t* pi, int32_t* trans);
int64_t step_ptr_i32_i64_i64(int32_t* trans, int64_t state, int64_t dig);
int64_t count_arith_i64_i64_i64_i64(int64_t lo, int64_t hi, int64_t mod, int64_t rem);
int32_t prefix_to_N_i64_ptr_i64_ptr_i64(int64_t P, int64_t* outN, int64_t* outRem);
int64_t internal_len_d_i64_i64_ptr_i32(int64_t d, int64_t m, int32_t* trans);
int64_t internal_upto_i64_i64_ptr_i32_ptr_i64(int64_t N, int64_t m, int32_t* trans, int64_t* ilen);
int32_t fill_pat_i64_ptr_i8_i64(int64_t n, int8_t* pat, int64_t m);
int64_t boundary_upto_i64_i64_ptr_i8(int64_t N, int64_t m, int8_t* pat);
int64_t brute_count_i64_i64_ptr_i32(int64_t upto, int64_t m, int32_t* trans);
int64_t f_of_n_i64(int64_t n);
int32_t main(void);
int64_t ipow10_i64(int64_t e) {
int64_t r = 1;
int64_t i = 0;
while (i < e) {
r = (r * 10);
i = (i + 1);
}
return r;
}
int64_t num_digits_i64(int64_t n0) {
int64_t n = n0;
if (n == 0) {
return 1;
}
int64_t d = 0;
while (n > 0) {
d = (d + 1);
n = FLOW_CHECKED_DIV((n), (10));
}
return d;
}
int64_t digit_at_i64_i64_i64(int64_t n0, int64_t pos_from_left, int64_t nd) {
int64_t n = n0;
int64_t p = ((nd - 1) - pos_from_left);
int64_t i = 0;
while (i < p) {
n = FLOW_CHECKED_DIV((n), (10));
i = (i + 1);
}
return FLOW_CHECKED_MOD((n), (10));
}
int32_t build_kmp_ptr_i8_i64_ptr_i32_ptr_i32(int8_t* pat, int64_t m, int32_t* pi, int32_t* trans) {
pi[0] = 0;
int64_t j = 0;
int64_t i = 1;
while (i < m) {
while ((j > 0 && pat[i] != pat[j])) {
j = ((int64_t)(pi[(j - 1)]));
}
if (pat[i] == pat[j]) {
j = (j + 1);
}
pi[i] = ((int32_t)(j));
i = (i + 1);
}
int64_t state = 0;
while (state < m) {
int64_t dig = 0;
while (dig < 10) {
int64_t s = state;
while ((s > 0 && ((int64_t)(pat[s])) != dig)) {
s = ((int64_t)(pi[(s - 1)]));
}
if (((int64_t)(pat[s])) == dig) {
s = (s + 1);
}
int64_t inc = 0;
if (s == m) {
inc = 1;
s = ((int64_t)(pi[(m - 1)]));
}
trans[((state * 10) + dig)] = ((int32_t)((s + FLOW_CHECKED_SHL((inc), (16)))));
dig = (dig + 1);
}
state = (state + 1);
}
return 0;
}
int64_t step_ptr_i32_i64_i64(int32_t* trans, int64_t state, int64_t dig) {
return ((int64_t)(trans[((state * 10) + dig)]));
}
int64_t count_arith_i64_i64_i64_i64(int64_t lo, int64_t hi, int64_t mod, int64_t rem) {
if (hi < lo) {
return 0;
}
int64_t first = (lo + FLOW_CHECKED_MOD((((rem - FLOW_CHECKED_MOD((lo), (mod))) + mod)), (mod)));
if (first > hi) {
return 0;
}
return (FLOW_CHECKED_DIV(((hi - first)), (mod)) + 1);
}
int32_t prefix_to_N_i64_ptr_i64_ptr_i64(int64_t P, int64_t* outN, int64_t* outRem) {
if (P <= 0) {
outN[0] = 0;
outRem[0] = 0;
return 0;
}
int64_t cum = 0;
int64_t d = 1;
int64_t start = 1;
while (1) {
int64_t block_count = (9 * start);
int64_t block_len = (block_count * d);
if ((cum + block_len) < P) {
cum = (cum + block_len);
d = (d + 1);
start = (start * 10);
} else {
int64_t need = (P - cum);
int64_t full = FLOW_CHECKED_DIV((need), (d));
int64_t rem = FLOW_CHECKED_MOD((need), (d));
outN[0] = ((start - 1) + full);
outRem[0] = rem;
return 0;
}
}
return 0;
}
int64_t internal_len_d_i64_i64_ptr_i32(int64_t d, int64_t m, int32_t* trans) {
int64_t* dp_count = (int64_t*)(calloc(m, 8));
int64_t* dp_match = (int64_t*)(calloc(m, 8));
int64_t dig = 1;
while (dig <= 9) {
int64_t st = step_ptr_i32_i64_i64(trans, 0, dig);
int64_t ns = (st & 65535);
int64_t inc = FLOW_CHECKED_SHR((st), (16));
dp_count[ns] = (dp_count[ns] + 1);
dp_match[ns] = (dp_match[ns] + inc);
dig = (dig + 1);
}
int64_t pos = 1;
while (pos < d) {
int64_t* newc = (int64_t*)(calloc(m, 8));
int64_t* newm = (int64_t*)(calloc(m, 8));
int64_t st = 0;
while (st < m) {
int64_t c = dp_count[st];
if (c != 0) {
int64_t cm = dp_match[st];
dig = 0;
while (dig < 10) {
int64_t tr = step_ptr_i32_i64_i64(trans, st, dig);
int64_t ns = (tr & 65535);
int64_t inc = FLOW_CHECKED_SHR((tr), (16));
newc[ns] = (newc[ns] + c);
newm[ns] = ((newm[ns] + cm) + (c * inc));
dig = (dig + 1);
}
}
st = (st + 1);
}
free(dp_count);
free(dp_match);
dp_count = newc;
dp_match = newm;
pos = (pos + 1);
}
int64_t res = 0;
int64_t st = 0;
while (st < m) {
res = (res + dp_match[st]);
st = (st + 1);
}
free(dp_count);
free(dp_match);
return res;
}
int64_t internal_upto_i64_i64_ptr_i32_ptr_i64(int64_t N, int64_t m, int32_t* trans, int64_t* ilen) {
if (N <= 0) {
return 0;
}
int64_t D = num_digits_i64(N);
int64_t res = 0;
int64_t d = 1;
while (d < D) {
res = (res + ilen[d]);
d = (d + 1);
}
int64_t* dpCt = (int64_t*)(calloc(m, 8));
int64_t* dpMt = (int64_t*)(calloc(m, 8));
int64_t* dpCl = (int64_t*)(calloc(m, 8));
int64_t* dpMl = (int64_t*)(calloc(m, 8));
dpCt[0] = 1;
int64_t pos = 0;
while (pos < D) {
int64_t lim = digit_at_i64_i64_i64(N, pos, D);
int64_t* newCt = (int64_t*)(calloc(m, 8));
int64_t* newMt = (int64_t*)(calloc(m, 8));
int64_t* newCl = (int64_t*)(calloc(m, 8));
int64_t* newMl = (int64_t*)(calloc(m, 8));
int64_t mind = 0;
if (pos == 0) {
mind = 1;
}
int64_t st = 0;
while (st < m) {
int64_t c = dpCt[st];
if (c != 0) {
int64_t cm = dpMt[st];
int64_t dig = mind;
while (dig <= lim) {
int64_t tr = step_ptr_i32_i64_i64(trans, st, dig);
int64_t ns = (tr & 65535);
int64_t inc = FLOW_CHECKED_SHR((tr), (16));
if (dig == lim) {
newCt[ns] = (newCt[ns] + c);
newMt[ns] = ((newMt[ns] + cm) + (c * inc));
} else {
newCl[ns] = (newCl[ns] + c);
newMl[ns] = ((newMl[ns] + cm) + (c * inc));
}
dig = (dig + 1);
}
}
st = (st + 1);
}
st = 0;
while (st < m) {
int64_t c = dpCl[st];
if (c != 0) {
int64_t cm = dpMl[st];
int64_t dig = mind;
if (pos != 0) {
dig = 0;
}
while (dig <= 9) {
int64_t tr = step_ptr_i32_i64_i64(trans, st, dig);
int64_t ns = (tr & 65535);
int64_t inc = FLOW_CHECKED_SHR((tr), (16));
newCl[ns] = (newCl[ns] + c);
newMl[ns] = ((newMl[ns] + cm) + (c * inc));
dig = (dig + 1);
}
}
st = (st + 1);
}
free(dpCt);
free(dpMt);
free(dpCl);
free(dpMl);
dpCt = newCt;
dpMt = newMt;
dpCl = newCl;
dpMl = newMl;
pos = (pos + 1);
}
int64_t st = 0;
while (st < m) {
res = ((res + dpMt[st]) + dpMl[st]);
st = (st + 1);
}
free(dpCt);
free(dpMt);
free(dpCl);
free(dpMl);
return res;
}
int32_t fill_pat_i64_ptr_i8_i64(int64_t n, int8_t* pat, int64_t m) {
int64_t i = 0;
while (i < m) {
pat[i] = ((int8_t)(digit_at_i64_i64_i64(n, i, m)));
i = (i + 1);
}
return 0;
}
int64_t boundary_upto_i64_i64_ptr_i8(int64_t N, int64_t m, int8_t* pat) {
if ((m <= 1 || N <= 1)) {
return 0;
}
int64_t total = 0;
int64_t max_d = num_digits_i64((N - 1));
int64_t k = 1;
while (k < m) {
if (pat[k] == 0) {
k = (k + 1);
continue;
}
int64_t suf_val = 0;
int64_t i = 0;
while (i < k) {
suf_val = ((suf_val * 10) + ((int64_t)(pat[i])));
i = (i + 1);
}
int64_t L = (m - k);
int64_t pre_val = 0;
i = 0;
while (i < L) {
pre_val = ((pre_val * 10) + ((int64_t)(pat[(k + i)])));
i = (i + 1);
}
int64_t mod = ipow10_i64(k);
int64_t d = 1;
while (d <= max_d) {
int64_t x_lo = 1;
if (d > 1) {
x_lo = ipow10_i64((d - 1));
}
int64_t x_hi = (ipow10_i64(d) - 2);
if (x_hi > (N - 1)) {
x_hi = (N - 1);
}
if ((x_hi >= x_lo && d >= L)) {
int64_t y_lo = (pre_val * ipow10_i64((d - L)));
int64_t y_hi = (((pre_val + 1) * ipow10_i64((d - L))) - 1);
int64_t lo = x_lo;
if ((y_lo - 1) > lo) {
lo = (y_lo - 1);
}
int64_t hi = x_hi;
if ((y_hi - 1) < hi) {
hi = (y_hi - 1);
}
if (hi >= lo) {
total = (total + count_arith_i64_i64_i64_i64(lo, hi, mod, suf_val));
}
}
d = (d + 1);
}
int64_t all9 = 1;
i = 0;
while (i < k) {
if (pat[i] != 9) {
all9 = 0;
}
i = (i + 1);
}
if (all9 == 1) {
int64_t ok = 1;
if (pat[k] != 1) {
ok = 0;
}
i = 1;
while (i < L) {
if (pat[(k + i)] != 0) {
ok = 0;
}
i = (i + 1);
}
if (ok == 1) {
int64_t dmax = (num_digits_i64(N) - 1);
int64_t dmin = 1;
if ((L - 1) > dmin) {
dmin = (L - 1);
}
if (dmax >= dmin) {
total = (total + ((dmax - dmin) + 1));
}
}
}
k = (k + 1);
}
return total;
}
int64_t brute_count_i64_i64_ptr_i32(int64_t upto, int64_t m, int32_t* trans) {
int64_t state = 0;
int64_t total = 0;
int64_t n = 1;
while (n <= upto) {
int64_t nd = num_digits_i64(n);
int64_t p = 0;
while (p < nd) {
int64_t dig = digit_at_i64_i64_i64(n, p, nd);
int64_t tr = step_ptr_i32_i64_i64(trans, state, dig);
state = (tr & 65535);
total = (total + FLOW_CHECKED_SHR((tr), (16)));
p = (p + 1);
}
n = (n + 1);
}
return total;
}
int64_t f_of_n_i64(int64_t n) {
int64_t m = num_digits_i64(n);
int8_t* pat = (int8_t*)(calloc(m, 1));
fill_pat_i64_ptr_i8_i64(n, pat, m);
int32_t* pi = (int32_t*)(calloc(m, 4));
int32_t* trans = (int32_t*)(calloc((m * 10), 4));
build_kmp_ptr_i8_i64_ptr_i32_ptr_i32(pat, m, pi, trans);
int64_t A = 1;
if (m >= 2) {
A = ipow10_i64((m - 2));
}
int64_t* ilen = (int64_t*)(calloc(21, 8));
int64_t d = 1;
while (d <= 20) {
ilen[d] = internal_len_d_i64_i64_ptr_i32(d, m, trans);
d = (d + 1);
}
int64_t brute_A = brute_count_i64_i64_ptr_i32(A, m, trans);
int64_t internal_A = internal_upto_i64_i64_ptr_i32_ptr_i64(A, m, trans, ilen);
int64_t boundary_A = boundary_upto_i64_i64_ptr_i8(A, m, pat);
int64_t target = n;
int64_t lo = 1;
int64_t hi = 1;
while (1) {
int64_t P = ((hi + m) - 1);
int64_t* outN = (int64_t*)(calloc(1, 8));
int64_t* outRem = (int64_t*)(calloc(1, 8));
prefix_to_N_i64_ptr_i64_ptr_i64(P, outN, outRem);
int64_t Nf = outN[0];
int64_t rem = outRem[0];
int64_t cnt = 0;
if (Nf <= A) {
cnt = brute_count_i64_i64_ptr_i32(Nf, m, trans);
} else {
cnt = ((brute_A + (internal_upto_i64_i64_ptr_i32_ptr_i64(Nf, m, trans, ilen) - internal_A)) + (boundary_upto_i64_i64_ptr_i8(Nf, m, pat) - boundary_A));
}
if (rem > 0) {
int64_t state = 0;
int64_t need = (m - 1);
int8_t* digs = (int8_t*)(calloc(((need + rem) + 8), 1));
int64_t dn = 0;
int64_t x = Nf;
while ((dn < need && x >= 1)) {
int64_t nd = num_digits_i64(x);
int8_t* tmp = (int8_t*)(calloc(nd, 1));
int64_t p = 0;
while (p < nd) {
tmp[p] = ((int8_t)(digit_at_i64_i64_i64(x, p, nd)));
p = (p + 1);
}
int64_t shift = (dn - 1);
while (shift >= 0) {
digs[(shift + nd)] = digs[shift];
shift = (shift - 1);
}
p = 0;
while (p < nd) {
digs[p] = tmp[p];
p = (p + 1);
}
dn = (dn + nd);
free(tmp);
x = (x - 1);
}
if (dn > need) {
int64_t p = 0;
while (p < need) {
digs[p] = digs[((dn - need) + p)];
p = (p + 1);
}
dn = need;
}
int64_t nxt = (Nf + 1);
int64_t nd2 = num_digits_i64(nxt);
int64_t p = 0;
while (p < rem) {
digs[(dn + p)] = ((int8_t)(digit_at_i64_i64_i64(nxt, p, nd2)));
p = (p + 1);
}
int64_t tlen = dn;
int64_t total_len = (dn + rem);
p = 0;
while (p < total_len) {
int64_t tr = step_ptr_i32_i64_i64(trans, state, ((int64_t)(digs[p])));
state = (tr & 65535);
if ((FLOW_CHECKED_SHR((tr), (16)) == 1 && p >= tlen)) {
cnt = (cnt + 1);
}
p = (p + 1);
}
free(digs);
}
free(outN);
free(outRem);
if (cnt >= target) {
break;
}
hi = (hi * 2);
if (hi <= 0) {
hi = 9223372036854775807;
break;
}
}
lo = 1;
while (lo < hi) {
int64_t mid = (lo + FLOW_CHECKED_DIV(((hi - lo)), (2)));
int64_t P = ((mid + m) - 1);
int64_t* outN = (int64_t*)(calloc(1, 8));
int64_t* outRem = (int64_t*)(calloc(1, 8));
prefix_to_N_i64_ptr_i64_ptr_i64(P, outN, outRem);
int64_t Nf = outN[0];
int64_t rem = outRem[0];
int64_t cnt = 0;
if (Nf <= A) {
cnt = brute_count_i64_i64_ptr_i32(Nf, m, trans);
} else {
cnt = ((brute_A + (internal_upto_i64_i64_ptr_i32_ptr_i64(Nf, m, trans, ilen) - internal_A)) + (boundary_upto_i64_i64_ptr_i8(Nf, m, pat) - boundary_A));
}
if (rem > 0) {
int64_t state = 0;
int64_t need = (m - 1);
int8_t* digs = (int8_t*)(calloc(((need + rem) + 8), 1));
int64_t dn = 0;
int64_t x = Nf;
while ((dn < need && x >= 1)) {
int64_t nd = num_digits_i64(x);
int8_t* tmp = (int8_t*)(calloc(nd, 1));
int64_t p = 0;
while (p < nd) {
tmp[p] = ((int8_t)(digit_at_i64_i64_i64(x, p, nd)));
p = (p + 1);
}
int64_t shift = (dn - 1);
while (shift >= 0) {
digs[(shift + nd)] = digs[shift];
shift = (shift - 1);
}
p = 0;
while (p < nd) {
digs[p] = tmp[p];
p = (p + 1);
}
dn = (dn + nd);
free(tmp);
x = (x - 1);
}
if (dn > need) {
int64_t p = 0;
while (p < need) {
digs[p] = digs[((dn - need) + p)];
p = (p + 1);
}
dn = need;
}
int64_t nxt = (Nf + 1);
int64_t nd2 = num_digits_i64(nxt);
int64_t p = 0;
while (p < rem) {
digs[(dn + p)] = ((int8_t)(digit_at_i64_i64_i64(nxt, p, nd2)));
p = (p + 1);
}
int64_t tlen = dn;
int64_t total_len = (dn + rem);
p = 0;
while (p < total_len) {
int64_t tr = step_ptr_i32_i64_i64(trans, state, ((int64_t)(digs[p])));
state = (tr & 65535);
if ((FLOW_CHECKED_SHR((tr), (16)) == 1 && p >= tlen)) {
cnt = (cnt + 1);
}
p = (p + 1);
}
free(digs);
}
free(outN);
free(outRem);
if (cnt >= target) {
hi = mid;
} else {
lo = (mid + 1);
}
}
free(pat);
free(pi);
free(trans);
free(ilen);
return lo;
}
int32_t main(void) {
int64_t total = 0;
int64_t k = 1;
int64_t pw = 3;
while (k <= 13) {
total = (total + f_of_n_i64(pw));
pw = (pw * 3);
k = (k + 1);
}
printf("%lld\n", total);
return 0;
}
Generated MLIR
module {
llvm.func @printf(!llvm.ptr, ...) -> i32
llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
func.func @ipow10(%arg0: i64) -> i64 {
%0 = arith.constant 1 : i32
%1 = arith.extsi %0 : i32 to i64
%2 = llvm.mlir.constant(1 : i64) : i64
%3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
llvm.store %1, %3 : i64, !llvm.ptr
%4 = arith.constant 0 : i32
%5 = arith.extsi %4 : i32 to i64
%6 = llvm.mlir.constant(1 : i64) : i64
%7 = llvm.alloca %6 x i64 : (i64) -> !llvm.ptr
llvm.store %5, %7 : i64, !llvm.ptr
cf.br ^bb0
^bb0:
%8 = llvm.load %7 : !llvm.ptr -> i64
%9 = arith.cmpi slt, %8, %arg0 : i64
cf.cond_br %9, ^bb1, ^bb2
^bb1:
%10 = llvm.load %3 : !llvm.ptr -> i64
%11 = arith.constant 10 : i32
%13 = arith.extsi %11 : i32 to i64
%12 = arith.muli %10, %13 : i64
llvm.store %12, %3 : i64, !llvm.ptr
%14 = llvm.load %7 : !llvm.ptr -> i64
%15 = arith.constant 1 : i32
%17 = arith.extsi %15 : i32 to i64
%16 = arith.addi %14, %17 : i64
llvm.store %16, %7 : i64, !llvm.ptr
cf.br ^bb0
^bb2:
%18 = llvm.load %3 : !llvm.ptr -> i64
func.return %18 : i64
}
func.func @num_digits(%arg0: i64) -> i64 {
%19 = llvm.mlir.constant(1 : i64) : i64
%20 = llvm.alloca %19 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %20 : i64, !llvm.ptr
%21 = llvm.load %20 : !llvm.ptr -> i64
%22 = arith.constant 0 : i32
%24 = arith.extsi %22 : i32 to i64
%23 = arith.cmpi eq, %21, %24 : i64
cf.cond_br %23, ^bb3, ^bb4
^bb3:
%25 = arith.constant 1 : i32
%26 = arith.extsi %25 : i32 to i64
func.return %26 : i64
^bb4:
cf.br ^bb5
^bb5:
%27 = arith.constant 0 : i32
%28 = arith.extsi %27 : i32 to i64
%29 = llvm.mlir.constant(1 : i64) : i64
%30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
llvm.store %28, %30 : i64, !llvm.ptr
cf.br ^bb6
^bb6:
%31 = llvm.load %20 : !llvm.ptr -> i64
%32 = arith.constant 0 : i32
%34 = arith.extsi %32 : i32 to i64
%33 = arith.cmpi sgt, %31, %34 : i64
cf.cond_br %33, ^bb7, ^bb8
^bb7:
%35 = llvm.load %30 : !llvm.ptr -> i64
%36 = arith.constant 1 : i32
%38 = arith.extsi %36 : i32 to i64
%37 = arith.addi %35, %38 : i64
llvm.store %37, %30 : i64, !llvm.ptr
%39 = llvm.load %20 : !llvm.ptr -> i64
%40 = arith.constant 10 : i32
%42 = arith.extsi %40 : i32 to i64
%41 = arith.divsi %39, %42 : i64
llvm.store %41, %20 : i64, !llvm.ptr
cf.br ^bb6
^bb8:
%43 = llvm.load %30 : !llvm.ptr -> i64
func.return %43 : i64
}
func.func @digit_at(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%44 = llvm.mlir.constant(1 : i64) : i64
%45 = llvm.alloca %44 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %45 : i64, !llvm.ptr
%46 = arith.constant 1 : i32
%48 = arith.extsi %46 : i32 to i64
%47 = arith.subi %arg2, %48 : i64
%49 = arith.subi %47, %arg1 : i64
%50 = llvm.mlir.constant(1 : i64) : i64
%51 = llvm.alloca %50 x i64 : (i64) -> !llvm.ptr
llvm.store %49, %51 : i64, !llvm.ptr
%52 = arith.constant 0 : i32
%53 = arith.extsi %52 : i32 to i64
%54 = llvm.mlir.constant(1 : i64) : i64
%55 = llvm.alloca %54 x i64 : (i64) -> !llvm.ptr
llvm.store %53, %55 : i64, !llvm.ptr
cf.br ^bb9
^bb9:
%56 = llvm.load %55 : !llvm.ptr -> i64
%57 = llvm.load %51 : !llvm.ptr -> i64
%58 = arith.cmpi slt, %56, %57 : i64
cf.cond_br %58, ^bb10, ^bb11
^bb10:
%59 = llvm.load %45 : !llvm.ptr -> i64
%60 = arith.constant 10 : i32
%62 = arith.extsi %60 : i32 to i64
%61 = arith.divsi %59, %62 : i64
llvm.store %61, %45 : i64, !llvm.ptr
%63 = llvm.load %55 : !llvm.ptr -> i64
%64 = arith.constant 1 : i32
%66 = arith.extsi %64 : i32 to i64
%65 = arith.addi %63, %66 : i64
llvm.store %65, %55 : i64, !llvm.ptr
cf.br ^bb9
^bb11:
%67 = llvm.load %45 : !llvm.ptr -> i64
%68 = arith.constant 10 : i32
%70 = arith.extsi %68 : i32 to i64
%69 = arith.remsi %67, %70 : i64
func.return %69 : i64
}
func.func @build_kmp(%arg0: !llvm.ptr, %arg1: i64, %arg2: !llvm.ptr, %arg3: !llvm.ptr) -> i32 {
%71 = arith.constant 0 : i32
%72 = arith.constant 0 : i32
%73 = arith.extsi %72 : i32 to i64
%74 = llvm.getelementptr %arg2[%73] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %71, %74 : i32, !llvm.ptr
%75 = arith.constant 0 : i32
%76 = arith.extsi %75 : i32 to i64
%77 = llvm.mlir.constant(1 : i64) : i64
%78 = llvm.alloca %77 x i64 : (i64) -> !llvm.ptr
llvm.store %76, %78 : i64, !llvm.ptr
%79 = arith.constant 1 : i32
%80 = arith.extsi %79 : i32 to i64
%81 = llvm.mlir.constant(1 : i64) : i64
%82 = llvm.alloca %81 x i64 : (i64) -> !llvm.ptr
llvm.store %80, %82 : i64, !llvm.ptr
cf.br ^bb12
^bb12:
%83 = llvm.load %82 : !llvm.ptr -> i64
%84 = arith.cmpi slt, %83, %arg1 : i64
cf.cond_br %84, ^bb13, ^bb14
^bb13:
cf.br ^bb15
^bb15:
%85 = llvm.load %78 : !llvm.ptr -> i64
%86 = arith.constant 0 : i32
%88 = arith.extsi %86 : i32 to i64
%87 = arith.cmpi sgt, %85, %88 : i64
%89 = scf.if %87 -> (i1) {
%91 = llvm.load %82 : !llvm.ptr -> i64
%92 = llvm.getelementptr %arg0[%91] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%90 = llvm.load %92 : !llvm.ptr -> i8
%94 = llvm.load %78 : !llvm.ptr -> i64
%95 = llvm.getelementptr %arg0[%94] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%93 = llvm.load %95 : !llvm.ptr -> i8
%97 = arith.extsi %90 : i8 to i32
%98 = arith.extsi %93 : i8 to i32
%96 = arith.cmpi ne, %97, %98 : i32
scf.yield %96 : i1
} else {
%99 = arith.constant false
scf.yield %99 : i1
}
cf.cond_br %89, ^bb16, ^bb17
^bb16:
%101 = llvm.load %78 : !llvm.ptr -> i64
%102 = arith.constant 1 : i32
%104 = arith.extsi %102 : i32 to i64
%103 = arith.subi %101, %104 : i64
%105 = llvm.getelementptr %arg2[%103] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%100 = llvm.load %105 : !llvm.ptr -> i32
%106 = arith.extsi %100 : i32 to i64
llvm.store %106, %78 : i64, !llvm.ptr
cf.br ^bb15
^bb17:
%108 = llvm.load %82 : !llvm.ptr -> i64
%109 = llvm.getelementptr %arg0[%108] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%107 = llvm.load %109 : !llvm.ptr -> i8
%111 = llvm.load %78 : !llvm.ptr -> i64
%112 = llvm.getelementptr %arg0[%111] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%110 = llvm.load %112 : !llvm.ptr -> i8
%114 = arith.extsi %107 : i8 to i32
%115 = arith.extsi %110 : i8 to i32
%113 = arith.cmpi eq, %114, %115 : i32
cf.cond_br %113, ^bb18, ^bb19
^bb18:
%116 = llvm.load %78 : !llvm.ptr -> i64
%117 = arith.constant 1 : i32
%119 = arith.extsi %117 : i32 to i64
%118 = arith.addi %116, %119 : i64
llvm.store %118, %78 : i64, !llvm.ptr
cf.br ^bb20
^bb19:
cf.br ^bb20
^bb20:
%120 = llvm.load %78 : !llvm.ptr -> i64
%121 = arith.trunci %120 : i64 to i32
%122 = llvm.load %82 : !llvm.ptr -> i64
%123 = llvm.getelementptr %arg2[%122] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %121, %123 : i32, !llvm.ptr
%124 = llvm.load %82 : !llvm.ptr -> i64
%125 = arith.constant 1 : i32
%127 = arith.extsi %125 : i32 to i64
%126 = arith.addi %124, %127 : i64
llvm.store %126, %82 : i64, !llvm.ptr
cf.br ^bb12
^bb14:
%128 = arith.constant 0 : i32
%129 = arith.extsi %128 : i32 to i64
%130 = llvm.mlir.constant(1 : i64) : i64
%131 = llvm.alloca %130 x i64 : (i64) -> !llvm.ptr
llvm.store %129, %131 : i64, !llvm.ptr
cf.br ^bb21
^bb21:
%132 = llvm.load %131 : !llvm.ptr -> i64
%133 = arith.cmpi slt, %132, %arg1 : i64
cf.cond_br %133, ^bb22, ^bb23
^bb22:
%134 = arith.constant 0 : i32
%135 = arith.extsi %134 : i32 to i64
%136 = llvm.mlir.constant(1 : i64) : i64
%137 = llvm.alloca %136 x i64 : (i64) -> !llvm.ptr
llvm.store %135, %137 : i64, !llvm.ptr
cf.br ^bb24
^bb24:
%138 = llvm.load %137 : !llvm.ptr -> i64
%139 = arith.constant 10 : i32
%141 = arith.extsi %139 : i32 to i64
%140 = arith.cmpi slt, %138, %141 : i64
cf.cond_br %140, ^bb25, ^bb26
^bb25:
%142 = llvm.load %131 : !llvm.ptr -> i64
%143 = llvm.mlir.constant(1 : i64) : i64
%144 = llvm.alloca %143 x i64 : (i64) -> !llvm.ptr
llvm.store %142, %144 : i64, !llvm.ptr
cf.br ^bb27
^bb27:
%145 = llvm.load %144 : !llvm.ptr -> i64
%146 = arith.constant 0 : i32
%148 = arith.extsi %146 : i32 to i64
%147 = arith.cmpi sgt, %145, %148 : i64
%149 = scf.if %147 -> (i1) {
%151 = llvm.load %144 : !llvm.ptr -> i64
%152 = llvm.getelementptr %arg0[%151] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%150 = llvm.load %152 : !llvm.ptr -> i8
%153 = arith.extsi %150 : i8 to i64
%154 = llvm.load %137 : !llvm.ptr -> i64
%155 = arith.cmpi ne, %153, %154 : i64
scf.yield %155 : i1
} else {
%156 = arith.constant false
scf.yield %156 : i1
}
cf.cond_br %149, ^bb28, ^bb29
^bb28:
%158 = llvm.load %144 : !llvm.ptr -> i64
%159 = arith.constant 1 : i32
%161 = arith.extsi %159 : i32 to i64
%160 = arith.subi %158, %161 : i64
%162 = llvm.getelementptr %arg2[%160] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%157 = llvm.load %162 : !llvm.ptr -> i32
%163 = arith.extsi %157 : i32 to i64
llvm.store %163, %144 : i64, !llvm.ptr
cf.br ^bb27
^bb29:
%165 = llvm.load %144 : !llvm.ptr -> i64
%166 = llvm.getelementptr %arg0[%165] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%164 = llvm.load %166 : !llvm.ptr -> i8
%167 = arith.extsi %164 : i8 to i64
%168 = llvm.load %137 : !llvm.ptr -> i64
%169 = arith.cmpi eq, %167, %168 : i64
cf.cond_br %169, ^bb30, ^bb31
^bb30:
%170 = llvm.load %144 : !llvm.ptr -> i64
%171 = arith.constant 1 : i32
%173 = arith.extsi %171 : i32 to i64
%172 = arith.addi %170, %173 : i64
llvm.store %172, %144 : i64, !llvm.ptr
cf.br ^bb32
^bb31:
cf.br ^bb32
^bb32:
%174 = arith.constant 0 : i32
%175 = arith.extsi %174 : i32 to i64
%176 = llvm.mlir.constant(1 : i64) : i64
%177 = llvm.alloca %176 x i64 : (i64) -> !llvm.ptr
llvm.store %175, %177 : i64, !llvm.ptr
%178 = llvm.load %144 : !llvm.ptr -> i64
%179 = arith.cmpi eq, %178, %arg1 : i64
cf.cond_br %179, ^bb33, ^bb34
^bb33:
%180 = arith.constant 1 : i32
%181 = arith.extsi %180 : i32 to i64
llvm.store %181, %177 : i64, !llvm.ptr
%183 = arith.constant 1 : i32
%185 = arith.extsi %183 : i32 to i64
%184 = arith.subi %arg1, %185 : i64
%186 = llvm.getelementptr %arg2[%184] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%182 = llvm.load %186 : !llvm.ptr -> i32
%187 = arith.extsi %182 : i32 to i64
llvm.store %187, %144 : i64, !llvm.ptr
cf.br ^bb35
^bb34:
cf.br ^bb35
^bb35:
%188 = llvm.load %144 : !llvm.ptr -> i64
%189 = llvm.load %177 : !llvm.ptr -> i64
%190 = arith.constant 16 : i32
%192 = arith.extsi %190 : i32 to i64
%191 = arith.shli %189, %192 : i64
%193 = arith.addi %188, %191 : i64
%194 = arith.trunci %193 : i64 to i32
%195 = llvm.load %131 : !llvm.ptr -> i64
%196 = arith.constant 10 : i32
%198 = arith.extsi %196 : i32 to i64
%197 = arith.muli %195, %198 : i64
%199 = llvm.load %137 : !llvm.ptr -> i64
%200 = arith.addi %197, %199 : i64
%201 = llvm.getelementptr %arg3[%200] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %194, %201 : i32, !llvm.ptr
%202 = llvm.load %137 : !llvm.ptr -> i64
%203 = arith.constant 1 : i32
%205 = arith.extsi %203 : i32 to i64
%204 = arith.addi %202, %205 : i64
llvm.store %204, %137 : i64, !llvm.ptr
cf.br ^bb24
^bb26:
%206 = llvm.load %131 : !llvm.ptr -> i64
%207 = arith.constant 1 : i32
%209 = arith.extsi %207 : i32 to i64
%208 = arith.addi %206, %209 : i64
llvm.store %208, %131 : i64, !llvm.ptr
cf.br ^bb21
^bb23:
%210 = arith.constant 0 : i32
func.return %210 : i32
}
func.func @step(%arg0: !llvm.ptr, %arg1: i64, %arg2: i64) -> i64 {
%212 = arith.constant 10 : i32
%214 = arith.extsi %212 : i32 to i64
%213 = arith.muli %arg1, %214 : i64
%215 = arith.addi %213, %arg2 : i64
%216 = llvm.getelementptr %arg0[%215] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%211 = llvm.load %216 : !llvm.ptr -> i32
%217 = arith.extsi %211 : i32 to i64
func.return %217 : i64
}
func.func @count_arith(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64) -> i64 {
%218 = arith.cmpi slt, %arg1, %arg0 : i64
cf.cond_br %218, ^bb36, ^bb37
^bb36:
%219 = arith.constant 0 : i32
%220 = arith.extsi %219 : i32 to i64
func.return %220 : i64
^bb37:
cf.br ^bb38
^bb38:
%221 = arith.remsi %arg0, %arg2 : i64
%222 = arith.subi %arg3, %221 : i64
%223 = arith.addi %222, %arg2 : i64
%224 = arith.remsi %223, %arg2 : i64
%225 = arith.addi %arg0, %224 : i64
%226 = llvm.mlir.constant(1 : i64) : i64
%227 = llvm.alloca %226 x i64 : (i64) -> !llvm.ptr
llvm.store %225, %227 : i64, !llvm.ptr
%228 = llvm.load %227 : !llvm.ptr -> i64
%229 = arith.cmpi sgt, %228, %arg1 : i64
cf.cond_br %229, ^bb39, ^bb40
^bb39:
%230 = arith.constant 0 : i32
%231 = arith.extsi %230 : i32 to i64
func.return %231 : i64
^bb40:
cf.br ^bb41
^bb41:
%232 = llvm.load %227 : !llvm.ptr -> i64
%233 = arith.subi %arg1, %232 : i64
%234 = arith.divsi %233, %arg2 : i64
%235 = arith.constant 1 : i32
%237 = arith.extsi %235 : i32 to i64
%236 = arith.addi %234, %237 : i64
func.return %236 : i64
}
func.func @prefix_to_N(%arg0: i64, %arg1: !llvm.ptr, %arg2: !llvm.ptr) -> i32 {
%238 = arith.constant 0 : i32
%240 = arith.extsi %238 : i32 to i64
%239 = arith.cmpi sle, %arg0, %240 : i64
cf.cond_br %239, ^bb42, ^bb43
^bb42:
%241 = arith.constant 0 : i32
%242 = arith.constant 0 : i32
%243 = arith.extsi %241 : i32 to i64
%244 = arith.extsi %242 : i32 to i64
%245 = llvm.getelementptr %arg1[%244] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %243, %245 : i64, !llvm.ptr
%246 = arith.constant 0 : i32
%247 = arith.constant 0 : i32
%248 = arith.extsi %246 : i32 to i64
%249 = arith.extsi %247 : i32 to i64
%250 = llvm.getelementptr %arg2[%249] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %248, %250 : i64, !llvm.ptr
%251 = arith.constant 0 : i32
func.return %251 : i32
^bb43:
cf.br ^bb44
^bb44:
%252 = arith.constant 0 : i32
%253 = arith.extsi %252 : i32 to i64
%254 = llvm.mlir.constant(1 : i64) : i64
%255 = llvm.alloca %254 x i64 : (i64) -> !llvm.ptr
llvm.store %253, %255 : i64, !llvm.ptr
%256 = arith.constant 1 : i32
%257 = arith.extsi %256 : i32 to i64
%258 = llvm.mlir.constant(1 : i64) : i64
%259 = llvm.alloca %258 x i64 : (i64) -> !llvm.ptr
llvm.store %257, %259 : i64, !llvm.ptr
%260 = arith.constant 1 : i32
%261 = arith.extsi %260 : i32 to i64
%262 = llvm.mlir.constant(1 : i64) : i64
%263 = llvm.alloca %262 x i64 : (i64) -> !llvm.ptr
llvm.store %261, %263 : i64, !llvm.ptr
cf.br ^bb45
^bb45:
%264 = arith.constant 1 : i1
cf.cond_br %264, ^bb46, ^bb47
^bb46:
%265 = arith.constant 9 : i32
%266 = llvm.load %263 : !llvm.ptr -> i64
%268 = arith.extsi %265 : i32 to i64
%267 = arith.muli %268, %266 : i64
%269 = llvm.load %259 : !llvm.ptr -> i64
%270 = arith.muli %267, %269 : i64
%271 = llvm.load %255 : !llvm.ptr -> i64
%272 = arith.addi %271, %270 : i64
%273 = arith.cmpi slt, %272, %arg0 : i64
cf.cond_br %273, ^bb48, ^bb49
^bb48:
%274 = llvm.load %255 : !llvm.ptr -> i64
%275 = arith.addi %274, %270 : i64
llvm.store %275, %255 : i64, !llvm.ptr
%276 = llvm.load %259 : !llvm.ptr -> i64
%277 = arith.constant 1 : i32
%279 = arith.extsi %277 : i32 to i64
%278 = arith.addi %276, %279 : i64
llvm.store %278, %259 : i64, !llvm.ptr
%280 = llvm.load %263 : !llvm.ptr -> i64
%281 = arith.constant 10 : i32
%283 = arith.extsi %281 : i32 to i64
%282 = arith.muli %280, %283 : i64
llvm.store %282, %263 : i64, !llvm.ptr
cf.br ^bb50
^bb49:
%284 = llvm.load %255 : !llvm.ptr -> i64
%285 = arith.subi %arg0, %284 : i64
%286 = llvm.load %259 : !llvm.ptr -> i64
%287 = arith.divsi %285, %286 : i64
%288 = llvm.load %259 : !llvm.ptr -> i64
%289 = arith.remsi %285, %288 : i64
%290 = llvm.load %263 : !llvm.ptr -> i64
%291 = arith.constant 1 : i32
%293 = arith.extsi %291 : i32 to i64
%292 = arith.subi %290, %293 : i64
%294 = arith.addi %292, %287 : i64
%295 = arith.constant 0 : i32
%296 = arith.extsi %295 : i32 to i64
%297 = llvm.getelementptr %arg1[%296] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %294, %297 : i64, !llvm.ptr
%298 = arith.constant 0 : i32
%299 = arith.extsi %298 : i32 to i64
%300 = llvm.getelementptr %arg2[%299] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %289, %300 : i64, !llvm.ptr
%301 = arith.constant 0 : i32
func.return %301 : i32
^bb50:
cf.br ^bb45
^bb47:
%302 = arith.constant 0 : i32
func.return %302 : i32
}
func.func @internal_len_d(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr) -> i64 {
%304 = arith.constant 8 : i32
%305 = arith.extsi %304 : i32 to i64
%303 = func.call @calloc(%arg1, %305) : (i64, i64) -> !llvm.ptr
%307 = arith.constant 8 : i32
%308 = arith.extsi %307 : i32 to i64
%306 = func.call @calloc(%arg1, %308) : (i64, i64) -> !llvm.ptr
%309 = arith.constant 1 : i32
%310 = arith.extsi %309 : i32 to i64
%311 = llvm.mlir.constant(1 : i64) : i64
%312 = llvm.alloca %311 x i64 : (i64) -> !llvm.ptr
llvm.store %310, %312 : i64, !llvm.ptr
cf.br ^bb51
^bb51:
%313 = llvm.load %312 : !llvm.ptr -> i64
%314 = arith.constant 9 : i32
%316 = arith.extsi %314 : i32 to i64
%315 = arith.cmpi sle, %313, %316 : i64
cf.cond_br %315, ^bb52, ^bb53
^bb52:
%318 = arith.constant 0 : i32
%319 = llvm.load %312 : !llvm.ptr -> i64
%320 = arith.extsi %318 : i32 to i64
%317 = func.call @step(%arg2, %320, %319) : (!llvm.ptr, i64, i64) -> i64
%321 = arith.constant 65535 : i32
%323 = arith.extsi %321 : i32 to i64
%322 = arith.andi %317, %323 : i64
%324 = arith.constant 16 : i32
%326 = arith.extsi %324 : i32 to i64
%325 = arith.shrsi %317, %326 : i64
%328 = llvm.getelementptr %303[%322] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%327 = llvm.load %328 : !llvm.ptr -> i64
%329 = arith.constant 1 : i32
%331 = arith.extsi %329 : i32 to i64
%330 = arith.addi %327, %331 : i64
%332 = llvm.getelementptr %303[%322] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %330, %332 : i64, !llvm.ptr
%334 = llvm.getelementptr %306[%322] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%333 = llvm.load %334 : !llvm.ptr -> i64
%335 = arith.addi %333, %325 : i64
%336 = llvm.getelementptr %306[%322] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %335, %336 : i64, !llvm.ptr
%337 = llvm.load %312 : !llvm.ptr -> i64
%338 = arith.constant 1 : i32
%340 = arith.extsi %338 : i32 to i64
%339 = arith.addi %337, %340 : i64
llvm.store %339, %312 : i64, !llvm.ptr
cf.br ^bb51
^bb53:
%341 = arith.constant 1 : i32
%342 = arith.extsi %341 : i32 to i64
%343 = llvm.mlir.constant(1 : i64) : i64
%344 = llvm.alloca %343 x i64 : (i64) -> !llvm.ptr
llvm.store %342, %344 : i64, !llvm.ptr
cf.br ^bb54(%303, %306 : !llvm.ptr, !llvm.ptr)
^bb54(%345: !llvm.ptr, %346: !llvm.ptr):
%347 = llvm.load %344 : !llvm.ptr -> i64
%348 = arith.cmpi slt, %347, %arg0 : i64
cf.cond_br %348, ^bb55(%345, %346 : !llvm.ptr, !llvm.ptr), ^bb56(%345, %346 : !llvm.ptr, !llvm.ptr)
^bb55(%349: !llvm.ptr, %350: !llvm.ptr):
%352 = arith.constant 8 : i32
%353 = arith.extsi %352 : i32 to i64
%351 = func.call @calloc(%arg1, %353) : (i64, i64) -> !llvm.ptr
%355 = arith.constant 8 : i32
%356 = arith.extsi %355 : i32 to i64
%354 = func.call @calloc(%arg1, %356) : (i64, i64) -> !llvm.ptr
%357 = arith.constant 0 : i32
%358 = arith.extsi %357 : i32 to i64
%359 = llvm.mlir.constant(1 : i64) : i64
%360 = llvm.alloca %359 x i64 : (i64) -> !llvm.ptr
llvm.store %358, %360 : i64, !llvm.ptr
cf.br ^bb57
^bb57:
%361 = llvm.load %360 : !llvm.ptr -> i64
%362 = arith.cmpi slt, %361, %arg1 : i64
cf.cond_br %362, ^bb58, ^bb59
^bb58:
%364 = llvm.load %360 : !llvm.ptr -> i64
%365 = llvm.getelementptr %349[%364] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%363 = llvm.load %365 : !llvm.ptr -> i64
%366 = arith.constant 0 : i32
%368 = arith.extsi %366 : i32 to i64
%367 = arith.cmpi ne, %363, %368 : i64
cf.cond_br %367, ^bb60, ^bb61
^bb60:
%370 = llvm.load %360 : !llvm.ptr -> i64
%371 = llvm.getelementptr %350[%370] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%369 = llvm.load %371 : !llvm.ptr -> i64
%372 = arith.constant 0 : i32
%373 = arith.extsi %372 : i32 to i64
llvm.store %373, %312 : i64, !llvm.ptr
cf.br ^bb63
^bb63:
%374 = llvm.load %312 : !llvm.ptr -> i64
%375 = arith.constant 10 : i32
%377 = arith.extsi %375 : i32 to i64
%376 = arith.cmpi slt, %374, %377 : i64
cf.cond_br %376, ^bb64, ^bb65
^bb64:
%379 = llvm.load %360 : !llvm.ptr -> i64
%380 = llvm.load %312 : !llvm.ptr -> i64
%378 = func.call @step(%arg2, %379, %380) : (!llvm.ptr, i64, i64) -> i64
%381 = arith.constant 65535 : i32
%383 = arith.extsi %381 : i32 to i64
%382 = arith.andi %378, %383 : i64
%384 = arith.constant 16 : i32
%386 = arith.extsi %384 : i32 to i64
%385 = arith.shrsi %378, %386 : i64
%388 = llvm.getelementptr %351[%382] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%387 = llvm.load %388 : !llvm.ptr -> i64
%389 = arith.addi %387, %363 : i64
%390 = llvm.getelementptr %351[%382] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %389, %390 : i64, !llvm.ptr
%392 = llvm.getelementptr %354[%382] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%391 = llvm.load %392 : !llvm.ptr -> i64
%393 = arith.addi %391, %369 : i64
%394 = arith.muli %363, %385 : i64
%395 = arith.addi %393, %394 : i64
%396 = llvm.getelementptr %354[%382] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %395, %396 : i64, !llvm.ptr
%397 = llvm.load %312 : !llvm.ptr -> i64
%398 = arith.constant 1 : i32
%400 = arith.extsi %398 : i32 to i64
%399 = arith.addi %397, %400 : i64
llvm.store %399, %312 : i64, !llvm.ptr
cf.br ^bb63
^bb65:
cf.br ^bb62
^bb61:
cf.br ^bb62
^bb62:
%401 = llvm.load %360 : !llvm.ptr -> i64
%402 = arith.constant 1 : i32
%404 = arith.extsi %402 : i32 to i64
%403 = arith.addi %401, %404 : i64
llvm.store %403, %360 : i64, !llvm.ptr
cf.br ^bb57
^bb59:
func.call @free(%349) : (!llvm.ptr) -> ()
func.call @free(%350) : (!llvm.ptr) -> ()
%407 = llvm.load %344 : !llvm.ptr -> i64
%408 = arith.constant 1 : i32
%410 = arith.extsi %408 : i32 to i64
%409 = arith.addi %407, %410 : i64
llvm.store %409, %344 : i64, !llvm.ptr
cf.br ^bb54(%351, %354 : !llvm.ptr, !llvm.ptr)
^bb56(%411: !llvm.ptr, %412: !llvm.ptr):
%413 = arith.constant 0 : i32
%414 = arith.extsi %413 : i32 to i64
%415 = llvm.mlir.constant(1 : i64) : i64
%416 = llvm.alloca %415 x i64 : (i64) -> !llvm.ptr
llvm.store %414, %416 : i64, !llvm.ptr
%417 = arith.constant 0 : i32
%418 = arith.extsi %417 : i32 to i64
%419 = llvm.mlir.constant(1 : i64) : i64
%420 = llvm.alloca %419 x i64 : (i64) -> !llvm.ptr
llvm.store %418, %420 : i64, !llvm.ptr
cf.br ^bb66
^bb66:
%421 = llvm.load %420 : !llvm.ptr -> i64
%422 = arith.cmpi slt, %421, %arg1 : i64
cf.cond_br %422, ^bb67, ^bb68
^bb67:
%423 = llvm.load %416 : !llvm.ptr -> i64
%425 = llvm.load %420 : !llvm.ptr -> i64
%426 = llvm.getelementptr %412[%425] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%424 = llvm.load %426 : !llvm.ptr -> i64
%427 = arith.addi %423, %424 : i64
llvm.store %427, %416 : i64, !llvm.ptr
%428 = llvm.load %420 : !llvm.ptr -> i64
%429 = arith.constant 1 : i32
%431 = arith.extsi %429 : i32 to i64
%430 = arith.addi %428, %431 : i64
llvm.store %430, %420 : i64, !llvm.ptr
cf.br ^bb66
^bb68:
func.call @free(%411) : (!llvm.ptr) -> ()
func.call @free(%412) : (!llvm.ptr) -> ()
%434 = llvm.load %416 : !llvm.ptr -> i64
func.return %434 : i64
}
func.func @internal_upto(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr, %arg3: !llvm.ptr) -> i64 {
%435 = arith.constant 0 : i32
%437 = arith.extsi %435 : i32 to i64
%436 = arith.cmpi sle, %arg0, %437 : i64
cf.cond_br %436, ^bb69, ^bb70
^bb69:
%438 = arith.constant 0 : i32
%439 = arith.extsi %438 : i32 to i64
func.return %439 : i64
^bb70:
cf.br ^bb71
^bb71:
%440 = func.call @num_digits(%arg0) : (i64) -> i64
%441 = arith.constant 0 : i32
%442 = arith.extsi %441 : i32 to i64
%443 = llvm.mlir.constant(1 : i64) : i64
%444 = llvm.alloca %443 x i64 : (i64) -> !llvm.ptr
llvm.store %442, %444 : i64, !llvm.ptr
%445 = arith.constant 1 : i32
%446 = arith.extsi %445 : i32 to i64
%447 = llvm.mlir.constant(1 : i64) : i64
%448 = llvm.alloca %447 x i64 : (i64) -> !llvm.ptr
llvm.store %446, %448 : i64, !llvm.ptr
cf.br ^bb72
^bb72:
%449 = llvm.load %448 : !llvm.ptr -> i64
%450 = arith.cmpi slt, %449, %440 : i64
cf.cond_br %450, ^bb73, ^bb74
^bb73:
%451 = llvm.load %444 : !llvm.ptr -> i64
%453 = llvm.load %448 : !llvm.ptr -> i64
%454 = llvm.getelementptr %arg3[%453] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%452 = llvm.load %454 : !llvm.ptr -> i64
%455 = arith.addi %451, %452 : i64
llvm.store %455, %444 : i64, !llvm.ptr
%456 = llvm.load %448 : !llvm.ptr -> i64
%457 = arith.constant 1 : i32
%459 = arith.extsi %457 : i32 to i64
%458 = arith.addi %456, %459 : i64
llvm.store %458, %448 : i64, !llvm.ptr
cf.br ^bb72
^bb74:
%461 = arith.constant 8 : i32
%462 = arith.extsi %461 : i32 to i64
%460 = func.call @calloc(%arg1, %462) : (i64, i64) -> !llvm.ptr
%464 = arith.constant 8 : i32
%465 = arith.extsi %464 : i32 to i64
%463 = func.call @calloc(%arg1, %465) : (i64, i64) -> !llvm.ptr
%467 = arith.constant 8 : i32
%468 = arith.extsi %467 : i32 to i64
%466 = func.call @calloc(%arg1, %468) : (i64, i64) -> !llvm.ptr
%470 = arith.constant 8 : i32
%471 = arith.extsi %470 : i32 to i64
%469 = func.call @calloc(%arg1, %471) : (i64, i64) -> !llvm.ptr
%472 = arith.constant 1 : i32
%473 = arith.constant 0 : i32
%474 = arith.extsi %472 : i32 to i64
%475 = arith.extsi %473 : i32 to i64
%476 = llvm.getelementptr %460[%475] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %474, %476 : i64, !llvm.ptr
%477 = arith.constant 0 : i32
%478 = arith.extsi %477 : i32 to i64
%479 = llvm.mlir.constant(1 : i64) : i64
%480 = llvm.alloca %479 x i64 : (i64) -> !llvm.ptr
llvm.store %478, %480 : i64, !llvm.ptr
cf.br ^bb75(%460, %463, %466, %469 : !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr)
^bb75(%481: !llvm.ptr, %482: !llvm.ptr, %483: !llvm.ptr, %484: !llvm.ptr):
%485 = llvm.load %480 : !llvm.ptr -> i64
%486 = arith.cmpi slt, %485, %440 : i64
cf.cond_br %486, ^bb76(%481, %482, %483, %484 : !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr), ^bb77(%481, %482, %483, %484 : !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr)
^bb76(%487: !llvm.ptr, %488: !llvm.ptr, %489: !llvm.ptr, %490: !llvm.ptr):
%492 = llvm.load %480 : !llvm.ptr -> i64
%491 = func.call @digit_at(%arg0, %492, %440) : (i64, i64, i64) -> i64
%494 = arith.constant 8 : i32
%495 = arith.extsi %494 : i32 to i64
%493 = func.call @calloc(%arg1, %495) : (i64, i64) -> !llvm.ptr
%497 = arith.constant 8 : i32
%498 = arith.extsi %497 : i32 to i64
%496 = func.call @calloc(%arg1, %498) : (i64, i64) -> !llvm.ptr
%500 = arith.constant 8 : i32
%501 = arith.extsi %500 : i32 to i64
%499 = func.call @calloc(%arg1, %501) : (i64, i64) -> !llvm.ptr
%503 = arith.constant 8 : i32
%504 = arith.extsi %503 : i32 to i64
%502 = func.call @calloc(%arg1, %504) : (i64, i64) -> !llvm.ptr
%505 = arith.constant 0 : i32
%506 = arith.extsi %505 : i32 to i64
%507 = llvm.load %480 : !llvm.ptr -> i64
%508 = arith.constant 0 : i32
%510 = arith.extsi %508 : i32 to i64
%509 = arith.cmpi eq, %507, %510 : i64
%511 = scf.if %509 -> (i64) {
%512 = arith.constant 1 : i32
%513 = arith.extsi %512 : i32 to i64
scf.yield %513 : i64
} else {
scf.yield %506 : i64
}
%514 = arith.constant 0 : i32
%515 = arith.extsi %514 : i32 to i64
%516 = llvm.mlir.constant(1 : i64) : i64
%517 = llvm.alloca %516 x i64 : (i64) -> !llvm.ptr
llvm.store %515, %517 : i64, !llvm.ptr
cf.br ^bb78
^bb78:
%518 = llvm.load %517 : !llvm.ptr -> i64
%519 = arith.cmpi slt, %518, %arg1 : i64
cf.cond_br %519, ^bb79, ^bb80
^bb79:
%521 = llvm.load %517 : !llvm.ptr -> i64
%522 = llvm.getelementptr %487[%521] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%520 = llvm.load %522 : !llvm.ptr -> i64
%523 = arith.constant 0 : i32
%525 = arith.extsi %523 : i32 to i64
%524 = arith.cmpi ne, %520, %525 : i64
cf.cond_br %524, ^bb81, ^bb82
^bb81:
%527 = llvm.load %517 : !llvm.ptr -> i64
%528 = llvm.getelementptr %488[%527] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%526 = llvm.load %528 : !llvm.ptr -> i64
%529 = llvm.mlir.constant(1 : i64) : i64
%530 = llvm.alloca %529 x i64 : (i64) -> !llvm.ptr
llvm.store %511, %530 : i64, !llvm.ptr
cf.br ^bb84
^bb84:
%531 = llvm.load %530 : !llvm.ptr -> i64
%532 = arith.cmpi sle, %531, %491 : i64
cf.cond_br %532, ^bb85, ^bb86
^bb85:
%534 = llvm.load %517 : !llvm.ptr -> i64
%535 = llvm.load %530 : !llvm.ptr -> i64
%533 = func.call @step(%arg2, %534, %535) : (!llvm.ptr, i64, i64) -> i64
%536 = arith.constant 65535 : i32
%538 = arith.extsi %536 : i32 to i64
%537 = arith.andi %533, %538 : i64
%539 = arith.constant 16 : i32
%541 = arith.extsi %539 : i32 to i64
%540 = arith.shrsi %533, %541 : i64
%542 = llvm.load %530 : !llvm.ptr -> i64
%543 = arith.cmpi eq, %542, %491 : i64
cf.cond_br %543, ^bb87, ^bb88
^bb87:
%545 = llvm.getelementptr %493[%537] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%544 = llvm.load %545 : !llvm.ptr -> i64
%546 = arith.addi %544, %520 : i64
%547 = llvm.getelementptr %493[%537] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %546, %547 : i64, !llvm.ptr
%549 = llvm.getelementptr %496[%537] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%548 = llvm.load %549 : !llvm.ptr -> i64
%550 = arith.addi %548, %526 : i64
%551 = arith.muli %520, %540 : i64
%552 = arith.addi %550, %551 : i64
%553 = llvm.getelementptr %496[%537] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %552, %553 : i64, !llvm.ptr
cf.br ^bb89
^bb88:
%555 = llvm.getelementptr %499[%537] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%554 = llvm.load %555 : !llvm.ptr -> i64
%556 = arith.addi %554, %520 : i64
%557 = llvm.getelementptr %499[%537] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %556, %557 : i64, !llvm.ptr
%559 = llvm.getelementptr %502[%537] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%558 = llvm.load %559 : !llvm.ptr -> i64
%560 = arith.addi %558, %526 : i64
%561 = arith.muli %520, %540 : i64
%562 = arith.addi %560, %561 : i64
%563 = llvm.getelementptr %502[%537] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %562, %563 : i64, !llvm.ptr
cf.br ^bb89
^bb89:
%564 = llvm.load %530 : !llvm.ptr -> i64
%565 = arith.constant 1 : i32
%567 = arith.extsi %565 : i32 to i64
%566 = arith.addi %564, %567 : i64
llvm.store %566, %530 : i64, !llvm.ptr
cf.br ^bb84
^bb86:
cf.br ^bb83
^bb82:
cf.br ^bb83
^bb83:
%568 = llvm.load %517 : !llvm.ptr -> i64
%569 = arith.constant 1 : i32
%571 = arith.extsi %569 : i32 to i64
%570 = arith.addi %568, %571 : i64
llvm.store %570, %517 : i64, !llvm.ptr
cf.br ^bb78
^bb80:
%572 = arith.constant 0 : i32
%573 = arith.extsi %572 : i32 to i64
llvm.store %573, %517 : i64, !llvm.ptr
cf.br ^bb90
^bb90:
%574 = llvm.load %517 : !llvm.ptr -> i64
%575 = arith.cmpi slt, %574, %arg1 : i64
cf.cond_br %575, ^bb91, ^bb92
^bb91:
%577 = llvm.load %517 : !llvm.ptr -> i64
%578 = llvm.getelementptr %489[%577] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%576 = llvm.load %578 : !llvm.ptr -> i64
%579 = arith.constant 0 : i32
%581 = arith.extsi %579 : i32 to i64
%580 = arith.cmpi ne, %576, %581 : i64
cf.cond_br %580, ^bb93, ^bb94
^bb93:
%583 = llvm.load %517 : !llvm.ptr -> i64
%584 = llvm.getelementptr %490[%583] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%582 = llvm.load %584 : !llvm.ptr -> i64
%585 = llvm.mlir.constant(1 : i64) : i64
%586 = llvm.alloca %585 x i64 : (i64) -> !llvm.ptr
llvm.store %511, %586 : i64, !llvm.ptr
%587 = llvm.load %480 : !llvm.ptr -> i64
%588 = arith.constant 0 : i32
%590 = arith.extsi %588 : i32 to i64
%589 = arith.cmpi ne, %587, %590 : i64
cf.cond_br %589, ^bb96, ^bb97
^bb96:
%591 = arith.constant 0 : i32
%592 = arith.extsi %591 : i32 to i64
llvm.store %592, %586 : i64, !llvm.ptr
cf.br ^bb98
^bb97:
cf.br ^bb98
^bb98:
cf.br ^bb99
^bb99:
%593 = llvm.load %586 : !llvm.ptr -> i64
%594 = arith.constant 9 : i32
%596 = arith.extsi %594 : i32 to i64
%595 = arith.cmpi sle, %593, %596 : i64
cf.cond_br %595, ^bb100, ^bb101
^bb100:
%598 = llvm.load %517 : !llvm.ptr -> i64
%599 = llvm.load %586 : !llvm.ptr -> i64
%597 = func.call @step(%arg2, %598, %599) : (!llvm.ptr, i64, i64) -> i64
%600 = arith.constant 65535 : i32
%602 = arith.extsi %600 : i32 to i64
%601 = arith.andi %597, %602 : i64
%603 = arith.constant 16 : i32
%605 = arith.extsi %603 : i32 to i64
%604 = arith.shrsi %597, %605 : i64
%607 = llvm.getelementptr %499[%601] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%606 = llvm.load %607 : !llvm.ptr -> i64
%608 = arith.addi %606, %576 : i64
%609 = llvm.getelementptr %499[%601] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %608, %609 : i64, !llvm.ptr
%611 = llvm.getelementptr %502[%601] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%610 = llvm.load %611 : !llvm.ptr -> i64
%612 = arith.addi %610, %582 : i64
%613 = arith.muli %576, %604 : i64
%614 = arith.addi %612, %613 : i64
%615 = llvm.getelementptr %502[%601] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %614, %615 : i64, !llvm.ptr
%616 = llvm.load %586 : !llvm.ptr -> i64
%617 = arith.constant 1 : i32
%619 = arith.extsi %617 : i32 to i64
%618 = arith.addi %616, %619 : i64
llvm.store %618, %586 : i64, !llvm.ptr
cf.br ^bb99
^bb101:
cf.br ^bb95
^bb94:
cf.br ^bb95
^bb95:
%620 = llvm.load %517 : !llvm.ptr -> i64
%621 = arith.constant 1 : i32
%623 = arith.extsi %621 : i32 to i64
%622 = arith.addi %620, %623 : i64
llvm.store %622, %517 : i64, !llvm.ptr
cf.br ^bb90
^bb92:
func.call @free(%487) : (!llvm.ptr) -> ()
func.call @free(%488) : (!llvm.ptr) -> ()
func.call @free(%489) : (!llvm.ptr) -> ()
func.call @free(%490) : (!llvm.ptr) -> ()
%628 = llvm.load %480 : !llvm.ptr -> i64
%629 = arith.constant 1 : i32
%631 = arith.extsi %629 : i32 to i64
%630 = arith.addi %628, %631 : i64
llvm.store %630, %480 : i64, !llvm.ptr
cf.br ^bb75(%493, %496, %499, %502 : !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr)
^bb77(%632: !llvm.ptr, %633: !llvm.ptr, %634: !llvm.ptr, %635: !llvm.ptr):
%636 = arith.constant 0 : i32
%637 = arith.extsi %636 : i32 to i64
%638 = llvm.mlir.constant(1 : i64) : i64
%639 = llvm.alloca %638 x i64 : (i64) -> !llvm.ptr
llvm.store %637, %639 : i64, !llvm.ptr
cf.br ^bb102
^bb102:
%640 = llvm.load %639 : !llvm.ptr -> i64
%641 = arith.cmpi slt, %640, %arg1 : i64
cf.cond_br %641, ^bb103, ^bb104
^bb103:
%642 = llvm.load %444 : !llvm.ptr -> i64
%644 = llvm.load %639 : !llvm.ptr -> i64
%645 = llvm.getelementptr %633[%644] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%643 = llvm.load %645 : !llvm.ptr -> i64
%646 = arith.addi %642, %643 : i64
%648 = llvm.load %639 : !llvm.ptr -> i64
%649 = llvm.getelementptr %635[%648] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%647 = llvm.load %649 : !llvm.ptr -> i64
%650 = arith.addi %646, %647 : i64
llvm.store %650, %444 : i64, !llvm.ptr
%651 = llvm.load %639 : !llvm.ptr -> i64
%652 = arith.constant 1 : i32
%654 = arith.extsi %652 : i32 to i64
%653 = arith.addi %651, %654 : i64
llvm.store %653, %639 : i64, !llvm.ptr
cf.br ^bb102
^bb104:
func.call @free(%632) : (!llvm.ptr) -> ()
func.call @free(%633) : (!llvm.ptr) -> ()
func.call @free(%634) : (!llvm.ptr) -> ()
func.call @free(%635) : (!llvm.ptr) -> ()
%659 = llvm.load %444 : !llvm.ptr -> i64
func.return %659 : i64
}
func.func @fill_pat(%arg0: i64, %arg1: !llvm.ptr, %arg2: i64) -> i32 {
%660 = arith.constant 0 : i32
%661 = arith.extsi %660 : i32 to i64
%662 = llvm.mlir.constant(1 : i64) : i64
%663 = llvm.alloca %662 x i64 : (i64) -> !llvm.ptr
llvm.store %661, %663 : i64, !llvm.ptr
cf.br ^bb105
^bb105:
%664 = llvm.load %663 : !llvm.ptr -> i64
%665 = arith.cmpi slt, %664, %arg2 : i64
cf.cond_br %665, ^bb106, ^bb107
^bb106:
%667 = llvm.load %663 : !llvm.ptr -> i64
%666 = func.call @digit_at(%arg0, %667, %arg2) : (i64, i64, i64) -> i64
%668 = arith.trunci %666 : i64 to i8
%669 = llvm.load %663 : !llvm.ptr -> i64
%670 = llvm.getelementptr %arg1[%669] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %668, %670 : i8, !llvm.ptr
%671 = llvm.load %663 : !llvm.ptr -> i64
%672 = arith.constant 1 : i32
%674 = arith.extsi %672 : i32 to i64
%673 = arith.addi %671, %674 : i64
llvm.store %673, %663 : i64, !llvm.ptr
cf.br ^bb105
^bb107:
%675 = arith.constant 0 : i32
func.return %675 : i32
}
func.func @boundary_upto(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr) -> i64 {
%676 = arith.constant 1 : i32
%678 = arith.extsi %676 : i32 to i64
%677 = arith.cmpi sle, %arg1, %678 : i64
%679 = scf.if %677 -> (i1) {
%680 = arith.constant true
scf.yield %680 : i1
} else {
%681 = arith.constant 1 : i32
%683 = arith.extsi %681 : i32 to i64
%682 = arith.cmpi sle, %arg0, %683 : i64
scf.yield %682 : i1
}
cf.cond_br %679, ^bb108, ^bb109
^bb108:
%684 = arith.constant 0 : i32
%685 = arith.extsi %684 : i32 to i64
func.return %685 : i64
^bb109:
cf.br ^bb110
^bb110:
%686 = arith.constant 0 : i32
%687 = arith.extsi %686 : i32 to i64
%688 = llvm.mlir.constant(1 : i64) : i64
%689 = llvm.alloca %688 x i64 : (i64) -> !llvm.ptr
llvm.store %687, %689 : i64, !llvm.ptr
%691 = arith.constant 1 : i32
%693 = arith.extsi %691 : i32 to i64
%692 = arith.subi %arg0, %693 : i64
%690 = func.call @num_digits(%692) : (i64) -> i64
%694 = arith.constant 1 : i32
%695 = arith.extsi %694 : i32 to i64
%696 = llvm.mlir.constant(1 : i64) : i64
%697 = llvm.alloca %696 x i64 : (i64) -> !llvm.ptr
llvm.store %695, %697 : i64, !llvm.ptr
cf.br ^bb111
^bb111:
%698 = llvm.load %697 : !llvm.ptr -> i64
%699 = arith.cmpi slt, %698, %arg1 : i64
cf.cond_br %699, ^bb112, ^bb113
^bb112:
%701 = llvm.load %697 : !llvm.ptr -> i64
%702 = llvm.getelementptr %arg2[%701] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%700 = llvm.load %702 : !llvm.ptr -> i8
%703 = arith.constant 0 : i32
%705 = arith.extsi %700 : i8 to i32
%704 = arith.cmpi eq, %705, %703 : i32
cf.cond_br %704, ^bb114, ^bb115
^bb114:
%706 = llvm.load %697 : !llvm.ptr -> i64
%707 = arith.constant 1 : i32
%709 = arith.extsi %707 : i32 to i64
%708 = arith.addi %706, %709 : i64
llvm.store %708, %697 : i64, !llvm.ptr
cf.br ^bb111
^bb115:
cf.br ^bb116
^bb116:
%710 = arith.constant 0 : i32
%711 = arith.extsi %710 : i32 to i64
%712 = llvm.mlir.constant(1 : i64) : i64
%713 = llvm.alloca %712 x i64 : (i64) -> !llvm.ptr
llvm.store %711, %713 : i64, !llvm.ptr
%714 = arith.constant 0 : i32
%715 = arith.extsi %714 : i32 to i64
%716 = llvm.mlir.constant(1 : i64) : i64
%717 = llvm.alloca %716 x i64 : (i64) -> !llvm.ptr
llvm.store %715, %717 : i64, !llvm.ptr
cf.br ^bb117
^bb117:
%718 = llvm.load %717 : !llvm.ptr -> i64
%719 = llvm.load %697 : !llvm.ptr -> i64
%720 = arith.cmpi slt, %718, %719 : i64
cf.cond_br %720, ^bb118, ^bb119
^bb118:
%721 = llvm.load %713 : !llvm.ptr -> i64
%722 = arith.constant 10 : i32
%724 = arith.extsi %722 : i32 to i64
%723 = arith.muli %721, %724 : i64
%726 = llvm.load %717 : !llvm.ptr -> i64
%727 = llvm.getelementptr %arg2[%726] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%725 = llvm.load %727 : !llvm.ptr -> i8
%728 = arith.extsi %725 : i8 to i64
%729 = arith.addi %723, %728 : i64
llvm.store %729, %713 : i64, !llvm.ptr
%730 = llvm.load %717 : !llvm.ptr -> i64
%731 = arith.constant 1 : i32
%733 = arith.extsi %731 : i32 to i64
%732 = arith.addi %730, %733 : i64
llvm.store %732, %717 : i64, !llvm.ptr
cf.br ^bb117
^bb119:
%734 = llvm.load %697 : !llvm.ptr -> i64
%735 = arith.subi %arg1, %734 : i64
%736 = arith.constant 0 : i32
%737 = arith.extsi %736 : i32 to i64
%738 = llvm.mlir.constant(1 : i64) : i64
%739 = llvm.alloca %738 x i64 : (i64) -> !llvm.ptr
llvm.store %737, %739 : i64, !llvm.ptr
%740 = arith.constant 0 : i32
%741 = arith.extsi %740 : i32 to i64
llvm.store %741, %717 : i64, !llvm.ptr
cf.br ^bb120
^bb120:
%742 = llvm.load %717 : !llvm.ptr -> i64
%743 = arith.cmpi slt, %742, %735 : i64
cf.cond_br %743, ^bb121, ^bb122
^bb121:
%744 = llvm.load %739 : !llvm.ptr -> i64
%745 = arith.constant 10 : i32
%747 = arith.extsi %745 : i32 to i64
%746 = arith.muli %744, %747 : i64
%749 = llvm.load %697 : !llvm.ptr -> i64
%750 = llvm.load %717 : !llvm.ptr -> i64
%751 = arith.addi %749, %750 : i64
%752 = llvm.getelementptr %arg2[%751] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%748 = llvm.load %752 : !llvm.ptr -> i8
%753 = arith.extsi %748 : i8 to i64
%754 = arith.addi %746, %753 : i64
llvm.store %754, %739 : i64, !llvm.ptr
%755 = llvm.load %717 : !llvm.ptr -> i64
%756 = arith.constant 1 : i32
%758 = arith.extsi %756 : i32 to i64
%757 = arith.addi %755, %758 : i64
llvm.store %757, %717 : i64, !llvm.ptr
cf.br ^bb120
^bb122:
%760 = llvm.load %697 : !llvm.ptr -> i64
%759 = func.call @ipow10(%760) : (i64) -> i64
%761 = arith.constant 1 : i32
%762 = arith.extsi %761 : i32 to i64
%763 = llvm.mlir.constant(1 : i64) : i64
%764 = llvm.alloca %763 x i64 : (i64) -> !llvm.ptr
llvm.store %762, %764 : i64, !llvm.ptr
cf.br ^bb123
^bb123:
%765 = llvm.load %764 : !llvm.ptr -> i64
%766 = arith.cmpi sle, %765, %690 : i64
cf.cond_br %766, ^bb124, ^bb125
^bb124:
%767 = arith.constant 1 : i32
%768 = arith.extsi %767 : i32 to i64
%769 = llvm.load %764 : !llvm.ptr -> i64
%770 = arith.constant 1 : i32
%772 = arith.extsi %770 : i32 to i64
%771 = arith.cmpi sgt, %769, %772 : i64
%773 = scf.if %771 -> (i64) {
%775 = llvm.load %764 : !llvm.ptr -> i64
%776 = arith.constant 1 : i32
%778 = arith.extsi %776 : i32 to i64
%777 = arith.subi %775, %778 : i64
%774 = func.call @ipow10(%777) : (i64) -> i64
scf.yield %774 : i64
} else {
scf.yield %768 : i64
}
%780 = llvm.load %764 : !llvm.ptr -> i64
%779 = func.call @ipow10(%780) : (i64) -> i64
%781 = arith.constant 2 : i32
%783 = arith.extsi %781 : i32 to i64
%782 = arith.subi %779, %783 : i64
%784 = llvm.mlir.constant(1 : i64) : i64
%785 = llvm.alloca %784 x i64 : (i64) -> !llvm.ptr
llvm.store %782, %785 : i64, !llvm.ptr
%786 = llvm.load %785 : !llvm.ptr -> i64
%787 = arith.constant 1 : i32
%789 = arith.extsi %787 : i32 to i64
%788 = arith.subi %arg0, %789 : i64
%790 = arith.cmpi sgt, %786, %788 : i64
cf.cond_br %790, ^bb126, ^bb127
^bb126:
%791 = arith.constant 1 : i32
%793 = arith.extsi %791 : i32 to i64
%792 = arith.subi %arg0, %793 : i64
llvm.store %792, %785 : i64, !llvm.ptr
cf.br ^bb128
^bb127:
cf.br ^bb128
^bb128:
%794 = llvm.load %785 : !llvm.ptr -> i64
%795 = arith.cmpi sge, %794, %773 : i64
%796 = scf.if %795 -> (i1) {
%797 = llvm.load %764 : !llvm.ptr -> i64
%798 = arith.cmpi sge, %797, %735 : i64
scf.yield %798 : i1
} else {
%799 = arith.constant false
scf.yield %799 : i1
}
cf.cond_br %796, ^bb129, ^bb130
^bb129:
%800 = llvm.load %739 : !llvm.ptr -> i64
%802 = llvm.load %764 : !llvm.ptr -> i64
%803 = arith.subi %802, %735 : i64
%801 = func.call @ipow10(%803) : (i64) -> i64
%804 = arith.muli %800, %801 : i64
%805 = llvm.load %739 : !llvm.ptr -> i64
%806 = arith.constant 1 : i32
%808 = arith.extsi %806 : i32 to i64
%807 = arith.addi %805, %808 : i64
%810 = llvm.load %764 : !llvm.ptr -> i64
%811 = arith.subi %810, %735 : i64
%809 = func.call @ipow10(%811) : (i64) -> i64
%812 = arith.muli %807, %809 : i64
%813 = arith.constant 1 : i32
%815 = arith.extsi %813 : i32 to i64
%814 = arith.subi %812, %815 : i64
%816 = llvm.mlir.constant(1 : i64) : i64
%817 = llvm.alloca %816 x i64 : (i64) -> !llvm.ptr
llvm.store %773, %817 : i64, !llvm.ptr
%818 = arith.constant 1 : i32
%820 = arith.extsi %818 : i32 to i64
%819 = arith.subi %804, %820 : i64
%821 = llvm.load %817 : !llvm.ptr -> i64
%822 = arith.cmpi sgt, %819, %821 : i64
cf.cond_br %822, ^bb132, ^bb133
^bb132:
%823 = arith.constant 1 : i32
%825 = arith.extsi %823 : i32 to i64
%824 = arith.subi %804, %825 : i64
llvm.store %824, %817 : i64, !llvm.ptr
cf.br ^bb134
^bb133:
cf.br ^bb134
^bb134:
%826 = llvm.load %785 : !llvm.ptr -> i64
%827 = llvm.mlir.constant(1 : i64) : i64
%828 = llvm.alloca %827 x i64 : (i64) -> !llvm.ptr
llvm.store %826, %828 : i64, !llvm.ptr
%829 = arith.constant 1 : i32
%831 = arith.extsi %829 : i32 to i64
%830 = arith.subi %814, %831 : i64
%832 = llvm.load %828 : !llvm.ptr -> i64
%833 = arith.cmpi slt, %830, %832 : i64
cf.cond_br %833, ^bb135, ^bb136
^bb135:
%834 = arith.constant 1 : i32
%836 = arith.extsi %834 : i32 to i64
%835 = arith.subi %814, %836 : i64
llvm.store %835, %828 : i64, !llvm.ptr
cf.br ^bb137
^bb136:
cf.br ^bb137
^bb137:
%837 = llvm.load %828 : !llvm.ptr -> i64
%838 = llvm.load %817 : !llvm.ptr -> i64
%839 = arith.cmpi sge, %837, %838 : i64
cf.cond_br %839, ^bb138, ^bb139
^bb138:
%840 = llvm.load %689 : !llvm.ptr -> i64
%842 = llvm.load %817 : !llvm.ptr -> i64
%843 = llvm.load %828 : !llvm.ptr -> i64
%844 = llvm.load %713 : !llvm.ptr -> i64
%841 = func.call @count_arith(%842, %843, %759, %844) : (i64, i64, i64, i64) -> i64
%845 = arith.addi %840, %841 : i64
llvm.store %845, %689 : i64, !llvm.ptr
cf.br ^bb140
^bb139:
cf.br ^bb140
^bb140:
cf.br ^bb131
^bb130:
cf.br ^bb131
^bb131:
%846 = llvm.load %764 : !llvm.ptr -> i64
%847 = arith.constant 1 : i32
%849 = arith.extsi %847 : i32 to i64
%848 = arith.addi %846, %849 : i64
llvm.store %848, %764 : i64, !llvm.ptr
cf.br ^bb123
^bb125:
%850 = arith.constant 1 : i32
%851 = arith.extsi %850 : i32 to i64
%852 = llvm.mlir.constant(1 : i64) : i64
%853 = llvm.alloca %852 x i64 : (i64) -> !llvm.ptr
llvm.store %851, %853 : i64, !llvm.ptr
%854 = arith.constant 0 : i32
%855 = arith.extsi %854 : i32 to i64
llvm.store %855, %717 : i64, !llvm.ptr
cf.br ^bb141
^bb141:
%856 = llvm.load %717 : !llvm.ptr -> i64
%857 = llvm.load %697 : !llvm.ptr -> i64
%858 = arith.cmpi slt, %856, %857 : i64
cf.cond_br %858, ^bb142, ^bb143
^bb142:
%860 = llvm.load %717 : !llvm.ptr -> i64
%861 = llvm.getelementptr %arg2[%860] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%859 = llvm.load %861 : !llvm.ptr -> i8
%862 = arith.constant 9 : i32
%864 = arith.extsi %859 : i8 to i32
%863 = arith.cmpi ne, %864, %862 : i32
cf.cond_br %863, ^bb144, ^bb145
^bb144:
%865 = arith.constant 0 : i32
%866 = arith.extsi %865 : i32 to i64
llvm.store %866, %853 : i64, !llvm.ptr
cf.br ^bb146
^bb145:
cf.br ^bb146
^bb146:
%867 = llvm.load %717 : !llvm.ptr -> i64
%868 = arith.constant 1 : i32
%870 = arith.extsi %868 : i32 to i64
%869 = arith.addi %867, %870 : i64
llvm.store %869, %717 : i64, !llvm.ptr
cf.br ^bb141
^bb143:
%871 = llvm.load %853 : !llvm.ptr -> i64
%872 = arith.constant 1 : i32
%874 = arith.extsi %872 : i32 to i64
%873 = arith.cmpi eq, %871, %874 : i64
cf.cond_br %873, ^bb147, ^bb148
^bb147:
%875 = arith.constant 1 : i32
%876 = arith.extsi %875 : i32 to i64
%877 = llvm.mlir.constant(1 : i64) : i64
%878 = llvm.alloca %877 x i64 : (i64) -> !llvm.ptr
llvm.store %876, %878 : i64, !llvm.ptr
%880 = llvm.load %697 : !llvm.ptr -> i64
%881 = llvm.getelementptr %arg2[%880] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%879 = llvm.load %881 : !llvm.ptr -> i8
%882 = arith.constant 1 : i32
%884 = arith.extsi %879 : i8 to i32
%883 = arith.cmpi ne, %884, %882 : i32
cf.cond_br %883, ^bb150, ^bb151
^bb150:
%885 = arith.constant 0 : i32
%886 = arith.extsi %885 : i32 to i64
llvm.store %886, %878 : i64, !llvm.ptr
cf.br ^bb152
^bb151:
cf.br ^bb152
^bb152:
%887 = arith.constant 1 : i32
%888 = arith.extsi %887 : i32 to i64
llvm.store %888, %717 : i64, !llvm.ptr
cf.br ^bb153
^bb153:
%889 = llvm.load %717 : !llvm.ptr -> i64
%890 = arith.cmpi slt, %889, %735 : i64
cf.cond_br %890, ^bb154, ^bb155
^bb154:
%892 = llvm.load %697 : !llvm.ptr -> i64
%893 = llvm.load %717 : !llvm.ptr -> i64
%894 = arith.addi %892, %893 : i64
%895 = llvm.getelementptr %arg2[%894] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%891 = llvm.load %895 : !llvm.ptr -> i8
%896 = arith.constant 0 : i32
%898 = arith.extsi %891 : i8 to i32
%897 = arith.cmpi ne, %898, %896 : i32
cf.cond_br %897, ^bb156, ^bb157
^bb156:
%899 = arith.constant 0 : i32
%900 = arith.extsi %899 : i32 to i64
llvm.store %900, %878 : i64, !llvm.ptr
cf.br ^bb158
^bb157:
cf.br ^bb158
^bb158:
%901 = llvm.load %717 : !llvm.ptr -> i64
%902 = arith.constant 1 : i32
%904 = arith.extsi %902 : i32 to i64
%903 = arith.addi %901, %904 : i64
llvm.store %903, %717 : i64, !llvm.ptr
cf.br ^bb153
^bb155:
%905 = llvm.load %878 : !llvm.ptr -> i64
%906 = arith.constant 1 : i32
%908 = arith.extsi %906 : i32 to i64
%907 = arith.cmpi eq, %905, %908 : i64
cf.cond_br %907, ^bb159, ^bb160
^bb159:
%909 = func.call @num_digits(%arg0) : (i64) -> i64
%910 = arith.constant 1 : i32
%912 = arith.extsi %910 : i32 to i64
%911 = arith.subi %909, %912 : i64
%913 = arith.constant 1 : i32
%914 = arith.extsi %913 : i32 to i64
%915 = llvm.mlir.constant(1 : i64) : i64
%916 = llvm.alloca %915 x i64 : (i64) -> !llvm.ptr
llvm.store %914, %916 : i64, !llvm.ptr
%917 = arith.constant 1 : i32
%919 = arith.extsi %917 : i32 to i64
%918 = arith.subi %735, %919 : i64
%920 = llvm.load %916 : !llvm.ptr -> i64
%921 = arith.cmpi sgt, %918, %920 : i64
cf.cond_br %921, ^bb162, ^bb163
^bb162:
%922 = arith.constant 1 : i32
%924 = arith.extsi %922 : i32 to i64
%923 = arith.subi %735, %924 : i64
llvm.store %923, %916 : i64, !llvm.ptr
cf.br ^bb164
^bb163:
cf.br ^bb164
^bb164:
%925 = llvm.load %916 : !llvm.ptr -> i64
%926 = arith.cmpi sge, %911, %925 : i64
cf.cond_br %926, ^bb165, ^bb166
^bb165:
%927 = llvm.load %689 : !llvm.ptr -> i64
%928 = llvm.load %916 : !llvm.ptr -> i64
%929 = arith.subi %911, %928 : i64
%930 = arith.constant 1 : i32
%932 = arith.extsi %930 : i32 to i64
%931 = arith.addi %929, %932 : i64
%933 = arith.addi %927, %931 : i64
llvm.store %933, %689 : i64, !llvm.ptr
cf.br ^bb167
^bb166:
cf.br ^bb167
^bb167:
cf.br ^bb161
^bb160:
cf.br ^bb161
^bb161:
cf.br ^bb149
^bb148:
cf.br ^bb149
^bb149:
%934 = llvm.load %697 : !llvm.ptr -> i64
%935 = arith.constant 1 : i32
%937 = arith.extsi %935 : i32 to i64
%936 = arith.addi %934, %937 : i64
llvm.store %936, %697 : i64, !llvm.ptr
cf.br ^bb111
^bb113:
%938 = llvm.load %689 : !llvm.ptr -> i64
func.return %938 : i64
}
func.func @brute_count(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr) -> i64 {
%939 = arith.constant 0 : i32
%940 = arith.extsi %939 : i32 to i64
%941 = llvm.mlir.constant(1 : i64) : i64
%942 = llvm.alloca %941 x i64 : (i64) -> !llvm.ptr
llvm.store %940, %942 : i64, !llvm.ptr
%943 = arith.constant 0 : i32
%944 = arith.extsi %943 : i32 to i64
%945 = llvm.mlir.constant(1 : i64) : i64
%946 = llvm.alloca %945 x i64 : (i64) -> !llvm.ptr
llvm.store %944, %946 : i64, !llvm.ptr
%947 = arith.constant 1 : i32
%948 = arith.extsi %947 : i32 to i64
%949 = llvm.mlir.constant(1 : i64) : i64
%950 = llvm.alloca %949 x i64 : (i64) -> !llvm.ptr
llvm.store %948, %950 : i64, !llvm.ptr
cf.br ^bb168
^bb168:
%951 = llvm.load %950 : !llvm.ptr -> i64
%952 = arith.cmpi sle, %951, %arg0 : i64
cf.cond_br %952, ^bb169, ^bb170
^bb169:
%954 = llvm.load %950 : !llvm.ptr -> i64
%953 = func.call @num_digits(%954) : (i64) -> i64
%955 = arith.constant 0 : i32
%956 = arith.extsi %955 : i32 to i64
%957 = llvm.mlir.constant(1 : i64) : i64
%958 = llvm.alloca %957 x i64 : (i64) -> !llvm.ptr
llvm.store %956, %958 : i64, !llvm.ptr
cf.br ^bb171
^bb171:
%959 = llvm.load %958 : !llvm.ptr -> i64
%960 = arith.cmpi slt, %959, %953 : i64
cf.cond_br %960, ^bb172, ^bb173
^bb172:
%962 = llvm.load %950 : !llvm.ptr -> i64
%963 = llvm.load %958 : !llvm.ptr -> i64
%961 = func.call @digit_at(%962, %963, %953) : (i64, i64, i64) -> i64
%965 = llvm.load %942 : !llvm.ptr -> i64
%964 = func.call @step(%arg2, %965, %961) : (!llvm.ptr, i64, i64) -> i64
%966 = arith.constant 65535 : i32
%968 = arith.extsi %966 : i32 to i64
%967 = arith.andi %964, %968 : i64
llvm.store %967, %942 : i64, !llvm.ptr
%969 = llvm.load %946 : !llvm.ptr -> i64
%970 = arith.constant 16 : i32
%972 = arith.extsi %970 : i32 to i64
%971 = arith.shrsi %964, %972 : i64
%973 = arith.addi %969, %971 : i64
llvm.store %973, %946 : i64, !llvm.ptr
%974 = llvm.load %958 : !llvm.ptr -> i64
%975 = arith.constant 1 : i32
%977 = arith.extsi %975 : i32 to i64
%976 = arith.addi %974, %977 : i64
llvm.store %976, %958 : i64, !llvm.ptr
cf.br ^bb171
^bb173:
%978 = llvm.load %950 : !llvm.ptr -> i64
%979 = arith.constant 1 : i32
%981 = arith.extsi %979 : i32 to i64
%980 = arith.addi %978, %981 : i64
llvm.store %980, %950 : i64, !llvm.ptr
cf.br ^bb168
^bb170:
%982 = llvm.load %946 : !llvm.ptr -> i64
func.return %982 : i64
}
func.func @f_of_n(%arg0: i64) -> i64 {
%983 = func.call @num_digits(%arg0) : (i64) -> i64
%985 = arith.constant 1 : i32
%986 = arith.extsi %985 : i32 to i64
%984 = func.call @calloc(%983, %986) : (i64, i64) -> !llvm.ptr
%987 = func.call @fill_pat(%arg0, %984, %983) : (i64, !llvm.ptr, i64) -> i32
%989 = arith.constant 4 : i32
%990 = arith.extsi %989 : i32 to i64
%988 = func.call @calloc(%983, %990) : (i64, i64) -> !llvm.ptr
%992 = arith.constant 10 : i32
%994 = arith.extsi %992 : i32 to i64
%993 = arith.muli %983, %994 : i64
%995 = arith.constant 4 : i32
%996 = arith.extsi %995 : i32 to i64
%991 = func.call @calloc(%993, %996) : (i64, i64) -> !llvm.ptr
%997 = func.call @build_kmp(%984, %983, %988, %991) : (!llvm.ptr, i64, !llvm.ptr, !llvm.ptr) -> i32
%998 = arith.constant 1 : i32
%999 = arith.extsi %998 : i32 to i64
%1000 = arith.constant 2 : i32
%1002 = arith.extsi %1000 : i32 to i64
%1001 = arith.cmpi sge, %983, %1002 : i64
%1003 = scf.if %1001 -> (i64) {
%1005 = arith.constant 2 : i32
%1007 = arith.extsi %1005 : i32 to i64
%1006 = arith.subi %983, %1007 : i64
%1004 = func.call @ipow10(%1006) : (i64) -> i64
scf.yield %1004 : i64
} else {
scf.yield %999 : i64
}
%1009 = arith.constant 21 : i32
%1010 = arith.constant 8 : i32
%1011 = arith.extsi %1009 : i32 to i64
%1012 = arith.extsi %1010 : i32 to i64
%1008 = func.call @calloc(%1011, %1012) : (i64, i64) -> !llvm.ptr
%1013 = arith.constant 1 : i32
%1014 = arith.extsi %1013 : i32 to i64
%1015 = llvm.mlir.constant(1 : i64) : i64
%1016 = llvm.alloca %1015 x i64 : (i64) -> !llvm.ptr
llvm.store %1014, %1016 : i64, !llvm.ptr
cf.br ^bb174
^bb174:
%1017 = llvm.load %1016 : !llvm.ptr -> i64
%1018 = arith.constant 20 : i32
%1020 = arith.extsi %1018 : i32 to i64
%1019 = arith.cmpi sle, %1017, %1020 : i64
cf.cond_br %1019, ^bb175, ^bb176
^bb175:
%1022 = llvm.load %1016 : !llvm.ptr -> i64
%1021 = func.call @internal_len_d(%1022, %983, %991) : (i64, i64, !llvm.ptr) -> i64
%1023 = llvm.load %1016 : !llvm.ptr -> i64
%1024 = llvm.getelementptr %1008[%1023] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %1021, %1024 : i64, !llvm.ptr
%1025 = llvm.load %1016 : !llvm.ptr -> i64
%1026 = arith.constant 1 : i32
%1028 = arith.extsi %1026 : i32 to i64
%1027 = arith.addi %1025, %1028 : i64
llvm.store %1027, %1016 : i64, !llvm.ptr
cf.br ^bb174
^bb176:
%1029 = func.call @brute_count(%1003, %983, %991) : (i64, i64, !llvm.ptr) -> i64
%1030 = func.call @internal_upto(%1003, %983, %991, %1008) : (i64, i64, !llvm.ptr, !llvm.ptr) -> i64
%1031 = func.call @boundary_upto(%1003, %983, %984) : (i64, i64, !llvm.ptr) -> i64
%1032 = arith.constant 1 : i32
%1033 = arith.extsi %1032 : i32 to i64
%1034 = llvm.mlir.constant(1 : i64) : i64
%1035 = llvm.alloca %1034 x i64 : (i64) -> !llvm.ptr
llvm.store %1033, %1035 : i64, !llvm.ptr
%1036 = arith.constant 1 : i32
%1037 = arith.extsi %1036 : i32 to i64
%1038 = llvm.mlir.constant(1 : i64) : i64
%1039 = llvm.alloca %1038 x i64 : (i64) -> !llvm.ptr
llvm.store %1037, %1039 : i64, !llvm.ptr
cf.br ^bb177
^bb177:
%1040 = arith.constant 1 : i1
cf.cond_br %1040, ^bb178, ^bb179
^bb178:
%1041 = llvm.load %1039 : !llvm.ptr -> i64
%1042 = arith.addi %1041, %983 : i64
%1043 = arith.constant 1 : i32
%1045 = arith.extsi %1043 : i32 to i64
%1044 = arith.subi %1042, %1045 : i64
%1047 = arith.constant 1 : i32
%1048 = arith.constant 8 : i32
%1049 = arith.extsi %1047 : i32 to i64
%1050 = arith.extsi %1048 : i32 to i64
%1046 = func.call @calloc(%1049, %1050) : (i64, i64) -> !llvm.ptr
%1052 = arith.constant 1 : i32
%1053 = arith.constant 8 : i32
%1054 = arith.extsi %1052 : i32 to i64
%1055 = arith.extsi %1053 : i32 to i64
%1051 = func.call @calloc(%1054, %1055) : (i64, i64) -> !llvm.ptr
%1056 = func.call @prefix_to_N(%1044, %1046, %1051) : (i64, !llvm.ptr, !llvm.ptr) -> i32
%1058 = arith.constant 0 : i32
%1059 = arith.extsi %1058 : i32 to i64
%1060 = llvm.getelementptr %1046[%1059] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%1057 = llvm.load %1060 : !llvm.ptr -> i64
%1062 = arith.constant 0 : i32
%1063 = arith.extsi %1062 : i32 to i64
%1064 = llvm.getelementptr %1051[%1063] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%1061 = llvm.load %1064 : !llvm.ptr -> i64
%1065 = arith.constant 0 : i32
%1066 = arith.extsi %1065 : i32 to i64
%1067 = llvm.mlir.constant(1 : i64) : i64
%1068 = llvm.alloca %1067 x i64 : (i64) -> !llvm.ptr
llvm.store %1066, %1068 : i64, !llvm.ptr
%1069 = arith.cmpi sle, %1057, %1003 : i64
cf.cond_br %1069, ^bb180, ^bb181
^bb180:
%1070 = func.call @brute_count(%1057, %983, %991) : (i64, i64, !llvm.ptr) -> i64
llvm.store %1070, %1068 : i64, !llvm.ptr
cf.br ^bb182
^bb181:
%1071 = func.call @internal_upto(%1057, %983, %991, %1008) : (i64, i64, !llvm.ptr, !llvm.ptr) -> i64
%1072 = arith.subi %1071, %1030 : i64
%1073 = arith.addi %1029, %1072 : i64
%1074 = func.call @boundary_upto(%1057, %983, %984) : (i64, i64, !llvm.ptr) -> i64
%1075 = arith.subi %1074, %1031 : i64
%1076 = arith.addi %1073, %1075 : i64
llvm.store %1076, %1068 : i64, !llvm.ptr
cf.br ^bb182
^bb182:
%1077 = arith.constant 0 : i32
%1079 = arith.extsi %1077 : i32 to i64
%1078 = arith.cmpi sgt, %1061, %1079 : i64
cf.cond_br %1078, ^bb183, ^bb184
^bb183:
%1080 = arith.constant 0 : i32
%1081 = arith.extsi %1080 : i32 to i64
%1082 = llvm.mlir.constant(1 : i64) : i64
%1083 = llvm.alloca %1082 x i64 : (i64) -> !llvm.ptr
llvm.store %1081, %1083 : i64, !llvm.ptr
%1084 = arith.constant 1 : i32
%1086 = arith.extsi %1084 : i32 to i64
%1085 = arith.subi %983, %1086 : i64
%1088 = arith.addi %1085, %1061 : i64
%1089 = arith.constant 8 : i32
%1091 = arith.extsi %1089 : i32 to i64
%1090 = arith.addi %1088, %1091 : i64
%1092 = arith.constant 1 : i32
%1093 = arith.extsi %1092 : i32 to i64
%1087 = func.call @calloc(%1090, %1093) : (i64, i64) -> !llvm.ptr
%1094 = arith.constant 0 : i32
%1095 = arith.extsi %1094 : i32 to i64
%1096 = llvm.mlir.constant(1 : i64) : i64
%1097 = llvm.alloca %1096 x i64 : (i64) -> !llvm.ptr
llvm.store %1095, %1097 : i64, !llvm.ptr
%1098 = llvm.mlir.constant(1 : i64) : i64
%1099 = llvm.alloca %1098 x i64 : (i64) -> !llvm.ptr
llvm.store %1057, %1099 : i64, !llvm.ptr
cf.br ^bb186
^bb186:
%1100 = llvm.load %1097 : !llvm.ptr -> i64
%1101 = arith.cmpi slt, %1100, %1085 : i64
%1102 = scf.if %1101 -> (i1) {
%1103 = llvm.load %1099 : !llvm.ptr -> i64
%1104 = arith.constant 1 : i32
%1106 = arith.extsi %1104 : i32 to i64
%1105 = arith.cmpi sge, %1103, %1106 : i64
scf.yield %1105 : i1
} else {
%1107 = arith.constant false
scf.yield %1107 : i1
}
cf.cond_br %1102, ^bb187, ^bb188
^bb187:
%1109 = llvm.load %1099 : !llvm.ptr -> i64
%1108 = func.call @num_digits(%1109) : (i64) -> i64
%1111 = arith.constant 1 : i32
%1112 = arith.extsi %1111 : i32 to i64
%1110 = func.call @calloc(%1108, %1112) : (i64, i64) -> !llvm.ptr
%1113 = arith.constant 0 : i32
%1114 = arith.extsi %1113 : i32 to i64
%1115 = llvm.mlir.constant(1 : i64) : i64
%1116 = llvm.alloca %1115 x i64 : (i64) -> !llvm.ptr
llvm.store %1114, %1116 : i64, !llvm.ptr
cf.br ^bb189
^bb189:
%1117 = llvm.load %1116 : !llvm.ptr -> i64
%1118 = arith.cmpi slt, %1117, %1108 : i64
cf.cond_br %1118, ^bb190, ^bb191
^bb190:
%1120 = llvm.load %1099 : !llvm.ptr -> i64
%1121 = llvm.load %1116 : !llvm.ptr -> i64
%1119 = func.call @digit_at(%1120, %1121, %1108) : (i64, i64, i64) -> i64
%1122 = arith.trunci %1119 : i64 to i8
%1123 = llvm.load %1116 : !llvm.ptr -> i64
%1124 = llvm.getelementptr %1110[%1123] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %1122, %1124 : i8, !llvm.ptr
%1125 = llvm.load %1116 : !llvm.ptr -> i64
%1126 = arith.constant 1 : i32
%1128 = arith.extsi %1126 : i32 to i64
%1127 = arith.addi %1125, %1128 : i64
llvm.store %1127, %1116 : i64, !llvm.ptr
cf.br ^bb189
^bb191:
%1129 = llvm.load %1097 : !llvm.ptr -> i64
%1130 = arith.constant 1 : i32
%1132 = arith.extsi %1130 : i32 to i64
%1131 = arith.subi %1129, %1132 : i64
%1133 = llvm.mlir.constant(1 : i64) : i64
%1134 = llvm.alloca %1133 x i64 : (i64) -> !llvm.ptr
llvm.store %1131, %1134 : i64, !llvm.ptr
cf.br ^bb192
^bb192:
%1135 = llvm.load %1134 : !llvm.ptr -> i64
%1136 = arith.constant 0 : i32
%1138 = arith.extsi %1136 : i32 to i64
%1137 = arith.cmpi sge, %1135, %1138 : i64
cf.cond_br %1137, ^bb193, ^bb194
^bb193:
%1140 = llvm.load %1134 : !llvm.ptr -> i64
%1141 = llvm.getelementptr %1087[%1140] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%1139 = llvm.load %1141 : !llvm.ptr -> i8
%1142 = llvm.load %1134 : !llvm.ptr -> i64
%1143 = arith.addi %1142, %1108 : i64
%1144 = llvm.getelementptr %1087[%1143] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %1139, %1144 : i8, !llvm.ptr
%1145 = llvm.load %1134 : !llvm.ptr -> i64
%1146 = arith.constant 1 : i32
%1148 = arith.extsi %1146 : i32 to i64
%1147 = arith.subi %1145, %1148 : i64
llvm.store %1147, %1134 : i64, !llvm.ptr
cf.br ^bb192
^bb194:
%1149 = arith.constant 0 : i32
%1150 = arith.extsi %1149 : i32 to i64
llvm.store %1150, %1116 : i64, !llvm.ptr
cf.br ^bb195
^bb195:
%1151 = llvm.load %1116 : !llvm.ptr -> i64
%1152 = arith.cmpi slt, %1151, %1108 : i64
cf.cond_br %1152, ^bb196, ^bb197
^bb196:
%1154 = llvm.load %1116 : !llvm.ptr -> i64
%1155 = llvm.getelementptr %1110[%1154] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%1153 = llvm.load %1155 : !llvm.ptr -> i8
%1156 = llvm.load %1116 : !llvm.ptr -> i64
%1157 = llvm.getelementptr %1087[%1156] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %1153, %1157 : i8, !llvm.ptr
%1158 = llvm.load %1116 : !llvm.ptr -> i64
%1159 = arith.constant 1 : i32
%1161 = arith.extsi %1159 : i32 to i64
%1160 = arith.addi %1158, %1161 : i64
llvm.store %1160, %1116 : i64, !llvm.ptr
cf.br ^bb195
^bb197:
%1162 = llvm.load %1097 : !llvm.ptr -> i64
%1163 = arith.addi %1162, %1108 : i64
llvm.store %1163, %1097 : i64, !llvm.ptr
func.call @free(%1110) : (!llvm.ptr) -> ()
%1165 = llvm.load %1099 : !llvm.ptr -> i64
%1166 = arith.constant 1 : i32
%1168 = arith.extsi %1166 : i32 to i64
%1167 = arith.subi %1165, %1168 : i64
llvm.store %1167, %1099 : i64, !llvm.ptr
cf.br ^bb186
^bb188:
%1169 = llvm.load %1097 : !llvm.ptr -> i64
%1170 = arith.cmpi sgt, %1169, %1085 : i64
cf.cond_br %1170, ^bb198, ^bb199
^bb198:
%1171 = arith.constant 0 : i32
%1172 = arith.extsi %1171 : i32 to i64
%1173 = llvm.mlir.constant(1 : i64) : i64
%1174 = llvm.alloca %1173 x i64 : (i64) -> !llvm.ptr
llvm.store %1172, %1174 : i64, !llvm.ptr
cf.br ^bb201
^bb201:
%1175 = llvm.load %1174 : !llvm.ptr -> i64
%1176 = arith.cmpi slt, %1175, %1085 : i64
cf.cond_br %1176, ^bb202, ^bb203
^bb202:
%1178 = llvm.load %1097 : !llvm.ptr -> i64
%1179 = arith.subi %1178, %1085 : i64
%1180 = llvm.load %1174 : !llvm.ptr -> i64
%1181 = arith.addi %1179, %1180 : i64
%1182 = llvm.getelementptr %1087[%1181] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%1177 = llvm.load %1182 : !llvm.ptr -> i8
%1183 = llvm.load %1174 : !llvm.ptr -> i64
%1184 = llvm.getelementptr %1087[%1183] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %1177, %1184 : i8, !llvm.ptr
%1185 = llvm.load %1174 : !llvm.ptr -> i64
%1186 = arith.constant 1 : i32
%1188 = arith.extsi %1186 : i32 to i64
%1187 = arith.addi %1185, %1188 : i64
llvm.store %1187, %1174 : i64, !llvm.ptr
cf.br ^bb201
^bb203:
llvm.store %1085, %1097 : i64, !llvm.ptr
cf.br ^bb200
^bb199:
cf.br ^bb200
^bb200:
%1189 = arith.constant 1 : i32
%1191 = arith.extsi %1189 : i32 to i64
%1190 = arith.addi %1057, %1191 : i64
%1192 = func.call @num_digits(%1190) : (i64) -> i64
%1193 = arith.constant 0 : i32
%1194 = arith.extsi %1193 : i32 to i64
%1195 = llvm.mlir.constant(1 : i64) : i64
%1196 = llvm.alloca %1195 x i64 : (i64) -> !llvm.ptr
llvm.store %1194, %1196 : i64, !llvm.ptr
cf.br ^bb204
^bb204:
%1197 = llvm.load %1196 : !llvm.ptr -> i64
%1198 = arith.cmpi slt, %1197, %1061 : i64
cf.cond_br %1198, ^bb205, ^bb206
^bb205:
%1200 = llvm.load %1196 : !llvm.ptr -> i64
%1199 = func.call @digit_at(%1190, %1200, %1192) : (i64, i64, i64) -> i64
%1201 = arith.trunci %1199 : i64 to i8
%1202 = llvm.load %1097 : !llvm.ptr -> i64
%1203 = llvm.load %1196 : !llvm.ptr -> i64
%1204 = arith.addi %1202, %1203 : i64
%1205 = llvm.getelementptr %1087[%1204] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %1201, %1205 : i8, !llvm.ptr
%1206 = llvm.load %1196 : !llvm.ptr -> i64
%1207 = arith.constant 1 : i32
%1209 = arith.extsi %1207 : i32 to i64
%1208 = arith.addi %1206, %1209 : i64
llvm.store %1208, %1196 : i64, !llvm.ptr
cf.br ^bb204
^bb206:
%1210 = llvm.load %1097 : !llvm.ptr -> i64
%1211 = llvm.load %1097 : !llvm.ptr -> i64
%1212 = arith.addi %1211, %1061 : i64
%1213 = arith.constant 0 : i32
%1214 = arith.extsi %1213 : i32 to i64
llvm.store %1214, %1196 : i64, !llvm.ptr
cf.br ^bb207
^bb207:
%1215 = llvm.load %1196 : !llvm.ptr -> i64
%1216 = arith.cmpi slt, %1215, %1212 : i64
cf.cond_br %1216, ^bb208, ^bb209
^bb208:
%1218 = llvm.load %1083 : !llvm.ptr -> i64
%1220 = llvm.load %1196 : !llvm.ptr -> i64
%1221 = llvm.getelementptr %1087[%1220] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%1219 = llvm.load %1221 : !llvm.ptr -> i8
%1222 = arith.extsi %1219 : i8 to i64
%1217 = func.call @step(%991, %1218, %1222) : (!llvm.ptr, i64, i64) -> i64
%1223 = arith.constant 65535 : i32
%1225 = arith.extsi %1223 : i32 to i64
%1224 = arith.andi %1217, %1225 : i64
llvm.store %1224, %1083 : i64, !llvm.ptr
%1226 = arith.constant 16 : i32
%1228 = arith.extsi %1226 : i32 to i64
%1227 = arith.shrsi %1217, %1228 : i64
%1229 = arith.constant 1 : i32
%1231 = arith.extsi %1229 : i32 to i64
%1230 = arith.cmpi eq, %1227, %1231 : i64
%1232 = scf.if %1230 -> (i1) {
%1233 = llvm.load %1196 : !llvm.ptr -> i64
%1234 = arith.cmpi sge, %1233, %1210 : i64
scf.yield %1234 : i1
} else {
%1235 = arith.constant false
scf.yield %1235 : i1
}
cf.cond_br %1232, ^bb210, ^bb211
^bb210:
%1236 = llvm.load %1068 : !llvm.ptr -> i64
%1237 = arith.constant 1 : i32
%1239 = arith.extsi %1237 : i32 to i64
%1238 = arith.addi %1236, %1239 : i64
llvm.store %1238, %1068 : i64, !llvm.ptr
cf.br ^bb212
^bb211:
cf.br ^bb212
^bb212:
%1240 = llvm.load %1196 : !llvm.ptr -> i64
%1241 = arith.constant 1 : i32
%1243 = arith.extsi %1241 : i32 to i64
%1242 = arith.addi %1240, %1243 : i64
llvm.store %1242, %1196 : i64, !llvm.ptr
cf.br ^bb207
^bb209:
func.call @free(%1087) : (!llvm.ptr) -> ()
cf.br ^bb185
^bb184:
cf.br ^bb185
^bb185:
func.call @free(%1046) : (!llvm.ptr) -> ()
func.call @free(%1051) : (!llvm.ptr) -> ()
%1247 = llvm.load %1068 : !llvm.ptr -> i64
%1248 = arith.cmpi sge, %1247, %arg0 : i64
cf.cond_br %1248, ^bb213, ^bb214
^bb213:
cf.br ^bb179
^bb214:
cf.br ^bb215
^bb215:
%1249 = llvm.load %1039 : !llvm.ptr -> i64
%1250 = arith.constant 2 : i32
%1252 = arith.extsi %1250 : i32 to i64
%1251 = arith.muli %1249, %1252 : i64
llvm.store %1251, %1039 : i64, !llvm.ptr
%1253 = llvm.load %1039 : !llvm.ptr -> i64
%1254 = arith.constant 0 : i32
%1256 = arith.extsi %1254 : i32 to i64
%1255 = arith.cmpi sle, %1253, %1256 : i64
cf.cond_br %1255, ^bb216, ^bb217
^bb216:
%1257 = arith.constant 9223372032559808511 : i32
%1258 = arith.extsi %1257 : i32 to i64
llvm.store %1258, %1039 : i64, !llvm.ptr
cf.br ^bb179
^bb217:
cf.br ^bb218
^bb218:
cf.br ^bb177
^bb179:
%1259 = arith.constant 1 : i32
%1260 = arith.extsi %1259 : i32 to i64
llvm.store %1260, %1035 : i64, !llvm.ptr
cf.br ^bb219
^bb219:
%1261 = llvm.load %1035 : !llvm.ptr -> i64
%1262 = llvm.load %1039 : !llvm.ptr -> i64
%1263 = arith.cmpi slt, %1261, %1262 : i64
cf.cond_br %1263, ^bb220, ^bb221
^bb220:
%1264 = llvm.load %1035 : !llvm.ptr -> i64
%1265 = llvm.load %1039 : !llvm.ptr -> i64
%1266 = llvm.load %1035 : !llvm.ptr -> i64
%1267 = arith.subi %1265, %1266 : i64
%1268 = arith.constant 2 : i32
%1270 = arith.extsi %1268 : i32 to i64
%1269 = arith.divsi %1267, %1270 : i64
%1271 = arith.addi %1264, %1269 : i64
%1272 = arith.addi %1271, %983 : i64
%1273 = arith.constant 1 : i32
%1275 = arith.extsi %1273 : i32 to i64
%1274 = arith.subi %1272, %1275 : i64
%1277 = arith.constant 1 : i32
%1278 = arith.constant 8 : i32
%1279 = arith.extsi %1277 : i32 to i64
%1280 = arith.extsi %1278 : i32 to i64
%1276 = func.call @calloc(%1279, %1280) : (i64, i64) -> !llvm.ptr
%1282 = arith.constant 1 : i32
%1283 = arith.constant 8 : i32
%1284 = arith.extsi %1282 : i32 to i64
%1285 = arith.extsi %1283 : i32 to i64
%1281 = func.call @calloc(%1284, %1285) : (i64, i64) -> !llvm.ptr
%1286 = func.call @prefix_to_N(%1274, %1276, %1281) : (i64, !llvm.ptr, !llvm.ptr) -> i32
%1288 = arith.constant 0 : i32
%1289 = arith.extsi %1288 : i32 to i64
%1290 = llvm.getelementptr %1276[%1289] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%1287 = llvm.load %1290 : !llvm.ptr -> i64
%1292 = arith.constant 0 : i32
%1293 = arith.extsi %1292 : i32 to i64
%1294 = llvm.getelementptr %1281[%1293] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%1291 = llvm.load %1294 : !llvm.ptr -> i64
%1295 = arith.constant 0 : i32
%1296 = arith.extsi %1295 : i32 to i64
%1297 = llvm.mlir.constant(1 : i64) : i64
%1298 = llvm.alloca %1297 x i64 : (i64) -> !llvm.ptr
llvm.store %1296, %1298 : i64, !llvm.ptr
%1299 = arith.cmpi sle, %1287, %1003 : i64
cf.cond_br %1299, ^bb222, ^bb223
^bb222:
%1300 = func.call @brute_count(%1287, %983, %991) : (i64, i64, !llvm.ptr) -> i64
llvm.store %1300, %1298 : i64, !llvm.ptr
cf.br ^bb224
^bb223:
%1301 = func.call @internal_upto(%1287, %983, %991, %1008) : (i64, i64, !llvm.ptr, !llvm.ptr) -> i64
%1302 = arith.subi %1301, %1030 : i64
%1303 = arith.addi %1029, %1302 : i64
%1304 = func.call @boundary_upto(%1287, %983, %984) : (i64, i64, !llvm.ptr) -> i64
%1305 = arith.subi %1304, %1031 : i64
%1306 = arith.addi %1303, %1305 : i64
llvm.store %1306, %1298 : i64, !llvm.ptr
cf.br ^bb224
^bb224:
%1307 = arith.constant 0 : i32
%1309 = arith.extsi %1307 : i32 to i64
%1308 = arith.cmpi sgt, %1291, %1309 : i64
cf.cond_br %1308, ^bb225, ^bb226
^bb225:
%1310 = arith.constant 0 : i32
%1311 = arith.extsi %1310 : i32 to i64
%1312 = llvm.mlir.constant(1 : i64) : i64
%1313 = llvm.alloca %1312 x i64 : (i64) -> !llvm.ptr
llvm.store %1311, %1313 : i64, !llvm.ptr
%1314 = arith.constant 1 : i32
%1316 = arith.extsi %1314 : i32 to i64
%1315 = arith.subi %983, %1316 : i64
%1318 = arith.addi %1315, %1291 : i64
%1319 = arith.constant 8 : i32
%1321 = arith.extsi %1319 : i32 to i64
%1320 = arith.addi %1318, %1321 : i64
%1322 = arith.constant 1 : i32
%1323 = arith.extsi %1322 : i32 to i64
%1317 = func.call @calloc(%1320, %1323) : (i64, i64) -> !llvm.ptr
%1324 = arith.constant 0 : i32
%1325 = arith.extsi %1324 : i32 to i64
%1326 = llvm.mlir.constant(1 : i64) : i64
%1327 = llvm.alloca %1326 x i64 : (i64) -> !llvm.ptr
llvm.store %1325, %1327 : i64, !llvm.ptr
%1328 = llvm.mlir.constant(1 : i64) : i64
%1329 = llvm.alloca %1328 x i64 : (i64) -> !llvm.ptr
llvm.store %1287, %1329 : i64, !llvm.ptr
cf.br ^bb228
^bb228:
%1330 = llvm.load %1327 : !llvm.ptr -> i64
%1331 = arith.cmpi slt, %1330, %1315 : i64
%1332 = scf.if %1331 -> (i1) {
%1333 = llvm.load %1329 : !llvm.ptr -> i64
%1334 = arith.constant 1 : i32
%1336 = arith.extsi %1334 : i32 to i64
%1335 = arith.cmpi sge, %1333, %1336 : i64
scf.yield %1335 : i1
} else {
%1337 = arith.constant false
scf.yield %1337 : i1
}
cf.cond_br %1332, ^bb229, ^bb230
^bb229:
%1339 = llvm.load %1329 : !llvm.ptr -> i64
%1338 = func.call @num_digits(%1339) : (i64) -> i64
%1341 = arith.constant 1 : i32
%1342 = arith.extsi %1341 : i32 to i64
%1340 = func.call @calloc(%1338, %1342) : (i64, i64) -> !llvm.ptr
%1343 = arith.constant 0 : i32
%1344 = arith.extsi %1343 : i32 to i64
%1345 = llvm.mlir.constant(1 : i64) : i64
%1346 = llvm.alloca %1345 x i64 : (i64) -> !llvm.ptr
llvm.store %1344, %1346 : i64, !llvm.ptr
cf.br ^bb231
^bb231:
%1347 = llvm.load %1346 : !llvm.ptr -> i64
%1348 = arith.cmpi slt, %1347, %1338 : i64
cf.cond_br %1348, ^bb232, ^bb233
^bb232:
%1350 = llvm.load %1329 : !llvm.ptr -> i64
%1351 = llvm.load %1346 : !llvm.ptr -> i64
%1349 = func.call @digit_at(%1350, %1351, %1338) : (i64, i64, i64) -> i64
%1352 = arith.trunci %1349 : i64 to i8
%1353 = llvm.load %1346 : !llvm.ptr -> i64
%1354 = llvm.getelementptr %1340[%1353] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %1352, %1354 : i8, !llvm.ptr
%1355 = llvm.load %1346 : !llvm.ptr -> i64
%1356 = arith.constant 1 : i32
%1358 = arith.extsi %1356 : i32 to i64
%1357 = arith.addi %1355, %1358 : i64
llvm.store %1357, %1346 : i64, !llvm.ptr
cf.br ^bb231
^bb233:
%1359 = llvm.load %1327 : !llvm.ptr -> i64
%1360 = arith.constant 1 : i32
%1362 = arith.extsi %1360 : i32 to i64
%1361 = arith.subi %1359, %1362 : i64
%1363 = llvm.mlir.constant(1 : i64) : i64
%1364 = llvm.alloca %1363 x i64 : (i64) -> !llvm.ptr
llvm.store %1361, %1364 : i64, !llvm.ptr
cf.br ^bb234
^bb234:
%1365 = llvm.load %1364 : !llvm.ptr -> i64
%1366 = arith.constant 0 : i32
%1368 = arith.extsi %1366 : i32 to i64
%1367 = arith.cmpi sge, %1365, %1368 : i64
cf.cond_br %1367, ^bb235, ^bb236
^bb235:
%1370 = llvm.load %1364 : !llvm.ptr -> i64
%1371 = llvm.getelementptr %1317[%1370] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%1369 = llvm.load %1371 : !llvm.ptr -> i8
%1372 = llvm.load %1364 : !llvm.ptr -> i64
%1373 = arith.addi %1372, %1338 : i64
%1374 = llvm.getelementptr %1317[%1373] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %1369, %1374 : i8, !llvm.ptr
%1375 = llvm.load %1364 : !llvm.ptr -> i64
%1376 = arith.constant 1 : i32
%1378 = arith.extsi %1376 : i32 to i64
%1377 = arith.subi %1375, %1378 : i64
llvm.store %1377, %1364 : i64, !llvm.ptr
cf.br ^bb234
^bb236:
%1379 = arith.constant 0 : i32
%1380 = arith.extsi %1379 : i32 to i64
llvm.store %1380, %1346 : i64, !llvm.ptr
cf.br ^bb237
^bb237:
%1381 = llvm.load %1346 : !llvm.ptr -> i64
%1382 = arith.cmpi slt, %1381, %1338 : i64
cf.cond_br %1382, ^bb238, ^bb239
^bb238:
%1384 = llvm.load %1346 : !llvm.ptr -> i64
%1385 = llvm.getelementptr %1340[%1384] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%1383 = llvm.load %1385 : !llvm.ptr -> i8
%1386 = llvm.load %1346 : !llvm.ptr -> i64
%1387 = llvm.getelementptr %1317[%1386] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %1383, %1387 : i8, !llvm.ptr
%1388 = llvm.load %1346 : !llvm.ptr -> i64
%1389 = arith.constant 1 : i32
%1391 = arith.extsi %1389 : i32 to i64
%1390 = arith.addi %1388, %1391 : i64
llvm.store %1390, %1346 : i64, !llvm.ptr
cf.br ^bb237
^bb239:
%1392 = llvm.load %1327 : !llvm.ptr -> i64
%1393 = arith.addi %1392, %1338 : i64
llvm.store %1393, %1327 : i64, !llvm.ptr
func.call @free(%1340) : (!llvm.ptr) -> ()
%1395 = llvm.load %1329 : !llvm.ptr -> i64
%1396 = arith.constant 1 : i32
%1398 = arith.extsi %1396 : i32 to i64
%1397 = arith.subi %1395, %1398 : i64
llvm.store %1397, %1329 : i64, !llvm.ptr
cf.br ^bb228
^bb230:
%1399 = llvm.load %1327 : !llvm.ptr -> i64
%1400 = arith.cmpi sgt, %1399, %1315 : i64
cf.cond_br %1400, ^bb240, ^bb241
^bb240:
%1401 = arith.constant 0 : i32
%1402 = arith.extsi %1401 : i32 to i64
%1403 = llvm.mlir.constant(1 : i64) : i64
%1404 = llvm.alloca %1403 x i64 : (i64) -> !llvm.ptr
llvm.store %1402, %1404 : i64, !llvm.ptr
cf.br ^bb243
^bb243:
%1405 = llvm.load %1404 : !llvm.ptr -> i64
%1406 = arith.cmpi slt, %1405, %1315 : i64
cf.cond_br %1406, ^bb244, ^bb245
^bb244:
%1408 = llvm.load %1327 : !llvm.ptr -> i64
%1409 = arith.subi %1408, %1315 : i64
%1410 = llvm.load %1404 : !llvm.ptr -> i64
%1411 = arith.addi %1409, %1410 : i64
%1412 = llvm.getelementptr %1317[%1411] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%1407 = llvm.load %1412 : !llvm.ptr -> i8
%1413 = llvm.load %1404 : !llvm.ptr -> i64
%1414 = llvm.getelementptr %1317[%1413] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %1407, %1414 : i8, !llvm.ptr
%1415 = llvm.load %1404 : !llvm.ptr -> i64
%1416 = arith.constant 1 : i32
%1418 = arith.extsi %1416 : i32 to i64
%1417 = arith.addi %1415, %1418 : i64
llvm.store %1417, %1404 : i64, !llvm.ptr
cf.br ^bb243
^bb245:
llvm.store %1315, %1327 : i64, !llvm.ptr
cf.br ^bb242
^bb241:
cf.br ^bb242
^bb242:
%1419 = arith.constant 1 : i32
%1421 = arith.extsi %1419 : i32 to i64
%1420 = arith.addi %1287, %1421 : i64
%1422 = func.call @num_digits(%1420) : (i64) -> i64
%1423 = arith.constant 0 : i32
%1424 = arith.extsi %1423 : i32 to i64
%1425 = llvm.mlir.constant(1 : i64) : i64
%1426 = llvm.alloca %1425 x i64 : (i64) -> !llvm.ptr
llvm.store %1424, %1426 : i64, !llvm.ptr
cf.br ^bb246
^bb246:
%1427 = llvm.load %1426 : !llvm.ptr -> i64
%1428 = arith.cmpi slt, %1427, %1291 : i64
cf.cond_br %1428, ^bb247, ^bb248
^bb247:
%1430 = llvm.load %1426 : !llvm.ptr -> i64
%1429 = func.call @digit_at(%1420, %1430, %1422) : (i64, i64, i64) -> i64
%1431 = arith.trunci %1429 : i64 to i8
%1432 = llvm.load %1327 : !llvm.ptr -> i64
%1433 = llvm.load %1426 : !llvm.ptr -> i64
%1434 = arith.addi %1432, %1433 : i64
%1435 = llvm.getelementptr %1317[%1434] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %1431, %1435 : i8, !llvm.ptr
%1436 = llvm.load %1426 : !llvm.ptr -> i64
%1437 = arith.constant 1 : i32
%1439 = arith.extsi %1437 : i32 to i64
%1438 = arith.addi %1436, %1439 : i64
llvm.store %1438, %1426 : i64, !llvm.ptr
cf.br ^bb246
^bb248:
%1440 = llvm.load %1327 : !llvm.ptr -> i64
%1441 = llvm.load %1327 : !llvm.ptr -> i64
%1442 = arith.addi %1441, %1291 : i64
%1443 = arith.constant 0 : i32
%1444 = arith.extsi %1443 : i32 to i64
llvm.store %1444, %1426 : i64, !llvm.ptr
cf.br ^bb249
^bb249:
%1445 = llvm.load %1426 : !llvm.ptr -> i64
%1446 = arith.cmpi slt, %1445, %1442 : i64
cf.cond_br %1446, ^bb250, ^bb251
^bb250:
%1448 = llvm.load %1313 : !llvm.ptr -> i64
%1450 = llvm.load %1426 : !llvm.ptr -> i64
%1451 = llvm.getelementptr %1317[%1450] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%1449 = llvm.load %1451 : !llvm.ptr -> i8
%1452 = arith.extsi %1449 : i8 to i64
%1447 = func.call @step(%991, %1448, %1452) : (!llvm.ptr, i64, i64) -> i64
%1453 = arith.constant 65535 : i32
%1455 = arith.extsi %1453 : i32 to i64
%1454 = arith.andi %1447, %1455 : i64
llvm.store %1454, %1313 : i64, !llvm.ptr
%1456 = arith.constant 16 : i32
%1458 = arith.extsi %1456 : i32 to i64
%1457 = arith.shrsi %1447, %1458 : i64
%1459 = arith.constant 1 : i32
%1461 = arith.extsi %1459 : i32 to i64
%1460 = arith.cmpi eq, %1457, %1461 : i64
%1462 = scf.if %1460 -> (i1) {
%1463 = llvm.load %1426 : !llvm.ptr -> i64
%1464 = arith.cmpi sge, %1463, %1440 : i64
scf.yield %1464 : i1
} else {
%1465 = arith.constant false
scf.yield %1465 : i1
}
cf.cond_br %1462, ^bb252, ^bb253
^bb252:
%1466 = llvm.load %1298 : !llvm.ptr -> i64
%1467 = arith.constant 1 : i32
%1469 = arith.extsi %1467 : i32 to i64
%1468 = arith.addi %1466, %1469 : i64
llvm.store %1468, %1298 : i64, !llvm.ptr
cf.br ^bb254
^bb253:
cf.br ^bb254
^bb254:
%1470 = llvm.load %1426 : !llvm.ptr -> i64
%1471 = arith.constant 1 : i32
%1473 = arith.extsi %1471 : i32 to i64
%1472 = arith.addi %1470, %1473 : i64
llvm.store %1472, %1426 : i64, !llvm.ptr
cf.br ^bb249
^bb251:
func.call @free(%1317) : (!llvm.ptr) -> ()
cf.br ^bb227
^bb226:
cf.br ^bb227
^bb227:
func.call @free(%1276) : (!llvm.ptr) -> ()
func.call @free(%1281) : (!llvm.ptr) -> ()
%1477 = llvm.load %1298 : !llvm.ptr -> i64
%1478 = arith.cmpi sge, %1477, %arg0 : i64
cf.cond_br %1478, ^bb255, ^bb256
^bb255:
llvm.store %1271, %1039 : i64, !llvm.ptr
cf.br ^bb257
^bb256:
%1479 = arith.constant 1 : i32
%1481 = arith.extsi %1479 : i32 to i64
%1480 = arith.addi %1271, %1481 : i64
llvm.store %1480, %1035 : i64, !llvm.ptr
cf.br ^bb257
^bb257:
cf.br ^bb219
^bb221:
func.call @free(%984) : (!llvm.ptr) -> ()
func.call @free(%988) : (!llvm.ptr) -> ()
func.call @free(%991) : (!llvm.ptr) -> ()
func.call @free(%1008) : (!llvm.ptr) -> ()
%1486 = llvm.load %1035 : !llvm.ptr -> i64
func.return %1486 : i64
}
func.func @main() -> i32 {
%1487 = arith.constant 0 : i32
%1488 = arith.extsi %1487 : i32 to i64
%1489 = llvm.mlir.constant(1 : i64) : i64
%1490 = llvm.alloca %1489 x i64 : (i64) -> !llvm.ptr
llvm.store %1488, %1490 : i64, !llvm.ptr
%1491 = arith.constant 1 : i32
%1492 = arith.extsi %1491 : i32 to i64
%1493 = llvm.mlir.constant(1 : i64) : i64
%1494 = llvm.alloca %1493 x i64 : (i64) -> !llvm.ptr
llvm.store %1492, %1494 : i64, !llvm.ptr
%1495 = arith.constant 3 : i32
%1496 = arith.extsi %1495 : i32 to i64
%1497 = llvm.mlir.constant(1 : i64) : i64
%1498 = llvm.alloca %1497 x i64 : (i64) -> !llvm.ptr
llvm.store %1496, %1498 : i64, !llvm.ptr
cf.br ^bb258
^bb258:
%1499 = llvm.load %1494 : !llvm.ptr -> i64
%1500 = arith.constant 13 : i32
%1502 = arith.extsi %1500 : i32 to i64
%1501 = arith.cmpi sle, %1499, %1502 : i64
cf.cond_br %1501, ^bb259, ^bb260
^bb259:
%1503 = llvm.load %1490 : !llvm.ptr -> i64
%1505 = llvm.load %1498 : !llvm.ptr -> i64
%1504 = func.call @f_of_n(%1505) : (i64) -> i64
%1506 = arith.addi %1503, %1504 : i64
llvm.store %1506, %1490 : i64, !llvm.ptr
%1507 = llvm.load %1498 : !llvm.ptr -> i64
%1508 = arith.constant 3 : i32
%1510 = arith.extsi %1508 : i32 to i64
%1509 = arith.muli %1507, %1510 : i64
llvm.store %1509, %1498 : i64, !llvm.ptr
%1511 = llvm.load %1494 : !llvm.ptr -> i64
%1512 = arith.constant 1 : i32
%1514 = arith.extsi %1512 : i32 to i64
%1513 = arith.addi %1511, %1514 : i64
llvm.store %1513, %1494 : i64, !llvm.ptr
cf.br ^bb258
^bb260:
%1515 = llvm.mlir.addressof @str_0 : !llvm.ptr
%1516 = llvm.load %1490 : !llvm.ptr -> i64
%1517 = llvm.call @printf(%1515, %1516) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
%1518 = arith.constant 0 : i32
func.return %1518 : i32
}
}