Problem 721

High Powers of Irrational Numbers: G(5e6) mod 999999937.

Answer700792959
Output700792959
StatusPASS
Native helperno
Runtime3370 ms
Peak memory1072 KB
Time complexityO(n^2) (estimated)
Space complexityO(1) (estimated)

Performance comparison

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

Flow source

# Project Euler 721
# High Powers of Irrational Numbers: G(5e6) mod 999999937.

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

const MOD: i64 = 999999937

function clz64(n: i64) -> i32 {
    if n == 0 { return 64 }
    let mut count: i32 = 0
    let mut x: i64 = n
    if (x >> 32) == 0 { count = count + 32; x = x << 32 }
    if (x >> 48) == 0 { count = count + 16; x = x << 16 }
    if (x >> 56) == 0 { count = count + 8; x = x << 8 }
    if (x >> 60) == 0 { count = count + 4; x = x << 4 }
    if (x >> 62) == 0 { count = count + 2; x = x << 2 }
    if (x >> 63) == 0 { count = count + 1 }
    return count
}

function bin_exp(x: i64, a: i64, n: i64, out: ptr<i64>) -> void {
    let mut A: i64 = x
    let mut B: i64 = 1
    let msb: i32 = 63 - clz64(n)
    let mut i: i32 = msb - 1
    while i >= 0 {
        let na: i64 = (A * A + a % MOD * (B % MOD) % MOD * (B % MOD)) % MOD
        let nb: i64 = (2 * A % MOD * B) % MOD
        A = na
        B = nb
        if (n >> i) % 2 == 1 {
            na = (x % MOD * A + a % MOD * B) % MOD
            nb = (A + x % MOD * B) % MOD
            A = na
            B = nb
        }
        i = i - 1
    }
    out[0] = A
    out[1] = B
}

function main() -> i32 {
    let n: i64 = 5000000
    let mut total: i64 = 0
    let out: ptr<i64> = calloc(2, 8)
    let mut a: i64 = 1
    while a <= n {
        let mut ca: i64 = sqrt(a as f64) as i64
        while (ca + 1) * (ca + 1) <= a {
            ca = ca + 1
        }
        while ca * ca > a {
            ca = ca - 1
        }
        if ca * ca == a {
            bin_exp(ca, a, a * a, out)
            total = total + 2 * out[0]
        } else {
            bin_exp(ca + 1, a, a * a, out)
            total = total + 2 * out[0] - 1
        }
        total = total % MOD
        a = a + 1
    }
    free(out)
    printf("%lld\n", total)
    return 0
}

Generated C

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

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

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

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

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

#include <math.h>

void* _ui_state = NULL;

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

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

int32_t clz64_i64(int64_t n);
void bin_exp_i64_i64_i64_ptr_i64(int64_t x, int64_t a, int64_t n, int64_t* out);
int32_t main(void);

static const int64_t MOD = 999999937;




int32_t clz64_i64(int64_t n) {
    if (n == 0) {
        return 64;
    }
    int32_t count = 0;
    int64_t x = n;
    if (FLOW_CHECKED_SHR((x), (32)) == 0) {
        count = (count + 32);
        x = FLOW_CHECKED_SHL((x), (32));
    }
    if (FLOW_CHECKED_SHR((x), (48)) == 0) {
        count = (count + 16);
        x = FLOW_CHECKED_SHL((x), (16));
    }
    if (FLOW_CHECKED_SHR((x), (56)) == 0) {
        count = (count + 8);
        x = FLOW_CHECKED_SHL((x), (8));
    }
    if (FLOW_CHECKED_SHR((x), (60)) == 0) {
        count = (count + 4);
        x = FLOW_CHECKED_SHL((x), (4));
    }
    if (FLOW_CHECKED_SHR((x), (62)) == 0) {
        count = (count + 2);
        x = FLOW_CHECKED_SHL((x), (2));
    }
    if (FLOW_CHECKED_SHR((x), (63)) == 0) {
        count = (count + 1);
    }
    return count;
}

