← All problems
Problem 937
Equiproduct Partition. G(10^8) mod 1000000007.
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n^3)O(n * m)
Space complexity O(n)O(n)
Approach Flow solution Dynamic programming or generating function
Verdict Unknown
Flow source
# Project Euler 937
# Equiproduct Partition. G(10^8) mod 1000000007.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function malloc(n: i64) -> ptr<void>
function free(p: ptr<void>) -> void
function memset(s: ptr<void>, c: i32, n: i64) -> ptr<void>
function sqrt(x: f64) -> f64
}
const MOD: i64 = 1000000007
function popcount64(x: i64) -> i32 {
let mut n: i64 = x
let mut count: i32 = 0
while n != 0 {
n = n & (n - 1)
count = count + 1
}
return count
}
function ctz64(x: i64) -> i32 {
if x == 0 {
return 64
}
let mut n: i64 = x
let mut count: i32 = 0
while (n & 1) == 0 {
count = count + 1
n = n >> 1
}
return count
}
function bit_mask(shift: i64) -> i64 {
if shift < 63 {
return (1 as i64) << shift
}
return -9223372036854775808
}
function delta_flip(delta: ptr<i64>, k: i64) -> void {
let word: i64 = k >> 6
let bit: i64 = bit_mask(k & 63)
delta[word] = delta[word] ^ bit
}
function delta_get(delta: ptr<i64>, k: i64) -> i32 {
let word: i64 = k >> 6
let shift: i64 = k & 63
let val: i64 = delta[word] >> shift
return (val & 1) as i32
}
function compute_G(n: i64) -> i64 {
# Build odd-prime sieve
let size: i64 = n / 2 + 1
let is_prime: ptr<i8> = malloc(size)
memset(is_prime, 1, size)
is_prime[0] = 0
let limit: i64 = sqrt(n as f64) as i64
let mut i: i64 = 1
while 2 * i + 1 <= limit {
if is_prime[i] != 0 {
let p: i64 = 2 * i + 1
let mut j: i64 = p * p
while j <= n {
is_prime[j / 2] = 0
j = j + 2 * p
}
}
i = i + 1
}
# Delta bit array (zero-filled by calloc)
let delta_words: i64 = (n + 64) / 64
let delta: ptr<i64> = calloc(delta_words, 8)
# Process p=2
let mut E2: i64 = 0
let mut par2: i32 = 0
let mut k2: i64 = 2
while k2 <= n {
let e: i32 = ctz64(k2)
E2 = E2 + (e as i64)
let new_par: i32 = popcount64(E2) & 1
if new_par != par2 {
delta_flip(delta, k2)
par2 = new_par
}
k2 = k2 + 2
}
# Process each relevant odd prime (p%8 in {5,7})
let mut idx: i64 = 1
while idx <= n / 2 {
if is_prime[idx] != 0 {
let p: i64 = 2 * idx + 1
let pm8: i64 = p & 7
if pm8 == 5 || pm8 == 7 {
let mut Ep: i64 = 0
let mut parp: i32 = 0
let mut m: i64 = 1
while m * p <= n {
let k: i64 = m * p
let mut e: i64 = 1
let mut r: i64 = m
while r % p == 0 {
e = e + 1
r = r / p
}
Ep = Ep + e
let new_par: i32 = popcount64(Ep) & 1
if new_par != parp {
delta_flip(delta, k)
parp = new_par
}
m = m + 1
}
}
}
idx = idx + 1
}
# Final pass: compute running parity and sum factorials
let mut fact: i64 = 1
let mut ans: i64 = 0
let mut running_par: i32 = 0
let mut k: i64 = 1
while k <= n {
fact = fact * k % MOD
if delta_get(delta, k) != 0 {
running_par = running_par ^ 1
}
if running_par == 0 {
ans = ans + fact
if ans >= MOD {
ans = ans - MOD
}
}
k = k + 1
}
free(is_prime)
free(delta)
return ans
}
function main() -> i32 {
printf("%lld\n", compute_G(100000000))
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; }
int32_t popcount64_i64(int64_t x);
int32_t ctz64_i64(int64_t x);
int64_t bit_mask_i64(int64_t shift);
void delta_flip_ptr_i64_i64(int64_t* delta, int64_t k);
int32_t delta_get_ptr_i64_i64(int64_t* delta, int64_t k);
int64_t compute_G_i64(int64_t n);
int32_t main(void);
static const int64_t MOD = 1000000007;
int32_t popcount64_i64(int64_t x) {
int64_t n = x;
int32_t count = 0;
while (n != 0) {
n = (n & (n - 1));
count = (count + 1);
}
return count;
}
int32_t ctz64_i64(int64_t x) {
if (x == 0) {
return 64;
}
int64_t n = x;
int32_t count = 0;
while ((n & 1) == 0) {
count = (count + 1);
n = FLOW_CHECKED_SHR((n), (1));
}
return count;
}
int64_t bit_mask_i64(int64_t shift) {
if (shift < 63) {
return FLOW_CHECKED_SHL((((int64_t)(1))), (shift));
}
return (-((__int128)0x8000000000000000ULL));
}
void delta_flip_ptr_i64_i64(int64_t* delta, int64_t k) {
int64_t word = FLOW_CHECKED_SHR((k), (6));
int64_t bit = bit_mask_i64((k & 63));
delta[word] = (delta[word] ^ bit);
}
int32_t delta_get_ptr_i64_i64(int64_t* delta, int64_t k) {
int64_t word = FLOW_CHECKED_SHR((k), (6));
int64_t shift = (k & 63);
int64_t val = FLOW_CHECKED_SHR((delta[word]), (shift));
return ((int32_t)((val & 1)));
}
int64_t compute_G_i64(int64_t n) {
int64_t size = (FLOW_CHECKED_DIV((n), (2)) + 1);
int8_t* is_prime = (int8_t*)(malloc(size));
memset(is_prime, 1, size);
is_prime[0] = 0;
int64_t limit = ((int64_t)(sqrt(((double)(n)))));
int64_t i = 1;
while (((2 * i) + 1) <= limit) {
if (is_prime[i] != 0) {
int64_t p = ((2 * i) + 1);
int64_t j = (p * p);
while (j <= n) {
is_prime[FLOW_CHECKED_DIV((j), (2))] = 0;
j = (j + (2 * p));
}
}
i = (i + 1);
}
int64_t delta_words = FLOW_CHECKED_DIV(((n + 64)), (64));
int64_t* delta = (int64_t*)(calloc(delta_words, 8));
int64_t E2 = 0;
int32_t par2 = 0;
int64_t k2 = 2;
while (k2 <= n) {
int32_t e = ctz64_i64(k2);
E2 = (E2 + ((int64_t)(e)));
int32_t new_par = (popcount64_i64(E2) & 1);
if (new_par != par2) {
delta_flip_ptr_i64_i64(delta, k2);
par2 = new_par;
}
k2 = (k2 + 2);
}
int64_t idx = 1;
while (idx <= FLOW_CHECKED_DIV((n), (2))) {
if (is_prime[idx] != 0) {
int64_t p = ((2 * idx) + 1);
int64_t pm8 = (p & 7);
if ((pm8 == 5 || pm8 == 7)) {
int64_t Ep = 0;
int32_t parp = 0;
int64_t m = 1;
while ((m * p) <= n) {
int64_t k = (m * p);
int64_t e = 1;
int64_t r = m;
while (FLOW_CHECKED_MOD((r), (p)) == 0) {
e = (e + 1);
r = FLOW_CHECKED_DIV((r), (p));
}
Ep = (Ep + e);
int32_t new_par = (popcount64_i64(Ep) & 1);
if (new_par != parp) {
delta_flip_ptr_i64_i64(delta, k);
parp = new_par;
}
m = (m + 1);
}
}
}
idx = (idx + 1);
}
int64_t fact = 1;
int64_t ans = 0;
int32_t running_par = 0;
int64_t k = 1;
while (k <= n) {
fact = FLOW_CHECKED_MOD(((fact * k)), (MOD));
if (delta_get_ptr_i64_i64(delta, k) != 0) {
running_par = (running_par ^ 1);
}
if (running_par == 0) {
ans = (ans + fact);
if (ans >= MOD) {
ans = (ans - MOD);
}
}
k = (k + 1);
}
free(is_prime);
free(delta);
return ans;
}
int32_t main(void) {
printf("%lld\n", compute_G_i64(100000000));
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 @malloc(i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
func.func private @memset(!llvm.ptr, i32, i64) -> !llvm.ptr
func.func private @sqrt(f64) -> f64
// Constant: MOD
llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
func.func @popcount64(%arg0: i64) -> i32 {
%0 = llvm.mlir.constant(1 : i64) : i64
%1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %1 : i64, !llvm.ptr
%2 = arith.constant 0 : i32
%3 = llvm.mlir.constant(1 : i64) : i64
%4 = llvm.alloca %3 x i32 : (i64) -> !llvm.ptr
llvm.store %2, %4 : i32, !llvm.ptr
cf.br ^bb0
^bb0:
%5 = llvm.load %1 : !llvm.ptr -> i64
%6 = arith.constant 0 : i32
%8 = arith.extsi %6 : i32 to i64
%7 = arith.cmpi ne, %5, %8 : i64
cf.cond_br %7, ^bb1, ^bb2
^bb1:
%9 = llvm.load %1 : !llvm.ptr -> i64
%10 = llvm.load %1 : !llvm.ptr -> i64
%11 = arith.constant 1 : i32
%13 = arith.extsi %11 : i32 to i64
%12 = arith.subi %10, %13 : i64
%14 = arith.andi %9, %12 : i64
llvm.store %14, %1 : i64, !llvm.ptr
%15 = llvm.load %4 : !llvm.ptr -> i32
%16 = arith.constant 1 : i32
%17 = arith.addi %15, %16 : i32
llvm.store %17, %4 : i32, !llvm.ptr
cf.br ^bb0
^bb2:
%18 = llvm.load %4 : !llvm.ptr -> i32
func.return %18 : i32
}
func.func @ctz64(%arg0: i64) -> i32 {
%19 = arith.constant 0 : i32
%21 = arith.extsi %19 : i32 to i64
%20 = arith.cmpi eq, %arg0, %21 : i64
cf.cond_br %20, ^bb3, ^bb4
^bb3:
%22 = arith.constant 64 : i32
func.return %22 : i32
^bb4:
cf.br ^bb5
^bb5:
%23 = llvm.mlir.constant(1 : i64) : i64
%24 = llvm.alloca %23 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %24 : i64, !llvm.ptr
%25 = arith.constant 0 : i32
%26 = llvm.mlir.constant(1 : i64) : i64
%27 = llvm.alloca %26 x i32 : (i64) -> !llvm.ptr
llvm.store %25, %27 : i32, !llvm.ptr
cf.br ^bb6
^bb6:
%28 = llvm.load %24 : !llvm.ptr -> i64
%29 = arith.constant 1 : i32
%31 = arith.extsi %29 : i32 to i64
%30 = arith.andi %28, %31 : i64
%32 = arith.constant 0 : i32
%34 = arith.extsi %32 : i32 to i64
%33 = arith.cmpi eq, %30, %34 : i64
cf.cond_br %33, ^bb7, ^bb8
^bb7:
%35 = llvm.load %27 : !llvm.ptr -> i32
%36 = arith.constant 1 : i32
%37 = arith.addi %35, %36 : i32
llvm.store %37, %27 : i32, !llvm.ptr
%38 = llvm.load %24 : !llvm.ptr -> i64
%39 = arith.constant 1 : i32
%41 = arith.extsi %39 : i32 to i64
%40 = arith.shrsi %38, %41 : i64
llvm.store %40, %24 : i64, !llvm.ptr
cf.br ^bb6
^bb8:
%42 = llvm.load %27 : !llvm.ptr -> i32
func.return %42 : i32
}
func.func @bit_mask(%arg0: i64) -> i64 {
%43 = arith.constant 63 : i32
%45 = arith.extsi %43 : i32 to i64
%44 = arith.cmpi slt, %arg0, %45 : i64
cf.cond_br %44, ^bb9, ^bb10
^bb9:
%46 = arith.constant 1 : i32
%47 = arith.extsi %46 : i32 to i64
%48 = arith.shli %47, %arg0 : i64
func.return %48 : i64
^bb10:
cf.br ^bb11
^bb11:
%49 = arith.constant 9223372032559808512 : i32
%51 = arith.constant 0 : i32
%50 = arith.subi %51, %49 : i32
%52 = arith.extsi %50 : i32 to i64
func.return %52 : i64
}
func.func @delta_flip(%arg0: !llvm.ptr, %arg1: i64) -> () {
%53 = arith.constant 6 : i32
%55 = arith.extsi %53 : i32 to i64
%54 = arith.shrsi %arg1, %55 : i64
%57 = arith.constant 63 : i32
%59 = arith.extsi %57 : i32 to i64
%58 = arith.andi %arg1, %59 : i64
%56 = func.call @bit_mask(%58) : (i64) -> i64
%61 = llvm.getelementptr %arg0[%54] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%60 = llvm.load %61 : !llvm.ptr -> i64
%62 = arith.xori %60, %56 : i64
%63 = llvm.getelementptr %arg0[%54] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %62, %63 : i64, !llvm.ptr
func.return
}
func.func @delta_get(%arg0: !llvm.ptr, %arg1: i64) -> i32 {
%64 = arith.constant 6 : i32
%66 = arith.extsi %64 : i32 to i64
%65 = arith.shrsi %arg1, %66 : i64
%67 = arith.constant 63 : i32
%69 = arith.extsi %67 : i32 to i64
%68 = arith.andi %arg1, %69 : i64
%71 = llvm.getelementptr %arg0[%65] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%70 = llvm.load %71 : !llvm.ptr -> i64
%72 = arith.shrsi %70, %68 : i64
%73 = arith.constant 1 : i32
%75 = arith.extsi %73 : i32 to i64
%74 = arith.andi %72, %75 : i64
%76 = arith.trunci %74 : i64 to i32
func.return %76 : i32
}
func.func @compute_G(%arg0: i64) -> i64 {
%77 = arith.constant 2 : i32
%79 = arith.extsi %77 : i32 to i64
%78 = arith.divsi %arg0, %79 : i64
%80 = arith.constant 1 : i32
%82 = arith.extsi %80 : i32 to i64
%81 = arith.addi %78, %82 : i64
%83 = func.call @malloc(%81) : (i64) -> !llvm.ptr
%85 = arith.constant 1 : i32
%84 = func.call @memset(%83, %85, %81) : (!llvm.ptr, i32, i64) -> !llvm.ptr
%86 = arith.constant 0 : i32
%87 = arith.constant 0 : i32
%88 = arith.trunci %86 : i32 to i8
%89 = arith.extsi %87 : i32 to i64
%90 = llvm.getelementptr %83[%89] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %88, %90 : i8, !llvm.ptr
%91 = arith.sitofp %arg0 : i64 to f64
%92 = math.sqrt %91 : f64
%93 = arith.fptosi %92 : f64 to i64
%94 = arith.constant 1 : i32
%95 = arith.extsi %94 : i32 to i64
%96 = llvm.mlir.constant(1 : i64) : i64
%97 = llvm.alloca %96 x i64 : (i64) -> !llvm.ptr
llvm.store %95, %97 : i64, !llvm.ptr
cf.br ^bb12
^bb12:
%98 = arith.constant 2 : i32
%99 = llvm.load %97 : !llvm.ptr -> i64
%101 = arith.extsi %98 : i32 to i64
%100 = arith.muli %101, %99 : i64
%102 = arith.constant 1 : i32
%104 = arith.extsi %102 : i32 to i64
%103 = arith.addi %100, %104 : i64
%105 = arith.cmpi sle, %103, %93 : i64
cf.cond_br %105, ^bb13, ^bb14
^bb13:
%107 = llvm.load %97 : !llvm.ptr -> i64
%108 = llvm.getelementptr %83[%107] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%106 = llvm.load %108 : !llvm.ptr -> i8
%109 = arith.constant 0 : i32
%111 = arith.extsi %106 : i8 to i32
%110 = arith.cmpi ne, %111, %109 : i32
cf.cond_br %110, ^bb15, ^bb16
^bb15:
%112 = arith.constant 2 : i32
%113 = llvm.load %97 : !llvm.ptr -> i64
%115 = arith.extsi %112 : i32 to i64
%114 = arith.muli %115, %113 : i64
%116 = arith.constant 1 : i32
%118 = arith.extsi %116 : i32 to i64
%117 = arith.addi %114, %118 : i64
%119 = arith.muli %117, %117 : i64
%120 = llvm.mlir.constant(1 : i64) : i64
%121 = llvm.alloca %120 x i64 : (i64) -> !llvm.ptr
llvm.store %119, %121 : i64, !llvm.ptr
cf.br ^bb18
^bb18:
%122 = llvm.load %121 : !llvm.ptr -> i64
%123 = arith.cmpi sle, %122, %arg0 : i64
cf.cond_br %123, ^bb19, ^bb20
^bb19:
%124 = arith.constant 0 : i32
%125 = llvm.load %121 : !llvm.ptr -> i64
%126 = arith.constant 2 : i32
%128 = arith.extsi %126 : i32 to i64
%127 = arith.divsi %125, %128 : i64
%129 = arith.trunci %124 : i32 to i8
%130 = llvm.getelementptr %83[%127] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %129, %130 : i8, !llvm.ptr
%131 = llvm.load %121 : !llvm.ptr -> i64
%132 = arith.constant 2 : i32
%134 = arith.extsi %132 : i32 to i64
%133 = arith.muli %134, %117 : i64
%135 = arith.addi %131, %133 : i64
llvm.store %135, %121 : i64, !llvm.ptr
cf.br ^bb18
^bb20:
cf.br ^bb17
^bb16:
cf.br ^bb17
^bb17:
%136 = llvm.load %97 : !llvm.ptr -> i64
%137 = arith.constant 1 : i32
%139 = arith.extsi %137 : i32 to i64
%138 = arith.addi %136, %139 : i64
llvm.store %138, %97 : i64, !llvm.ptr
cf.br ^bb12
^bb14:
%140 = arith.constant 64 : i32
%142 = arith.extsi %140 : i32 to i64
%141 = arith.addi %arg0, %142 : i64
%143 = arith.constant 64 : i32
%145 = arith.extsi %143 : i32 to i64
%144 = arith.divsi %141, %145 : i64
%147 = arith.constant 8 : i32
%148 = arith.extsi %147 : i32 to i64
%146 = func.call @calloc(%144, %148) : (i64, i64) -> !llvm.ptr
%149 = arith.constant 0 : i32
%150 = arith.extsi %149 : i32 to i64
%151 = llvm.mlir.constant(1 : i64) : i64
%152 = llvm.alloca %151 x i64 : (i64) -> !llvm.ptr
llvm.store %150, %152 : i64, !llvm.ptr
%153 = arith.constant 0 : i32
%154 = llvm.mlir.constant(1 : i64) : i64
%155 = llvm.alloca %154 x i32 : (i64) -> !llvm.ptr
llvm.store %153, %155 : i32, !llvm.ptr
%156 = arith.constant 2 : i32
%157 = arith.extsi %156 : i32 to i64
%158 = llvm.mlir.constant(1 : i64) : i64
%159 = llvm.alloca %158 x i64 : (i64) -> !llvm.ptr
llvm.store %157, %159 : i64, !llvm.ptr
cf.br ^bb21
^bb21:
%160 = llvm.load %159 : !llvm.ptr -> i64
%161 = arith.cmpi sle, %160, %arg0 : i64
cf.cond_br %161, ^bb22, ^bb23
^bb22:
%163 = llvm.load %159 : !llvm.ptr -> i64
%162 = func.call @ctz64(%163) : (i64) -> i32
%164 = llvm.load %152 : !llvm.ptr -> i64
%165 = arith.extsi %162 : i32 to i64
%166 = arith.addi %164, %165 : i64
llvm.store %166, %152 : i64, !llvm.ptr
%168 = llvm.load %152 : !llvm.ptr -> i64
%167 = func.call @popcount64(%168) : (i64) -> i32
%169 = arith.constant 1 : i32
%170 = arith.andi %167, %169 : i32
%171 = llvm.load %155 : !llvm.ptr -> i32
%172 = arith.cmpi ne, %170, %171 : i32
cf.cond_br %172, ^bb24, ^bb25
^bb24:
%174 = llvm.load %159 : !llvm.ptr -> i64
func.call @delta_flip(%146, %174) : (!llvm.ptr, i64) -> ()
llvm.store %170, %155 : i32, !llvm.ptr
cf.br ^bb26
^bb25:
cf.br ^bb26
^bb26:
%175 = llvm.load %159 : !llvm.ptr -> i64
%176 = arith.constant 2 : i32
%178 = arith.extsi %176 : i32 to i64
%177 = arith.addi %175, %178 : i64
llvm.store %177, %159 : i64, !llvm.ptr
cf.br ^bb21
^bb23:
%179 = arith.constant 1 : 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 ^bb27
^bb27:
%183 = llvm.load %182 : !llvm.ptr -> i64
%184 = arith.constant 2 : i32
%186 = arith.extsi %184 : i32 to i64
%185 = arith.divsi %arg0, %186 : i64
%187 = arith.cmpi sle, %183, %185 : i64
cf.cond_br %187, ^bb28, ^bb29
^bb28:
%189 = llvm.load %182 : !llvm.ptr -> i64
%190 = llvm.getelementptr %83[%189] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%188 = llvm.load %190 : !llvm.ptr -> i8
%191 = arith.constant 0 : i32
%193 = arith.extsi %188 : i8 to i32
%192 = arith.cmpi ne, %193, %191 : i32
cf.cond_br %192, ^bb30, ^bb31
^bb30:
%194 = arith.constant 2 : i32
%195 = llvm.load %182 : !llvm.ptr -> i64
%197 = arith.extsi %194 : i32 to i64
%196 = arith.muli %197, %195 : i64
%198 = arith.constant 1 : i32
%200 = arith.extsi %198 : i32 to i64
%199 = arith.addi %196, %200 : i64
%201 = arith.constant 7 : i32
%203 = arith.extsi %201 : i32 to i64
%202 = arith.andi %199, %203 : i64
%204 = arith.constant 5 : i32
%206 = arith.extsi %204 : i32 to i64
%205 = arith.cmpi eq, %202, %206 : i64
%207 = scf.if %205 -> (i1) {
%208 = arith.constant true
scf.yield %208 : i1
} else {
%209 = arith.constant 7 : i32
%211 = arith.extsi %209 : i32 to i64
%210 = arith.cmpi eq, %202, %211 : i64
scf.yield %210 : i1
}
cf.cond_br %207, ^bb33, ^bb34
^bb33:
%212 = arith.constant 0 : i32
%213 = arith.extsi %212 : i32 to i64
%214 = llvm.mlir.constant(1 : i64) : i64
%215 = llvm.alloca %214 x i64 : (i64) -> !llvm.ptr
llvm.store %213, %215 : i64, !llvm.ptr
%216 = arith.constant 0 : i32
%217 = llvm.mlir.constant(1 : i64) : i64
%218 = llvm.alloca %217 x i32 : (i64) -> !llvm.ptr
llvm.store %216, %218 : i32, !llvm.ptr
%219 = arith.constant 1 : i32
%220 = arith.extsi %219 : i32 to i64
%221 = llvm.mlir.constant(1 : i64) : i64
%222 = llvm.alloca %221 x i64 : (i64) -> !llvm.ptr
llvm.store %220, %222 : i64, !llvm.ptr
cf.br ^bb36
^bb36:
%223 = llvm.load %222 : !llvm.ptr -> i64
%224 = arith.muli %223, %199 : i64
%225 = arith.cmpi sle, %224, %arg0 : i64
cf.cond_br %225, ^bb37, ^bb38
^bb37:
%226 = llvm.load %222 : !llvm.ptr -> i64
%227 = arith.muli %226, %199 : i64
%228 = arith.constant 1 : i32
%229 = arith.extsi %228 : i32 to i64
%230 = llvm.mlir.constant(1 : i64) : i64
%231 = llvm.alloca %230 x i64 : (i64) -> !llvm.ptr
llvm.store %229, %231 : i64, !llvm.ptr
%232 = llvm.load %222 : !llvm.ptr -> i64
%233 = llvm.mlir.constant(1 : i64) : i64
%234 = llvm.alloca %233 x i64 : (i64) -> !llvm.ptr
llvm.store %232, %234 : i64, !llvm.ptr
cf.br ^bb39
^bb39:
%235 = llvm.load %234 : !llvm.ptr -> i64
%236 = arith.remsi %235, %199 : i64
%237 = arith.constant 0 : i32
%239 = arith.extsi %237 : i32 to i64
%238 = arith.cmpi eq, %236, %239 : i64
cf.cond_br %238, ^bb40, ^bb41
^bb40:
%240 = llvm.load %231 : !llvm.ptr -> i64
%241 = arith.constant 1 : i32
%243 = arith.extsi %241 : i32 to i64
%242 = arith.addi %240, %243 : i64
llvm.store %242, %231 : i64, !llvm.ptr
%244 = llvm.load %234 : !llvm.ptr -> i64
%245 = arith.divsi %244, %199 : i64
llvm.store %245, %234 : i64, !llvm.ptr
cf.br ^bb39
^bb41:
%246 = llvm.load %215 : !llvm.ptr -> i64
%247 = llvm.load %231 : !llvm.ptr -> i64
%248 = arith.addi %246, %247 : i64
llvm.store %248, %215 : i64, !llvm.ptr
%250 = llvm.load %215 : !llvm.ptr -> i64
%249 = func.call @popcount64(%250) : (i64) -> i32
%251 = arith.constant 1 : i32
%252 = arith.andi %249, %251 : i32
%253 = llvm.load %218 : !llvm.ptr -> i32
%254 = arith.cmpi ne, %252, %253 : i32
cf.cond_br %254, ^bb42, ^bb43
^bb42:
func.call @delta_flip(%146, %227) : (!llvm.ptr, i64) -> ()
llvm.store %252, %218 : i32, !llvm.ptr
cf.br ^bb44
^bb43:
cf.br ^bb44
^bb44:
%256 = llvm.load %222 : !llvm.ptr -> i64
%257 = arith.constant 1 : i32
%259 = arith.extsi %257 : i32 to i64
%258 = arith.addi %256, %259 : i64
llvm.store %258, %222 : i64, !llvm.ptr
cf.br ^bb36
^bb38:
cf.br ^bb35
^bb34:
cf.br ^bb35
^bb35:
cf.br ^bb32
^bb31:
cf.br ^bb32
^bb32:
%260 = llvm.load %182 : !llvm.ptr -> i64
%261 = arith.constant 1 : i32
%263 = arith.extsi %261 : i32 to i64
%262 = arith.addi %260, %263 : i64
llvm.store %262, %182 : i64, !llvm.ptr
cf.br ^bb27
^bb29:
%264 = arith.constant 1 : i32
%265 = arith.extsi %264 : i32 to i64
%266 = llvm.mlir.constant(1 : i64) : i64
%267 = llvm.alloca %266 x i64 : (i64) -> !llvm.ptr
llvm.store %265, %267 : i64, !llvm.ptr
%268 = arith.constant 0 : i32
%269 = arith.extsi %268 : i32 to i64
%270 = llvm.mlir.constant(1 : i64) : i64
%271 = llvm.alloca %270 x i64 : (i64) -> !llvm.ptr
llvm.store %269, %271 : i64, !llvm.ptr
%272 = arith.constant 0 : i32
%273 = llvm.mlir.constant(1 : i64) : i64
%274 = llvm.alloca %273 x i32 : (i64) -> !llvm.ptr
llvm.store %272, %274 : i32, !llvm.ptr
%275 = arith.constant 1 : i32
%276 = arith.extsi %275 : i32 to i64
%277 = llvm.mlir.constant(1 : i64) : i64
%278 = llvm.alloca %277 x i64 : (i64) -> !llvm.ptr
llvm.store %276, %278 : i64, !llvm.ptr
cf.br ^bb45
^bb45:
%279 = llvm.load %278 : !llvm.ptr -> i64
%280 = arith.cmpi sle, %279, %arg0 : i64
cf.cond_br %280, ^bb46, ^bb47
^bb46:
%281 = llvm.load %267 : !llvm.ptr -> i64
%282 = llvm.load %278 : !llvm.ptr -> i64
%283 = arith.muli %281, %282 : i64
%284 = llvm.mlir.addressof @MOD : !llvm.ptr
%285 = llvm.load %284 : !llvm.ptr -> i64
%286 = arith.remsi %283, %285 : i64
llvm.store %286, %267 : i64, !llvm.ptr
%288 = llvm.load %278 : !llvm.ptr -> i64
%287 = func.call @delta_get(%146, %288) : (!llvm.ptr, i64) -> i32
%289 = arith.constant 0 : i32
%290 = arith.cmpi ne, %287, %289 : i32
cf.cond_br %290, ^bb48, ^bb49
^bb48:
%291 = llvm.load %274 : !llvm.ptr -> i32
%292 = arith.constant 1 : i32
%293 = arith.xori %291, %292 : i32
llvm.store %293, %274 : i32, !llvm.ptr
cf.br ^bb50
^bb49:
cf.br ^bb50
^bb50:
%294 = llvm.load %274 : !llvm.ptr -> i32
%295 = arith.constant 0 : i32
%296 = arith.cmpi eq, %294, %295 : i32
cf.cond_br %296, ^bb51, ^bb52
^bb51:
%297 = llvm.load %271 : !llvm.ptr -> i64
%298 = llvm.load %267 : !llvm.ptr -> i64
%299 = arith.addi %297, %298 : i64
llvm.store %299, %271 : i64, !llvm.ptr
%300 = llvm.load %271 : !llvm.ptr -> i64
%301 = llvm.mlir.addressof @MOD : !llvm.ptr
%302 = llvm.load %301 : !llvm.ptr -> i64
%303 = arith.cmpi sge, %300, %302 : i64
cf.cond_br %303, ^bb54, ^bb55
^bb54:
%304 = llvm.load %271 : !llvm.ptr -> i64
%305 = llvm.mlir.addressof @MOD : !llvm.ptr
%306 = llvm.load %305 : !llvm.ptr -> i64
%307 = arith.subi %304, %306 : i64
llvm.store %307, %271 : i64, !llvm.ptr
cf.br ^bb56
^bb55:
cf.br ^bb56
^bb56:
cf.br ^bb53
^bb52:
cf.br ^bb53
^bb53:
%308 = llvm.load %278 : !llvm.ptr -> i64
%309 = arith.constant 1 : i32
%311 = arith.extsi %309 : i32 to i64
%310 = arith.addi %308, %311 : i64
llvm.store %310, %278 : i64, !llvm.ptr
cf.br ^bb45
^bb47:
func.call @free(%83) : (!llvm.ptr) -> ()
func.call @free(%146) : (!llvm.ptr) -> ()
%314 = llvm.load %271 : !llvm.ptr -> i64
func.return %314 : i64
}
func.func @main() -> i32 {
%315 = llvm.mlir.addressof @str_0 : !llvm.ptr
%317 = arith.constant 100000000 : i32
%318 = arith.extsi %317 : i32 to i64
%316 = func.call @compute_G(%318) : (i64) -> i64
%319 = llvm.call @printf(%315, %316) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
%320 = arith.constant 0 : i32
func.return %320 : i32
}
}