Problem 255

Average iterations for rounded square roots of 14-digit integers.

Answer4.4474011180
Output4.4474011180
StatusPASS
Native helperno
Runtime1070 ms
Peak memory1136 KB
Time complexityO(n log n) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n log n)O(n log n)
Space complexityO(1)O(1)
ApproachFlow solutionNewton iteration
VerdictOptimal

Flow source

# Project Euler 255
# Average iterations for rounded square roots of 14-digit integers.

import euler.nt { isqrt }

extern {
    function calloc(n: i64, size: i64) -> ptr<void>
    function free(p: ptr<void>) -> void
}

function pow10(e: i64) -> i64 {
    let mut r: i64 = 1
    for i in 0..e {
        r = r * 10
    }
    return r
}

function floordiv(a: i64, b: i64) -> i64 {
    if b == 0 { return 0 }
    let q: i64 = a / b
    let r: i64 = a % b
    if r != 0 {
        if a < 0 && b > 0 { q = q - 1 }
        elif a > 0 && b < 0 { q = q - 1 }
    }
    return q
}

function x0_for_digits(d: i64) -> i64 {
    if d % 2 == 1 {
        return 2 * pow10((d - 1) / 2)
    }
    return 7 * pow10((d - 2) / 2)
}

function iter_count(n: i64, x0: i64) -> i64 {
    let mut x: i64 = x0
    let mut it: i64 = 0
    while true {
        it = it + 1
        let x1: i64 = floordiv(x + floordiv(n + x - 1, x), 2)
        if x1 == x { return it }
        x = x1
    }
    return 0
}

function print_average(total: i64, count: i64) -> void {
    let scale: i64 = 10000000000
    let mut ip: i64 = total / count
    let mut rem: i64 = total % count
    let mut fp: i64 = 0
    for di in 0..10 {
        rem = rem * 10
        let digit: i64 = floordiv(rem, count)
        fp = fp * 10 + digit
        rem = rem % count
    }
    if 2 * rem >= count {
        fp = fp + 1
        if fp >= scale {
            fp = fp - scale
            ip = ip + 1
        }
    }
    printf("%lld.%010lld\n", ip, fp)
}

function iters_sum_seg(mm: i64, a: i64, b: i64, x: i64, k: i64, total_p: ptr<i64>) -> void {
    let q_lo: i64 = floordiv(mm + a + x - 1, x)
    let q_hi: i64 = floordiv(mm + b + x - 1, x)
    let nk: i64 = k + 1
    let mut q: i64 = q_lo
    while q <= q_hi {
        let mut sa: i64 = (q - 1) * x - mm + 1
        if sa < a { sa = a }
        let mut sb: i64 = q * x - mm
        if sb > b { sb = b }
        if sa <= sb {
            let cnt: i64 = sb - sa + 1
            let x1: i64 = floordiv(x + q, 2)
            if x1 == x {
                total_p[0] = total_p[0] + nk * cnt
            } else {
                iters_sum_seg(mm, sa, sb, x1, nk, total_p)
            }
        }
        q = q + 1
    }
}

function iters_sum_interval(mm: i64, s_lo: i64, s_hi: i64, x0: i64) -> i64 {
    if s_lo > s_hi { return 0 }
    let total_p: ptr<i64> = calloc(1, 8)
    total_p[0] = 0
    iters_sum_seg(mm, s_lo, s_hi, x0, 0, total_p)
    let ans: i64 = total_p[0]
    free(total_p)
    return ans
}

function average_interval(d: i64) -> void {
    let L: i64 = pow10(d - 1)
    let U: i64 = pow10(d) - 1
    let x0: i64 = x0_for_digits(d)

    let mut m_full_start: i64 = isqrt(L)
    while m_full_start * m_full_start - m_full_start + 1 < L {
        m_full_start = m_full_start + 1
    }
    let mut m_full_end: i64 = isqrt(U)
    while m_full_end * m_full_end + m_full_end > U {
        m_full_end = m_full_end - 1
    }

    let mut total: i64 = 0

    let m_low: i64 = m_full_start - 1
    if m_low > 0 {
        let mm: i64 = m_low * m_low
        let end: i64 = mm + m_low
        if end >= L {
            let mut s_lo: i64 = L - mm
            let s_min: i64 = -m_low + 1
            if s_lo < s_min { s_lo = s_min }
            let s_hi: i64 = m_low
            total = total + iters_sum_interval(mm, s_lo, s_hi, x0)
        }
    }

    let m_high: i64 = m_full_end + 1
    let mm_h: i64 = m_high * m_high
    let start: i64 = mm_h - m_high + 1
    if start <= U {
        let s_lo2: i64 = -m_high + 1
        let mut s_hi2: i64 = U - mm_h
        if s_hi2 > m_high { s_hi2 = m_high }
        total = total + iters_sum_interval(mm_h, s_lo2, s_hi2, x0)
    }

    let mut m: i64 = m_full_start
    let mut mm: i64 = m * m
    while m <= m_full_end {
        total = total + iters_sum_interval(mm, -m + 1, m, x0)
        mm = mm + 2 * m + 1
        m = m + 1
    }

    let count: i64 = U - L + 1
    print_average(total, count)
}

function main() -> i32 {
    average_interval(14)
    return 0
}

Generated C

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
    while (flow_temp_head) {
        flow_temp_node* n = flow_temp_head;
        flow_temp_head = n->next;
        free(n);
    }
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
    flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
    if (!node) return NULL;
    node->next = flow_temp_head;
    flow_temp_head = node;
    if (!flow_temp_atexit_set) {
        flow_temp_atexit_set = 1;
        atexit(flow_temp_free_all);
    }
    return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
    size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
    char* r = (char*)flow_temp_alloc(la + lb + 1);
    if (!r) return NULL;
    if (la) memcpy(r, a, la);
    if (lb) memcpy(r + la, b, lb);
    r[la + lb] = '\0';
    return r;
}

#define __flow_in_arr(arr, val) __extension__ ({ \
    int _found = 0; \
    size_t _n = sizeof(arr)/sizeof((arr)[0]); \
    for (size_t _i = 0; _i < _n; _i++) { \
        if ((arr)[_i] == (val)) { _found = 1; break; } \
    } _found; })

/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
    fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
    abort();
#if defined(__GNUC__) || defined(__clang__)
    __builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")

#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif

#include <math.h>

void* _ui_state = NULL;

static inline float i32_to_f32(int32_t v) { return (float)v; }

/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }

int64_t gcd_i64_i64(int64_t a0, int64_t b0);
int64_t lcm_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64(int64_t n);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t n);
int64_t pow10_i64(int64_t e);
int64_t floordiv_i64_i64(int64_t a, int64_t b);
int64_t x0_for_digits_i64(int64_t d);
int64_t iter_count_i64_i64(int64_t n, int64_t x0);
void print_average_i64_i64(int64_t total, int64_t count);
void iters_sum_seg_i64_i64_i64_i64_i64_ptr_i64(int64_t mm, int64_t a, int64_t b, int64_t x, int64_t k, int64_t* total_p);
int64_t iters_sum_interval_i64_i64_i64_i64(int64_t mm, int64_t s_lo, int64_t s_hi, int64_t x0);
void average_interval_i64(int64_t d);
int32_t main(void);

