Problem 583

Heron Envelopes — sum perimeters of valid flap envelopes with P <= 10^7.

Answer1174137929000
Output1174137929000
StatusPASS
Native helperno
Runtime22480 ms
Peak memory198672 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)?
Space complexityO(n^2)?
ApproachFlow solutionNot curated
VerdictUnknown

Flow source

# Project Euler 583
# Heron Envelopes — sum perimeters of valid flap envelopes with P <= 10^7.

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

function gcd(a0: i64, b0: i64) -> i64 {
    let mut a: i64 = a0
    let mut b: i64 = b0
    while b != 0 {
        let t: i64 = a % b
        a = b
        b = t
    }
    return a
}

function isqrt(n: i64) -> i64 {
    if n <= 0 { return 0 }
    let mut x: i64 = n
    let mut y: i64 = (x + 1) / 2
    while y < x {
        x = y
        y = (x + n / x) / 2
    }
    return x
}

function is_square(n: i64) -> i32 {
    if n < 0 { return 0 }
    let r: i64 = isqrt(n)
    if r * r == n { return 1 }
    return 0
}

function S(p: i64) -> i64 {
    let N: i64 = p / 2
    let counts: ptr<i32> = calloc(N + 1, 4)
    if counts == null { return -1 }

    let mmax_leg: i64 = isqrt(2 * N) + 1
    let mut m: i64 = 2
    while m <= mmax_leg {
        let mm: i64 = m * m
        let mut n: i64 = 1
        if (m & 1) != 0 { n = 2 }
        while n < m {
            if gcd(m, n) == 1 {
                let mut a0: i64 = mm - n * n
                let mut b0: i64 = 2 * m * n
                if a0 > b0 {
                    let t: i64 = a0
                    a0 = b0
                    b0 = t
                }
                if b0 <= N {
                    let mut aa: i64 = a0
                    let mut bb: i64 = b0
                    while bb <= N {
                        counts[aa] = counts[aa] + 1
                        counts[bb] = counts[bb] + 1
                        aa = aa + a0
                        bb = bb + b0
                    }
                }
            }
            n = n + 2
        }
        m = m + 1
    }

    let offset: ptr<i64> = calloc(N + 2, 8)
    let mut total_e: i64 = 0
    let mut i: i64 = 0
    while i <= N {
        offset[i] = total_e
        total_e = total_e + (counts[i] as i64)
        i = i + 1
    }
    offset[N + 1] = total_e
    let vals: ptr<i32> = calloc(total_e + 1, 4)
    let cursor: ptr<i64> = calloc(N + 1, 8)
    if vals == null || cursor == null { return -1 }
    i = 0
    while i <= N {
        cursor[i] = offset[i]
        i = i + 1
    }

    m = 2
    while m <= mmax_leg {
        let mm: i64 = m * m
        let mut n: i64 = 1
        if (m & 1) != 0 { n = 2 }
        while n < m {
            if gcd(m, n) == 1 {
                let mut a0: i64 = mm - n * n
                let mut b0: i64 = 2 * m * n
                if a0 > b0 {
                    let t: i64 = a0
                    a0 = b0
                    b0 = t
                }
                if b0 <= N {
                    let mut aa: i64 = a0
                    let mut bb: i64 = b0
                    while bb <= N {
                        vals[cursor[aa]] = bb as i32
                        cursor[aa] = cursor[aa] + 1
                        vals[cursor[bb]] = aa as i32
                        cursor[bb] = cursor[bb] + 1
                        aa = aa + a0
                        bb = bb + b0
                    }
                }
            }
            n = n + 2
        }
        m = m + 1
    }

    let mut ans: i64 = 0
    let mmax_hyp: i64 = isqrt(N) + 1
    m = 2
    while m <= mmax_hyp {
        let mm: i64 = m * m
        let mut n: i64 = 1
        if (m & 1) != 0 { n = 2 }
        while n < m {
            if gcd(m, n) == 1 {
                let mut a0: i64 = mm - n * n
                let mut b0: i64 = 2 * m * n
                let c0: i64 = mm + n * n
                if c0 <= N {
                    if a0 > b0 {
                        let t: i64 = a0
                        a0 = b0
                        b0 = t
                    }
                    let mut a: i64 = a0
                    let mut b: i64 = b0
                    let mut c: i64 = c0
                    while c <= N {
                        let mut pass: i64 = 0
                        while pass < 2 {
                            let mut AA: i64 = a
                            let mut TT: i64 = b
                            if pass == 1 {
                                AA = b
                                TT = a
                            }
                            let start: i64 = offset[AA]
                            let end: i64 = offset[AA + 1]
                            if start != end {
                                let h_max: i64 = N - AA - c
                                if h_max > TT {
                                    let lo: i64 = 2 * TT + 1
                                    let hi: i64 = TT + h_max
                                    let fourA2: i64 = (AA * AA) << 2
                                    let per_base: i64 = 2 * (AA + c)
                                    let mut q: i64 = start
                                    while q < end {
                                        let u: i64 = vals[q] as i64
                                        if u >= lo && u <= hi {
                                            let h: i64 = u - TT
                                            if h > TT && h <= h_max {
                                                if is_square(fourA2 + h * h) != 0 {
                                                    ans = ans + per_base + 2 * h
                                                }
                                            }
                                        }
                                        q = q + 1
                                    }
                                }
                            }
                            pass = pass + 1
                        }
                        a = a + a0
                        b = b + b0
                        c = c + c0
                    }
                }
            }
            n = n + 2
        }
        m = m + 1
    }

    free(counts)
    free(offset)
    free(vals)
    free(cursor)
    return ans
}

