Problem 925

Sum of B(n^2) for n=1..10^16-1, mod 1e9+7. B(n) = next lexicographic permutation of n's digits (0 if none). Pure Flow port of the native C solver using i128.

Answer400034379
Output400034379
StatusPASS
Native helperno
Runtime7200 ms
Peak memory1088 KB
Time complexityO(n log n) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n log n)O(n!)
Space complexityO(1)O(n)
ApproachFlow solutionPermutation enumeration or constraint search
VerdictOptimal

Flow source

# Project Euler 925: Next permutation of squares
# Sum of B(n^2) for n=1..10^16-1, mod 1e9+7.
# B(n) = next lexicographic permutation of n's digits (0 if none).
# Pure Flow port of the native C solver using i128.

extern {
    function calloc(n: i64, size: i64) -> ptr<void>
    function free(p: ptr<void>) -> void
    function malloc(n: i64) -> ptr<void>
    function printf(fmt: ptr<i8>, ...) -> i32
}

const MOD: i64 = 1000000007

let mut g_pow10: ptr<i128> = null as ptr<i128>
let mut g_pow10_mod: ptr<i64> = null as ptr<i64>
let mut g_K: i32 = 0

# Compute (next_permutation(n) - n) % MOD for n given as i128.
function delta_mod_i128(n0: i128) -> i64 {
    if n0 == 0 { return 0 }
    let digits: array<i32, 40> = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    let mut len: i32 = 0
    let mut tmp: i128 = n0
    while tmp > 0 {
        digits[len] = (tmp % 10) as i32
        len = len + 1
        tmp = tmp / 10
    }
    # Reverse to most-significant first
    let mut i: i32 = 0
    let mut j: i32 = len - 1
    while i < j {
        let t: i32 = digits[i]
        digits[i] = digits[j]
        digits[j] = t
        i = i + 1
        j = j - 1
    }

    # n mod MOD from digits
    let mut n_mod: i64 = 0
    for d in 0..len {
        n_mod = ((n_mod * 10) % MOD + (digits[d] as i64)) % MOD
    }

    # Find largest i with digits[i] < digits[i+1]
    let mut ii: i32 = len - 2
    while ii >= 0 && digits[ii] >= digits[ii + 1] {
        ii = ii - 1
    }
    if ii < 0 {
        let r: i64 = (MOD - n_mod) % MOD
        return r
    }

    # Find largest j > i with digits[j] > digits[i]
    let mut jj: i32 = len - 1
    while digits[jj] <= digits[ii] {
        jj = jj - 1
    }

    # Swap
    let t: i32 = digits[ii]
    digits[ii] = digits[jj]
    digits[jj] = t

    # Reverse suffix starting at i+1
    let mut lo: i32 = ii + 1
    let mut hi: i32 = len - 1
    while lo < hi {
        let tt: i32 = digits[lo]
        digits[lo] = digits[hi]
        digits[hi] = tt
        lo = lo + 1
        hi = hi - 1
    }

    # next_permutation value mod MOD
    let mut np_mod: i64 = 0
    for d in 0..len {
        np_mod = ((np_mod * 10) % MOD + (digits[d] as i64)) % MOD
    }

    let dm: i64 = (np_mod - n_mod) % MOD
    if dm < 0 { return dm + MOD }
    return dm
}

function mod_pow(a0: i64, e0: i64) -> i64 {
    let mut r: i64 = 1
    let mut a: i64 = a0 % MOD
    if a < 0 { a = a + MOD }
    let mut e: i64 = e0
    while e > 0 {
        if (e & 1) != 0 {
            r = ((r * a) % MOD) as i64
        }
        a = ((a * a) % MOD) as i64
        e = e >> 1
    }
    return r
}

function square_sum_below_power10(k: i32) -> i64 {
    let n: i64 = mod_pow(10, (k as i64))
    let mut t1: i64 = (n - 1) % MOD
    if t1 < 0 { t1 = t1 + MOD }
    let mut t2: i64 = (2 * n - 1) % MOD
    if t2 < 0 { t2 = t2 + MOD }
    let inv6: i64 = mod_pow(6, MOD - 2)
    let mut result: i64 = ((n * t1) % MOD) as i64
    result = ((result * t2) % MOD) as i64
    result = ((result * inv6) % MOD) as i64
    return result
}

function recurse(suffix0: i64, width: i32, trailing_zeros: i32) -> i64 {
    let k: i32 = g_K

    if width + trailing_zeros >= k {
        let val: i128 = (suffix0 as i128) * g_pow10[trailing_zeros]
        let sq: i128 = val * val
        return delta_mod_i128(sq)
    }

    let square_suffix: i64 = ((suffix0 as i128) * (suffix0 as i128) % g_pow10[width]) as i64
    let left_digit: i64 = square_suffix / (g_pow10[width - 1] as i64)
    let next_place: i128 = g_pow10[width]
    let next_modulus: i128 = g_pow10[width + 1]
    let free_digits: i32 = k - width - trailing_zeros - 1
    let completion_count: i64 = g_pow10_mod[free_digits]

    let mut total: i64 = 0

    for digit in 0..10 {
        let next_suffix: i128 = (digit as i128) * next_place + (suffix0 as i128)
        let next_sq: i128 = next_suffix * next_suffix
        let new_digit: i64 = ((next_sq % next_modulus) / next_place) as i64

        if new_digit >= left_digit {
            total = (total + recurse((next_suffix as i64), width + 1, trailing_zeros)) % MOD
        } else {
            let next_sq_mod: i128 = next_sq % next_modulus
            let visible: i128 = next_sq_mod * g_pow10[2 * trailing_zeros]
            let representative: i128 = g_pow10[width + 1 + 2 * trailing_zeros] + visible
            let representative_delta: i64 = delta_mod_i128(representative)

            if next_sq < next_modulus {
                total = (total + delta_mod_i128(visible)) % MOD
                let mut term: i64 = (completion_count - 1) % MOD
                if term < 0 { term = term + MOD }
                term = ((term * representative_delta) % MOD) as i64
                total = (total + term) % MOD
            } else {
                let term: i64 = ((completion_count * representative_delta) % MOD) as i64
                total = (total + term) % MOD
            }
        }
    }
    return total
}

function correction_sum(k: i32) -> i64 {
    g_K = k

    # Build pow10 array (exact, up to 2*k+2) using i128
    g_pow10[0] = 1
    for i in 1..(2 * k + 3) {
        g_pow10[i] = g_pow10[i - 1] * 10
    }

    # Build pow10_mod (up to k)
    g_pow10_mod[0] = 1
    for i in 1..(k + 1) {
        g_pow10_mod[i] = (g_pow10_mod[i - 1] * 10) % MOD
    }

    let mut total: i64 = 0
    for trailing_zeros in 0..k {
        for last_digit in 1..10 {
            total = (total + recurse((last_digit as i64), 1, trailing_zeros)) % MOD
        }
    }
    return total
}

function main() -> i32 {
    g_pow10 = (malloc(40 * 16)) as ptr<i128>
    g_pow10_mod = (malloc(20 * 8)) as ptr<i64>
    let k: i32 = 16
    let result: i64 = (square_sum_below_power10(k) + correction_sum(k)) % MOD
    printf("%lld\n", result)
    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 delta_mod_i128_i128(__int128 n0);
int64_t mod_pow_i64_i64(int64_t a0, int64_t e0);
int64_t square_sum_below_power10_i32(int32_t k);
int64_t recurse_i64_i32_i32(int64_t suffix0, int32_t width, int32_t trailing_zeros);
int64_t correction_sum_i32(int32_t k);
int32_t main(void);

static const int64_t MOD = 1000000007;

/* Module statics */
static __int128* g_pow10 = ((__int128*)(NULL));
static int64_t* g_pow10_mod = ((int64_t*)(NULL));
static int32_t g_K = 0;





int64_t delta_mod_i128_i128(__int128 n0) {
    if (n0 == 0) {
        return 0;
    }
    int32_t digits[40] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    int32_t len = 0;
    __int128 tmp = n0;
    while (tmp > 0) {
        digits[len] = ((int32_t)(FLOW_CHECKED_MOD((tmp), (10))));
        len = (len + 1);
        tmp = FLOW_CHECKED_DIV((tmp), (10));
    }
    int32_t i = 0;
    int32_t j = (len - 1);
    while (i < j) {
        int32_t t = (((unsigned)(i) < 40) ? digits[i] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(i), 40), flow_fault_handler("array index out of bounds"), digits[0]));
        digits[i] = (((unsigned)(j) < 40) ? digits[j] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(j), 40), flow_fault_handler("array index out of bounds"), digits[0]));
        digits[j] = t;
        i = (i + 1);
        j = (j - 1);
    }
    int64_t n_mod = 0;
    int32_t __flow_step_1 = 1;
    for (int32_t d = 0; (0 <= len) ? d < len : d > len; d += (0 <= len) ? 1 : -1) {
        n_mod = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((n_mod * 10)), (MOD)) + ((int64_t)((((unsigned)(d) < 40) ? digits[d] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(d), 40), flow_fault_handler("array index out of bounds"), digits[0])))))), (MOD));
    }
    int32_t ii = (len - 2);
    while ((ii >= 0 && (((unsigned)(ii) < 40) ? digits[ii] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(ii), 40), flow_fault_handler("array index out of bounds"), digits[0])) >= (((unsigned)((ii + 1)) < 40) ? digits[(ii + 1)] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)((ii + 1)), 40), flow_fault_handler("array index out of bounds"), digits[0])))) {
        ii = (ii - 1);
    }
    if (ii < 0) {
        int64_t r = FLOW_CHECKED_MOD(((MOD - n_mod)), (MOD));
        return r;
    }
    int32_t jj = (len - 1);
    while ((((unsigned)(jj) < 40) ? digits[jj] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(jj), 40), flow_fault_handler("array index out of bounds"), digits[0])) <= (((unsigned)(ii) < 40) ? digits[ii] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(ii), 40), flow_fault_handler("array index out of bounds"), digits[0]))) {
        jj = (jj - 1);
    }
    int32_t t = (((unsigned)(ii) < 40) ? digits[ii] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(ii), 40), flow_fault_handler("array index out of bounds"), digits[0]));
    digits[ii] = (((unsigned)(jj) < 40) ? digits[jj] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(jj), 40), flow_fault_handler("array index out of bounds"), digits[0]));
    digits[jj] = t;
    int32_t lo = (ii + 1);
    int32_t hi = (len - 1);
    while (lo < hi) {
        int32_t tt = (((unsigned)(lo) < 40) ? digits[lo] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(lo), 40), flow_fault_handler("array index out of bounds"), digits[0]));
        digits[lo] = (((unsigned)(hi) < 40) ? digits[hi] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(hi), 40), flow_fault_handler("array index out of bounds"), digits[0]));
        digits[hi] = tt;
        lo = (lo + 1);
        hi = (hi - 1);
    }
    int64_t np_mod = 0;
    int32_t __flow_step_2 = 1;
    for (int32_t d = 0; (0 <= len) ? d < len : d > len; d += (0 <= len) ? 1 : -1) {
        np_mod = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((np_mod * 10)), (MOD)) + ((int64_t)((((unsigned)(d) < 40) ? digits[d] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(d), 40), flow_fault_handler("array index out of bounds"), digits[0])))))), (MOD));
    }
    int64_t dm = FLOW_CHECKED_MOD(((np_mod - n_mod)), (MOD));
    if (dm < 0) {
        return (dm + MOD);
    }
    return dm;
}