int64_t gcd_i64_i64(int64_t a0, int64_t b0) {
    int64_t a = a0;
    int64_t b = b0;
    while (b != 0) {
        int64_t t = FLOW_CHECKED_MOD((a), (b));
        a = b;
        b = t;
    }
    return a;
}

int64_t lcm_i64_i64(int64_t a, int64_t b) {
    if ((a == 0 || b == 0)) {
        return 0;
    }
    return (FLOW_CHECKED_DIV((a), (gcd_i64_i64(a, b))) * b);
}

int64_t isqrt_i64(int64_t n) {
    if (n < 2) {
        return n;
    }
    int64_t x = n;
    int64_t y = FLOW_CHECKED_DIV(((x + 1)), (2));
    while (y < x) {
        x = y;
        y = FLOW_CHECKED_DIV(((x + FLOW_CHECKED_DIV((n), (x)))), (2));
    }
    return x;
}

int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod) {
    int64_t a = FLOW_CHECKED_MOD((a0), (mod));
    int64_t b = FLOW_CHECKED_MOD((b0), (mod));
    int64_t result = 0;
    while (b > 0) {
        if (FLOW_CHECKED_MOD((b), (2)) == 1) {
            result = FLOW_CHECKED_MOD(((result + a)), (mod));
        }
        a = FLOW_CHECKED_MOD(((a * 2)), (mod));
        b = FLOW_CHECKED_DIV((b), (2));
    }
    return result;
}

int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
    if (mod == 1) {
        return 0;
    }
    int64_t result = 1;
    int64_t b = FLOW_CHECKED_MOD((base), (mod));
    int64_t e = exp;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            result = mulmod_i64_i64_i64(result, b, mod);
        }
        b = mulmod_i64_i64_i64(b, b, mod);
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return result;
}

bool is_prime_i64(int64_t n) {
    if (n < 2) {
        return 0;
    }
    if (n < 4) {
        return 1;
    }
    if ((FLOW_CHECKED_MOD((n), (2)) == 0 || FLOW_CHECKED_MOD((n), (3)) == 0)) {
        return 0;
    }
    int64_t i = 5;
    while ((i * i) <= n) {
        if ((FLOW_CHECKED_MOD((n), (i)) == 0 || FLOW_CHECKED_MOD((n), ((i + 2))) == 0)) {
            return 0;
        }
        i = (i + 6);
    }
    return 1;
}



int64_t pow10_i64(int64_t e) {
    int64_t r = 1;
    int32_t __flow_step_1 = 1;
    for (int32_t i = 0; (0 <= e) ? i < e : i > e; i += (0 <= e) ? 1 : -1) {
        r = (r * 10);
    }
    return r;
}

int64_t floordiv_i64_i64(int64_t a, int64_t b) {
    if (b == 0) {
        return 0;
    }
    int64_t q = FLOW_CHECKED_DIV((a), (b));
    int64_t r = FLOW_CHECKED_MOD((a), (b));
    if (r != 0) {
        if ((a < 0 && b > 0)) {
            q = (q - 1);
        } else if ((a > 0 && b < 0)) {
            q = (q - 1);
        }
    }
    return q;
}

int64_t x0_for_digits_i64(int64_t d) {
    if (FLOW_CHECKED_MOD((d), (2)) == 1) {
        return (2 * pow10_i64(FLOW_CHECKED_DIV(((d - 1)), (2))));
    }
    return (7 * pow10_i64(FLOW_CHECKED_DIV(((d - 2)), (2))));
}

int64_t iter_count_i64_i64(int64_t n, int64_t x0) {
    int64_t x = x0;
    int64_t it = 0;
    while (1) {
        it = (it + 1);
        int64_t x1 = floordiv_i64_i64((x + floordiv_i64_i64(((n + x) - 1), x)), 2);
        if (x1 == x) {
            return it;
        }
        x = x1;
    }
    return 0;
}

void print_average_i64_i64(int64_t total, int64_t count) {
    int64_t scale = 10000000000;
    int64_t ip = FLOW_CHECKED_DIV((total), (count));
    int64_t rem = FLOW_CHECKED_MOD((total), (count));
    int64_t fp = 0;
    int32_t __flow_step_2 = 1;
    for (int32_t di = 0; (0 <= 10) ? di < 10 : di > 10; di += (0 <= 10) ? 1 : -1) {
        rem = (rem * 10);
        int64_t digit = floordiv_i64_i64(rem, count);
        fp = ((fp * 10) + digit);
        rem = FLOW_CHECKED_MOD((rem), (count));
    }
    if ((2 * rem) >= count) {
        fp = (fp + 1);
        if (fp >= scale) {
            fp = (fp - scale);
            ip = (ip + 1);
        }
    }
    printf("%lld.%010lld\n", ip, fp);
}

void iters_sum_seg_i64_i64_i64_i64_i64_ptr_i64(int64_t mm, int64_t a, int64_t b, int64_t x, int64_t k, int64_t* total_p) {
    int64_t q_lo = floordiv_i64_i64((((mm + a) + x) - 1), x);
    int64_t q_hi = floordiv_i64_i64((((mm + b) + x) - 1), x);
    int64_t nk = (k + 1);
    int64_t q = q_lo;
    while (q <= q_hi) {
        int64_t sa = ((((q - 1) * x) - mm) + 1);
        if (sa < a) {
            sa = a;
        }
        int64_t sb = ((q * x) - mm);
        if (sb > b) {
            sb = b;
        }
        if (sa <= sb) {
            int64_t cnt = ((sb - sa) + 1);
            int64_t x1 = floordiv_i64_i64((x + q), 2);
            if (x1 == x) {
                total_p[0] = (total_p[0] + (nk * cnt));
            } else {
                iters_sum_seg_i64_i64_i64_i64_i64_ptr_i64(mm, sa, sb, x1, nk, total_p);
            }
        }
        q = (q + 1);
    }
}

int64_t iters_sum_interval_i64_i64_i64_i64(int64_t mm, int64_t s_lo, int64_t s_hi, int64_t x0) {
    if (s_lo > s_hi) {
        return 0;
    }
    int64_t* total_p = (int64_t*)(calloc(1, 8));
    total_p[0] = 0;
    iters_sum_seg_i64_i64_i64_i64_i64_ptr_i64(mm, s_lo, s_hi, x0, 0, total_p);
    int64_t ans = total_p[0];
    free(total_p);
    return ans;
}

