Problem 066

Minimal solution of x² − D y² = 1; find D ≤ 1000 with largest x.

Answer661
Output661
StatusPASS
Native helperno
Runtime0 ms
Peak memory1072 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(sqrt(n))
Space complexityO(n^2)O(1)
ApproachFlow solutionContinued fraction convergents
VerdictSuboptimal

Flow source

# Project Euler 066
# Minimal solution of x² − D y² = 1; find D ≤ 1000 with largest x.

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

function is_square(n: i64) -> bool {
    let mut r: i64 = 1
    while r * r < n { r = r + 1 }
    return r * r == n
}

function max2i(a: i32, b: i32) -> i32 {
    if a > b { return a }
    return b
}

function set_small(d: ptr<i32>, v: i64) -> i32 {
    if v == 0 {
        d[0] = 0
        return 1
    }
    let mut x: i64 = v
    let mut len: i32 = 0
    while x > 0 {
        d[len] = (x % 10) as i32
        x = x / 10
        len = len + 1
    }
    return len
}

function add_big(a: ptr<i32>, alen: i32, b: ptr<i32>, blen: i32, out: ptr<i32>) -> i32 {
    let mut carry: i32 = 0
    let mut i: i32 = 0
    let maxlen: i32 = max2i(alen, blen)
    while i < maxlen || carry > 0 {
        let mut v: i32 = carry
        if i < alen { v = v + a[i] }
        if i < blen { v = v + b[i] }
        out[i] = v % 10
        carry = v / 10
        i = i + 1
    }
    return i
}

function mul_small(a: ptr<i32>, alen: i32, m: i64, out: ptr<i32>) -> i32 {
    let mut carry: i64 = 0
    let mut i: i32 = 0
    while i < alen {
        let v: i64 = (a[i] as i64) * m + carry
        out[i] = (v % 10) as i32
        carry = v / 10
        i = i + 1
    }
    while carry > 0 {
        out[i] = (carry % 10) as i32
        carry = carry / 10
        i = i + 1
    }
    return i
}

function mul_big(a: ptr<i32>, alen: i32, b: ptr<i32>, blen: i32, out: ptr<i32>, outmax: i32) -> i32 {
    let mut i: i32 = 0
    while i < outmax {
        out[i] = 0
        i = i + 1
    }
    i = 0
    while i < alen {
        let mut carry: i64 = 0
        let mut j: i32 = 0
        while j < blen {
            let idx: i32 = i + j
            let v: i64 = (out[idx] as i64) + (a[i] as i64) * (b[j] as i64) + carry
            out[idx] = (v % 10) as i32
            carry = v / 10
            j = j + 1
        }
        let mut idx: i32 = i + blen
        while carry > 0 {
            let v: i64 = (out[idx] as i64) + carry
            out[idx] = (v % 10) as i32
            carry = v / 10
            idx = idx + 1
        }
        i = i + 1
    }
    let mut len: i32 = alen + blen
    while len > 1 && out[len - 1] == 0 {
        len = len - 1
    }
    return len
}

function cmp_big(a: ptr<i32>, alen: i32, b: ptr<i32>, blen: i32) -> i32 {
    if alen != blen {
        if alen > blen { return 1 }
        return -1
    }
    let mut i: i32 = alen - 1
    while i >= 0 {
        if a[i] != b[i] {
            if a[i] > b[i] { return 1 }
            return -1
        }
        i = i - 1
    }
    return 0
}

# returns true if a - b == 1 (a >= b)
function diff_is_one(a: ptr<i32>, alen: i32, b: ptr<i32>, blen: i32) -> bool {
    let mut borrow: i32 = 0
    let mut i: i32 = 0
    let maxlen: i32 = max2i(alen, blen)
    while i < maxlen {
        let mut av: i32 = 0
        let mut bv: i32 = 0
        if i < alen { av = a[i] }
        if i < blen { bv = b[i] }
        let mut v: i32 = av - bv - borrow
        if v < 0 {
            v = v + 10
            borrow = 1
        } else {
            borrow = 0
        }
        if i == 0 {
            if v != 1 { return false }
        } else {
            if v != 0 { return false }
        }
        i = i + 1
    }
    return borrow == 0
}

