Problem 268
Count numbers <= 10^16 divisible by at least 4 distinct primes <= 100.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n^3) | O(sqrt(n)) |
| Space complexity | O(n) | O(1) |
| Approach | Flow solution | Trial division or Pollard rho |
| Verdict | Suboptimal |
Flow source
# Project Euler 268
# Count numbers <= 10^16 divisible by at least 4 distinct primes <= 100.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
function tetrahedral(n: i64) -> i64 {
return n * (n + 1) * (n + 2) / 6
}
function main() -> i32 {
let primes: ptr<i64> = calloc(25, 8)
primes[0]=2; primes[1]=3; primes[2]=5; primes[3]=7; primes[4]=11
primes[5]=13; primes[6]=17; primes[7]=19; primes[8]=23; primes[9]=29
primes[10]=31; primes[11]=37; primes[12]=41; primes[13]=43; primes[14]=47
primes[15]=53; primes[16]=59; primes[17]=61; primes[18]=67; primes[19]=71
primes[20]=73; primes[21]=79; primes[22]=83; primes[23]=89; primes[24]=97
let num_primes: i64 = 25
let min_primes: i64 = 4
let limit: i64 = 10000000000000000
let count: ptr<i64> = calloc(num_primes + 1, 8)
let mut i: i64 = min_primes
while i <= num_primes {
count[i] = tetrahedral(i - min_primes + 1)
i = i + 1
}
let mut total: i64 = 0
let one: i64 = 1
let max_mask: i64 = (one << num_primes) - 1
let mut mask: i64 = 0
while mask < max_mask {
let mut product: i64 = 1
let mut too_large: bool = false
let mut num_bits: i64 = 0
let mut current: i64 = 0
while current < num_primes {
let bitpos: i64 = one << current
if (mask & bitpos) != 0 {
num_bits = num_bits + 1
if product > limit / primes[current] {
too_large = true
let with_lowest: i64 = mask & (mask - 1)
let mut lowest: i64 = mask - with_lowest
mask = mask + lowest
while (mask & (lowest << 1)) != 0 {
lowest = lowest << 1
mask = mask + lowest
}
mask = mask - 1
break
}
product = product * primes[current]
}
current = current + 1
}
if !too_large && num_bits >= min_primes {
let mut divisible: i64 = limit / product
divisible = divisible * count[num_bits]
if num_bits % 2 == 1 {
total = total - divisible
} else {
total = total + divisible
}
}
mask = mask + 1
}
printf("%lld\n", total)
free(primes); free(count)
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 tetrahedral_i64(int64_t n);
int32_t main(void);
int64_t tetrahedral_i64(int64_t n) {
return FLOW_CHECKED_DIV((((n * (n + 1)) * (n + 2))), (6));
}
int32_t main(void) {
int64_t* primes = (int64_t*)(calloc(25, 8));
primes[0] = 2;
primes[1] = 3;
primes[2] = 5;
primes[3] = 7;
primes[4] = 11;
primes[5] = 13;
primes[6] = 17;
primes[7] = 19;
primes[8] = 23;
primes[9] = 29;
primes[10] = 31;
primes[11] = 37;
primes[12] = 41;
primes[13] = 43;
primes[14] = 47;
primes[15] = 53;
primes[16] = 59;
primes[17] = 61;
primes[18] = 67;
primes[19] = 71;
primes[20] = 73;
primes[21] = 79;
primes[22] = 83;
primes[23] = 89;
primes[24] = 97;
int64_t num_primes = 25;
int64_t min_primes = 4;
int64_t limit = 10000000000000000;
int64_t* count = (int64_t*)(calloc((num_primes + 1), 8));
int64_t i = min_primes;
while (i <= num_primes) {
count[i] = tetrahedral_i64(((i - min_primes) + 1));
i = (i + 1);
}
int64_t total = 0;
int64_t one = 1;
int64_t max_mask = (FLOW_CHECKED_SHL((one), (num_primes)) - 1);
int64_t mask = 0;
while (mask < max_mask) {
int64_t product = 1;
bool too_large = 0;
int64_t num_bits = 0;
int64_t current = 0;
while (current < num_primes) {
int64_t bitpos = FLOW_CHECKED_SHL((one), (current));
if ((mask & bitpos) != 0) {
num_bits = (num_bits + 1);
if (product > FLOW_CHECKED_DIV((limit), (primes[current]))) {
too_large = 1;
int64_t with_lowest = (mask & (mask - 1));
int64_t lowest = (mask - with_lowest);
mask = (mask + lowest);
while ((mask & FLOW_CHECKED_SHL((lowest), (1))) != 0) {
lowest = FLOW_CHECKED_SHL((lowest), (1));
mask = (mask + lowest);
}
mask = (mask - 1);
break;
}
product = (product * primes[current]);
}
current = (current + 1);
}
if (((!(too_large)) && num_bits >= min_primes)) {
int64_t divisible = FLOW_CHECKED_DIV((limit), (product));
divisible = (divisible * count[num_bits]);
if (FLOW_CHECKED_MOD((num_bits), (2)) == 1) {
total = (total - divisible);
} else {
total = (total + divisible);
}
}
mask = (mask + 1);
}
printf("%lld\n", total);
free(primes);
free(count);
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 @tetrahedral(%arg0: i64) -> i64 {
%0 = arith.constant 1 : i32
%2 = arith.extsi %0 : i32 to i64
%1 = arith.addi %arg0, %2 : i64
%3 = arith.muli %arg0, %1 : i64
%4 = arith.constant 2 : i32
%6 = arith.extsi %4 : i32 to i64
%5 = arith.addi %arg0, %6 : i64
%7 = arith.muli %3, %5 : i64
%8 = arith.constant 6 : i32
%10 = arith.extsi %8 : i32 to i64
%9 = arith.divsi %7, %10 : i64
func.return %9 : i64
}
func.func @main() -> i32 {
%12 = arith.constant 25 : i32
%13 = arith.constant 8 : i32
%14 = arith.extsi %12 : i32 to i64
%15 = arith.extsi %13 : i32 to i64
%11 = func.call @calloc(%14, %15) : (i64, i64) -> !llvm.ptr
%16 = arith.constant 2 : i32
%17 = arith.constant 0 : i32
%18 = arith.extsi %16 : i32 to i64
%19 = arith.extsi %17 : i32 to i64
%20 = llvm.getelementptr %11[%19] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %18, %20 : i64, !llvm.ptr
%21 = arith.constant 3 : i32
%22 = arith.constant 1 : i32
%23 = arith.extsi %21 : i32 to i64
%24 = arith.extsi %22 : i32 to i64
%25 = llvm.getelementptr %11[%24] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %23, %25 : i64, !llvm.ptr
%26 = arith.constant 5 : i32
%27 = arith.constant 2 : i32
%28 = arith.extsi %26 : i32 to i64
%29 = arith.extsi %27 : i32 to i64
%30 = llvm.getelementptr %11[%29] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %28, %30 : i64, !llvm.ptr
%31 = arith.constant 7 : i32
%32 = arith.constant 3 : i32
%33 = arith.extsi %31 : i32 to i64
%34 = arith.extsi %32 : i32 to i64
%35 = llvm.getelementptr %11[%34] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %33, %35 : i64, !llvm.ptr
%36 = arith.constant 11 : i32
%37 = arith.constant 4 : i32
%38 = arith.extsi %36 : i32 to i64
%39 = arith.extsi %37 : i32 to i64
%40 = llvm.getelementptr %11[%39] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %38, %40 : i64, !llvm.ptr
%41 = arith.constant 13 : i32
%42 = arith.constant 5 : i32
%43 = arith.extsi %41 : i32 to i64
%44 = arith.extsi %42 : i32 to i64
%45 = llvm.getelementptr %11[%44] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %43, %45 : i64, !llvm.ptr
%46 = arith.constant 17 : i32
%47 = arith.constant 6 : i32
%48 = arith.extsi %46 : i32 to i64
%49 = arith.extsi %47 : i32 to i64
%50 = llvm.getelementptr %11[%49] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %48, %50 : i64, !llvm.ptr
%51 = arith.constant 19 : i32
%52 = arith.constant 7 : i32
%53 = arith.extsi %51 : i32 to i64
%54 = arith.extsi %52 : i32 to i64
%55 = llvm.getelementptr %11[%54] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %53, %55 : i64, !llvm.ptr
%56 = arith.constant 23 : i32
%57 = arith.constant 8 : i32
%58 = arith.extsi %56 : i32 to i64
%59 = arith.extsi %57 : i32 to i64
%60 = llvm.getelementptr %11[%59] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %58, %60 : i64, !llvm.ptr
%61 = arith.constant 29 : i32
%62 = arith.constant 9 : i32
%63 = arith.extsi %61 : i32 to i64
%64 = arith.extsi %62 : i32 to i64
%65 = llvm.getelementptr %11[%64] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %63, %65 : i64, !llvm.ptr
%66 = arith.constant 31 : i32
%67 = arith.constant 10 : i32
%68 = arith.extsi %66 : i32 to i64
%69 = arith.extsi %67 : i32 to i64
%70 = llvm.getelementptr %11[%69] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %68, %70 : i64, !llvm.ptr
%71 = arith.constant 37 : i32
%72 = arith.constant 11 : i32
%73 = arith.extsi %71 : i32 to i64
%74 = arith.extsi %72 : i32 to i64
%75 = llvm.getelementptr %11[%74] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %73, %75 : i64, !llvm.ptr
%76 = arith.constant 41 : i32
%77 = arith.constant 12 : i32
%78 = arith.extsi %76 : i32 to i64
%79 = arith.extsi %77 : i32 to i64
%80 = llvm.getelementptr %11[%79] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %78, %80 : i64, !llvm.ptr
%81 = arith.constant 43 : i32
%82 = arith.constant 13 : i32
%83 = arith.extsi %81 : i32 to i64
%84 = arith.extsi %82 : i32 to i64
%85 = llvm.getelementptr %11[%84] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %83, %85 : i64, !llvm.ptr
%86 = arith.constant 47 : i32
%87 = arith.constant 14 : i32
%88 = arith.extsi %86 : i32 to i64
%89 = arith.extsi %87 : i32 to i64
%90 = llvm.getelementptr %11[%89] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %88, %90 : i64, !llvm.ptr
%91 = arith.constant 53 : i32
%92 = arith.constant 15 : i32
%93 = arith.extsi %91 : i32 to i64
%94 = arith.extsi %92 : i32 to i64
%95 = llvm.getelementptr %11[%94] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %93, %95 : i64, !llvm.ptr
%96 = arith.constant 59 : i32
%97 = arith.constant 16 : i32
%98 = arith.extsi %96 : i32 to i64
%99 = arith.extsi %97 : i32 to i64
%100 = llvm.getelementptr %11[%99] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %98, %100 : i64, !llvm.ptr
%101 = arith.constant 61 : i32
%102 = arith.constant 17 : i32
%103 = arith.extsi %101 : i32 to i64
%104 = arith.extsi %102 : i32 to i64
%105 = llvm.getelementptr %11[%104] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %103, %105 : i64, !llvm.ptr
%106 = arith.constant 67 : i32
%107 = arith.constant 18 : i32
%108 = arith.extsi %106 : i32 to i64
%109 = arith.extsi %107 : i32 to i64
%110 = llvm.getelementptr %11[%109] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %108, %110 : i64, !llvm.ptr
%111 = arith.constant 71 : i32
%112 = arith.constant 19 : i32
%113 = arith.extsi %111 : i32 to i64
%114 = arith.extsi %112 : i32 to i64
%115 = llvm.getelementptr %11[%114] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %113, %115 : i64, !llvm.ptr
%116 = arith.constant 73 : i32
%117 = arith.constant 20 : i32
%118 = arith.extsi %116 : i32 to i64
%119 = arith.extsi %117 : i32 to i64
%120 = llvm.getelementptr %11[%119] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %118, %120 : i64, !llvm.ptr
%121 = arith.constant 79 : i32
%122 = arith.constant 21 : i32
%123 = arith.extsi %121 : i32 to i64
%124 = arith.extsi %122 : i32 to i64
%125 = llvm.getelementptr %11[%124] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %123, %125 : i64, !llvm.ptr
%126 = arith.constant 83 : i32
%127 = arith.constant 22 : i32
%128 = arith.extsi %126 : i32 to i64
%129 = arith.extsi %127 : i32 to i64
%130 = llvm.getelementptr %11[%129] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %128, %130 : i64, !llvm.ptr
%131 = arith.constant 89 : i32
%132 = arith.constant 23 : i32
%133 = arith.extsi %131 : i32 to i64
%134 = arith.extsi %132 : i32 to i64
%135 = llvm.getelementptr %11[%134] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %133, %135 : i64, !llvm.ptr
%136 = arith.constant 97 : i32
%137 = arith.constant 24 : i32
%138 = arith.extsi %136 : i32 to i64
%139 = arith.extsi %137 : i32 to i64
%140 = llvm.getelementptr %11[%139] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %138, %140 : i64, !llvm.ptr
%141 = arith.constant 25 : i32
%142 = arith.extsi %141 : i32 to i64
%143 = arith.constant 4 : i32
%144 = arith.extsi %143 : i32 to i64
%145 = arith.constant 9999995705032704 : i32
%146 = arith.extsi %145 : i32 to i64
%148 = arith.constant 1 : i32
%150 = arith.extsi %148 : i32 to i64
%149 = arith.addi %142, %150 : i64
%151 = arith.constant 8 : i32
%152 = arith.extsi %151 : i32 to i64
%147 = func.call @calloc(%149, %152) : (i64, i64) -> !llvm.ptr
%153 = llvm.mlir.constant(1 : i64) : i64
%154 = llvm.alloca %153 x i64 : (i64) -> !llvm.ptr
llvm.store %144, %154 : i64, !llvm.ptr
cf.br ^bb0
^bb0:
%155 = llvm.load %154 : !llvm.ptr -> i64
%156 = arith.cmpi sle, %155, %142 : i64
cf.cond_br %156, ^bb1, ^bb2
^bb1:
%158 = llvm.load %154 : !llvm.ptr -> i64
%159 = arith.subi %158, %144 : i64
%160 = arith.constant 1 : i32
%162 = arith.extsi %160 : i32 to i64
%161 = arith.addi %159, %162 : i64
%157 = func.call @tetrahedral(%161) : (i64) -> i64
%163 = llvm.load %154 : !llvm.ptr -> i64
%164 = llvm.getelementptr %147[%163] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %157, %164 : i64, !llvm.ptr
%165 = llvm.load %154 : !llvm.ptr -> i64
%166 = arith.constant 1 : i32
%168 = arith.extsi %166 : i32 to i64
%167 = arith.addi %165, %168 : i64
llvm.store %167, %154 : i64, !llvm.ptr
cf.br ^bb0
^bb2:
%169 = arith.constant 0 : i32
%170 = arith.extsi %169 : i32 to i64
%171 = llvm.mlir.constant(1 : i64) : i64
%172 = llvm.alloca %171 x i64 : (i64) -> !llvm.ptr
llvm.store %170, %172 : i64, !llvm.ptr
%173 = arith.constant 1 : i32
%174 = arith.extsi %173 : i32 to i64
%175 = arith.shli %174, %142 : i64
%176 = arith.constant 1 : i32
%178 = arith.extsi %176 : i32 to i64
%177 = arith.subi %175, %178 : i64
%179 = arith.constant 0 : i32
%180 = arith.extsi %179 : i32 to i64
%181 = llvm.mlir.constant(1 : i64) : i64
%182 = llvm.alloca %181 x i64 : (i64) -> !llvm.ptr
llvm.store %180, %182 : i64, !llvm.ptr
cf.br ^bb3
^bb3:
%183 = llvm.load %182 : !llvm.ptr -> i64
%184 = arith.cmpi slt, %183, %177 : i64
cf.cond_br %184, ^bb4, ^bb5
^bb4:
%185 = arith.constant 1 : i32
%186 = arith.extsi %185 : i32 to i64
%187 = llvm.mlir.constant(1 : i64) : i64
%188 = llvm.alloca %187 x i64 : (i64) -> !llvm.ptr
llvm.store %186, %188 : i64, !llvm.ptr
%189 = arith.constant 0 : i1
%190 = llvm.mlir.constant(1 : i64) : i64
%191 = llvm.alloca %190 x i1 : (i64) -> !llvm.ptr
llvm.store %189, %191 : i1, !llvm.ptr
%192 = arith.constant 0 : i32
%193 = arith.extsi %192 : i32 to i64
%194 = llvm.mlir.constant(1 : i64) : i64
%195 = llvm.alloca %194 x i64 : (i64) -> !llvm.ptr
llvm.store %193, %195 : i64, !llvm.ptr
%196 = arith.constant 0 : i32
%197 = arith.extsi %196 : i32 to i64
%198 = llvm.mlir.constant(1 : i64) : i64
%199 = llvm.alloca %198 x i64 : (i64) -> !llvm.ptr
llvm.store %197, %199 : i64, !llvm.ptr
cf.br ^bb6
^bb6:
%200 = llvm.load %199 : !llvm.ptr -> i64
%201 = arith.cmpi slt, %200, %142 : i64
cf.cond_br %201, ^bb7, ^bb8
^bb7:
%202 = llvm.load %199 : !llvm.ptr -> i64
%203 = arith.shli %174, %202 : i64
%204 = llvm.load %182 : !llvm.ptr -> i64
%205 = arith.andi %204, %203 : i64
%206 = arith.constant 0 : i32
%208 = arith.extsi %206 : i32 to i64
%207 = arith.cmpi ne, %205, %208 : i64
cf.cond_br %207, ^bb9, ^bb10
^bb9:
%209 = llvm.load %195 : !llvm.ptr -> i64
%210 = arith.constant 1 : i32
%212 = arith.extsi %210 : i32 to i64
%211 = arith.addi %209, %212 : i64
llvm.store %211, %195 : i64, !llvm.ptr
%213 = llvm.load %188 : !llvm.ptr -> i64
%215 = llvm.load %199 : !llvm.ptr -> i64
%216 = llvm.getelementptr %11[%215] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%214 = llvm.load %216 : !llvm.ptr -> i64
%217 = arith.divsi %146, %214 : i64
%218 = arith.cmpi sgt, %213, %217 : i64
cf.cond_br %218, ^bb12, ^bb13
^bb12:
%219 = arith.constant 1 : i1
llvm.store %219, %191 : i1, !llvm.ptr
%220 = llvm.load %182 : !llvm.ptr -> i64
%221 = llvm.load %182 : !llvm.ptr -> i64
%222 = arith.constant 1 : i32
%224 = arith.extsi %222 : i32 to i64
%223 = arith.subi %221, %224 : i64
%225 = arith.andi %220, %223 : i64
%226 = llvm.load %182 : !llvm.ptr -> i64
%227 = arith.subi %226, %225 : i64
%228 = llvm.mlir.constant(1 : i64) : i64
%229 = llvm.alloca %228 x i64 : (i64) -> !llvm.ptr
llvm.store %227, %229 : i64, !llvm.ptr
%230 = llvm.load %182 : !llvm.ptr -> i64
%231 = llvm.load %229 : !llvm.ptr -> i64
%232 = arith.addi %230, %231 : i64
llvm.store %232, %182 : i64, !llvm.ptr
cf.br ^bb15
^bb15:
%233 = llvm.load %182 : !llvm.ptr -> i64
%234 = llvm.load %229 : !llvm.ptr -> i64
%235 = arith.constant 1 : i32
%237 = arith.extsi %235 : i32 to i64
%236 = arith.shli %234, %237 : i64
%238 = arith.andi %233, %236 : i64
%239 = arith.constant 0 : i32
%241 = arith.extsi %239 : i32 to i64
%240 = arith.cmpi ne, %238, %241 : i64
cf.cond_br %240, ^bb16, ^bb17
^bb16:
%242 = llvm.load %229 : !llvm.ptr -> i64
%243 = arith.constant 1 : i32
%245 = arith.extsi %243 : i32 to i64
%244 = arith.shli %242, %245 : i64
llvm.store %244, %229 : i64, !llvm.ptr
%246 = llvm.load %182 : !llvm.ptr -> i64
%247 = llvm.load %229 : !llvm.ptr -> i64
%248 = arith.addi %246, %247 : i64
llvm.store %248, %182 : i64, !llvm.ptr
cf.br ^bb15
^bb17:
%249 = llvm.load %182 : !llvm.ptr -> i64
%250 = arith.constant 1 : i32
%252 = arith.extsi %250 : i32 to i64
%251 = arith.subi %249, %252 : i64
llvm.store %251, %182 : i64, !llvm.ptr
cf.br ^bb8
^bb13:
cf.br ^bb14
^bb14:
%253 = llvm.load %188 : !llvm.ptr -> i64
%255 = llvm.load %199 : !llvm.ptr -> i64
%256 = llvm.getelementptr %11[%255] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%254 = llvm.load %256 : !llvm.ptr -> i64
%257 = arith.muli %253, %254 : i64
llvm.store %257, %188 : i64, !llvm.ptr
cf.br ^bb11
^bb10:
cf.br ^bb11
^bb11:
%258 = llvm.load %199 : !llvm.ptr -> i64
%259 = arith.constant 1 : i32
%261 = arith.extsi %259 : i32 to i64
%260 = arith.addi %258, %261 : i64
llvm.store %260, %199 : i64, !llvm.ptr
cf.br ^bb6
^bb8:
%262 = llvm.load %191 : !llvm.ptr -> i1
%264 = arith.constant 1 : i1
%263 = arith.xori %262, %264 : i1
%266 = scf.if %263 -> (i1) {
%267 = llvm.load %195 : !llvm.ptr -> i64
%268 = arith.cmpi sge, %267, %144 : i64
scf.yield %268 : i1
} else {
%269 = arith.constant false
scf.yield %269 : i1
}
cf.cond_br %266, ^bb18, ^bb19
^bb18:
%270 = llvm.load %188 : !llvm.ptr -> i64
%271 = arith.divsi %146, %270 : i64
%272 = llvm.mlir.constant(1 : i64) : i64
%273 = llvm.alloca %272 x i64 : (i64) -> !llvm.ptr
llvm.store %271, %273 : i64, !llvm.ptr
%274 = llvm.load %273 : !llvm.ptr -> i64
%276 = llvm.load %195 : !llvm.ptr -> i64
%277 = llvm.getelementptr %147[%276] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%275 = llvm.load %277 : !llvm.ptr -> i64
%278 = arith.muli %274, %275 : i64
llvm.store %278, %273 : i64, !llvm.ptr
%279 = llvm.load %195 : !llvm.ptr -> i64
%280 = arith.constant 2 : i32
%282 = arith.extsi %280 : i32 to i64
%281 = arith.remsi %279, %282 : i64
%283 = arith.constant 1 : i32
%285 = arith.extsi %283 : i32 to i64
%284 = arith.cmpi eq, %281, %285 : i64
cf.cond_br %284, ^bb21, ^bb22
^bb21:
%286 = llvm.load %172 : !llvm.ptr -> i64
%287 = llvm.load %273 : !llvm.ptr -> i64
%288 = arith.subi %286, %287 : i64
llvm.store %288, %172 : i64, !llvm.ptr
cf.br ^bb23
^bb22:
%289 = llvm.load %172 : !llvm.ptr -> i64
%290 = llvm.load %273 : !llvm.ptr -> i64
%291 = arith.addi %289, %290 : i64
llvm.store %291, %172 : i64, !llvm.ptr
cf.br ^bb23
^bb23:
cf.br ^bb20
^bb19:
cf.br ^bb20
^bb20:
%292 = llvm.load %182 : !llvm.ptr -> i64
%293 = arith.constant 1 : i32
%295 = arith.extsi %293 : i32 to i64
%294 = arith.addi %292, %295 : i64
llvm.store %294, %182 : i64, !llvm.ptr
cf.br ^bb3
^bb5:
%296 = llvm.mlir.addressof @str_0 : !llvm.ptr
%297 = llvm.load %172 : !llvm.ptr -> i64
%298 = llvm.call @printf(%296, %297) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%11) : (!llvm.ptr) -> ()
func.call @free(%147) : (!llvm.ptr) -> ()
%301 = arith.constant 0 : i32
func.return %301 : i32
}
}