void average_interval_i64(int64_t d) {
    int64_t L = pow10_i64((d - 1));
    int64_t U = (pow10_i64(d) - 1);
    int64_t x0 = x0_for_digits_i64(d);
    int64_t m_full_start = isqrt_i64(L);
    while ((((m_full_start * m_full_start) - m_full_start) + 1) < L) {
        m_full_start = (m_full_start + 1);
    }
    int64_t m_full_end = isqrt_i64(U);
    while (((m_full_end * m_full_end) + m_full_end) > U) {
        m_full_end = (m_full_end - 1);
    }
    int64_t total = 0;
    int64_t m_low = (m_full_start - 1);
    if (m_low > 0) {
        int64_t mm = (m_low * m_low);
        int64_t end = (mm + m_low);
        if (end >= L) {
            int64_t s_lo = (L - mm);
            int64_t s_min = ((-m_low) + 1);
            if (s_lo < s_min) {
                s_lo = s_min;
            }
            int64_t s_hi = m_low;
            total = (total + iters_sum_interval_i64_i64_i64_i64(mm, s_lo, s_hi, x0));
        }
    }
    int64_t m_high = (m_full_end + 1);
    int64_t mm_h = (m_high * m_high);
    int64_t start = ((mm_h - m_high) + 1);
    if (start <= U) {
        int64_t s_lo2 = ((-m_high) + 1);
        int64_t s_hi2 = (U - mm_h);
        if (s_hi2 > m_high) {
            s_hi2 = m_high;
        }
        total = (total + iters_sum_interval_i64_i64_i64_i64(mm_h, s_lo2, s_hi2, x0));
    }
    int64_t m = m_full_start;
    int64_t mm = (m * m);
    while (m <= m_full_end) {
        total = (total + iters_sum_interval_i64_i64_i64_i64(mm, ((-m) + 1), m, x0));
        mm = ((mm + (2 * m)) + 1);
        m = (m + 1);
    }
    int64_t count = ((U - L) + 1);
    print_average_i64_i64(total, count);
}