function main() -> i32 {
    let width: i32 = 80
    let wide: i32 = 160
    let best_x: ptr<i32> = calloc(width as i64, 4)
    let tmp: ptr<i32> = calloc(width as i64, 4)
    let hh: ptr<i32> = calloc(wide as i64, 4)
    let kk: ptr<i32> = calloc(wide as i64, 4)
    let dkk: ptr<i32> = calloc(wide as i64, 4)
    if best_x == null || tmp == null || hh == null || kk == null || dkk == null { return 1 }

    let mut best_len: i32 = 0
    let mut best_d: i64 = 0

    let mut d: i64 = 2
    while d <= 1000 {
        if !is_square(d) {
            let mut r: i64 = 1
            while r * r <= d { r = r + 1 }
            r = r - 1

            let h0: ptr<i32> = calloc(width as i64, 4)
            let h1: ptr<i32> = calloc(width as i64, 4)
            let h2: ptr<i32> = calloc(width as i64, 4)
            let k0: ptr<i32> = calloc(width as i64, 4)
            let k1: ptr<i32> = calloc(width as i64, 4)
            let k2: ptr<i32> = calloc(width as i64, 4)
            if h0 == null || h1 == null || h2 == null || k0 == null || k1 == null || k2 == null {
                return 1
            }

            # h-2=0, h-1=1; k-2=1, k-1=0
            let mut hlen0: i32 = set_small(h0, 0)
            let mut hlen1: i32 = set_small(h1, 1)
            let mut klen0: i32 = set_small(k0, 1)
            let mut klen1: i32 = set_small(k1, 0)

            let mut m: i64 = 0
            let mut dd: i64 = 1
            let mut a: i64 = r
            let mut step: i32 = 0
            while step < 500 {
                let ml: i32 = mul_small(h1, hlen1, a, tmp)
                let hlen2: i32 = add_big(tmp, ml, h0, hlen0, h2)
                let mlk: i32 = mul_small(k1, klen1, a, tmp)
                let klen2: i32 = add_big(tmp, mlk, k0, klen0, k2)

                let hhlen: i32 = mul_big(h2, hlen2, h2, hlen2, hh, wide)
                let kklen: i32 = mul_big(k2, klen2, k2, klen2, kk, wide)
                # dkk = d * kk
                let mut i: i32 = 0
                while i < wide {
                    dkk[i] = 0
                    i = i + 1
                }
                let dkklen: i32 = mul_small(kk, kklen, d, dkk)

                if diff_is_one(hh, hhlen, dkk, dkklen) {
                    if best_len == 0 || cmp_big(h2, hlen2, best_x, best_len) > 0 {
                        memcpy(best_x, h2, (hlen2 as i64) * 4)
                        best_len = hlen2
                        best_d = d
                    }
                    break
                }

                memcpy(h0, h1, (hlen1 as i64) * 4)
                hlen0 = hlen1
                memcpy(h1, h2, (hlen2 as i64) * 4)
                hlen1 = hlen2
                memcpy(k0, k1, (klen1 as i64) * 4)
                klen0 = klen1
                memcpy(k1, k2, (klen2 as i64) * 4)
                klen1 = klen2

                m = dd * a - m
                dd = (d - m * m) / dd
                a = (r + m) / dd
                step = step + 1
            }
            free(h0)
            free(h1)
            free(h2)
            free(k0)
            free(k1)
            free(k2)
        }
        d = d + 1
    }
    printf("%lld\n", best_d)
    free(dkk)
    free(kk)
    free(hh)
    free(tmp)
    free(best_x)
    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; }

bool is_square_i64(int64_t n);
int32_t max2i_i32_i32(int32_t a, int32_t b);
int32_t set_small_ptr_i32_i64(int32_t* d, int64_t v);
int32_t add_big_ptr_i32_i32_ptr_i32_i32_ptr_i32(int32_t* a, int32_t alen, int32_t* b, int32_t blen, int32_t* out);
int32_t mul_small_ptr_i32_i32_i64_ptr_i32(int32_t* a, int32_t alen, int64_t m, int32_t* out);
int32_t mul_big_ptr_i32_i32_ptr_i32_i32_ptr_i32_i32(int32_t* a, int32_t alen, int32_t* b, int32_t blen, int32_t* out, int32_t outmax);
int32_t cmp_big_ptr_i32_i32_ptr_i32_i32(int32_t* a, int32_t alen, int32_t* b, int32_t blen);
bool diff_is_one_ptr_i32_i32_ptr_i32_i32(int32_t* a, int32_t alen, int32_t* b, int32_t blen);
int32_t main(void);




bool is_square_i64(int64_t n) {
    int64_t r = 1;
    while ((r * r) < n) {
        r = (r + 1);
    }
    return (r * r) == n;
}

int32_t max2i_i32_i32(int32_t a, int32_t b) {
    if (a > b) {
        return a;
    }
    return b;
}