void bin_exp_i64_i64_i64_ptr_i64(int64_t x, int64_t a, int64_t n, int64_t* out) {
    int64_t A = x;
    int64_t B = 1;
    int32_t msb = (63 - clz64_i64(n));
    int32_t i = (msb - 1);
    while (i >= 0) {
        int64_t na = FLOW_CHECKED_MOD((((A * A) + (FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((a), (MOD)) * FLOW_CHECKED_MOD((B), (MOD)))), (MOD)) * FLOW_CHECKED_MOD((B), (MOD))))), (MOD));
        int64_t nb = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((2 * A)), (MOD)) * B)), (MOD));
        A = na;
        B = nb;
        if (FLOW_CHECKED_MOD((FLOW_CHECKED_SHR((n), (i))), (2)) == 1) {
            na = FLOW_CHECKED_MOD((((FLOW_CHECKED_MOD((x), (MOD)) * A) + (FLOW_CHECKED_MOD((a), (MOD)) * B))), (MOD));
            nb = FLOW_CHECKED_MOD(((A + (FLOW_CHECKED_MOD((x), (MOD)) * B))), (MOD));
            A = na;
            B = nb;
        }
        i = (i - 1);
    }
    out[0] = A;
    out[1] = B;
}

int32_t main(void) {
    int64_t n = 5000000;
    int64_t total = 0;
    int64_t* out = (int64_t*)(calloc(2, 8));
    int64_t a = 1;
    while (a <= n) {
        int64_t ca = ((int64_t)(sqrt(((double)(a)))));
        while (((ca + 1) * (ca + 1)) <= a) {
            ca = (ca + 1);
        }
        while ((ca * ca) > a) {
            ca = (ca - 1);
        }
        if ((ca * ca) == a) {
            bin_exp_i64_i64_i64_ptr_i64(ca, a, (a * a), out);
            total = (total + (2 * out[0]));
        } else {
            bin_exp_i64_i64_i64_ptr_i64((ca + 1), a, (a * a), out);
            total = ((total + (2 * out[0])) - 1);
        }
        total = FLOW_CHECKED_MOD((total), (MOD));
        a = (a + 1);
    }
    free(out);
    printf("%lld\n", total);
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func private @sqrt(f64) -> f64
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(999999937 : i64) : i64
  func.func @clz64(%arg0: i64) -> i32 {
    %0 = arith.constant 0 : i32
    %2 = arith.extsi %0 : i32 to i64
    %1 = arith.cmpi eq, %arg0, %2 : i64
    cf.cond_br %1, ^bb0, ^bb1
    ^bb0:
      %3 = arith.constant 64 : i32
      func.return %3 : i32
    ^bb1:
      cf.br ^bb2
    ^bb2:
    %4 = arith.constant 0 : i32
    %5 = llvm.mlir.constant(1 : i64) : i64
    %6 = llvm.alloca %5 x i32 : (i64) -> !llvm.ptr
    llvm.store %4, %6 : i32, !llvm.ptr
    %7 = llvm.mlir.constant(1 : i64) : i64
    %8 = llvm.alloca %7 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %8 : i64, !llvm.ptr
    %9 = llvm.load %8 : !llvm.ptr -> i64
    %10 = arith.constant 32 : i32
    %12 = arith.extsi %10 : i32 to i64
    %11 = arith.shrsi %9, %12 : i64
    %13 = arith.constant 0 : i32
    %15 = arith.extsi %13 : i32 to i64
    %14 = arith.cmpi eq, %11, %15 : i64
    cf.cond_br %14, ^bb3, ^bb4
    ^bb3:
      %16 = llvm.load %6 : !llvm.ptr -> i32
      %17 = arith.constant 32 : i32
      %18 = arith.addi %16, %17 : i32
      llvm.store %18, %6 : i32, !llvm.ptr
      %19 = llvm.load %8 : !llvm.ptr -> i64
      %20 = arith.constant 32 : i32
      %22 = arith.extsi %20 : i32 to i64
      %21 = arith.shli %19, %22 : i64
      llvm.store %21, %8 : i64, !llvm.ptr
      cf.br ^bb5
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %23 = llvm.load %8 : !llvm.ptr -> i64
    %24 = arith.constant 48 : i32
    %26 = arith.extsi %24 : i32 to i64
    %25 = arith.shrsi %23, %26 : i64
    %27 = arith.constant 0 : i32
    %29 = arith.extsi %27 : i32 to i64
    %28 = arith.cmpi eq, %25, %29 : i64
    cf.cond_br %28, ^bb6, ^bb7
    ^bb6:
      %30 = llvm.load %6 : !llvm.ptr -> i32
      %31 = arith.constant 16 : i32
      %32 = arith.addi %30, %31 : i32
      llvm.store %32, %6 : i32, !llvm.ptr
      %33 = llvm.load %8 : !llvm.ptr -> i64
      %34 = arith.constant 16 : i32
      %36 = arith.extsi %34 : i32 to i64
      %35 = arith.shli %33, %36 : i64
      llvm.store %35, %8 : i64, !llvm.ptr
      cf.br ^bb8
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %37 = llvm.load %8 : !llvm.ptr -> i64
    %38 = arith.constant 56 : i32
    %40 = arith.extsi %38 : i32 to i64
    %39 = arith.shrsi %37, %40 : i64
    %41 = arith.constant 0 : i32
    %43 = arith.extsi %41 : i32 to i64
    %42 = arith.cmpi eq, %39, %43 : i64
    cf.cond_br %42, ^bb9, ^bb10
    ^bb9:
      %44 = llvm.load %6 : !llvm.ptr -> i32
      %45 = arith.constant 8 : i32
      %46 = arith.addi %44, %45 : i32
      llvm.store %46, %6 : i32, !llvm.ptr
      %47 = llvm.load %8 : !llvm.ptr -> i64
      %48 = arith.constant 8 : i32
      %50 = arith.extsi %48 : i32 to i64
      %49 = arith.shli %47, %50 : i64
      llvm.store %49, %8 : i64, !llvm.ptr
      cf.br ^bb11
    ^bb10:
      cf.br ^bb11
    ^bb11:
    %51 = llvm.load %8 : !llvm.ptr -> i64
    %52 = arith.constant 60 : i32
    %54 = arith.extsi %52 : i32 to i64
    %53 = arith.shrsi %51, %54 : i64
    %55 = arith.constant 0 : i32
    %57 = arith.extsi %55 : i32 to i64
    %56 = arith.cmpi eq, %53, %57 : i64
    cf.cond_br %56, ^bb12, ^bb13
    ^bb12:
      %58 = llvm.load %6 : !llvm.ptr -> i32
      %59 = arith.constant 4 : i32
      %60 = arith.addi %58, %59 : i32
      llvm.store %60, %6 : i32, !llvm.ptr
      %61 = llvm.load %8 : !llvm.ptr -> i64
      %62 = arith.constant 4 : i32
      %64 = arith.extsi %62 : i32 to i64
      %63 = arith.shli %61, %64 : i64
      llvm.store %63, %8 : i64, !llvm.ptr
      cf.br ^bb14
    ^bb13:
      cf.br ^bb14
    ^bb14:
    %65 = llvm.load %8 : !llvm.ptr -> i64
    %66 = arith.constant 62 : i32
    %68 = arith.extsi %66 : i32 to i64
    %67 = arith.shrsi %65, %68 : i64
    %69 = arith.constant 0 : i32
    %71 = arith.extsi %69 : i32 to i64
    %70 = arith.cmpi eq, %67, %71 : i64
    cf.cond_br %70, ^bb15, ^bb16
    ^bb15:
      %72 = llvm.load %6 : !llvm.ptr -> i32
      %73 = arith.constant 2 : i32
      %74 = arith.addi %72, %73 : i32
      llvm.store %74, %6 : i32, !llvm.ptr
      %75 = llvm.load %8 : !llvm.ptr -> i64
      %76 = arith.constant 2 : i32
      %78 = arith.extsi %76 : i32 to i64
      %77 = arith.shli %75, %78 : i64
      llvm.store %77, %8 : i64, !llvm.ptr
      cf.br ^bb17
    ^bb16:
      cf.br ^bb17
    ^bb17:
    %79 = llvm.load %8 : !llvm.ptr -> i64
    %80 = arith.constant 63 : i32
    %82 = arith.extsi %80 : i32 to i64
    %81 = arith.shrsi %79, %82 : i64
    %83 = arith.constant 0 : i32
    %85 = arith.extsi %83 : i32 to i64
    %84 = arith.cmpi eq, %81, %85 : i64
    cf.cond_br %84, ^bb18, ^bb19
    ^bb18:
      %86 = llvm.load %6 : !llvm.ptr -> i32
      %87 = arith.constant 1 : i32
      %88 = arith.addi %86, %87 : i32
      llvm.store %88, %6 : i32, !llvm.ptr
      cf.br ^bb20
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %89 = llvm.load %6 : !llvm.ptr -> i32
    func.return %89 : i32
  }
  func.func @bin_exp(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: !llvm.ptr) -> () {
    %90 = llvm.mlir.constant(1 : i64) : i64
    %91 = llvm.alloca %90 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %91 : i64, !llvm.ptr
    %92 = arith.constant 1 : i32
    %93 = arith.extsi %92 : i32 to i64
    %94 = llvm.mlir.constant(1 : i64) : i64
    %95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
    llvm.store %93, %95 : i64, !llvm.ptr
    %96 = arith.constant 63 : i32
    %97 = func.call @clz64(%arg2) : (i64) -> i32
    %98 = arith.subi %96, %97 : i32
    %99 = arith.constant 1 : i32
    %100 = arith.subi %98, %99 : 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.constant 0 : i32
    %105 = arith.cmpi sge, %103, %104 : i32
    cf.cond_br %105, ^bb22, ^bb23
    ^bb22:
      %106 = llvm.load %91 : !llvm.ptr -> i64
      %107 = llvm.load %91 : !llvm.ptr -> i64
      %108 = arith.muli %106, %107 : i64
      %109 = llvm.mlir.addressof @MOD : !llvm.ptr
      %110 = llvm.load %109 : !llvm.ptr -> i64
      %111 = arith.remsi %arg1, %110 : i64
      %112 = llvm.load %95 : !llvm.ptr -> i64
      %113 = llvm.mlir.addressof @MOD : !llvm.ptr
      %114 = llvm.load %113 : !llvm.ptr -> i64
      %115 = arith.remsi %112, %114 : i64
      %116 = arith.muli %111, %115 : i64
      %117 = llvm.mlir.addressof @MOD : !llvm.ptr
      %118 = llvm.load %117 : !llvm.ptr -> i64
      %119 = arith.remsi %116, %118 : i64
      %120 = llvm.load %95 : !llvm.ptr -> i64
      %121 = llvm.mlir.addressof @MOD : !llvm.ptr
      %122 = llvm.load %121 : !llvm.ptr -> i64
      %123 = arith.remsi %120, %122 : i64
      %124 = arith.muli %119, %123 : i64
      %125 = arith.addi %108, %124 : i64
      %126 = llvm.mlir.addressof @MOD : !llvm.ptr
      %127 = llvm.load %126 : !llvm.ptr -> i64
      %128 = arith.remsi %125, %127 : i64
      %129 = arith.constant 2 : i32
      %130 = llvm.load %91 : !llvm.ptr -> i64
      %132 = arith.extsi %129 : i32 to i64
      %131 = arith.muli %132, %130 : i64
      %133 = llvm.mlir.addressof @MOD : !llvm.ptr
      %134 = llvm.load %133 : !llvm.ptr -> i64
      %135 = arith.remsi %131, %134 : i64
      %136 = llvm.load %95 : !llvm.ptr -> i64
      %137 = arith.muli %135, %136 : i64
      %138 = llvm.mlir.addressof @MOD : !llvm.ptr
      %139 = llvm.load %138 : !llvm.ptr -> i64
      %140 = arith.remsi %137, %139 : i64
      llvm.store %128, %91 : i64, !llvm.ptr
      llvm.store %140, %95 : i64, !llvm.ptr
      %141 = llvm.load %102 : !llvm.ptr -> i32
      %143 = arith.extsi %141 : i32 to i64
      %142 = arith.shrsi %arg2, %143 : i64
      %144 = arith.constant 2 : i32
      %146 = arith.extsi %144 : i32 to i64
      %145 = arith.remsi %142, %146 : i64
      %147 = arith.constant 1 : i32
      %149 = arith.extsi %147 : i32 to i64
      %148 = arith.cmpi eq, %145, %149 : i64
      %150, %151 = scf.if %148 -> (i64, i64) {
        %152 = llvm.mlir.addressof @MOD : !llvm.ptr
        %153 = llvm.load %152 : !llvm.ptr -> i64
        %154 = arith.remsi %arg0, %153 : i64
        %155 = llvm.load %91 : !llvm.ptr -> i64
        %156 = arith.muli %154, %155 : i64
        %157 = llvm.mlir.addressof @MOD : !llvm.ptr
        %158 = llvm.load %157 : !llvm.ptr -> i64
        %159 = arith.remsi %arg1, %158 : i64
        %160 = llvm.load %95 : !llvm.ptr -> i64
        %161 = arith.muli %159, %160 : i64
        %162 = arith.addi %156, %161 : i64
        %163 = llvm.mlir.addressof @MOD : !llvm.ptr
        %164 = llvm.load %163 : !llvm.ptr -> i64
        %165 = arith.remsi %162, %164 : i64
        %166 = llvm.load %91 : !llvm.ptr -> i64
        %167 = llvm.mlir.addressof @MOD : !llvm.ptr
        %168 = llvm.load %167 : !llvm.ptr -> i64
        %169 = arith.remsi %arg0, %168 : i64
        %170 = llvm.load %95 : !llvm.ptr -> i64
        %171 = arith.muli %169, %170 : i64
        %172 = arith.addi %166, %171 : i64
        %173 = llvm.mlir.addressof @MOD : !llvm.ptr
        %174 = llvm.load %173 : !llvm.ptr -> i64
        %175 = arith.remsi %172, %174 : i64
        llvm.store %165, %91 : i64, !llvm.ptr
        llvm.store %175, %95 : i64, !llvm.ptr
        scf.yield %165, %175 : i64, i64
      } else {
        scf.yield %128, %140 : i64, i64
      }
      %176 = llvm.load %102 : !llvm.ptr -> i32
      %177 = arith.constant 1 : i32
      %178 = arith.subi %176, %177 : i32
      llvm.store %178, %102 : i32, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %179 = llvm.load %91 : !llvm.ptr -> i64
    %180 = arith.constant 0 : i32
    %181 = arith.extsi %180 : i32 to i64
    %182 = llvm.getelementptr %arg3[%181] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %179, %182 : i64, !llvm.ptr
    %183 = llvm.load %95 : !llvm.ptr -> i64
    %184 = arith.constant 1 : i32
    %185 = arith.extsi %184 : i32 to i64
    %186 = llvm.getelementptr %arg3[%185] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %183, %186 : i64, !llvm.ptr
    func.return
  }
  func.func @main() -> i32 {
    %187 = arith.constant 5000000 : i32
    %188 = arith.extsi %187 : i32 to i64
    %189 = arith.constant 0 : i32
    %190 = arith.extsi %189 : i32 to i64
    %191 = llvm.mlir.constant(1 : i64) : i64
    %192 = llvm.alloca %191 x i64 : (i64) -> !llvm.ptr
    llvm.store %190, %192 : i64, !llvm.ptr
    %194 = arith.constant 2 : i32
    %195 = arith.constant 8 : i32
    %196 = arith.extsi %194 : i32 to i64
    %197 = arith.extsi %195 : i32 to i64
    %193 = func.call @calloc(%196, %197) : (i64, i64) -> !llvm.ptr
    %198 = arith.constant 1 : i32
    %199 = arith.extsi %198 : i32 to i64
    %200 = llvm.mlir.constant(1 : i64) : i64
    %201 = llvm.alloca %200 x i64 : (i64) -> !llvm.ptr
    llvm.store %199, %201 : i64, !llvm.ptr
    cf.br ^bb24
    ^bb24:
    %202 = llvm.load %201 : !llvm.ptr -> i64
    %203 = arith.cmpi sle, %202, %188 : i64
    cf.cond_br %203, ^bb25, ^bb26
    ^bb25:
      %204 = llvm.load %201 : !llvm.ptr -> i64
      %205 = arith.sitofp %204 : i64 to f64
      %206 = math.sqrt %205 : f64
      %207 = arith.fptosi %206 : f64 to i64
      %208 = llvm.mlir.constant(1 : i64) : i64
      %209 = llvm.alloca %208 x i64 : (i64) -> !llvm.ptr
      llvm.store %207, %209 : i64, !llvm.ptr
      cf.br ^bb27
      ^bb27:
      %210 = llvm.load %209 : !llvm.ptr -> i64
      %211 = arith.constant 1 : i32
      %213 = arith.extsi %211 : i32 to i64
      %212 = arith.addi %210, %213 : i64
      %214 = llvm.load %209 : !llvm.ptr -> i64
      %215 = arith.constant 1 : i32
      %217 = arith.extsi %215 : i32 to i64
      %216 = arith.addi %214, %217 : i64
      %218 = arith.muli %212, %216 : i64
      %219 = llvm.load %201 : !llvm.ptr -> i64
      %220 = arith.cmpi sle, %218, %219 : i64
      cf.cond_br %220, ^bb28, ^bb29
      ^bb28:
        %221 = llvm.load %209 : !llvm.ptr -> i64
        %222 = arith.constant 1 : i32
        %224 = arith.extsi %222 : i32 to i64
        %223 = arith.addi %221, %224 : i64
        llvm.store %223, %209 : i64, !llvm.ptr
        cf.br ^bb27
      ^bb29:
      cf.br ^bb30
      ^bb30:
      %225 = llvm.load %209 : !llvm.ptr -> i64
      %226 = llvm.load %209 : !llvm.ptr -> i64
      %227 = arith.muli %225, %226 : i64
      %228 = llvm.load %201 : !llvm.ptr -> i64
      %229 = arith.cmpi sgt, %227, %228 : i64
      cf.cond_br %229, ^bb31, ^bb32
      ^bb31:
        %230 = llvm.load %209 : !llvm.ptr -> i64
        %231 = arith.constant 1 : i32
        %233 = arith.extsi %231 : i32 to i64
        %232 = arith.subi %230, %233 : i64
        llvm.store %232, %209 : i64, !llvm.ptr
        cf.br ^bb30
      ^bb32:
      %234 = llvm.load %209 : !llvm.ptr -> i64
      %235 = llvm.load %209 : !llvm.ptr -> i64
      %236 = arith.muli %234, %235 : i64
      %237 = llvm.load %201 : !llvm.ptr -> i64
      %238 = arith.cmpi eq, %236, %237 : i64
      cf.cond_br %238, ^bb33, ^bb34
      ^bb33:
        %240 = llvm.load %209 : !llvm.ptr -> i64
        %241 = llvm.load %201 : !llvm.ptr -> i64
        %242 = llvm.load %201 : !llvm.ptr -> i64
        %243 = llvm.load %201 : !llvm.ptr -> i64
        %244 = arith.muli %242, %243 : i64
        func.call @bin_exp(%240, %241, %244, %193) : (i64, i64, i64, !llvm.ptr) -> ()
        %245 = llvm.load %192 : !llvm.ptr -> i64
        %246 = arith.constant 2 : i32
        %248 = arith.constant 0 : i32
        %249 = arith.extsi %248 : i32 to i64
        %250 = llvm.getelementptr %193[%249] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %247 = llvm.load %250 : !llvm.ptr -> i64
        %252 = arith.extsi %246 : i32 to i64
        %251 = arith.muli %252, %247 : i64
        %253 = arith.addi %245, %251 : i64
        llvm.store %253, %192 : i64, !llvm.ptr
        cf.br ^bb35
      ^bb34:
        %255 = llvm.load %209 : !llvm.ptr -> i64
        %256 = arith.constant 1 : i32
        %258 = arith.extsi %256 : i32 to i64
        %257 = arith.addi %255, %258 : i64
        %259 = llvm.load %201 : !llvm.ptr -> i64
        %260 = llvm.load %201 : !llvm.ptr -> i64
        %261 = llvm.load %201 : !llvm.ptr -> i64
        %262 = arith.muli %260, %261 : i64
        func.call @bin_exp(%257, %259, %262, %193) : (i64, i64, i64, !llvm.ptr) -> ()
        %263 = llvm.load %192 : !llvm.ptr -> i64
        %264 = arith.constant 2 : i32
        %266 = arith.constant 0 : i32
        %267 = arith.extsi %266 : i32 to i64
        %268 = llvm.getelementptr %193[%267] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %265 = llvm.load %268 : !llvm.ptr -> i64
        %270 = arith.extsi %264 : i32 to i64
        %269 = arith.muli %270, %265 : i64
        %271 = arith.addi %263, %269 : i64
        %272 = arith.constant 1 : i32
        %274 = arith.extsi %272 : i32 to i64
        %273 = arith.subi %271, %274 : i64
        llvm.store %273, %192 : i64, !llvm.ptr
        cf.br ^bb35
      ^bb35:
      %275 = llvm.load %192 : !llvm.ptr -> i64
      %276 = llvm.mlir.addressof @MOD : !llvm.ptr
      %277 = llvm.load %276 : !llvm.ptr -> i64
      %278 = arith.remsi %275, %277 : i64
      llvm.store %278, %192 : i64, !llvm.ptr
      %279 = llvm.load %201 : !llvm.ptr -> i64
      %280 = arith.constant 1 : i32
      %282 = arith.extsi %280 : i32 to i64
      %281 = arith.addi %279, %282 : i64
      llvm.store %281, %201 : i64, !llvm.ptr
      cf.br ^bb24
    ^bb26:
    func.call @free(%193) : (!llvm.ptr) -> ()
    %284 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %285 = llvm.load %192 : !llvm.ptr -> i64
    %286 = llvm.call @printf(%284, %285) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %287 = arith.constant 0 : i32
    func.return %287 : i32
  }
}