int64_t mod_pow_i64_i64(int64_t a0, int64_t e0) {
    int64_t r = 1;
    int64_t a = FLOW_CHECKED_MOD((a0), (MOD));
    if (a < 0) {
        a = (a + MOD);
    }
    int64_t e = e0;
    while (e > 0) {
        if ((e & 1) != 0) {
            r = ((int64_t)(FLOW_CHECKED_MOD(((r * a)), (MOD))));
        }
        a = ((int64_t)(FLOW_CHECKED_MOD(((a * a)), (MOD))));
        e = FLOW_CHECKED_SHR((e), (1));
    }
    return r;
}

int64_t square_sum_below_power10_i32(int32_t k) {
    int64_t n = mod_pow_i64_i64(10, ((int64_t)(k)));
    int64_t t1 = FLOW_CHECKED_MOD(((n - 1)), (MOD));
    if (t1 < 0) {
        t1 = (t1 + MOD);
    }
    int64_t t2 = FLOW_CHECKED_MOD((((2 * n) - 1)), (MOD));
    if (t2 < 0) {
        t2 = (t2 + MOD);
    }
    int64_t inv6 = mod_pow_i64_i64(6, (MOD - 2));
    int64_t result = ((int64_t)(FLOW_CHECKED_MOD(((n * t1)), (MOD))));
    result = ((int64_t)(FLOW_CHECKED_MOD(((result * t2)), (MOD))));
    result = ((int64_t)(FLOW_CHECKED_MOD(((result * inv6)), (MOD))));
    return result;
}

int64_t recurse_i64_i32_i32(int64_t suffix0, int32_t width, int32_t trailing_zeros) {
    int32_t k = g_K;
    if ((width + trailing_zeros) >= k) {
        __int128 val = (((__int128)(suffix0)) * g_pow10[trailing_zeros]);
        __int128 sq = (val * val);
        return delta_mod_i128_i128(sq);
    }
    int64_t square_suffix = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(suffix0)) * ((__int128)(suffix0)))), (g_pow10[width]))));
    int64_t left_digit = FLOW_CHECKED_DIV((square_suffix), (((int64_t)(g_pow10[(width - 1)]))));
    __int128 next_place = g_pow10[width];
    __int128 next_modulus = g_pow10[(width + 1)];
    int32_t free_digits = (((k - width) - trailing_zeros) - 1);
    int64_t completion_count = g_pow10_mod[free_digits];
    int64_t total = 0;
    int32_t __flow_step_3 = 1;
    for (int32_t digit = 0; (0 <= 10) ? digit < 10 : digit > 10; digit += (0 <= 10) ? 1 : -1) {
        __int128 next_suffix = ((((__int128)(digit)) * next_place) + ((__int128)(suffix0)));
        __int128 next_sq = (next_suffix * next_suffix);
        int64_t new_digit = ((int64_t)(FLOW_CHECKED_DIV((FLOW_CHECKED_MOD((next_sq), (next_modulus))), (next_place))));
        if (new_digit >= left_digit) {
            total = FLOW_CHECKED_MOD(((total + recurse_i64_i32_i32(((int64_t)(next_suffix)), (width + 1), trailing_zeros))), (MOD));
        } else {
            __int128 next_sq_mod = FLOW_CHECKED_MOD((next_sq), (next_modulus));
            __int128 visible = (next_sq_mod * g_pow10[(2 * trailing_zeros)]);
            __int128 representative = (g_pow10[((width + 1) + (2 * trailing_zeros))] + visible);
            int64_t representative_delta = delta_mod_i128_i128(representative);
            if (next_sq < next_modulus) {
                total = FLOW_CHECKED_MOD(((total + delta_mod_i128_i128(visible))), (MOD));
                int64_t term = FLOW_CHECKED_MOD(((completion_count - 1)), (MOD));
                if (term < 0) {
                    term = (term + MOD);
                }
                term = ((int64_t)(FLOW_CHECKED_MOD(((term * representative_delta)), (MOD))));
                total = FLOW_CHECKED_MOD(((total + term)), (MOD));
            } else {
                int64_t term = ((int64_t)(FLOW_CHECKED_MOD(((completion_count * representative_delta)), (MOD))));
                total = FLOW_CHECKED_MOD(((total + term)), (MOD));
            }
        }
    }
    return total;
}

int64_t correction_sum_i32(int32_t k) {
    g_K = k;
    g_pow10[0] = 1;
    int32_t __flow_step_4 = 1;
    for (int32_t i = 1; (1 <= ((2 * k) + 3)) ? i < ((2 * k) + 3) : i > ((2 * k) + 3); i += (1 <= ((2 * k) + 3)) ? 1 : -1) {
        g_pow10[i] = (g_pow10[(i - 1)] * 10);
    }
    g_pow10_mod[0] = 1;
    int32_t __flow_step_5 = 1;
    for (int32_t i = 1; (1 <= (k + 1)) ? i < (k + 1) : i > (k + 1); i += (1 <= (k + 1)) ? 1 : -1) {
        g_pow10_mod[i] = FLOW_CHECKED_MOD(((g_pow10_mod[(i - 1)] * 10)), (MOD));
    }
    int64_t total = 0;
    int32_t __flow_step_6 = 1;
    for (int32_t trailing_zeros = 0; (0 <= k) ? trailing_zeros < k : trailing_zeros > k; trailing_zeros += (0 <= k) ? 1 : -1) {
        int32_t __flow_step_7 = 1;
        for (int32_t last_digit = 1; (1 <= 10) ? last_digit < 10 : last_digit > 10; last_digit += (1 <= 10) ? 1 : -1) {
            total = FLOW_CHECKED_MOD(((total + recurse_i64_i32_i32(((int64_t)(last_digit)), 1, trailing_zeros))), (MOD));
        }
    }
    return total;
}

