← All problems
Problem 293
Sum of distinct pseudo-Fortunate numbers for admissible N < 10^9.
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n^2)O(n log log n)
Space complexity O(n^2)O(n)
Approach Flow solution Sieve-based search
Verdict Suboptimal
Flow source
# Project Euler 293
# Sum of distinct pseudo-Fortunate numbers for admissible N < 10^9.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
function is_prime_mr(n: i64) -> bool {
if n < 2 { return false }
if n < 4 { return true }
if n % 2 == 0 || n % 3 == 0 { return false }
let mut i: i64 = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 { return false }
i = i + 6
}
return true
}
function main() -> i32 {
let limit: i64 = 1000000000
let factors: ptr<i64> = calloc(9, 8)
factors[0] = 2; factors[1] = 3; factors[2] = 5; factors[3] = 7
factors[4] = 11; factors[5] = 13; factors[6] = 17; factors[7] = 19; factors[8] = 23
# generate admissible via stack
let MAXA: i64 = 10000
let adm: ptr<i64> = calloc(MAXA, 8)
let todo_n: ptr<i64> = calloc(MAXA, 8)
let todo_m: ptr<i64> = calloc(MAXA, 8)
if adm == null || todo_n == null || todo_m == null { return 1 }
let mut ac: i64 = 0
let mut tc: i64 = 1
todo_n[0] = 2
todo_m[0] = 0
while tc > 0 {
# pop smallest (linear scan since few)
let mut best: i64 = 0
for bi in 1..tc {
if todo_n[bi] < todo_n[best] { best = bi }
}
let number: i64 = todo_n[best]
let maxp: i64 = todo_m[best]
todo_n[best] = todo_n[tc - 1]
todo_m[best] = todo_m[tc - 1]
tc = tc - 1
adm[ac] = number
ac = ac + 1
let mut i: i64 = 0
while i <= maxp + 1 {
if i >= 9 { break }
let next: i64 = number * factors[i]
if next < limit {
let nm: i64 = maxp
if i > nm { nm = i }
# push if not already present
let mut found: bool = false
let mut j: i64 = 0
while j < tc {
if todo_n[j] == next {
if todo_m[j] < nm { todo_m[j] = nm }
found = true
break
}
j = j + 1
}
if !found {
todo_n[tc] = next
todo_m[tc] = nm
tc = tc + 1
}
}
i = i + 1
}
}
# collect distinct M
let seen: ptr<i8> = calloc(10000, 1)
if seen == null { return 1 }
let mut sum: i64 = 0
for ai in 0..ac {
let n: i64 = adm[ai]
let mut m: i64 = 3
while true {
if is_prime_mr(n + m) {
if seen[m] == 0 {
seen[m] = 1
sum = sum + m
}
break
}
m = m + 2
}
}
printf("%lld\n", sum)
free(seen); free(adm); free(todo_n); free(todo_m); free(factors)
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; }
bool is_prime_mr_i64(int64_t n);
int32_t main(void);
bool is_prime_mr_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 limit = 1000000000;
int64_t* factors = (int64_t*)(calloc(9, 8));
factors[0] = 2;
factors[1] = 3;
factors[2] = 5;
factors[3] = 7;
factors[4] = 11;
factors[5] = 13;
factors[6] = 17;
factors[7] = 19;
factors[8] = 23;
int64_t MAXA = 10000;
int64_t* adm = (int64_t*)(calloc(MAXA, 8));
int64_t* todo_n = (int64_t*)(calloc(MAXA, 8));
int64_t* todo_m = (int64_t*)(calloc(MAXA, 8));
if (((adm == NULL || todo_n == NULL) || todo_m == NULL)) {
return 1;
}
int64_t ac = 0;
int64_t tc = 1;
todo_n[0] = 2;
todo_m[0] = 0;
while (tc > 0) {
int64_t best = 0;
int32_t __flow_step_1 = 1;
for (int32_t bi = 1; (1 <= tc) ? bi < tc : bi > tc; bi += (1 <= tc) ? 1 : -1) {
if (todo_n[bi] < todo_n[best]) {
best = bi;
}
}
int64_t number = todo_n[best];
int64_t maxp = todo_m[best];
todo_n[best] = todo_n[(tc - 1)];
todo_m[best] = todo_m[(tc - 1)];
tc = (tc - 1);
adm[ac] = number;
ac = (ac + 1);
int64_t i = 0;
while (i <= (maxp + 1)) {
if (i >= 9) {
break;
}
int64_t next = (number * factors[i]);
if (next < limit) {
int64_t nm = maxp;
if (i > nm) {
nm = i;
}
bool found = 0;
int64_t j = 0;
while (j < tc) {
if (todo_n[j] == next) {
if (todo_m[j] < nm) {
todo_m[j] = nm;
}
found = 1;
break;
}
j = (j + 1);
}
if ((!(found))) {
todo_n[tc] = next;
todo_m[tc] = nm;
tc = (tc + 1);
}
}
i = (i + 1);
}
}
int8_t* seen = (int8_t*)(calloc(10000, 1));
if (seen == NULL) {
return 1;
}
int64_t sum = 0;
int32_t __flow_step_2 = 1;
for (int32_t ai = 0; (0 <= ac) ? ai < ac : ai > ac; ai += (0 <= ac) ? 1 : -1) {
int64_t n = adm[ai];
int64_t m = 3;
while (1) {
if (is_prime_mr_i64((n + m))) {
if (seen[m] == 0) {
seen[m] = 1;
sum = (sum + m);
}
break;
}
m = (m + 2);
}
}
printf("%lld\n", sum);
free(seen);
free(adm);
free(todo_n);
free(todo_m);
free(factors);
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 @is_prime_mr(%arg0: i64) -> i1 {
%0 = arith.constant 2 : i32
%2 = arith.extsi %0 : i32 to i64
%1 = arith.cmpi slt, %arg0, %2 : i64
cf.cond_br %1, ^bb0, ^bb1
^bb0:
%3 = arith.constant 0 : i1
func.return %3 : i1
^bb1:
cf.br ^bb2
^bb2:
%4 = arith.constant 4 : i32
%6 = arith.extsi %4 : i32 to i64
%5 = arith.cmpi slt, %arg0, %6 : i64
cf.cond_br %5, ^bb3, ^bb4
^bb3:
%7 = arith.constant 1 : i1
func.return %7 : i1
^bb4:
cf.br ^bb5
^bb5:
%8 = arith.constant 2 : i32
%10 = arith.extsi %8 : i32 to i64
%9 = arith.remsi %arg0, %10 : i64
%11 = arith.constant 0 : i32
%13 = arith.extsi %11 : i32 to i64
%12 = arith.cmpi eq, %9, %13 : i64
%14 = scf.if %12 -> (i1) {
%15 = arith.constant true
scf.yield %15 : i1
} else {
%16 = arith.constant 3 : i32
%18 = arith.extsi %16 : i32 to i64
%17 = arith.remsi %arg0, %18 : i64
%19 = arith.constant 0 : i32
%21 = arith.extsi %19 : i32 to i64
%20 = arith.cmpi eq, %17, %21 : i64
scf.yield %20 : i1
}
cf.cond_br %14, ^bb6, ^bb7
^bb6:
%22 = arith.constant 0 : i1
func.return %22 : i1
^bb7:
cf.br ^bb8
^bb8:
%23 = arith.constant 5 : i32
%24 = arith.extsi %23 : i32 to i64
%25 = llvm.mlir.constant(1 : i64) : i64
%26 = llvm.alloca %25 x i64 : (i64) -> !llvm.ptr
llvm.store %24, %26 : i64, !llvm.ptr
cf.br ^bb9
^bb9:
%27 = llvm.load %26 : !llvm.ptr -> i64
%28 = llvm.load %26 : !llvm.ptr -> i64
%29 = arith.muli %27, %28 : i64
%30 = arith.cmpi sle, %29, %arg0 : i64
cf.cond_br %30, ^bb10, ^bb11
^bb10:
%31 = llvm.load %26 : !llvm.ptr -> i64
%32 = arith.remsi %arg0, %31 : i64
%33 = arith.constant 0 : i32
%35 = arith.extsi %33 : i32 to i64
%34 = arith.cmpi eq, %32, %35 : i64
%36 = scf.if %34 -> (i1) {
%37 = arith.constant true
scf.yield %37 : i1
} else {
%38 = llvm.load %26 : !llvm.ptr -> i64
%39 = arith.constant 2 : i32
%41 = arith.extsi %39 : i32 to i64
%40 = arith.addi %38, %41 : i64
%42 = arith.remsi %arg0, %40 : i64
%43 = arith.constant 0 : i32
%45 = arith.extsi %43 : i32 to i64
%44 = arith.cmpi eq, %42, %45 : i64
scf.yield %44 : i1
}
cf.cond_br %36, ^bb12, ^bb13
^bb12:
%46 = arith.constant 0 : i1
func.return %46 : i1
^bb13:
cf.br ^bb14
^bb14:
%47 = llvm.load %26 : !llvm.ptr -> i64
%48 = arith.constant 6 : i32
%50 = arith.extsi %48 : i32 to i64
%49 = arith.addi %47, %50 : i64
llvm.store %49, %26 : i64, !llvm.ptr
cf.br ^bb9
^bb11:
%51 = arith.constant 1 : i1
func.return %51 : i1
}
func.func @main() -> i32 {
%52 = arith.constant 1000000000 : i32
%53 = arith.extsi %52 : i32 to i64
%55 = arith.constant 9 : i32
%56 = arith.constant 8 : i32
%57 = arith.extsi %55 : i32 to i64
%58 = arith.extsi %56 : i32 to i64
%54 = func.call @calloc(%57, %58) : (i64, i64) -> !llvm.ptr
%59 = arith.constant 2 : i32
%60 = arith.constant 0 : i32
%61 = arith.extsi %59 : i32 to i64
%62 = arith.extsi %60 : i32 to i64
%63 = llvm.getelementptr %54[%62] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %61, %63 : i64, !llvm.ptr
%64 = arith.constant 3 : i32
%65 = arith.constant 1 : i32
%66 = arith.extsi %64 : i32 to i64
%67 = arith.extsi %65 : i32 to i64
%68 = llvm.getelementptr %54[%67] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %66, %68 : i64, !llvm.ptr
%69 = arith.constant 5 : i32
%70 = arith.constant 2 : i32
%71 = arith.extsi %69 : i32 to i64
%72 = arith.extsi %70 : i32 to i64
%73 = llvm.getelementptr %54[%72] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %71, %73 : i64, !llvm.ptr
%74 = arith.constant 7 : i32
%75 = arith.constant 3 : i32
%76 = arith.extsi %74 : i32 to i64
%77 = arith.extsi %75 : i32 to i64
%78 = llvm.getelementptr %54[%77] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %76, %78 : i64, !llvm.ptr
%79 = arith.constant 11 : i32
%80 = arith.constant 4 : i32
%81 = arith.extsi %79 : i32 to i64
%82 = arith.extsi %80 : i32 to i64
%83 = llvm.getelementptr %54[%82] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %81, %83 : i64, !llvm.ptr
%84 = arith.constant 13 : i32
%85 = arith.constant 5 : i32
%86 = arith.extsi %84 : i32 to i64
%87 = arith.extsi %85 : i32 to i64
%88 = llvm.getelementptr %54[%87] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %86, %88 : i64, !llvm.ptr
%89 = arith.constant 17 : i32
%90 = arith.constant 6 : i32
%91 = arith.extsi %89 : i32 to i64
%92 = arith.extsi %90 : i32 to i64
%93 = llvm.getelementptr %54[%92] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %91, %93 : i64, !llvm.ptr
%94 = arith.constant 19 : i32
%95 = arith.constant 7 : i32
%96 = arith.extsi %94 : i32 to i64
%97 = arith.extsi %95 : i32 to i64
%98 = llvm.getelementptr %54[%97] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %96, %98 : i64, !llvm.ptr
%99 = arith.constant 23 : i32
%100 = arith.constant 8 : i32
%101 = arith.extsi %99 : i32 to i64
%102 = arith.extsi %100 : i32 to i64
%103 = llvm.getelementptr %54[%102] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %101, %103 : i64, !llvm.ptr
%104 = arith.constant 10000 : i32
%105 = arith.extsi %104 : i32 to i64
%107 = arith.constant 8 : i32
%108 = arith.extsi %107 : i32 to i64
%106 = func.call @calloc(%105, %108) : (i64, i64) -> !llvm.ptr
%110 = arith.constant 8 : i32
%111 = arith.extsi %110 : i32 to i64
%109 = func.call @calloc(%105, %111) : (i64, i64) -> !llvm.ptr
%113 = arith.constant 8 : i32
%114 = arith.extsi %113 : i32 to i64
%112 = func.call @calloc(%105, %114) : (i64, i64) -> !llvm.ptr
%115 = llvm.mlir.zero : !llvm.ptr
%116 = llvm.icmp "eq" %106, %115 : !llvm.ptr
%117 = scf.if %116 -> (i1) {
%118 = arith.constant true
scf.yield %118 : i1
} else {
%119 = llvm.mlir.zero : !llvm.ptr
%120 = llvm.icmp "eq" %109, %119 : !llvm.ptr
scf.yield %120 : i1
}
%121 = scf.if %117 -> (i1) {
%122 = arith.constant true
scf.yield %122 : i1
} else {
%123 = llvm.mlir.zero : !llvm.ptr
%124 = llvm.icmp "eq" %112, %123 : !llvm.ptr
scf.yield %124 : i1
}
cf.cond_br %121, ^bb15, ^bb16
^bb15:
%125 = arith.constant 1 : i32
func.return %125 : i32
^bb16:
cf.br ^bb17
^bb17:
%126 = arith.constant 0 : i32
%127 = arith.extsi %126 : i32 to i64
%128 = llvm.mlir.constant(1 : i64) : i64
%129 = llvm.alloca %128 x i64 : (i64) -> !llvm.ptr
llvm.store %127, %129 : i64, !llvm.ptr
%130 = arith.constant 1 : i32
%131 = arith.extsi %130 : i32 to i64
%132 = llvm.mlir.constant(1 : i64) : i64
%133 = llvm.alloca %132 x i64 : (i64) -> !llvm.ptr
llvm.store %131, %133 : i64, !llvm.ptr
%134 = arith.constant 2 : i32
%135 = arith.constant 0 : i32
%136 = arith.extsi %134 : i32 to i64
%137 = arith.extsi %135 : i32 to i64
%138 = llvm.getelementptr %109[%137] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %136, %138 : i64, !llvm.ptr
%139 = arith.constant 0 : i32
%140 = arith.constant 0 : i32
%141 = arith.extsi %139 : i32 to i64
%142 = arith.extsi %140 : i32 to i64
%143 = llvm.getelementptr %112[%142] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %141, %143 : i64, !llvm.ptr
cf.br ^bb18
^bb18:
%144 = llvm.load %133 : !llvm.ptr -> i64
%145 = arith.constant 0 : i32
%147 = arith.extsi %145 : i32 to i64
%146 = arith.cmpi sgt, %144, %147 : i64
cf.cond_br %146, ^bb19, ^bb20
^bb19:
%148 = arith.constant 0 : i32
%149 = arith.extsi %148 : i32 to i64
%150 = llvm.mlir.constant(1 : i64) : i64
%151 = llvm.alloca %150 x i64 : (i64) -> !llvm.ptr
llvm.store %149, %151 : i64, !llvm.ptr
%152 = arith.constant 1 : i32
%153 = llvm.load %133 : !llvm.ptr -> i64
%154 = arith.index_cast %152 : i32 to index
%155 = arith.index_cast %153 : i32 to index
%157 = arith.constant 1 : index
%158 = arith.constant -1 : index
%159 = arith.cmpi sle, %154, %155 : index
%156 = arith.select %159, %157, %158 : index
cf.br ^bb21(%154 : index)
^bb21(%160: index):
%161 = arith.cmpi slt, %160, %155 : index
%162 = arith.cmpi sgt, %160, %155 : index
%163 = arith.select %159, %161, %162 : i1
cf.cond_br %163, ^bb22(%160 : index), ^bb23(%160 : index)
^bb22(%164: index):
%166 = arith.index_cast %164 : index to i64
%167 = llvm.getelementptr %109[%166] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%165 = llvm.load %167 : !llvm.ptr -> i64
%169 = llvm.load %151 : !llvm.ptr -> i64
%170 = llvm.getelementptr %109[%169] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%168 = llvm.load %170 : !llvm.ptr -> i64
%171 = arith.cmpi slt, %165, %168 : i64
cf.cond_br %171, ^bb24, ^bb25
^bb24:
%172 = arith.index_cast %164 : index to i64
llvm.store %172, %151 : i64, !llvm.ptr
cf.br ^bb26
^bb25:
cf.br ^bb26
^bb26:
%173 = arith.addi %164, %156 : index
cf.br ^bb21(%173 : index)
^bb23(%174: index):
%176 = llvm.load %151 : !llvm.ptr -> i64
%177 = llvm.getelementptr %109[%176] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%175 = llvm.load %177 : !llvm.ptr -> i64
%179 = llvm.load %151 : !llvm.ptr -> i64
%180 = llvm.getelementptr %112[%179] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%178 = llvm.load %180 : !llvm.ptr -> i64
%182 = llvm.load %133 : !llvm.ptr -> i64
%183 = arith.constant 1 : i32
%185 = arith.extsi %183 : i32 to i64
%184 = arith.subi %182, %185 : i64
%186 = llvm.getelementptr %109[%184] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%181 = llvm.load %186 : !llvm.ptr -> i64
%187 = llvm.load %151 : !llvm.ptr -> i64
%188 = llvm.getelementptr %109[%187] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %181, %188 : i64, !llvm.ptr
%190 = llvm.load %133 : !llvm.ptr -> i64
%191 = arith.constant 1 : i32
%193 = arith.extsi %191 : i32 to i64
%192 = arith.subi %190, %193 : i64
%194 = llvm.getelementptr %112[%192] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%189 = llvm.load %194 : !llvm.ptr -> i64
%195 = llvm.load %151 : !llvm.ptr -> i64
%196 = llvm.getelementptr %112[%195] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %189, %196 : i64, !llvm.ptr
%197 = llvm.load %133 : !llvm.ptr -> i64
%198 = arith.constant 1 : i32
%200 = arith.extsi %198 : i32 to i64
%199 = arith.subi %197, %200 : i64
llvm.store %199, %133 : i64, !llvm.ptr
%201 = llvm.load %129 : !llvm.ptr -> i64
%202 = llvm.getelementptr %106[%201] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %175, %202 : i64, !llvm.ptr
%203 = llvm.load %129 : !llvm.ptr -> i64
%204 = arith.constant 1 : i32
%206 = arith.extsi %204 : i32 to i64
%205 = arith.addi %203, %206 : i64
llvm.store %205, %129 : i64, !llvm.ptr
%207 = arith.constant 0 : i32
%208 = arith.extsi %207 : i32 to i64
%209 = llvm.mlir.constant(1 : i64) : i64
%210 = llvm.alloca %209 x i64 : (i64) -> !llvm.ptr
llvm.store %208, %210 : i64, !llvm.ptr
cf.br ^bb27
^bb27:
%211 = llvm.load %210 : !llvm.ptr -> i64
%212 = arith.constant 1 : i32
%214 = arith.extsi %212 : i32 to i64
%213 = arith.addi %178, %214 : i64
%215 = arith.cmpi sle, %211, %213 : i64
cf.cond_br %215, ^bb28, ^bb29
^bb28:
%216 = llvm.load %210 : !llvm.ptr -> i64
%217 = arith.constant 9 : i32
%219 = arith.extsi %217 : i32 to i64
%218 = arith.cmpi sge, %216, %219 : i64
cf.cond_br %218, ^bb30, ^bb31
^bb30:
cf.br ^bb29
^bb31:
cf.br ^bb32
^bb32:
%221 = llvm.load %210 : !llvm.ptr -> i64
%222 = llvm.getelementptr %54[%221] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%220 = llvm.load %222 : !llvm.ptr -> i64
%223 = arith.muli %175, %220 : i64
%224 = arith.cmpi slt, %223, %53 : i64
cf.cond_br %224, ^bb33, ^bb34
^bb33:
%225 = llvm.load %210 : !llvm.ptr -> i64
%226 = arith.cmpi sgt, %225, %178 : i64
%227 = scf.if %226 -> (i64) {
%228 = llvm.load %210 : !llvm.ptr -> i64
scf.yield %228 : i64
} else {
scf.yield %178 : i64
}
%229 = arith.constant 0 : i1
%230 = llvm.mlir.constant(1 : i64) : i64
%231 = llvm.alloca %230 x i1 : (i64) -> !llvm.ptr
llvm.store %229, %231 : i1, !llvm.ptr
%232 = arith.constant 0 : i32
%233 = arith.extsi %232 : i32 to i64
%234 = llvm.mlir.constant(1 : i64) : i64
%235 = llvm.alloca %234 x i64 : (i64) -> !llvm.ptr
llvm.store %233, %235 : i64, !llvm.ptr
cf.br ^bb36
^bb36:
%236 = llvm.load %235 : !llvm.ptr -> i64
%237 = llvm.load %133 : !llvm.ptr -> i64
%238 = arith.cmpi slt, %236, %237 : i64
cf.cond_br %238, ^bb37, ^bb38
^bb37:
%240 = llvm.load %235 : !llvm.ptr -> i64
%241 = llvm.getelementptr %109[%240] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%239 = llvm.load %241 : !llvm.ptr -> i64
%242 = arith.cmpi eq, %239, %223 : i64
cf.cond_br %242, ^bb39, ^bb40
^bb39:
%244 = llvm.load %235 : !llvm.ptr -> i64
%245 = llvm.getelementptr %112[%244] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%243 = llvm.load %245 : !llvm.ptr -> i64
%246 = arith.cmpi slt, %243, %227 : i64
cf.cond_br %246, ^bb42, ^bb43
^bb42:
%247 = llvm.load %235 : !llvm.ptr -> i64
%248 = llvm.getelementptr %112[%247] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %227, %248 : i64, !llvm.ptr
cf.br ^bb44
^bb43:
cf.br ^bb44
^bb44:
%249 = arith.constant 1 : i1
llvm.store %249, %231 : i1, !llvm.ptr
cf.br ^bb38
^bb40:
cf.br ^bb41
^bb41:
%250 = llvm.load %235 : !llvm.ptr -> i64
%251 = arith.constant 1 : i32
%253 = arith.extsi %251 : i32 to i64
%252 = arith.addi %250, %253 : i64
llvm.store %252, %235 : i64, !llvm.ptr
cf.br ^bb36
^bb38:
%254 = llvm.load %231 : !llvm.ptr -> i1
%256 = arith.constant 1 : i1
%255 = arith.xori %254, %256 : i1
cf.cond_br %255, ^bb45, ^bb46
^bb45:
%258 = llvm.load %133 : !llvm.ptr -> i64
%259 = llvm.getelementptr %109[%258] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %223, %259 : i64, !llvm.ptr
%260 = llvm.load %133 : !llvm.ptr -> i64
%261 = llvm.getelementptr %112[%260] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %227, %261 : i64, !llvm.ptr
%262 = llvm.load %133 : !llvm.ptr -> i64
%263 = arith.constant 1 : i32
%265 = arith.extsi %263 : i32 to i64
%264 = arith.addi %262, %265 : i64
llvm.store %264, %133 : i64, !llvm.ptr
cf.br ^bb47
^bb46:
cf.br ^bb47
^bb47:
cf.br ^bb35
^bb34:
cf.br ^bb35
^bb35:
%266 = llvm.load %210 : !llvm.ptr -> i64
%267 = arith.constant 1 : i32
%269 = arith.extsi %267 : i32 to i64
%268 = arith.addi %266, %269 : i64
llvm.store %268, %210 : i64, !llvm.ptr
cf.br ^bb27
^bb29:
cf.br ^bb18
^bb20:
%271 = arith.constant 10000 : i32
%272 = arith.constant 1 : i32
%273 = arith.extsi %271 : i32 to i64
%274 = arith.extsi %272 : i32 to i64
%270 = func.call @calloc(%273, %274) : (i64, i64) -> !llvm.ptr
%275 = llvm.mlir.zero : !llvm.ptr
%276 = llvm.icmp "eq" %270, %275 : !llvm.ptr
cf.cond_br %276, ^bb48, ^bb49
^bb48:
%277 = arith.constant 1 : i32
func.return %277 : i32
^bb49:
cf.br ^bb50
^bb50:
%278 = arith.constant 0 : i32
%279 = arith.extsi %278 : i32 to i64
%280 = llvm.mlir.constant(1 : i64) : i64
%281 = llvm.alloca %280 x i64 : (i64) -> !llvm.ptr
llvm.store %279, %281 : i64, !llvm.ptr
%282 = arith.constant 0 : i32
%283 = llvm.load %129 : !llvm.ptr -> i64
%284 = arith.index_cast %282 : i32 to index
%285 = arith.index_cast %283 : i32 to index
%287 = arith.constant 1 : index
%288 = arith.constant -1 : index
%289 = arith.cmpi sle, %284, %285 : index
%286 = arith.select %289, %287, %288 : index
cf.br ^bb51(%284 : index)
^bb51(%290: index):
%291 = arith.cmpi slt, %290, %285 : index
%292 = arith.cmpi sgt, %290, %285 : index
%293 = arith.select %289, %291, %292 : i1
cf.cond_br %293, ^bb52(%290 : index), ^bb53(%290 : index)
^bb52(%294: index):
%296 = arith.index_cast %294 : index to i64
%297 = llvm.getelementptr %106[%296] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%295 = llvm.load %297 : !llvm.ptr -> i64
%298 = arith.constant 3 : i32
%299 = arith.extsi %298 : i32 to i64
%300 = llvm.mlir.constant(1 : i64) : i64
%301 = llvm.alloca %300 x i64 : (i64) -> !llvm.ptr
llvm.store %299, %301 : i64, !llvm.ptr
cf.br ^bb54
^bb54:
%302 = arith.constant 1 : i1
cf.cond_br %302, ^bb55, ^bb56
^bb55:
%304 = llvm.load %301 : !llvm.ptr -> i64
%305 = arith.addi %295, %304 : i64
%303 = func.call @is_prime_mr(%305) : (i64) -> i1
cf.cond_br %303, ^bb57, ^bb58
^bb57:
%307 = llvm.load %301 : !llvm.ptr -> i64
%308 = llvm.getelementptr %270[%307] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%306 = llvm.load %308 : !llvm.ptr -> i8
%309 = arith.constant 0 : i32
%311 = arith.extsi %306 : i8 to i32
%310 = arith.cmpi eq, %311, %309 : i32
cf.cond_br %310, ^bb60, ^bb61
^bb60:
%312 = arith.constant 1 : i32
%313 = llvm.load %301 : !llvm.ptr -> i64
%314 = arith.trunci %312 : i32 to i8
%315 = llvm.getelementptr %270[%313] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %314, %315 : i8, !llvm.ptr
%316 = llvm.load %281 : !llvm.ptr -> i64
%317 = llvm.load %301 : !llvm.ptr -> i64
%318 = arith.addi %316, %317 : i64
llvm.store %318, %281 : i64, !llvm.ptr
cf.br ^bb62
^bb61:
cf.br ^bb62
^bb62:
cf.br ^bb56
^bb58:
cf.br ^bb59
^bb59:
%319 = llvm.load %301 : !llvm.ptr -> i64
%320 = arith.constant 2 : i32
%322 = arith.extsi %320 : i32 to i64
%321 = arith.addi %319, %322 : i64
llvm.store %321, %301 : i64, !llvm.ptr
cf.br ^bb54
^bb56:
%323 = arith.addi %294, %286 : index
cf.br ^bb51(%323 : index)
^bb53(%324: index):
%325 = llvm.mlir.addressof @str_0 : !llvm.ptr
%326 = llvm.load %281 : !llvm.ptr -> i64
%327 = llvm.call @printf(%325, %326) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%270) : (!llvm.ptr) -> ()
func.call @free(%106) : (!llvm.ptr) -> ()
func.call @free(%109) : (!llvm.ptr) -> ()
func.call @free(%112) : (!llvm.ptr) -> ()
func.call @free(%54) : (!llvm.ptr) -> ()
%333 = arith.constant 0 : i32
func.return %333 : i32
}
}