function main() -> i32 {
    printf("%lld\n", S(10000000))
    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 isqrt_i64(int64_t n);
int32_t is_square_i64(int64_t n);
int64_t S_i64(int64_t p);
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 isqrt_i64(int64_t n) {
    if (n <= 0) {
        return 0;
    }
    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;
}

int32_t is_square_i64(int64_t n) {
    if (n < 0) {
        return 0;
    }
    int64_t r = isqrt_i64(n);
    if ((r * r) == n) {
        return 1;
    }
    return 0;
}

int64_t S_i64(int64_t p) {
    int64_t N = FLOW_CHECKED_DIV((p), (2));
    int32_t* counts = (int32_t*)(calloc((N + 1), 4));
    if (counts == NULL) {
        return (-1);
    }
    int64_t mmax_leg = (isqrt_i64((2 * N)) + 1);
    int64_t m = 2;
    while (m <= mmax_leg) {
        int64_t mm = (m * m);
        int64_t n = 1;
        if ((m & 1) != 0) {
            n = 2;
        }
        while (n < m) {
            if (gcd_i64_i64(m, n) == 1) {
                int64_t a0 = (mm - (n * n));
                int64_t b0 = ((2 * m) * n);
                if (a0 > b0) {
                    int64_t t = a0;
                    a0 = b0;
                    b0 = t;
                }
                if (b0 <= N) {
                    int64_t aa = a0;
                    int64_t bb = b0;
                    while (bb <= N) {
                        counts[aa] = (counts[aa] + 1);
                        counts[bb] = (counts[bb] + 1);
                        aa = (aa + a0);
                        bb = (bb + b0);
                    }
                }
            }
            n = (n + 2);
        }
        m = (m + 1);
    }
    int64_t* offset = (int64_t*)(calloc((N + 2), 8));
    int64_t total_e = 0;
    int64_t i = 0;
    while (i <= N) {
        offset[i] = total_e;
        total_e = (total_e + ((int64_t)(counts[i])));
        i = (i + 1);
    }
    offset[(N + 1)] = total_e;
    int32_t* vals = (int32_t*)(calloc((total_e + 1), 4));
    int64_t* cursor = (int64_t*)(calloc((N + 1), 8));
    if ((vals == NULL || cursor == NULL)) {
        return (-1);
    }
    i = 0;
    while (i <= N) {
        cursor[i] = offset[i];
        i = (i + 1);
    }
    m = 2;
    while (m <= mmax_leg) {
        int64_t mm = (m * m);
        int64_t n = 1;
        if ((m & 1) != 0) {
            n = 2;
        }
        while (n < m) {
            if (gcd_i64_i64(m, n) == 1) {
                int64_t a0 = (mm - (n * n));
                int64_t b0 = ((2 * m) * n);
                if (a0 > b0) {
                    int64_t t = a0;
                    a0 = b0;
                    b0 = t;
                }
                if (b0 <= N) {
                    int64_t aa = a0;
                    int64_t bb = b0;
                    while (bb <= N) {
                        vals[cursor[aa]] = ((int32_t)(bb));
                        cursor[aa] = (cursor[aa] + 1);
                        vals[cursor[bb]] = ((int32_t)(aa));
                        cursor[bb] = (cursor[bb] + 1);
                        aa = (aa + a0);
                        bb = (bb + b0);
                    }
                }
            }
            n = (n + 2);
        }
        m = (m + 1);
    }
    int64_t ans = 0;
    int64_t mmax_hyp = (isqrt_i64(N) + 1);
    m = 2;
    while (m <= mmax_hyp) {
        int64_t mm = (m * m);
        int64_t n = 1;
        if ((m & 1) != 0) {
            n = 2;
        }
        while (n < m) {
            if (gcd_i64_i64(m, n) == 1) {
                int64_t a0 = (mm - (n * n));
                int64_t b0 = ((2 * m) * n);
                int64_t c0 = (mm + (n * n));
                if (c0 <= N) {
                    if (a0 > b0) {
                        int64_t t = a0;
                        a0 = b0;
                        b0 = t;
                    }
                    int64_t a = a0;
                    int64_t b = b0;
                    int64_t c = c0;
                    while (c <= N) {
                        int64_t pass = 0;
                        while (pass < 2) {
                            int64_t AA = a;
                            int64_t TT = b;
                            if (pass == 1) {
                                AA = b;
                                TT = a;
                            }
                            int64_t start = offset[AA];
                            int64_t end = offset[(AA + 1)];
                            if (start != end) {
                                int64_t h_max = ((N - AA) - c);
                                if (h_max > TT) {
                                    int64_t lo = ((2 * TT) + 1);
                                    int64_t hi = (TT + h_max);
                                    int64_t fourA2 = FLOW_CHECKED_SHL(((AA * AA)), (2));
                                    int64_t per_base = (2 * (AA + c));
                                    int64_t q = start;
                                    while (q < end) {
                                        int64_t u = ((int64_t)(vals[q]));
                                        if ((u >= lo && u <= hi)) {
                                            int64_t h = (u - TT);
                                            if ((h > TT && h <= h_max)) {
                                                if (is_square_i64((fourA2 + (h * h))) != 0) {
                                                    ans = ((ans + per_base) + (2 * h));
                                                }
                                            }
                                        }
                                        q = (q + 1);
                                    }
                                }
                            }
                            pass = (pass + 1);
                        }
                        a = (a + a0);
                        b = (b + b0);
                        c = (c + c0);
                    }
                }
            }
            n = (n + 2);
        }
        m = (m + 1);
    }
    free(counts);
    free(offset);
    free(vals);
    free(cursor);
    return ans;
}

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