Problem 850
Fractions of Powers. Ported from native C to pure Flow.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n log n) | ? |
| Space complexity | O(n^2) | ? |
| Approach | Flow solution | Not curated |
| Verdict | Unknown |
Flow source
# Project Euler 850
# Fractions of Powers.
# Ported from native C to pure Flow.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
function sqrt(x: f64) -> f64
}
const MOD: i64 = 977676779
const MOD2: i64 = 2 * 977676779
let mut g_N: i64 = 0
let mut g_mod2: i64 = 0
let mut g_primes: ptr<i32> = null
let mut g_num_primes: i32 = 0
let mut g_fp: ptr<i64> = null
let mut g_fe: ptr<i32> = null
let mut g_factors_count: i32 = 0
let mut g_H_ge3: i64 = 0
function odd_count_from(first: i64, limit: i64) -> i64 {
if first > limit { return 0 }
let mut f: i64 = first
if f % 2 == 0 { f = f + 1 }
if f > limit { return 0 }
return (limit - f) / 2 + 1
}
function imax(a: i64, b: i64) -> i64 {
if a > b { return a }
return b
}
function imin(a: i64, b: i64) -> i64 {
if a < b { return a }
return b
}
function isqrt_i64(n: i64) -> i64 {
if n < 0 { return 0 }
let mut r: i64 = (sqrt(n as f64)) as i64
while r > 0 && r * r > n {
r = r - 1
}
while (r + 1) * (r + 1) <= n {
r = r + 1
}
return r
}
function profile_contribution(d: i64, rad: i64, phi_mod: i64, max_exp: i32) -> i64 {
let mut tail_first: i64 = imax(3, (max_exp as i64) + 1)
if tail_first % 2 == 0 { tail_first = tail_first + 1 }
let oc: i64 = odd_count_from(tail_first, g_N) % g_mod2
let dr: i64 = g_N / (d * rad)
let mut total: i64 = (((oc as i128) * (dr as i128)) % (g_mod2 as i128)) as i64
let small_last: i64 = imin(g_N, tail_first - 2)
let limit: i64 = g_N / d
let mut k: i64 = 3
while k <= small_last {
let mut rho: i64 = 1
let denom: i64 = k - 1
let mut overflow: bool = false
let mut i: i32 = 0
while i < g_factors_count {
let p: i64 = g_fp[i]
let exponent: i32 = g_fe[i]
let e: i32 = (exponent + (denom as i32) - 1) / (denom as i32)
let mut p_power: i64 = 1
let mut j: i32 = 0
while j < e {
if p_power > limit / p {
overflow = true
break
}
p_power = p_power * p
j = j + 1
}
if overflow {
rho = limit + 1
break
}
if rho > limit / p_power {
rho = limit + 1
overflow = true
break
}
rho = rho * p_power
i = i + 1
}
if rho <= limit {
total = total + g_N / (d * rho)
}
k = k + 2
}
return (((phi_mod as i128) * ((total % g_mod2) as i128)) % (g_mod2 as i128)) as i64
}
function visit(start_idx: i32, d: i64, rad: i64, phi_mod: i64, max_exp: i32) -> void {
g_H_ge3 = (g_H_ge3 + profile_contribution(d, rad, phi_mod, max_exp)) % g_mod2
let mut i: i32 = start_idx
while i < g_num_primes {
let p: i64 = g_primes[i] as i64
if d * rad > g_N / (p * p) { break }
let next_rad: i64 = rad * p
let mut next_d: i64 = d * p
let mut phi_factor: i64 = p - 1
let mut exponent: i32 = 1
while next_d <= g_N / next_rad {
g_fp[g_factors_count] = p
g_fe[g_factors_count] = exponent
g_factors_count = g_factors_count + 1
let new_phi: i64 = (((phi_mod as i128) * ((phi_factor % g_mod2) as i128)) % (g_mod2 as i128)) as i64
let mut new_max: i32 = max_exp
if exponent > max_exp { new_max = exponent }
visit(i + 1, next_d, next_rad, new_phi, new_max)
g_factors_count = g_factors_count - 1
exponent = exponent + 1
next_d = next_d * p
phi_factor = phi_factor * p
}
i = i + 1
}
}
function main() -> i32 {
g_N = 33557799775533
g_mod2 = MOD2
g_factors_count = 0
g_H_ge3 = 0
let sqrt_N: i64 = isqrt_i64(g_N)
let slimit: i64 = sqrt_N + 1
# Sieve primes up to sqrt_N
let sieve: ptr<i8> = calloc(slimit, 1)
let mut p: i64 = 2
while p * p <= sqrt_N {
if sieve[p] == 0 {
let mut m: i64 = p * p
while m <= sqrt_N {
sieve[m] = 1
m = m + p
}
}
p = p + 1
}
let mut count: i32 = 0
let mut pi: i64 = 2
while pi <= sqrt_N {
if sieve[pi] == 0 {
count = count + 1
}
pi = pi + 1
}
g_primes = calloc(count as i64, 4) as ptr<i32>
let mut idx: i32 = 0
pi = 2
while pi <= sqrt_N {
if sieve[pi] == 0 {
g_primes[idx] = pi as i32
idx = idx + 1
}
pi = pi + 1
}
g_num_primes = count
free(sieve)
g_fp = calloc(30, 8) as ptr<i64>
g_fe = calloc(30, 4) as ptr<i32>
visit(0, 1, 1, 1, 0)
let H1: i64 = g_N % g_mod2
let odd_count: i64 = (g_N + 1) / 2
let total_h: i64 = (H1 + g_H_ge3) % g_mod2
let sum_n: i64 = ((((g_N as i128) * ((g_N + 1) as i128)) / (2 as i128)) % (g_mod2 as i128)) as i64
let twoS_raw: i64 = ((((odd_count % g_mod2) as i128) * (sum_n as i128)) % (g_mod2 as i128)) as i64 - total_h
let mut twoS_mod: i64 = twoS_raw % g_mod2
if twoS_mod < 0 { twoS_mod = twoS_mod + g_mod2 }
printf("%lld\n", (twoS_mod / 2) % MOD)
free(g_primes)
free(g_fp)
free(g_fe)
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 odd_count_from_i64_i64(int64_t first, int64_t limit);
int64_t imax_i64_i64(int64_t a, int64_t b);
int64_t imin_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64_i64(int64_t n);
int64_t profile_contribution_i64_i64_i64_i32(int64_t d, int64_t rad, int64_t phi_mod, int32_t max_exp);
void visit_i32_i64_i64_i64_i32(int32_t start_idx, int64_t d, int64_t rad, int64_t phi_mod, int32_t max_exp);
int32_t main(void);
static const int64_t MOD = 977676779;
static const int64_t MOD2 = (2 * 977676779);
/* Module statics */
static int64_t g_N = 0;
static int64_t g_mod2 = 0;
static int32_t* g_primes = NULL;
static int32_t g_num_primes = 0;
static int64_t* g_fp = NULL;
static int32_t* g_fe = NULL;
static int32_t g_factors_count = 0;
static int64_t g_H_ge3 = 0;
int64_t odd_count_from_i64_i64(int64_t first, int64_t limit) {
if (first > limit) {
return 0;
}
int64_t f = first;
if (FLOW_CHECKED_MOD((f), (2)) == 0) {
f = (f + 1);
}
if (f > limit) {
return 0;
}
return (FLOW_CHECKED_DIV(((limit - f)), (2)) + 1);
}
int64_t imax_i64_i64(int64_t a, int64_t b) {
if (a > b) {
return a;
}
return b;
}
int64_t imin_i64_i64(int64_t a, int64_t b) {
if (a < b) {
return a;
}
return b;
}
int64_t isqrt_i64_i64(int64_t n) {
if (n < 0) {
return 0;
}
int64_t r = ((int64_t)(sqrt(((double)(n)))));
while ((r > 0 && (r * r) > n)) {
r = (r - 1);
}
while (((r + 1) * (r + 1)) <= n) {
r = (r + 1);
}
return r;
}
int64_t profile_contribution_i64_i64_i64_i32(int64_t d, int64_t rad, int64_t phi_mod, int32_t max_exp) {
int64_t tail_first = imax_i64_i64(3, (((int64_t)(max_exp)) + 1));
if (FLOW_CHECKED_MOD((tail_first), (2)) == 0) {
tail_first = (tail_first + 1);
}
int64_t oc = FLOW_CHECKED_MOD((odd_count_from_i64_i64(tail_first, g_N)), (g_mod2));
int64_t dr = FLOW_CHECKED_DIV((g_N), ((d * rad)));
int64_t total = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(oc)) * ((__int128)(dr)))), (((__int128)(g_mod2))))));
int64_t small_last = imin_i64_i64(g_N, (tail_first - 2));
int64_t limit = FLOW_CHECKED_DIV((g_N), (d));
int64_t k = 3;
while (k <= small_last) {
int64_t rho = 1;
int64_t denom = (k - 1);
bool overflow = 0;
int32_t i = 0;
while (i < g_factors_count) {
int64_t p = g_fp[i];
int32_t exponent = g_fe[i];
int32_t e = FLOW_CHECKED_DIV((((exponent + ((int32_t)(denom))) - 1)), (((int32_t)(denom))));
int64_t p_power = 1;
int32_t j = 0;
while (j < e) {
if (p_power > FLOW_CHECKED_DIV((limit), (p))) {
overflow = 1;
break;
}
p_power = (p_power * p);
j = (j + 1);
}
if (overflow) {
rho = (limit + 1);
break;
}
if (rho > FLOW_CHECKED_DIV((limit), (p_power))) {
rho = (limit + 1);
overflow = 1;
break;
}
rho = (rho * p_power);
i = (i + 1);
}
if (rho <= limit) {
total = (total + FLOW_CHECKED_DIV((g_N), ((d * rho))));
}
k = (k + 2);
}
return ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(phi_mod)) * ((__int128)(FLOW_CHECKED_MOD((total), (g_mod2)))))), (((__int128)(g_mod2))))));
}
void visit_i32_i64_i64_i64_i32(int32_t start_idx, int64_t d, int64_t rad, int64_t phi_mod, int32_t max_exp) {
g_H_ge3 = FLOW_CHECKED_MOD(((g_H_ge3 + profile_contribution_i64_i64_i64_i32(d, rad, phi_mod, max_exp))), (g_mod2));
int32_t i = start_idx;
while (i < g_num_primes) {
int64_t p = ((int64_t)(g_primes[i]));
if ((d * rad) > FLOW_CHECKED_DIV((g_N), ((p * p)))) {
break;
}
int64_t next_rad = (rad * p);
int64_t next_d = (d * p);
int64_t phi_factor = (p - 1);
int32_t exponent = 1;
while (next_d <= FLOW_CHECKED_DIV((g_N), (next_rad))) {
g_fp[g_factors_count] = p;
g_fe[g_factors_count] = exponent;
g_factors_count = (g_factors_count + 1);
int64_t new_phi = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(phi_mod)) * ((__int128)(FLOW_CHECKED_MOD((phi_factor), (g_mod2)))))), (((__int128)(g_mod2))))));
int32_t new_max = max_exp;
if (exponent > max_exp) {
new_max = exponent;
}
visit_i32_i64_i64_i64_i32((i + 1), next_d, next_rad, new_phi, new_max);
g_factors_count = (g_factors_count - 1);
exponent = (exponent + 1);
next_d = (next_d * p);
phi_factor = (phi_factor * p);
}
i = (i + 1);
}
}
int32_t main(void) {
g_N = 33557799775533;
g_mod2 = MOD2;
g_factors_count = 0;
g_H_ge3 = 0;
int64_t sqrt_N = isqrt_i64_i64(g_N);
int64_t slimit = (sqrt_N + 1);
int8_t* sieve = (int8_t*)(calloc(slimit, 1));
int64_t p = 2;
while ((p * p) <= sqrt_N) {
if (sieve[p] == 0) {
int64_t m = (p * p);
while (m <= sqrt_N) {
sieve[m] = 1;
m = (m + p);
}
}
p = (p + 1);
}
int32_t count = 0;
int64_t pi = 2;
while (pi <= sqrt_N) {
if (sieve[pi] == 0) {
count = (count + 1);
}
pi = (pi + 1);
}
g_primes = ((int32_t*)(calloc(((int64_t)(count)), 4)));
int32_t idx = 0;
pi = 2;
while (pi <= sqrt_N) {
if (sieve[pi] == 0) {
g_primes[idx] = ((int32_t)(pi));
idx = (idx + 1);
}
pi = (pi + 1);
}
g_num_primes = count;
free(sieve);
g_fp = ((int64_t*)(calloc(30, 8)));
g_fe = ((int32_t*)(calloc(30, 4)));
visit_i32_i64_i64_i64_i32(0, 1, 1, 1, 0);
int64_t H1 = FLOW_CHECKED_MOD((g_N), (g_mod2));
int64_t odd_count = FLOW_CHECKED_DIV(((g_N + 1)), (2));
int64_t total_h = FLOW_CHECKED_MOD(((H1 + g_H_ge3)), (g_mod2));
int64_t sum_n = ((int64_t)(FLOW_CHECKED_MOD((FLOW_CHECKED_DIV(((((__int128)(g_N)) * ((__int128)((g_N + 1))))), (((__int128)(2))))), (((__int128)(g_mod2))))));
int64_t twoS_raw = (((int64_t)(FLOW_CHECKED_MOD(((((__int128)(FLOW_CHECKED_MOD((odd_count), (g_mod2)))) * ((__int128)(sum_n)))), (((__int128)(g_mod2)))))) - total_h);
int64_t twoS_mod = FLOW_CHECKED_MOD((twoS_raw), (g_mod2));
if (twoS_mod < 0) {
twoS_mod = (twoS_mod + g_mod2);
}
printf("%lld\n", FLOW_CHECKED_MOD((FLOW_CHECKED_DIV((twoS_mod), (2))), (MOD)));
free(g_primes);
free(g_fp);
free(g_fe);
return 0;
}
Generated MLIR
module {
llvm.func @printf(!llvm.ptr, ...) -> i32
llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
func.func private @sqrt(f64) -> f64
// Constant: MOD
llvm.mlir.global internal constant @MOD(977676779 : i64) : i64
// Constant: MOD2
llvm.mlir.global internal constant @MOD2(1955353558 : i64) : i64
// Module static: g_N
llvm.mlir.global internal @g_N(0 : i64) : i64
// Module static: g_mod2
llvm.mlir.global internal @g_mod2(0 : i64) : i64
// Module static: g_primes
llvm.mlir.global internal @g_primes() {addr_space = 0 : i32} : !llvm.ptr {
%0 = llvm.mlir.zero : !llvm.ptr
llvm.return %0 : !llvm.ptr
}
// Module static: g_num_primes
llvm.mlir.global internal @g_num_primes(0 : i32) : i32
// Module static: g_fp
llvm.mlir.global internal @g_fp() {addr_space = 0 : i32} : !llvm.ptr {
%1 = llvm.mlir.zero : !llvm.ptr
llvm.return %1 : !llvm.ptr
}
// Module static: g_fe
llvm.mlir.global internal @g_fe() {addr_space = 0 : i32} : !llvm.ptr {
%2 = llvm.mlir.zero : !llvm.ptr
llvm.return %2 : !llvm.ptr
}
// Module static: g_factors_count
llvm.mlir.global internal @g_factors_count(0 : i32) : i32
// Module static: g_H_ge3
llvm.mlir.global internal @g_H_ge3(0 : i64) : i64
func.func @odd_count_from(%arg0: i64, %arg1: i64) -> i64 {
%3 = arith.cmpi sgt, %arg0, %arg1 : i64
cf.cond_br %3, ^bb0, ^bb1
^bb0:
%4 = arith.constant 0 : i32
%5 = arith.extsi %4 : i32 to i64
func.return %5 : i64
^bb1:
cf.br ^bb2
^bb2:
%6 = llvm.mlir.constant(1 : i64) : i64
%7 = llvm.alloca %6 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %7 : i64, !llvm.ptr
%8 = llvm.load %7 : !llvm.ptr -> i64
%9 = arith.constant 2 : i32
%11 = arith.extsi %9 : i32 to i64
%10 = arith.remsi %8, %11 : i64
%12 = arith.constant 0 : i32
%14 = arith.extsi %12 : i32 to i64
%13 = arith.cmpi eq, %10, %14 : i64
cf.cond_br %13, ^bb3, ^bb4
^bb3:
%15 = llvm.load %7 : !llvm.ptr -> i64
%16 = arith.constant 1 : i32
%18 = arith.extsi %16 : i32 to i64
%17 = arith.addi %15, %18 : i64
llvm.store %17, %7 : i64, !llvm.ptr
cf.br ^bb5
^bb4:
cf.br ^bb5
^bb5:
%19 = llvm.load %7 : !llvm.ptr -> i64
%20 = arith.cmpi sgt, %19, %arg1 : i64
cf.cond_br %20, ^bb6, ^bb7
^bb6:
%21 = arith.constant 0 : i32
%22 = arith.extsi %21 : i32 to i64
func.return %22 : i64
^bb7:
cf.br ^bb8
^bb8:
%23 = llvm.load %7 : !llvm.ptr -> i64
%24 = arith.subi %arg1, %23 : i64
%25 = arith.constant 2 : i32
%27 = arith.extsi %25 : i32 to i64
%26 = arith.divsi %24, %27 : i64
%28 = arith.constant 1 : i32
%30 = arith.extsi %28 : i32 to i64
%29 = arith.addi %26, %30 : i64
func.return %29 : i64
}
func.func @imax(%arg0: i64, %arg1: i64) -> i64 {
%31 = arith.cmpi sgt, %arg0, %arg1 : i64
cf.cond_br %31, ^bb9, ^bb10
^bb9:
func.return %arg0 : i64
^bb10:
cf.br ^bb11
^bb11:
func.return %arg1 : i64
}
func.func @imin(%arg0: i64, %arg1: i64) -> i64 {
%32 = arith.cmpi slt, %arg0, %arg1 : i64
cf.cond_br %32, ^bb12, ^bb13
^bb12:
func.return %arg0 : i64
^bb13:
cf.br ^bb14
^bb14:
func.return %arg1 : i64
}
func.func @isqrt_i64(%arg0: i64) -> i64 {
%33 = arith.constant 0 : i32
%35 = arith.extsi %33 : i32 to i64
%34 = arith.cmpi slt, %arg0, %35 : i64
cf.cond_br %34, ^bb15, ^bb16
^bb15:
%36 = arith.constant 0 : i32
%37 = arith.extsi %36 : i32 to i64
func.return %37 : i64
^bb16:
cf.br ^bb17
^bb17:
%38 = arith.sitofp %arg0 : i64 to f64
%39 = math.sqrt %38 : f64
%40 = arith.fptosi %39 : f64 to i64
%41 = llvm.mlir.constant(1 : i64) : i64
%42 = llvm.alloca %41 x i64 : (i64) -> !llvm.ptr
llvm.store %40, %42 : i64, !llvm.ptr
cf.br ^bb18
^bb18:
%43 = llvm.load %42 : !llvm.ptr -> i64
%44 = arith.constant 0 : i32
%46 = arith.extsi %44 : i32 to i64
%45 = arith.cmpi sgt, %43, %46 : i64
%47 = scf.if %45 -> (i1) {
%48 = llvm.load %42 : !llvm.ptr -> i64
%49 = llvm.load %42 : !llvm.ptr -> i64
%50 = arith.muli %48, %49 : i64
%51 = arith.cmpi sgt, %50, %arg0 : i64
scf.yield %51 : i1
} else {
%52 = arith.constant false
scf.yield %52 : i1
}
cf.cond_br %47, ^bb19, ^bb20
^bb19:
%53 = llvm.load %42 : !llvm.ptr -> i64
%54 = arith.constant 1 : i32
%56 = arith.extsi %54 : i32 to i64
%55 = arith.subi %53, %56 : i64
llvm.store %55, %42 : i64, !llvm.ptr
cf.br ^bb18
^bb20:
cf.br ^bb21
^bb21:
%57 = llvm.load %42 : !llvm.ptr -> i64
%58 = arith.constant 1 : i32
%60 = arith.extsi %58 : i32 to i64
%59 = arith.addi %57, %60 : i64
%61 = llvm.load %42 : !llvm.ptr -> i64
%62 = arith.constant 1 : i32
%64 = arith.extsi %62 : i32 to i64
%63 = arith.addi %61, %64 : i64
%65 = arith.muli %59, %63 : i64
%66 = arith.cmpi sle, %65, %arg0 : i64
cf.cond_br %66, ^bb22, ^bb23
^bb22:
%67 = llvm.load %42 : !llvm.ptr -> i64
%68 = arith.constant 1 : i32
%70 = arith.extsi %68 : i32 to i64
%69 = arith.addi %67, %70 : i64
llvm.store %69, %42 : i64, !llvm.ptr
cf.br ^bb21
^bb23:
%71 = llvm.load %42 : !llvm.ptr -> i64
func.return %71 : i64
}
func.func @profile_contribution(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i32) -> i64 {
%73 = arith.constant 3 : i32
%74 = arith.extsi %arg3 : i32 to i64
%75 = arith.constant 1 : i32
%77 = arith.extsi %75 : i32 to i64
%76 = arith.addi %74, %77 : i64
%78 = arith.extsi %73 : i32 to i64
%72 = func.call @imax(%78, %76) : (i64, i64) -> i64
%79 = llvm.mlir.constant(1 : i64) : i64
%80 = llvm.alloca %79 x i64 : (i64) -> !llvm.ptr
llvm.store %72, %80 : i64, !llvm.ptr
%81 = llvm.load %80 : !llvm.ptr -> i64
%82 = arith.constant 2 : i32
%84 = arith.extsi %82 : i32 to i64
%83 = arith.remsi %81, %84 : i64
%85 = arith.constant 0 : i32
%87 = arith.extsi %85 : i32 to i64
%86 = arith.cmpi eq, %83, %87 : i64
cf.cond_br %86, ^bb24, ^bb25
^bb24:
%88 = llvm.load %80 : !llvm.ptr -> i64
%89 = arith.constant 1 : i32
%91 = arith.extsi %89 : i32 to i64
%90 = arith.addi %88, %91 : i64
llvm.store %90, %80 : i64, !llvm.ptr
cf.br ^bb26
^bb25:
cf.br ^bb26
^bb26:
%93 = llvm.load %80 : !llvm.ptr -> i64
%94 = llvm.mlir.addressof @g_N : !llvm.ptr
%95 = llvm.load %94 : !llvm.ptr -> i64
%92 = func.call @odd_count_from(%93, %95) : (i64, i64) -> i64
%96 = llvm.mlir.addressof @g_mod2 : !llvm.ptr
%97 = llvm.load %96 : !llvm.ptr -> i64
%98 = arith.remsi %92, %97 : i64
%99 = llvm.mlir.addressof @g_N : !llvm.ptr
%100 = llvm.load %99 : !llvm.ptr -> i64
%101 = arith.muli %arg0, %arg1 : i64
%102 = arith.divsi %100, %101 : i64
%103 = arith.extsi %98 : i64 to i128
%104 = arith.extsi %102 : i64 to i128
%106 = arith.trunci %103 : i128 to i64
%107 = arith.trunci %104 : i128 to i64
%105 = arith.muli %106, %107 : i64
%108 = llvm.mlir.addressof @g_mod2 : !llvm.ptr
%109 = llvm.load %108 : !llvm.ptr -> i64
%110 = arith.extsi %109 : i64 to i128
%112 = arith.trunci %110 : i128 to i64
%111 = arith.remsi %105, %112 : i64
%113 = llvm.mlir.constant(1 : i64) : i64
%114 = llvm.alloca %113 x i64 : (i64) -> !llvm.ptr
llvm.store %111, %114 : i64, !llvm.ptr
%116 = llvm.mlir.addressof @g_N : !llvm.ptr
%117 = llvm.load %116 : !llvm.ptr -> i64
%118 = llvm.load %80 : !llvm.ptr -> i64
%119 = arith.constant 2 : i32
%121 = arith.extsi %119 : i32 to i64
%120 = arith.subi %118, %121 : i64
%115 = func.call @imin(%117, %120) : (i64, i64) -> i64
%122 = llvm.mlir.addressof @g_N : !llvm.ptr
%123 = llvm.load %122 : !llvm.ptr -> i64
%124 = arith.divsi %123, %arg0 : i64
%125 = arith.constant 3 : i32
%126 = arith.extsi %125 : i32 to i64
%127 = llvm.mlir.constant(1 : i64) : i64
%128 = llvm.alloca %127 x i64 : (i64) -> !llvm.ptr
llvm.store %126, %128 : i64, !llvm.ptr
cf.br ^bb27
^bb27:
%129 = llvm.load %128 : !llvm.ptr -> i64
%130 = arith.cmpi sle, %129, %115 : i64
cf.cond_br %130, ^bb28, ^bb29
^bb28:
%131 = arith.constant 1 : i32
%132 = arith.extsi %131 : i32 to i64
%133 = llvm.mlir.constant(1 : i64) : i64
%134 = llvm.alloca %133 x i64 : (i64) -> !llvm.ptr
llvm.store %132, %134 : i64, !llvm.ptr
%135 = llvm.load %128 : !llvm.ptr -> i64
%136 = arith.constant 1 : i32
%138 = arith.extsi %136 : i32 to i64
%137 = arith.subi %135, %138 : i64
%139 = arith.constant 0 : i1
%140 = llvm.mlir.constant(1 : i64) : i64
%141 = llvm.alloca %140 x i1 : (i64) -> !llvm.ptr
llvm.store %139, %141 : i1, !llvm.ptr
%142 = arith.constant 0 : i32
%143 = llvm.mlir.constant(1 : i64) : i64
%144 = llvm.alloca %143 x i32 : (i64) -> !llvm.ptr
llvm.store %142, %144 : i32, !llvm.ptr
cf.br ^bb30
^bb30:
%145 = llvm.load %144 : !llvm.ptr -> i32
%146 = llvm.mlir.addressof @g_factors_count : !llvm.ptr
%147 = llvm.load %146 : !llvm.ptr -> i32
%148 = arith.cmpi slt, %145, %147 : i32
cf.cond_br %148, ^bb31, ^bb32
^bb31:
%150 = llvm.mlir.addressof @g_fp : !llvm.ptr
%151 = llvm.load %150 : !llvm.ptr -> !llvm.ptr
%152 = llvm.load %144 : !llvm.ptr -> i32
%153 = arith.extsi %152 : i32 to i64
%154 = llvm.getelementptr %151[%153] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%149 = llvm.load %154 : !llvm.ptr -> i64
%156 = llvm.mlir.addressof @g_fe : !llvm.ptr
%157 = llvm.load %156 : !llvm.ptr -> !llvm.ptr
%158 = llvm.load %144 : !llvm.ptr -> i32
%159 = arith.extsi %158 : i32 to i64
%160 = llvm.getelementptr %157[%159] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%155 = llvm.load %160 : !llvm.ptr -> i32
%161 = arith.trunci %137 : i64 to i32
%162 = arith.addi %155, %161 : i32
%163 = arith.constant 1 : i32
%164 = arith.subi %162, %163 : i32
%165 = arith.trunci %137 : i64 to i32
%166 = arith.divsi %164, %165 : i32
%167 = arith.constant 1 : i32
%168 = arith.extsi %167 : i32 to i64
%169 = llvm.mlir.constant(1 : i64) : i64
%170 = llvm.alloca %169 x i64 : (i64) -> !llvm.ptr
llvm.store %168, %170 : i64, !llvm.ptr
%171 = arith.constant 0 : i32
%172 = llvm.mlir.constant(1 : i64) : i64
%173 = llvm.alloca %172 x i32 : (i64) -> !llvm.ptr
llvm.store %171, %173 : i32, !llvm.ptr
cf.br ^bb33
^bb33:
%174 = llvm.load %173 : !llvm.ptr -> i32
%175 = arith.cmpi slt, %174, %166 : i32
cf.cond_br %175, ^bb34, ^bb35
^bb34:
%176 = llvm.load %170 : !llvm.ptr -> i64
%177 = arith.divsi %124, %149 : i64
%178 = arith.cmpi sgt, %176, %177 : i64
cf.cond_br %178, ^bb36, ^bb37
^bb36:
%179 = arith.constant 1 : i1
llvm.store %179, %141 : i1, !llvm.ptr
cf.br ^bb35
^bb37:
cf.br ^bb38
^bb38:
%180 = llvm.load %170 : !llvm.ptr -> i64
%181 = arith.muli %180, %149 : i64
llvm.store %181, %170 : i64, !llvm.ptr
%182 = llvm.load %173 : !llvm.ptr -> i32
%183 = arith.constant 1 : i32
%184 = arith.addi %182, %183 : i32
llvm.store %184, %173 : i32, !llvm.ptr
cf.br ^bb33
^bb35:
%185 = llvm.load %141 : !llvm.ptr -> i1
cf.cond_br %185, ^bb39, ^bb40
^bb39:
%186 = arith.constant 1 : i32
%188 = arith.extsi %186 : i32 to i64
%187 = arith.addi %124, %188 : i64
llvm.store %187, %134 : i64, !llvm.ptr
cf.br ^bb32
^bb40:
cf.br ^bb41
^bb41:
%189 = llvm.load %134 : !llvm.ptr -> i64
%190 = llvm.load %170 : !llvm.ptr -> i64
%191 = arith.divsi %124, %190 : i64
%192 = arith.cmpi sgt, %189, %191 : i64
cf.cond_br %192, ^bb42, ^bb43
^bb42:
%193 = arith.constant 1 : i32
%195 = arith.extsi %193 : i32 to i64
%194 = arith.addi %124, %195 : i64
llvm.store %194, %134 : i64, !llvm.ptr
%196 = arith.constant 1 : i1
llvm.store %196, %141 : i1, !llvm.ptr
cf.br ^bb32
^bb43:
cf.br ^bb44
^bb44:
%197 = llvm.load %134 : !llvm.ptr -> i64
%198 = llvm.load %170 : !llvm.ptr -> i64
%199 = arith.muli %197, %198 : i64
llvm.store %199, %134 : i64, !llvm.ptr
%200 = llvm.load %144 : !llvm.ptr -> i32
%201 = arith.constant 1 : i32
%202 = arith.addi %200, %201 : i32
llvm.store %202, %144 : i32, !llvm.ptr
cf.br ^bb30
^bb32:
%203 = llvm.load %134 : !llvm.ptr -> i64
%204 = arith.cmpi sle, %203, %124 : i64
cf.cond_br %204, ^bb45, ^bb46
^bb45:
%205 = llvm.load %114 : !llvm.ptr -> i64
%206 = llvm.mlir.addressof @g_N : !llvm.ptr
%207 = llvm.load %206 : !llvm.ptr -> i64
%208 = llvm.load %134 : !llvm.ptr -> i64
%209 = arith.muli %arg0, %208 : i64
%210 = arith.divsi %207, %209 : i64
%211 = arith.addi %205, %210 : i64
llvm.store %211, %114 : i64, !llvm.ptr
cf.br ^bb47
^bb46:
cf.br ^bb47
^bb47:
%212 = llvm.load %128 : !llvm.ptr -> i64
%213 = arith.constant 2 : i32
%215 = arith.extsi %213 : i32 to i64
%214 = arith.addi %212, %215 : i64
llvm.store %214, %128 : i64, !llvm.ptr
cf.br ^bb27
^bb29:
%216 = arith.extsi %arg2 : i64 to i128
%217 = llvm.load %114 : !llvm.ptr -> i64
%218 = llvm.mlir.addressof @g_mod2 : !llvm.ptr
%219 = llvm.load %218 : !llvm.ptr -> i64
%220 = arith.remsi %217, %219 : i64
%221 = arith.extsi %220 : i64 to i128
%223 = arith.trunci %216 : i128 to i64
%224 = arith.trunci %221 : i128 to i64
%222 = arith.muli %223, %224 : i64
%225 = llvm.mlir.addressof @g_mod2 : !llvm.ptr
%226 = llvm.load %225 : !llvm.ptr -> i64
%227 = arith.extsi %226 : i64 to i128
%229 = arith.trunci %227 : i128 to i64
%228 = arith.remsi %222, %229 : i64
func.return %228 : i64
}
func.func @visit(%arg0: i32, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: i32) -> () {
%230 = llvm.mlir.addressof @g_H_ge3 : !llvm.ptr
%231 = llvm.load %230 : !llvm.ptr -> i64
%232 = func.call @profile_contribution(%arg1, %arg2, %arg3, %arg4) : (i64, i64, i64, i32) -> i64
%233 = arith.addi %231, %232 : i64
%234 = llvm.mlir.addressof @g_mod2 : !llvm.ptr
%235 = llvm.load %234 : !llvm.ptr -> i64
%236 = arith.remsi %233, %235 : i64
%237 = llvm.mlir.addressof @g_H_ge3 : !llvm.ptr
llvm.store %236, %237 : i64, !llvm.ptr
%238 = llvm.mlir.constant(1 : i64) : i64
%239 = llvm.alloca %238 x i32 : (i64) -> !llvm.ptr
llvm.store %arg0, %239 : i32, !llvm.ptr
cf.br ^bb48
^bb48:
%240 = llvm.load %239 : !llvm.ptr -> i32
%241 = llvm.mlir.addressof @g_num_primes : !llvm.ptr
%242 = llvm.load %241 : !llvm.ptr -> i32
%243 = arith.cmpi slt, %240, %242 : i32
cf.cond_br %243, ^bb49, ^bb50
^bb49:
%245 = llvm.mlir.addressof @g_primes : !llvm.ptr
%246 = llvm.load %245 : !llvm.ptr -> !llvm.ptr
%247 = llvm.load %239 : !llvm.ptr -> i32
%248 = arith.extsi %247 : i32 to i64
%249 = llvm.getelementptr %246[%248] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%244 = llvm.load %249 : !llvm.ptr -> i32
%250 = arith.extsi %244 : i32 to i64
%251 = arith.muli %arg1, %arg2 : i64
%252 = llvm.mlir.addressof @g_N : !llvm.ptr
%253 = llvm.load %252 : !llvm.ptr -> i64
%254 = arith.muli %250, %250 : i64
%255 = arith.divsi %253, %254 : i64
%256 = arith.cmpi sgt, %251, %255 : i64
cf.cond_br %256, ^bb51, ^bb52
^bb51:
cf.br ^bb50
^bb52:
cf.br ^bb53
^bb53:
%257 = arith.muli %arg2, %250 : i64
%258 = arith.muli %arg1, %250 : i64
%259 = llvm.mlir.constant(1 : i64) : i64
%260 = llvm.alloca %259 x i64 : (i64) -> !llvm.ptr
llvm.store %258, %260 : i64, !llvm.ptr
%261 = arith.constant 1 : i32
%263 = arith.extsi %261 : i32 to i64
%262 = arith.subi %250, %263 : i64
%264 = llvm.mlir.constant(1 : i64) : i64
%265 = llvm.alloca %264 x i64 : (i64) -> !llvm.ptr
llvm.store %262, %265 : i64, !llvm.ptr
%266 = arith.constant 1 : i32
%267 = llvm.mlir.constant(1 : i64) : i64
%268 = llvm.alloca %267 x i32 : (i64) -> !llvm.ptr
llvm.store %266, %268 : i32, !llvm.ptr
cf.br ^bb54
^bb54:
%269 = llvm.load %260 : !llvm.ptr -> i64
%270 = llvm.mlir.addressof @g_N : !llvm.ptr
%271 = llvm.load %270 : !llvm.ptr -> i64
%272 = arith.divsi %271, %257 : i64
%273 = arith.cmpi sle, %269, %272 : i64
cf.cond_br %273, ^bb55, ^bb56
^bb55:
%274 = llvm.mlir.addressof @g_fp : !llvm.ptr
%275 = llvm.load %274 : !llvm.ptr -> !llvm.ptr
%276 = llvm.mlir.addressof @g_factors_count : !llvm.ptr
%277 = llvm.load %276 : !llvm.ptr -> i32
%278 = arith.extsi %277 : i32 to i64
%279 = llvm.getelementptr %275[%278] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %250, %279 : i64, !llvm.ptr
%280 = llvm.load %268 : !llvm.ptr -> i32
%281 = llvm.mlir.addressof @g_fe : !llvm.ptr
%282 = llvm.load %281 : !llvm.ptr -> !llvm.ptr
%283 = llvm.mlir.addressof @g_factors_count : !llvm.ptr
%284 = llvm.load %283 : !llvm.ptr -> i32
%285 = arith.extsi %284 : i32 to i64
%286 = llvm.getelementptr %282[%285] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %280, %286 : i32, !llvm.ptr
%287 = llvm.mlir.addressof @g_factors_count : !llvm.ptr
%288 = llvm.load %287 : !llvm.ptr -> i32
%289 = arith.constant 1 : i32
%290 = arith.addi %288, %289 : i32
%291 = llvm.mlir.addressof @g_factors_count : !llvm.ptr
llvm.store %290, %291 : i32, !llvm.ptr
%292 = arith.extsi %arg3 : i64 to i128
%293 = llvm.load %265 : !llvm.ptr -> i64
%294 = llvm.mlir.addressof @g_mod2 : !llvm.ptr
%295 = llvm.load %294 : !llvm.ptr -> i64
%296 = arith.remsi %293, %295 : i64
%297 = arith.extsi %296 : i64 to i128
%299 = arith.trunci %292 : i128 to i64
%300 = arith.trunci %297 : i128 to i64
%298 = arith.muli %299, %300 : i64
%301 = llvm.mlir.addressof @g_mod2 : !llvm.ptr
%302 = llvm.load %301 : !llvm.ptr -> i64
%303 = arith.extsi %302 : i64 to i128
%305 = arith.trunci %303 : i128 to i64
%304 = arith.remsi %298, %305 : i64
%306 = llvm.mlir.constant(1 : i64) : i64
%307 = llvm.alloca %306 x i32 : (i64) -> !llvm.ptr
llvm.store %arg4, %307 : i32, !llvm.ptr
%308 = llvm.load %268 : !llvm.ptr -> i32
%309 = arith.cmpi sgt, %308, %arg4 : i32
cf.cond_br %309, ^bb57, ^bb58
^bb57:
%310 = llvm.load %268 : !llvm.ptr -> i32
llvm.store %310, %307 : i32, !llvm.ptr
cf.br ^bb59
^bb58:
cf.br ^bb59
^bb59:
%312 = llvm.load %239 : !llvm.ptr -> i32
%313 = arith.constant 1 : i32
%314 = arith.addi %312, %313 : i32
%315 = llvm.load %260 : !llvm.ptr -> i64
%316 = llvm.load %307 : !llvm.ptr -> i32
func.call @visit(%314, %315, %257, %304, %316) : (i32, i64, i64, i64, i32) -> ()
%317 = llvm.mlir.addressof @g_factors_count : !llvm.ptr
%318 = llvm.load %317 : !llvm.ptr -> i32
%319 = arith.constant 1 : i32
%320 = arith.subi %318, %319 : i32
%321 = llvm.mlir.addressof @g_factors_count : !llvm.ptr
llvm.store %320, %321 : i32, !llvm.ptr
%322 = llvm.load %268 : !llvm.ptr -> i32
%323 = arith.constant 1 : i32
%324 = arith.addi %322, %323 : i32
llvm.store %324, %268 : i32, !llvm.ptr
%325 = llvm.load %260 : !llvm.ptr -> i64
%326 = arith.muli %325, %250 : i64
llvm.store %326, %260 : i64, !llvm.ptr
%327 = llvm.load %265 : !llvm.ptr -> i64
%328 = arith.muli %327, %250 : i64
llvm.store %328, %265 : i64, !llvm.ptr
cf.br ^bb54
^bb56:
%329 = llvm.load %239 : !llvm.ptr -> i32
%330 = arith.constant 1 : i32
%331 = arith.addi %329, %330 : i32
llvm.store %331, %239 : i32, !llvm.ptr
cf.br ^bb48
^bb50:
func.return
}
func.func @main() -> i32 {
%332 = arith.constant 33553504808237 : i32
%333 = arith.extsi %332 : i32 to i64
%334 = llvm.mlir.addressof @g_N : !llvm.ptr
llvm.store %333, %334 : i64, !llvm.ptr
%335 = llvm.mlir.addressof @MOD2 : !llvm.ptr
%336 = llvm.load %335 : !llvm.ptr -> i64
%337 = llvm.mlir.addressof @g_mod2 : !llvm.ptr
llvm.store %336, %337 : i64, !llvm.ptr
%338 = arith.constant 0 : i32
%339 = llvm.mlir.addressof @g_factors_count : !llvm.ptr
llvm.store %338, %339 : i32, !llvm.ptr
%340 = arith.constant 0 : i32
%341 = arith.extsi %340 : i32 to i64
%342 = llvm.mlir.addressof @g_H_ge3 : !llvm.ptr
llvm.store %341, %342 : i64, !llvm.ptr
%344 = llvm.mlir.addressof @g_N : !llvm.ptr
%345 = llvm.load %344 : !llvm.ptr -> i64
%343 = func.call @isqrt_i64(%345) : (i64) -> i64
%346 = arith.constant 1 : i32
%348 = arith.extsi %346 : i32 to i64
%347 = arith.addi %343, %348 : i64
%350 = arith.constant 1 : i32
%351 = arith.extsi %350 : i32 to i64
%349 = func.call @calloc(%347, %351) : (i64, i64) -> !llvm.ptr
%352 = arith.constant 2 : i32
%353 = arith.extsi %352 : i32 to i64
%354 = llvm.mlir.constant(1 : i64) : i64
%355 = llvm.alloca %354 x i64 : (i64) -> !llvm.ptr
llvm.store %353, %355 : i64, !llvm.ptr
cf.br ^bb60
^bb60:
%356 = llvm.load %355 : !llvm.ptr -> i64
%357 = llvm.load %355 : !llvm.ptr -> i64
%358 = arith.muli %356, %357 : i64
%359 = arith.cmpi sle, %358, %343 : i64
cf.cond_br %359, ^bb61, ^bb62
^bb61:
%361 = llvm.load %355 : !llvm.ptr -> i64
%362 = llvm.getelementptr %349[%361] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%360 = llvm.load %362 : !llvm.ptr -> i8
%363 = arith.constant 0 : i32
%365 = arith.extsi %360 : i8 to i32
%364 = arith.cmpi eq, %365, %363 : i32
cf.cond_br %364, ^bb63, ^bb64
^bb63:
%366 = llvm.load %355 : !llvm.ptr -> i64
%367 = llvm.load %355 : !llvm.ptr -> i64
%368 = arith.muli %366, %367 : i64
%369 = llvm.mlir.constant(1 : i64) : i64
%370 = llvm.alloca %369 x i64 : (i64) -> !llvm.ptr
llvm.store %368, %370 : i64, !llvm.ptr
cf.br ^bb66
^bb66:
%371 = llvm.load %370 : !llvm.ptr -> i64
%372 = arith.cmpi sle, %371, %343 : i64
cf.cond_br %372, ^bb67, ^bb68
^bb67:
%373 = arith.constant 1 : i32
%374 = llvm.load %370 : !llvm.ptr -> i64
%375 = arith.trunci %373 : i32 to i8
%376 = llvm.getelementptr %349[%374] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %375, %376 : i8, !llvm.ptr
%377 = llvm.load %370 : !llvm.ptr -> i64
%378 = llvm.load %355 : !llvm.ptr -> i64
%379 = arith.addi %377, %378 : i64
llvm.store %379, %370 : i64, !llvm.ptr
cf.br ^bb66
^bb68:
cf.br ^bb65
^bb64:
cf.br ^bb65
^bb65:
%380 = llvm.load %355 : !llvm.ptr -> i64
%381 = arith.constant 1 : i32
%383 = arith.extsi %381 : i32 to i64
%382 = arith.addi %380, %383 : i64
llvm.store %382, %355 : i64, !llvm.ptr
cf.br ^bb60
^bb62:
%384 = arith.constant 0 : i32
%385 = llvm.mlir.constant(1 : i64) : i64
%386 = llvm.alloca %385 x i32 : (i64) -> !llvm.ptr
llvm.store %384, %386 : i32, !llvm.ptr
%387 = arith.constant 2 : i32
%388 = arith.extsi %387 : i32 to i64
%389 = llvm.mlir.constant(1 : i64) : i64
%390 = llvm.alloca %389 x i64 : (i64) -> !llvm.ptr
llvm.store %388, %390 : i64, !llvm.ptr
cf.br ^bb69
^bb69:
%391 = llvm.load %390 : !llvm.ptr -> i64
%392 = arith.cmpi sle, %391, %343 : i64
cf.cond_br %392, ^bb70, ^bb71
^bb70:
%394 = llvm.load %390 : !llvm.ptr -> i64
%395 = llvm.getelementptr %349[%394] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%393 = llvm.load %395 : !llvm.ptr -> i8
%396 = arith.constant 0 : i32
%398 = arith.extsi %393 : i8 to i32
%397 = arith.cmpi eq, %398, %396 : i32
cf.cond_br %397, ^bb72, ^bb73
^bb72:
%399 = llvm.load %386 : !llvm.ptr -> i32
%400 = arith.constant 1 : i32
%401 = arith.addi %399, %400 : i32
llvm.store %401, %386 : i32, !llvm.ptr
cf.br ^bb74
^bb73:
cf.br ^bb74
^bb74:
%402 = llvm.load %390 : !llvm.ptr -> i64
%403 = arith.constant 1 : i32
%405 = arith.extsi %403 : i32 to i64
%404 = arith.addi %402, %405 : i64
llvm.store %404, %390 : i64, !llvm.ptr
cf.br ^bb69
^bb71:
%407 = llvm.load %386 : !llvm.ptr -> i32
%408 = arith.extsi %407 : i32 to i64
%409 = arith.constant 4 : i32
%410 = arith.extsi %409 : i32 to i64
%406 = func.call @calloc(%408, %410) : (i64, i64) -> !llvm.ptr
%411 = llvm.mlir.addressof @g_primes : !llvm.ptr
llvm.store %406, %411 : !llvm.ptr, !llvm.ptr
%412 = arith.constant 0 : i32
%413 = llvm.mlir.constant(1 : i64) : i64
%414 = llvm.alloca %413 x i32 : (i64) -> !llvm.ptr
llvm.store %412, %414 : i32, !llvm.ptr
%415 = arith.constant 2 : i32
%416 = arith.extsi %415 : i32 to i64
llvm.store %416, %390 : i64, !llvm.ptr
cf.br ^bb75
^bb75:
%417 = llvm.load %390 : !llvm.ptr -> i64
%418 = arith.cmpi sle, %417, %343 : i64
cf.cond_br %418, ^bb76, ^bb77
^bb76:
%420 = llvm.load %390 : !llvm.ptr -> i64
%421 = llvm.getelementptr %349[%420] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%419 = llvm.load %421 : !llvm.ptr -> i8
%422 = arith.constant 0 : i32
%424 = arith.extsi %419 : i8 to i32
%423 = arith.cmpi eq, %424, %422 : i32
cf.cond_br %423, ^bb78, ^bb79
^bb78:
%425 = llvm.load %390 : !llvm.ptr -> i64
%426 = arith.trunci %425 : i64 to i32
%427 = llvm.mlir.addressof @g_primes : !llvm.ptr
%428 = llvm.load %427 : !llvm.ptr -> !llvm.ptr
%429 = llvm.load %414 : !llvm.ptr -> i32
%430 = arith.extsi %429 : i32 to i64
%431 = llvm.getelementptr %428[%430] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %426, %431 : i32, !llvm.ptr
%432 = llvm.load %414 : !llvm.ptr -> i32
%433 = arith.constant 1 : i32
%434 = arith.addi %432, %433 : i32
llvm.store %434, %414 : i32, !llvm.ptr
cf.br ^bb80
^bb79:
cf.br ^bb80
^bb80:
%435 = llvm.load %390 : !llvm.ptr -> i64
%436 = arith.constant 1 : i32
%438 = arith.extsi %436 : i32 to i64
%437 = arith.addi %435, %438 : i64
llvm.store %437, %390 : i64, !llvm.ptr
cf.br ^bb75
^bb77:
%439 = llvm.load %386 : !llvm.ptr -> i32
%440 = llvm.mlir.addressof @g_num_primes : !llvm.ptr
llvm.store %439, %440 : i32, !llvm.ptr
func.call @free(%349) : (!llvm.ptr) -> ()
%443 = arith.constant 30 : i32
%444 = arith.constant 8 : i32
%445 = arith.extsi %443 : i32 to i64
%446 = arith.extsi %444 : i32 to i64
%442 = func.call @calloc(%445, %446) : (i64, i64) -> !llvm.ptr
%447 = llvm.mlir.addressof @g_fp : !llvm.ptr
llvm.store %442, %447 : !llvm.ptr, !llvm.ptr
%449 = arith.constant 30 : i32
%450 = arith.constant 4 : i32
%451 = arith.extsi %449 : i32 to i64
%452 = arith.extsi %450 : i32 to i64
%448 = func.call @calloc(%451, %452) : (i64, i64) -> !llvm.ptr
%453 = llvm.mlir.addressof @g_fe : !llvm.ptr
llvm.store %448, %453 : !llvm.ptr, !llvm.ptr
%455 = arith.constant 0 : i32
%456 = arith.constant 1 : i32
%457 = arith.constant 1 : i32
%458 = arith.constant 1 : i32
%459 = arith.constant 0 : i32
%460 = arith.extsi %456 : i32 to i64
%461 = arith.extsi %457 : i32 to i64
%462 = arith.extsi %458 : i32 to i64
func.call @visit(%455, %460, %461, %462, %459) : (i32, i64, i64, i64, i32) -> ()
%463 = llvm.mlir.addressof @g_N : !llvm.ptr
%464 = llvm.load %463 : !llvm.ptr -> i64
%465 = llvm.mlir.addressof @g_mod2 : !llvm.ptr
%466 = llvm.load %465 : !llvm.ptr -> i64
%467 = arith.remsi %464, %466 : i64
%468 = llvm.mlir.addressof @g_N : !llvm.ptr
%469 = llvm.load %468 : !llvm.ptr -> i64
%470 = arith.constant 1 : i32
%472 = arith.extsi %470 : i32 to i64
%471 = arith.addi %469, %472 : i64
%473 = arith.constant 2 : i32
%475 = arith.extsi %473 : i32 to i64
%474 = arith.divsi %471, %475 : i64
%476 = llvm.mlir.addressof @g_H_ge3 : !llvm.ptr
%477 = llvm.load %476 : !llvm.ptr -> i64
%478 = arith.addi %467, %477 : i64
%479 = llvm.mlir.addressof @g_mod2 : !llvm.ptr
%480 = llvm.load %479 : !llvm.ptr -> i64
%481 = arith.remsi %478, %480 : i64
%482 = llvm.mlir.addressof @g_N : !llvm.ptr
%483 = llvm.load %482 : !llvm.ptr -> i64
%484 = arith.extsi %483 : i64 to i128
%485 = llvm.mlir.addressof @g_N : !llvm.ptr
%486 = llvm.load %485 : !llvm.ptr -> i64
%487 = arith.constant 1 : i32
%489 = arith.extsi %487 : i32 to i64
%488 = arith.addi %486, %489 : i64
%490 = arith.extsi %488 : i64 to i128
%492 = arith.trunci %484 : i128 to i64
%493 = arith.trunci %490 : i128 to i64
%491 = arith.muli %492, %493 : i64
%494 = arith.constant 2 : i32
%495 = arith.extsi %494 : i32 to i128
%497 = arith.trunci %495 : i128 to i64
%496 = arith.divsi %491, %497 : i64
%498 = llvm.mlir.addressof @g_mod2 : !llvm.ptr
%499 = llvm.load %498 : !llvm.ptr -> i64
%500 = arith.extsi %499 : i64 to i128
%502 = arith.trunci %500 : i128 to i64
%501 = arith.remsi %496, %502 : i64
%503 = llvm.mlir.addressof @g_mod2 : !llvm.ptr
%504 = llvm.load %503 : !llvm.ptr -> i64
%505 = arith.remsi %474, %504 : i64
%506 = arith.extsi %505 : i64 to i128
%507 = arith.extsi %501 : i64 to i128
%509 = arith.trunci %506 : i128 to i64
%510 = arith.trunci %507 : i128 to i64
%508 = arith.muli %509, %510 : i64
%511 = llvm.mlir.addressof @g_mod2 : !llvm.ptr
%512 = llvm.load %511 : !llvm.ptr -> i64
%513 = arith.extsi %512 : i64 to i128
%515 = arith.trunci %513 : i128 to i64
%514 = arith.remsi %508, %515 : i64
%516 = arith.subi %514, %481 : i64
%517 = llvm.mlir.addressof @g_mod2 : !llvm.ptr
%518 = llvm.load %517 : !llvm.ptr -> i64
%519 = arith.remsi %516, %518 : i64
%520 = llvm.mlir.constant(1 : i64) : i64
%521 = llvm.alloca %520 x i64 : (i64) -> !llvm.ptr
llvm.store %519, %521 : i64, !llvm.ptr
%522 = llvm.load %521 : !llvm.ptr -> i64
%523 = arith.constant 0 : i32
%525 = arith.extsi %523 : i32 to i64
%524 = arith.cmpi slt, %522, %525 : i64
cf.cond_br %524, ^bb81, ^bb82
^bb81:
%526 = llvm.load %521 : !llvm.ptr -> i64
%527 = llvm.mlir.addressof @g_mod2 : !llvm.ptr
%528 = llvm.load %527 : !llvm.ptr -> i64
%529 = arith.addi %526, %528 : i64
llvm.store %529, %521 : i64, !llvm.ptr
cf.br ^bb83
^bb82:
cf.br ^bb83
^bb83:
%530 = llvm.mlir.addressof @str_0 : !llvm.ptr
%531 = llvm.load %521 : !llvm.ptr -> i64
%532 = arith.constant 2 : i32
%534 = arith.extsi %532 : i32 to i64
%533 = arith.divsi %531, %534 : i64
%535 = llvm.mlir.addressof @MOD : !llvm.ptr
%536 = llvm.load %535 : !llvm.ptr -> i64
%537 = arith.remsi %533, %536 : i64
%538 = llvm.call @printf(%530, %537) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
%540 = llvm.mlir.addressof @g_primes : !llvm.ptr
%541 = llvm.load %540 : !llvm.ptr -> !llvm.ptr
func.call @free(%541) : (!llvm.ptr) -> ()
%543 = llvm.mlir.addressof @g_fp : !llvm.ptr
%544 = llvm.load %543 : !llvm.ptr -> !llvm.ptr
func.call @free(%544) : (!llvm.ptr) -> ()
%546 = llvm.mlir.addressof @g_fe : !llvm.ptr
%547 = llvm.load %546 : !llvm.ptr -> !llvm.ptr
func.call @free(%547) : (!llvm.ptr) -> ()
%548 = arith.constant 0 : i32
func.return %548 : i32
}
}