int32_t main(void) {
    average_interval_i64(14);
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%lld.%010lld\n\00") {addr_space = 0 : i32} : !llvm.array<14 x i8>
  func.func @gcd(%arg0: i64, %arg1: i64) -> i64 {
    %0 = llvm.mlir.constant(1 : i64) : i64
    %1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %1 : i64, !llvm.ptr
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %3 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %4 = llvm.load %3 : !llvm.ptr -> i64
    %5 = arith.constant 0 : i32
    %7 = arith.extsi %5 : i32 to i64
    %6 = arith.cmpi ne, %4, %7 : i64
    cf.cond_br %6, ^bb1, ^bb2
    ^bb1:
      %8 = llvm.load %1 : !llvm.ptr -> i64
      %9 = llvm.load %3 : !llvm.ptr -> i64
      %10 = arith.remsi %8, %9 : i64
      %11 = llvm.load %3 : !llvm.ptr -> i64
      llvm.store %11, %1 : i64, !llvm.ptr
      llvm.store %10, %3 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %12 = llvm.load %1 : !llvm.ptr -> i64
    func.return %12 : i64
  }
  func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
    %13 = arith.constant 0 : i32
    %15 = arith.extsi %13 : i32 to i64
    %14 = arith.cmpi eq, %arg0, %15 : i64
    %16 = scf.if %14 -> (i1) {
      %17 = arith.constant true
      scf.yield %17 : i1
    } else {
      %18 = arith.constant 0 : i32
      %20 = arith.extsi %18 : i32 to i64
      %19 = arith.cmpi eq, %arg1, %20 : i64
      scf.yield %19 : i1
    }
    cf.cond_br %16, ^bb3, ^bb4
    ^bb3:
      %21 = arith.constant 0 : i32
      %22 = arith.extsi %21 : i32 to i64
      func.return %22 : i64
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
    %24 = arith.divsi %arg0, %23 : i64
    %25 = arith.muli %24, %arg1 : i64
    func.return %25 : i64
  }
  func.func @isqrt(%arg0: i64) -> i64 {
    %26 = arith.constant 2 : i32
    %28 = arith.extsi %26 : i32 to i64
    %27 = arith.cmpi slt, %arg0, %28 : i64
    cf.cond_br %27, ^bb6, ^bb7
    ^bb6:
      func.return %arg0 : i64
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %29 = llvm.mlir.constant(1 : i64) : i64
    %30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %30 : i64, !llvm.ptr
    %31 = llvm.load %30 : !llvm.ptr -> i64
    %32 = arith.constant 1 : i32
    %34 = arith.extsi %32 : i32 to i64
    %33 = arith.addi %31, %34 : i64
    %35 = arith.constant 2 : i32
    %37 = arith.extsi %35 : i32 to i64
    %36 = arith.divsi %33, %37 : i64
    %38 = llvm.mlir.constant(1 : i64) : i64
    %39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
    llvm.store %36, %39 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %40 = llvm.load %39 : !llvm.ptr -> i64
    %41 = llvm.load %30 : !llvm.ptr -> i64
    %42 = arith.cmpi slt, %40, %41 : i64
    cf.cond_br %42, ^bb10, ^bb11
    ^bb10:
      %43 = llvm.load %39 : !llvm.ptr -> i64
      llvm.store %43, %30 : i64, !llvm.ptr
      %44 = llvm.load %30 : !llvm.ptr -> i64
      %45 = llvm.load %30 : !llvm.ptr -> i64
      %46 = arith.divsi %arg0, %45 : i64
      %47 = arith.addi %44, %46 : i64
      %48 = arith.constant 2 : i32
      %50 = arith.extsi %48 : i32 to i64
      %49 = arith.divsi %47, %50 : i64
      llvm.store %49, %39 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %51 = llvm.load %30 : !llvm.ptr -> i64
    func.return %51 : i64
  }
  func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %52 = arith.remsi %arg0, %arg2 : i64
    %53 = llvm.mlir.constant(1 : i64) : i64
    %54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
    llvm.store %52, %54 : i64, !llvm.ptr
    %55 = arith.remsi %arg1, %arg2 : i64
    %56 = llvm.mlir.constant(1 : i64) : i64
    %57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
    llvm.store %55, %57 : i64, !llvm.ptr
    %58 = arith.constant 0 : i32
    %59 = arith.extsi %58 : i32 to i64
    %60 = llvm.mlir.constant(1 : i64) : i64
    %61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
    llvm.store %59, %61 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %62 = llvm.load %57 : !llvm.ptr -> i64
    %63 = arith.constant 0 : i32
    %65 = arith.extsi %63 : i32 to i64
    %64 = arith.cmpi sgt, %62, %65 : i64
    cf.cond_br %64, ^bb13, ^bb14
    ^bb13:
      %66 = llvm.load %57 : !llvm.ptr -> i64
      %67 = arith.constant 2 : i32
      %69 = arith.extsi %67 : i32 to i64
      %68 = arith.remsi %66, %69 : i64
      %70 = arith.constant 1 : i32
      %72 = arith.extsi %70 : i32 to i64
      %71 = arith.cmpi eq, %68, %72 : i64
      cf.cond_br %71, ^bb15, ^bb16
      ^bb15:
        %73 = llvm.load %61 : !llvm.ptr -> i64
        %74 = llvm.load %54 : !llvm.ptr -> i64
        %75 = arith.addi %73, %74 : i64
        %76 = arith.remsi %75, %arg2 : i64
        llvm.store %76, %61 : i64, !llvm.ptr
        cf.br ^bb17
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %77 = llvm.load %54 : !llvm.ptr -> i64
      %78 = arith.constant 2 : i32
      %80 = arith.extsi %78 : i32 to i64
      %79 = arith.muli %77, %80 : i64
      %81 = arith.remsi %79, %arg2 : i64
      llvm.store %81, %54 : i64, !llvm.ptr
      %82 = llvm.load %57 : !llvm.ptr -> i64
      %83 = arith.constant 2 : i32
      %85 = arith.extsi %83 : i32 to i64
      %84 = arith.divsi %82, %85 : i64
      llvm.store %84, %57 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %86 = llvm.load %61 : !llvm.ptr -> i64
    func.return %86 : i64
  }
  func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %87 = arith.constant 1 : i32
    %89 = arith.extsi %87 : i32 to i64
    %88 = arith.cmpi eq, %arg2, %89 : i64
    cf.cond_br %88, ^bb18, ^bb19
    ^bb18:
      %90 = arith.constant 0 : i32
      %91 = arith.extsi %90 : i32 to i64
      func.return %91 : i64
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %92 = arith.constant 1 : i32
    %93 = arith.extsi %92 : i32 to i64
    %94 = llvm.mlir.constant(1 : i64) : i64
    %95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
    llvm.store %93, %95 : i64, !llvm.ptr
    %96 = arith.remsi %arg0, %arg2 : i64
    %97 = llvm.mlir.constant(1 : i64) : i64
    %98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
    llvm.store %96, %98 : i64, !llvm.ptr
    %99 = llvm.mlir.constant(1 : i64) : i64
    %100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %100 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %101 = llvm.load %100 : !llvm.ptr -> i64
    %102 = arith.constant 0 : i32
    %104 = arith.extsi %102 : i32 to i64
    %103 = arith.cmpi sgt, %101, %104 : i64
    cf.cond_br %103, ^bb22, ^bb23
    ^bb22:
      %105 = llvm.load %100 : !llvm.ptr -> i64
      %106 = arith.constant 2 : i32
      %108 = arith.extsi %106 : i32 to i64
      %107 = arith.remsi %105, %108 : i64
      %109 = arith.constant 1 : i32
      %111 = arith.extsi %109 : i32 to i64
      %110 = arith.cmpi eq, %107, %111 : i64
      cf.cond_br %110, ^bb24, ^bb25
      ^bb24:
        %113 = llvm.load %95 : !llvm.ptr -> i64
        %114 = llvm.load %98 : !llvm.ptr -> i64
        %112 = func.call @mulmod(%113, %114, %arg2) : (i64, i64, i64) -> i64
        llvm.store %112, %95 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %116 = llvm.load %98 : !llvm.ptr -> i64
      %117 = llvm.load %98 : !llvm.ptr -> i64
      %115 = func.call @mulmod(%116, %117, %arg2) : (i64, i64, i64) -> i64
      llvm.store %115, %98 : i64, !llvm.ptr
      %118 = llvm.load %100 : !llvm.ptr -> i64
      %119 = arith.constant 2 : i32
      %121 = arith.extsi %119 : i32 to i64
      %120 = arith.divsi %118, %121 : i64
      llvm.store %120, %100 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %122 = llvm.load %95 : !llvm.ptr -> i64
    func.return %122 : i64
  }
  func.func @is_prime(%arg0: i64) -> i1 {
    %123 = arith.constant 2 : i32
    %125 = arith.extsi %123 : i32 to i64
    %124 = arith.cmpi slt, %arg0, %125 : i64
    cf.cond_br %124, ^bb27, ^bb28
    ^bb27:
      %126 = arith.constant 0 : i1
      func.return %126 : i1
    ^bb28:
      cf.br ^bb29
    ^bb29:
    %127 = arith.constant 4 : i32
    %129 = arith.extsi %127 : i32 to i64
    %128 = arith.cmpi slt, %arg0, %129 : i64
    cf.cond_br %128, ^bb30, ^bb31
    ^bb30:
      %130 = arith.constant 1 : i1
      func.return %130 : i1
    ^bb31:
      cf.br ^bb32
    ^bb32:
    %131 = arith.constant 2 : i32
    %133 = arith.extsi %131 : i32 to i64
    %132 = arith.remsi %arg0, %133 : i64
    %134 = arith.constant 0 : i32
    %136 = arith.extsi %134 : i32 to i64
    %135 = arith.cmpi eq, %132, %136 : i64
    %137 = scf.if %135 -> (i1) {
      %138 = arith.constant true
      scf.yield %138 : i1
    } else {
      %139 = arith.constant 3 : i32
      %141 = arith.extsi %139 : i32 to i64
      %140 = arith.remsi %arg0, %141 : i64
      %142 = arith.constant 0 : i32
      %144 = arith.extsi %142 : i32 to i64
      %143 = arith.cmpi eq, %140, %144 : i64
      scf.yield %143 : i1
    }
    cf.cond_br %137, ^bb33, ^bb34
    ^bb33:
      %145 = arith.constant 0 : i1
      func.return %145 : i1
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %146 = arith.constant 5 : i32
    %147 = arith.extsi %146 : i32 to i64
    %148 = llvm.mlir.constant(1 : i64) : i64
    %149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
    llvm.store %147, %149 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %150 = llvm.load %149 : !llvm.ptr -> i64
    %151 = llvm.load %149 : !llvm.ptr -> i64
    %152 = arith.muli %150, %151 : i64
    %153 = arith.cmpi sle, %152, %arg0 : i64
    cf.cond_br %153, ^bb37, ^bb38
    ^bb37:
      %154 = llvm.load %149 : !llvm.ptr -> i64
      %155 = arith.remsi %arg0, %154 : i64
      %156 = arith.constant 0 : i32
      %158 = arith.extsi %156 : i32 to i64
      %157 = arith.cmpi eq, %155, %158 : i64
      %159 = scf.if %157 -> (i1) {
        %160 = arith.constant true
        scf.yield %160 : i1
      } else {
        %161 = llvm.load %149 : !llvm.ptr -> i64
        %162 = arith.constant 2 : i32
        %164 = arith.extsi %162 : i32 to i64
        %163 = arith.addi %161, %164 : i64
        %165 = arith.remsi %arg0, %163 : i64
        %166 = arith.constant 0 : i32
        %168 = arith.extsi %166 : i32 to i64
        %167 = arith.cmpi eq, %165, %168 : i64
        scf.yield %167 : i1
      }
      cf.cond_br %159, ^bb39, ^bb40
      ^bb39:
        %169 = arith.constant 0 : i1
        func.return %169 : i1
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %170 = llvm.load %149 : !llvm.ptr -> i64
      %171 = arith.constant 6 : i32
      %173 = arith.extsi %171 : i32 to i64
      %172 = arith.addi %170, %173 : i64
      llvm.store %172, %149 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %174 = arith.constant 1 : i1
    func.return %174 : i1
  }
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func @pow10(%arg0: i64) -> i64 {
    %175 = arith.constant 1 : i32
    %176 = arith.extsi %175 : i32 to i64
    %177 = llvm.mlir.constant(1 : i64) : i64
    %178 = llvm.alloca %177 x i64 : (i64) -> !llvm.ptr
    llvm.store %176, %178 : i64, !llvm.ptr
    %179 = arith.constant 0 : i32
    %180 = arith.index_cast %179 : i32 to index
    %181 = arith.index_cast %arg0 : i32 to index
    %183 = arith.constant 1 : index
    %184 = arith.constant -1 : index
    %185 = arith.cmpi sle, %180, %181 : index
    %182 = arith.select %185, %183, %184 : index
    cf.br ^bb42(%180 : index)
    ^bb42(%186: index):
    %187 = arith.cmpi slt, %186, %181 : index
    %188 = arith.cmpi sgt, %186, %181 : index
    %189 = arith.select %185, %187, %188 : i1
    cf.cond_br %189, ^bb43(%186 : index), ^bb44(%186 : index)
    ^bb43(%190: index):
      %191 = llvm.load %178 : !llvm.ptr -> i64
      %192 = arith.constant 10 : i32
      %194 = arith.extsi %192 : i32 to i64
      %193 = arith.muli %191, %194 : i64
      llvm.store %193, %178 : i64, !llvm.ptr
      %195 = arith.addi %190, %182 : index
      cf.br ^bb42(%195 : index)
    ^bb44(%196: index):
    %197 = llvm.load %178 : !llvm.ptr -> i64
    func.return %197 : i64
  }
  func.func @floordiv(%arg0: i64, %arg1: i64) -> i64 {
    %198 = arith.constant 0 : i32
    %200 = arith.extsi %198 : i32 to i64
    %199 = arith.cmpi eq, %arg1, %200 : i64
    cf.cond_br %199, ^bb45, ^bb46
    ^bb45:
      %201 = arith.constant 0 : i32
      %202 = arith.extsi %201 : i32 to i64
      func.return %202 : i64
    ^bb46:
      cf.br ^bb47
    ^bb47:
    %203 = arith.divsi %arg0, %arg1 : i64
    %204 = arith.remsi %arg0, %arg1 : i64
    %205 = arith.constant 0 : i32
    %207 = arith.extsi %205 : i32 to i64
    %206 = arith.cmpi ne, %204, %207 : i64
    cf.cond_br %206, ^bb48, ^bb49
    ^bb48:
      %208 = arith.constant 0 : i32
      %210 = arith.extsi %208 : i32 to i64
      %209 = arith.cmpi slt, %arg0, %210 : i64
      %211 = scf.if %209 -> (i1) {
        %212 = arith.constant 0 : i32
        %214 = arith.extsi %212 : i32 to i64
        %213 = arith.cmpi sgt, %arg1, %214 : i64
        scf.yield %213 : i1
      } else {
        %215 = arith.constant false
        scf.yield %215 : i1
      }
      cf.cond_br %211, ^bb51, ^bb52
      ^bb51:
        %216 = arith.constant 1 : i32
        %218 = arith.extsi %216 : i32 to i64
        %217 = arith.subi %203, %218 : i64
        cf.br ^bb53(%217 : i64)
      ^bb52:
        %219 = arith.constant 0 : i32
        %221 = arith.extsi %219 : i32 to i64
        %220 = arith.cmpi sgt, %arg0, %221 : i64
        %222 = scf.if %220 -> (i1) {
          %223 = arith.constant 0 : i32
          %225 = arith.extsi %223 : i32 to i64
          %224 = arith.cmpi slt, %arg1, %225 : i64
          scf.yield %224 : i1
        } else {
          %226 = arith.constant false
          scf.yield %226 : i1
        }
        cf.cond_br %222, ^bb54, ^bb53(%203 : i64)
      ^bb54:
        %227 = arith.constant 1 : i32
        %229 = arith.extsi %227 : i32 to i64
        %228 = arith.subi %203, %229 : i64
        cf.br ^bb53(%228 : i64)
      ^bb53(%230: i64):
      cf.br ^bb50(%230 : i64)
    ^bb49:
      cf.br ^bb50(%203 : i64)
    ^bb50(%231: i64):
    func.return %231 : i64
  }
  func.func @x0_for_digits(%arg0: i64) -> i64 {
    %232 = arith.constant 2 : i32
    %234 = arith.extsi %232 : i32 to i64
    %233 = arith.remsi %arg0, %234 : i64
    %235 = arith.constant 1 : i32
    %237 = arith.extsi %235 : i32 to i64
    %236 = arith.cmpi eq, %233, %237 : i64
    cf.cond_br %236, ^bb55, ^bb56
    ^bb55:
      %238 = arith.constant 2 : i32
      %240 = arith.constant 1 : i32
      %242 = arith.extsi %240 : i32 to i64
      %241 = arith.subi %arg0, %242 : i64
      %243 = arith.constant 2 : i32
      %245 = arith.extsi %243 : i32 to i64
      %244 = arith.divsi %241, %245 : i64
      %239 = func.call @pow10(%244) : (i64) -> i64
      %247 = arith.extsi %238 : i32 to i64
      %246 = arith.muli %247, %239 : i64
      func.return %246 : i64
    ^bb56:
      cf.br ^bb57
    ^bb57:
    %248 = arith.constant 7 : i32
    %250 = arith.constant 2 : i32
    %252 = arith.extsi %250 : i32 to i64
    %251 = arith.subi %arg0, %252 : i64
    %253 = arith.constant 2 : i32
    %255 = arith.extsi %253 : i32 to i64
    %254 = arith.divsi %251, %255 : i64
    %249 = func.call @pow10(%254) : (i64) -> i64
    %257 = arith.extsi %248 : i32 to i64
    %256 = arith.muli %257, %249 : i64
    func.return %256 : i64
  }
  func.func @iter_count(%arg0: i64, %arg1: i64) -> i64 {
    %258 = llvm.mlir.constant(1 : i64) : i64
    %259 = llvm.alloca %258 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %259 : i64, !llvm.ptr
    %260 = arith.constant 0 : 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 ^bb58
    ^bb58:
    %264 = arith.constant 1 : i1
    cf.cond_br %264, ^bb59, ^bb60
    ^bb59:
      %265 = llvm.load %263 : !llvm.ptr -> i64
      %266 = arith.constant 1 : i32
      %268 = arith.extsi %266 : i32 to i64
      %267 = arith.addi %265, %268 : i64
      llvm.store %267, %263 : i64, !llvm.ptr
      %270 = llvm.load %259 : !llvm.ptr -> i64
      %272 = llvm.load %259 : !llvm.ptr -> i64
      %273 = arith.addi %arg0, %272 : i64
      %274 = arith.constant 1 : i32
      %276 = arith.extsi %274 : i32 to i64
      %275 = arith.subi %273, %276 : i64
      %277 = llvm.load %259 : !llvm.ptr -> i64
      %271 = func.call @floordiv(%275, %277) : (i64, i64) -> i64
      %278 = arith.addi %270, %271 : i64
      %279 = arith.constant 2 : i32
      %280 = arith.extsi %279 : i32 to i64
      %269 = func.call @floordiv(%278, %280) : (i64, i64) -> i64
      %281 = llvm.load %259 : !llvm.ptr -> i64
      %282 = arith.cmpi eq, %269, %281 : i64
      cf.cond_br %282, ^bb61, ^bb62
      ^bb61:
        %283 = llvm.load %263 : !llvm.ptr -> i64
        func.return %283 : i64
      ^bb62:
        cf.br ^bb63
      ^bb63:
      llvm.store %269, %259 : i64, !llvm.ptr
      cf.br ^bb58
    ^bb60:
    %284 = arith.constant 0 : i32
    %285 = arith.extsi %284 : i32 to i64
    func.return %285 : i64
  }
  func.func @print_average(%arg0: i64, %arg1: i64) -> () {
    %286 = arith.constant 5705032704 : i32
    %287 = arith.extsi %286 : i32 to i64
    %288 = arith.divsi %arg0, %arg1 : i64
    %289 = llvm.mlir.constant(1 : i64) : i64
    %290 = llvm.alloca %289 x i64 : (i64) -> !llvm.ptr
    llvm.store %288, %290 : i64, !llvm.ptr
    %291 = arith.remsi %arg0, %arg1 : i64
    %292 = llvm.mlir.constant(1 : i64) : i64
    %293 = llvm.alloca %292 x i64 : (i64) -> !llvm.ptr
    llvm.store %291, %293 : i64, !llvm.ptr
    %294 = arith.constant 0 : i32
    %295 = arith.extsi %294 : i32 to i64
    %296 = llvm.mlir.constant(1 : i64) : i64
    %297 = llvm.alloca %296 x i64 : (i64) -> !llvm.ptr
    llvm.store %295, %297 : i64, !llvm.ptr
    %298 = arith.constant 0 : i32
    %299 = arith.constant 10 : i32
    %300 = arith.index_cast %298 : i32 to index
    %301 = arith.index_cast %299 : i32 to index
    %303 = arith.constant 1 : index
    %304 = arith.constant -1 : index
    %305 = arith.cmpi sle, %300, %301 : index
    %302 = arith.select %305, %303, %304 : index
    cf.br ^bb64(%300 : index)
    ^bb64(%306: index):
    %307 = arith.cmpi slt, %306, %301 : index
    %308 = arith.cmpi sgt, %306, %301 : index
    %309 = arith.select %305, %307, %308 : i1
    cf.cond_br %309, ^bb65(%306 : index), ^bb66(%306 : index)
    ^bb65(%310: index):
      %311 = llvm.load %293 : !llvm.ptr -> i64
      %312 = arith.constant 10 : i32
      %314 = arith.extsi %312 : i32 to i64
      %313 = arith.muli %311, %314 : i64
      llvm.store %313, %293 : i64, !llvm.ptr
      %316 = llvm.load %293 : !llvm.ptr -> i64
      %315 = func.call @floordiv(%316, %arg1) : (i64, i64) -> i64
      %317 = llvm.load %297 : !llvm.ptr -> i64
      %318 = arith.constant 10 : i32
      %320 = arith.extsi %318 : i32 to i64
      %319 = arith.muli %317, %320 : i64
      %321 = arith.addi %319, %315 : i64
      llvm.store %321, %297 : i64, !llvm.ptr
      %322 = llvm.load %293 : !llvm.ptr -> i64
      %323 = arith.remsi %322, %arg1 : i64
      llvm.store %323, %293 : i64, !llvm.ptr
      %324 = arith.addi %310, %302 : index
      cf.br ^bb64(%324 : index)
    ^bb66(%325: index):
    %326 = arith.constant 2 : i32
    %327 = llvm.load %293 : !llvm.ptr -> i64
    %329 = arith.extsi %326 : i32 to i64
    %328 = arith.muli %329, %327 : i64
    %330 = arith.cmpi sge, %328, %arg1 : i64
    cf.cond_br %330, ^bb67, ^bb68
    ^bb67:
      %331 = llvm.load %297 : !llvm.ptr -> i64
      %332 = arith.constant 1 : i32
      %334 = arith.extsi %332 : i32 to i64
      %333 = arith.addi %331, %334 : i64
      llvm.store %333, %297 : i64, !llvm.ptr
      %335 = llvm.load %297 : !llvm.ptr -> i64
      %336 = arith.cmpi sge, %335, %287 : i64
      cf.cond_br %336, ^bb70, ^bb71
      ^bb70:
        %337 = llvm.load %297 : !llvm.ptr -> i64
        %338 = arith.subi %337, %287 : i64
        llvm.store %338, %297 : i64, !llvm.ptr
        %339 = llvm.load %290 : !llvm.ptr -> i64
        %340 = arith.constant 1 : i32
        %342 = arith.extsi %340 : i32 to i64
        %341 = arith.addi %339, %342 : i64
        llvm.store %341, %290 : i64, !llvm.ptr
        cf.br ^bb72
      ^bb71:
        cf.br ^bb72
      ^bb72:
      cf.br ^bb69
    ^bb68:
      cf.br ^bb69
    ^bb69:
    %343 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %344 = llvm.load %290 : !llvm.ptr -> i64
    %345 = llvm.load %297 : !llvm.ptr -> i64
    %346 = llvm.call @printf(%343, %344, %345) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64, i64) -> i32
    func.return
  }
  func.func @iters_sum_seg(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: i64, %arg5: !llvm.ptr) -> () {
    %348 = arith.addi %arg0, %arg1 : i64
    %349 = arith.addi %348, %arg3 : i64
    %350 = arith.constant 1 : i32
    %352 = arith.extsi %350 : i32 to i64
    %351 = arith.subi %349, %352 : i64
    %347 = func.call @floordiv(%351, %arg3) : (i64, i64) -> i64
    %354 = arith.addi %arg0, %arg2 : i64
    %355 = arith.addi %354, %arg3 : i64
    %356 = arith.constant 1 : i32
    %358 = arith.extsi %356 : i32 to i64
    %357 = arith.subi %355, %358 : i64
    %353 = func.call @floordiv(%357, %arg3) : (i64, i64) -> i64
    %359 = arith.constant 1 : i32
    %361 = arith.extsi %359 : i32 to i64
    %360 = arith.addi %arg4, %361 : i64
    %362 = llvm.mlir.constant(1 : i64) : i64
    %363 = llvm.alloca %362 x i64 : (i64) -> !llvm.ptr
    llvm.store %347, %363 : i64, !llvm.ptr
    cf.br ^bb73
    ^bb73:
    %364 = llvm.load %363 : !llvm.ptr -> i64
    %365 = arith.cmpi sle, %364, %353 : i64
    cf.cond_br %365, ^bb74, ^bb75
    ^bb74:
      %366 = llvm.load %363 : !llvm.ptr -> i64
      %367 = arith.constant 1 : i32
      %369 = arith.extsi %367 : i32 to i64
      %368 = arith.subi %366, %369 : i64
      %370 = arith.muli %368, %arg3 : i64
      %371 = arith.subi %370, %arg0 : i64
      %372 = arith.constant 1 : i32
      %374 = arith.extsi %372 : i32 to i64
      %373 = arith.addi %371, %374 : i64
      %375 = llvm.mlir.constant(1 : i64) : i64
      %376 = llvm.alloca %375 x i64 : (i64) -> !llvm.ptr
      llvm.store %373, %376 : i64, !llvm.ptr
      %377 = llvm.load %376 : !llvm.ptr -> i64
      %378 = arith.cmpi slt, %377, %arg1 : i64
      cf.cond_br %378, ^bb76, ^bb77
      ^bb76:
        llvm.store %arg1, %376 : i64, !llvm.ptr
        cf.br ^bb78
      ^bb77:
        cf.br ^bb78
      ^bb78:
      %379 = llvm.load %363 : !llvm.ptr -> i64
      %380 = arith.muli %379, %arg3 : i64
      %381 = arith.subi %380, %arg0 : i64
      %382 = llvm.mlir.constant(1 : i64) : i64
      %383 = llvm.alloca %382 x i64 : (i64) -> !llvm.ptr
      llvm.store %381, %383 : i64, !llvm.ptr
      %384 = llvm.load %383 : !llvm.ptr -> i64
      %385 = arith.cmpi sgt, %384, %arg2 : i64
      cf.cond_br %385, ^bb79, ^bb80
      ^bb79:
        llvm.store %arg2, %383 : i64, !llvm.ptr
        cf.br ^bb81
      ^bb80:
        cf.br ^bb81
      ^bb81:
      %386 = llvm.load %376 : !llvm.ptr -> i64
      %387 = llvm.load %383 : !llvm.ptr -> i64
      %388 = arith.cmpi sle, %386, %387 : i64
      cf.cond_br %388, ^bb82, ^bb83
      ^bb82:
        %389 = llvm.load %383 : !llvm.ptr -> i64
        %390 = llvm.load %376 : !llvm.ptr -> i64
        %391 = arith.subi %389, %390 : i64
        %392 = arith.constant 1 : i32
        %394 = arith.extsi %392 : i32 to i64
        %393 = arith.addi %391, %394 : i64
        %396 = llvm.load %363 : !llvm.ptr -> i64
        %397 = arith.addi %arg3, %396 : i64
        %398 = arith.constant 2 : i32
        %399 = arith.extsi %398 : i32 to i64
        %395 = func.call @floordiv(%397, %399) : (i64, i64) -> i64
        %400 = arith.cmpi eq, %395, %arg3 : i64
        cf.cond_br %400, ^bb85, ^bb86
        ^bb85:
          %402 = arith.constant 0 : i32
          %403 = arith.extsi %402 : i32 to i64
          %404 = llvm.getelementptr %arg5[%403] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %401 = llvm.load %404 : !llvm.ptr -> i64
          %405 = arith.muli %360, %393 : i64
          %406 = arith.addi %401, %405 : i64
          %407 = arith.constant 0 : i32
          %408 = arith.extsi %407 : i32 to i64
          %409 = llvm.getelementptr %arg5[%408] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %406, %409 : i64, !llvm.ptr
          cf.br ^bb87
        ^bb86:
          %411 = llvm.load %376 : !llvm.ptr -> i64
          %412 = llvm.load %383 : !llvm.ptr -> i64
          func.call @iters_sum_seg(%arg0, %411, %412, %395, %360, %arg5) : (i64, i64, i64, i64, i64, !llvm.ptr) -> ()
          cf.br ^bb87
        ^bb87:
        cf.br ^bb84
      ^bb83:
        cf.br ^bb84
      ^bb84:
      %413 = llvm.load %363 : !llvm.ptr -> i64
      %414 = arith.constant 1 : i32
      %416 = arith.extsi %414 : i32 to i64
      %415 = arith.addi %413, %416 : i64
      llvm.store %415, %363 : i64, !llvm.ptr
      cf.br ^bb73
    ^bb75:
    func.return
  }
  func.func @iters_sum_interval(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64) -> i64 {
    %417 = arith.cmpi sgt, %arg1, %arg2 : i64
    cf.cond_br %417, ^bb88, ^bb89
    ^bb88:
      %418 = arith.constant 0 : i32
      %419 = arith.extsi %418 : i32 to i64
      func.return %419 : i64
    ^bb89:
      cf.br ^bb90
    ^bb90:
    %421 = arith.constant 1 : i32
    %422 = arith.constant 8 : i32
    %423 = arith.extsi %421 : i32 to i64
    %424 = arith.extsi %422 : i32 to i64
    %420 = func.call @calloc(%423, %424) : (i64, i64) -> !llvm.ptr
    %425 = arith.constant 0 : i32
    %426 = arith.constant 0 : i32
    %427 = arith.extsi %425 : i32 to i64
    %428 = arith.extsi %426 : i32 to i64
    %429 = llvm.getelementptr %420[%428] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %427, %429 : i64, !llvm.ptr
    %431 = arith.constant 0 : i32
    %432 = arith.extsi %431 : i32 to i64
    func.call @iters_sum_seg(%arg0, %arg1, %arg2, %arg3, %432, %420) : (i64, i64, i64, i64, i64, !llvm.ptr) -> ()
    %434 = arith.constant 0 : i32
    %435 = arith.extsi %434 : i32 to i64
    %436 = llvm.getelementptr %420[%435] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %433 = llvm.load %436 : !llvm.ptr -> i64
    func.call @free(%420) : (!llvm.ptr) -> ()
    func.return %433 : i64
  }
  func.func @average_interval(%arg0: i64) -> () {
    %439 = arith.constant 1 : i32
    %441 = arith.extsi %439 : i32 to i64
    %440 = arith.subi %arg0, %441 : i64
    %438 = func.call @pow10(%440) : (i64) -> i64
    %442 = func.call @pow10(%arg0) : (i64) -> i64
    %443 = arith.constant 1 : i32
    %445 = arith.extsi %443 : i32 to i64
    %444 = arith.subi %442, %445 : i64
    %446 = func.call @x0_for_digits(%arg0) : (i64) -> i64
    %447 = func.call @isqrt(%438) : (i64) -> i64
    %448 = llvm.mlir.constant(1 : i64) : i64
    %449 = llvm.alloca %448 x i64 : (i64) -> !llvm.ptr
    llvm.store %447, %449 : i64, !llvm.ptr
    cf.br ^bb91
    ^bb91:
    %450 = llvm.load %449 : !llvm.ptr -> i64
    %451 = llvm.load %449 : !llvm.ptr -> i64
    %452 = arith.muli %450, %451 : i64
    %453 = llvm.load %449 : !llvm.ptr -> i64
    %454 = arith.subi %452, %453 : i64
    %455 = arith.constant 1 : i32
    %457 = arith.extsi %455 : i32 to i64
    %456 = arith.addi %454, %457 : i64
    %458 = arith.cmpi slt, %456, %438 : i64
    cf.cond_br %458, ^bb92, ^bb93
    ^bb92:
      %459 = llvm.load %449 : !llvm.ptr -> i64
      %460 = arith.constant 1 : i32
      %462 = arith.extsi %460 : i32 to i64
      %461 = arith.addi %459, %462 : i64
      llvm.store %461, %449 : i64, !llvm.ptr
      cf.br ^bb91
    ^bb93:
    %463 = func.call @isqrt(%444) : (i64) -> i64
    %464 = llvm.mlir.constant(1 : i64) : i64
    %465 = llvm.alloca %464 x i64 : (i64) -> !llvm.ptr
    llvm.store %463, %465 : i64, !llvm.ptr
    cf.br ^bb94
    ^bb94:
    %466 = llvm.load %465 : !llvm.ptr -> i64
    %467 = llvm.load %465 : !llvm.ptr -> i64
    %468 = arith.muli %466, %467 : i64
    %469 = llvm.load %465 : !llvm.ptr -> i64
    %470 = arith.addi %468, %469 : i64
    %471 = arith.cmpi sgt, %470, %444 : i64
    cf.cond_br %471, ^bb95, ^bb96
    ^bb95:
      %472 = llvm.load %465 : !llvm.ptr -> i64
      %473 = arith.constant 1 : i32
      %475 = arith.extsi %473 : i32 to i64
      %474 = arith.subi %472, %475 : i64
      llvm.store %474, %465 : i64, !llvm.ptr
      cf.br ^bb94
    ^bb96:
    %476 = arith.constant 0 : i32
    %477 = arith.extsi %476 : i32 to i64
    %478 = llvm.mlir.constant(1 : i64) : i64
    %479 = llvm.alloca %478 x i64 : (i64) -> !llvm.ptr
    llvm.store %477, %479 : i64, !llvm.ptr
    %480 = llvm.load %449 : !llvm.ptr -> i64
    %481 = arith.constant 1 : i32
    %483 = arith.extsi %481 : i32 to i64
    %482 = arith.subi %480, %483 : i64
    %484 = arith.constant 0 : i32
    %486 = arith.extsi %484 : i32 to i64
    %485 = arith.cmpi sgt, %482, %486 : i64
    cf.cond_br %485, ^bb97, ^bb98
    ^bb97:
      %487 = arith.muli %482, %482 : i64
      %488 = arith.addi %487, %482 : i64
      %489 = arith.cmpi sge, %488, %438 : i64
      cf.cond_br %489, ^bb100, ^bb101
      ^bb100:
        %490 = arith.subi %438, %487 : i64
        %491 = llvm.mlir.constant(1 : i64) : i64
        %492 = llvm.alloca %491 x i64 : (i64) -> !llvm.ptr
        llvm.store %490, %492 : i64, !llvm.ptr
        %494 = arith.constant 0 : i64
        %493 = arith.subi %494, %482 : i64
        %495 = arith.constant 1 : i32
        %497 = arith.extsi %495 : i32 to i64
        %496 = arith.addi %493, %497 : i64
        %498 = llvm.load %492 : !llvm.ptr -> i64
        %499 = arith.cmpi slt, %498, %496 : i64
        cf.cond_br %499, ^bb103, ^bb104
        ^bb103:
          llvm.store %496, %492 : i64, !llvm.ptr
          cf.br ^bb105
        ^bb104:
          cf.br ^bb105
        ^bb105:
        %500 = llvm.load %479 : !llvm.ptr -> i64
        %502 = llvm.load %492 : !llvm.ptr -> i64
        %501 = func.call @iters_sum_interval(%487, %502, %482, %446) : (i64, i64, i64, i64) -> i64
        %503 = arith.addi %500, %501 : i64
        llvm.store %503, %479 : i64, !llvm.ptr
        cf.br ^bb102
      ^bb101:
        cf.br ^bb102
      ^bb102:
      cf.br ^bb99
    ^bb98:
      cf.br ^bb99
    ^bb99:
    %504 = llvm.load %465 : !llvm.ptr -> i64
    %505 = arith.constant 1 : i32
    %507 = arith.extsi %505 : i32 to i64
    %506 = arith.addi %504, %507 : i64
    %508 = arith.muli %506, %506 : i64
    %509 = arith.subi %508, %506 : i64
    %510 = arith.constant 1 : i32
    %512 = arith.extsi %510 : i32 to i64
    %511 = arith.addi %509, %512 : i64
    %513 = arith.cmpi sle, %511, %444 : i64
    cf.cond_br %513, ^bb106, ^bb107
    ^bb106:
      %515 = arith.constant 0 : i64
      %514 = arith.subi %515, %506 : i64
      %516 = arith.constant 1 : i32
      %518 = arith.extsi %516 : i32 to i64
      %517 = arith.addi %514, %518 : i64
      %519 = arith.subi %444, %508 : i64
      %520 = llvm.mlir.constant(1 : i64) : i64
      %521 = llvm.alloca %520 x i64 : (i64) -> !llvm.ptr
      llvm.store %519, %521 : i64, !llvm.ptr
      %522 = llvm.load %521 : !llvm.ptr -> i64
      %523 = arith.cmpi sgt, %522, %506 : i64
      cf.cond_br %523, ^bb109, ^bb110
      ^bb109:
        llvm.store %506, %521 : i64, !llvm.ptr
        cf.br ^bb111
      ^bb110:
        cf.br ^bb111
      ^bb111:
      %524 = llvm.load %479 : !llvm.ptr -> i64
      %526 = llvm.load %521 : !llvm.ptr -> i64
      %525 = func.call @iters_sum_interval(%508, %517, %526, %446) : (i64, i64, i64, i64) -> i64
      %527 = arith.addi %524, %525 : i64
      llvm.store %527, %479 : i64, !llvm.ptr
      cf.br ^bb108
    ^bb107:
      cf.br ^bb108
    ^bb108:
    %528 = llvm.load %449 : !llvm.ptr -> i64
    %529 = llvm.mlir.constant(1 : i64) : i64
    %530 = llvm.alloca %529 x i64 : (i64) -> !llvm.ptr
    llvm.store %528, %530 : i64, !llvm.ptr
    %531 = llvm.load %530 : !llvm.ptr -> i64
    %532 = llvm.load %530 : !llvm.ptr -> i64
    %533 = arith.muli %531, %532 : i64
    %534 = llvm.mlir.constant(1 : i64) : i64
    %535 = llvm.alloca %534 x i64 : (i64) -> !llvm.ptr
    llvm.store %533, %535 : i64, !llvm.ptr
    cf.br ^bb112
    ^bb112:
    %536 = llvm.load %530 : !llvm.ptr -> i64
    %537 = llvm.load %465 : !llvm.ptr -> i64
    %538 = arith.cmpi sle, %536, %537 : i64
    cf.cond_br %538, ^bb113, ^bb114
    ^bb113:
      %539 = llvm.load %479 : !llvm.ptr -> i64
      %541 = llvm.load %535 : !llvm.ptr -> i64
      %542 = llvm.load %530 : !llvm.ptr -> i64
      %544 = arith.constant 0 : i64
      %543 = arith.subi %544, %542 : i64
      %545 = arith.constant 1 : i32
      %547 = arith.extsi %545 : i32 to i64
      %546 = arith.addi %543, %547 : i64
      %548 = llvm.load %530 : !llvm.ptr -> i64
      %540 = func.call @iters_sum_interval(%541, %546, %548, %446) : (i64, i64, i64, i64) -> i64
      %549 = arith.addi %539, %540 : i64
      llvm.store %549, %479 : i64, !llvm.ptr
      %550 = llvm.load %535 : !llvm.ptr -> i64
      %551 = arith.constant 2 : i32
      %552 = llvm.load %530 : !llvm.ptr -> i64
      %554 = arith.extsi %551 : i32 to i64
      %553 = arith.muli %554, %552 : i64
      %555 = arith.addi %550, %553 : i64
      %556 = arith.constant 1 : i32
      %558 = arith.extsi %556 : i32 to i64
      %557 = arith.addi %555, %558 : i64
      llvm.store %557, %535 : i64, !llvm.ptr
      %559 = llvm.load %530 : !llvm.ptr -> i64
      %560 = arith.constant 1 : i32
      %562 = arith.extsi %560 : i32 to i64
      %561 = arith.addi %559, %562 : i64
      llvm.store %561, %530 : i64, !llvm.ptr
      cf.br ^bb112
    ^bb114:
    %563 = arith.subi %444, %438 : i64
    %564 = arith.constant 1 : i32
    %566 = arith.extsi %564 : i32 to i64
    %565 = arith.addi %563, %566 : i64
    %568 = llvm.load %479 : !llvm.ptr -> i64
    func.call @print_average(%568, %565) : (i64, i64) -> ()
    func.return
  }
  func.func @main() -> i32 {
    %570 = arith.constant 14 : i32
    %571 = arith.extsi %570 : i32 to i64
    func.call @average_interval(%571) : (i64) -> ()
    %572 = arith.constant 0 : i32
    func.return %572 : i32
  }
}