Problem 386

sum N(n) for n<=10^8: max antichain size in divisor lattice.

Answer528755790
Output528755790
StatusPASS
Native helperno
Runtime2500 ms
Peak memory50480 KB
Time complexityO(n log n) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n log n)O(n^2)
Space complexityO(n^2)O(n^2)
ApproachFlow solutionCombinatorial or DP counting
VerdictOptimal

Flow source

# Project Euler 386
# sum N(n) for n<=10^8: max antichain size in divisor lattice.

extern {
    function calloc(n: i64, size: i64) -> ptr<void>
    function free(p: ptr<void>) -> void
}

function is_prime(x: i64, sieve: ptr<i8>) -> i64 {
    if (x & 1) == 0 {
        if x == 2 { return 1 }
        return 0
    }
    if sieve[x >> 1] != 0 { return 1 }
    return 0
}

function antichain(exps: ptr<i32>, from: i32, to_idx: i32, half: i32) -> i32 {
    # Match unsigned C++: half underflow means impossible → 0
    if half < 0 { return 0 }
    let mut sum: i32 = 0
    let mut num: i32 = 0
    let mut x: i32 = from
    while x < to_idx {
        sum = sum + exps[x]
        num = num + 1
        x = x + 1
    }
    if sum < half || num == 0 { return 0 }
    if half == 0 || num == 1 { return 1 }

    let mut result: i32 = 0
    let mut i: i32 = 0
    while i <= exps[from] {
        result = result + antichain(exps, from + 1, to_idx, half - i)
        i = i + 1
    }
    return result
}

function sort_exps(exps: ptr<i32>, n: i32) -> void {
    let mut i: i32 = 1
    while i < n {
        let key: i32 = exps[i]
        let mut j: i32 = i - 1
        while j >= 0 && exps[j] > key {
            exps[j + 1] = exps[j]
            j = j - 1
        }
        exps[j + 1] = key
        i = i + 1
    }
}

function pack_exps(exps: ptr<i32>, n: i32) -> i64 {
    let mut key: i64 = n as i64
    let mut i: i32 = 0
    while i < n {
        key = key * 40 + (exps[i] as i64)
        i = i + 1
    }
    return key
}

function cache_get(keys: ptr<i64>, vals: ptr<i32>, used: ptr<i8>, cap: i64, key: i64) -> i32 {
    let mut slot: i64 = key
    if slot < 0 { slot = 0 - slot }
    slot = slot & (cap - 1)
    while used[slot] != 0 {
        if keys[slot] == key { return vals[slot] }
        slot = (slot + 1) & (cap - 1)
    }
    return 0 - 1
}

function cache_put(keys: ptr<i64>, vals: ptr<i32>, used: ptr<i8>, cap: i64, key: i64, val: i32) -> void {
    let mut slot: i64 = key
    if slot < 0 { slot = 0 - slot }
    slot = slot & (cap - 1)
    while used[slot] != 0 && keys[slot] != key {
        slot = (slot + 1) & (cap - 1)
    }
    used[slot] = 1
    keys[slot] = key
    vals[slot] = val
}

function evaluate(factors: ptr<i32>, nfact: i32, exps: ptr<i32>,
                  keys: ptr<i64>, vals: ptr<i32>, used: ptr<i8>, cap: i64) -> i32 {
    let mut ne: i32 = 1
    exps[0] = 1
    let mut i: i32 = 1
    while i < nfact {
        if factors[i] == factors[i - 1] {
            exps[ne - 1] = exps[ne - 1] + 1
        } else {
            exps[ne] = 1
            ne = ne + 1
        }
        i = i + 1
    }
    sort_exps(exps, ne)
    let key: i64 = pack_exps(exps, ne)
    let hit: i32 = cache_get(keys, vals, used, cap, key)
    if hit >= 0 { return hit }
    let result: i32 = antichain(exps, 0, ne, nfact / 2)
    cache_put(keys, vals, used, cap, key, result)
    return result
}

function search(limit: i64, current: i64, largest: i64, factors: ptr<i32>, nfact: i32,
                sieve: ptr<i8>, exps: ptr<i32>,
                keys: ptr<i64>, vals: ptr<i32>, used: ptr<i8>, cap: i64) -> i64 {
    let mut result: i64 = 0
    let mut prime: i64 = largest
    while prime <= limit {
        if is_prime(prime, sieve) == 1 {
            if current > limit / prime { break }
            let next: i64 = current * prime
            factors[nfact] = prime as i32
            result = result + (evaluate(factors, nfact + 1, exps, keys, vals, used, cap) as i64)
            if next <= limit / prime {
                result = result + search(limit, next, prime, factors, nfact + 1, sieve, exps, keys, vals, used, cap)
            }
        }
        if prime == 2 {
            prime = 3
        } else {
            prime = prime + 2
        }
    }
    return result
}

function main() -> i32 {
    let limit: i64 = 100000000
    let half: i64 = limit >> 1
    let sieve: ptr<i8> = calloc(half, 1)
    if sieve == null { return 1 }
    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] != 0 {
            let mut current: i64 = 3 * i + 1
            while current < half {
                sieve[current] = 0
                current = current + 2 * i + 1
            }
        }
        i = i + 1
    }

    let cap: i64 = 65536
    let keys: ptr<i64> = calloc(cap, 8)
    let vals: ptr<i32> = calloc(cap, 4)
    let used: ptr<i8> = calloc(cap, 1)
    let factors: ptr<i32> = calloc(64, 4)
    let exps: ptr<i32> = calloc(64, 4)
    if keys == null || vals == null || used == null || factors == null || exps == null { return 1 }

    let mut result: i64 = 1
    let mut p: i64 = 2
    while p <= limit {
        if is_prime(p, sieve) == 1 {
            factors[0] = p as i32
            result = result + (evaluate(factors, 1, exps, keys, vals, used, cap) as i64)
            if p <= limit / p {
                result = result + search(limit, p, p, factors, 1, sieve, exps, keys, vals, used, cap)
            }
        }
        if p == 2 { p = 3 } else { p = p + 2 }
    }

    printf("%lld\n", result)
    free(exps)
    free(factors)
    free(used)
    free(vals)
    free(keys)
    free(sieve)
    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 is_prime_i64_ptr_i8(int64_t x, int8_t* sieve);
int32_t antichain_ptr_i32_i32_i32_i32(int32_t* exps, int32_t from, int32_t to_idx, int32_t half);
void sort_exps_ptr_i32_i32(int32_t* exps, int32_t n);
int64_t pack_exps_ptr_i32_i32(int32_t* exps, int32_t n);
int32_t cache_get_ptr_i64_ptr_i32_ptr_i8_i64_i64(int64_t* keys, int32_t* vals, int8_t* used, int64_t cap, int64_t key);
void cache_put_ptr_i64_ptr_i32_ptr_i8_i64_i64_i32(int64_t* keys, int32_t* vals, int8_t* used, int64_t cap, int64_t key, int32_t val);
int32_t evaluate_ptr_i32_i32_ptr_i32_ptr_i64_ptr_i32_ptr_i8_i64(int32_t* factors, int32_t nfact, int32_t* exps, int64_t* keys, int32_t* vals, int8_t* used, int64_t cap);
int64_t search_i64_i64_i64_ptr_i32_i32_ptr_i8_ptr_i32_ptr_i64_ptr_i32_ptr_i8_i64(int64_t limit, int64_t current, int64_t largest, int32_t* factors, int32_t nfact, int8_t* sieve, int32_t* exps, int64_t* keys, int32_t* vals, int8_t* used, int64_t cap);
int32_t main(void);