int32_t set_small_ptr_i32_i64(int32_t* d, int64_t v) {
    if (v == 0) {
        d[0] = 0;
        return 1;
    }
    int64_t x = v;
    int32_t len = 0;
    while (x > 0) {
        d[len] = ((int32_t)(FLOW_CHECKED_MOD((x), (10))));
        x = FLOW_CHECKED_DIV((x), (10));
        len = (len + 1);
    }
    return len;
}

int32_t add_big_ptr_i32_i32_ptr_i32_i32_ptr_i32(int32_t* a, int32_t alen, int32_t* b, int32_t blen, int32_t* out) {
    int32_t carry = 0;
    int32_t i = 0;
    int32_t maxlen = max2i_i32_i32(alen, blen);
    while ((i < maxlen || carry > 0)) {
        int32_t v = carry;
        if (i < alen) {
            v = (v + a[i]);
        }
        if (i < blen) {
            v = (v + b[i]);
        }
        out[i] = FLOW_CHECKED_MOD((v), (10));
        carry = FLOW_CHECKED_DIV((v), (10));
        i = (i + 1);
    }
    return i;
}

int32_t mul_small_ptr_i32_i32_i64_ptr_i32(int32_t* a, int32_t alen, int64_t m, int32_t* out) {
    int64_t carry = 0;
    int32_t i = 0;
    while (i < alen) {
        int64_t v = ((((int64_t)(a[i])) * m) + carry);
        out[i] = ((int32_t)(FLOW_CHECKED_MOD((v), (10))));
        carry = FLOW_CHECKED_DIV((v), (10));
        i = (i + 1);
    }
    while (carry > 0) {
        out[i] = ((int32_t)(FLOW_CHECKED_MOD((carry), (10))));
        carry = FLOW_CHECKED_DIV((carry), (10));
        i = (i + 1);
    }
    return i;
}

int32_t mul_big_ptr_i32_i32_ptr_i32_i32_ptr_i32_i32(int32_t* a, int32_t alen, int32_t* b, int32_t blen, int32_t* out, int32_t outmax) {
    int32_t i = 0;
    while (i < outmax) {
        out[i] = 0;
        i = (i + 1);
    }
    i = 0;
    while (i < alen) {
        int64_t carry = 0;
        int32_t j = 0;
        while (j < blen) {
            int32_t idx = (i + j);
            int64_t v = ((((int64_t)(out[idx])) + (((int64_t)(a[i])) * ((int64_t)(b[j])))) + carry);
            out[idx] = ((int32_t)(FLOW_CHECKED_MOD((v), (10))));
            carry = FLOW_CHECKED_DIV((v), (10));
            j = (j + 1);
        }
        int32_t idx = (i + blen);
        while (carry > 0) {
            int64_t v = (((int64_t)(out[idx])) + carry);
            out[idx] = ((int32_t)(FLOW_CHECKED_MOD((v), (10))));
            carry = FLOW_CHECKED_DIV((v), (10));
            idx = (idx + 1);
        }
        i = (i + 1);
    }
    int32_t len = (alen + blen);
    while ((len > 1 && out[(len - 1)] == 0)) {
        len = (len - 1);
    }
    return len;
}

int32_t cmp_big_ptr_i32_i32_ptr_i32_i32(int32_t* a, int32_t alen, int32_t* b, int32_t blen) {
    if (alen != blen) {
        if (alen > blen) {
            return 1;
        }
        return (-1);
    }
    int32_t i = (alen - 1);
    while (i >= 0) {
        if (a[i] != b[i]) {
            if (a[i] > b[i]) {
                return 1;
            }
            return (-1);
        }
        i = (i - 1);
    }
    return 0;
}

bool diff_is_one_ptr_i32_i32_ptr_i32_i32(int32_t* a, int32_t alen, int32_t* b, int32_t blen) {
    int32_t borrow = 0;
    int32_t i = 0;
    int32_t maxlen = max2i_i32_i32(alen, blen);
    while (i < maxlen) {
        int32_t av = 0;
        int32_t bv = 0;
        if (i < alen) {
            av = a[i];
        }
        if (i < blen) {
            bv = b[i];
        }
        int32_t v = ((av - bv) - borrow);
        if (v < 0) {
            v = (v + 10);
            borrow = 1;
        } else {
            borrow = 0;
        }
        if (i == 0) {
            if (v != 1) {
                return 0;
            }
        } else {
            if (v != 0) {
                return 0;
            }
        }
        i = (i + 1);
    }
    return borrow == 0;
}

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