Problem 514
Geoboard Shapes — E(100) expected convex hull area.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n^2) | O(n * s^2) |
| Space complexity | O(n^2) | O(s^2) |
| Approach | Flow solution | Markov chain or DP over states |
| Verdict | Unknown |
Flow source
# Project Euler 514
# Geoboard Shapes — E(100) expected convex hull area.
import euler.nt { gcd }
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
function line_len(kx_base: i64, kyv: i64) -> i64 {
if kyv > kx_base { return 1 + kx_base }
return 1 + kyv
}
function main() -> i32 {
let N: i64 = 100
let M: i64 = N + 1
let p: f64 = 1.0 / (M as f64)
let q: f64 = 1.0 - p
let total_points: i64 = M * M
let qpow: ptr<f64> = calloc(total_points + 1, 8)
let omq: ptr<f64> = calloc(total_points + 1, 8)
let qsmall: ptr<f64> = calloc(M + 1, 8)
let p2S: ptr<f64> = calloc(M + 1, 8)
let ky: ptr<i64> = calloc((N + 1) * M, 8)
let kx: ptr<i64> = calloc((N + 1) * M, 8)
if qpow == null || omq == null || qsmall == null || p2S == null || ky == null || kx == null { return 1 }
qpow[0] = 1.0
let mut i: i64 = 1
while i <= total_points {
qpow[i] = qpow[i - 1] * q
i = i + 1
}
i = 0
while i <= total_points {
omq[i] = 1.0 - qpow[i]
i = i + 1
}
qsmall[0] = 1.0
i = 1
while i <= M {
qsmall[i] = qsmall[i - 1] * q
i = i + 1
}
let p2: f64 = p * p
let mut L: i64 = 2
while L <= M {
let mut s: f64 = 0.0
let mut d: i64 = 1
while d < L {
s = s + (d as f64) * ((L - d) as f64) * qsmall[d - 1]
d = d + 1
}
p2S[L] = p2 * s
L = L + 1
}
let mut b: i64 = 1
while b <= N {
let mut y: i64 = 0
while y < M {
ky[b * M + y] = (N - y) / b
y = y + 1
}
b = b + 1
}
let mut a: i64 = 1
while a <= N {
let mut x: i64 = 0
while x < M {
kx[a * M + x] = (N - x) / a
x = x + 1
}
a = a + 1
}
let mut total_cross_scaled: f64 = 0.0
a = 1
while a <= N {
let mut bb: i64 = 0
while bb <= a {
if gcd(a, bb) == 1 {
if bb != 0 || a == 1 {
let mut mult: f64 = 8.0
if bb == 0 || a == bb { mult = 4.0 }
if bb == 0 {
let mut above: i64 = 0
let mut dir_sum: f64 = 0.0
let min_t: i64 = -a * N
let mut K: f64 = (4 * (N - 0) + (4 * min_t - 2 * N * (bb - a))) as f64
let Lline: i64 = M
let coeff: f64 = p2S[Lline]
let mut y3: i64 = 0
while y3 < M {
let below: i64 = total_points - above - Lline
dir_sum = dir_sum + qpow[above] * omq[below] * (K * coeff)
above = above + Lline
K = K - 4.0
y3 = y3 + 1
}
total_cross_scaled = total_cross_scaled + mult * dir_sum
} else {
let R: i64 = N * (a + bb) + 1
let counts: ptr<i64> = calloc(R, 8)
if counts != null {
let mut x0: i64 = 0
while x0 < a {
let kx_base: i64 = kx[a * M + x0]
let bx: i64 = bb * x0
let mut y0: i64 = 0
while y0 < M {
counts[bx + a * (N - y0)] = line_len(kx_base, ky[bb * M + y0])
y0 = y0 + 1
}
x0 = x0 + 1
}
x0 = a
while x0 < M {
let kx_base2: i64 = kx[a * M + x0]
let bx2: i64 = bb * x0
let mut y0b: i64 = 0
while y0b < bb {
counts[bx2 + a * (N - y0b)] = line_len(kx_base2, ky[bb * M + y0b])
y0b = y0b + 1
}
x0 = x0 + 1
}
let mut above2: i64 = 0
let k0: i64 = 4 * (-a * N) - 2 * N * (bb - a)
let mut K2: f64 = (4 * (R - 1) + k0) as f64
let mut dir_sum2: f64 = 0.0
let mut idx: i64 = R - 1
while idx >= 0 {
let cnt: i64 = counts[idx]
if cnt > 0 {
let below2: i64 = total_points - above2 - cnt
dir_sum2 = dir_sum2 + qpow[above2] * omq[below2] * (K2 * p2S[cnt])
above2 = above2 + cnt
}
K2 = K2 - 4.0
idx = idx - 1
}
total_cross_scaled = total_cross_scaled + mult * dir_sum2
free(counts)
}
}
}
}
bb = bb + 1
}
a = a + 1
}
let ans: f64 = total_cross_scaled / 8.0
printf("%.5f\n", ans)
free(qpow); free(omq); free(qsmall); free(p2S); free(ky); free(kx)
return 0
}
Generated C
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
while (flow_temp_head) {
flow_temp_node* n = flow_temp_head;
flow_temp_head = n->next;
free(n);
}
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
if (!node) return NULL;
node->next = flow_temp_head;
flow_temp_head = node;
if (!flow_temp_atexit_set) {
flow_temp_atexit_set = 1;
atexit(flow_temp_free_all);
}
return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
char* r = (char*)flow_temp_alloc(la + lb + 1);
if (!r) return NULL;
if (la) memcpy(r, a, la);
if (lb) memcpy(r + la, b, lb);
r[la + lb] = '\0';
return r;
}
#define __flow_in_arr(arr, val) __extension__ ({ \
int _found = 0; \
size_t _n = sizeof(arr)/sizeof((arr)[0]); \
for (size_t _i = 0; _i < _n; _i++) { \
if ((arr)[_i] == (val)) { _found = 1; break; } \
} _found; })
/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
abort();
#if defined(__GNUC__) || defined(__clang__)
__builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")
#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#include <math.h>
void* _ui_state = NULL;
static inline float i32_to_f32(int32_t v) { return (float)v; }
/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }
int64_t gcd_i64_i64(int64_t a0, int64_t b0);
int64_t lcm_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64(int64_t n);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t n);
int64_t line_len_i64_i64(int64_t kx_base, int64_t kyv);
int32_t main(void);
int64_t gcd_i64_i64(int64_t a0, int64_t b0) {
int64_t a = a0;
int64_t b = b0;
while (b != 0) {
int64_t t = FLOW_CHECKED_MOD((a), (b));
a = b;
b = t;
}
return a;
}
int64_t lcm_i64_i64(int64_t a, int64_t b) {
if ((a == 0 || b == 0)) {
return 0;
}
return (FLOW_CHECKED_DIV((a), (gcd_i64_i64(a, b))) * b);
}
int64_t isqrt_i64(int64_t n) {
if (n < 2) {
return n;
}
int64_t x = n;
int64_t y = FLOW_CHECKED_DIV(((x + 1)), (2));
while (y < x) {
x = y;
y = FLOW_CHECKED_DIV(((x + FLOW_CHECKED_DIV((n), (x)))), (2));
}
return x;
}
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod) {
int64_t a = FLOW_CHECKED_MOD((a0), (mod));
int64_t b = FLOW_CHECKED_MOD((b0), (mod));
int64_t result = 0;
while (b > 0) {
if (FLOW_CHECKED_MOD((b), (2)) == 1) {
result = FLOW_CHECKED_MOD(((result + a)), (mod));
}
a = FLOW_CHECKED_MOD(((a * 2)), (mod));
b = FLOW_CHECKED_DIV((b), (2));
}
return result;
}
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
if (mod == 1) {
return 0;
}
int64_t result = 1;
int64_t b = FLOW_CHECKED_MOD((base), (mod));
int64_t e = exp;
while (e > 0) {
if (FLOW_CHECKED_MOD((e), (2)) == 1) {
result = mulmod_i64_i64_i64(result, b, mod);
}
b = mulmod_i64_i64_i64(b, b, mod);
e = FLOW_CHECKED_DIV((e), (2));
}
return result;
}
bool is_prime_i64(int64_t n) {
if (n < 2) {
return 0;
}
if (n < 4) {
return 1;
}
if ((FLOW_CHECKED_MOD((n), (2)) == 0 || FLOW_CHECKED_MOD((n), (3)) == 0)) {
return 0;
}
int64_t i = 5;
while ((i * i) <= n) {
if ((FLOW_CHECKED_MOD((n), (i)) == 0 || FLOW_CHECKED_MOD((n), ((i + 2))) == 0)) {
return 0;
}
i = (i + 6);
}
return 1;
}
int64_t line_len_i64_i64(int64_t kx_base, int64_t kyv) {
if (kyv > kx_base) {
return (1 + kx_base);
}
return (1 + kyv);
}
int32_t main(void) {
int64_t N = 100;
int64_t M = (N + 1);
double p = (1.0 / ((double)(M)));
double q = (1.0 - p);
int64_t total_points = (M * M);
double* qpow = (double*)(calloc((total_points + 1), 8));
double* omq = (double*)(calloc((total_points + 1), 8));
double* qsmall = (double*)(calloc((M + 1), 8));
double* p2S = (double*)(calloc((M + 1), 8));
int64_t* ky = (int64_t*)(calloc(((N + 1) * M), 8));
int64_t* kx = (int64_t*)(calloc(((N + 1) * M), 8));
if ((((((qpow == NULL || omq == NULL) || qsmall == NULL) || p2S == NULL) || ky == NULL) || kx == NULL)) {
return 1;
}
qpow[0] = 1.0;
int64_t i = 1;
while (i <= total_points) {
qpow[i] = (qpow[(i - 1)] * q);
i = (i + 1);
}
i = 0;
while (i <= total_points) {
omq[i] = (1.0 - qpow[i]);
i = (i + 1);
}
qsmall[0] = 1.0;
i = 1;
while (i <= M) {
qsmall[i] = (qsmall[(i - 1)] * q);
i = (i + 1);
}
double p2 = (p * p);
int64_t L = 2;
while (L <= M) {
double s = 0.0;
int64_t d = 1;
while (d < L) {
s = (s + ((((double)(d)) * ((double)((L - d)))) * qsmall[(d - 1)]));
d = (d + 1);
}
p2S[L] = (p2 * s);
L = (L + 1);
}
int64_t b = 1;
while (b <= N) {
int64_t y = 0;
while (y < M) {
ky[((b * M) + y)] = FLOW_CHECKED_DIV(((N - y)), (b));
y = (y + 1);
}
b = (b + 1);
}
int64_t a = 1;
while (a <= N) {
int64_t x = 0;
while (x < M) {
kx[((a * M) + x)] = FLOW_CHECKED_DIV(((N - x)), (a));
x = (x + 1);
}
a = (a + 1);
}
double total_cross_scaled = 0.0;
a = 1;
while (a <= N) {
int64_t bb = 0;
while (bb <= a) {
if (gcd_i64_i64(a, bb) == 1) {
if ((bb != 0 || a == 1)) {
double mult = 8.0;
if ((bb == 0 || a == bb)) {
mult = 4.0;
}
if (bb == 0) {
int64_t above = 0;
double dir_sum = 0.0;
int64_t min_t = ((-a) * N);
double K = ((double)(((4 * (N - 0)) + ((4 * min_t) - ((2 * N) * (bb - a))))));
int64_t Lline = M;
double coeff = p2S[Lline];
int64_t y3 = 0;
while (y3 < M) {
int64_t below = ((total_points - above) - Lline);
dir_sum = (dir_sum + ((qpow[above] * omq[below]) * (K * coeff)));
above = (above + Lline);
K = (K - 4.0);
y3 = (y3 + 1);
}
total_cross_scaled = (total_cross_scaled + (mult * dir_sum));
} else {
int64_t R = ((N * (a + bb)) + 1);
int64_t* counts = (int64_t*)(calloc(R, 8));
if (counts != NULL) {
int64_t x0 = 0;
while (x0 < a) {
int64_t kx_base = kx[((a * M) + x0)];
int64_t bx = (bb * x0);
int64_t y0 = 0;
while (y0 < M) {
counts[(bx + (a * (N - y0)))] = line_len_i64_i64(kx_base, ky[((bb * M) + y0)]);
y0 = (y0 + 1);
}
x0 = (x0 + 1);
}
x0 = a;
while (x0 < M) {
int64_t kx_base2 = kx[((a * M) + x0)];
int64_t bx2 = (bb * x0);
int64_t y0b = 0;
while (y0b < bb) {
counts[(bx2 + (a * (N - y0b)))] = line_len_i64_i64(kx_base2, ky[((bb * M) + y0b)]);
y0b = (y0b + 1);
}
x0 = (x0 + 1);
}
int64_t above2 = 0;
int64_t k0 = ((4 * ((-a) * N)) - ((2 * N) * (bb - a)));
double K2 = ((double)(((4 * (R - 1)) + k0)));
double dir_sum2 = 0.0;
int64_t idx = (R - 1);
while (idx >= 0) {
int64_t cnt = counts[idx];
if (cnt > 0) {
int64_t below2 = ((total_points - above2) - cnt);
dir_sum2 = (dir_sum2 + ((qpow[above2] * omq[below2]) * (K2 * p2S[cnt])));
above2 = (above2 + cnt);
}
K2 = (K2 - 4.0);
idx = (idx - 1);
}
total_cross_scaled = (total_cross_scaled + (mult * dir_sum2));
free(counts);
}
}
}
}
bb = (bb + 1);
}
a = (a + 1);
}
double ans = (total_cross_scaled / 8.0);
printf("%.5f\n", ans);
free(qpow);
free(omq);
free(qsmall);
free(p2S);
free(ky);
free(kx);
return 0;
}
Generated MLIR
module {
llvm.func @printf(!llvm.ptr, ...) -> i32
llvm.mlir.global internal constant @str_0("%.5f\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
func.func @gcd(%arg0: i64, %arg1: i64) -> i64 {
%0 = llvm.mlir.constant(1 : i64) : i64
%1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %1 : i64, !llvm.ptr
%2 = llvm.mlir.constant(1 : i64) : i64
%3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %3 : i64, !llvm.ptr
cf.br ^bb0
^bb0:
%4 = llvm.load %3 : !llvm.ptr -> i64
%5 = arith.constant 0 : i32
%7 = arith.extsi %5 : i32 to i64
%6 = arith.cmpi ne, %4, %7 : i64
cf.cond_br %6, ^bb1, ^bb2
^bb1:
%8 = llvm.load %1 : !llvm.ptr -> i64
%9 = llvm.load %3 : !llvm.ptr -> i64
%10 = arith.remsi %8, %9 : i64
%11 = llvm.load %3 : !llvm.ptr -> i64
llvm.store %11, %1 : i64, !llvm.ptr
llvm.store %10, %3 : i64, !llvm.ptr
cf.br ^bb0
^bb2:
%12 = llvm.load %1 : !llvm.ptr -> i64
func.return %12 : i64
}
func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
%13 = arith.constant 0 : i32
%15 = arith.extsi %13 : i32 to i64
%14 = arith.cmpi eq, %arg0, %15 : i64
%16 = scf.if %14 -> (i1) {
%17 = arith.constant true
scf.yield %17 : i1
} else {
%18 = arith.constant 0 : i32
%20 = arith.extsi %18 : i32 to i64
%19 = arith.cmpi eq, %arg1, %20 : i64
scf.yield %19 : i1
}
cf.cond_br %16, ^bb3, ^bb4
^bb3:
%21 = arith.constant 0 : i32
%22 = arith.extsi %21 : i32 to i64
func.return %22 : i64
^bb4:
cf.br ^bb5
^bb5:
%23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
%24 = arith.divsi %arg0, %23 : i64
%25 = arith.muli %24, %arg1 : i64
func.return %25 : i64
}
func.func @isqrt(%arg0: i64) -> i64 {
%26 = arith.constant 2 : i32
%28 = arith.extsi %26 : i32 to i64
%27 = arith.cmpi slt, %arg0, %28 : i64
cf.cond_br %27, ^bb6, ^bb7
^bb6:
func.return %arg0 : i64
^bb7:
cf.br ^bb8
^bb8:
%29 = llvm.mlir.constant(1 : i64) : i64
%30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %30 : i64, !llvm.ptr
%31 = llvm.load %30 : !llvm.ptr -> i64
%32 = arith.constant 1 : i32
%34 = arith.extsi %32 : i32 to i64
%33 = arith.addi %31, %34 : i64
%35 = arith.constant 2 : i32
%37 = arith.extsi %35 : i32 to i64
%36 = arith.divsi %33, %37 : i64
%38 = llvm.mlir.constant(1 : i64) : i64
%39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
llvm.store %36, %39 : i64, !llvm.ptr
cf.br ^bb9
^bb9:
%40 = llvm.load %39 : !llvm.ptr -> i64
%41 = llvm.load %30 : !llvm.ptr -> i64
%42 = arith.cmpi slt, %40, %41 : i64
cf.cond_br %42, ^bb10, ^bb11
^bb10:
%43 = llvm.load %39 : !llvm.ptr -> i64
llvm.store %43, %30 : i64, !llvm.ptr
%44 = llvm.load %30 : !llvm.ptr -> i64
%45 = llvm.load %30 : !llvm.ptr -> i64
%46 = arith.divsi %arg0, %45 : i64
%47 = arith.addi %44, %46 : i64
%48 = arith.constant 2 : i32
%50 = arith.extsi %48 : i32 to i64
%49 = arith.divsi %47, %50 : i64
llvm.store %49, %39 : i64, !llvm.ptr
cf.br ^bb9
^bb11:
%51 = llvm.load %30 : !llvm.ptr -> i64
func.return %51 : i64
}
func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%52 = arith.remsi %arg0, %arg2 : i64
%53 = llvm.mlir.constant(1 : i64) : i64
%54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
llvm.store %52, %54 : i64, !llvm.ptr
%55 = arith.remsi %arg1, %arg2 : i64
%56 = llvm.mlir.constant(1 : i64) : i64
%57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
llvm.store %55, %57 : i64, !llvm.ptr
%58 = arith.constant 0 : i32
%59 = arith.extsi %58 : i32 to i64
%60 = llvm.mlir.constant(1 : i64) : i64
%61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
llvm.store %59, %61 : i64, !llvm.ptr
cf.br ^bb12
^bb12:
%62 = llvm.load %57 : !llvm.ptr -> i64
%63 = arith.constant 0 : i32
%65 = arith.extsi %63 : i32 to i64
%64 = arith.cmpi sgt, %62, %65 : i64
cf.cond_br %64, ^bb13, ^bb14
^bb13:
%66 = llvm.load %57 : !llvm.ptr -> i64
%67 = arith.constant 2 : i32
%69 = arith.extsi %67 : i32 to i64
%68 = arith.remsi %66, %69 : i64
%70 = arith.constant 1 : i32
%72 = arith.extsi %70 : i32 to i64
%71 = arith.cmpi eq, %68, %72 : i64
cf.cond_br %71, ^bb15, ^bb16
^bb15:
%73 = llvm.load %61 : !llvm.ptr -> i64
%74 = llvm.load %54 : !llvm.ptr -> i64
%75 = arith.addi %73, %74 : i64
%76 = arith.remsi %75, %arg2 : i64
llvm.store %76, %61 : i64, !llvm.ptr
cf.br ^bb17
^bb16:
cf.br ^bb17
^bb17:
%77 = llvm.load %54 : !llvm.ptr -> i64
%78 = arith.constant 2 : i32
%80 = arith.extsi %78 : i32 to i64
%79 = arith.muli %77, %80 : i64
%81 = arith.remsi %79, %arg2 : i64
llvm.store %81, %54 : i64, !llvm.ptr
%82 = llvm.load %57 : !llvm.ptr -> i64
%83 = arith.constant 2 : i32
%85 = arith.extsi %83 : i32 to i64
%84 = arith.divsi %82, %85 : i64
llvm.store %84, %57 : i64, !llvm.ptr
cf.br ^bb12
^bb14:
%86 = llvm.load %61 : !llvm.ptr -> i64
func.return %86 : i64
}
func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%87 = arith.constant 1 : i32
%89 = arith.extsi %87 : i32 to i64
%88 = arith.cmpi eq, %arg2, %89 : i64
cf.cond_br %88, ^bb18, ^bb19
^bb18:
%90 = arith.constant 0 : i32
%91 = arith.extsi %90 : i32 to i64
func.return %91 : i64
^bb19:
cf.br ^bb20
^bb20:
%92 = arith.constant 1 : i32
%93 = arith.extsi %92 : i32 to i64
%94 = llvm.mlir.constant(1 : i64) : i64
%95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
llvm.store %93, %95 : i64, !llvm.ptr
%96 = arith.remsi %arg0, %arg2 : i64
%97 = llvm.mlir.constant(1 : i64) : i64
%98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
llvm.store %96, %98 : i64, !llvm.ptr
%99 = llvm.mlir.constant(1 : i64) : i64
%100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %100 : i64, !llvm.ptr
cf.br ^bb21
^bb21:
%101 = llvm.load %100 : !llvm.ptr -> i64
%102 = arith.constant 0 : i32
%104 = arith.extsi %102 : i32 to i64
%103 = arith.cmpi sgt, %101, %104 : i64
cf.cond_br %103, ^bb22, ^bb23
^bb22:
%105 = llvm.load %100 : !llvm.ptr -> i64
%106 = arith.constant 2 : i32
%108 = arith.extsi %106 : i32 to i64
%107 = arith.remsi %105, %108 : i64
%109 = arith.constant 1 : i32
%111 = arith.extsi %109 : i32 to i64
%110 = arith.cmpi eq, %107, %111 : i64
cf.cond_br %110, ^bb24, ^bb25
^bb24:
%113 = llvm.load %95 : !llvm.ptr -> i64
%114 = llvm.load %98 : !llvm.ptr -> i64
%112 = func.call @mulmod(%113, %114, %arg2) : (i64, i64, i64) -> i64
llvm.store %112, %95 : i64, !llvm.ptr
cf.br ^bb26
^bb25:
cf.br ^bb26
^bb26:
%116 = llvm.load %98 : !llvm.ptr -> i64
%117 = llvm.load %98 : !llvm.ptr -> i64
%115 = func.call @mulmod(%116, %117, %arg2) : (i64, i64, i64) -> i64
llvm.store %115, %98 : i64, !llvm.ptr
%118 = llvm.load %100 : !llvm.ptr -> i64
%119 = arith.constant 2 : i32
%121 = arith.extsi %119 : i32 to i64
%120 = arith.divsi %118, %121 : i64
llvm.store %120, %100 : i64, !llvm.ptr
cf.br ^bb21
^bb23:
%122 = llvm.load %95 : !llvm.ptr -> i64
func.return %122 : i64
}
func.func @is_prime(%arg0: i64) -> i1 {
%123 = arith.constant 2 : i32
%125 = arith.extsi %123 : i32 to i64
%124 = arith.cmpi slt, %arg0, %125 : i64
cf.cond_br %124, ^bb27, ^bb28
^bb27:
%126 = arith.constant 0 : i1
func.return %126 : i1
^bb28:
cf.br ^bb29
^bb29:
%127 = arith.constant 4 : i32
%129 = arith.extsi %127 : i32 to i64
%128 = arith.cmpi slt, %arg0, %129 : i64
cf.cond_br %128, ^bb30, ^bb31
^bb30:
%130 = arith.constant 1 : i1
func.return %130 : i1
^bb31:
cf.br ^bb32
^bb32:
%131 = arith.constant 2 : i32
%133 = arith.extsi %131 : i32 to i64
%132 = arith.remsi %arg0, %133 : i64
%134 = arith.constant 0 : i32
%136 = arith.extsi %134 : i32 to i64
%135 = arith.cmpi eq, %132, %136 : i64
%137 = scf.if %135 -> (i1) {
%138 = arith.constant true
scf.yield %138 : i1
} else {
%139 = arith.constant 3 : i32
%141 = arith.extsi %139 : i32 to i64
%140 = arith.remsi %arg0, %141 : i64
%142 = arith.constant 0 : i32
%144 = arith.extsi %142 : i32 to i64
%143 = arith.cmpi eq, %140, %144 : i64
scf.yield %143 : i1
}
cf.cond_br %137, ^bb33, ^bb34
^bb33:
%145 = arith.constant 0 : i1
func.return %145 : i1
^bb34:
cf.br ^bb35
^bb35:
%146 = arith.constant 5 : i32
%147 = arith.extsi %146 : i32 to i64
%148 = llvm.mlir.constant(1 : i64) : i64
%149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
llvm.store %147, %149 : i64, !llvm.ptr
cf.br ^bb36
^bb36:
%150 = llvm.load %149 : !llvm.ptr -> i64
%151 = llvm.load %149 : !llvm.ptr -> i64
%152 = arith.muli %150, %151 : i64
%153 = arith.cmpi sle, %152, %arg0 : i64
cf.cond_br %153, ^bb37, ^bb38
^bb37:
%154 = llvm.load %149 : !llvm.ptr -> i64
%155 = arith.remsi %arg0, %154 : i64
%156 = arith.constant 0 : i32
%158 = arith.extsi %156 : i32 to i64
%157 = arith.cmpi eq, %155, %158 : i64
%159 = scf.if %157 -> (i1) {
%160 = arith.constant true
scf.yield %160 : i1
} else {
%161 = llvm.load %149 : !llvm.ptr -> i64
%162 = arith.constant 2 : i32
%164 = arith.extsi %162 : i32 to i64
%163 = arith.addi %161, %164 : i64
%165 = arith.remsi %arg0, %163 : i64
%166 = arith.constant 0 : i32
%168 = arith.extsi %166 : i32 to i64
%167 = arith.cmpi eq, %165, %168 : i64
scf.yield %167 : i1
}
cf.cond_br %159, ^bb39, ^bb40
^bb39:
%169 = arith.constant 0 : i1
func.return %169 : i1
^bb40:
cf.br ^bb41
^bb41:
%170 = llvm.load %149 : !llvm.ptr -> i64
%171 = arith.constant 6 : i32
%173 = arith.extsi %171 : i32 to i64
%172 = arith.addi %170, %173 : i64
llvm.store %172, %149 : i64, !llvm.ptr
cf.br ^bb36
^bb38:
%174 = arith.constant 1 : i1
func.return %174 : i1
}
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
func.func @line_len(%arg0: i64, %arg1: i64) -> i64 {
%175 = arith.cmpi sgt, %arg1, %arg0 : i64
cf.cond_br %175, ^bb42, ^bb43
^bb42:
%176 = arith.constant 1 : i32
%178 = arith.extsi %176 : i32 to i64
%177 = arith.addi %178, %arg0 : i64
func.return %177 : i64
^bb43:
cf.br ^bb44
^bb44:
%179 = arith.constant 1 : i32
%181 = arith.extsi %179 : i32 to i64
%180 = arith.addi %181, %arg1 : i64
func.return %180 : i64
}
func.func @main() -> i32 {
%182 = arith.constant 100 : i32
%183 = arith.extsi %182 : i32 to i64
%184 = arith.constant 1 : i32
%186 = arith.extsi %184 : i32 to i64
%185 = arith.addi %183, %186 : i64
%187 = arith.constant 1.0 : f32
%188 = arith.sitofp %185 : i64 to f64
%190 = arith.extf %187 : f32 to f64
%189 = arith.divf %190, %188 : f64
%191 = arith.constant 1.0 : f32
%193 = arith.extf %191 : f32 to f64
%192 = arith.subf %193, %189 : f64
%194 = arith.muli %185, %185 : i64
%196 = arith.constant 1 : i32
%198 = arith.extsi %196 : i32 to i64
%197 = arith.addi %194, %198 : i64
%199 = arith.constant 8 : i32
%200 = arith.extsi %199 : i32 to i64
%195 = func.call @calloc(%197, %200) : (i64, i64) -> !llvm.ptr
%202 = arith.constant 1 : i32
%204 = arith.extsi %202 : i32 to i64
%203 = arith.addi %194, %204 : i64
%205 = arith.constant 8 : i32
%206 = arith.extsi %205 : i32 to i64
%201 = func.call @calloc(%203, %206) : (i64, i64) -> !llvm.ptr
%208 = arith.constant 1 : i32
%210 = arith.extsi %208 : i32 to i64
%209 = arith.addi %185, %210 : i64
%211 = arith.constant 8 : i32
%212 = arith.extsi %211 : i32 to i64
%207 = func.call @calloc(%209, %212) : (i64, i64) -> !llvm.ptr
%214 = arith.constant 1 : i32
%216 = arith.extsi %214 : i32 to i64
%215 = arith.addi %185, %216 : i64
%217 = arith.constant 8 : i32
%218 = arith.extsi %217 : i32 to i64
%213 = func.call @calloc(%215, %218) : (i64, i64) -> !llvm.ptr
%220 = arith.constant 1 : i32
%222 = arith.extsi %220 : i32 to i64
%221 = arith.addi %183, %222 : i64
%223 = arith.muli %221, %185 : i64
%224 = arith.constant 8 : i32
%225 = arith.extsi %224 : i32 to i64
%219 = func.call @calloc(%223, %225) : (i64, i64) -> !llvm.ptr
%227 = arith.constant 1 : i32
%229 = arith.extsi %227 : i32 to i64
%228 = arith.addi %183, %229 : i64
%230 = arith.muli %228, %185 : i64
%231 = arith.constant 8 : i32
%232 = arith.extsi %231 : i32 to i64
%226 = func.call @calloc(%230, %232) : (i64, i64) -> !llvm.ptr
%233 = llvm.mlir.zero : !llvm.ptr
%234 = llvm.icmp "eq" %195, %233 : !llvm.ptr
%235 = scf.if %234 -> (i1) {
%236 = arith.constant true
scf.yield %236 : i1
} else {
%237 = llvm.mlir.zero : !llvm.ptr
%238 = llvm.icmp "eq" %201, %237 : !llvm.ptr
scf.yield %238 : i1
}
%239 = scf.if %235 -> (i1) {
%240 = arith.constant true
scf.yield %240 : i1
} else {
%241 = llvm.mlir.zero : !llvm.ptr
%242 = llvm.icmp "eq" %207, %241 : !llvm.ptr
scf.yield %242 : i1
}
%243 = scf.if %239 -> (i1) {
%244 = arith.constant true
scf.yield %244 : i1
} else {
%245 = llvm.mlir.zero : !llvm.ptr
%246 = llvm.icmp "eq" %213, %245 : !llvm.ptr
scf.yield %246 : i1
}
%247 = scf.if %243 -> (i1) {
%248 = arith.constant true
scf.yield %248 : i1
} else {
%249 = llvm.mlir.zero : !llvm.ptr
%250 = llvm.icmp "eq" %219, %249 : !llvm.ptr
scf.yield %250 : i1
}
%251 = scf.if %247 -> (i1) {
%252 = arith.constant true
scf.yield %252 : i1
} else {
%253 = llvm.mlir.zero : !llvm.ptr
%254 = llvm.icmp "eq" %226, %253 : !llvm.ptr
scf.yield %254 : i1
}
cf.cond_br %251, ^bb45, ^bb46
^bb45:
%255 = arith.constant 1 : i32
func.return %255 : i32
^bb46:
cf.br ^bb47
^bb47:
%256 = arith.constant 1.0 : f32
%257 = arith.constant 0 : i32
%258 = arith.extf %256 : f32 to f64
%259 = arith.extsi %257 : i32 to i64
%260 = llvm.getelementptr %195[%259] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %258, %260 : f64, !llvm.ptr
%261 = arith.constant 1 : i32
%262 = arith.extsi %261 : i32 to i64
%263 = llvm.mlir.constant(1 : i64) : i64
%264 = llvm.alloca %263 x i64 : (i64) -> !llvm.ptr
llvm.store %262, %264 : i64, !llvm.ptr
cf.br ^bb48
^bb48:
%265 = llvm.load %264 : !llvm.ptr -> i64
%266 = arith.cmpi sle, %265, %194 : i64
cf.cond_br %266, ^bb49, ^bb50
^bb49:
%268 = llvm.load %264 : !llvm.ptr -> i64
%269 = arith.constant 1 : i32
%271 = arith.extsi %269 : i32 to i64
%270 = arith.subi %268, %271 : i64
%272 = llvm.getelementptr %195[%270] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%267 = llvm.load %272 : !llvm.ptr -> f64
%273 = arith.mulf %267, %192 : f64
%274 = llvm.load %264 : !llvm.ptr -> i64
%275 = llvm.getelementptr %195[%274] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %273, %275 : f64, !llvm.ptr
%276 = llvm.load %264 : !llvm.ptr -> i64
%277 = arith.constant 1 : i32
%279 = arith.extsi %277 : i32 to i64
%278 = arith.addi %276, %279 : i64
llvm.store %278, %264 : i64, !llvm.ptr
cf.br ^bb48
^bb50:
%280 = arith.constant 0 : i32
%281 = arith.extsi %280 : i32 to i64
llvm.store %281, %264 : i64, !llvm.ptr
cf.br ^bb51
^bb51:
%282 = llvm.load %264 : !llvm.ptr -> i64
%283 = arith.cmpi sle, %282, %194 : i64
cf.cond_br %283, ^bb52, ^bb53
^bb52:
%284 = arith.constant 1.0 : f32
%286 = llvm.load %264 : !llvm.ptr -> i64
%287 = llvm.getelementptr %195[%286] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%285 = llvm.load %287 : !llvm.ptr -> f64
%289 = arith.extf %284 : f32 to f64
%288 = arith.subf %289, %285 : f64
%290 = llvm.load %264 : !llvm.ptr -> i64
%291 = llvm.getelementptr %201[%290] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %288, %291 : f64, !llvm.ptr
%292 = llvm.load %264 : !llvm.ptr -> i64
%293 = arith.constant 1 : i32
%295 = arith.extsi %293 : i32 to i64
%294 = arith.addi %292, %295 : i64
llvm.store %294, %264 : i64, !llvm.ptr
cf.br ^bb51
^bb53:
%296 = arith.constant 1.0 : f32
%297 = arith.constant 0 : i32
%298 = arith.extf %296 : f32 to f64
%299 = arith.extsi %297 : i32 to i64
%300 = llvm.getelementptr %207[%299] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %298, %300 : f64, !llvm.ptr
%301 = arith.constant 1 : i32
%302 = arith.extsi %301 : i32 to i64
llvm.store %302, %264 : i64, !llvm.ptr
cf.br ^bb54
^bb54:
%303 = llvm.load %264 : !llvm.ptr -> i64
%304 = arith.cmpi sle, %303, %185 : i64
cf.cond_br %304, ^bb55, ^bb56
^bb55:
%306 = llvm.load %264 : !llvm.ptr -> i64
%307 = arith.constant 1 : i32
%309 = arith.extsi %307 : i32 to i64
%308 = arith.subi %306, %309 : i64
%310 = llvm.getelementptr %207[%308] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%305 = llvm.load %310 : !llvm.ptr -> f64
%311 = arith.mulf %305, %192 : f64
%312 = llvm.load %264 : !llvm.ptr -> i64
%313 = llvm.getelementptr %207[%312] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %311, %313 : f64, !llvm.ptr
%314 = llvm.load %264 : !llvm.ptr -> i64
%315 = arith.constant 1 : i32
%317 = arith.extsi %315 : i32 to i64
%316 = arith.addi %314, %317 : i64
llvm.store %316, %264 : i64, !llvm.ptr
cf.br ^bb54
^bb56:
%318 = arith.mulf %189, %189 : f64
%319 = arith.constant 2 : i32
%320 = arith.extsi %319 : i32 to i64
%321 = llvm.mlir.constant(1 : i64) : i64
%322 = llvm.alloca %321 x i64 : (i64) -> !llvm.ptr
llvm.store %320, %322 : i64, !llvm.ptr
cf.br ^bb57
^bb57:
%323 = llvm.load %322 : !llvm.ptr -> i64
%324 = arith.cmpi sle, %323, %185 : i64
cf.cond_br %324, ^bb58, ^bb59
^bb58:
%325 = arith.constant 0.0 : f32
%326 = arith.extf %325 : f32 to f64
%327 = llvm.mlir.constant(1 : i64) : i64
%328 = llvm.alloca %327 x f64 : (i64) -> !llvm.ptr
llvm.store %326, %328 : f64, !llvm.ptr
%329 = arith.constant 1 : i32
%330 = arith.extsi %329 : i32 to i64
%331 = llvm.mlir.constant(1 : i64) : i64
%332 = llvm.alloca %331 x i64 : (i64) -> !llvm.ptr
llvm.store %330, %332 : i64, !llvm.ptr
cf.br ^bb60
^bb60:
%333 = llvm.load %332 : !llvm.ptr -> i64
%334 = llvm.load %322 : !llvm.ptr -> i64
%335 = arith.cmpi slt, %333, %334 : i64
cf.cond_br %335, ^bb61, ^bb62
^bb61:
%336 = llvm.load %328 : !llvm.ptr -> f64
%337 = llvm.load %332 : !llvm.ptr -> i64
%338 = arith.sitofp %337 : i64 to f64
%339 = llvm.load %322 : !llvm.ptr -> i64
%340 = llvm.load %332 : !llvm.ptr -> i64
%341 = arith.subi %339, %340 : i64
%342 = arith.sitofp %341 : i64 to f64
%343 = arith.mulf %338, %342 : f64
%345 = llvm.load %332 : !llvm.ptr -> i64
%346 = arith.constant 1 : i32
%348 = arith.extsi %346 : i32 to i64
%347 = arith.subi %345, %348 : i64
%349 = llvm.getelementptr %207[%347] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%344 = llvm.load %349 : !llvm.ptr -> f64
%350 = arith.mulf %343, %344 : f64
%351 = arith.addf %336, %350 : f64
llvm.store %351, %328 : f64, !llvm.ptr
%352 = llvm.load %332 : !llvm.ptr -> i64
%353 = arith.constant 1 : i32
%355 = arith.extsi %353 : i32 to i64
%354 = arith.addi %352, %355 : i64
llvm.store %354, %332 : i64, !llvm.ptr
cf.br ^bb60
^bb62:
%356 = llvm.load %328 : !llvm.ptr -> f64
%357 = arith.mulf %318, %356 : f64
%358 = llvm.load %322 : !llvm.ptr -> i64
%359 = llvm.getelementptr %213[%358] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %357, %359 : f64, !llvm.ptr
%360 = llvm.load %322 : !llvm.ptr -> i64
%361 = arith.constant 1 : i32
%363 = arith.extsi %361 : i32 to i64
%362 = arith.addi %360, %363 : i64
llvm.store %362, %322 : i64, !llvm.ptr
cf.br ^bb57
^bb59:
%364 = arith.constant 1 : i32
%365 = arith.extsi %364 : i32 to i64
%366 = llvm.mlir.constant(1 : i64) : i64
%367 = llvm.alloca %366 x i64 : (i64) -> !llvm.ptr
llvm.store %365, %367 : i64, !llvm.ptr
cf.br ^bb63
^bb63:
%368 = llvm.load %367 : !llvm.ptr -> i64
%369 = arith.cmpi sle, %368, %183 : i64
cf.cond_br %369, ^bb64, ^bb65
^bb64:
%370 = arith.constant 0 : i32
%371 = arith.extsi %370 : i32 to i64
%372 = llvm.mlir.constant(1 : i64) : i64
%373 = llvm.alloca %372 x i64 : (i64) -> !llvm.ptr
llvm.store %371, %373 : i64, !llvm.ptr
cf.br ^bb66
^bb66:
%374 = llvm.load %373 : !llvm.ptr -> i64
%375 = arith.cmpi slt, %374, %185 : i64
cf.cond_br %375, ^bb67, ^bb68
^bb67:
%376 = llvm.load %373 : !llvm.ptr -> i64
%377 = arith.subi %183, %376 : i64
%378 = llvm.load %367 : !llvm.ptr -> i64
%379 = arith.divsi %377, %378 : i64
%380 = llvm.load %367 : !llvm.ptr -> i64
%381 = arith.muli %380, %185 : i64
%382 = llvm.load %373 : !llvm.ptr -> i64
%383 = arith.addi %381, %382 : i64
%384 = llvm.getelementptr %219[%383] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %379, %384 : i64, !llvm.ptr
%385 = llvm.load %373 : !llvm.ptr -> i64
%386 = arith.constant 1 : i32
%388 = arith.extsi %386 : i32 to i64
%387 = arith.addi %385, %388 : i64
llvm.store %387, %373 : i64, !llvm.ptr
cf.br ^bb66
^bb68:
%389 = llvm.load %367 : !llvm.ptr -> i64
%390 = arith.constant 1 : i32
%392 = arith.extsi %390 : i32 to i64
%391 = arith.addi %389, %392 : i64
llvm.store %391, %367 : i64, !llvm.ptr
cf.br ^bb63
^bb65:
%393 = arith.constant 1 : i32
%394 = arith.extsi %393 : i32 to i64
%395 = llvm.mlir.constant(1 : i64) : i64
%396 = llvm.alloca %395 x i64 : (i64) -> !llvm.ptr
llvm.store %394, %396 : i64, !llvm.ptr
cf.br ^bb69
^bb69:
%397 = llvm.load %396 : !llvm.ptr -> i64
%398 = arith.cmpi sle, %397, %183 : i64
cf.cond_br %398, ^bb70, ^bb71
^bb70:
%399 = arith.constant 0 : i32
%400 = arith.extsi %399 : i32 to i64
%401 = llvm.mlir.constant(1 : i64) : i64
%402 = llvm.alloca %401 x i64 : (i64) -> !llvm.ptr
llvm.store %400, %402 : i64, !llvm.ptr
cf.br ^bb72
^bb72:
%403 = llvm.load %402 : !llvm.ptr -> i64
%404 = arith.cmpi slt, %403, %185 : i64
cf.cond_br %404, ^bb73, ^bb74
^bb73:
%405 = llvm.load %402 : !llvm.ptr -> i64
%406 = arith.subi %183, %405 : i64
%407 = llvm.load %396 : !llvm.ptr -> i64
%408 = arith.divsi %406, %407 : i64
%409 = llvm.load %396 : !llvm.ptr -> i64
%410 = arith.muli %409, %185 : i64
%411 = llvm.load %402 : !llvm.ptr -> i64
%412 = arith.addi %410, %411 : i64
%413 = llvm.getelementptr %226[%412] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %408, %413 : i64, !llvm.ptr
%414 = llvm.load %402 : !llvm.ptr -> i64
%415 = arith.constant 1 : i32
%417 = arith.extsi %415 : i32 to i64
%416 = arith.addi %414, %417 : i64
llvm.store %416, %402 : i64, !llvm.ptr
cf.br ^bb72
^bb74:
%418 = llvm.load %396 : !llvm.ptr -> i64
%419 = arith.constant 1 : i32
%421 = arith.extsi %419 : i32 to i64
%420 = arith.addi %418, %421 : i64
llvm.store %420, %396 : i64, !llvm.ptr
cf.br ^bb69
^bb71:
%422 = arith.constant 0.0 : f32
%423 = arith.extf %422 : f32 to f64
%424 = llvm.mlir.constant(1 : i64) : i64
%425 = llvm.alloca %424 x f64 : (i64) -> !llvm.ptr
llvm.store %423, %425 : f64, !llvm.ptr
%426 = arith.constant 1 : i32
%427 = arith.extsi %426 : i32 to i64
llvm.store %427, %396 : i64, !llvm.ptr
cf.br ^bb75
^bb75:
%428 = llvm.load %396 : !llvm.ptr -> i64
%429 = arith.cmpi sle, %428, %183 : i64
cf.cond_br %429, ^bb76, ^bb77
^bb76:
%430 = arith.constant 0 : i32
%431 = arith.extsi %430 : i32 to i64
%432 = llvm.mlir.constant(1 : i64) : i64
%433 = llvm.alloca %432 x i64 : (i64) -> !llvm.ptr
llvm.store %431, %433 : i64, !llvm.ptr
cf.br ^bb78
^bb78:
%434 = llvm.load %433 : !llvm.ptr -> i64
%435 = llvm.load %396 : !llvm.ptr -> i64
%436 = arith.cmpi sle, %434, %435 : i64
cf.cond_br %436, ^bb79, ^bb80
^bb79:
%438 = llvm.load %396 : !llvm.ptr -> i64
%439 = llvm.load %433 : !llvm.ptr -> i64
%437 = func.call @gcd(%438, %439) : (i64, i64) -> i64
%440 = arith.constant 1 : i32
%442 = arith.extsi %440 : i32 to i64
%441 = arith.cmpi eq, %437, %442 : i64
cf.cond_br %441, ^bb81, ^bb82
^bb81:
%443 = llvm.load %433 : !llvm.ptr -> i64
%444 = arith.constant 0 : i32
%446 = arith.extsi %444 : i32 to i64
%445 = arith.cmpi ne, %443, %446 : i64
%447 = scf.if %445 -> (i1) {
%448 = arith.constant true
scf.yield %448 : i1
} else {
%449 = llvm.load %396 : !llvm.ptr -> i64
%450 = arith.constant 1 : i32
%452 = arith.extsi %450 : i32 to i64
%451 = arith.cmpi eq, %449, %452 : i64
scf.yield %451 : i1
}
cf.cond_br %447, ^bb84, ^bb85
^bb84:
%453 = arith.constant 8.0 : f32
%454 = arith.extf %453 : f32 to f64
%455 = llvm.mlir.constant(1 : i64) : i64
%456 = llvm.alloca %455 x f64 : (i64) -> !llvm.ptr
llvm.store %454, %456 : f64, !llvm.ptr
%457 = llvm.load %433 : !llvm.ptr -> i64
%458 = arith.constant 0 : i32
%460 = arith.extsi %458 : i32 to i64
%459 = arith.cmpi eq, %457, %460 : i64
%461 = scf.if %459 -> (i1) {
%462 = arith.constant true
scf.yield %462 : i1
} else {
%463 = llvm.load %396 : !llvm.ptr -> i64
%464 = llvm.load %433 : !llvm.ptr -> i64
%465 = arith.cmpi eq, %463, %464 : i64
scf.yield %465 : i1
}
cf.cond_br %461, ^bb87, ^bb88
^bb87:
%466 = arith.constant 4.0 : f32
%467 = arith.extf %466 : f32 to f64
llvm.store %467, %456 : f64, !llvm.ptr
cf.br ^bb89
^bb88:
cf.br ^bb89
^bb89:
%468 = llvm.load %433 : !llvm.ptr -> i64
%469 = arith.constant 0 : i32
%471 = arith.extsi %469 : i32 to i64
%470 = arith.cmpi eq, %468, %471 : i64
cf.cond_br %470, ^bb90, ^bb91
^bb90:
%472 = arith.constant 0 : i32
%473 = arith.extsi %472 : i32 to i64
%474 = llvm.mlir.constant(1 : i64) : i64
%475 = llvm.alloca %474 x i64 : (i64) -> !llvm.ptr
llvm.store %473, %475 : i64, !llvm.ptr
%476 = arith.constant 0.0 : f32
%477 = arith.extf %476 : f32 to f64
%478 = llvm.mlir.constant(1 : i64) : i64
%479 = llvm.alloca %478 x f64 : (i64) -> !llvm.ptr
llvm.store %477, %479 : f64, !llvm.ptr
%480 = llvm.load %396 : !llvm.ptr -> i64
%482 = arith.constant 0 : i64
%481 = arith.subi %482, %480 : i64
%483 = arith.muli %481, %183 : i64
%484 = arith.constant 4 : i32
%485 = arith.constant 0 : i32
%487 = arith.extsi %485 : i32 to i64
%486 = arith.subi %183, %487 : i64
%489 = arith.extsi %484 : i32 to i64
%488 = arith.muli %489, %486 : i64
%490 = arith.constant 4 : i32
%492 = arith.extsi %490 : i32 to i64
%491 = arith.muli %492, %483 : i64
%493 = arith.constant 2 : i32
%495 = arith.extsi %493 : i32 to i64
%494 = arith.muli %495, %183 : i64
%496 = llvm.load %433 : !llvm.ptr -> i64
%497 = llvm.load %396 : !llvm.ptr -> i64
%498 = arith.subi %496, %497 : i64
%499 = arith.muli %494, %498 : i64
%500 = arith.subi %491, %499 : i64
%501 = arith.addi %488, %500 : i64
%502 = arith.sitofp %501 : i64 to f64
%503 = llvm.mlir.constant(1 : i64) : i64
%504 = llvm.alloca %503 x f64 : (i64) -> !llvm.ptr
llvm.store %502, %504 : f64, !llvm.ptr
%506 = llvm.getelementptr %213[%185] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%505 = llvm.load %506 : !llvm.ptr -> f64
%507 = arith.constant 0 : i32
%508 = arith.extsi %507 : i32 to i64
%509 = llvm.mlir.constant(1 : i64) : i64
%510 = llvm.alloca %509 x i64 : (i64) -> !llvm.ptr
llvm.store %508, %510 : i64, !llvm.ptr
cf.br ^bb93
^bb93:
%511 = llvm.load %510 : !llvm.ptr -> i64
%512 = arith.cmpi slt, %511, %185 : i64
cf.cond_br %512, ^bb94, ^bb95
^bb94:
%513 = llvm.load %475 : !llvm.ptr -> i64
%514 = arith.subi %194, %513 : i64
%515 = arith.subi %514, %185 : i64
%516 = llvm.load %479 : !llvm.ptr -> f64
%518 = llvm.load %475 : !llvm.ptr -> i64
%519 = llvm.getelementptr %195[%518] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%517 = llvm.load %519 : !llvm.ptr -> f64
%521 = llvm.getelementptr %201[%515] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%520 = llvm.load %521 : !llvm.ptr -> f64
%522 = arith.mulf %517, %520 : f64
%523 = llvm.load %504 : !llvm.ptr -> f64
%524 = arith.mulf %523, %505 : f64
%525 = arith.mulf %522, %524 : f64
%526 = arith.addf %516, %525 : f64
llvm.store %526, %479 : f64, !llvm.ptr
%527 = llvm.load %475 : !llvm.ptr -> i64
%528 = arith.addi %527, %185 : i64
llvm.store %528, %475 : i64, !llvm.ptr
%529 = llvm.load %504 : !llvm.ptr -> f64
%530 = arith.constant 4.0 : f32
%532 = arith.extf %530 : f32 to f64
%531 = arith.subf %529, %532 : f64
llvm.store %531, %504 : f64, !llvm.ptr
%533 = llvm.load %510 : !llvm.ptr -> i64
%534 = arith.constant 1 : i32
%536 = arith.extsi %534 : i32 to i64
%535 = arith.addi %533, %536 : i64
llvm.store %535, %510 : i64, !llvm.ptr
cf.br ^bb93
^bb95:
%537 = llvm.load %425 : !llvm.ptr -> f64
%538 = llvm.load %456 : !llvm.ptr -> f64
%539 = llvm.load %479 : !llvm.ptr -> f64
%540 = arith.mulf %538, %539 : f64
%541 = arith.addf %537, %540 : f64
llvm.store %541, %425 : f64, !llvm.ptr
cf.br ^bb92
^bb91:
%542 = llvm.load %396 : !llvm.ptr -> i64
%543 = llvm.load %433 : !llvm.ptr -> i64
%544 = arith.addi %542, %543 : i64
%545 = arith.muli %183, %544 : i64
%546 = arith.constant 1 : i32
%548 = arith.extsi %546 : i32 to i64
%547 = arith.addi %545, %548 : i64
%550 = arith.constant 8 : i32
%551 = arith.extsi %550 : i32 to i64
%549 = func.call @calloc(%547, %551) : (i64, i64) -> !llvm.ptr
%552 = llvm.mlir.zero : !llvm.ptr
%553 = llvm.icmp "ne" %549, %552 : !llvm.ptr
cf.cond_br %553, ^bb96, ^bb97
^bb96:
%554 = arith.constant 0 : i32
%555 = arith.extsi %554 : i32 to i64
%556 = llvm.mlir.constant(1 : i64) : i64
%557 = llvm.alloca %556 x i64 : (i64) -> !llvm.ptr
llvm.store %555, %557 : i64, !llvm.ptr
cf.br ^bb99
^bb99:
%558 = llvm.load %557 : !llvm.ptr -> i64
%559 = llvm.load %396 : !llvm.ptr -> i64
%560 = arith.cmpi slt, %558, %559 : i64
cf.cond_br %560, ^bb100, ^bb101
^bb100:
%562 = llvm.load %396 : !llvm.ptr -> i64
%563 = arith.muli %562, %185 : i64
%564 = llvm.load %557 : !llvm.ptr -> i64
%565 = arith.addi %563, %564 : i64
%566 = llvm.getelementptr %226[%565] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%561 = llvm.load %566 : !llvm.ptr -> i64
%567 = llvm.load %433 : !llvm.ptr -> i64
%568 = llvm.load %557 : !llvm.ptr -> i64
%569 = arith.muli %567, %568 : i64
%570 = arith.constant 0 : i32
%571 = arith.extsi %570 : i32 to i64
%572 = llvm.mlir.constant(1 : i64) : i64
%573 = llvm.alloca %572 x i64 : (i64) -> !llvm.ptr
llvm.store %571, %573 : i64, !llvm.ptr
cf.br ^bb102
^bb102:
%574 = llvm.load %573 : !llvm.ptr -> i64
%575 = arith.cmpi slt, %574, %185 : i64
cf.cond_br %575, ^bb103, ^bb104
^bb103:
%578 = llvm.load %433 : !llvm.ptr -> i64
%579 = arith.muli %578, %185 : i64
%580 = llvm.load %573 : !llvm.ptr -> i64
%581 = arith.addi %579, %580 : i64
%582 = llvm.getelementptr %219[%581] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%577 = llvm.load %582 : !llvm.ptr -> i64
%576 = func.call @line_len(%561, %577) : (i64, i64) -> i64
%583 = llvm.load %396 : !llvm.ptr -> i64
%584 = llvm.load %573 : !llvm.ptr -> i64
%585 = arith.subi %183, %584 : i64
%586 = arith.muli %583, %585 : i64
%587 = arith.addi %569, %586 : i64
%588 = llvm.getelementptr %549[%587] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %576, %588 : i64, !llvm.ptr
%589 = llvm.load %573 : !llvm.ptr -> i64
%590 = arith.constant 1 : i32
%592 = arith.extsi %590 : i32 to i64
%591 = arith.addi %589, %592 : i64
llvm.store %591, %573 : i64, !llvm.ptr
cf.br ^bb102
^bb104:
%593 = llvm.load %557 : !llvm.ptr -> i64
%594 = arith.constant 1 : i32
%596 = arith.extsi %594 : i32 to i64
%595 = arith.addi %593, %596 : i64
llvm.store %595, %557 : i64, !llvm.ptr
cf.br ^bb99
^bb101:
%597 = llvm.load %396 : !llvm.ptr -> i64
llvm.store %597, %557 : i64, !llvm.ptr
cf.br ^bb105
^bb105:
%598 = llvm.load %557 : !llvm.ptr -> i64
%599 = arith.cmpi slt, %598, %185 : i64
cf.cond_br %599, ^bb106, ^bb107
^bb106:
%601 = llvm.load %396 : !llvm.ptr -> i64
%602 = arith.muli %601, %185 : i64
%603 = llvm.load %557 : !llvm.ptr -> i64
%604 = arith.addi %602, %603 : i64
%605 = llvm.getelementptr %226[%604] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%600 = llvm.load %605 : !llvm.ptr -> i64
%606 = llvm.load %433 : !llvm.ptr -> i64
%607 = llvm.load %557 : !llvm.ptr -> i64
%608 = arith.muli %606, %607 : i64
%609 = arith.constant 0 : i32
%610 = arith.extsi %609 : i32 to i64
%611 = llvm.mlir.constant(1 : i64) : i64
%612 = llvm.alloca %611 x i64 : (i64) -> !llvm.ptr
llvm.store %610, %612 : i64, !llvm.ptr
cf.br ^bb108
^bb108:
%613 = llvm.load %612 : !llvm.ptr -> i64
%614 = llvm.load %433 : !llvm.ptr -> i64
%615 = arith.cmpi slt, %613, %614 : i64
cf.cond_br %615, ^bb109, ^bb110
^bb109:
%618 = llvm.load %433 : !llvm.ptr -> i64
%619 = arith.muli %618, %185 : i64
%620 = llvm.load %612 : !llvm.ptr -> i64
%621 = arith.addi %619, %620 : i64
%622 = llvm.getelementptr %219[%621] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%617 = llvm.load %622 : !llvm.ptr -> i64
%616 = func.call @line_len(%600, %617) : (i64, i64) -> i64
%623 = llvm.load %396 : !llvm.ptr -> i64
%624 = llvm.load %612 : !llvm.ptr -> i64
%625 = arith.subi %183, %624 : i64
%626 = arith.muli %623, %625 : i64
%627 = arith.addi %608, %626 : i64
%628 = llvm.getelementptr %549[%627] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %616, %628 : i64, !llvm.ptr
%629 = llvm.load %612 : !llvm.ptr -> i64
%630 = arith.constant 1 : i32
%632 = arith.extsi %630 : i32 to i64
%631 = arith.addi %629, %632 : i64
llvm.store %631, %612 : i64, !llvm.ptr
cf.br ^bb108
^bb110:
%633 = llvm.load %557 : !llvm.ptr -> i64
%634 = arith.constant 1 : i32
%636 = arith.extsi %634 : i32 to i64
%635 = arith.addi %633, %636 : i64
llvm.store %635, %557 : i64, !llvm.ptr
cf.br ^bb105
^bb107:
%637 = arith.constant 0 : i32
%638 = arith.extsi %637 : i32 to i64
%639 = llvm.mlir.constant(1 : i64) : i64
%640 = llvm.alloca %639 x i64 : (i64) -> !llvm.ptr
llvm.store %638, %640 : i64, !llvm.ptr
%641 = arith.constant 4 : i32
%642 = llvm.load %396 : !llvm.ptr -> i64
%644 = arith.constant 0 : i64
%643 = arith.subi %644, %642 : i64
%645 = arith.muli %643, %183 : i64
%647 = arith.extsi %641 : i32 to i64
%646 = arith.muli %647, %645 : i64
%648 = arith.constant 2 : i32
%650 = arith.extsi %648 : i32 to i64
%649 = arith.muli %650, %183 : i64
%651 = llvm.load %433 : !llvm.ptr -> i64
%652 = llvm.load %396 : !llvm.ptr -> i64
%653 = arith.subi %651, %652 : i64
%654 = arith.muli %649, %653 : i64
%655 = arith.subi %646, %654 : i64
%656 = arith.constant 4 : i32
%657 = arith.constant 1 : i32
%659 = arith.extsi %657 : i32 to i64
%658 = arith.subi %547, %659 : i64
%661 = arith.extsi %656 : i32 to i64
%660 = arith.muli %661, %658 : i64
%662 = arith.addi %660, %655 : i64
%663 = arith.sitofp %662 : i64 to f64
%664 = llvm.mlir.constant(1 : i64) : i64
%665 = llvm.alloca %664 x f64 : (i64) -> !llvm.ptr
llvm.store %663, %665 : f64, !llvm.ptr
%666 = arith.constant 0.0 : f32
%667 = arith.extf %666 : f32 to f64
%668 = llvm.mlir.constant(1 : i64) : i64
%669 = llvm.alloca %668 x f64 : (i64) -> !llvm.ptr
llvm.store %667, %669 : f64, !llvm.ptr
%670 = arith.constant 1 : i32
%672 = arith.extsi %670 : i32 to i64
%671 = arith.subi %547, %672 : i64
%673 = llvm.mlir.constant(1 : i64) : i64
%674 = llvm.alloca %673 x i64 : (i64) -> !llvm.ptr
llvm.store %671, %674 : i64, !llvm.ptr
cf.br ^bb111
^bb111:
%675 = llvm.load %674 : !llvm.ptr -> i64
%676 = arith.constant 0 : i32
%678 = arith.extsi %676 : i32 to i64
%677 = arith.cmpi sge, %675, %678 : i64
cf.cond_br %677, ^bb112, ^bb113
^bb112:
%680 = llvm.load %674 : !llvm.ptr -> i64
%681 = llvm.getelementptr %549[%680] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%679 = llvm.load %681 : !llvm.ptr -> i64
%682 = arith.constant 0 : i32
%684 = arith.extsi %682 : i32 to i64
%683 = arith.cmpi sgt, %679, %684 : i64
cf.cond_br %683, ^bb114, ^bb115
^bb114:
%685 = llvm.load %640 : !llvm.ptr -> i64
%686 = arith.subi %194, %685 : i64
%687 = arith.subi %686, %679 : i64
%688 = llvm.load %669 : !llvm.ptr -> f64
%690 = llvm.load %640 : !llvm.ptr -> i64
%691 = llvm.getelementptr %195[%690] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%689 = llvm.load %691 : !llvm.ptr -> f64
%693 = llvm.getelementptr %201[%687] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%692 = llvm.load %693 : !llvm.ptr -> f64
%694 = arith.mulf %689, %692 : f64
%695 = llvm.load %665 : !llvm.ptr -> f64
%697 = llvm.getelementptr %213[%679] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%696 = llvm.load %697 : !llvm.ptr -> f64
%698 = arith.mulf %695, %696 : f64
%699 = arith.mulf %694, %698 : f64
%700 = arith.addf %688, %699 : f64
llvm.store %700, %669 : f64, !llvm.ptr
%701 = llvm.load %640 : !llvm.ptr -> i64
%702 = arith.addi %701, %679 : i64
llvm.store %702, %640 : i64, !llvm.ptr
cf.br ^bb116
^bb115:
cf.br ^bb116
^bb116:
%703 = llvm.load %665 : !llvm.ptr -> f64
%704 = arith.constant 4.0 : f32
%706 = arith.extf %704 : f32 to f64
%705 = arith.subf %703, %706 : f64
llvm.store %705, %665 : f64, !llvm.ptr
%707 = llvm.load %674 : !llvm.ptr -> i64
%708 = arith.constant 1 : i32
%710 = arith.extsi %708 : i32 to i64
%709 = arith.subi %707, %710 : i64
llvm.store %709, %674 : i64, !llvm.ptr
cf.br ^bb111
^bb113:
%711 = llvm.load %425 : !llvm.ptr -> f64
%712 = llvm.load %456 : !llvm.ptr -> f64
%713 = llvm.load %669 : !llvm.ptr -> f64
%714 = arith.mulf %712, %713 : f64
%715 = arith.addf %711, %714 : f64
llvm.store %715, %425 : f64, !llvm.ptr
func.call @free(%549) : (!llvm.ptr) -> ()
cf.br ^bb98
^bb97:
cf.br ^bb98
^bb98:
cf.br ^bb92
^bb92:
cf.br ^bb86
^bb85:
cf.br ^bb86
^bb86:
cf.br ^bb83
^bb82:
cf.br ^bb83
^bb83:
%717 = llvm.load %433 : !llvm.ptr -> i64
%718 = arith.constant 1 : i32
%720 = arith.extsi %718 : i32 to i64
%719 = arith.addi %717, %720 : i64
llvm.store %719, %433 : i64, !llvm.ptr
cf.br ^bb78
^bb80:
%721 = llvm.load %396 : !llvm.ptr -> i64
%722 = arith.constant 1 : i32
%724 = arith.extsi %722 : i32 to i64
%723 = arith.addi %721, %724 : i64
llvm.store %723, %396 : i64, !llvm.ptr
cf.br ^bb75
^bb77:
%725 = llvm.load %425 : !llvm.ptr -> f64
%726 = arith.constant 8.0 : f32
%728 = arith.extf %726 : f32 to f64
%727 = arith.divf %725, %728 : f64
%729 = llvm.mlir.addressof @str_0 : !llvm.ptr
%730 = llvm.call @printf(%729, %727) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, f64) -> i32
func.call @free(%195) : (!llvm.ptr) -> ()
func.call @free(%201) : (!llvm.ptr) -> ()
func.call @free(%207) : (!llvm.ptr) -> ()
func.call @free(%213) : (!llvm.ptr) -> ()
func.call @free(%219) : (!llvm.ptr) -> ()
func.call @free(%226) : (!llvm.ptr) -> ()
%737 = arith.constant 0 : i32
func.return %737 : i32
}
}