int64_t is_prime_i64_ptr_i8(int64_t x, int8_t* sieve) {
    if ((x & 1) == 0) {
        if (x == 2) {
            return 1;
        }
        return 0;
    }
    if (sieve[FLOW_CHECKED_SHR((x), (1))] != 0) {
        return 1;
    }
    return 0;
}

int32_t antichain_ptr_i32_i32_i32_i32(int32_t* exps, int32_t from, int32_t to_idx, int32_t half) {
    if (half < 0) {
        return 0;
    }
    int32_t sum = 0;
    int32_t num = 0;
    int32_t x = from;
    while (x < to_idx) {
        sum = (sum + exps[x]);
        num = (num + 1);
        x = (x + 1);
    }
    if ((sum < half || num == 0)) {
        return 0;
    }
    if ((half == 0 || num == 1)) {
        return 1;
    }
    int32_t result = 0;
    int32_t i = 0;
    while (i <= exps[from]) {
        result = (result + antichain_ptr_i32_i32_i32_i32(exps, (from + 1), to_idx, (half - i)));
        i = (i + 1);
    }
    return result;
}

void sort_exps_ptr_i32_i32(int32_t* exps, int32_t n) {
    int32_t i = 1;
    while (i < n) {
        int32_t key = exps[i];
        int32_t j = (i - 1);
        while ((j >= 0 && exps[j] > key)) {
            exps[(j + 1)] = exps[j];
            j = (j - 1);
        }
        exps[(j + 1)] = key;
        i = (i + 1);
    }
}

int64_t pack_exps_ptr_i32_i32(int32_t* exps, int32_t n) {
    int64_t key = ((int64_t)(n));
    int32_t i = 0;
    while (i < n) {
        key = ((key * 40) + ((int64_t)(exps[i])));
        i = (i + 1);
    }
    return key;
}

int32_t cache_get_ptr_i64_ptr_i32_ptr_i8_i64_i64(int64_t* keys, int32_t* vals, int8_t* used, int64_t cap, int64_t key) {
    int64_t slot = key;
    if (slot < 0) {
        slot = (0 - slot);
    }
    slot = (slot & (cap - 1));
    while (used[slot] != 0) {
        if (keys[slot] == key) {
            return vals[slot];
        }
        slot = ((slot + 1) & (cap - 1));
    }
    return (0 - 1);
}

void cache_put_ptr_i64_ptr_i32_ptr_i8_i64_i64_i32(int64_t* keys, int32_t* vals, int8_t* used, int64_t cap, int64_t key, int32_t val) {
    int64_t slot = key;
    if (slot < 0) {
        slot = (0 - slot);
    }
    slot = (slot & (cap - 1));
    while ((used[slot] != 0 && keys[slot] != key)) {
        slot = ((slot + 1) & (cap - 1));
    }
    used[slot] = 1;
    keys[slot] = key;
    vals[slot] = val;
}

int32_t evaluate_ptr_i32_i32_ptr_i32_ptr_i64_ptr_i32_ptr_i8_i64(int32_t* factors, int32_t nfact, int32_t* exps, int64_t* keys, int32_t* vals, int8_t* used, int64_t cap) {
    int32_t ne = 1;
    exps[0] = 1;
    int32_t i = 1;
    while (i < nfact) {
        if (factors[i] == factors[(i - 1)]) {
            exps[(ne - 1)] = (exps[(ne - 1)] + 1);
        } else {
            exps[ne] = 1;
            ne = (ne + 1);
        }
        i = (i + 1);
    }
    sort_exps_ptr_i32_i32(exps, ne);
    int64_t key = pack_exps_ptr_i32_i32(exps, ne);
    int32_t hit = cache_get_ptr_i64_ptr_i32_ptr_i8_i64_i64(keys, vals, used, cap, key);
    if (hit >= 0) {
        return hit;
    }
    int32_t result = antichain_ptr_i32_i32_i32_i32(exps, 0, ne, FLOW_CHECKED_DIV((nfact), (2)));
    cache_put_ptr_i64_ptr_i32_ptr_i8_i64_i64_i32(keys, vals, used, cap, key, result);
    return result;
}

int64_t search_i64_i64_i64_ptr_i32_i32_ptr_i8_ptr_i32_ptr_i64_ptr_i32_ptr_i8_i64(int64_t limit, int64_t current, int64_t largest, int32_t* factors, int32_t nfact, int8_t* sieve, int32_t* exps, int64_t* keys, int32_t* vals, int8_t* used, int64_t cap) {
    int64_t result = 0;
    int64_t prime = largest;
    while (prime <= limit) {
        if (is_prime_i64_ptr_i8(prime, sieve) == 1) {
            if (current > FLOW_CHECKED_DIV((limit), (prime))) {
                break;
            }
            int64_t next = (current * prime);
            factors[nfact] = ((int32_t)(prime));
            result = (result + ((int64_t)(evaluate_ptr_i32_i32_ptr_i32_ptr_i64_ptr_i32_ptr_i8_i64(factors, (nfact + 1), exps, keys, vals, used, cap))));
            if (next <= FLOW_CHECKED_DIV((limit), (prime))) {
                result = (result + search_i64_i64_i64_ptr_i32_i32_ptr_i8_ptr_i32_ptr_i64_ptr_i32_ptr_i8_i64(limit, next, prime, factors, (nfact + 1), sieve, exps, keys, vals, used, cap));
            }
        }
        if (prime == 2) {
            prime = 3;
        } else {
            prime = (prime + 2);
        }
    }
    return result;
}

