Problem 196
S(5678027) + S(7208785) for prime-triplet elements in triangle rows.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n^4) | O(n^2) |
| Space complexity | O(n) | O(n^2) |
| Approach | Flow solution | Bottom-up DP |
| Verdict | Suboptimal |
Flow source
# Project Euler 196
# S(5678027) + S(7208785) for prime-triplet elements in triangle rows.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
function memset(p: ptr<void>, v: i32, n: i64) -> ptr<void>
}
let mut sieve: ptr<i8> = null
let mut sieve_half: i64 = 0
let mut segment: ptr<i8> = null
let mut segment_len: i64 = 0
let mut segment_start: i64 = 0
let mut three_plus: ptr<i8> = null
function isqrt(n: i64) -> i64 {
if n <= 0 { return 0 }
let mut x: i64 = n
let mut y: i64 = (x + 1) / 2
while y < x {
x = y
y = (x + n / x) / 2
}
return x
}
function fill_sieve(size: i64) -> void {
let half: i64 = (size >> 1) + 1
if sieve_half >= half { return }
if sieve != null { free(sieve) }
sieve = calloc(half, 1)
sieve_half = half
let mut i: i64 = 0
while i < half {
sieve[i] = 1
i = i + 1
}
sieve[0] = 0
i = 1
while 2 * i * i < half {
if sieve[i] == 1 {
let mut current: i64 = 3 * i + 1
let step: i64 = 2 * i + 1
while current < half {
sieve[current] = 0
current = current + step
}
}
i = i + 1
}
}
function is_prime_small(x: i64) -> bool {
if x % 2 == 0 { return x == 2 }
return sieve[x >> 1] == 1
}
function get_number(x: i64, y: i64) -> i64 {
return x + y * (y - 1) / 2
}
function fill_segmented_sieve(from_val: i64, to_val: i64) -> void {
fill_sieve(isqrt(to_val))
segment_start = from_val | 1
let num_values: i64 = to_val - from_val + 1
if segment != null { free(segment) }
if three_plus != null { free(three_plus) }
segment_len = num_values + 1
segment = calloc(segment_len, 1)
three_plus = calloc(segment_len, 1)
for i in 0..segment_len {
segment[i] = 1
three_plus[i] = 0
}
let lim: i64 = isqrt(to_val)
for p in 3..(lim + 1) step 2 {
if is_prime_small(p) {
let mut smallest: i64 = from_val - (from_val % p) + p
if smallest % 2 == 0 { smallest = smallest + p }
let mut j: i64 = smallest
while j <= to_val {
segment[(j - segment_start) / 2] = 0
j = j + 2 * p
}
}
}
}
function is_prime_in_segment(x: i64, y: i64) -> bool {
if x < 1 || x > y { return false }
let current: i64 = get_number(x, y)
if current % 2 == 0 { return current == 2 }
return segment[(current - segment_start) / 2] == 1
}
function process_line(line: i64) -> i64 {
let mut sieve_from: i64 = get_number(1, line - 2)
let sieve_to: i64 = get_number(1, line + 3) - 1
if line <= 2 { sieve_from = 1 }
fill_segmented_sieve(sieve_from, sieve_to)
for y in (line - 1)..(line + 2) {
for x in 1..(y + 1) {
if is_prime_in_segment(x, y) {
let mut count_primes: i32 = 0
let mut dx: i64 = 0 - 1
while dx <= 1 {
let mut dy: i64 = 0 - 1
while dy <= 1 {
if count_primes < 3 && is_prime_in_segment(x + dx, y + dy) {
count_primes = count_primes + 1
}
dy = dy + 1
}
dx = dx + 1
}
if count_primes >= 3 {
three_plus[get_number(x, y) - segment_start] = 1
} else {
three_plus[get_number(x, y) - segment_start] = 0
}
}
}
}
let mut total: i64 = 0
for x in 1..(line + 1) {
if is_prime_in_segment(x, line) {
let mut at_least: bool = false
let mut dx: i64 = 0 - 1
while dx <= 1 {
let mut dy: i64 = 0 - 1
while dy <= 1 {
if three_plus[get_number(x + dx, line + dy) - segment_start] == 1 {
at_least = true
}
dy = dy + 1
}
dx = dx + 1
}
if at_least {
total = total + get_number(x, line)
}
}
}
return total
}
function main() -> i32 {
let one: i64 = 5678027
let two: i64 = 7208785
printf("%lld\n", process_line(one) + process_line(two))
if sieve != null { free(sieve) }
if segment != null { free(segment) }
if three_plus != null { free(three_plus) }
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 isqrt_i64(int64_t n);
void fill_sieve_i64(int64_t size);
bool is_prime_small_i64(int64_t x);
int64_t get_number_i64_i64(int64_t x, int64_t y);
void fill_segmented_sieve_i64_i64(int64_t from_val, int64_t to_val);
bool is_prime_in_segment_i64_i64(int64_t x, int64_t y);
int64_t process_line_i64(int64_t line);
int32_t main(void);
/* Module statics */
static int8_t* sieve = NULL;
static int64_t sieve_half = 0;
static int8_t* segment = NULL;
static int64_t segment_len = 0;
static int64_t segment_start = 0;
static int8_t* three_plus = NULL;
int64_t isqrt_i64(int64_t n) {
if (n <= 0) {
return 0;
}
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;
}
void fill_sieve_i64(int64_t size) {
int64_t half = (FLOW_CHECKED_SHR((size), (1)) + 1);
if (sieve_half >= half) {
return;
}
if (sieve != NULL) {
free(sieve);
}
sieve = calloc(half, 1);
sieve_half = half;
int64_t i = 0;
while (i < half) {
sieve[i] = 1;
i = (i + 1);
}
sieve[0] = 0;
i = 1;
while (((2 * i) * i) < half) {
if (sieve[i] == 1) {
int64_t current = ((3 * i) + 1);
int64_t step = ((2 * i) + 1);
while (current < half) {
sieve[current] = 0;
current = (current + step);
}
}
i = (i + 1);
}
}
bool is_prime_small_i64(int64_t x) {
if (FLOW_CHECKED_MOD((x), (2)) == 0) {
return x == 2;
}
return sieve[FLOW_CHECKED_SHR((x), (1))] == 1;
}
int64_t get_number_i64_i64(int64_t x, int64_t y) {
return (x + FLOW_CHECKED_DIV(((y * (y - 1))), (2)));
}
void fill_segmented_sieve_i64_i64(int64_t from_val, int64_t to_val) {
fill_sieve_i64(isqrt_i64(to_val));
segment_start = (from_val | 1);
int64_t num_values = ((to_val - from_val) + 1);
if (segment != NULL) {
free(segment);
}
if (three_plus != NULL) {
free(three_plus);
}
segment_len = (num_values + 1);
segment = calloc(segment_len, 1);
three_plus = calloc(segment_len, 1);
int32_t __flow_step_1 = 1;
for (int32_t i = 0; (0 <= segment_len) ? i < segment_len : i > segment_len; i += (0 <= segment_len) ? 1 : -1) {
segment[i] = 1;
three_plus[i] = 0;
}
int64_t lim = isqrt_i64(to_val);
int32_t __flow_step_2 = 2;
for (int32_t p = 3; (__flow_step_2 > 0) ? p < (lim + 1) : p > (lim + 1); p += __flow_step_2) {
if (is_prime_small_i64(p)) {
int64_t smallest = ((from_val - FLOW_CHECKED_MOD((from_val), (p))) + p);
if (FLOW_CHECKED_MOD((smallest), (2)) == 0) {
smallest = (smallest + p);
}
int64_t j = smallest;
while (j <= to_val) {
segment[FLOW_CHECKED_DIV(((j - segment_start)), (2))] = 0;
j = (j + (2 * p));
}
}
}
}
bool is_prime_in_segment_i64_i64(int64_t x, int64_t y) {
if ((x < 1 || x > y)) {
return 0;
}
int64_t current = get_number_i64_i64(x, y);
if (FLOW_CHECKED_MOD((current), (2)) == 0) {
return current == 2;
}
return segment[FLOW_CHECKED_DIV(((current - segment_start)), (2))] == 1;
}
int64_t process_line_i64(int64_t line) {
int64_t sieve_from = get_number_i64_i64(1, (line - 2));
int64_t sieve_to = (get_number_i64_i64(1, (line + 3)) - 1);
if (line <= 2) {
sieve_from = 1;
}
fill_segmented_sieve_i64_i64(sieve_from, sieve_to);
int32_t __flow_step_3 = 1;
for (int32_t y = (line - 1); ((line - 1) <= (line + 2)) ? y < (line + 2) : y > (line + 2); y += ((line - 1) <= (line + 2)) ? 1 : -1) {
int32_t __flow_step_4 = 1;
for (int32_t x = 1; (1 <= (y + 1)) ? x < (y + 1) : x > (y + 1); x += (1 <= (y + 1)) ? 1 : -1) {
if (is_prime_in_segment_i64_i64(x, y)) {
int32_t count_primes = 0;
int64_t dx = (0 - 1);
while (dx <= 1) {
int64_t dy = (0 - 1);
while (dy <= 1) {
if ((count_primes < 3 && is_prime_in_segment_i64_i64((x + dx), (y + dy)))) {
count_primes = (count_primes + 1);
}
dy = (dy + 1);
}
dx = (dx + 1);
}
if (count_primes >= 3) {
three_plus[(get_number_i64_i64(x, y) - segment_start)] = 1;
} else {
three_plus[(get_number_i64_i64(x, y) - segment_start)] = 0;
}
}
}
}
int64_t total = 0;
int32_t __flow_step_5 = 1;
for (int32_t x = 1; (1 <= (line + 1)) ? x < (line + 1) : x > (line + 1); x += (1 <= (line + 1)) ? 1 : -1) {
if (is_prime_in_segment_i64_i64(x, line)) {
bool at_least = 0;
int64_t dx = (0 - 1);
while (dx <= 1) {
int64_t dy = (0 - 1);
while (dy <= 1) {
if (three_plus[(get_number_i64_i64((x + dx), (line + dy)) - segment_start)] == 1) {
at_least = 1;
}
dy = (dy + 1);
}
dx = (dx + 1);
}
if (at_least) {
total = (total + get_number_i64_i64(x, line));
}
}
}
return total;
}
int32_t main(void) {
int64_t one = 5678027;
int64_t two = 7208785;
printf("%lld\n", (process_line_i64(one) + process_line_i64(two)));
if (sieve != NULL) {
free(sieve);
}
if (segment != NULL) {
free(segment);
}
if (three_plus != NULL) {
free(three_plus);
}
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 @memset(!llvm.ptr, i32, i64) -> !llvm.ptr
// Module static: sieve
llvm.mlir.global internal @sieve() {addr_space = 0 : i32} : !llvm.ptr {
%0 = llvm.mlir.zero : !llvm.ptr
llvm.return %0 : !llvm.ptr
}
// Module static: sieve_half
llvm.mlir.global internal @sieve_half(0 : i64) : i64
// Module static: segment
llvm.mlir.global internal @segment() {addr_space = 0 : i32} : !llvm.ptr {
%1 = llvm.mlir.zero : !llvm.ptr
llvm.return %1 : !llvm.ptr
}
// Module static: segment_len
llvm.mlir.global internal @segment_len(0 : i64) : i64
// Module static: segment_start
llvm.mlir.global internal @segment_start(0 : i64) : i64
// Module static: three_plus
llvm.mlir.global internal @three_plus() {addr_space = 0 : i32} : !llvm.ptr {
%2 = llvm.mlir.zero : !llvm.ptr
llvm.return %2 : !llvm.ptr
}
func.func @isqrt(%arg0: i64) -> i64 {
%3 = arith.constant 0 : i32
%5 = arith.extsi %3 : i32 to i64
%4 = arith.cmpi sle, %arg0, %5 : i64
cf.cond_br %4, ^bb0, ^bb1
^bb0:
%6 = arith.constant 0 : i32
%7 = arith.extsi %6 : i32 to i64
func.return %7 : i64
^bb1:
cf.br ^bb2
^bb2:
%8 = llvm.mlir.constant(1 : i64) : i64
%9 = llvm.alloca %8 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %9 : i64, !llvm.ptr
%10 = llvm.load %9 : !llvm.ptr -> i64
%11 = arith.constant 1 : i32
%13 = arith.extsi %11 : i32 to i64
%12 = arith.addi %10, %13 : i64
%14 = arith.constant 2 : i32
%16 = arith.extsi %14 : i32 to i64
%15 = arith.divsi %12, %16 : i64
%17 = llvm.mlir.constant(1 : i64) : i64
%18 = llvm.alloca %17 x i64 : (i64) -> !llvm.ptr
llvm.store %15, %18 : i64, !llvm.ptr
cf.br ^bb3
^bb3:
%19 = llvm.load %18 : !llvm.ptr -> i64
%20 = llvm.load %9 : !llvm.ptr -> i64
%21 = arith.cmpi slt, %19, %20 : i64
cf.cond_br %21, ^bb4, ^bb5
^bb4:
%22 = llvm.load %18 : !llvm.ptr -> i64
llvm.store %22, %9 : i64, !llvm.ptr
%23 = llvm.load %9 : !llvm.ptr -> i64
%24 = llvm.load %9 : !llvm.ptr -> i64
%25 = arith.divsi %arg0, %24 : i64
%26 = arith.addi %23, %25 : i64
%27 = arith.constant 2 : i32
%29 = arith.extsi %27 : i32 to i64
%28 = arith.divsi %26, %29 : i64
llvm.store %28, %18 : i64, !llvm.ptr
cf.br ^bb3
^bb5:
%30 = llvm.load %9 : !llvm.ptr -> i64
func.return %30 : i64
}
func.func @fill_sieve(%arg0: i64) -> () {
%31 = arith.constant 1 : i32
%33 = arith.extsi %31 : i32 to i64
%32 = arith.shrsi %arg0, %33 : i64
%34 = arith.constant 1 : i32
%36 = arith.extsi %34 : i32 to i64
%35 = arith.addi %32, %36 : i64
%37 = llvm.mlir.addressof @sieve_half : !llvm.ptr
%38 = llvm.load %37 : !llvm.ptr -> i64
%39 = arith.cmpi sge, %38, %35 : i64
cf.cond_br %39, ^bb6, ^bb7
^bb6:
func.return
^bb7:
cf.br ^bb8
^bb8:
%40 = llvm.mlir.addressof @sieve : !llvm.ptr
%41 = llvm.load %40 : !llvm.ptr -> !llvm.ptr
%42 = llvm.mlir.zero : !llvm.ptr
%43 = llvm.icmp "ne" %41, %42 : !llvm.ptr
cf.cond_br %43, ^bb9, ^bb10
^bb9:
%45 = llvm.mlir.addressof @sieve : !llvm.ptr
%46 = llvm.load %45 : !llvm.ptr -> !llvm.ptr
func.call @free(%46) : (!llvm.ptr) -> ()
cf.br ^bb11
^bb10:
cf.br ^bb11
^bb11:
%48 = arith.constant 1 : i32
%49 = arith.extsi %48 : i32 to i64
%47 = func.call @calloc(%35, %49) : (i64, i64) -> !llvm.ptr
%50 = llvm.mlir.addressof @sieve : !llvm.ptr
llvm.store %47, %50 : !llvm.ptr, !llvm.ptr
%51 = llvm.mlir.addressof @sieve_half : !llvm.ptr
llvm.store %35, %51 : i64, !llvm.ptr
%52 = arith.constant 0 : i32
%53 = arith.extsi %52 : i32 to i64
%54 = llvm.mlir.constant(1 : i64) : i64
%55 = llvm.alloca %54 x i64 : (i64) -> !llvm.ptr
llvm.store %53, %55 : i64, !llvm.ptr
cf.br ^bb12
^bb12:
%56 = llvm.load %55 : !llvm.ptr -> i64
%57 = arith.cmpi slt, %56, %35 : i64
cf.cond_br %57, ^bb13, ^bb14
^bb13:
%58 = arith.constant 1 : i32
%59 = llvm.mlir.addressof @sieve : !llvm.ptr
%60 = llvm.load %59 : !llvm.ptr -> !llvm.ptr
%61 = llvm.load %55 : !llvm.ptr -> i64
%62 = arith.trunci %58 : i32 to i8
%63 = llvm.getelementptr %60[%61] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %62, %63 : i8, !llvm.ptr
%64 = llvm.load %55 : !llvm.ptr -> i64
%65 = arith.constant 1 : i32
%67 = arith.extsi %65 : i32 to i64
%66 = arith.addi %64, %67 : i64
llvm.store %66, %55 : i64, !llvm.ptr
cf.br ^bb12
^bb14:
%68 = arith.constant 0 : i32
%69 = llvm.mlir.addressof @sieve : !llvm.ptr
%70 = llvm.load %69 : !llvm.ptr -> !llvm.ptr
%71 = arith.constant 0 : i32
%72 = arith.trunci %68 : i32 to i8
%73 = arith.extsi %71 : i32 to i64
%74 = llvm.getelementptr %70[%73] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %72, %74 : i8, !llvm.ptr
%75 = arith.constant 1 : i32
%76 = arith.extsi %75 : i32 to i64
llvm.store %76, %55 : i64, !llvm.ptr
cf.br ^bb15
^bb15:
%77 = arith.constant 2 : i32
%78 = llvm.load %55 : !llvm.ptr -> i64
%80 = arith.extsi %77 : i32 to i64
%79 = arith.muli %80, %78 : i64
%81 = llvm.load %55 : !llvm.ptr -> i64
%82 = arith.muli %79, %81 : i64
%83 = arith.cmpi slt, %82, %35 : i64
cf.cond_br %83, ^bb16, ^bb17
^bb16:
%85 = llvm.mlir.addressof @sieve : !llvm.ptr
%86 = llvm.load %85 : !llvm.ptr -> !llvm.ptr
%87 = llvm.load %55 : !llvm.ptr -> i64
%88 = llvm.getelementptr %86[%87] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%84 = llvm.load %88 : !llvm.ptr -> i8
%89 = arith.constant 1 : i32
%91 = arith.extsi %84 : i8 to i32
%90 = arith.cmpi eq, %91, %89 : i32
cf.cond_br %90, ^bb18, ^bb19
^bb18:
%92 = arith.constant 3 : i32
%93 = llvm.load %55 : !llvm.ptr -> i64
%95 = arith.extsi %92 : i32 to i64
%94 = arith.muli %95, %93 : i64
%96 = arith.constant 1 : i32
%98 = arith.extsi %96 : i32 to i64
%97 = arith.addi %94, %98 : i64
%99 = llvm.mlir.constant(1 : i64) : i64
%100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
llvm.store %97, %100 : i64, !llvm.ptr
%101 = arith.constant 2 : i32
%102 = llvm.load %55 : !llvm.ptr -> i64
%104 = arith.extsi %101 : i32 to i64
%103 = arith.muli %104, %102 : i64
%105 = arith.constant 1 : i32
%107 = arith.extsi %105 : i32 to i64
%106 = arith.addi %103, %107 : i64
cf.br ^bb21
^bb21:
%108 = llvm.load %100 : !llvm.ptr -> i64
%109 = arith.cmpi slt, %108, %35 : i64
cf.cond_br %109, ^bb22, ^bb23
^bb22:
%110 = arith.constant 0 : i32
%111 = llvm.mlir.addressof @sieve : !llvm.ptr
%112 = llvm.load %111 : !llvm.ptr -> !llvm.ptr
%113 = llvm.load %100 : !llvm.ptr -> i64
%114 = arith.trunci %110 : i32 to i8
%115 = llvm.getelementptr %112[%113] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %114, %115 : i8, !llvm.ptr
%116 = llvm.load %100 : !llvm.ptr -> i64
%117 = arith.addi %116, %106 : i64
llvm.store %117, %100 : i64, !llvm.ptr
cf.br ^bb21
^bb23:
cf.br ^bb20
^bb19:
cf.br ^bb20
^bb20:
%118 = llvm.load %55 : !llvm.ptr -> i64
%119 = arith.constant 1 : i32
%121 = arith.extsi %119 : i32 to i64
%120 = arith.addi %118, %121 : i64
llvm.store %120, %55 : i64, !llvm.ptr
cf.br ^bb15
^bb17:
func.return
}
func.func @is_prime_small(%arg0: i64) -> i1 {
%122 = arith.constant 2 : i32
%124 = arith.extsi %122 : i32 to i64
%123 = arith.remsi %arg0, %124 : i64
%125 = arith.constant 0 : i32
%127 = arith.extsi %125 : i32 to i64
%126 = arith.cmpi eq, %123, %127 : i64
cf.cond_br %126, ^bb24, ^bb25
^bb24:
%128 = arith.constant 2 : i32
%130 = arith.extsi %128 : i32 to i64
%129 = arith.cmpi eq, %arg0, %130 : i64
func.return %129 : i1
^bb25:
cf.br ^bb26
^bb26:
%132 = llvm.mlir.addressof @sieve : !llvm.ptr
%133 = llvm.load %132 : !llvm.ptr -> !llvm.ptr
%134 = arith.constant 1 : i32
%136 = arith.extsi %134 : i32 to i64
%135 = arith.shrsi %arg0, %136 : i64
%137 = llvm.getelementptr %133[%135] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%131 = llvm.load %137 : !llvm.ptr -> i8
%138 = arith.constant 1 : i32
%140 = arith.extsi %131 : i8 to i32
%139 = arith.cmpi eq, %140, %138 : i32
func.return %139 : i1
}
func.func @get_number(%arg0: i64, %arg1: i64) -> i64 {
%141 = arith.constant 1 : i32
%143 = arith.extsi %141 : i32 to i64
%142 = arith.subi %arg1, %143 : i64
%144 = arith.muli %arg1, %142 : i64
%145 = arith.constant 2 : i32
%147 = arith.extsi %145 : i32 to i64
%146 = arith.divsi %144, %147 : i64
%148 = arith.addi %arg0, %146 : i64
func.return %148 : i64
}
func.func @fill_segmented_sieve(%arg0: i64, %arg1: i64) -> () {
%150 = func.call @isqrt(%arg1) : (i64) -> i64
func.call @fill_sieve(%150) : (i64) -> ()
%151 = arith.constant 1 : i32
%153 = arith.extsi %151 : i32 to i64
%152 = arith.ori %arg0, %153 : i64
%154 = llvm.mlir.addressof @segment_start : !llvm.ptr
llvm.store %152, %154 : i64, !llvm.ptr
%155 = arith.subi %arg1, %arg0 : i64
%156 = arith.constant 1 : i32
%158 = arith.extsi %156 : i32 to i64
%157 = arith.addi %155, %158 : i64
%159 = llvm.mlir.addressof @segment : !llvm.ptr
%160 = llvm.load %159 : !llvm.ptr -> !llvm.ptr
%161 = llvm.mlir.zero : !llvm.ptr
%162 = llvm.icmp "ne" %160, %161 : !llvm.ptr
cf.cond_br %162, ^bb27, ^bb28
^bb27:
%164 = llvm.mlir.addressof @segment : !llvm.ptr
%165 = llvm.load %164 : !llvm.ptr -> !llvm.ptr
func.call @free(%165) : (!llvm.ptr) -> ()
cf.br ^bb29
^bb28:
cf.br ^bb29
^bb29:
%166 = llvm.mlir.addressof @three_plus : !llvm.ptr
%167 = llvm.load %166 : !llvm.ptr -> !llvm.ptr
%168 = llvm.mlir.zero : !llvm.ptr
%169 = llvm.icmp "ne" %167, %168 : !llvm.ptr
cf.cond_br %169, ^bb30, ^bb31
^bb30:
%171 = llvm.mlir.addressof @three_plus : !llvm.ptr
%172 = llvm.load %171 : !llvm.ptr -> !llvm.ptr
func.call @free(%172) : (!llvm.ptr) -> ()
cf.br ^bb32
^bb31:
cf.br ^bb32
^bb32:
%173 = arith.constant 1 : i32
%175 = arith.extsi %173 : i32 to i64
%174 = arith.addi %157, %175 : i64
%176 = llvm.mlir.addressof @segment_len : !llvm.ptr
llvm.store %174, %176 : i64, !llvm.ptr
%178 = llvm.mlir.addressof @segment_len : !llvm.ptr
%179 = llvm.load %178 : !llvm.ptr -> i64
%180 = arith.constant 1 : i32
%181 = arith.extsi %180 : i32 to i64
%177 = func.call @calloc(%179, %181) : (i64, i64) -> !llvm.ptr
%182 = llvm.mlir.addressof @segment : !llvm.ptr
llvm.store %177, %182 : !llvm.ptr, !llvm.ptr
%184 = llvm.mlir.addressof @segment_len : !llvm.ptr
%185 = llvm.load %184 : !llvm.ptr -> i64
%186 = arith.constant 1 : i32
%187 = arith.extsi %186 : i32 to i64
%183 = func.call @calloc(%185, %187) : (i64, i64) -> !llvm.ptr
%188 = llvm.mlir.addressof @three_plus : !llvm.ptr
llvm.store %183, %188 : !llvm.ptr, !llvm.ptr
%189 = arith.constant 0 : i32
%190 = llvm.mlir.addressof @segment_len : !llvm.ptr
%191 = llvm.load %190 : !llvm.ptr -> i64
%192 = arith.index_cast %189 : i32 to index
%193 = arith.index_cast %191 : i32 to index
%195 = arith.constant 1 : index
%196 = arith.constant -1 : index
%197 = arith.cmpi sle, %192, %193 : index
%194 = arith.select %197, %195, %196 : index
cf.br ^bb33(%192 : index)
^bb33(%198: index):
%199 = arith.cmpi slt, %198, %193 : index
%200 = arith.cmpi sgt, %198, %193 : index
%201 = arith.select %197, %199, %200 : i1
cf.cond_br %201, ^bb34(%198 : index), ^bb35(%198 : index)
^bb34(%202: index):
%203 = arith.constant 1 : i32
%204 = llvm.mlir.addressof @segment : !llvm.ptr
%205 = llvm.load %204 : !llvm.ptr -> !llvm.ptr
%206 = arith.trunci %203 : i32 to i8
%207 = arith.index_cast %202 : index to i64
%208 = llvm.getelementptr %205[%207] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %206, %208 : i8, !llvm.ptr
%209 = arith.constant 0 : i32
%210 = llvm.mlir.addressof @three_plus : !llvm.ptr
%211 = llvm.load %210 : !llvm.ptr -> !llvm.ptr
%212 = arith.trunci %209 : i32 to i8
%213 = arith.index_cast %202 : index to i64
%214 = llvm.getelementptr %211[%213] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %212, %214 : i8, !llvm.ptr
%215 = arith.addi %202, %194 : index
cf.br ^bb33(%215 : index)
^bb35(%216: index):
%217 = func.call @isqrt(%arg1) : (i64) -> i64
%218 = arith.constant 3 : i32
%219 = arith.constant 1 : i32
%221 = arith.extsi %219 : i32 to i64
%220 = arith.addi %217, %221 : i64
%222 = arith.index_cast %218 : i32 to index
%223 = arith.index_cast %220 : i32 to index
%224 = arith.constant 2 : index
cf.br ^bb36(%222 : index)
^bb36(%225: index):
%226 = arith.cmpi slt, %225, %223 : index
cf.cond_br %226, ^bb37(%225 : index), ^bb38(%225 : index)
^bb37(%227: index):
%229 = arith.index_cast %227 : index to i64
%228 = func.call @is_prime_small(%229) : (i64) -> i1
cf.cond_br %228, ^bb39, ^bb40
^bb39:
%231 = arith.trunci %arg0 : i64 to i32
%232 = arith.index_cast %227 : index to i32
%230 = arith.remsi %231, %232 : i32
%234 = arith.extsi %230 : i32 to i64
%233 = arith.subi %arg0, %234 : i64
%236 = arith.trunci %233 : i64 to i32
%237 = arith.index_cast %227 : index to i32
%235 = arith.addi %236, %237 : i32
%238 = arith.extsi %235 : i32 to i64
%239 = llvm.mlir.constant(1 : i64) : i64
%240 = llvm.alloca %239 x i64 : (i64) -> !llvm.ptr
llvm.store %238, %240 : i64, !llvm.ptr
%241 = llvm.load %240 : !llvm.ptr -> i64
%242 = arith.constant 2 : i32
%244 = arith.extsi %242 : i32 to i64
%243 = arith.remsi %241, %244 : i64
%245 = arith.constant 0 : i32
%247 = arith.extsi %245 : i32 to i64
%246 = arith.cmpi eq, %243, %247 : i64
cf.cond_br %246, ^bb42, ^bb43
^bb42:
%248 = llvm.load %240 : !llvm.ptr -> i64
%250 = arith.trunci %248 : i64 to i32
%251 = arith.index_cast %227 : index to i32
%249 = arith.addi %250, %251 : i32
%252 = arith.extsi %249 : i32 to i64
llvm.store %252, %240 : i64, !llvm.ptr
cf.br ^bb44
^bb43:
cf.br ^bb44
^bb44:
%253 = llvm.load %240 : !llvm.ptr -> i64
%254 = llvm.mlir.constant(1 : i64) : i64
%255 = llvm.alloca %254 x i64 : (i64) -> !llvm.ptr
llvm.store %253, %255 : i64, !llvm.ptr
cf.br ^bb45
^bb45:
%256 = llvm.load %255 : !llvm.ptr -> i64
%257 = arith.cmpi sle, %256, %arg1 : i64
cf.cond_br %257, ^bb46, ^bb47
^bb46:
%258 = arith.constant 0 : i32
%259 = llvm.mlir.addressof @segment : !llvm.ptr
%260 = llvm.load %259 : !llvm.ptr -> !llvm.ptr
%261 = llvm.load %255 : !llvm.ptr -> i64
%262 = llvm.mlir.addressof @segment_start : !llvm.ptr
%263 = llvm.load %262 : !llvm.ptr -> i64
%264 = arith.subi %261, %263 : i64
%265 = arith.constant 2 : i32
%267 = arith.extsi %265 : i32 to i64
%266 = arith.divsi %264, %267 : i64
%268 = arith.trunci %258 : i32 to i8
%269 = llvm.getelementptr %260[%266] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %268, %269 : i8, !llvm.ptr
%270 = llvm.load %255 : !llvm.ptr -> i64
%271 = arith.constant 2 : i32
%273 = arith.index_cast %227 : index to i32
%272 = arith.muli %271, %273 : i32
%275 = arith.extsi %272 : i32 to i64
%274 = arith.addi %270, %275 : i64
llvm.store %274, %255 : i64, !llvm.ptr
cf.br ^bb45
^bb47:
cf.br ^bb41
^bb40:
cf.br ^bb41
^bb41:
%276 = arith.addi %227, %224 : index
cf.br ^bb36(%276 : index)
^bb38(%277: index):
func.return
}
func.func @is_prime_in_segment(%arg0: i64, %arg1: i64) -> i1 {
%278 = arith.constant 1 : i32
%280 = arith.extsi %278 : i32 to i64
%279 = arith.cmpi slt, %arg0, %280 : i64
%281 = scf.if %279 -> (i1) {
%282 = arith.constant true
scf.yield %282 : i1
} else {
%283 = arith.cmpi sgt, %arg0, %arg1 : i64
scf.yield %283 : i1
}
cf.cond_br %281, ^bb48, ^bb49
^bb48:
%284 = arith.constant 0 : i1
func.return %284 : i1
^bb49:
cf.br ^bb50
^bb50:
%285 = func.call @get_number(%arg0, %arg1) : (i64, i64) -> i64
%286 = arith.constant 2 : i32
%288 = arith.extsi %286 : i32 to i64
%287 = arith.remsi %285, %288 : i64
%289 = arith.constant 0 : i32
%291 = arith.extsi %289 : i32 to i64
%290 = arith.cmpi eq, %287, %291 : i64
cf.cond_br %290, ^bb51, ^bb52
^bb51:
%292 = arith.constant 2 : i32
%294 = arith.extsi %292 : i32 to i64
%293 = arith.cmpi eq, %285, %294 : i64
func.return %293 : i1
^bb52:
cf.br ^bb53
^bb53:
%296 = llvm.mlir.addressof @segment : !llvm.ptr
%297 = llvm.load %296 : !llvm.ptr -> !llvm.ptr
%298 = llvm.mlir.addressof @segment_start : !llvm.ptr
%299 = llvm.load %298 : !llvm.ptr -> i64
%300 = arith.subi %285, %299 : i64
%301 = arith.constant 2 : i32
%303 = arith.extsi %301 : i32 to i64
%302 = arith.divsi %300, %303 : i64
%304 = llvm.getelementptr %297[%302] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%295 = llvm.load %304 : !llvm.ptr -> i8
%305 = arith.constant 1 : i32
%307 = arith.extsi %295 : i8 to i32
%306 = arith.cmpi eq, %307, %305 : i32
func.return %306 : i1
}
func.func @process_line(%arg0: i64) -> i64 {
%309 = arith.constant 1 : i32
%310 = arith.constant 2 : i32
%312 = arith.extsi %310 : i32 to i64
%311 = arith.subi %arg0, %312 : i64
%313 = arith.extsi %309 : i32 to i64
%308 = func.call @get_number(%313, %311) : (i64, i64) -> i64
%314 = llvm.mlir.constant(1 : i64) : i64
%315 = llvm.alloca %314 x i64 : (i64) -> !llvm.ptr
llvm.store %308, %315 : i64, !llvm.ptr
%317 = arith.constant 1 : i32
%318 = arith.constant 3 : i32
%320 = arith.extsi %318 : i32 to i64
%319 = arith.addi %arg0, %320 : i64
%321 = arith.extsi %317 : i32 to i64
%316 = func.call @get_number(%321, %319) : (i64, i64) -> i64
%322 = arith.constant 1 : i32
%324 = arith.extsi %322 : i32 to i64
%323 = arith.subi %316, %324 : i64
%325 = arith.constant 2 : i32
%327 = arith.extsi %325 : i32 to i64
%326 = arith.cmpi sle, %arg0, %327 : i64
cf.cond_br %326, ^bb54, ^bb55
^bb54:
%328 = arith.constant 1 : i32
%329 = arith.extsi %328 : i32 to i64
llvm.store %329, %315 : i64, !llvm.ptr
cf.br ^bb56
^bb55:
cf.br ^bb56
^bb56:
%331 = llvm.load %315 : !llvm.ptr -> i64
func.call @fill_segmented_sieve(%331, %323) : (i64, i64) -> ()
%332 = arith.constant 1 : i32
%334 = arith.extsi %332 : i32 to i64
%333 = arith.subi %arg0, %334 : i64
%335 = arith.constant 2 : i32
%337 = arith.extsi %335 : i32 to i64
%336 = arith.addi %arg0, %337 : i64
%338 = arith.index_cast %333 : i32 to index
%339 = arith.index_cast %336 : i32 to index
%341 = arith.constant 1 : index
%342 = arith.constant -1 : index
%343 = arith.cmpi sle, %338, %339 : index
%340 = arith.select %343, %341, %342 : index
cf.br ^bb57(%338 : index)
^bb57(%344: index):
%345 = arith.cmpi slt, %344, %339 : index
%346 = arith.cmpi sgt, %344, %339 : index
%347 = arith.select %343, %345, %346 : i1
cf.cond_br %347, ^bb58(%344 : index), ^bb59(%344 : index)
^bb58(%348: index):
%349 = arith.constant 1 : i32
%350 = arith.constant 1 : i32
%352 = arith.index_cast %348 : index to i32
%351 = arith.addi %352, %350 : i32
%353 = arith.index_cast %349 : i32 to index
%354 = arith.index_cast %351 : i32 to index
%356 = arith.constant 1 : index
%357 = arith.constant -1 : index
%358 = arith.cmpi sle, %353, %354 : index
%355 = arith.select %358, %356, %357 : index
cf.br ^bb60(%353 : index)
^bb60(%359: index):
%360 = arith.cmpi slt, %359, %354 : index
%361 = arith.cmpi sgt, %359, %354 : index
%362 = arith.select %358, %360, %361 : i1
cf.cond_br %362, ^bb61(%359 : index), ^bb62(%359 : index)
^bb61(%363: index):
%365 = arith.index_cast %363 : index to i64
%366 = arith.index_cast %348 : index to i64
%364 = func.call @is_prime_in_segment(%365, %366) : (i64, i64) -> i1
cf.cond_br %364, ^bb63, ^bb64
^bb63:
%367 = arith.constant 0 : i32
%368 = llvm.mlir.constant(1 : i64) : i64
%369 = llvm.alloca %368 x i32 : (i64) -> !llvm.ptr
llvm.store %367, %369 : i32, !llvm.ptr
%370 = arith.constant 0 : i32
%371 = arith.constant 1 : i32
%372 = arith.subi %370, %371 : i32
%373 = arith.extsi %372 : i32 to i64
%374 = llvm.mlir.constant(1 : i64) : i64
%375 = llvm.alloca %374 x i64 : (i64) -> !llvm.ptr
llvm.store %373, %375 : i64, !llvm.ptr
cf.br ^bb66
^bb66:
%376 = llvm.load %375 : !llvm.ptr -> i64
%377 = arith.constant 1 : i32
%379 = arith.extsi %377 : i32 to i64
%378 = arith.cmpi sle, %376, %379 : i64
cf.cond_br %378, ^bb67, ^bb68
^bb67:
%380 = arith.constant 0 : i32
%381 = arith.constant 1 : i32
%382 = arith.subi %380, %381 : i32
%383 = arith.extsi %382 : i32 to i64
%384 = llvm.mlir.constant(1 : i64) : i64
%385 = llvm.alloca %384 x i64 : (i64) -> !llvm.ptr
llvm.store %383, %385 : i64, !llvm.ptr
cf.br ^bb69
^bb69:
%386 = llvm.load %385 : !llvm.ptr -> i64
%387 = arith.constant 1 : i32
%389 = arith.extsi %387 : i32 to i64
%388 = arith.cmpi sle, %386, %389 : i64
cf.cond_br %388, ^bb70, ^bb71
^bb70:
%390 = llvm.load %369 : !llvm.ptr -> i32
%391 = arith.constant 3 : i32
%392 = arith.cmpi slt, %390, %391 : i32
%393 = scf.if %392 -> (i1) {
%395 = llvm.load %375 : !llvm.ptr -> i64
%397 = arith.index_cast %363 : index to i32
%398 = arith.trunci %395 : i64 to i32
%396 = arith.addi %397, %398 : i32
%399 = llvm.load %385 : !llvm.ptr -> i64
%401 = arith.index_cast %348 : index to i32
%402 = arith.trunci %399 : i64 to i32
%400 = arith.addi %401, %402 : i32
%403 = arith.extsi %396 : i32 to i64
%404 = arith.extsi %400 : i32 to i64
%394 = func.call @is_prime_in_segment(%403, %404) : (i64, i64) -> i1
scf.yield %394 : i1
} else {
%405 = arith.constant false
scf.yield %405 : i1
}
cf.cond_br %393, ^bb72, ^bb73
^bb72:
%406 = llvm.load %369 : !llvm.ptr -> i32
%407 = arith.constant 1 : i32
%408 = arith.addi %406, %407 : i32
llvm.store %408, %369 : i32, !llvm.ptr
cf.br ^bb74
^bb73:
cf.br ^bb74
^bb74:
%409 = llvm.load %385 : !llvm.ptr -> i64
%410 = arith.constant 1 : i32
%412 = arith.extsi %410 : i32 to i64
%411 = arith.addi %409, %412 : i64
llvm.store %411, %385 : i64, !llvm.ptr
cf.br ^bb69
^bb71:
%413 = llvm.load %375 : !llvm.ptr -> i64
%414 = arith.constant 1 : i32
%416 = arith.extsi %414 : i32 to i64
%415 = arith.addi %413, %416 : i64
llvm.store %415, %375 : i64, !llvm.ptr
cf.br ^bb66
^bb68:
%417 = llvm.load %369 : !llvm.ptr -> i32
%418 = arith.constant 3 : i32
%419 = arith.cmpi sge, %417, %418 : i32
cf.cond_br %419, ^bb75, ^bb76
^bb75:
%420 = arith.constant 1 : i32
%421 = llvm.mlir.addressof @three_plus : !llvm.ptr
%422 = llvm.load %421 : !llvm.ptr -> !llvm.ptr
%424 = arith.index_cast %363 : index to i64
%425 = arith.index_cast %348 : index to i64
%423 = func.call @get_number(%424, %425) : (i64, i64) -> i64
%426 = llvm.mlir.addressof @segment_start : !llvm.ptr
%427 = llvm.load %426 : !llvm.ptr -> i64
%428 = arith.subi %423, %427 : i64
%429 = arith.trunci %420 : i32 to i8
%430 = llvm.getelementptr %422[%428] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %429, %430 : i8, !llvm.ptr
cf.br ^bb77
^bb76:
%431 = arith.constant 0 : i32
%432 = llvm.mlir.addressof @three_plus : !llvm.ptr
%433 = llvm.load %432 : !llvm.ptr -> !llvm.ptr
%435 = arith.index_cast %363 : index to i64
%436 = arith.index_cast %348 : index to i64
%434 = func.call @get_number(%435, %436) : (i64, i64) -> i64
%437 = llvm.mlir.addressof @segment_start : !llvm.ptr
%438 = llvm.load %437 : !llvm.ptr -> i64
%439 = arith.subi %434, %438 : i64
%440 = arith.trunci %431 : i32 to i8
%441 = llvm.getelementptr %433[%439] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %440, %441 : i8, !llvm.ptr
cf.br ^bb77
^bb77:
cf.br ^bb65
^bb64:
cf.br ^bb65
^bb65:
%442 = arith.addi %363, %355 : index
cf.br ^bb60(%442 : index)
^bb62(%443: index):
%444 = arith.addi %348, %340 : index
cf.br ^bb57(%444 : index)
^bb59(%445: index):
%446 = arith.constant 0 : i32
%447 = arith.extsi %446 : i32 to i64
%448 = llvm.mlir.constant(1 : i64) : i64
%449 = llvm.alloca %448 x i64 : (i64) -> !llvm.ptr
llvm.store %447, %449 : i64, !llvm.ptr
%450 = arith.constant 1 : i32
%451 = arith.constant 1 : i32
%453 = arith.extsi %451 : i32 to i64
%452 = arith.addi %arg0, %453 : i64
%454 = arith.index_cast %450 : i32 to index
%455 = arith.index_cast %452 : i32 to index
%457 = arith.constant 1 : index
%458 = arith.constant -1 : index
%459 = arith.cmpi sle, %454, %455 : index
%456 = arith.select %459, %457, %458 : index
cf.br ^bb78(%454 : index)
^bb78(%460: index):
%461 = arith.cmpi slt, %460, %455 : index
%462 = arith.cmpi sgt, %460, %455 : index
%463 = arith.select %459, %461, %462 : i1
cf.cond_br %463, ^bb79(%460 : index), ^bb80(%460 : index)
^bb79(%464: index):
%466 = arith.index_cast %464 : index to i64
%465 = func.call @is_prime_in_segment(%466, %arg0) : (i64, i64) -> i1
cf.cond_br %465, ^bb81, ^bb82
^bb81:
%467 = arith.constant 0 : i1
%468 = llvm.mlir.constant(1 : i64) : i64
%469 = llvm.alloca %468 x i1 : (i64) -> !llvm.ptr
llvm.store %467, %469 : i1, !llvm.ptr
%470 = arith.constant 0 : i32
%471 = arith.constant 1 : i32
%472 = arith.subi %470, %471 : i32
%473 = arith.extsi %472 : i32 to i64
%474 = llvm.mlir.constant(1 : i64) : i64
%475 = llvm.alloca %474 x i64 : (i64) -> !llvm.ptr
llvm.store %473, %475 : i64, !llvm.ptr
cf.br ^bb84
^bb84:
%476 = llvm.load %475 : !llvm.ptr -> i64
%477 = arith.constant 1 : i32
%479 = arith.extsi %477 : i32 to i64
%478 = arith.cmpi sle, %476, %479 : i64
cf.cond_br %478, ^bb85, ^bb86
^bb85:
%480 = arith.constant 0 : i32
%481 = arith.constant 1 : i32
%482 = arith.subi %480, %481 : i32
%483 = arith.extsi %482 : i32 to i64
%484 = llvm.mlir.constant(1 : i64) : i64
%485 = llvm.alloca %484 x i64 : (i64) -> !llvm.ptr
llvm.store %483, %485 : i64, !llvm.ptr
cf.br ^bb87
^bb87:
%486 = llvm.load %485 : !llvm.ptr -> i64
%487 = arith.constant 1 : i32
%489 = arith.extsi %487 : i32 to i64
%488 = arith.cmpi sle, %486, %489 : i64
cf.cond_br %488, ^bb88, ^bb89
^bb88:
%491 = llvm.mlir.addressof @three_plus : !llvm.ptr
%492 = llvm.load %491 : !llvm.ptr -> !llvm.ptr
%494 = llvm.load %475 : !llvm.ptr -> i64
%496 = arith.index_cast %464 : index to i32
%497 = arith.trunci %494 : i64 to i32
%495 = arith.addi %496, %497 : i32
%498 = llvm.load %485 : !llvm.ptr -> i64
%499 = arith.addi %arg0, %498 : i64
%500 = arith.extsi %495 : i32 to i64
%493 = func.call @get_number(%500, %499) : (i64, i64) -> i64
%501 = llvm.mlir.addressof @segment_start : !llvm.ptr
%502 = llvm.load %501 : !llvm.ptr -> i64
%503 = arith.subi %493, %502 : i64
%504 = llvm.getelementptr %492[%503] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%490 = llvm.load %504 : !llvm.ptr -> i8
%505 = arith.constant 1 : i32
%507 = arith.extsi %490 : i8 to i32
%506 = arith.cmpi eq, %507, %505 : i32
cf.cond_br %506, ^bb90, ^bb91
^bb90:
%508 = arith.constant 1 : i1
llvm.store %508, %469 : i1, !llvm.ptr
cf.br ^bb92
^bb91:
cf.br ^bb92
^bb92:
%509 = llvm.load %485 : !llvm.ptr -> i64
%510 = arith.constant 1 : i32
%512 = arith.extsi %510 : i32 to i64
%511 = arith.addi %509, %512 : i64
llvm.store %511, %485 : i64, !llvm.ptr
cf.br ^bb87
^bb89:
%513 = llvm.load %475 : !llvm.ptr -> i64
%514 = arith.constant 1 : i32
%516 = arith.extsi %514 : i32 to i64
%515 = arith.addi %513, %516 : i64
llvm.store %515, %475 : i64, !llvm.ptr
cf.br ^bb84
^bb86:
%517 = llvm.load %469 : !llvm.ptr -> i1
cf.cond_br %517, ^bb93, ^bb94
^bb93:
%518 = llvm.load %449 : !llvm.ptr -> i64
%520 = arith.index_cast %464 : index to i64
%519 = func.call @get_number(%520, %arg0) : (i64, i64) -> i64
%521 = arith.addi %518, %519 : i64
llvm.store %521, %449 : i64, !llvm.ptr
cf.br ^bb95
^bb94:
cf.br ^bb95
^bb95:
cf.br ^bb83
^bb82:
cf.br ^bb83
^bb83:
%522 = arith.addi %464, %456 : index
cf.br ^bb78(%522 : index)
^bb80(%523: index):
%524 = llvm.load %449 : !llvm.ptr -> i64
func.return %524 : i64
}
func.func @main() -> i32 {
%525 = arith.constant 5678027 : i32
%526 = arith.extsi %525 : i32 to i64
%527 = arith.constant 7208785 : i32
%528 = arith.extsi %527 : i32 to i64
%529 = llvm.mlir.addressof @str_0 : !llvm.ptr
%530 = func.call @process_line(%526) : (i64) -> i64
%531 = func.call @process_line(%528) : (i64) -> i64
%532 = arith.addi %530, %531 : i64
%533 = llvm.call @printf(%529, %532) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
%534 = llvm.mlir.addressof @sieve : !llvm.ptr
%535 = llvm.load %534 : !llvm.ptr -> !llvm.ptr
%536 = llvm.mlir.zero : !llvm.ptr
%537 = llvm.icmp "ne" %535, %536 : !llvm.ptr
cf.cond_br %537, ^bb96, ^bb97
^bb96:
%539 = llvm.mlir.addressof @sieve : !llvm.ptr
%540 = llvm.load %539 : !llvm.ptr -> !llvm.ptr
func.call @free(%540) : (!llvm.ptr) -> ()
cf.br ^bb98
^bb97:
cf.br ^bb98
^bb98:
%541 = llvm.mlir.addressof @segment : !llvm.ptr
%542 = llvm.load %541 : !llvm.ptr -> !llvm.ptr
%543 = llvm.mlir.zero : !llvm.ptr
%544 = llvm.icmp "ne" %542, %543 : !llvm.ptr
cf.cond_br %544, ^bb99, ^bb100
^bb99:
%546 = llvm.mlir.addressof @segment : !llvm.ptr
%547 = llvm.load %546 : !llvm.ptr -> !llvm.ptr
func.call @free(%547) : (!llvm.ptr) -> ()
cf.br ^bb101
^bb100:
cf.br ^bb101
^bb101:
%548 = llvm.mlir.addressof @three_plus : !llvm.ptr
%549 = llvm.load %548 : !llvm.ptr -> !llvm.ptr
%550 = llvm.mlir.zero : !llvm.ptr
%551 = llvm.icmp "ne" %549, %550 : !llvm.ptr
cf.cond_br %551, ^bb102, ^bb103
^bb102:
%553 = llvm.mlir.addressof @three_plus : !llvm.ptr
%554 = llvm.load %553 : !llvm.ptr -> !llvm.ptr
func.call @free(%554) : (!llvm.ptr) -> ()
cf.br ^bb104
^bb103:
cf.br ^bb104
^bb104:
%555 = arith.constant 0 : i32
func.return %555 : i32
}
}