Problem 630
Generate 2500 pseudo-random points, form unique lines through pairs, compute S(L) = M*(M-1) - sum c*(c-1) over parallel classes.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n^2) | ? |
| Space complexity | O(n^2) | ? |
| Approach | Flow solution | Not curated |
| Verdict | Unknown |
Flow source
# Project Euler 630: Crossed Lines
# Generate 2500 pseudo-random points, form unique lines through pairs,
# compute S(L) = M*(M-1) - sum c*(c-1) over parallel classes.
import euler.nt { isqrt, gcd }
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
const A_BITS: i64 = 11
const B_BITS: i64 = 12
const D_BITS: i64 = 23
const B_OFFSET: i64 = 1999
const D_OFFSET: i64 = 4000000
function main() -> i32 {
let npts: i64 = 2500
# Generate points
let px: ptr<i64> = calloc(npts, 8)
let py: ptr<i64> = calloc(npts, 8)
let s: i64 = 290797
let mut t_prev: i64 = s
for k in 0..npts {
# T_{2k}: s = s^2 mod 50515093
t_prev = (t_prev * t_prev) % 50515093
let t1: i64 = (t_prev % 2000) - 1000
# T_{2k+1}: s = s^2 mod 50515093
t_prev = (t_prev * t_prev) % 50515093
let t2: i64 = (t_prev % 2000) - 1000
px[k] = t1
py[k] = t2
}
# Assert first 3 points
if px[0] != 527 || py[0] != 144 { printf("FAIL p0\n"); return 1 }
if px[1] != -488 || py[1] != 732 { printf("FAIL p1\n"); return 1 }
if px[2] != -454 || py[2] != -947 { printf("FAIL p2\n"); return 1 }
# Generate line codes for all pairs
# npts*(npts-1)/2 = 2500*2499/2 = 3123750 codes max
let max_codes: i64 = npts * (npts - 1) / 2
let codes: ptr<i64> = calloc(max_codes, 8)
let mut ncodes: i64 = 0
for i in 0..(npts - 1) {
let x1: i64 = px[i]
let y1: i64 = py[i]
for j in (i + 1)..npts {
let x2: i64 = px[j]
let y2: i64 = py[j]
let dx: i64 = x2 - x1
let dy: i64 = y2 - y1
if dx == 0 && dy == 0 { continue }
let mut adx: i64 = dx
if adx < 0 { adx = -adx }
let mut ady: i64 = dy
if ady < 0 { ady = -ady }
let g: i64 = gcd(adx, ady)
let rdx: i64 = dx / g
let rdy: i64 = dy / g
# Normal (A,B) = (rdy, -rdx)
let mut A: i64 = rdy
let mut B: i64 = -rdx
if A < 0 || (A == 0 && B < 0) {
A = -A
B = -B
}
let normal_id: i64 = (A << B_BITS) | (B + B_OFFSET)
let D: i64 = A * x1 + B * y1
let code: i64 = (normal_id << D_BITS) | (D + D_OFFSET)
codes[ncodes] = code
ncodes = ncodes + 1
}
}
# Sort codes using manual quicksort
# Use iterative quicksort with stack
let stack_lo: ptr<i64> = calloc(ncodes, 8)
let stack_hi: ptr<i64> = calloc(ncodes, 8)
let mut sp: i64 = 0
stack_lo[0] = 0
stack_hi[0] = ncodes - 1
sp = 1
while sp > 0 {
sp = sp - 1
let lo: i64 = stack_lo[sp]
let hi: i64 = stack_hi[sp]
if lo >= hi { continue }
# Partition with last element as pivot
let pivot: i64 = codes[hi]
let mut i: i64 = lo - 1
for j in lo..hi {
if codes[j] <= pivot {
i = i + 1
let tmp: i64 = codes[i]
codes[i] = codes[j]
codes[j] = tmp
}
}
i = i + 1
let tmp2: i64 = codes[i]
codes[i] = codes[hi]
codes[hi] = tmp2
stack_lo[sp] = lo
stack_hi[sp] = i - 1
sp = sp + 1
stack_lo[sp] = i + 1
stack_hi[sp] = hi
sp = sp + 1
}
free(stack_lo)
free(stack_hi)
# Count unique lines and parallel classes
let mut M: i64 = 0
let mut sum_parallel: i64 = 0
let mut prev_code: i64 = -1
let mut prev_normal: i64 = -1
let mut c: i64 = 0
for i in 0..ncodes {
let code: i64 = codes[i]
if code == prev_code { continue }
M = M + 1
let normal: i64 = code >> D_BITS
if normal != prev_normal {
if prev_normal != -1 {
sum_parallel = sum_parallel + c * (c - 1)
}
prev_normal = normal
c = 1
} else {
c = c + 1
}
prev_code = code
}
if prev_normal != -1 {
sum_parallel = sum_parallel + c * (c - 1)
}
let S: i64 = M * (M - 1) - sum_parallel
printf("%lld\n", S)
free(codes)
free(py)
free(px)
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);
int32_t main(void);
static const int64_t A_BITS = 11;
static const int64_t B_BITS = 12;
static const int64_t D_BITS = 23;
static const int64_t B_OFFSET = 1999;
static const int64_t D_OFFSET = 4000000;
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;
}
int32_t main(void) {
int64_t npts = 2500;
int64_t* px = (int64_t*)(calloc(npts, 8));
int64_t* py = (int64_t*)(calloc(npts, 8));
int64_t s = 290797;
int64_t t_prev = s;
int32_t __flow_step_1 = 1;
for (int32_t k = 0; (0 <= npts) ? k < npts : k > npts; k += (0 <= npts) ? 1 : -1) {
t_prev = FLOW_CHECKED_MOD(((t_prev * t_prev)), (50515093));
int64_t t1 = (FLOW_CHECKED_MOD((t_prev), (2000)) - 1000);
t_prev = FLOW_CHECKED_MOD(((t_prev * t_prev)), (50515093));
int64_t t2 = (FLOW_CHECKED_MOD((t_prev), (2000)) - 1000);
px[k] = t1;
py[k] = t2;
}
if ((px[0] != 527 || py[0] != 144)) {
printf("FAIL p0\n");
return 1;
}
if ((px[1] != (-488) || py[1] != 732)) {
printf("FAIL p1\n");
return 1;
}
if ((px[2] != (-454) || py[2] != (-947))) {
printf("FAIL p2\n");
return 1;
}
int64_t max_codes = FLOW_CHECKED_DIV(((npts * (npts - 1))), (2));
int64_t* codes = (int64_t*)(calloc(max_codes, 8));
int64_t ncodes = 0;
int32_t __flow_step_2 = 1;
for (int32_t i = 0; (0 <= (npts - 1)) ? i < (npts - 1) : i > (npts - 1); i += (0 <= (npts - 1)) ? 1 : -1) {
int64_t x1 = px[i];
int64_t y1 = py[i];
int32_t __flow_step_3 = 1;
for (int32_t j = (i + 1); ((i + 1) <= npts) ? j < npts : j > npts; j += ((i + 1) <= npts) ? 1 : -1) {
int64_t x2 = px[j];
int64_t y2 = py[j];
int64_t dx = (x2 - x1);
int64_t dy = (y2 - y1);
if ((dx == 0 && dy == 0)) {
continue;
}
int64_t adx = dx;
if (adx < 0) {
adx = (-adx);
}
int64_t ady = dy;
if (ady < 0) {
ady = (-ady);
}
int64_t g = gcd_i64_i64(adx, ady);
int64_t rdx = FLOW_CHECKED_DIV((dx), (g));
int64_t rdy = FLOW_CHECKED_DIV((dy), (g));
int64_t A = rdy;
int64_t B = (-rdx);
if ((A < 0 || (A == 0 && B < 0))) {
A = (-A);
B = (-B);
}
int64_t normal_id = (FLOW_CHECKED_SHL((A), (B_BITS)) | (B + B_OFFSET));
int64_t D = ((A * x1) + (B * y1));
int64_t code = (FLOW_CHECKED_SHL((normal_id), (D_BITS)) | (D + D_OFFSET));
codes[ncodes] = code;
ncodes = (ncodes + 1);
}
}
int64_t* stack_lo = (int64_t*)(calloc(ncodes, 8));
int64_t* stack_hi = (int64_t*)(calloc(ncodes, 8));
int64_t sp = 0;
stack_lo[0] = 0;
stack_hi[0] = (ncodes - 1);
sp = 1;
while (sp > 0) {
sp = (sp - 1);
int64_t lo = stack_lo[sp];
int64_t hi = stack_hi[sp];
if (lo >= hi) {
continue;
}
int64_t pivot = codes[hi];
int64_t i = (lo - 1);
int32_t __flow_step_4 = 1;
for (int32_t j = lo; (lo <= hi) ? j < hi : j > hi; j += (lo <= hi) ? 1 : -1) {
if (codes[j] <= pivot) {
i = (i + 1);
int64_t tmp = codes[i];
codes[i] = codes[j];
codes[j] = tmp;
}
}
i = (i + 1);
int64_t tmp2 = codes[i];
codes[i] = codes[hi];
codes[hi] = tmp2;
stack_lo[sp] = lo;
stack_hi[sp] = (i - 1);
sp = (sp + 1);
stack_lo[sp] = (i + 1);
stack_hi[sp] = hi;
sp = (sp + 1);
}
free(stack_lo);
free(stack_hi);
int64_t M = 0;
int64_t sum_parallel = 0;
int64_t prev_code = (-1);
int64_t prev_normal = (-1);
int64_t c = 0;
int32_t __flow_step_5 = 1;
for (int32_t i = 0; (0 <= ncodes) ? i < ncodes : i > ncodes; i += (0 <= ncodes) ? 1 : -1) {
int64_t code = codes[i];
if (code == prev_code) {
continue;
}
M = (M + 1);
int64_t normal = FLOW_CHECKED_SHR((code), (D_BITS));
if (normal != prev_normal) {
if (prev_normal != (-1)) {
sum_parallel = (sum_parallel + (c * (c - 1)));
}
prev_normal = normal;
c = 1;
} else {
c = (c + 1);
}
prev_code = code;
}
if (prev_normal != (-1)) {
sum_parallel = (sum_parallel + (c * (c - 1)));
}
int64_t S = ((M * (M - 1)) - sum_parallel);
printf("%lld\n", S);
free(codes);
free(py);
free(px);
return 0;
}
Generated MLIR
module {
llvm.func @printf(!llvm.ptr, ...) -> i32
llvm.mlir.global internal constant @str_0("FAIL p0\n\00") {addr_space = 0 : i32} : !llvm.array<9 x i8>
llvm.mlir.global internal constant @str_1("FAIL p1\n\00") {addr_space = 0 : i32} : !llvm.array<9 x i8>
llvm.mlir.global internal constant @str_2("FAIL p2\n\00") {addr_space = 0 : i32} : !llvm.array<9 x i8>
llvm.mlir.global internal constant @str_3("%lld\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) -> ()
// Constant: A_BITS
llvm.mlir.global internal constant @A_BITS(11 : i64) : i64
// Constant: B_BITS
llvm.mlir.global internal constant @B_BITS(12 : i64) : i64
// Constant: D_BITS
llvm.mlir.global internal constant @D_BITS(23 : i64) : i64
// Constant: B_OFFSET
llvm.mlir.global internal constant @B_OFFSET(1999 : i64) : i64
// Constant: D_OFFSET
llvm.mlir.global internal constant @D_OFFSET(4000000 : i64) : i64
func.func @main() -> i32 {
%175 = arith.constant 2500 : i32
%176 = arith.extsi %175 : i32 to i64
%178 = arith.constant 8 : i32
%179 = arith.extsi %178 : i32 to i64
%177 = func.call @calloc(%176, %179) : (i64, i64) -> !llvm.ptr
%181 = arith.constant 8 : i32
%182 = arith.extsi %181 : i32 to i64
%180 = func.call @calloc(%176, %182) : (i64, i64) -> !llvm.ptr
%183 = arith.constant 290797 : i32
%184 = arith.extsi %183 : i32 to i64
%185 = llvm.mlir.constant(1 : i64) : i64
%186 = llvm.alloca %185 x i64 : (i64) -> !llvm.ptr
llvm.store %184, %186 : i64, !llvm.ptr
%187 = arith.constant 0 : i32
%188 = arith.index_cast %187 : i32 to index
%189 = arith.index_cast %176 : i32 to index
%191 = arith.constant 1 : index
%192 = arith.constant -1 : index
%193 = arith.cmpi sle, %188, %189 : index
%190 = arith.select %193, %191, %192 : index
cf.br ^bb42(%188 : index)
^bb42(%194: index):
%195 = arith.cmpi slt, %194, %189 : index
%196 = arith.cmpi sgt, %194, %189 : index
%197 = arith.select %193, %195, %196 : i1
cf.cond_br %197, ^bb43(%194 : index), ^bb44(%194 : index)
^bb43(%198: index):
%199 = llvm.load %186 : !llvm.ptr -> i64
%200 = llvm.load %186 : !llvm.ptr -> i64
%201 = arith.muli %199, %200 : i64
%202 = arith.constant 50515093 : i32
%204 = arith.extsi %202 : i32 to i64
%203 = arith.remsi %201, %204 : i64
llvm.store %203, %186 : i64, !llvm.ptr
%205 = llvm.load %186 : !llvm.ptr -> i64
%206 = arith.constant 2000 : i32
%208 = arith.extsi %206 : i32 to i64
%207 = arith.remsi %205, %208 : i64
%209 = arith.constant 1000 : i32
%211 = arith.extsi %209 : i32 to i64
%210 = arith.subi %207, %211 : i64
%212 = llvm.load %186 : !llvm.ptr -> i64
%213 = llvm.load %186 : !llvm.ptr -> i64
%214 = arith.muli %212, %213 : i64
%215 = arith.constant 50515093 : i32
%217 = arith.extsi %215 : i32 to i64
%216 = arith.remsi %214, %217 : i64
llvm.store %216, %186 : i64, !llvm.ptr
%218 = llvm.load %186 : !llvm.ptr -> i64
%219 = arith.constant 2000 : i32
%221 = arith.extsi %219 : i32 to i64
%220 = arith.remsi %218, %221 : i64
%222 = arith.constant 1000 : i32
%224 = arith.extsi %222 : i32 to i64
%223 = arith.subi %220, %224 : i64
%225 = arith.index_cast %198 : index to i64
%226 = llvm.getelementptr %177[%225] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %210, %226 : i64, !llvm.ptr
%227 = arith.index_cast %198 : index to i64
%228 = llvm.getelementptr %180[%227] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %223, %228 : i64, !llvm.ptr
%229 = arith.addi %198, %190 : index
cf.br ^bb42(%229 : index)
^bb44(%230: index):
%232 = arith.constant 0 : i32
%233 = arith.extsi %232 : i32 to i64
%234 = llvm.getelementptr %177[%233] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%231 = llvm.load %234 : !llvm.ptr -> i64
%235 = arith.constant 527 : i32
%237 = arith.extsi %235 : i32 to i64
%236 = arith.cmpi ne, %231, %237 : i64
%238 = scf.if %236 -> (i1) {
%239 = arith.constant true
scf.yield %239 : i1
} else {
%241 = arith.constant 0 : i32
%242 = arith.extsi %241 : i32 to i64
%243 = llvm.getelementptr %180[%242] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%240 = llvm.load %243 : !llvm.ptr -> i64
%244 = arith.constant 144 : i32
%246 = arith.extsi %244 : i32 to i64
%245 = arith.cmpi ne, %240, %246 : i64
scf.yield %245 : i1
}
cf.cond_br %238, ^bb45, ^bb46
^bb45:
%247 = llvm.mlir.addressof @str_0 : !llvm.ptr
%248 = llvm.call @printf(%247) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr) -> i32
%249 = arith.constant 1 : i32
func.return %249 : i32
^bb46:
cf.br ^bb47
^bb47:
%251 = arith.constant 1 : i32
%252 = arith.extsi %251 : i32 to i64
%253 = llvm.getelementptr %177[%252] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%250 = llvm.load %253 : !llvm.ptr -> i64
%254 = arith.constant 488 : i32
%256 = arith.constant 0 : i32
%255 = arith.subi %256, %254 : i32
%258 = arith.extsi %255 : i32 to i64
%257 = arith.cmpi ne, %250, %258 : i64
%259 = scf.if %257 -> (i1) {
%260 = arith.constant true
scf.yield %260 : i1
} else {
%262 = arith.constant 1 : i32
%263 = arith.extsi %262 : i32 to i64
%264 = llvm.getelementptr %180[%263] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%261 = llvm.load %264 : !llvm.ptr -> i64
%265 = arith.constant 732 : i32
%267 = arith.extsi %265 : i32 to i64
%266 = arith.cmpi ne, %261, %267 : i64
scf.yield %266 : i1
}
cf.cond_br %259, ^bb48, ^bb49
^bb48:
%268 = llvm.mlir.addressof @str_1 : !llvm.ptr
%269 = llvm.call @printf(%268) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr) -> i32
%270 = arith.constant 1 : i32
func.return %270 : i32
^bb49:
cf.br ^bb50
^bb50:
%272 = arith.constant 2 : i32
%273 = arith.extsi %272 : i32 to i64
%274 = llvm.getelementptr %177[%273] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%271 = llvm.load %274 : !llvm.ptr -> i64
%275 = arith.constant 454 : i32
%277 = arith.constant 0 : i32
%276 = arith.subi %277, %275 : i32
%279 = arith.extsi %276 : i32 to i64
%278 = arith.cmpi ne, %271, %279 : i64
%280 = scf.if %278 -> (i1) {
%281 = arith.constant true
scf.yield %281 : i1
} else {
%283 = arith.constant 2 : i32
%284 = arith.extsi %283 : i32 to i64
%285 = llvm.getelementptr %180[%284] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%282 = llvm.load %285 : !llvm.ptr -> i64
%286 = arith.constant 947 : i32
%288 = arith.constant 0 : i32
%287 = arith.subi %288, %286 : i32
%290 = arith.extsi %287 : i32 to i64
%289 = arith.cmpi ne, %282, %290 : i64
scf.yield %289 : i1
}
cf.cond_br %280, ^bb51, ^bb52
^bb51:
%291 = llvm.mlir.addressof @str_2 : !llvm.ptr
%292 = llvm.call @printf(%291) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr) -> i32
%293 = arith.constant 1 : i32
func.return %293 : i32
^bb52:
cf.br ^bb53
^bb53:
%294 = arith.constant 1 : i32
%296 = arith.extsi %294 : i32 to i64
%295 = arith.subi %176, %296 : i64
%297 = arith.muli %176, %295 : i64
%298 = arith.constant 2 : i32
%300 = arith.extsi %298 : i32 to i64
%299 = arith.divsi %297, %300 : i64
%302 = arith.constant 8 : i32
%303 = arith.extsi %302 : i32 to i64
%301 = func.call @calloc(%299, %303) : (i64, i64) -> !llvm.ptr
%304 = arith.constant 0 : i32
%305 = arith.extsi %304 : i32 to i64
%306 = llvm.mlir.constant(1 : i64) : i64
%307 = llvm.alloca %306 x i64 : (i64) -> !llvm.ptr
llvm.store %305, %307 : i64, !llvm.ptr
%308 = arith.constant 0 : i32
%309 = arith.constant 1 : i32
%311 = arith.extsi %309 : i32 to i64
%310 = arith.subi %176, %311 : i64
%312 = arith.index_cast %308 : i32 to index
%313 = arith.index_cast %310 : i32 to index
%315 = arith.constant 1 : index
%316 = arith.constant -1 : index
%317 = arith.cmpi sle, %312, %313 : index
%314 = arith.select %317, %315, %316 : index
cf.br ^bb54(%312 : index)
^bb54(%318: index):
%319 = arith.cmpi slt, %318, %313 : index
%320 = arith.cmpi sgt, %318, %313 : index
%321 = arith.select %317, %319, %320 : i1
cf.cond_br %321, ^bb55(%318 : index), ^bb56(%318 : index)
^bb55(%322: index):
%324 = arith.index_cast %322 : index to i64
%325 = llvm.getelementptr %177[%324] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%323 = llvm.load %325 : !llvm.ptr -> i64
%327 = arith.index_cast %322 : index to i64
%328 = llvm.getelementptr %180[%327] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%326 = llvm.load %328 : !llvm.ptr -> i64
%329 = arith.constant 1 : i32
%331 = arith.index_cast %322 : index to i32
%330 = arith.addi %331, %329 : i32
%332 = arith.index_cast %330 : i32 to index
%333 = arith.index_cast %176 : i32 to index
%335 = arith.constant 1 : index
%336 = arith.constant -1 : index
%337 = arith.cmpi sle, %332, %333 : index
%334 = arith.select %337, %335, %336 : index
cf.br ^bb57(%332 : index)
^bb57(%338: index):
%339 = arith.cmpi slt, %338, %333 : index
%340 = arith.cmpi sgt, %338, %333 : index
%341 = arith.select %337, %339, %340 : i1
cf.cond_br %341, ^bb58(%338 : index), ^bb59(%338 : index)
^bb58(%342: index):
%344 = arith.index_cast %342 : index to i64
%345 = llvm.getelementptr %177[%344] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%343 = llvm.load %345 : !llvm.ptr -> i64
%347 = arith.index_cast %342 : index to i64
%348 = llvm.getelementptr %180[%347] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%346 = llvm.load %348 : !llvm.ptr -> i64
%349 = arith.subi %343, %323 : i64
%350 = arith.subi %346, %326 : i64
%351 = arith.constant 0 : i32
%353 = arith.extsi %351 : i32 to i64
%352 = arith.cmpi eq, %349, %353 : i64
%354 = scf.if %352 -> (i1) {
%355 = arith.constant 0 : i32
%357 = arith.extsi %355 : i32 to i64
%356 = arith.cmpi eq, %350, %357 : i64
scf.yield %356 : i1
} else {
%358 = arith.constant false
scf.yield %358 : i1
}
cf.cond_br %354, ^bb60, ^bb61
^bb60:
%359 = arith.addi %342, %334 : index
cf.br ^bb57(%359 : index)
^bb61:
cf.br ^bb62
^bb62:
%360 = llvm.mlir.constant(1 : i64) : i64
%361 = llvm.alloca %360 x i64 : (i64) -> !llvm.ptr
llvm.store %349, %361 : i64, !llvm.ptr
%362 = llvm.load %361 : !llvm.ptr -> i64
%363 = arith.constant 0 : i32
%365 = arith.extsi %363 : i32 to i64
%364 = arith.cmpi slt, %362, %365 : i64
cf.cond_br %364, ^bb63, ^bb64
^bb63:
%366 = llvm.load %361 : !llvm.ptr -> i64
%368 = arith.constant 0 : i64
%367 = arith.subi %368, %366 : i64
llvm.store %367, %361 : i64, !llvm.ptr
cf.br ^bb65
^bb64:
cf.br ^bb65
^bb65:
%369 = llvm.mlir.constant(1 : i64) : i64
%370 = llvm.alloca %369 x i64 : (i64) -> !llvm.ptr
llvm.store %350, %370 : i64, !llvm.ptr
%371 = llvm.load %370 : !llvm.ptr -> i64
%372 = arith.constant 0 : i32
%374 = arith.extsi %372 : i32 to i64
%373 = arith.cmpi slt, %371, %374 : i64
cf.cond_br %373, ^bb66, ^bb67
^bb66:
%375 = llvm.load %370 : !llvm.ptr -> i64
%377 = arith.constant 0 : i64
%376 = arith.subi %377, %375 : i64
llvm.store %376, %370 : i64, !llvm.ptr
cf.br ^bb68
^bb67:
cf.br ^bb68
^bb68:
%379 = llvm.load %361 : !llvm.ptr -> i64
%380 = llvm.load %370 : !llvm.ptr -> i64
%378 = func.call @gcd(%379, %380) : (i64, i64) -> i64
%381 = arith.divsi %349, %378 : i64
%382 = arith.divsi %350, %378 : i64
%383 = llvm.mlir.constant(1 : i64) : i64
%384 = llvm.alloca %383 x i64 : (i64) -> !llvm.ptr
llvm.store %382, %384 : i64, !llvm.ptr
%386 = arith.constant 0 : i64
%385 = arith.subi %386, %381 : i64
%387 = llvm.mlir.constant(1 : i64) : i64
%388 = llvm.alloca %387 x i64 : (i64) -> !llvm.ptr
llvm.store %385, %388 : i64, !llvm.ptr
%389 = llvm.load %384 : !llvm.ptr -> i64
%390 = arith.constant 0 : i32
%392 = arith.extsi %390 : i32 to i64
%391 = arith.cmpi slt, %389, %392 : i64
%393 = scf.if %391 -> (i1) {
%394 = arith.constant true
scf.yield %394 : i1
} else {
%395 = llvm.load %384 : !llvm.ptr -> i64
%396 = arith.constant 0 : i32
%398 = arith.extsi %396 : i32 to i64
%397 = arith.cmpi eq, %395, %398 : i64
%399 = scf.if %397 -> (i1) {
%400 = llvm.load %388 : !llvm.ptr -> i64
%401 = arith.constant 0 : i32
%403 = arith.extsi %401 : i32 to i64
%402 = arith.cmpi slt, %400, %403 : i64
scf.yield %402 : i1
} else {
%404 = arith.constant false
scf.yield %404 : i1
}
scf.yield %399 : i1
}
cf.cond_br %393, ^bb69, ^bb70
^bb69:
%405 = llvm.load %384 : !llvm.ptr -> i64
%407 = arith.constant 0 : i64
%406 = arith.subi %407, %405 : i64
llvm.store %406, %384 : i64, !llvm.ptr
%408 = llvm.load %388 : !llvm.ptr -> i64
%410 = arith.constant 0 : i64
%409 = arith.subi %410, %408 : i64
llvm.store %409, %388 : i64, !llvm.ptr
cf.br ^bb71
^bb70:
cf.br ^bb71
^bb71:
%411 = llvm.load %384 : !llvm.ptr -> i64
%412 = llvm.mlir.addressof @B_BITS : !llvm.ptr
%413 = llvm.load %412 : !llvm.ptr -> i64
%414 = arith.shli %411, %413 : i64
%415 = llvm.load %388 : !llvm.ptr -> i64
%416 = llvm.mlir.addressof @B_OFFSET : !llvm.ptr
%417 = llvm.load %416 : !llvm.ptr -> i64
%418 = arith.addi %415, %417 : i64
%419 = arith.ori %414, %418 : i64
%420 = llvm.load %384 : !llvm.ptr -> i64
%421 = arith.muli %420, %323 : i64
%422 = llvm.load %388 : !llvm.ptr -> i64
%423 = arith.muli %422, %326 : i64
%424 = arith.addi %421, %423 : i64
%425 = llvm.mlir.addressof @D_BITS : !llvm.ptr
%426 = llvm.load %425 : !llvm.ptr -> i64
%427 = arith.shli %419, %426 : i64
%428 = llvm.mlir.addressof @D_OFFSET : !llvm.ptr
%429 = llvm.load %428 : !llvm.ptr -> i64
%430 = arith.addi %424, %429 : i64
%431 = arith.ori %427, %430 : i64
%432 = llvm.load %307 : !llvm.ptr -> i64
%433 = llvm.getelementptr %301[%432] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %431, %433 : i64, !llvm.ptr
%434 = llvm.load %307 : !llvm.ptr -> i64
%435 = arith.constant 1 : i32
%437 = arith.extsi %435 : i32 to i64
%436 = arith.addi %434, %437 : i64
llvm.store %436, %307 : i64, !llvm.ptr
%438 = arith.addi %342, %334 : index
cf.br ^bb57(%438 : index)
^bb59(%439: index):
%440 = arith.addi %322, %314 : index
cf.br ^bb54(%440 : index)
^bb56(%441: index):
%443 = llvm.load %307 : !llvm.ptr -> i64
%444 = arith.constant 8 : i32
%445 = arith.extsi %444 : i32 to i64
%442 = func.call @calloc(%443, %445) : (i64, i64) -> !llvm.ptr
%447 = llvm.load %307 : !llvm.ptr -> i64
%448 = arith.constant 8 : i32
%449 = arith.extsi %448 : i32 to i64
%446 = func.call @calloc(%447, %449) : (i64, i64) -> !llvm.ptr
%450 = arith.constant 0 : i32
%451 = arith.extsi %450 : i32 to i64
%452 = llvm.mlir.constant(1 : i64) : i64
%453 = llvm.alloca %452 x i64 : (i64) -> !llvm.ptr
llvm.store %451, %453 : i64, !llvm.ptr
%454 = arith.constant 0 : i32
%455 = arith.constant 0 : i32
%456 = arith.extsi %454 : i32 to i64
%457 = arith.extsi %455 : i32 to i64
%458 = llvm.getelementptr %442[%457] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %456, %458 : i64, !llvm.ptr
%459 = llvm.load %307 : !llvm.ptr -> i64
%460 = arith.constant 1 : i32
%462 = arith.extsi %460 : i32 to i64
%461 = arith.subi %459, %462 : i64
%463 = arith.constant 0 : i32
%464 = arith.extsi %463 : i32 to i64
%465 = llvm.getelementptr %446[%464] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %461, %465 : i64, !llvm.ptr
%466 = arith.constant 1 : i32
%467 = arith.extsi %466 : i32 to i64
llvm.store %467, %453 : i64, !llvm.ptr
cf.br ^bb72
^bb72:
%468 = llvm.load %453 : !llvm.ptr -> i64
%469 = arith.constant 0 : i32
%471 = arith.extsi %469 : i32 to i64
%470 = arith.cmpi sgt, %468, %471 : i64
cf.cond_br %470, ^bb73, ^bb74
^bb73:
%472 = llvm.load %453 : !llvm.ptr -> i64
%473 = arith.constant 1 : i32
%475 = arith.extsi %473 : i32 to i64
%474 = arith.subi %472, %475 : i64
llvm.store %474, %453 : i64, !llvm.ptr
%477 = llvm.load %453 : !llvm.ptr -> i64
%478 = llvm.getelementptr %442[%477] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%476 = llvm.load %478 : !llvm.ptr -> i64
%480 = llvm.load %453 : !llvm.ptr -> i64
%481 = llvm.getelementptr %446[%480] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%479 = llvm.load %481 : !llvm.ptr -> i64
%482 = arith.cmpi sge, %476, %479 : i64
cf.cond_br %482, ^bb75, ^bb76
^bb75:
cf.br ^bb72
^bb76:
cf.br ^bb77
^bb77:
%484 = llvm.getelementptr %301[%479] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%483 = llvm.load %484 : !llvm.ptr -> i64
%485 = arith.constant 1 : i32
%487 = arith.extsi %485 : i32 to i64
%486 = arith.subi %476, %487 : i64
%488 = llvm.mlir.constant(1 : i64) : i64
%489 = llvm.alloca %488 x i64 : (i64) -> !llvm.ptr
llvm.store %486, %489 : i64, !llvm.ptr
%490 = arith.index_cast %476 : i32 to index
%491 = arith.index_cast %479 : i32 to index
%493 = arith.constant 1 : index
%494 = arith.constant -1 : index
%495 = arith.cmpi sle, %490, %491 : index
%492 = arith.select %495, %493, %494 : index
cf.br ^bb78(%490 : index)
^bb78(%496: index):
%497 = arith.cmpi slt, %496, %491 : index
%498 = arith.cmpi sgt, %496, %491 : index
%499 = arith.select %495, %497, %498 : i1
cf.cond_br %499, ^bb79(%496 : index), ^bb80(%496 : index)
^bb79(%500: index):
%502 = arith.index_cast %500 : index to i64
%503 = llvm.getelementptr %301[%502] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%501 = llvm.load %503 : !llvm.ptr -> i64
%504 = arith.cmpi sle, %501, %483 : i64
cf.cond_br %504, ^bb81, ^bb82
^bb81:
%505 = llvm.load %489 : !llvm.ptr -> i64
%506 = arith.constant 1 : i32
%508 = arith.extsi %506 : i32 to i64
%507 = arith.addi %505, %508 : i64
llvm.store %507, %489 : i64, !llvm.ptr
%510 = llvm.load %489 : !llvm.ptr -> i64
%511 = llvm.getelementptr %301[%510] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%509 = llvm.load %511 : !llvm.ptr -> i64
%513 = arith.index_cast %500 : index to i64
%514 = llvm.getelementptr %301[%513] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%512 = llvm.load %514 : !llvm.ptr -> i64
%515 = llvm.load %489 : !llvm.ptr -> i64
%516 = llvm.getelementptr %301[%515] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %512, %516 : i64, !llvm.ptr
%517 = arith.index_cast %500 : index to i64
%518 = llvm.getelementptr %301[%517] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %509, %518 : i64, !llvm.ptr
cf.br ^bb83
^bb82:
cf.br ^bb83
^bb83:
%519 = arith.addi %500, %492 : index
cf.br ^bb78(%519 : index)
^bb80(%520: index):
%521 = llvm.load %489 : !llvm.ptr -> i64
%522 = arith.constant 1 : i32
%524 = arith.extsi %522 : i32 to i64
%523 = arith.addi %521, %524 : i64
llvm.store %523, %489 : i64, !llvm.ptr
%526 = llvm.load %489 : !llvm.ptr -> i64
%527 = llvm.getelementptr %301[%526] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%525 = llvm.load %527 : !llvm.ptr -> i64
%529 = llvm.getelementptr %301[%479] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%528 = llvm.load %529 : !llvm.ptr -> i64
%530 = llvm.load %489 : !llvm.ptr -> i64
%531 = llvm.getelementptr %301[%530] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %528, %531 : i64, !llvm.ptr
%532 = llvm.getelementptr %301[%479] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %525, %532 : i64, !llvm.ptr
%533 = llvm.load %453 : !llvm.ptr -> i64
%534 = llvm.getelementptr %442[%533] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %476, %534 : i64, !llvm.ptr
%535 = llvm.load %489 : !llvm.ptr -> i64
%536 = arith.constant 1 : i32
%538 = arith.extsi %536 : i32 to i64
%537 = arith.subi %535, %538 : i64
%539 = llvm.load %453 : !llvm.ptr -> i64
%540 = llvm.getelementptr %446[%539] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %537, %540 : i64, !llvm.ptr
%541 = llvm.load %453 : !llvm.ptr -> i64
%542 = arith.constant 1 : i32
%544 = arith.extsi %542 : i32 to i64
%543 = arith.addi %541, %544 : i64
llvm.store %543, %453 : i64, !llvm.ptr
%545 = llvm.load %489 : !llvm.ptr -> i64
%546 = arith.constant 1 : i32
%548 = arith.extsi %546 : i32 to i64
%547 = arith.addi %545, %548 : i64
%549 = llvm.load %453 : !llvm.ptr -> i64
%550 = llvm.getelementptr %442[%549] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %547, %550 : i64, !llvm.ptr
%551 = llvm.load %453 : !llvm.ptr -> i64
%552 = llvm.getelementptr %446[%551] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %479, %552 : i64, !llvm.ptr
%553 = llvm.load %453 : !llvm.ptr -> i64
%554 = arith.constant 1 : i32
%556 = arith.extsi %554 : i32 to i64
%555 = arith.addi %553, %556 : i64
llvm.store %555, %453 : i64, !llvm.ptr
cf.br ^bb72
^bb74:
func.call @free(%442) : (!llvm.ptr) -> ()
func.call @free(%446) : (!llvm.ptr) -> ()
%559 = arith.constant 0 : i32
%560 = arith.extsi %559 : i32 to i64
%561 = llvm.mlir.constant(1 : i64) : i64
%562 = llvm.alloca %561 x i64 : (i64) -> !llvm.ptr
llvm.store %560, %562 : i64, !llvm.ptr
%563 = arith.constant 0 : i32
%564 = arith.extsi %563 : i32 to i64
%565 = llvm.mlir.constant(1 : i64) : i64
%566 = llvm.alloca %565 x i64 : (i64) -> !llvm.ptr
llvm.store %564, %566 : i64, !llvm.ptr
%567 = arith.constant 1 : i32
%569 = arith.constant 0 : i32
%568 = arith.subi %569, %567 : i32
%570 = arith.extsi %568 : i32 to i64
%571 = llvm.mlir.constant(1 : i64) : i64
%572 = llvm.alloca %571 x i64 : (i64) -> !llvm.ptr
llvm.store %570, %572 : i64, !llvm.ptr
%573 = arith.constant 1 : i32
%575 = arith.constant 0 : i32
%574 = arith.subi %575, %573 : i32
%576 = arith.extsi %574 : i32 to i64
%577 = llvm.mlir.constant(1 : i64) : i64
%578 = llvm.alloca %577 x i64 : (i64) -> !llvm.ptr
llvm.store %576, %578 : i64, !llvm.ptr
%579 = arith.constant 0 : i32
%580 = arith.extsi %579 : i32 to i64
%581 = llvm.mlir.constant(1 : i64) : i64
%582 = llvm.alloca %581 x i64 : (i64) -> !llvm.ptr
llvm.store %580, %582 : i64, !llvm.ptr
%583 = arith.constant 0 : i32
%584 = llvm.load %307 : !llvm.ptr -> i64
%585 = arith.index_cast %583 : i32 to index
%586 = arith.index_cast %584 : i32 to index
%588 = arith.constant 1 : index
%589 = arith.constant -1 : index
%590 = arith.cmpi sle, %585, %586 : index
%587 = arith.select %590, %588, %589 : index
cf.br ^bb84(%585 : index)
^bb84(%591: index):
%592 = arith.cmpi slt, %591, %586 : index
%593 = arith.cmpi sgt, %591, %586 : index
%594 = arith.select %590, %592, %593 : i1
cf.cond_br %594, ^bb85(%591 : index), ^bb86(%591 : index)
^bb85(%595: index):
%597 = arith.index_cast %595 : index to i64
%598 = llvm.getelementptr %301[%597] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%596 = llvm.load %598 : !llvm.ptr -> i64
%599 = llvm.load %572 : !llvm.ptr -> i64
%600 = arith.cmpi eq, %596, %599 : i64
cf.cond_br %600, ^bb87, ^bb88
^bb87:
%601 = arith.addi %595, %587 : index
cf.br ^bb84(%601 : index)
^bb88:
cf.br ^bb89
^bb89:
%602 = llvm.load %562 : !llvm.ptr -> i64
%603 = arith.constant 1 : i32
%605 = arith.extsi %603 : i32 to i64
%604 = arith.addi %602, %605 : i64
llvm.store %604, %562 : i64, !llvm.ptr
%606 = llvm.mlir.addressof @D_BITS : !llvm.ptr
%607 = llvm.load %606 : !llvm.ptr -> i64
%608 = arith.shrsi %596, %607 : i64
%609 = llvm.load %578 : !llvm.ptr -> i64
%610 = arith.cmpi ne, %608, %609 : i64
cf.cond_br %610, ^bb90, ^bb91
^bb90:
%611 = llvm.load %578 : !llvm.ptr -> i64
%612 = arith.constant 1 : i32
%614 = arith.constant 0 : i32
%613 = arith.subi %614, %612 : i32
%616 = arith.extsi %613 : i32 to i64
%615 = arith.cmpi ne, %611, %616 : i64
cf.cond_br %615, ^bb93, ^bb94
^bb93:
%617 = llvm.load %566 : !llvm.ptr -> i64
%618 = llvm.load %582 : !llvm.ptr -> i64
%619 = llvm.load %582 : !llvm.ptr -> i64
%620 = arith.constant 1 : i32
%622 = arith.extsi %620 : i32 to i64
%621 = arith.subi %619, %622 : i64
%623 = arith.muli %618, %621 : i64
%624 = arith.addi %617, %623 : i64
llvm.store %624, %566 : i64, !llvm.ptr
cf.br ^bb95
^bb94:
cf.br ^bb95
^bb95:
llvm.store %608, %578 : i64, !llvm.ptr
%625 = arith.constant 1 : i32
%626 = arith.extsi %625 : i32 to i64
llvm.store %626, %582 : i64, !llvm.ptr
cf.br ^bb92
^bb91:
%627 = llvm.load %582 : !llvm.ptr -> i64
%628 = arith.constant 1 : i32
%630 = arith.extsi %628 : i32 to i64
%629 = arith.addi %627, %630 : i64
llvm.store %629, %582 : i64, !llvm.ptr
cf.br ^bb92
^bb92:
llvm.store %596, %572 : i64, !llvm.ptr
%631 = arith.addi %595, %587 : index
cf.br ^bb84(%631 : index)
^bb86(%632: index):
%633 = llvm.load %578 : !llvm.ptr -> i64
%634 = arith.constant 1 : i32
%636 = arith.constant 0 : i32
%635 = arith.subi %636, %634 : i32
%638 = arith.extsi %635 : i32 to i64
%637 = arith.cmpi ne, %633, %638 : i64
cf.cond_br %637, ^bb96, ^bb97
^bb96:
%639 = llvm.load %566 : !llvm.ptr -> i64
%640 = llvm.load %582 : !llvm.ptr -> i64
%641 = llvm.load %582 : !llvm.ptr -> i64
%642 = arith.constant 1 : i32
%644 = arith.extsi %642 : i32 to i64
%643 = arith.subi %641, %644 : i64
%645 = arith.muli %640, %643 : i64
%646 = arith.addi %639, %645 : i64
llvm.store %646, %566 : i64, !llvm.ptr
cf.br ^bb98
^bb97:
cf.br ^bb98
^bb98:
%647 = llvm.load %562 : !llvm.ptr -> i64
%648 = llvm.load %562 : !llvm.ptr -> i64
%649 = arith.constant 1 : i32
%651 = arith.extsi %649 : i32 to i64
%650 = arith.subi %648, %651 : i64
%652 = arith.muli %647, %650 : i64
%653 = llvm.load %566 : !llvm.ptr -> i64
%654 = arith.subi %652, %653 : i64
%655 = llvm.mlir.addressof @str_3 : !llvm.ptr
%656 = llvm.call @printf(%655, %654) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%301) : (!llvm.ptr) -> ()
func.call @free(%180) : (!llvm.ptr) -> ()
func.call @free(%177) : (!llvm.ptr) -> ()
%660 = arith.constant 0 : i32
func.return %660 : i32
}
}