int32_t main(void) {
    int64_t limit = 100000000;
    int64_t half = FLOW_CHECKED_SHR((limit), (1));
    int8_t* sieve = (int8_t*)(calloc(half, 1));
    if (sieve == NULL) {
        return 1;
    }
    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] != 0) {
            int64_t current = ((3 * i) + 1);
            while (current < half) {
                sieve[current] = 0;
                current = ((current + (2 * i)) + 1);
            }
        }
        i = (i + 1);
    }
    int64_t cap = 65536;
    int64_t* keys = (int64_t*)(calloc(cap, 8));
    int32_t* vals = (int32_t*)(calloc(cap, 4));
    int8_t* used = (int8_t*)(calloc(cap, 1));
    int32_t* factors = (int32_t*)(calloc(64, 4));
    int32_t* exps = (int32_t*)(calloc(64, 4));
    if (((((keys == NULL || vals == NULL) || used == NULL) || factors == NULL) || exps == NULL)) {
        return 1;
    }
    int64_t result = 1;
    int64_t p = 2;
    while (p <= limit) {
        if (is_prime_i64_ptr_i8(p, sieve) == 1) {
            factors[0] = ((int32_t)(p));
            result = (result + ((int64_t)(evaluate_ptr_i32_i32_ptr_i32_ptr_i64_ptr_i32_ptr_i8_i64(factors, 1, exps, keys, vals, used, cap))));
            if (p <= FLOW_CHECKED_DIV((limit), (p))) {
                result = (result + search_i64_i64_i64_ptr_i32_i32_ptr_i8_ptr_i32_ptr_i64_ptr_i32_ptr_i8_i64(limit, p, p, factors, 1, sieve, exps, keys, vals, used, cap));
            }
        }
        if (p == 2) {
            p = 3;
        } else {
            p = (p + 2);
        }
    }
    printf("%lld\n", result);
    free(exps);
    free(factors);
    free(used);
    free(vals);
    free(keys);
    free(sieve);
    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(%arg0: i64, %arg1: !llvm.ptr) -> i64 {
    %0 = arith.constant 1 : i32
    %2 = arith.extsi %0 : i32 to i64
    %1 = arith.andi %arg0, %2 : i64
    %3 = arith.constant 0 : i32
    %5 = arith.extsi %3 : i32 to i64
    %4 = arith.cmpi eq, %1, %5 : i64
    cf.cond_br %4, ^bb0, ^bb1
    ^bb0:
      %6 = arith.constant 2 : i32
      %8 = arith.extsi %6 : i32 to i64
      %7 = arith.cmpi eq, %arg0, %8 : i64
      cf.cond_br %7, ^bb3, ^bb4
      ^bb3:
        %9 = arith.constant 1 : i32
        %10 = arith.extsi %9 : i32 to i64
        func.return %10 : i64
      ^bb4:
        cf.br ^bb5
      ^bb5:
      %11 = arith.constant 0 : i32
      %12 = arith.extsi %11 : i32 to i64
      func.return %12 : i64
    ^bb1:
      cf.br ^bb2
    ^bb2:
    %14 = arith.constant 1 : i32
    %16 = arith.extsi %14 : i32 to i64
    %15 = arith.shrsi %arg0, %16 : i64
    %17 = llvm.getelementptr %arg1[%15] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    %13 = llvm.load %17 : !llvm.ptr -> i8
    %18 = arith.constant 0 : i32
    %20 = arith.extsi %13 : i8 to i32
    %19 = arith.cmpi ne, %20, %18 : i32
    cf.cond_br %19, ^bb6, ^bb7
    ^bb6:
      %21 = arith.constant 1 : i32
      %22 = arith.extsi %21 : i32 to i64
      func.return %22 : i64
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %23 = arith.constant 0 : i32
    %24 = arith.extsi %23 : i32 to i64
    func.return %24 : i64
  }
  func.func @antichain(%arg0: !llvm.ptr, %arg1: i32, %arg2: i32, %arg3: i32) -> i32 {
    %25 = arith.constant 0 : i32
    %26 = arith.cmpi slt, %arg3, %25 : i32
    cf.cond_br %26, ^bb9, ^bb10
    ^bb9:
      %27 = arith.constant 0 : i32
      func.return %27 : i32
    ^bb10:
      cf.br ^bb11
    ^bb11:
    %28 = arith.constant 0 : i32
    %29 = llvm.mlir.constant(1 : i64) : i64
    %30 = llvm.alloca %29 x i32 : (i64) -> !llvm.ptr
    llvm.store %28, %30 : i32, !llvm.ptr
    %31 = arith.constant 0 : i32
    %32 = llvm.mlir.constant(1 : i64) : i64
    %33 = llvm.alloca %32 x i32 : (i64) -> !llvm.ptr
    llvm.store %31, %33 : i32, !llvm.ptr
    %34 = llvm.mlir.constant(1 : i64) : i64
    %35 = llvm.alloca %34 x i32 : (i64) -> !llvm.ptr
    llvm.store %arg1, %35 : i32, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %36 = llvm.load %35 : !llvm.ptr -> i32
    %37 = arith.cmpi slt, %36, %arg2 : i32
    cf.cond_br %37, ^bb13, ^bb14
    ^bb13:
      %38 = llvm.load %30 : !llvm.ptr -> i32
      %40 = llvm.load %35 : !llvm.ptr -> i32
      %41 = arith.extsi %40 : i32 to i64
      %42 = llvm.getelementptr %arg0[%41] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %39 = llvm.load %42 : !llvm.ptr -> i32
      %43 = arith.addi %38, %39 : i32
      llvm.store %43, %30 : i32, !llvm.ptr
      %44 = llvm.load %33 : !llvm.ptr -> i32
      %45 = arith.constant 1 : i32
      %46 = arith.addi %44, %45 : i32
      llvm.store %46, %33 : i32, !llvm.ptr
      %47 = llvm.load %35 : !llvm.ptr -> i32
      %48 = arith.constant 1 : i32
      %49 = arith.addi %47, %48 : i32
      llvm.store %49, %35 : i32, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %50 = llvm.load %30 : !llvm.ptr -> i32
    %51 = arith.cmpi slt, %50, %arg3 : i32
    %52 = scf.if %51 -> (i1) {
      %53 = arith.constant true
      scf.yield %53 : i1
    } else {
      %54 = llvm.load %33 : !llvm.ptr -> i32
      %55 = arith.constant 0 : i32
      %56 = arith.cmpi eq, %54, %55 : i32
      scf.yield %56 : i1
    }
    cf.cond_br %52, ^bb15, ^bb16
    ^bb15:
      %57 = arith.constant 0 : i32
      func.return %57 : i32
    ^bb16:
      cf.br ^bb17
    ^bb17:
    %58 = arith.constant 0 : i32
    %59 = arith.cmpi eq, %arg3, %58 : i32
    %60 = scf.if %59 -> (i1) {
      %61 = arith.constant true
      scf.yield %61 : i1
    } else {
      %62 = llvm.load %33 : !llvm.ptr -> i32
      %63 = arith.constant 1 : i32
      %64 = arith.cmpi eq, %62, %63 : i32
      scf.yield %64 : i1
    }
    cf.cond_br %60, ^bb18, ^bb19
    ^bb18:
      %65 = arith.constant 1 : i32
      func.return %65 : i32
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %66 = arith.constant 0 : i32
    %67 = llvm.mlir.constant(1 : i64) : i64
    %68 = llvm.alloca %67 x i32 : (i64) -> !llvm.ptr
    llvm.store %66, %68 : i32, !llvm.ptr
    %69 = arith.constant 0 : i32
    %70 = llvm.mlir.constant(1 : i64) : i64
    %71 = llvm.alloca %70 x i32 : (i64) -> !llvm.ptr
    llvm.store %69, %71 : i32, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %72 = llvm.load %71 : !llvm.ptr -> i32
    %74 = arith.extsi %arg1 : i32 to i64
    %75 = llvm.getelementptr %arg0[%74] : (!llvm.ptr, i64) -> !llvm.ptr, i32
    %73 = llvm.load %75 : !llvm.ptr -> i32
    %76 = arith.cmpi sle, %72, %73 : i32
    cf.cond_br %76, ^bb22, ^bb23
    ^bb22:
      %77 = llvm.load %68 : !llvm.ptr -> i32
      %79 = arith.constant 1 : i32
      %80 = arith.addi %arg1, %79 : i32
      %81 = llvm.load %71 : !llvm.ptr -> i32
      %82 = arith.subi %arg3, %81 : i32
      %78 = func.call @antichain(%arg0, %80, %arg2, %82) : (!llvm.ptr, i32, i32, i32) -> i32
      %83 = arith.addi %77, %78 : i32
      llvm.store %83, %68 : i32, !llvm.ptr
      %84 = llvm.load %71 : !llvm.ptr -> i32
      %85 = arith.constant 1 : i32
      %86 = arith.addi %84, %85 : i32
      llvm.store %86, %71 : i32, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %87 = llvm.load %68 : !llvm.ptr -> i32
    func.return %87 : i32
  }
  func.func @sort_exps(%arg0: !llvm.ptr, %arg1: i32) -> () {
    %88 = arith.constant 1 : i32
    %89 = llvm.mlir.constant(1 : i64) : i64
    %90 = llvm.alloca %89 x i32 : (i64) -> !llvm.ptr
    llvm.store %88, %90 : i32, !llvm.ptr
    cf.br ^bb24
    ^bb24:
    %91 = llvm.load %90 : !llvm.ptr -> i32
    %92 = arith.cmpi slt, %91, %arg1 : i32
    cf.cond_br %92, ^bb25, ^bb26
    ^bb25:
      %94 = llvm.load %90 : !llvm.ptr -> i32
      %95 = arith.extsi %94 : i32 to i64
      %96 = llvm.getelementptr %arg0[%95] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %93 = llvm.load %96 : !llvm.ptr -> i32
      %97 = llvm.load %90 : !llvm.ptr -> i32
      %98 = arith.constant 1 : i32
      %99 = arith.subi %97, %98 : i32
      %100 = llvm.mlir.constant(1 : i64) : i64
      %101 = llvm.alloca %100 x i32 : (i64) -> !llvm.ptr
      llvm.store %99, %101 : i32, !llvm.ptr
      cf.br ^bb27
      ^bb27:
      %102 = llvm.load %101 : !llvm.ptr -> i32
      %103 = arith.constant 0 : i32
      %104 = arith.cmpi sge, %102, %103 : i32
      %105 = scf.if %104 -> (i1) {
        %107 = llvm.load %101 : !llvm.ptr -> i32
        %108 = arith.extsi %107 : i32 to i64
        %109 = llvm.getelementptr %arg0[%108] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %106 = llvm.load %109 : !llvm.ptr -> i32
        %110 = arith.cmpi sgt, %106, %93 : i32
        scf.yield %110 : i1
      } else {
        %111 = arith.constant false
        scf.yield %111 : i1
      }
      cf.cond_br %105, ^bb28, ^bb29
      ^bb28:
        %113 = llvm.load %101 : !llvm.ptr -> i32
        %114 = arith.extsi %113 : i32 to i64
        %115 = llvm.getelementptr %arg0[%114] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %112 = llvm.load %115 : !llvm.ptr -> i32
        %116 = llvm.load %101 : !llvm.ptr -> i32
        %117 = arith.constant 1 : i32
        %118 = arith.addi %116, %117 : i32
        %119 = arith.extsi %118 : i32 to i64
        %120 = llvm.getelementptr %arg0[%119] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %112, %120 : i32, !llvm.ptr
        %121 = llvm.load %101 : !llvm.ptr -> i32
        %122 = arith.constant 1 : i32
        %123 = arith.subi %121, %122 : i32
        llvm.store %123, %101 : i32, !llvm.ptr
        cf.br ^bb27
      ^bb29:
      %124 = llvm.load %101 : !llvm.ptr -> i32
      %125 = arith.constant 1 : i32
      %126 = arith.addi %124, %125 : i32
      %127 = arith.extsi %126 : i32 to i64
      %128 = llvm.getelementptr %arg0[%127] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %93, %128 : i32, !llvm.ptr
      %129 = llvm.load %90 : !llvm.ptr -> i32
      %130 = arith.constant 1 : i32
      %131 = arith.addi %129, %130 : i32
      llvm.store %131, %90 : i32, !llvm.ptr
      cf.br ^bb24
    ^bb26:
    func.return
  }
  func.func @pack_exps(%arg0: !llvm.ptr, %arg1: i32) -> i64 {
    %132 = arith.extsi %arg1 : i32 to i64
    %133 = llvm.mlir.constant(1 : i64) : i64
    %134 = llvm.alloca %133 x i64 : (i64) -> !llvm.ptr
    llvm.store %132, %134 : i64, !llvm.ptr
    %135 = arith.constant 0 : i32
    %136 = llvm.mlir.constant(1 : i64) : i64
    %137 = llvm.alloca %136 x i32 : (i64) -> !llvm.ptr
    llvm.store %135, %137 : i32, !llvm.ptr
    cf.br ^bb30
    ^bb30:
    %138 = llvm.load %137 : !llvm.ptr -> i32
    %139 = arith.cmpi slt, %138, %arg1 : i32
    cf.cond_br %139, ^bb31, ^bb32
    ^bb31:
      %140 = llvm.load %134 : !llvm.ptr -> i64
      %141 = arith.constant 40 : i32
      %143 = arith.extsi %141 : i32 to i64
      %142 = arith.muli %140, %143 : i64
      %145 = llvm.load %137 : !llvm.ptr -> i32
      %146 = arith.extsi %145 : i32 to i64
      %147 = llvm.getelementptr %arg0[%146] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %144 = llvm.load %147 : !llvm.ptr -> i32
      %148 = arith.extsi %144 : i32 to i64
      %149 = arith.addi %142, %148 : i64
      llvm.store %149, %134 : i64, !llvm.ptr
      %150 = llvm.load %137 : !llvm.ptr -> i32
      %151 = arith.constant 1 : i32
      %152 = arith.addi %150, %151 : i32
      llvm.store %152, %137 : i32, !llvm.ptr
      cf.br ^bb30
    ^bb32:
    %153 = llvm.load %134 : !llvm.ptr -> i64
    func.return %153 : i64
  }
  func.func @cache_get(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: !llvm.ptr, %arg3: i64, %arg4: i64) -> i32 {
    %154 = llvm.mlir.constant(1 : i64) : i64
    %155 = llvm.alloca %154 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg4, %155 : i64, !llvm.ptr
    %156 = llvm.load %155 : !llvm.ptr -> i64
    %157 = arith.constant 0 : i32
    %159 = arith.extsi %157 : i32 to i64
    %158 = arith.cmpi slt, %156, %159 : i64
    cf.cond_br %158, ^bb33, ^bb34
    ^bb33:
      %160 = arith.constant 0 : i32
      %161 = llvm.load %155 : !llvm.ptr -> i64
      %163 = arith.extsi %160 : i32 to i64
      %162 = arith.subi %163, %161 : i64
      llvm.store %162, %155 : i64, !llvm.ptr
      cf.br ^bb35
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %164 = llvm.load %155 : !llvm.ptr -> i64
    %165 = arith.constant 1 : i32
    %167 = arith.extsi %165 : i32 to i64
    %166 = arith.subi %arg3, %167 : i64
    %168 = arith.andi %164, %166 : i64
    llvm.store %168, %155 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %170 = llvm.load %155 : !llvm.ptr -> i64
    %171 = llvm.getelementptr %arg2[%170] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    %169 = llvm.load %171 : !llvm.ptr -> i8
    %172 = arith.constant 0 : i32
    %174 = arith.extsi %169 : i8 to i32
    %173 = arith.cmpi ne, %174, %172 : i32
    cf.cond_br %173, ^bb37, ^bb38
    ^bb37:
      %176 = llvm.load %155 : !llvm.ptr -> i64
      %177 = llvm.getelementptr %arg0[%176] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %175 = llvm.load %177 : !llvm.ptr -> i64
      %178 = arith.cmpi eq, %175, %arg4 : i64
      cf.cond_br %178, ^bb39, ^bb40
      ^bb39:
        %180 = llvm.load %155 : !llvm.ptr -> i64
        %181 = llvm.getelementptr %arg1[%180] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %179 = llvm.load %181 : !llvm.ptr -> i32
        func.return %179 : i32
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %182 = llvm.load %155 : !llvm.ptr -> i64
      %183 = arith.constant 1 : i32
      %185 = arith.extsi %183 : i32 to i64
      %184 = arith.addi %182, %185 : i64
      %186 = arith.constant 1 : i32
      %188 = arith.extsi %186 : i32 to i64
      %187 = arith.subi %arg3, %188 : i64
      %189 = arith.andi %184, %187 : i64
      llvm.store %189, %155 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %190 = arith.constant 0 : i32
    %191 = arith.constant 1 : i32
    %192 = arith.subi %190, %191 : i32
    func.return %192 : i32
  }
  func.func @cache_put(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: !llvm.ptr, %arg3: i64, %arg4: i64, %arg5: i32) -> () {
    %193 = llvm.mlir.constant(1 : i64) : i64
    %194 = llvm.alloca %193 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg4, %194 : i64, !llvm.ptr
    %195 = llvm.load %194 : !llvm.ptr -> i64
    %196 = arith.constant 0 : i32
    %198 = arith.extsi %196 : i32 to i64
    %197 = arith.cmpi slt, %195, %198 : i64
    cf.cond_br %197, ^bb42, ^bb43
    ^bb42:
      %199 = arith.constant 0 : i32
      %200 = llvm.load %194 : !llvm.ptr -> i64
      %202 = arith.extsi %199 : i32 to i64
      %201 = arith.subi %202, %200 : i64
      llvm.store %201, %194 : i64, !llvm.ptr
      cf.br ^bb44
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %203 = llvm.load %194 : !llvm.ptr -> i64
    %204 = arith.constant 1 : i32
    %206 = arith.extsi %204 : i32 to i64
    %205 = arith.subi %arg3, %206 : i64
    %207 = arith.andi %203, %205 : i64
    llvm.store %207, %194 : i64, !llvm.ptr
    cf.br ^bb45
    ^bb45:
    %209 = llvm.load %194 : !llvm.ptr -> i64
    %210 = llvm.getelementptr %arg2[%209] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    %208 = llvm.load %210 : !llvm.ptr -> i8
    %211 = arith.constant 0 : i32
    %213 = arith.extsi %208 : i8 to i32
    %212 = arith.cmpi ne, %213, %211 : i32
    %214 = scf.if %212 -> (i1) {
      %216 = llvm.load %194 : !llvm.ptr -> i64
      %217 = llvm.getelementptr %arg0[%216] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %215 = llvm.load %217 : !llvm.ptr -> i64
      %218 = arith.cmpi ne, %215, %arg4 : i64
      scf.yield %218 : i1
    } else {
      %219 = arith.constant false
      scf.yield %219 : i1
    }
    cf.cond_br %214, ^bb46, ^bb47
    ^bb46:
      %220 = llvm.load %194 : !llvm.ptr -> i64
      %221 = arith.constant 1 : i32
      %223 = arith.extsi %221 : i32 to i64
      %222 = arith.addi %220, %223 : i64
      %224 = arith.constant 1 : i32
      %226 = arith.extsi %224 : i32 to i64
      %225 = arith.subi %arg3, %226 : i64
      %227 = arith.andi %222, %225 : i64
      llvm.store %227, %194 : i64, !llvm.ptr
      cf.br ^bb45
    ^bb47:
    %228 = arith.constant 1 : i32
    %229 = llvm.load %194 : !llvm.ptr -> i64
    %230 = arith.trunci %228 : i32 to i8
    %231 = llvm.getelementptr %arg2[%229] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %230, %231 : i8, !llvm.ptr
    %232 = llvm.load %194 : !llvm.ptr -> i64
    %233 = llvm.getelementptr %arg0[%232] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %arg4, %233 : i64, !llvm.ptr
    %234 = llvm.load %194 : !llvm.ptr -> i64
    %235 = llvm.getelementptr %arg1[%234] : (!llvm.ptr, i64) -> !llvm.ptr, i32
    llvm.store %arg5, %235 : i32, !llvm.ptr
    func.return
  }
  func.func @evaluate(%arg0: !llvm.ptr, %arg1: i32, %arg2: !llvm.ptr, %arg3: !llvm.ptr, %arg4: !llvm.ptr, %arg5: !llvm.ptr, %arg6: i64) -> i32 {
    %236 = arith.constant 1 : i32
    %237 = llvm.mlir.constant(1 : i64) : i64
    %238 = llvm.alloca %237 x i32 : (i64) -> !llvm.ptr
    llvm.store %236, %238 : i32, !llvm.ptr
    %239 = arith.constant 1 : i32
    %240 = arith.constant 0 : i32
    %241 = arith.extsi %240 : i32 to i64
    %242 = llvm.getelementptr %arg2[%241] : (!llvm.ptr, i64) -> !llvm.ptr, i32
    llvm.store %239, %242 : i32, !llvm.ptr
    %243 = arith.constant 1 : i32
    %244 = llvm.mlir.constant(1 : i64) : i64
    %245 = llvm.alloca %244 x i32 : (i64) -> !llvm.ptr
    llvm.store %243, %245 : i32, !llvm.ptr
    cf.br ^bb48
    ^bb48:
    %246 = llvm.load %245 : !llvm.ptr -> i32
    %247 = arith.cmpi slt, %246, %arg1 : i32
    cf.cond_br %247, ^bb49, ^bb50
    ^bb49:
      %249 = llvm.load %245 : !llvm.ptr -> i32
      %250 = arith.extsi %249 : i32 to i64
      %251 = llvm.getelementptr %arg0[%250] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %248 = llvm.load %251 : !llvm.ptr -> i32
      %253 = llvm.load %245 : !llvm.ptr -> i32
      %254 = arith.constant 1 : i32
      %255 = arith.subi %253, %254 : i32
      %256 = arith.extsi %255 : i32 to i64
      %257 = llvm.getelementptr %arg0[%256] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %252 = llvm.load %257 : !llvm.ptr -> i32
      %258 = arith.cmpi eq, %248, %252 : i32
      cf.cond_br %258, ^bb51, ^bb52
      ^bb51:
        %260 = llvm.load %238 : !llvm.ptr -> i32
        %261 = arith.constant 1 : i32
        %262 = arith.subi %260, %261 : i32
        %263 = arith.extsi %262 : i32 to i64
        %264 = llvm.getelementptr %arg2[%263] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %259 = llvm.load %264 : !llvm.ptr -> i32
        %265 = arith.constant 1 : i32
        %266 = arith.addi %259, %265 : i32
        %267 = llvm.load %238 : !llvm.ptr -> i32
        %268 = arith.constant 1 : i32
        %269 = arith.subi %267, %268 : i32
        %270 = arith.extsi %269 : i32 to i64
        %271 = llvm.getelementptr %arg2[%270] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %266, %271 : i32, !llvm.ptr
        cf.br ^bb53
      ^bb52:
        %272 = arith.constant 1 : i32
        %273 = llvm.load %238 : !llvm.ptr -> i32
        %274 = arith.extsi %273 : i32 to i64
        %275 = llvm.getelementptr %arg2[%274] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %272, %275 : i32, !llvm.ptr
        %276 = llvm.load %238 : !llvm.ptr -> i32
        %277 = arith.constant 1 : i32
        %278 = arith.addi %276, %277 : i32
        llvm.store %278, %238 : i32, !llvm.ptr
        cf.br ^bb53
      ^bb53:
      %279 = llvm.load %245 : !llvm.ptr -> i32
      %280 = arith.constant 1 : i32
      %281 = arith.addi %279, %280 : i32
      llvm.store %281, %245 : i32, !llvm.ptr
      cf.br ^bb48
    ^bb50:
    %283 = llvm.load %238 : !llvm.ptr -> i32
    func.call @sort_exps(%arg2, %283) : (!llvm.ptr, i32) -> ()
    %285 = llvm.load %238 : !llvm.ptr -> i32
    %284 = func.call @pack_exps(%arg2, %285) : (!llvm.ptr, i32) -> i64
    %286 = func.call @cache_get(%arg3, %arg4, %arg5, %arg6, %284) : (!llvm.ptr, !llvm.ptr, !llvm.ptr, i64, i64) -> i32
    %287 = arith.constant 0 : i32
    %288 = arith.cmpi sge, %286, %287 : i32
    cf.cond_br %288, ^bb54, ^bb55
    ^bb54:
      func.return %286 : i32
    ^bb55:
      cf.br ^bb56
    ^bb56:
    %290 = arith.constant 0 : i32
    %291 = llvm.load %238 : !llvm.ptr -> i32
    %292 = arith.constant 2 : i32
    %293 = arith.divsi %arg1, %292 : i32
    %289 = func.call @antichain(%arg2, %290, %291, %293) : (!llvm.ptr, i32, i32, i32) -> i32
    func.call @cache_put(%arg3, %arg4, %arg5, %arg6, %284, %289) : (!llvm.ptr, !llvm.ptr, !llvm.ptr, i64, i64, i32) -> ()
    func.return %289 : i32
  }
  func.func @search(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: !llvm.ptr, %arg4: i32, %arg5: !llvm.ptr, %arg6: !llvm.ptr, %arg7: !llvm.ptr, %arg8: !llvm.ptr, %arg9: !llvm.ptr, %arg10: i64) -> i64 {
    %295 = arith.constant 0 : i32
    %296 = arith.extsi %295 : i32 to i64
    %297 = llvm.mlir.constant(1 : i64) : i64
    %298 = llvm.alloca %297 x i64 : (i64) -> !llvm.ptr
    llvm.store %296, %298 : i64, !llvm.ptr
    %299 = llvm.mlir.constant(1 : i64) : i64
    %300 = llvm.alloca %299 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg2, %300 : i64, !llvm.ptr
    cf.br ^bb57
    ^bb57:
    %301 = llvm.load %300 : !llvm.ptr -> i64
    %302 = arith.cmpi sle, %301, %arg0 : i64
    cf.cond_br %302, ^bb58, ^bb59
    ^bb58:
      %304 = llvm.load %300 : !llvm.ptr -> i64
      %303 = func.call @is_prime(%304, %arg5) : (i64, !llvm.ptr) -> i64
      %305 = arith.constant 1 : i32
      %307 = arith.extsi %305 : i32 to i64
      %306 = arith.cmpi eq, %303, %307 : i64
      cf.cond_br %306, ^bb60, ^bb61
      ^bb60:
        %308 = llvm.load %300 : !llvm.ptr -> i64
        %309 = arith.divsi %arg0, %308 : i64
        %310 = arith.cmpi sgt, %arg1, %309 : i64
        cf.cond_br %310, ^bb63, ^bb64
        ^bb63:
          cf.br ^bb59
        ^bb64:
          cf.br ^bb65
        ^bb65:
        %311 = llvm.load %300 : !llvm.ptr -> i64
        %312 = arith.muli %arg1, %311 : i64
        %313 = llvm.load %300 : !llvm.ptr -> i64
        %314 = arith.trunci %313 : i64 to i32
        %315 = arith.extsi %arg4 : i32 to i64
        %316 = llvm.getelementptr %arg3[%315] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %314, %316 : i32, !llvm.ptr
        %317 = llvm.load %298 : !llvm.ptr -> i64
        %319 = arith.constant 1 : i32
        %320 = arith.addi %arg4, %319 : i32
        %318 = func.call @evaluate(%arg3, %320, %arg6, %arg7, %arg8, %arg9, %arg10) : (!llvm.ptr, i32, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i32
        %321 = arith.extsi %318 : i32 to i64
        %322 = arith.addi %317, %321 : i64
        llvm.store %322, %298 : i64, !llvm.ptr
        %323 = llvm.load %300 : !llvm.ptr -> i64
        %324 = arith.divsi %arg0, %323 : i64
        %325 = arith.cmpi sle, %312, %324 : i64
        cf.cond_br %325, ^bb66, ^bb67
        ^bb66:
          %326 = llvm.load %298 : !llvm.ptr -> i64
          %328 = llvm.load %300 : !llvm.ptr -> i64
          %329 = arith.constant 1 : i32
          %330 = arith.addi %arg4, %329 : i32
          %327 = func.call @search(%arg0, %312, %328, %arg3, %330, %arg5, %arg6, %arg7, %arg8, %arg9, %arg10) : (i64, i64, i64, !llvm.ptr, i32, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i64
          %331 = arith.addi %326, %327 : i64
          llvm.store %331, %298 : i64, !llvm.ptr
          cf.br ^bb68
        ^bb67:
          cf.br ^bb68
        ^bb68:
        cf.br ^bb62
      ^bb61:
        cf.br ^bb62
      ^bb62:
      %332 = llvm.load %300 : !llvm.ptr -> i64
      %333 = arith.constant 2 : i32
      %335 = arith.extsi %333 : i32 to i64
      %334 = arith.cmpi eq, %332, %335 : i64
      cf.cond_br %334, ^bb69, ^bb70
      ^bb69:
        %336 = arith.constant 3 : i32
        %337 = arith.extsi %336 : i32 to i64
        llvm.store %337, %300 : i64, !llvm.ptr
        cf.br ^bb71
      ^bb70:
        %338 = llvm.load %300 : !llvm.ptr -> i64
        %339 = arith.constant 2 : i32
        %341 = arith.extsi %339 : i32 to i64
        %340 = arith.addi %338, %341 : i64
        llvm.store %340, %300 : i64, !llvm.ptr
        cf.br ^bb71
      ^bb71:
      cf.br ^bb57
    ^bb59:
    %342 = llvm.load %298 : !llvm.ptr -> i64
    func.return %342 : i64
  }
  func.func @main() -> i32 {
    %343 = arith.constant 100000000 : i32
    %344 = arith.extsi %343 : i32 to i64
    %345 = arith.constant 1 : i32
    %347 = arith.extsi %345 : i32 to i64
    %346 = arith.shrsi %344, %347 : i64
    %349 = arith.constant 1 : i32
    %350 = arith.extsi %349 : i32 to i64
    %348 = func.call @calloc(%346, %350) : (i64, i64) -> !llvm.ptr
    %351 = llvm.mlir.zero : !llvm.ptr
    %352 = llvm.icmp "eq" %348, %351 : !llvm.ptr
    cf.cond_br %352, ^bb72, ^bb73
    ^bb72:
      %353 = arith.constant 1 : i32
      func.return %353 : i32
    ^bb73:
      cf.br ^bb74
    ^bb74:
    %354 = arith.constant 0 : i32
    %355 = arith.extsi %354 : i32 to i64
    %356 = llvm.mlir.constant(1 : i64) : i64
    %357 = llvm.alloca %356 x i64 : (i64) -> !llvm.ptr
    llvm.store %355, %357 : i64, !llvm.ptr
    cf.br ^bb75
    ^bb75:
    %358 = llvm.load %357 : !llvm.ptr -> i64
    %359 = arith.cmpi slt, %358, %346 : i64
    cf.cond_br %359, ^bb76, ^bb77
    ^bb76:
      %360 = arith.constant 1 : i32
      %361 = llvm.load %357 : !llvm.ptr -> i64
      %362 = arith.trunci %360 : i32 to i8
      %363 = llvm.getelementptr %348[%361] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %362, %363 : i8, !llvm.ptr
      %364 = llvm.load %357 : !llvm.ptr -> i64
      %365 = arith.constant 1 : i32
      %367 = arith.extsi %365 : i32 to i64
      %366 = arith.addi %364, %367 : i64
      llvm.store %366, %357 : i64, !llvm.ptr
      cf.br ^bb75
    ^bb77:
    %368 = arith.constant 0 : i32
    %369 = arith.constant 0 : i32
    %370 = arith.trunci %368 : i32 to i8
    %371 = arith.extsi %369 : i32 to i64
    %372 = llvm.getelementptr %348[%371] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %370, %372 : i8, !llvm.ptr
    %373 = arith.constant 1 : i32
    %374 = arith.extsi %373 : i32 to i64
    llvm.store %374, %357 : i64, !llvm.ptr
    cf.br ^bb78
    ^bb78:
    %375 = arith.constant 2 : i32
    %376 = llvm.load %357 : !llvm.ptr -> i64
    %378 = arith.extsi %375 : i32 to i64
    %377 = arith.muli %378, %376 : i64
    %379 = llvm.load %357 : !llvm.ptr -> i64
    %380 = arith.muli %377, %379 : i64
    %381 = arith.cmpi slt, %380, %346 : i64
    cf.cond_br %381, ^bb79, ^bb80
    ^bb79:
      %383 = llvm.load %357 : !llvm.ptr -> i64
      %384 = llvm.getelementptr %348[%383] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %382 = llvm.load %384 : !llvm.ptr -> i8
      %385 = arith.constant 0 : i32
      %387 = arith.extsi %382 : i8 to i32
      %386 = arith.cmpi ne, %387, %385 : i32
      cf.cond_br %386, ^bb81, ^bb82
      ^bb81:
        %388 = arith.constant 3 : i32
        %389 = llvm.load %357 : !llvm.ptr -> i64
        %391 = arith.extsi %388 : i32 to i64
        %390 = arith.muli %391, %389 : i64
        %392 = arith.constant 1 : i32
        %394 = arith.extsi %392 : i32 to i64
        %393 = arith.addi %390, %394 : i64
        %395 = llvm.mlir.constant(1 : i64) : i64
        %396 = llvm.alloca %395 x i64 : (i64) -> !llvm.ptr
        llvm.store %393, %396 : i64, !llvm.ptr
        cf.br ^bb84
        ^bb84:
        %397 = llvm.load %396 : !llvm.ptr -> i64
        %398 = arith.cmpi slt, %397, %346 : i64
        cf.cond_br %398, ^bb85, ^bb86
        ^bb85:
          %399 = arith.constant 0 : i32
          %400 = llvm.load %396 : !llvm.ptr -> i64
          %401 = arith.trunci %399 : i32 to i8
          %402 = llvm.getelementptr %348[%400] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %401, %402 : i8, !llvm.ptr
          %403 = llvm.load %396 : !llvm.ptr -> i64
          %404 = arith.constant 2 : i32
          %405 = llvm.load %357 : !llvm.ptr -> i64
          %407 = arith.extsi %404 : i32 to i64
          %406 = arith.muli %407, %405 : i64
          %408 = arith.addi %403, %406 : i64
          %409 = arith.constant 1 : i32
          %411 = arith.extsi %409 : i32 to i64
          %410 = arith.addi %408, %411 : i64
          llvm.store %410, %396 : i64, !llvm.ptr
          cf.br ^bb84
        ^bb86:
        cf.br ^bb83
      ^bb82:
        cf.br ^bb83
      ^bb83:
      %412 = llvm.load %357 : !llvm.ptr -> i64
      %413 = arith.constant 1 : i32
      %415 = arith.extsi %413 : i32 to i64
      %414 = arith.addi %412, %415 : i64
      llvm.store %414, %357 : i64, !llvm.ptr
      cf.br ^bb78
    ^bb80:
    %416 = arith.constant 65536 : i32
    %417 = arith.extsi %416 : i32 to i64
    %419 = arith.constant 8 : i32
    %420 = arith.extsi %419 : i32 to i64
    %418 = func.call @calloc(%417, %420) : (i64, i64) -> !llvm.ptr
    %422 = arith.constant 4 : i32
    %423 = arith.extsi %422 : i32 to i64
    %421 = func.call @calloc(%417, %423) : (i64, i64) -> !llvm.ptr
    %425 = arith.constant 1 : i32
    %426 = arith.extsi %425 : i32 to i64
    %424 = func.call @calloc(%417, %426) : (i64, i64) -> !llvm.ptr
    %428 = arith.constant 64 : i32
    %429 = arith.constant 4 : i32
    %430 = arith.extsi %428 : i32 to i64
    %431 = arith.extsi %429 : i32 to i64
    %427 = func.call @calloc(%430, %431) : (i64, i64) -> !llvm.ptr
    %433 = arith.constant 64 : i32
    %434 = arith.constant 4 : i32
    %435 = arith.extsi %433 : i32 to i64
    %436 = arith.extsi %434 : i32 to i64
    %432 = func.call @calloc(%435, %436) : (i64, i64) -> !llvm.ptr
    %437 = llvm.mlir.zero : !llvm.ptr
    %438 = llvm.icmp "eq" %418, %437 : !llvm.ptr
    %439 = scf.if %438 -> (i1) {
      %440 = arith.constant true
      scf.yield %440 : i1
    } else {
      %441 = llvm.mlir.zero : !llvm.ptr
      %442 = llvm.icmp "eq" %421, %441 : !llvm.ptr
      scf.yield %442 : i1
    }
    %443 = scf.if %439 -> (i1) {
      %444 = arith.constant true
      scf.yield %444 : i1
    } else {
      %445 = llvm.mlir.zero : !llvm.ptr
      %446 = llvm.icmp "eq" %424, %445 : !llvm.ptr
      scf.yield %446 : i1
    }
    %447 = scf.if %443 -> (i1) {
      %448 = arith.constant true
      scf.yield %448 : i1
    } else {
      %449 = llvm.mlir.zero : !llvm.ptr
      %450 = llvm.icmp "eq" %427, %449 : !llvm.ptr
      scf.yield %450 : i1
    }
    %451 = scf.if %447 -> (i1) {
      %452 = arith.constant true
      scf.yield %452 : i1
    } else {
      %453 = llvm.mlir.zero : !llvm.ptr
      %454 = llvm.icmp "eq" %432, %453 : !llvm.ptr
      scf.yield %454 : i1
    }
    cf.cond_br %451, ^bb87, ^bb88
    ^bb87:
      %455 = arith.constant 1 : i32
      func.return %455 : i32
    ^bb88:
      cf.br ^bb89
    ^bb89:
    %456 = arith.constant 1 : i32
    %457 = arith.extsi %456 : i32 to i64
    %458 = llvm.mlir.constant(1 : i64) : i64
    %459 = llvm.alloca %458 x i64 : (i64) -> !llvm.ptr
    llvm.store %457, %459 : i64, !llvm.ptr
    %460 = arith.constant 2 : i32
    %461 = arith.extsi %460 : i32 to i64
    %462 = llvm.mlir.constant(1 : i64) : i64
    %463 = llvm.alloca %462 x i64 : (i64) -> !llvm.ptr
    llvm.store %461, %463 : i64, !llvm.ptr
    cf.br ^bb90
    ^bb90:
    %464 = llvm.load %463 : !llvm.ptr -> i64
    %465 = arith.cmpi sle, %464, %344 : i64
    cf.cond_br %465, ^bb91, ^bb92
    ^bb91:
      %467 = llvm.load %463 : !llvm.ptr -> i64
      %466 = func.call @is_prime(%467, %348) : (i64, !llvm.ptr) -> i64
      %468 = arith.constant 1 : i32
      %470 = arith.extsi %468 : i32 to i64
      %469 = arith.cmpi eq, %466, %470 : i64
      cf.cond_br %469, ^bb93, ^bb94
      ^bb93:
        %471 = llvm.load %463 : !llvm.ptr -> i64
        %472 = arith.trunci %471 : i64 to i32
        %473 = arith.constant 0 : i32
        %474 = arith.extsi %473 : i32 to i64
        %475 = llvm.getelementptr %427[%474] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %472, %475 : i32, !llvm.ptr
        %476 = llvm.load %459 : !llvm.ptr -> i64
        %478 = arith.constant 1 : i32
        %477 = func.call @evaluate(%427, %478, %432, %418, %421, %424, %417) : (!llvm.ptr, i32, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i32
        %479 = arith.extsi %477 : i32 to i64
        %480 = arith.addi %476, %479 : i64
        llvm.store %480, %459 : i64, !llvm.ptr
        %481 = llvm.load %463 : !llvm.ptr -> i64
        %482 = llvm.load %463 : !llvm.ptr -> i64
        %483 = arith.divsi %344, %482 : i64
        %484 = arith.cmpi sle, %481, %483 : i64
        cf.cond_br %484, ^bb96, ^bb97
        ^bb96:
          %485 = llvm.load %459 : !llvm.ptr -> i64
          %487 = llvm.load %463 : !llvm.ptr -> i64
          %488 = llvm.load %463 : !llvm.ptr -> i64
          %489 = arith.constant 1 : i32
          %486 = func.call @search(%344, %487, %488, %427, %489, %348, %432, %418, %421, %424, %417) : (i64, i64, i64, !llvm.ptr, i32, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i64
          %490 = arith.addi %485, %486 : i64
          llvm.store %490, %459 : i64, !llvm.ptr
          cf.br ^bb98
        ^bb97:
          cf.br ^bb98
        ^bb98:
        cf.br ^bb95
      ^bb94:
        cf.br ^bb95
      ^bb95:
      %491 = llvm.load %463 : !llvm.ptr -> i64
      %492 = arith.constant 2 : i32
      %494 = arith.extsi %492 : i32 to i64
      %493 = arith.cmpi eq, %491, %494 : i64
      cf.cond_br %493, ^bb99, ^bb100
      ^bb99:
        %495 = arith.constant 3 : i32
        %496 = arith.extsi %495 : i32 to i64
        llvm.store %496, %463 : i64, !llvm.ptr
        cf.br ^bb101
      ^bb100:
        %497 = llvm.load %463 : !llvm.ptr -> i64
        %498 = arith.constant 2 : i32
        %500 = arith.extsi %498 : i32 to i64
        %499 = arith.addi %497, %500 : i64
        llvm.store %499, %463 : i64, !llvm.ptr
        cf.br ^bb101
      ^bb101:
      cf.br ^bb90
    ^bb92:
    %501 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %502 = llvm.load %459 : !llvm.ptr -> i64
    %503 = llvm.call @printf(%501, %502) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%432) : (!llvm.ptr) -> ()
    func.call @free(%427) : (!llvm.ptr) -> ()
    func.call @free(%424) : (!llvm.ptr) -> ()
    func.call @free(%421) : (!llvm.ptr) -> ()
    func.call @free(%418) : (!llvm.ptr) -> ()
    func.call @free(%348) : (!llvm.ptr) -> ()
    %510 = arith.constant 0 : i32
    func.return %510 : i32
  }
}