int32_t main(void) {
    g_pow10 = ((__int128*)(malloc((40 * 16))));
    g_pow10_mod = ((int64_t*)(malloc((20 * 8))));
    int32_t k = 16;
    int64_t result = FLOW_CHECKED_MOD(((square_sum_below_power10_i32(k) + correction_sum_i32(k))), (MOD));
    printf("%lld\n", result);
    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 private @malloc(i64) -> !llvm.ptr

  // Constant: MOD
  llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
  // Module static: g_pow10
  llvm.mlir.global internal @g_pow10() {addr_space = 0 : i32} : !llvm.ptr {
    %0 = llvm.mlir.zero : !llvm.ptr
    llvm.return %0 : !llvm.ptr
  }
  // Module static: g_pow10_mod
  llvm.mlir.global internal @g_pow10_mod() {addr_space = 0 : i32} : !llvm.ptr {
    %1 = llvm.mlir.zero : !llvm.ptr
    llvm.return %1 : !llvm.ptr
  }
  // Module static: g_K
  llvm.mlir.global internal @g_K(0 : i32) : i32
  func.func @delta_mod_i128(%arg0: i128) -> i64 {
    %2 = arith.constant 0 : i32
    %4 = arith.trunci %arg0 : i128 to i64
    %5 = arith.extsi %2 : i32 to i64
    %3 = arith.cmpi eq, %4, %5 : i64
    cf.cond_br %3, ^bb0, ^bb1
    ^bb0:
      %6 = arith.constant 0 : i32
      %7 = arith.extsi %6 : i32 to i64
      func.return %7 : i64
    ^bb1:
      cf.br ^bb2
    ^bb2:
    %9 = arith.constant 0 : i32
    %10 = arith.constant 0 : i32
    %11 = arith.constant 0 : i32
    %12 = arith.constant 0 : i32
    %13 = arith.constant 0 : i32
    %14 = arith.constant 0 : i32
    %15 = arith.constant 0 : i32
    %16 = arith.constant 0 : i32
    %17 = arith.constant 0 : i32
    %18 = arith.constant 0 : i32
    %19 = arith.constant 0 : i32
    %20 = arith.constant 0 : i32
    %21 = arith.constant 0 : i32
    %22 = arith.constant 0 : i32
    %23 = arith.constant 0 : i32
    %24 = arith.constant 0 : i32
    %25 = arith.constant 0 : i32
    %26 = arith.constant 0 : i32
    %27 = arith.constant 0 : i32
    %28 = arith.constant 0 : i32
    %29 = arith.constant 0 : i32
    %30 = arith.constant 0 : i32
    %31 = arith.constant 0 : i32
    %32 = arith.constant 0 : i32
    %33 = arith.constant 0 : i32
    %34 = arith.constant 0 : i32
    %35 = arith.constant 0 : i32
    %36 = arith.constant 0 : i32
    %37 = arith.constant 0 : i32
    %38 = arith.constant 0 : i32
    %39 = arith.constant 0 : i32
    %40 = arith.constant 0 : i32
    %41 = arith.constant 0 : i32
    %42 = arith.constant 0 : i32
    %43 = arith.constant 0 : i32
    %44 = arith.constant 0 : i32
    %45 = arith.constant 0 : i32
    %46 = arith.constant 0 : i32
    %47 = arith.constant 0 : i32
    %48 = arith.constant 0 : i32
    %49 = llvm.mlir.constant(1 : i64) : i64
    %50 = llvm.alloca %49 x !llvm.array<40 x i32> : (i64) -> !llvm.ptr
    %51 = llvm.mlir.zero : !llvm.array<40 x i32>
    llvm.store %51, %50 : !llvm.array<40 x i32>, !llvm.ptr
    %52 = llvm.mlir.constant(0 : i64) : i64
    %53 = llvm.getelementptr %50[0, %52] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %9, %53 : i32, !llvm.ptr
    %54 = llvm.mlir.constant(1 : i64) : i64
    %55 = llvm.getelementptr %50[0, %54] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %10, %55 : i32, !llvm.ptr
    %56 = llvm.mlir.constant(2 : i64) : i64
    %57 = llvm.getelementptr %50[0, %56] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %11, %57 : i32, !llvm.ptr
    %58 = llvm.mlir.constant(3 : i64) : i64
    %59 = llvm.getelementptr %50[0, %58] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %12, %59 : i32, !llvm.ptr
    %60 = llvm.mlir.constant(4 : i64) : i64
    %61 = llvm.getelementptr %50[0, %60] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %13, %61 : i32, !llvm.ptr
    %62 = llvm.mlir.constant(5 : i64) : i64
    %63 = llvm.getelementptr %50[0, %62] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %14, %63 : i32, !llvm.ptr
    %64 = llvm.mlir.constant(6 : i64) : i64
    %65 = llvm.getelementptr %50[0, %64] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %15, %65 : i32, !llvm.ptr
    %66 = llvm.mlir.constant(7 : i64) : i64
    %67 = llvm.getelementptr %50[0, %66] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %16, %67 : i32, !llvm.ptr
    %68 = llvm.mlir.constant(8 : i64) : i64
    %69 = llvm.getelementptr %50[0, %68] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %17, %69 : i32, !llvm.ptr
    %70 = llvm.mlir.constant(9 : i64) : i64
    %71 = llvm.getelementptr %50[0, %70] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %18, %71 : i32, !llvm.ptr
    %72 = llvm.mlir.constant(10 : i64) : i64
    %73 = llvm.getelementptr %50[0, %72] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %19, %73 : i32, !llvm.ptr
    %74 = llvm.mlir.constant(11 : i64) : i64
    %75 = llvm.getelementptr %50[0, %74] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %20, %75 : i32, !llvm.ptr
    %76 = llvm.mlir.constant(12 : i64) : i64
    %77 = llvm.getelementptr %50[0, %76] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %21, %77 : i32, !llvm.ptr
    %78 = llvm.mlir.constant(13 : i64) : i64
    %79 = llvm.getelementptr %50[0, %78] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %22, %79 : i32, !llvm.ptr
    %80 = llvm.mlir.constant(14 : i64) : i64
    %81 = llvm.getelementptr %50[0, %80] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %23, %81 : i32, !llvm.ptr
    %82 = llvm.mlir.constant(15 : i64) : i64
    %83 = llvm.getelementptr %50[0, %82] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %24, %83 : i32, !llvm.ptr
    %84 = llvm.mlir.constant(16 : i64) : i64
    %85 = llvm.getelementptr %50[0, %84] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %25, %85 : i32, !llvm.ptr
    %86 = llvm.mlir.constant(17 : i64) : i64
    %87 = llvm.getelementptr %50[0, %86] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %26, %87 : i32, !llvm.ptr
    %88 = llvm.mlir.constant(18 : i64) : i64
    %89 = llvm.getelementptr %50[0, %88] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %27, %89 : i32, !llvm.ptr
    %90 = llvm.mlir.constant(19 : i64) : i64
    %91 = llvm.getelementptr %50[0, %90] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %28, %91 : i32, !llvm.ptr
    %92 = llvm.mlir.constant(20 : i64) : i64
    %93 = llvm.getelementptr %50[0, %92] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %29, %93 : i32, !llvm.ptr
    %94 = llvm.mlir.constant(21 : i64) : i64
    %95 = llvm.getelementptr %50[0, %94] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %30, %95 : i32, !llvm.ptr
    %96 = llvm.mlir.constant(22 : i64) : i64
    %97 = llvm.getelementptr %50[0, %96] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %31, %97 : i32, !llvm.ptr
    %98 = llvm.mlir.constant(23 : i64) : i64
    %99 = llvm.getelementptr %50[0, %98] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %32, %99 : i32, !llvm.ptr
    %100 = llvm.mlir.constant(24 : i64) : i64
    %101 = llvm.getelementptr %50[0, %100] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %33, %101 : i32, !llvm.ptr
    %102 = llvm.mlir.constant(25 : i64) : i64
    %103 = llvm.getelementptr %50[0, %102] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %34, %103 : i32, !llvm.ptr
    %104 = llvm.mlir.constant(26 : i64) : i64
    %105 = llvm.getelementptr %50[0, %104] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %35, %105 : i32, !llvm.ptr
    %106 = llvm.mlir.constant(27 : i64) : i64
    %107 = llvm.getelementptr %50[0, %106] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %36, %107 : i32, !llvm.ptr
    %108 = llvm.mlir.constant(28 : i64) : i64
    %109 = llvm.getelementptr %50[0, %108] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %37, %109 : i32, !llvm.ptr
    %110 = llvm.mlir.constant(29 : i64) : i64
    %111 = llvm.getelementptr %50[0, %110] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %38, %111 : i32, !llvm.ptr
    %112 = llvm.mlir.constant(30 : i64) : i64
    %113 = llvm.getelementptr %50[0, %112] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %39, %113 : i32, !llvm.ptr
    %114 = llvm.mlir.constant(31 : i64) : i64
    %115 = llvm.getelementptr %50[0, %114] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %40, %115 : i32, !llvm.ptr
    %116 = llvm.mlir.constant(32 : i64) : i64
    %117 = llvm.getelementptr %50[0, %116] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %41, %117 : i32, !llvm.ptr
    %118 = llvm.mlir.constant(33 : i64) : i64
    %119 = llvm.getelementptr %50[0, %118] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %42, %119 : i32, !llvm.ptr
    %120 = llvm.mlir.constant(34 : i64) : i64
    %121 = llvm.getelementptr %50[0, %120] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %43, %121 : i32, !llvm.ptr
    %122 = llvm.mlir.constant(35 : i64) : i64
    %123 = llvm.getelementptr %50[0, %122] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %44, %123 : i32, !llvm.ptr
    %124 = llvm.mlir.constant(36 : i64) : i64
    %125 = llvm.getelementptr %50[0, %124] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %45, %125 : i32, !llvm.ptr
    %126 = llvm.mlir.constant(37 : i64) : i64
    %127 = llvm.getelementptr %50[0, %126] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %46, %127 : i32, !llvm.ptr
    %128 = llvm.mlir.constant(38 : i64) : i64
    %129 = llvm.getelementptr %50[0, %128] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %47, %129 : i32, !llvm.ptr
    %130 = llvm.mlir.constant(39 : i64) : i64
    %131 = llvm.getelementptr %50[0, %130] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %48, %131 : i32, !llvm.ptr
    %132 = arith.constant 0 : i32
    %133 = llvm.mlir.constant(1 : i64) : i64
    %134 = llvm.alloca %133 x i32 : (i64) -> !llvm.ptr
    llvm.store %132, %134 : i32, !llvm.ptr
    %135 = llvm.mlir.constant(1 : i64) : i64
    %136 = llvm.alloca %135 x i128 : (i64) -> !llvm.ptr
    llvm.store %arg0, %136 : i128, !llvm.ptr
    cf.br ^bb3
    ^bb3:
    %137 = llvm.load %136 : !llvm.ptr -> i128
    %138 = arith.constant 0 : i32
    %140 = arith.trunci %137 : i128 to i64
    %141 = arith.extsi %138 : i32 to i64
    %139 = arith.cmpi sgt, %140, %141 : i64
    cf.cond_br %139, ^bb4, ^bb5
    ^bb4:
      %142 = llvm.load %136 : !llvm.ptr -> i128
      %143 = arith.constant 10 : i32
      %145 = arith.trunci %142 : i128 to i64
      %146 = arith.extsi %143 : i32 to i64
      %144 = arith.remsi %145, %146 : i64
      %147 = arith.trunci %144 : i64 to i32
      %148 = llvm.load %134 : !llvm.ptr -> i32
      %149 = arith.extsi %148 : i32 to i64
      %150 = llvm.getelementptr %50[0, %149] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
      llvm.store %147, %150 : i32, !llvm.ptr
      %151 = llvm.load %134 : !llvm.ptr -> i32
      %152 = arith.constant 1 : i32
      %153 = arith.addi %151, %152 : i32
      llvm.store %153, %134 : i32, !llvm.ptr
      %154 = llvm.load %136 : !llvm.ptr -> i128
      %155 = arith.constant 10 : i32
      %157 = arith.trunci %154 : i128 to i64
      %158 = arith.extsi %155 : i32 to i64
      %156 = arith.divsi %157, %158 : i64
      %159 = arith.extsi %156 : i64 to i128
      llvm.store %159, %136 : i128, !llvm.ptr
      cf.br ^bb3
    ^bb5:
    %160 = arith.constant 0 : i32
    %161 = llvm.mlir.constant(1 : i64) : i64
    %162 = llvm.alloca %161 x i32 : (i64) -> !llvm.ptr
    llvm.store %160, %162 : i32, !llvm.ptr
    %163 = llvm.load %134 : !llvm.ptr -> i32
    %164 = arith.constant 1 : i32
    %165 = arith.subi %163, %164 : i32
    %166 = llvm.mlir.constant(1 : i64) : i64
    %167 = llvm.alloca %166 x i32 : (i64) -> !llvm.ptr
    llvm.store %165, %167 : i32, !llvm.ptr
    cf.br ^bb6
    ^bb6:
    %168 = llvm.load %162 : !llvm.ptr -> i32
    %169 = llvm.load %167 : !llvm.ptr -> i32
    %170 = arith.cmpi slt, %168, %169 : i32
    cf.cond_br %170, ^bb7, ^bb8
    ^bb7:
      %172 = llvm.load %162 : !llvm.ptr -> i32
      %173 = arith.extsi %172 : i32 to i64
      %174 = llvm.getelementptr %50[0, %173] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
      %171 = llvm.load %174 : !llvm.ptr -> i32
      %176 = llvm.load %167 : !llvm.ptr -> i32
      %177 = arith.extsi %176 : i32 to i64
      %178 = llvm.getelementptr %50[0, %177] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
      %175 = llvm.load %178 : !llvm.ptr -> i32
      %179 = llvm.load %162 : !llvm.ptr -> i32
      %180 = arith.extsi %179 : i32 to i64
      %181 = llvm.getelementptr %50[0, %180] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
      llvm.store %175, %181 : i32, !llvm.ptr
      %182 = llvm.load %167 : !llvm.ptr -> i32
      %183 = arith.extsi %182 : i32 to i64
      %184 = llvm.getelementptr %50[0, %183] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
      llvm.store %171, %184 : i32, !llvm.ptr
      %185 = llvm.load %162 : !llvm.ptr -> i32
      %186 = arith.constant 1 : i32
      %187 = arith.addi %185, %186 : i32
      llvm.store %187, %162 : i32, !llvm.ptr
      %188 = llvm.load %167 : !llvm.ptr -> i32
      %189 = arith.constant 1 : i32
      %190 = arith.subi %188, %189 : i32
      llvm.store %190, %167 : i32, !llvm.ptr
      cf.br ^bb6
    ^bb8:
    %191 = arith.constant 0 : i32
    %192 = arith.extsi %191 : i32 to i64
    %193 = llvm.mlir.constant(1 : i64) : i64
    %194 = llvm.alloca %193 x i64 : (i64) -> !llvm.ptr
    llvm.store %192, %194 : i64, !llvm.ptr
    %195 = arith.constant 0 : i32
    %196 = llvm.load %134 : !llvm.ptr -> i32
    %197 = arith.index_cast %195 : i32 to index
    %198 = arith.index_cast %196 : i32 to index
    %200 = arith.constant 1 : index
    %201 = arith.constant -1 : index
    %202 = arith.cmpi sle, %197, %198 : index
    %199 = arith.select %202, %200, %201 : index
    cf.br ^bb9(%197 : index)
    ^bb9(%203: index):
    %204 = arith.cmpi slt, %203, %198 : index
    %205 = arith.cmpi sgt, %203, %198 : index
    %206 = arith.select %202, %204, %205 : i1
    cf.cond_br %206, ^bb10(%203 : index), ^bb11(%203 : index)
    ^bb10(%207: index):
      %208 = llvm.load %194 : !llvm.ptr -> i64
      %209 = arith.constant 10 : i32
      %211 = arith.extsi %209 : i32 to i64
      %210 = arith.muli %208, %211 : i64
      %212 = llvm.mlir.addressof @MOD : !llvm.ptr
      %213 = llvm.load %212 : !llvm.ptr -> i64
      %214 = arith.remsi %210, %213 : i64
      %216 = arith.index_cast %207 : index to i64
      %217 = llvm.getelementptr %50[0, %216] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
      %215 = llvm.load %217 : !llvm.ptr -> i32
      %218 = arith.extsi %215 : i32 to i64
      %219 = arith.addi %214, %218 : i64
      %220 = llvm.mlir.addressof @MOD : !llvm.ptr
      %221 = llvm.load %220 : !llvm.ptr -> i64
      %222 = arith.remsi %219, %221 : i64
      llvm.store %222, %194 : i64, !llvm.ptr
      %223 = arith.addi %207, %199 : index
      cf.br ^bb9(%223 : index)
    ^bb11(%224: index):
    %225 = llvm.load %134 : !llvm.ptr -> i32
    %226 = arith.constant 2 : i32
    %227 = arith.subi %225, %226 : i32
    %228 = llvm.mlir.constant(1 : i64) : i64
    %229 = llvm.alloca %228 x i32 : (i64) -> !llvm.ptr
    llvm.store %227, %229 : i32, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %230 = llvm.load %229 : !llvm.ptr -> i32
    %231 = arith.constant 0 : i32
    %232 = arith.cmpi sge, %230, %231 : i32
    %233 = scf.if %232 -> (i1) {
      %235 = llvm.load %229 : !llvm.ptr -> i32
      %236 = arith.extsi %235 : i32 to i64
      %237 = llvm.getelementptr %50[0, %236] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
      %234 = llvm.load %237 : !llvm.ptr -> i32
      %239 = llvm.load %229 : !llvm.ptr -> i32
      %240 = arith.constant 1 : i32
      %241 = arith.addi %239, %240 : i32
      %242 = arith.extsi %241 : i32 to i64
      %243 = llvm.getelementptr %50[0, %242] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
      %238 = llvm.load %243 : !llvm.ptr -> i32
      %244 = arith.cmpi sge, %234, %238 : i32
      scf.yield %244 : i1
    } else {
      %245 = arith.constant false
      scf.yield %245 : i1
    }
    cf.cond_br %233, ^bb13, ^bb14
    ^bb13:
      %246 = llvm.load %229 : !llvm.ptr -> i32
      %247 = arith.constant 1 : i32
      %248 = arith.subi %246, %247 : i32
      llvm.store %248, %229 : i32, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %249 = llvm.load %229 : !llvm.ptr -> i32
    %250 = arith.constant 0 : i32
    %251 = arith.cmpi slt, %249, %250 : i32
    cf.cond_br %251, ^bb15, ^bb16
    ^bb15:
      %252 = llvm.mlir.addressof @MOD : !llvm.ptr
      %253 = llvm.load %252 : !llvm.ptr -> i64
      %254 = llvm.load %194 : !llvm.ptr -> i64
      %255 = arith.subi %253, %254 : i64
      %256 = llvm.mlir.addressof @MOD : !llvm.ptr
      %257 = llvm.load %256 : !llvm.ptr -> i64
      %258 = arith.remsi %255, %257 : i64
      func.return %258 : i64
    ^bb16:
      cf.br ^bb17
    ^bb17:
    %259 = llvm.load %134 : !llvm.ptr -> i32
    %260 = arith.constant 1 : i32
    %261 = arith.subi %259, %260 : i32
    %262 = llvm.mlir.constant(1 : i64) : i64
    %263 = llvm.alloca %262 x i32 : (i64) -> !llvm.ptr
    llvm.store %261, %263 : i32, !llvm.ptr
    cf.br ^bb18
    ^bb18:
    %265 = llvm.load %263 : !llvm.ptr -> i32
    %266 = arith.extsi %265 : i32 to i64
    %267 = llvm.getelementptr %50[0, %266] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    %264 = llvm.load %267 : !llvm.ptr -> i32
    %269 = llvm.load %229 : !llvm.ptr -> i32
    %270 = arith.extsi %269 : i32 to i64
    %271 = llvm.getelementptr %50[0, %270] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    %268 = llvm.load %271 : !llvm.ptr -> i32
    %272 = arith.cmpi sle, %264, %268 : i32
    cf.cond_br %272, ^bb19, ^bb20
    ^bb19:
      %273 = llvm.load %263 : !llvm.ptr -> i32
      %274 = arith.constant 1 : i32
      %275 = arith.subi %273, %274 : i32
      llvm.store %275, %263 : i32, !llvm.ptr
      cf.br ^bb18
    ^bb20:
    %277 = llvm.load %229 : !llvm.ptr -> i32
    %278 = arith.extsi %277 : i32 to i64
    %279 = llvm.getelementptr %50[0, %278] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    %276 = llvm.load %279 : !llvm.ptr -> i32
    %281 = llvm.load %263 : !llvm.ptr -> i32
    %282 = arith.extsi %281 : i32 to i64
    %283 = llvm.getelementptr %50[0, %282] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    %280 = llvm.load %283 : !llvm.ptr -> i32
    %284 = llvm.load %229 : !llvm.ptr -> i32
    %285 = arith.extsi %284 : i32 to i64
    %286 = llvm.getelementptr %50[0, %285] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %280, %286 : i32, !llvm.ptr
    %287 = llvm.load %263 : !llvm.ptr -> i32
    %288 = arith.extsi %287 : i32 to i64
    %289 = llvm.getelementptr %50[0, %288] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
    llvm.store %276, %289 : i32, !llvm.ptr
    %290 = llvm.load %229 : !llvm.ptr -> i32
    %291 = arith.constant 1 : i32
    %292 = arith.addi %290, %291 : i32
    %293 = llvm.mlir.constant(1 : i64) : i64
    %294 = llvm.alloca %293 x i32 : (i64) -> !llvm.ptr
    llvm.store %292, %294 : i32, !llvm.ptr
    %295 = llvm.load %134 : !llvm.ptr -> i32
    %296 = arith.constant 1 : i32
    %297 = arith.subi %295, %296 : i32
    %298 = llvm.mlir.constant(1 : i64) : i64
    %299 = llvm.alloca %298 x i32 : (i64) -> !llvm.ptr
    llvm.store %297, %299 : i32, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %300 = llvm.load %294 : !llvm.ptr -> i32
    %301 = llvm.load %299 : !llvm.ptr -> i32
    %302 = arith.cmpi slt, %300, %301 : i32
    cf.cond_br %302, ^bb22, ^bb23
    ^bb22:
      %304 = llvm.load %294 : !llvm.ptr -> i32
      %305 = arith.extsi %304 : i32 to i64
      %306 = llvm.getelementptr %50[0, %305] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
      %303 = llvm.load %306 : !llvm.ptr -> i32
      %308 = llvm.load %299 : !llvm.ptr -> i32
      %309 = arith.extsi %308 : i32 to i64
      %310 = llvm.getelementptr %50[0, %309] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
      %307 = llvm.load %310 : !llvm.ptr -> i32
      %311 = llvm.load %294 : !llvm.ptr -> i32
      %312 = arith.extsi %311 : i32 to i64
      %313 = llvm.getelementptr %50[0, %312] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
      llvm.store %307, %313 : i32, !llvm.ptr
      %314 = llvm.load %299 : !llvm.ptr -> i32
      %315 = arith.extsi %314 : i32 to i64
      %316 = llvm.getelementptr %50[0, %315] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
      llvm.store %303, %316 : i32, !llvm.ptr
      %317 = llvm.load %294 : !llvm.ptr -> i32
      %318 = arith.constant 1 : i32
      %319 = arith.addi %317, %318 : i32
      llvm.store %319, %294 : i32, !llvm.ptr
      %320 = llvm.load %299 : !llvm.ptr -> i32
      %321 = arith.constant 1 : i32
      %322 = arith.subi %320, %321 : i32
      llvm.store %322, %299 : i32, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %323 = arith.constant 0 : i32
    %324 = arith.extsi %323 : i32 to i64
    %325 = llvm.mlir.constant(1 : i64) : i64
    %326 = llvm.alloca %325 x i64 : (i64) -> !llvm.ptr
    llvm.store %324, %326 : i64, !llvm.ptr
    %327 = arith.constant 0 : i32
    %328 = llvm.load %134 : !llvm.ptr -> i32
    %329 = arith.index_cast %327 : i32 to index
    %330 = arith.index_cast %328 : i32 to index
    %332 = arith.constant 1 : index
    %333 = arith.constant -1 : index
    %334 = arith.cmpi sle, %329, %330 : index
    %331 = arith.select %334, %332, %333 : index
    cf.br ^bb24(%329 : index)
    ^bb24(%335: index):
    %336 = arith.cmpi slt, %335, %330 : index
    %337 = arith.cmpi sgt, %335, %330 : index
    %338 = arith.select %334, %336, %337 : i1
    cf.cond_br %338, ^bb25(%335 : index), ^bb26(%335 : index)
    ^bb25(%339: index):
      %340 = llvm.load %326 : !llvm.ptr -> i64
      %341 = arith.constant 10 : i32
      %343 = arith.extsi %341 : i32 to i64
      %342 = arith.muli %340, %343 : i64
      %344 = llvm.mlir.addressof @MOD : !llvm.ptr
      %345 = llvm.load %344 : !llvm.ptr -> i64
      %346 = arith.remsi %342, %345 : i64
      %348 = arith.index_cast %339 : index to i64
      %349 = llvm.getelementptr %50[0, %348] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<40 x i32>
      %347 = llvm.load %349 : !llvm.ptr -> i32
      %350 = arith.extsi %347 : i32 to i64
      %351 = arith.addi %346, %350 : i64
      %352 = llvm.mlir.addressof @MOD : !llvm.ptr
      %353 = llvm.load %352 : !llvm.ptr -> i64
      %354 = arith.remsi %351, %353 : i64
      llvm.store %354, %326 : i64, !llvm.ptr
      %355 = arith.addi %339, %331 : index
      cf.br ^bb24(%355 : index)
    ^bb26(%356: index):
    %357 = llvm.load %326 : !llvm.ptr -> i64
    %358 = llvm.load %194 : !llvm.ptr -> i64
    %359 = arith.subi %357, %358 : i64
    %360 = llvm.mlir.addressof @MOD : !llvm.ptr
    %361 = llvm.load %360 : !llvm.ptr -> i64
    %362 = arith.remsi %359, %361 : i64
    %363 = arith.constant 0 : i32
    %365 = arith.extsi %363 : i32 to i64
    %364 = arith.cmpi slt, %362, %365 : i64
    cf.cond_br %364, ^bb27, ^bb28
    ^bb27:
      %366 = llvm.mlir.addressof @MOD : !llvm.ptr
      %367 = llvm.load %366 : !llvm.ptr -> i64
      %368 = arith.addi %362, %367 : i64
      func.return %368 : i64
    ^bb28:
      cf.br ^bb29
    ^bb29:
    func.return %362 : i64
  }
  func.func @mod_pow(%arg0: i64, %arg1: i64) -> i64 {
    %369 = arith.constant 1 : i32
    %370 = arith.extsi %369 : i32 to i64
    %371 = llvm.mlir.constant(1 : i64) : i64
    %372 = llvm.alloca %371 x i64 : (i64) -> !llvm.ptr
    llvm.store %370, %372 : i64, !llvm.ptr
    %373 = llvm.mlir.addressof @MOD : !llvm.ptr
    %374 = llvm.load %373 : !llvm.ptr -> i64
    %375 = arith.remsi %arg0, %374 : i64
    %376 = llvm.mlir.constant(1 : i64) : i64
    %377 = llvm.alloca %376 x i64 : (i64) -> !llvm.ptr
    llvm.store %375, %377 : i64, !llvm.ptr
    %378 = llvm.load %377 : !llvm.ptr -> i64
    %379 = arith.constant 0 : i32
    %381 = arith.extsi %379 : i32 to i64
    %380 = arith.cmpi slt, %378, %381 : i64
    cf.cond_br %380, ^bb30, ^bb31
    ^bb30:
      %382 = llvm.load %377 : !llvm.ptr -> i64
      %383 = llvm.mlir.addressof @MOD : !llvm.ptr
      %384 = llvm.load %383 : !llvm.ptr -> i64
      %385 = arith.addi %382, %384 : i64
      llvm.store %385, %377 : i64, !llvm.ptr
      cf.br ^bb32
    ^bb31:
      cf.br ^bb32
    ^bb32:
    %386 = llvm.mlir.constant(1 : i64) : i64
    %387 = llvm.alloca %386 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %387 : i64, !llvm.ptr
    cf.br ^bb33
    ^bb33:
    %388 = llvm.load %387 : !llvm.ptr -> i64
    %389 = arith.constant 0 : i32
    %391 = arith.extsi %389 : i32 to i64
    %390 = arith.cmpi sgt, %388, %391 : i64
    cf.cond_br %390, ^bb34, ^bb35
    ^bb34:
      %392 = llvm.load %387 : !llvm.ptr -> i64
      %393 = arith.constant 1 : i32
      %395 = arith.extsi %393 : i32 to i64
      %394 = arith.andi %392, %395 : i64
      %396 = arith.constant 0 : i32
      %398 = arith.extsi %396 : i32 to i64
      %397 = arith.cmpi ne, %394, %398 : i64
      cf.cond_br %397, ^bb36, ^bb37
      ^bb36:
        %399 = llvm.load %372 : !llvm.ptr -> i64
        %400 = llvm.load %377 : !llvm.ptr -> i64
        %401 = arith.muli %399, %400 : i64
        %402 = llvm.mlir.addressof @MOD : !llvm.ptr
        %403 = llvm.load %402 : !llvm.ptr -> i64
        %404 = arith.remsi %401, %403 : i64
        llvm.store %404, %372 : i64, !llvm.ptr
        cf.br ^bb38
      ^bb37:
        cf.br ^bb38
      ^bb38:
      %405 = llvm.load %377 : !llvm.ptr -> i64
      %406 = llvm.load %377 : !llvm.ptr -> i64
      %407 = arith.muli %405, %406 : i64
      %408 = llvm.mlir.addressof @MOD : !llvm.ptr
      %409 = llvm.load %408 : !llvm.ptr -> i64
      %410 = arith.remsi %407, %409 : i64
      llvm.store %410, %377 : i64, !llvm.ptr
      %411 = llvm.load %387 : !llvm.ptr -> i64
      %412 = arith.constant 1 : i32
      %414 = arith.extsi %412 : i32 to i64
      %413 = arith.shrsi %411, %414 : i64
      llvm.store %413, %387 : i64, !llvm.ptr
      cf.br ^bb33
    ^bb35:
    %415 = llvm.load %372 : !llvm.ptr -> i64
    func.return %415 : i64
  }
  func.func @square_sum_below_power10(%arg0: i32) -> i64 {
    %417 = arith.constant 10 : i32
    %418 = arith.extsi %arg0 : i32 to i64
    %419 = arith.extsi %417 : i32 to i64
    %416 = func.call @mod_pow(%419, %418) : (i64, i64) -> i64
    %420 = arith.constant 1 : i32
    %422 = arith.extsi %420 : i32 to i64
    %421 = arith.subi %416, %422 : i64
    %423 = llvm.mlir.addressof @MOD : !llvm.ptr
    %424 = llvm.load %423 : !llvm.ptr -> i64
    %425 = arith.remsi %421, %424 : i64
    %426 = llvm.mlir.constant(1 : i64) : i64
    %427 = llvm.alloca %426 x i64 : (i64) -> !llvm.ptr
    llvm.store %425, %427 : i64, !llvm.ptr
    %428 = llvm.load %427 : !llvm.ptr -> i64
    %429 = arith.constant 0 : i32
    %431 = arith.extsi %429 : i32 to i64
    %430 = arith.cmpi slt, %428, %431 : i64
    cf.cond_br %430, ^bb39, ^bb40
    ^bb39:
      %432 = llvm.load %427 : !llvm.ptr -> i64
      %433 = llvm.mlir.addressof @MOD : !llvm.ptr
      %434 = llvm.load %433 : !llvm.ptr -> i64
      %435 = arith.addi %432, %434 : i64
      llvm.store %435, %427 : i64, !llvm.ptr
      cf.br ^bb41
    ^bb40:
      cf.br ^bb41
    ^bb41:
    %436 = arith.constant 2 : i32
    %438 = arith.extsi %436 : i32 to i64
    %437 = arith.muli %438, %416 : i64
    %439 = arith.constant 1 : i32
    %441 = arith.extsi %439 : i32 to i64
    %440 = arith.subi %437, %441 : i64
    %442 = llvm.mlir.addressof @MOD : !llvm.ptr
    %443 = llvm.load %442 : !llvm.ptr -> i64
    %444 = arith.remsi %440, %443 : i64
    %445 = llvm.mlir.constant(1 : i64) : i64
    %446 = llvm.alloca %445 x i64 : (i64) -> !llvm.ptr
    llvm.store %444, %446 : i64, !llvm.ptr
    %447 = llvm.load %446 : !llvm.ptr -> i64
    %448 = arith.constant 0 : i32
    %450 = arith.extsi %448 : i32 to i64
    %449 = arith.cmpi slt, %447, %450 : i64
    cf.cond_br %449, ^bb42, ^bb43
    ^bb42:
      %451 = llvm.load %446 : !llvm.ptr -> i64
      %452 = llvm.mlir.addressof @MOD : !llvm.ptr
      %453 = llvm.load %452 : !llvm.ptr -> i64
      %454 = arith.addi %451, %453 : i64
      llvm.store %454, %446 : i64, !llvm.ptr
      cf.br ^bb44
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %456 = arith.constant 6 : i32
    %457 = llvm.mlir.addressof @MOD : !llvm.ptr
    %458 = llvm.load %457 : !llvm.ptr -> i64
    %459 = arith.constant 2 : i32
    %461 = arith.extsi %459 : i32 to i64
    %460 = arith.subi %458, %461 : i64
    %462 = arith.extsi %456 : i32 to i64
    %455 = func.call @mod_pow(%462, %460) : (i64, i64) -> i64
    %463 = llvm.load %427 : !llvm.ptr -> i64
    %464 = arith.muli %416, %463 : i64
    %465 = llvm.mlir.addressof @MOD : !llvm.ptr
    %466 = llvm.load %465 : !llvm.ptr -> i64
    %467 = arith.remsi %464, %466 : i64
    %468 = llvm.mlir.constant(1 : i64) : i64
    %469 = llvm.alloca %468 x i64 : (i64) -> !llvm.ptr
    llvm.store %467, %469 : i64, !llvm.ptr
    %470 = llvm.load %469 : !llvm.ptr -> i64
    %471 = llvm.load %446 : !llvm.ptr -> i64
    %472 = arith.muli %470, %471 : i64
    %473 = llvm.mlir.addressof @MOD : !llvm.ptr
    %474 = llvm.load %473 : !llvm.ptr -> i64
    %475 = arith.remsi %472, %474 : i64
    llvm.store %475, %469 : i64, !llvm.ptr
    %476 = llvm.load %469 : !llvm.ptr -> i64
    %477 = arith.muli %476, %455 : i64
    %478 = llvm.mlir.addressof @MOD : !llvm.ptr
    %479 = llvm.load %478 : !llvm.ptr -> i64
    %480 = arith.remsi %477, %479 : i64
    llvm.store %480, %469 : i64, !llvm.ptr
    %481 = llvm.load %469 : !llvm.ptr -> i64
    func.return %481 : i64
  }
  func.func @recurse(%arg0: i64, %arg1: i32, %arg2: i32) -> i64 {
    %482 = llvm.mlir.addressof @g_K : !llvm.ptr
    %483 = llvm.load %482 : !llvm.ptr -> i32
    %484 = arith.addi %arg1, %arg2 : i32
    %485 = arith.cmpi sge, %484, %483 : i32
    cf.cond_br %485, ^bb45, ^bb46
    ^bb45:
      %486 = arith.extsi %arg0 : i64 to i128
      %488 = llvm.mlir.addressof @g_pow10 : !llvm.ptr
      %489 = llvm.load %488 : !llvm.ptr -> !llvm.ptr
      %490 = arith.extsi %arg2 : i32 to i64
      %491 = llvm.getelementptr %489[%490] : (!llvm.ptr, i64) -> !llvm.ptr, i128
      %487 = llvm.load %491 : !llvm.ptr -> i128
      %493 = arith.trunci %486 : i128 to i64
      %494 = arith.trunci %487 : i128 to i64
      %492 = arith.muli %493, %494 : i64
      %495 = arith.extsi %492 : i64 to i128
      %497 = arith.trunci %495 : i128 to i64
      %498 = arith.trunci %495 : i128 to i64
      %496 = arith.muli %497, %498 : i64
      %499 = arith.extsi %496 : i64 to i128
      %500 = func.call @delta_mod_i128(%499) : (i128) -> i64
      func.return %500 : i64
    ^bb46:
      cf.br ^bb47
    ^bb47:
    %501 = arith.extsi %arg0 : i64 to i128
    %502 = arith.extsi %arg0 : i64 to i128
    %504 = arith.trunci %501 : i128 to i64
    %505 = arith.trunci %502 : i128 to i64
    %503 = arith.muli %504, %505 : i64
    %507 = llvm.mlir.addressof @g_pow10 : !llvm.ptr
    %508 = llvm.load %507 : !llvm.ptr -> !llvm.ptr
    %509 = arith.extsi %arg1 : i32 to i64
    %510 = llvm.getelementptr %508[%509] : (!llvm.ptr, i64) -> !llvm.ptr, i128
    %506 = llvm.load %510 : !llvm.ptr -> i128
    %512 = arith.trunci %506 : i128 to i64
    %511 = arith.remsi %503, %512 : i64
    %514 = llvm.mlir.addressof @g_pow10 : !llvm.ptr
    %515 = llvm.load %514 : !llvm.ptr -> !llvm.ptr
    %516 = arith.constant 1 : i32
    %517 = arith.subi %arg1, %516 : i32
    %518 = arith.extsi %517 : i32 to i64
    %519 = llvm.getelementptr %515[%518] : (!llvm.ptr, i64) -> !llvm.ptr, i128
    %513 = llvm.load %519 : !llvm.ptr -> i128
    %520 = arith.trunci %513 : i128 to i64
    %521 = arith.divsi %511, %520 : i64
    %523 = llvm.mlir.addressof @g_pow10 : !llvm.ptr
    %524 = llvm.load %523 : !llvm.ptr -> !llvm.ptr
    %525 = arith.extsi %arg1 : i32 to i64
    %526 = llvm.getelementptr %524[%525] : (!llvm.ptr, i64) -> !llvm.ptr, i128
    %522 = llvm.load %526 : !llvm.ptr -> i128
    %528 = llvm.mlir.addressof @g_pow10 : !llvm.ptr
    %529 = llvm.load %528 : !llvm.ptr -> !llvm.ptr
    %530 = arith.constant 1 : i32
    %531 = arith.addi %arg1, %530 : i32
    %532 = arith.extsi %531 : i32 to i64
    %533 = llvm.getelementptr %529[%532] : (!llvm.ptr, i64) -> !llvm.ptr, i128
    %527 = llvm.load %533 : !llvm.ptr -> i128
    %534 = arith.subi %483, %arg1 : i32
    %535 = arith.subi %534, %arg2 : i32
    %536 = arith.constant 1 : i32
    %537 = arith.subi %535, %536 : i32
    %539 = llvm.mlir.addressof @g_pow10_mod : !llvm.ptr
    %540 = llvm.load %539 : !llvm.ptr -> !llvm.ptr
    %541 = arith.extsi %537 : i32 to i64
    %542 = llvm.getelementptr %540[%541] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %538 = llvm.load %542 : !llvm.ptr -> i64
    %543 = arith.constant 0 : i32
    %544 = arith.extsi %543 : i32 to i64
    %545 = llvm.mlir.constant(1 : i64) : i64
    %546 = llvm.alloca %545 x i64 : (i64) -> !llvm.ptr
    llvm.store %544, %546 : i64, !llvm.ptr
    %547 = arith.constant 0 : i32
    %548 = arith.constant 10 : i32
    %549 = arith.index_cast %547 : i32 to index
    %550 = arith.index_cast %548 : i32 to index
    %552 = arith.constant 1 : index
    %553 = arith.constant -1 : index
    %554 = arith.cmpi sle, %549, %550 : index
    %551 = arith.select %554, %552, %553 : index
    cf.br ^bb48(%549 : index)
    ^bb48(%555: index):
    %556 = arith.cmpi slt, %555, %550 : index
    %557 = arith.cmpi sgt, %555, %550 : index
    %558 = arith.select %554, %556, %557 : i1
    cf.cond_br %558, ^bb49(%555 : index), ^bb50(%555 : index)
    ^bb49(%559: index):
      %560 = arith.index_cast %559 : index to i128
      %562 = arith.trunci %560 : i128 to i64
      %563 = arith.trunci %522 : i128 to i64
      %561 = arith.muli %562, %563 : i64
      %564 = arith.extsi %arg0 : i64 to i128
      %566 = arith.trunci %564 : i128 to i64
      %565 = arith.addi %561, %566 : i64
      %567 = arith.extsi %565 : i64 to i128
      %569 = arith.trunci %567 : i128 to i64
      %570 = arith.trunci %567 : i128 to i64
      %568 = arith.muli %569, %570 : i64
      %571 = arith.extsi %568 : i64 to i128
      %573 = arith.trunci %571 : i128 to i64
      %574 = arith.trunci %527 : i128 to i64
      %572 = arith.remsi %573, %574 : i64
      %576 = arith.trunci %522 : i128 to i64
      %575 = arith.divsi %572, %576 : i64
      %577 = arith.cmpi sge, %575, %521 : i64
      cf.cond_br %577, ^bb51, ^bb52
      ^bb51:
        %578 = llvm.load %546 : !llvm.ptr -> i64
        %580 = arith.trunci %567 : i128 to i64
        %581 = arith.constant 1 : i32
        %582 = arith.addi %arg1, %581 : i32
        %579 = func.call @recurse(%580, %582, %arg2) : (i64, i32, i32) -> i64
        %583 = arith.addi %578, %579 : i64
        %584 = llvm.mlir.addressof @MOD : !llvm.ptr
        %585 = llvm.load %584 : !llvm.ptr -> i64
        %586 = arith.remsi %583, %585 : i64
        llvm.store %586, %546 : i64, !llvm.ptr
        cf.br ^bb53
      ^bb52:
        %588 = arith.trunci %571 : i128 to i64
        %589 = arith.trunci %527 : i128 to i64
        %587 = arith.remsi %588, %589 : i64
        %590 = arith.extsi %587 : i64 to i128
        %592 = llvm.mlir.addressof @g_pow10 : !llvm.ptr
        %593 = llvm.load %592 : !llvm.ptr -> !llvm.ptr
        %594 = arith.constant 2 : i32
        %595 = arith.muli %594, %arg2 : i32
        %596 = arith.extsi %595 : i32 to i64
        %597 = llvm.getelementptr %593[%596] : (!llvm.ptr, i64) -> !llvm.ptr, i128
        %591 = llvm.load %597 : !llvm.ptr -> i128
        %599 = arith.trunci %590 : i128 to i64
        %600 = arith.trunci %591 : i128 to i64
        %598 = arith.muli %599, %600 : i64
        %601 = arith.extsi %598 : i64 to i128
        %603 = llvm.mlir.addressof @g_pow10 : !llvm.ptr
        %604 = llvm.load %603 : !llvm.ptr -> !llvm.ptr
        %605 = arith.constant 1 : i32
        %606 = arith.addi %arg1, %605 : i32
        %607 = arith.constant 2 : i32
        %608 = arith.muli %607, %arg2 : i32
        %609 = arith.addi %606, %608 : i32
        %610 = arith.extsi %609 : i32 to i64
        %611 = llvm.getelementptr %604[%610] : (!llvm.ptr, i64) -> !llvm.ptr, i128
        %602 = llvm.load %611 : !llvm.ptr -> i128
        %613 = arith.trunci %602 : i128 to i64
        %614 = arith.trunci %601 : i128 to i64
        %612 = arith.addi %613, %614 : i64
        %615 = arith.extsi %612 : i64 to i128
        %616 = func.call @delta_mod_i128(%615) : (i128) -> i64
        %618 = arith.trunci %571 : i128 to i64
        %619 = arith.trunci %527 : i128 to i64
        %617 = arith.cmpi slt, %618, %619 : i64
        cf.cond_br %617, ^bb54, ^bb55
        ^bb54:
          %620 = llvm.load %546 : !llvm.ptr -> i64
          %621 = func.call @delta_mod_i128(%601) : (i128) -> i64
          %622 = arith.addi %620, %621 : i64
          %623 = llvm.mlir.addressof @MOD : !llvm.ptr
          %624 = llvm.load %623 : !llvm.ptr -> i64
          %625 = arith.remsi %622, %624 : i64
          llvm.store %625, %546 : i64, !llvm.ptr
          %626 = arith.constant 1 : i32
          %628 = arith.extsi %626 : i32 to i64
          %627 = arith.subi %538, %628 : i64
          %629 = llvm.mlir.addressof @MOD : !llvm.ptr
          %630 = llvm.load %629 : !llvm.ptr -> i64
          %631 = arith.remsi %627, %630 : i64
          %632 = llvm.mlir.constant(1 : i64) : i64
          %633 = llvm.alloca %632 x i64 : (i64) -> !llvm.ptr
          llvm.store %631, %633 : i64, !llvm.ptr
          %634 = llvm.load %633 : !llvm.ptr -> i64
          %635 = arith.constant 0 : i32
          %637 = arith.extsi %635 : i32 to i64
          %636 = arith.cmpi slt, %634, %637 : i64
          cf.cond_br %636, ^bb57, ^bb58
          ^bb57:
            %638 = llvm.load %633 : !llvm.ptr -> i64
            %639 = llvm.mlir.addressof @MOD : !llvm.ptr
            %640 = llvm.load %639 : !llvm.ptr -> i64
            %641 = arith.addi %638, %640 : i64
            llvm.store %641, %633 : i64, !llvm.ptr
            cf.br ^bb59
          ^bb58:
            cf.br ^bb59
          ^bb59:
          %642 = llvm.load %633 : !llvm.ptr -> i64
          %643 = arith.muli %642, %616 : i64
          %644 = llvm.mlir.addressof @MOD : !llvm.ptr
          %645 = llvm.load %644 : !llvm.ptr -> i64
          %646 = arith.remsi %643, %645 : i64
          llvm.store %646, %633 : i64, !llvm.ptr
          %647 = llvm.load %546 : !llvm.ptr -> i64
          %648 = llvm.load %633 : !llvm.ptr -> i64
          %649 = arith.addi %647, %648 : i64
          %650 = llvm.mlir.addressof @MOD : !llvm.ptr
          %651 = llvm.load %650 : !llvm.ptr -> i64
          %652 = arith.remsi %649, %651 : i64
          llvm.store %652, %546 : i64, !llvm.ptr
          cf.br ^bb56
        ^bb55:
          %653 = arith.muli %538, %616 : i64
          %654 = llvm.mlir.addressof @MOD : !llvm.ptr
          %655 = llvm.load %654 : !llvm.ptr -> i64
          %656 = arith.remsi %653, %655 : i64
          %657 = llvm.load %546 : !llvm.ptr -> i64
          %658 = arith.addi %657, %656 : i64
          %659 = llvm.mlir.addressof @MOD : !llvm.ptr
          %660 = llvm.load %659 : !llvm.ptr -> i64
          %661 = arith.remsi %658, %660 : i64
          llvm.store %661, %546 : i64, !llvm.ptr
          cf.br ^bb56
        ^bb56:
        cf.br ^bb53
      ^bb53:
      %662 = arith.addi %559, %551 : index
      cf.br ^bb48(%662 : index)
    ^bb50(%663: index):
    %664 = llvm.load %546 : !llvm.ptr -> i64
    func.return %664 : i64
  }
  func.func @correction_sum(%arg0: i32) -> i64 {
    %665 = llvm.mlir.addressof @g_K : !llvm.ptr
    llvm.store %arg0, %665 : i32, !llvm.ptr
    %666 = arith.constant 1 : i32
    %667 = llvm.mlir.addressof @g_pow10 : !llvm.ptr
    %668 = llvm.load %667 : !llvm.ptr -> !llvm.ptr
    %669 = arith.constant 0 : i32
    %670 = arith.extsi %666 : i32 to i128
    %671 = arith.extsi %669 : i32 to i64
    %672 = llvm.getelementptr %668[%671] : (!llvm.ptr, i64) -> !llvm.ptr, i128
    llvm.store %670, %672 : i128, !llvm.ptr
    %673 = arith.constant 1 : i32
    %674 = arith.constant 2 : i32
    %675 = arith.muli %674, %arg0 : i32
    %676 = arith.constant 3 : i32
    %677 = arith.addi %675, %676 : i32
    %678 = arith.index_cast %673 : i32 to index
    %679 = arith.index_cast %677 : i32 to index
    %681 = arith.constant 1 : index
    %682 = arith.constant -1 : index
    %683 = arith.cmpi sle, %678, %679 : index
    %680 = arith.select %683, %681, %682 : index
    cf.br ^bb60(%678 : index)
    ^bb60(%684: index):
    %685 = arith.cmpi slt, %684, %679 : index
    %686 = arith.cmpi sgt, %684, %679 : index
    %687 = arith.select %683, %685, %686 : i1
    cf.cond_br %687, ^bb61(%684 : index), ^bb62(%684 : index)
    ^bb61(%688: index):
      %690 = llvm.mlir.addressof @g_pow10 : !llvm.ptr
      %691 = llvm.load %690 : !llvm.ptr -> !llvm.ptr
      %692 = arith.constant 1 : i32
      %694 = arith.index_cast %688 : index to i32
      %693 = arith.subi %694, %692 : i32
      %695 = arith.extsi %693 : i32 to i64
      %696 = llvm.getelementptr %691[%695] : (!llvm.ptr, i64) -> !llvm.ptr, i128
      %689 = llvm.load %696 : !llvm.ptr -> i128
      %697 = arith.constant 10 : i32
      %699 = arith.trunci %689 : i128 to i64
      %700 = arith.extsi %697 : i32 to i64
      %698 = arith.muli %699, %700 : i64
      %701 = llvm.mlir.addressof @g_pow10 : !llvm.ptr
      %702 = llvm.load %701 : !llvm.ptr -> !llvm.ptr
      %703 = arith.extsi %698 : i64 to i128
      %704 = arith.index_cast %688 : index to i64
      %705 = llvm.getelementptr %702[%704] : (!llvm.ptr, i64) -> !llvm.ptr, i128
      llvm.store %703, %705 : i128, !llvm.ptr
      %706 = arith.addi %688, %680 : index
      cf.br ^bb60(%706 : index)
    ^bb62(%707: index):
    %708 = arith.constant 1 : i32
    %709 = llvm.mlir.addressof @g_pow10_mod : !llvm.ptr
    %710 = llvm.load %709 : !llvm.ptr -> !llvm.ptr
    %711 = arith.constant 0 : i32
    %712 = arith.extsi %708 : i32 to i64
    %713 = arith.extsi %711 : i32 to i64
    %714 = llvm.getelementptr %710[%713] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %712, %714 : i64, !llvm.ptr
    %715 = arith.constant 1 : i32
    %716 = arith.constant 1 : i32
    %717 = arith.addi %arg0, %716 : i32
    %718 = arith.index_cast %715 : i32 to index
    %719 = arith.index_cast %717 : i32 to index
    %721 = arith.constant 1 : index
    %722 = arith.constant -1 : index
    %723 = arith.cmpi sle, %718, %719 : index
    %720 = arith.select %723, %721, %722 : index
    cf.br ^bb63(%718 : index)
    ^bb63(%724: index):
    %725 = arith.cmpi slt, %724, %719 : index
    %726 = arith.cmpi sgt, %724, %719 : index
    %727 = arith.select %723, %725, %726 : i1
    cf.cond_br %727, ^bb64(%724 : index), ^bb65(%724 : index)
    ^bb64(%728: index):
      %730 = llvm.mlir.addressof @g_pow10_mod : !llvm.ptr
      %731 = llvm.load %730 : !llvm.ptr -> !llvm.ptr
      %732 = arith.constant 1 : i32
      %734 = arith.index_cast %728 : index to i32
      %733 = arith.subi %734, %732 : i32
      %735 = arith.extsi %733 : i32 to i64
      %736 = llvm.getelementptr %731[%735] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %729 = llvm.load %736 : !llvm.ptr -> i64
      %737 = arith.constant 10 : i32
      %739 = arith.extsi %737 : i32 to i64
      %738 = arith.muli %729, %739 : i64
      %740 = llvm.mlir.addressof @MOD : !llvm.ptr
      %741 = llvm.load %740 : !llvm.ptr -> i64
      %742 = arith.remsi %738, %741 : i64
      %743 = llvm.mlir.addressof @g_pow10_mod : !llvm.ptr
      %744 = llvm.load %743 : !llvm.ptr -> !llvm.ptr
      %745 = arith.index_cast %728 : index to i64
      %746 = llvm.getelementptr %744[%745] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %742, %746 : i64, !llvm.ptr
      %747 = arith.addi %728, %720 : index
      cf.br ^bb63(%747 : index)
    ^bb65(%748: index):
    %749 = arith.constant 0 : i32
    %750 = arith.extsi %749 : i32 to i64
    %751 = llvm.mlir.constant(1 : i64) : i64
    %752 = llvm.alloca %751 x i64 : (i64) -> !llvm.ptr
    llvm.store %750, %752 : i64, !llvm.ptr
    %753 = arith.constant 0 : i32
    %754 = arith.index_cast %753 : i32 to index
    %755 = arith.index_cast %arg0 : i32 to index
    %757 = arith.constant 1 : index
    %758 = arith.constant -1 : index
    %759 = arith.cmpi sle, %754, %755 : index
    %756 = arith.select %759, %757, %758 : index
    cf.br ^bb66(%754 : index)
    ^bb66(%760: index):
    %761 = arith.cmpi slt, %760, %755 : index
    %762 = arith.cmpi sgt, %760, %755 : index
    %763 = arith.select %759, %761, %762 : i1
    cf.cond_br %763, ^bb67(%760 : index), ^bb68(%760 : index)
    ^bb67(%764: index):
      %765 = arith.constant 1 : i32
      %766 = arith.constant 10 : i32
      %767 = arith.index_cast %765 : i32 to index
      %768 = arith.index_cast %766 : i32 to index
      %770 = arith.constant 1 : index
      %771 = arith.constant -1 : index
      %772 = arith.cmpi sle, %767, %768 : index
      %769 = arith.select %772, %770, %771 : index
      cf.br ^bb69(%767 : index)
      ^bb69(%773: index):
      %774 = arith.cmpi slt, %773, %768 : index
      %775 = arith.cmpi sgt, %773, %768 : index
      %776 = arith.select %772, %774, %775 : i1
      cf.cond_br %776, ^bb70(%773 : index), ^bb71(%773 : index)
      ^bb70(%777: index):
        %778 = llvm.load %752 : !llvm.ptr -> i64
        %780 = arith.index_cast %777 : index to i64
        %781 = arith.constant 1 : i32
        %782 = arith.index_cast %764 : index to i32
        %779 = func.call @recurse(%780, %781, %782) : (i64, i32, i32) -> i64
        %783 = arith.addi %778, %779 : i64
        %784 = llvm.mlir.addressof @MOD : !llvm.ptr
        %785 = llvm.load %784 : !llvm.ptr -> i64
        %786 = arith.remsi %783, %785 : i64
        llvm.store %786, %752 : i64, !llvm.ptr
        %787 = arith.addi %777, %769 : index
        cf.br ^bb69(%787 : index)
      ^bb71(%788: index):
      %789 = arith.addi %764, %756 : index
      cf.br ^bb66(%789 : index)
    ^bb68(%790: index):
    %791 = llvm.load %752 : !llvm.ptr -> i64
    func.return %791 : i64
  }
  func.func @main() -> i32 {
    %793 = arith.constant 40 : i32
    %794 = arith.constant 16 : i32
    %795 = arith.muli %793, %794 : i32
    %796 = arith.extsi %795 : i32 to i64
    %792 = func.call @malloc(%796) : (i64) -> !llvm.ptr
    %797 = llvm.mlir.addressof @g_pow10 : !llvm.ptr
    llvm.store %792, %797 : !llvm.ptr, !llvm.ptr
    %799 = arith.constant 20 : i32
    %800 = arith.constant 8 : i32
    %801 = arith.muli %799, %800 : i32
    %802 = arith.extsi %801 : i32 to i64
    %798 = func.call @malloc(%802) : (i64) -> !llvm.ptr
    %803 = llvm.mlir.addressof @g_pow10_mod : !llvm.ptr
    llvm.store %798, %803 : !llvm.ptr, !llvm.ptr
    %804 = arith.constant 16 : i32
    %805 = func.call @square_sum_below_power10(%804) : (i32) -> i64
    %806 = func.call @correction_sum(%804) : (i32) -> i64
    %807 = arith.addi %805, %806 : i64
    %808 = llvm.mlir.addressof @MOD : !llvm.ptr
    %809 = llvm.load %808 : !llvm.ptr -> i64
    %810 = arith.remsi %807, %809 : i64
    %811 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %812 = llvm.call @printf(%811, %810) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %813 = arith.constant 0 : i32
    func.return %813 : i32
  }
}