Problem 565

Divisibility of Sum of Divisors Sum of n<=10^11 with sigma(n) divisible by 2017, via inclusion of trigger powers.

Answer2992480851924313898
Output2992480851924313898
StatusPASS
Native helperno
Runtime420 ms
Peak memory68288 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n log log n)
Space complexityO(n^2)O(n)
ApproachFlow solutionSieve-based divisor sums
VerdictSuboptimal

Flow source

# Project Euler 565
# Divisibility of Sum of Divisors
# Sum of n<=10^11 with sigma(n) divisible by 2017, via inclusion of trigger powers.

import euler.nt { isqrt }

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

function triangular(n: i64) -> i64 {
    return n * (n + 1) / 2
}

function modpow(base0: i64, exp0: i64, mod: i64) -> i64 {
    let mut result: i64 = 1
    let mut base: i64 = base0 % mod
    let mut exp: i64 = exp0
    while exp > 0 {
        if (exp & 1) != 0 {
            result = ((result as i128) * (base as i128) % (mod as i128)) as i64
        }
        base = ((base as i128) * (base as i128) % (mod as i128)) as i64
        exp = exp >> 1
    }
    return result
}

function prime_factors_into(n0: i64, out: ptr<i64>) -> i64 {
    let mut n: i64 = n0
    let mut c: i64 = 0
    let mut d: i64 = 2
    while d * d <= n {
        if n % d == 0 {
            out[c] = d
            c = c + 1
            while n % d == 0 { n = n / d }
        }
        if d == 2 { d = 3 } else { d = d + 2 }
    }
    if n > 1 {
        out[c] = n
        c = c + 1
    }
    return c
}

function multiplicative_order(base: i64, modulo: i64, factors: ptr<i64>, nf: i64) -> i64 {
    let mut order: i64 = modulo - 1
    let residue: i64 = base % modulo
    let mut i: i64 = 0
    while i < nf {
        let factor: i64 = factors[i]
        while order % factor == 0 && modpow(residue, order / factor, modulo) == 1 {
            order = order / factor
        }
        i = i + 1
    }
    return order
}

function single_event_sum(limit: i64, q: i64, q_power: i64) -> i64 {
    let m: i64 = limit / q_power
    return q_power * (triangular(m) - q * triangular(m / q))
}

function pair_event_sum(limit: i64, q: i64, q_power: i64, r: i64, r_power: i64) -> i64 {
    let base: i64 = q_power * r_power
    let m: i64 = limit / base
    return base * (triangular(m) - q * triangular(m / q) - r * triangular(m / r) + q * r * triangular(m / (q * r)))
}

function search(limit: i64, modulo: i64) -> i64 {
    let sqrt_lim: i64 = isqrt(limit)
    let sieve: ptr<i8> = calloc(sqrt_lim + 1, 1)
    if sieve == null { return -1 }
    sieve[0] = 1
    sieve[1] = 1
    let mut p: i64 = 2
    while p * p <= sqrt_lim {
        if sieve[p] == 0 {
            let mut m: i64 = p * p
            while m <= sqrt_lim {
                sieve[m] = 1
                m = m + p
            }
        }
        p = p + 1
    }
    let mut small_cap: i64 = 200000
    let small_primes: ptr<i64> = calloc(small_cap, 8)
    let mut nsp: i64 = 0
    p = 2
    while p <= sqrt_lim {
        if sieve[p] == 0 {
            small_primes[nsp] = p
            nsp = nsp + 1
        }
        p = p + 1
    }
    free(sieve)

    let factors: ptr<i64> = calloc(32, 8)
    let nf: i64 = prime_factors_into(modulo - 1, factors)

    # linear events: primes q <= limit with q ≡ -1 (mod modulo)
    let max_k: i64 = (limit + 1) / modulo
    let ksieve: ptr<i8> = calloc(max_k + 1, 1)
    if ksieve == null { return -1 }
    ksieve[0] = 1
    let mut ii: i64 = 0
    while ii < nsp {
        let pp: i64 = small_primes[ii]
        if pp != modulo {
            let residue: i64 = modpow(modulo % pp, pp - 2, pp)
            let min_k: i64 = (pp * pp + 1 + modulo - 1) / modulo
            let mut res: i64 = residue
            if res < min_k {
                res = res + ((min_k - res + pp - 1) / pp) * pp
            }
            let mut kk: i64 = res
            while kk <= max_k {
                ksieve[kk] = 1
                kk = kk + pp
            }
        }
        ii = ii + 1
    }
    let mut lin_cap: i64 = max_k / 10 + 1000
    let linear: ptr<i64> = calloc(lin_cap, 8)
    let mut nlin: i64 = 0
    let mut k: i64 = 1
    while k <= max_k {
        if ksieve[k] == 0 {
            if nlin >= lin_cap {
                lin_cap = lin_cap * 2
                linear = realloc(linear, lin_cap * 8)
            }
            linear[nlin] = modulo * k - 1
            nlin = nlin + 1
        }
        k = k + 1
    }
    free(ksieve)

    # higher trigger powers
    let mut hi_cap: i64 = 100000
    let hq: ptr<i64> = calloc(hi_cap, 8)
    let hp: ptr<i64> = calloc(hi_cap, 8)
    let mut nhi: i64 = 0
    ii = 0
    while ii < nsp {
        let q: i64 = small_primes[ii]
        if q != modulo {
            let residue: i64 = q % modulo
            if residue != 1 {
                let order: i64 = multiplicative_order(q, modulo, factors, nf)
                let mut power: i64 = 1
                let mut exponent: i64 = 0
                while power <= limit / q {
                    power = power * q
                    exponent = exponent + 1
                    if (exponent + 1) % order == 0 {
                        if !(order == 2 && exponent == 1) {
                            if nhi >= hi_cap {
                                hi_cap = hi_cap * 2
                                hq = realloc(hq, hi_cap * 8)
                                hp = realloc(hp, hi_cap * 8)
                            }
                            hq[nhi] = q
                            hp[nhi] = power
                            nhi = nhi + 1
                        }
                    }
                }
            }
        }
        ii = ii + 1
    }
    # sort higher by power (insertion sort; nhi small)
    let mut a: i64 = 1
    while a < nhi {
        let mut b: i64 = a
        while b > 0 && hp[b - 1] > hp[b] {
            let tq: i64 = hq[b]
            let tp: i64 = hp[b]
            hq[b] = hq[b - 1]
            hp[b] = hp[b - 1]
            hq[b - 1] = tq
            hp[b - 1] = tp
            b = b - 1
        }
        a = a + 1
    }

    let mut total: i64 = 0
    ii = 0
    while ii < nlin {
        let q: i64 = linear[ii]
        total = total + single_event_sum(limit, q, q)
        ii = ii + 1
    }
    ii = 0
    while ii < nhi {
        total = total + single_event_sum(limit, hq[ii], hp[ii])
        ii = ii + 1
    }

    ii = 0
    while ii < nlin {
        let q: i64 = linear[ii]
        if q * q > limit { break }
        # bisect_right linear for limit/q
        let mut lo: i64 = ii + 1
        let mut hi: i64 = nlin
        let key: i64 = limit / q
        while lo < hi {
            let mid: i64 = (lo + hi) / 2
            if linear[mid] <= key { lo = mid + 1 } else { hi = mid }
        }
        let mut jj: i64 = ii + 1
        while jj < lo {
            total = total - pair_event_sum(limit, q, q, linear[jj], linear[jj])
            jj = jj + 1
        }
        ii = ii + 1
    }

    ii = 0
    while ii < nhi {
        let q: i64 = hq[ii]
        let q_power: i64 = hp[ii]
        let mut lo: i64 = 0
        let mut hi: i64 = nlin
        let key: i64 = limit / q_power
        while lo < hi {
            let mid: i64 = (lo + hi) / 2
            if linear[mid] <= key { lo = mid + 1 } else { hi = mid }
        }
        let mut jj: i64 = 0
        while jj < lo {
            let r: i64 = linear[jj]
            if r != q {
                total = total - pair_event_sum(limit, q, q_power, r, r)
            }
            jj = jj + 1
        }
        ii = ii + 1
    }

    ii = 0
    while ii < nhi {
        let q: i64 = hq[ii]
        let q_power: i64 = hp[ii]
        if q_power * q_power > limit { break }
        let mut jj: i64 = ii + 1
        while jj < nhi {
            let r: i64 = hq[jj]
            let r_power: i64 = hp[jj]
            if q_power * r_power > limit { break }
            if q != r {
                total = total - pair_event_sum(limit, q, q_power, r, r_power)
            }
            jj = jj + 1
        }
        ii = ii + 1
    }

    free(hp)
    free(hq)
    free(linear)
    free(factors)
    free(small_primes)
    return total
}

function main() -> i32 {
    printf("%lld\n", search(100000000000, 2017))
    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 gcd_i64_i64(int64_t a0, int64_t b0);
int64_t lcm_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64(int64_t n);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t n);
int64_t triangular_i64(int64_t n);
int64_t modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod);
int64_t prime_factors_into_i64_ptr_i64(int64_t n0, int64_t* out);
int64_t multiplicative_order_i64_i64_ptr_i64_i64(int64_t base, int64_t modulo, int64_t* factors, int64_t nf);
int64_t single_event_sum_i64_i64_i64(int64_t limit, int64_t q, int64_t q_power);
int64_t pair_event_sum_i64_i64_i64_i64_i64(int64_t limit, int64_t q, int64_t q_power, int64_t r, int64_t r_power);
int64_t search_i64_i64(int64_t limit, int64_t modulo);
int32_t main(void);

int64_t gcd_i64_i64(int64_t a0, int64_t b0) {
    int64_t a = a0;
    int64_t b = b0;
    while (b != 0) {
        int64_t t = FLOW_CHECKED_MOD((a), (b));
        a = b;
        b = t;
    }
    return a;
}

int64_t lcm_i64_i64(int64_t a, int64_t b) {
    if ((a == 0 || b == 0)) {
        return 0;
    }
    return (FLOW_CHECKED_DIV((a), (gcd_i64_i64(a, b))) * b);
}

int64_t isqrt_i64(int64_t n) {
    if (n < 2) {
        return n;
    }
    int64_t x = n;
    int64_t y = FLOW_CHECKED_DIV(((x + 1)), (2));
    while (y < x) {
        x = y;
        y = FLOW_CHECKED_DIV(((x + FLOW_CHECKED_DIV((n), (x)))), (2));
    }
    return x;
}

int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod) {
    int64_t a = FLOW_CHECKED_MOD((a0), (mod));
    int64_t b = FLOW_CHECKED_MOD((b0), (mod));
    int64_t result = 0;
    while (b > 0) {
        if (FLOW_CHECKED_MOD((b), (2)) == 1) {
            result = FLOW_CHECKED_MOD(((result + a)), (mod));
        }
        a = FLOW_CHECKED_MOD(((a * 2)), (mod));
        b = FLOW_CHECKED_DIV((b), (2));
    }
    return result;
}

int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
    if (mod == 1) {
        return 0;
    }
    int64_t result = 1;
    int64_t b = FLOW_CHECKED_MOD((base), (mod));
    int64_t e = exp;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            result = mulmod_i64_i64_i64(result, b, mod);
        }
        b = mulmod_i64_i64_i64(b, b, mod);
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return result;
}

bool is_prime_i64(int64_t n) {
    if (n < 2) {
        return 0;
    }
    if (n < 4) {
        return 1;
    }
    if ((FLOW_CHECKED_MOD((n), (2)) == 0 || FLOW_CHECKED_MOD((n), (3)) == 0)) {
        return 0;
    }
    int64_t i = 5;
    while ((i * i) <= n) {
        if ((FLOW_CHECKED_MOD((n), (i)) == 0 || FLOW_CHECKED_MOD((n), ((i + 2))) == 0)) {
            return 0;
        }
        i = (i + 6);
    }
    return 1;
}




int64_t triangular_i64(int64_t n) {
    return FLOW_CHECKED_DIV(((n * (n + 1))), (2));
}

int64_t modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod) {
    int64_t result = 1;
    int64_t base = FLOW_CHECKED_MOD((base0), (mod));
    int64_t exp = exp0;
    while (exp > 0) {
        if ((exp & 1) != 0) {
            result = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(result)) * ((__int128)(base)))), (((__int128)(mod))))));
        }
        base = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(base)) * ((__int128)(base)))), (((__int128)(mod))))));
        exp = FLOW_CHECKED_SHR((exp), (1));
    }
    return result;
}

int64_t prime_factors_into_i64_ptr_i64(int64_t n0, int64_t* out) {
    int64_t n = n0;
    int64_t c = 0;
    int64_t d = 2;
    while ((d * d) <= n) {
        if (FLOW_CHECKED_MOD((n), (d)) == 0) {
            out[c] = d;
            c = (c + 1);
            while (FLOW_CHECKED_MOD((n), (d)) == 0) {
                n = FLOW_CHECKED_DIV((n), (d));
            }
        }
        if (d == 2) {
            d = 3;
        } else {
            d = (d + 2);
        }
    }
    if (n > 1) {
        out[c] = n;
        c = (c + 1);
    }
    return c;
}

int64_t multiplicative_order_i64_i64_ptr_i64_i64(int64_t base, int64_t modulo, int64_t* factors, int64_t nf) {
    int64_t order = (modulo - 1);
    int64_t residue = FLOW_CHECKED_MOD((base), (modulo));
    int64_t i = 0;
    while (i < nf) {
        int64_t factor = factors[i];
        while ((FLOW_CHECKED_MOD((order), (factor)) == 0 && modpow_i64_i64_i64(residue, FLOW_CHECKED_DIV((order), (factor)), modulo) == 1)) {
            order = FLOW_CHECKED_DIV((order), (factor));
        }
        i = (i + 1);
    }
    return order;
}

int64_t single_event_sum_i64_i64_i64(int64_t limit, int64_t q, int64_t q_power) {
    int64_t m = FLOW_CHECKED_DIV((limit), (q_power));
    return (q_power * (triangular_i64(m) - (q * triangular_i64(FLOW_CHECKED_DIV((m), (q))))));
}

int64_t pair_event_sum_i64_i64_i64_i64_i64(int64_t limit, int64_t q, int64_t q_power, int64_t r, int64_t r_power) {
    int64_t base = (q_power * r_power);
    int64_t m = FLOW_CHECKED_DIV((limit), (base));
    return (base * (((triangular_i64(m) - (q * triangular_i64(FLOW_CHECKED_DIV((m), (q))))) - (r * triangular_i64(FLOW_CHECKED_DIV((m), (r))))) + ((q * r) * triangular_i64(FLOW_CHECKED_DIV((m), ((q * r)))))));
}

int64_t search_i64_i64(int64_t limit, int64_t modulo) {
    int64_t sqrt_lim = isqrt_i64(limit);
    int8_t* sieve = (int8_t*)(calloc((sqrt_lim + 1), 1));
    if (sieve == NULL) {
        return (-1);
    }
    sieve[0] = 1;
    sieve[1] = 1;
    int64_t p = 2;
    while ((p * p) <= sqrt_lim) {
        if (sieve[p] == 0) {
            int64_t m = (p * p);
            while (m <= sqrt_lim) {
                sieve[m] = 1;
                m = (m + p);
            }
        }
        p = (p + 1);
    }
    int64_t small_cap = 200000;
    int64_t* small_primes = (int64_t*)(calloc(small_cap, 8));
    int64_t nsp = 0;
    p = 2;
    while (p <= sqrt_lim) {
        if (sieve[p] == 0) {
            small_primes[nsp] = p;
            nsp = (nsp + 1);
        }
        p = (p + 1);
    }
    free(sieve);
    int64_t* factors = (int64_t*)(calloc(32, 8));
    int64_t nf = prime_factors_into_i64_ptr_i64((modulo - 1), factors);
    int64_t max_k = FLOW_CHECKED_DIV(((limit + 1)), (modulo));
    int8_t* ksieve = (int8_t*)(calloc((max_k + 1), 1));
    if (ksieve == NULL) {
        return (-1);
    }
    ksieve[0] = 1;
    int64_t ii = 0;
    while (ii < nsp) {
        int64_t pp = small_primes[ii];
        if (pp != modulo) {
            int64_t residue = modpow_i64_i64_i64(FLOW_CHECKED_MOD((modulo), (pp)), (pp - 2), pp);
            int64_t min_k = FLOW_CHECKED_DIV((((((pp * pp) + 1) + modulo) - 1)), (modulo));
            int64_t res = residue;
            if (res < min_k) {
                res = (res + (FLOW_CHECKED_DIV(((((min_k - res) + pp) - 1)), (pp)) * pp));
            }
            int64_t kk = res;
            while (kk <= max_k) {
                ksieve[kk] = 1;
                kk = (kk + pp);
            }
        }
        ii = (ii + 1);
    }
    int64_t lin_cap = (FLOW_CHECKED_DIV((max_k), (10)) + 1000);
    int64_t* linear = (int64_t*)(calloc(lin_cap, 8));
    int64_t nlin = 0;
    int64_t k = 1;
    while (k <= max_k) {
        if (ksieve[k] == 0) {
            if (nlin >= lin_cap) {
                lin_cap = (lin_cap * 2);
                linear = realloc(linear, (lin_cap * 8));
            }
            linear[nlin] = ((modulo * k) - 1);
            nlin = (nlin + 1);
        }
        k = (k + 1);
    }
    free(ksieve);
    int64_t hi_cap = 100000;
    int64_t* hq = (int64_t*)(calloc(hi_cap, 8));
    int64_t* hp = (int64_t*)(calloc(hi_cap, 8));
    int64_t nhi = 0;
    ii = 0;
    while (ii < nsp) {
        int64_t q = small_primes[ii];
        if (q != modulo) {
            int64_t residue = FLOW_CHECKED_MOD((q), (modulo));
            if (residue != 1) {
                int64_t order = multiplicative_order_i64_i64_ptr_i64_i64(q, modulo, factors, nf);
                int64_t power = 1;
                int64_t exponent = 0;
                while (power <= FLOW_CHECKED_DIV((limit), (q))) {
                    power = (power * q);
                    exponent = (exponent + 1);
                    if (FLOW_CHECKED_MOD(((exponent + 1)), (order)) == 0) {
                        if ((!((order == 2 && exponent == 1)))) {
                            if (nhi >= hi_cap) {
                                hi_cap = (hi_cap * 2);
                                hq = realloc(hq, (hi_cap * 8));
                                hp = realloc(hp, (hi_cap * 8));
                            }
                            hq[nhi] = q;
                            hp[nhi] = power;
                            nhi = (nhi + 1);
                        }
                    }
                }
            }
        }
        ii = (ii + 1);
    }
    int64_t a = 1;
    while (a < nhi) {
        int64_t b = a;
        while ((b > 0 && hp[(b - 1)] > hp[b])) {
            int64_t tq = hq[b];
            int64_t tp = hp[b];
            hq[b] = hq[(b - 1)];
            hp[b] = hp[(b - 1)];
            hq[(b - 1)] = tq;
            hp[(b - 1)] = tp;
            b = (b - 1);
        }
        a = (a + 1);
    }
    int64_t total = 0;
    ii = 0;
    while (ii < nlin) {
        int64_t q = linear[ii];
        total = (total + single_event_sum_i64_i64_i64(limit, q, q));
        ii = (ii + 1);
    }
    ii = 0;
    while (ii < nhi) {
        total = (total + single_event_sum_i64_i64_i64(limit, hq[ii], hp[ii]));
        ii = (ii + 1);
    }
    ii = 0;
    while (ii < nlin) {
        int64_t q = linear[ii];
        if ((q * q) > limit) {
            break;
        }
        int64_t lo = (ii + 1);
        int64_t hi = nlin;
        int64_t key = FLOW_CHECKED_DIV((limit), (q));
        while (lo < hi) {
            int64_t mid = FLOW_CHECKED_DIV(((lo + hi)), (2));
            if (linear[mid] <= key) {
                lo = (mid + 1);
            } else {
                hi = mid;
            }
        }
        int64_t jj = (ii + 1);
        while (jj < lo) {
            total = (total - pair_event_sum_i64_i64_i64_i64_i64(limit, q, q, linear[jj], linear[jj]));
            jj = (jj + 1);
        }
        ii = (ii + 1);
    }
    ii = 0;
    while (ii < nhi) {
        int64_t q = hq[ii];
        int64_t q_power = hp[ii];
        int64_t lo = 0;
        int64_t hi = nlin;
        int64_t key = FLOW_CHECKED_DIV((limit), (q_power));
        while (lo < hi) {
            int64_t mid = FLOW_CHECKED_DIV(((lo + hi)), (2));
            if (linear[mid] <= key) {
                lo = (mid + 1);
            } else {
                hi = mid;
            }
        }
        int64_t jj = 0;
        while (jj < lo) {
            int64_t r = linear[jj];
            if (r != q) {
                total = (total - pair_event_sum_i64_i64_i64_i64_i64(limit, q, q_power, r, r));
            }
            jj = (jj + 1);
        }
        ii = (ii + 1);
    }
    ii = 0;
    while (ii < nhi) {
        int64_t q = hq[ii];
        int64_t q_power = hp[ii];
        if ((q_power * q_power) > limit) {
            break;
        }
        int64_t jj = (ii + 1);
        while (jj < nhi) {
            int64_t r = hq[jj];
            int64_t r_power = hp[jj];
            if ((q_power * r_power) > limit) {
                break;
            }
            if (q != r) {
                total = (total - pair_event_sum_i64_i64_i64_i64_i64(limit, q, q_power, r, r_power));
            }
            jj = (jj + 1);
        }
        ii = (ii + 1);
    }
    free(hp);
    free(hq);
    free(linear);
    free(factors);
    free(small_primes);
    return total;
}

int32_t main(void) {
    printf("%lld\n", search_i64_i64(100000000000, 2017));
    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 @gcd(%arg0: i64, %arg1: i64) -> i64 {
    %0 = llvm.mlir.constant(1 : i64) : i64
    %1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %1 : i64, !llvm.ptr
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %3 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %4 = llvm.load %3 : !llvm.ptr -> i64
    %5 = arith.constant 0 : i32
    %7 = arith.extsi %5 : i32 to i64
    %6 = arith.cmpi ne, %4, %7 : i64
    cf.cond_br %6, ^bb1, ^bb2
    ^bb1:
      %8 = llvm.load %1 : !llvm.ptr -> i64
      %9 = llvm.load %3 : !llvm.ptr -> i64
      %10 = arith.remsi %8, %9 : i64
      %11 = llvm.load %3 : !llvm.ptr -> i64
      llvm.store %11, %1 : i64, !llvm.ptr
      llvm.store %10, %3 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %12 = llvm.load %1 : !llvm.ptr -> i64
    func.return %12 : i64
  }
  func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
    %13 = arith.constant 0 : i32
    %15 = arith.extsi %13 : i32 to i64
    %14 = arith.cmpi eq, %arg0, %15 : i64
    %16 = scf.if %14 -> (i1) {
      %17 = arith.constant true
      scf.yield %17 : i1
    } else {
      %18 = arith.constant 0 : i32
      %20 = arith.extsi %18 : i32 to i64
      %19 = arith.cmpi eq, %arg1, %20 : i64
      scf.yield %19 : i1
    }
    cf.cond_br %16, ^bb3, ^bb4
    ^bb3:
      %21 = arith.constant 0 : i32
      %22 = arith.extsi %21 : i32 to i64
      func.return %22 : i64
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
    %24 = arith.divsi %arg0, %23 : i64
    %25 = arith.muli %24, %arg1 : i64
    func.return %25 : i64
  }
  func.func @isqrt(%arg0: i64) -> i64 {
    %26 = arith.constant 2 : i32
    %28 = arith.extsi %26 : i32 to i64
    %27 = arith.cmpi slt, %arg0, %28 : i64
    cf.cond_br %27, ^bb6, ^bb7
    ^bb6:
      func.return %arg0 : i64
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %29 = llvm.mlir.constant(1 : i64) : i64
    %30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %30 : i64, !llvm.ptr
    %31 = llvm.load %30 : !llvm.ptr -> i64
    %32 = arith.constant 1 : i32
    %34 = arith.extsi %32 : i32 to i64
    %33 = arith.addi %31, %34 : i64
    %35 = arith.constant 2 : i32
    %37 = arith.extsi %35 : i32 to i64
    %36 = arith.divsi %33, %37 : i64
    %38 = llvm.mlir.constant(1 : i64) : i64
    %39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
    llvm.store %36, %39 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %40 = llvm.load %39 : !llvm.ptr -> i64
    %41 = llvm.load %30 : !llvm.ptr -> i64
    %42 = arith.cmpi slt, %40, %41 : i64
    cf.cond_br %42, ^bb10, ^bb11
    ^bb10:
      %43 = llvm.load %39 : !llvm.ptr -> i64
      llvm.store %43, %30 : i64, !llvm.ptr
      %44 = llvm.load %30 : !llvm.ptr -> i64
      %45 = llvm.load %30 : !llvm.ptr -> i64
      %46 = arith.divsi %arg0, %45 : i64
      %47 = arith.addi %44, %46 : i64
      %48 = arith.constant 2 : i32
      %50 = arith.extsi %48 : i32 to i64
      %49 = arith.divsi %47, %50 : i64
      llvm.store %49, %39 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %51 = llvm.load %30 : !llvm.ptr -> i64
    func.return %51 : i64
  }
  func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %52 = arith.remsi %arg0, %arg2 : i64
    %53 = llvm.mlir.constant(1 : i64) : i64
    %54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
    llvm.store %52, %54 : i64, !llvm.ptr
    %55 = arith.remsi %arg1, %arg2 : i64
    %56 = llvm.mlir.constant(1 : i64) : i64
    %57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
    llvm.store %55, %57 : i64, !llvm.ptr
    %58 = arith.constant 0 : i32
    %59 = arith.extsi %58 : i32 to i64
    %60 = llvm.mlir.constant(1 : i64) : i64
    %61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
    llvm.store %59, %61 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %62 = llvm.load %57 : !llvm.ptr -> i64
    %63 = arith.constant 0 : i32
    %65 = arith.extsi %63 : i32 to i64
    %64 = arith.cmpi sgt, %62, %65 : i64
    cf.cond_br %64, ^bb13, ^bb14
    ^bb13:
      %66 = llvm.load %57 : !llvm.ptr -> i64
      %67 = arith.constant 2 : i32
      %69 = arith.extsi %67 : i32 to i64
      %68 = arith.remsi %66, %69 : i64
      %70 = arith.constant 1 : i32
      %72 = arith.extsi %70 : i32 to i64
      %71 = arith.cmpi eq, %68, %72 : i64
      cf.cond_br %71, ^bb15, ^bb16
      ^bb15:
        %73 = llvm.load %61 : !llvm.ptr -> i64
        %74 = llvm.load %54 : !llvm.ptr -> i64
        %75 = arith.addi %73, %74 : i64
        %76 = arith.remsi %75, %arg2 : i64
        llvm.store %76, %61 : i64, !llvm.ptr
        cf.br ^bb17
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %77 = llvm.load %54 : !llvm.ptr -> i64
      %78 = arith.constant 2 : i32
      %80 = arith.extsi %78 : i32 to i64
      %79 = arith.muli %77, %80 : i64
      %81 = arith.remsi %79, %arg2 : i64
      llvm.store %81, %54 : i64, !llvm.ptr
      %82 = llvm.load %57 : !llvm.ptr -> i64
      %83 = arith.constant 2 : i32
      %85 = arith.extsi %83 : i32 to i64
      %84 = arith.divsi %82, %85 : i64
      llvm.store %84, %57 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %86 = llvm.load %61 : !llvm.ptr -> i64
    func.return %86 : i64
  }
  func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %87 = arith.constant 1 : i32
    %89 = arith.extsi %87 : i32 to i64
    %88 = arith.cmpi eq, %arg2, %89 : i64
    cf.cond_br %88, ^bb18, ^bb19
    ^bb18:
      %90 = arith.constant 0 : i32
      %91 = arith.extsi %90 : i32 to i64
      func.return %91 : i64
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %92 = arith.constant 1 : i32
    %93 = arith.extsi %92 : i32 to i64
    %94 = llvm.mlir.constant(1 : i64) : i64
    %95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
    llvm.store %93, %95 : i64, !llvm.ptr
    %96 = arith.remsi %arg0, %arg2 : i64
    %97 = llvm.mlir.constant(1 : i64) : i64
    %98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
    llvm.store %96, %98 : i64, !llvm.ptr
    %99 = llvm.mlir.constant(1 : i64) : i64
    %100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %100 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %101 = llvm.load %100 : !llvm.ptr -> i64
    %102 = arith.constant 0 : i32
    %104 = arith.extsi %102 : i32 to i64
    %103 = arith.cmpi sgt, %101, %104 : i64
    cf.cond_br %103, ^bb22, ^bb23
    ^bb22:
      %105 = llvm.load %100 : !llvm.ptr -> i64
      %106 = arith.constant 2 : i32
      %108 = arith.extsi %106 : i32 to i64
      %107 = arith.remsi %105, %108 : i64
      %109 = arith.constant 1 : i32
      %111 = arith.extsi %109 : i32 to i64
      %110 = arith.cmpi eq, %107, %111 : i64
      cf.cond_br %110, ^bb24, ^bb25
      ^bb24:
        %113 = llvm.load %95 : !llvm.ptr -> i64
        %114 = llvm.load %98 : !llvm.ptr -> i64
        %112 = func.call @mulmod(%113, %114, %arg2) : (i64, i64, i64) -> i64
        llvm.store %112, %95 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %116 = llvm.load %98 : !llvm.ptr -> i64
      %117 = llvm.load %98 : !llvm.ptr -> i64
      %115 = func.call @mulmod(%116, %117, %arg2) : (i64, i64, i64) -> i64
      llvm.store %115, %98 : i64, !llvm.ptr
      %118 = llvm.load %100 : !llvm.ptr -> i64
      %119 = arith.constant 2 : i32
      %121 = arith.extsi %119 : i32 to i64
      %120 = arith.divsi %118, %121 : i64
      llvm.store %120, %100 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %122 = llvm.load %95 : !llvm.ptr -> i64
    func.return %122 : i64
  }
  func.func @is_prime(%arg0: i64) -> i1 {
    %123 = arith.constant 2 : i32
    %125 = arith.extsi %123 : i32 to i64
    %124 = arith.cmpi slt, %arg0, %125 : i64
    cf.cond_br %124, ^bb27, ^bb28
    ^bb27:
      %126 = arith.constant 0 : i1
      func.return %126 : i1
    ^bb28:
      cf.br ^bb29
    ^bb29:
    %127 = arith.constant 4 : i32
    %129 = arith.extsi %127 : i32 to i64
    %128 = arith.cmpi slt, %arg0, %129 : i64
    cf.cond_br %128, ^bb30, ^bb31
    ^bb30:
      %130 = arith.constant 1 : i1
      func.return %130 : i1
    ^bb31:
      cf.br ^bb32
    ^bb32:
    %131 = arith.constant 2 : i32
    %133 = arith.extsi %131 : i32 to i64
    %132 = arith.remsi %arg0, %133 : i64
    %134 = arith.constant 0 : i32
    %136 = arith.extsi %134 : i32 to i64
    %135 = arith.cmpi eq, %132, %136 : i64
    %137 = scf.if %135 -> (i1) {
      %138 = arith.constant true
      scf.yield %138 : i1
    } else {
      %139 = arith.constant 3 : i32
      %141 = arith.extsi %139 : i32 to i64
      %140 = arith.remsi %arg0, %141 : i64
      %142 = arith.constant 0 : i32
      %144 = arith.extsi %142 : i32 to i64
      %143 = arith.cmpi eq, %140, %144 : i64
      scf.yield %143 : i1
    }
    cf.cond_br %137, ^bb33, ^bb34
    ^bb33:
      %145 = arith.constant 0 : i1
      func.return %145 : i1
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %146 = arith.constant 5 : i32
    %147 = arith.extsi %146 : i32 to i64
    %148 = llvm.mlir.constant(1 : i64) : i64
    %149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
    llvm.store %147, %149 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %150 = llvm.load %149 : !llvm.ptr -> i64
    %151 = llvm.load %149 : !llvm.ptr -> i64
    %152 = arith.muli %150, %151 : i64
    %153 = arith.cmpi sle, %152, %arg0 : i64
    cf.cond_br %153, ^bb37, ^bb38
    ^bb37:
      %154 = llvm.load %149 : !llvm.ptr -> i64
      %155 = arith.remsi %arg0, %154 : i64
      %156 = arith.constant 0 : i32
      %158 = arith.extsi %156 : i32 to i64
      %157 = arith.cmpi eq, %155, %158 : i64
      %159 = scf.if %157 -> (i1) {
        %160 = arith.constant true
        scf.yield %160 : i1
      } else {
        %161 = llvm.load %149 : !llvm.ptr -> i64
        %162 = arith.constant 2 : i32
        %164 = arith.extsi %162 : i32 to i64
        %163 = arith.addi %161, %164 : i64
        %165 = arith.remsi %arg0, %163 : i64
        %166 = arith.constant 0 : i32
        %168 = arith.extsi %166 : i32 to i64
        %167 = arith.cmpi eq, %165, %168 : i64
        scf.yield %167 : i1
      }
      cf.cond_br %159, ^bb39, ^bb40
      ^bb39:
        %169 = arith.constant 0 : i1
        func.return %169 : i1
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %170 = llvm.load %149 : !llvm.ptr -> i64
      %171 = arith.constant 6 : i32
      %173 = arith.extsi %171 : i32 to i64
      %172 = arith.addi %170, %173 : i64
      llvm.store %172, %149 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %174 = arith.constant 1 : i1
    func.return %174 : i1
  }
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func private @realloc(!llvm.ptr, i64) -> !llvm.ptr
  func.func @triangular(%arg0: i64) -> i64 {
    %175 = arith.constant 1 : i32
    %177 = arith.extsi %175 : i32 to i64
    %176 = arith.addi %arg0, %177 : i64
    %178 = arith.muli %arg0, %176 : i64
    %179 = arith.constant 2 : i32
    %181 = arith.extsi %179 : i32 to i64
    %180 = arith.divsi %178, %181 : i64
    func.return %180 : i64
  }
  func.func @modpow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %182 = arith.constant 1 : i32
    %183 = arith.extsi %182 : i32 to i64
    %184 = llvm.mlir.constant(1 : i64) : i64
    %185 = llvm.alloca %184 x i64 : (i64) -> !llvm.ptr
    llvm.store %183, %185 : i64, !llvm.ptr
    %186 = arith.remsi %arg0, %arg2 : 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 = llvm.mlir.constant(1 : i64) : i64
    %190 = llvm.alloca %189 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %190 : i64, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %191 = llvm.load %190 : !llvm.ptr -> i64
    %192 = arith.constant 0 : i32
    %194 = arith.extsi %192 : i32 to i64
    %193 = arith.cmpi sgt, %191, %194 : i64
    cf.cond_br %193, ^bb43, ^bb44
    ^bb43:
      %195 = llvm.load %190 : !llvm.ptr -> i64
      %196 = arith.constant 1 : i32
      %198 = arith.extsi %196 : i32 to i64
      %197 = arith.andi %195, %198 : i64
      %199 = arith.constant 0 : i32
      %201 = arith.extsi %199 : i32 to i64
      %200 = arith.cmpi ne, %197, %201 : i64
      cf.cond_br %200, ^bb45, ^bb46
      ^bb45:
        %202 = llvm.load %185 : !llvm.ptr -> i64
        %203 = arith.extsi %202 : i64 to i128
        %204 = llvm.load %188 : !llvm.ptr -> i64
        %205 = arith.extsi %204 : i64 to i128
        %207 = arith.trunci %203 : i128 to i64
        %208 = arith.trunci %205 : i128 to i64
        %206 = arith.muli %207, %208 : i64
        %209 = arith.extsi %arg2 : i64 to i128
        %211 = arith.trunci %209 : i128 to i64
        %210 = arith.remsi %206, %211 : i64
        llvm.store %210, %185 : i64, !llvm.ptr
        cf.br ^bb47
      ^bb46:
        cf.br ^bb47
      ^bb47:
      %212 = llvm.load %188 : !llvm.ptr -> i64
      %213 = arith.extsi %212 : i64 to i128
      %214 = llvm.load %188 : !llvm.ptr -> i64
      %215 = arith.extsi %214 : i64 to i128
      %217 = arith.trunci %213 : i128 to i64
      %218 = arith.trunci %215 : i128 to i64
      %216 = arith.muli %217, %218 : i64
      %219 = arith.extsi %arg2 : i64 to i128
      %221 = arith.trunci %219 : i128 to i64
      %220 = arith.remsi %216, %221 : i64
      llvm.store %220, %188 : i64, !llvm.ptr
      %222 = llvm.load %190 : !llvm.ptr -> i64
      %223 = arith.constant 1 : i32
      %225 = arith.extsi %223 : i32 to i64
      %224 = arith.shrsi %222, %225 : i64
      llvm.store %224, %190 : i64, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    %226 = llvm.load %185 : !llvm.ptr -> i64
    func.return %226 : i64
  }
  func.func @prime_factors_into(%arg0: i64, %arg1: !llvm.ptr) -> i64 {
    %227 = llvm.mlir.constant(1 : i64) : i64
    %228 = llvm.alloca %227 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %228 : i64, !llvm.ptr
    %229 = arith.constant 0 : i32
    %230 = arith.extsi %229 : i32 to i64
    %231 = llvm.mlir.constant(1 : i64) : i64
    %232 = llvm.alloca %231 x i64 : (i64) -> !llvm.ptr
    llvm.store %230, %232 : i64, !llvm.ptr
    %233 = arith.constant 2 : i32
    %234 = arith.extsi %233 : i32 to i64
    %235 = llvm.mlir.constant(1 : i64) : i64
    %236 = llvm.alloca %235 x i64 : (i64) -> !llvm.ptr
    llvm.store %234, %236 : i64, !llvm.ptr
    cf.br ^bb48
    ^bb48:
    %237 = llvm.load %236 : !llvm.ptr -> i64
    %238 = llvm.load %236 : !llvm.ptr -> i64
    %239 = arith.muli %237, %238 : i64
    %240 = llvm.load %228 : !llvm.ptr -> i64
    %241 = arith.cmpi sle, %239, %240 : i64
    cf.cond_br %241, ^bb49, ^bb50
    ^bb49:
      %242 = llvm.load %228 : !llvm.ptr -> i64
      %243 = llvm.load %236 : !llvm.ptr -> i64
      %244 = arith.remsi %242, %243 : i64
      %245 = arith.constant 0 : i32
      %247 = arith.extsi %245 : i32 to i64
      %246 = arith.cmpi eq, %244, %247 : i64
      cf.cond_br %246, ^bb51, ^bb52
      ^bb51:
        %248 = llvm.load %236 : !llvm.ptr -> i64
        %249 = llvm.load %232 : !llvm.ptr -> i64
        %250 = llvm.getelementptr %arg1[%249] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %248, %250 : i64, !llvm.ptr
        %251 = llvm.load %232 : !llvm.ptr -> i64
        %252 = arith.constant 1 : i32
        %254 = arith.extsi %252 : i32 to i64
        %253 = arith.addi %251, %254 : i64
        llvm.store %253, %232 : i64, !llvm.ptr
        cf.br ^bb54
        ^bb54:
        %255 = llvm.load %228 : !llvm.ptr -> i64
        %256 = llvm.load %236 : !llvm.ptr -> i64
        %257 = arith.remsi %255, %256 : i64
        %258 = arith.constant 0 : i32
        %260 = arith.extsi %258 : i32 to i64
        %259 = arith.cmpi eq, %257, %260 : i64
        cf.cond_br %259, ^bb55, ^bb56
        ^bb55:
          %261 = llvm.load %228 : !llvm.ptr -> i64
          %262 = llvm.load %236 : !llvm.ptr -> i64
          %263 = arith.divsi %261, %262 : i64
          llvm.store %263, %228 : i64, !llvm.ptr
          cf.br ^bb54
        ^bb56:
        cf.br ^bb53
      ^bb52:
        cf.br ^bb53
      ^bb53:
      %264 = llvm.load %236 : !llvm.ptr -> i64
      %265 = arith.constant 2 : i32
      %267 = arith.extsi %265 : i32 to i64
      %266 = arith.cmpi eq, %264, %267 : i64
      cf.cond_br %266, ^bb57, ^bb58
      ^bb57:
        %268 = arith.constant 3 : i32
        %269 = arith.extsi %268 : i32 to i64
        llvm.store %269, %236 : i64, !llvm.ptr
        cf.br ^bb59
      ^bb58:
        %270 = llvm.load %236 : !llvm.ptr -> i64
        %271 = arith.constant 2 : i32
        %273 = arith.extsi %271 : i32 to i64
        %272 = arith.addi %270, %273 : i64
        llvm.store %272, %236 : i64, !llvm.ptr
        cf.br ^bb59
      ^bb59:
      cf.br ^bb48
    ^bb50:
    %274 = llvm.load %228 : !llvm.ptr -> i64
    %275 = arith.constant 1 : i32
    %277 = arith.extsi %275 : i32 to i64
    %276 = arith.cmpi sgt, %274, %277 : i64
    cf.cond_br %276, ^bb60, ^bb61
    ^bb60:
      %278 = llvm.load %228 : !llvm.ptr -> i64
      %279 = llvm.load %232 : !llvm.ptr -> i64
      %280 = llvm.getelementptr %arg1[%279] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %278, %280 : i64, !llvm.ptr
      %281 = llvm.load %232 : !llvm.ptr -> i64
      %282 = arith.constant 1 : i32
      %284 = arith.extsi %282 : i32 to i64
      %283 = arith.addi %281, %284 : i64
      llvm.store %283, %232 : i64, !llvm.ptr
      cf.br ^bb62
    ^bb61:
      cf.br ^bb62
    ^bb62:
    %285 = llvm.load %232 : !llvm.ptr -> i64
    func.return %285 : i64
  }
  func.func @multiplicative_order(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr, %arg3: i64) -> i64 {
    %286 = arith.constant 1 : i32
    %288 = arith.extsi %286 : i32 to i64
    %287 = arith.subi %arg1, %288 : i64
    %289 = llvm.mlir.constant(1 : i64) : i64
    %290 = llvm.alloca %289 x i64 : (i64) -> !llvm.ptr
    llvm.store %287, %290 : i64, !llvm.ptr
    %291 = arith.remsi %arg0, %arg1 : i64
    %292 = arith.constant 0 : i32
    %293 = arith.extsi %292 : i32 to i64
    %294 = llvm.mlir.constant(1 : i64) : i64
    %295 = llvm.alloca %294 x i64 : (i64) -> !llvm.ptr
    llvm.store %293, %295 : i64, !llvm.ptr
    cf.br ^bb63
    ^bb63:
    %296 = llvm.load %295 : !llvm.ptr -> i64
    %297 = arith.cmpi slt, %296, %arg3 : i64
    cf.cond_br %297, ^bb64, ^bb65
    ^bb64:
      %299 = llvm.load %295 : !llvm.ptr -> i64
      %300 = llvm.getelementptr %arg2[%299] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %298 = llvm.load %300 : !llvm.ptr -> i64
      cf.br ^bb66
      ^bb66:
      %301 = llvm.load %290 : !llvm.ptr -> i64
      %302 = arith.remsi %301, %298 : i64
      %303 = arith.constant 0 : i32
      %305 = arith.extsi %303 : i32 to i64
      %304 = arith.cmpi eq, %302, %305 : i64
      %306 = scf.if %304 -> (i1) {
        %308 = llvm.load %290 : !llvm.ptr -> i64
        %309 = arith.divsi %308, %298 : i64
        %307 = func.call @modpow(%291, %309, %arg1) : (i64, i64, i64) -> i64
        %310 = arith.constant 1 : i32
        %312 = arith.extsi %310 : i32 to i64
        %311 = arith.cmpi eq, %307, %312 : i64
        scf.yield %311 : i1
      } else {
        %313 = arith.constant false
        scf.yield %313 : i1
      }
      cf.cond_br %306, ^bb67, ^bb68
      ^bb67:
        %314 = llvm.load %290 : !llvm.ptr -> i64
        %315 = arith.divsi %314, %298 : i64
        llvm.store %315, %290 : i64, !llvm.ptr
        cf.br ^bb66
      ^bb68:
      %316 = llvm.load %295 : !llvm.ptr -> i64
      %317 = arith.constant 1 : i32
      %319 = arith.extsi %317 : i32 to i64
      %318 = arith.addi %316, %319 : i64
      llvm.store %318, %295 : i64, !llvm.ptr
      cf.br ^bb63
    ^bb65:
    %320 = llvm.load %290 : !llvm.ptr -> i64
    func.return %320 : i64
  }
  func.func @single_event_sum(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %321 = arith.divsi %arg0, %arg2 : i64
    %322 = func.call @triangular(%321) : (i64) -> i64
    %324 = arith.divsi %321, %arg1 : i64
    %323 = func.call @triangular(%324) : (i64) -> i64
    %325 = arith.muli %arg1, %323 : i64
    %326 = arith.subi %322, %325 : i64
    %327 = arith.muli %arg2, %326 : i64
    func.return %327 : i64
  }
  func.func @pair_event_sum(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: i64) -> i64 {
    %328 = arith.muli %arg2, %arg4 : i64
    %329 = arith.divsi %arg0, %328 : i64
    %330 = func.call @triangular(%329) : (i64) -> i64
    %332 = arith.divsi %329, %arg1 : i64
    %331 = func.call @triangular(%332) : (i64) -> i64
    %333 = arith.muli %arg1, %331 : i64
    %334 = arith.subi %330, %333 : i64
    %336 = arith.divsi %329, %arg3 : i64
    %335 = func.call @triangular(%336) : (i64) -> i64
    %337 = arith.muli %arg3, %335 : i64
    %338 = arith.subi %334, %337 : i64
    %339 = arith.muli %arg1, %arg3 : i64
    %341 = arith.muli %arg1, %arg3 : i64
    %342 = arith.divsi %329, %341 : i64
    %340 = func.call @triangular(%342) : (i64) -> i64
    %343 = arith.muli %339, %340 : i64
    %344 = arith.addi %338, %343 : i64
    %345 = arith.muli %328, %344 : i64
    func.return %345 : i64
  }
  func.func @search(%arg0: i64, %arg1: i64) -> i64 {
    %346 = func.call @isqrt(%arg0) : (i64) -> i64
    %348 = arith.constant 1 : i32
    %350 = arith.extsi %348 : i32 to i64
    %349 = arith.addi %346, %350 : i64
    %351 = arith.constant 1 : i32
    %352 = arith.extsi %351 : i32 to i64
    %347 = func.call @calloc(%349, %352) : (i64, i64) -> !llvm.ptr
    %353 = llvm.mlir.zero : !llvm.ptr
    %354 = llvm.icmp "eq" %347, %353 : !llvm.ptr
    cf.cond_br %354, ^bb69, ^bb70
    ^bb69:
      %355 = arith.constant 1 : i32
      %357 = arith.constant 0 : i32
      %356 = arith.subi %357, %355 : i32
      %358 = arith.extsi %356 : i32 to i64
      func.return %358 : i64
    ^bb70:
      cf.br ^bb71
    ^bb71:
    %359 = arith.constant 1 : i32
    %360 = arith.constant 0 : i32
    %361 = arith.trunci %359 : i32 to i8
    %362 = arith.extsi %360 : i32 to i64
    %363 = llvm.getelementptr %347[%362] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %361, %363 : i8, !llvm.ptr
    %364 = arith.constant 1 : i32
    %365 = arith.constant 1 : i32
    %366 = arith.trunci %364 : i32 to i8
    %367 = arith.extsi %365 : i32 to i64
    %368 = llvm.getelementptr %347[%367] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %366, %368 : i8, !llvm.ptr
    %369 = arith.constant 2 : i32
    %370 = arith.extsi %369 : i32 to i64
    %371 = llvm.mlir.constant(1 : i64) : i64
    %372 = llvm.alloca %371 x i64 : (i64) -> !llvm.ptr
    llvm.store %370, %372 : i64, !llvm.ptr
    cf.br ^bb72
    ^bb72:
    %373 = llvm.load %372 : !llvm.ptr -> i64
    %374 = llvm.load %372 : !llvm.ptr -> i64
    %375 = arith.muli %373, %374 : i64
    %376 = arith.cmpi sle, %375, %346 : i64
    cf.cond_br %376, ^bb73, ^bb74
    ^bb73:
      %378 = llvm.load %372 : !llvm.ptr -> i64
      %379 = llvm.getelementptr %347[%378] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %377 = llvm.load %379 : !llvm.ptr -> i8
      %380 = arith.constant 0 : i32
      %382 = arith.extsi %377 : i8 to i32
      %381 = arith.cmpi eq, %382, %380 : i32
      cf.cond_br %381, ^bb75, ^bb76
      ^bb75:
        %383 = llvm.load %372 : !llvm.ptr -> i64
        %384 = llvm.load %372 : !llvm.ptr -> i64
        %385 = arith.muli %383, %384 : i64
        %386 = llvm.mlir.constant(1 : i64) : i64
        %387 = llvm.alloca %386 x i64 : (i64) -> !llvm.ptr
        llvm.store %385, %387 : i64, !llvm.ptr
        cf.br ^bb78
        ^bb78:
        %388 = llvm.load %387 : !llvm.ptr -> i64
        %389 = arith.cmpi sle, %388, %346 : i64
        cf.cond_br %389, ^bb79, ^bb80
        ^bb79:
          %390 = arith.constant 1 : i32
          %391 = llvm.load %387 : !llvm.ptr -> i64
          %392 = arith.trunci %390 : i32 to i8
          %393 = llvm.getelementptr %347[%391] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %392, %393 : i8, !llvm.ptr
          %394 = llvm.load %387 : !llvm.ptr -> i64
          %395 = llvm.load %372 : !llvm.ptr -> i64
          %396 = arith.addi %394, %395 : i64
          llvm.store %396, %387 : i64, !llvm.ptr
          cf.br ^bb78
        ^bb80:
        cf.br ^bb77
      ^bb76:
        cf.br ^bb77
      ^bb77:
      %397 = llvm.load %372 : !llvm.ptr -> i64
      %398 = arith.constant 1 : i32
      %400 = arith.extsi %398 : i32 to i64
      %399 = arith.addi %397, %400 : i64
      llvm.store %399, %372 : i64, !llvm.ptr
      cf.br ^bb72
    ^bb74:
    %401 = arith.constant 200000 : i32
    %402 = arith.extsi %401 : i32 to i64
    %403 = llvm.mlir.constant(1 : i64) : i64
    %404 = llvm.alloca %403 x i64 : (i64) -> !llvm.ptr
    llvm.store %402, %404 : i64, !llvm.ptr
    %406 = llvm.load %404 : !llvm.ptr -> i64
    %407 = arith.constant 8 : i32
    %408 = arith.extsi %407 : i32 to i64
    %405 = func.call @calloc(%406, %408) : (i64, i64) -> !llvm.ptr
    %409 = arith.constant 0 : i32
    %410 = arith.extsi %409 : i32 to i64
    %411 = llvm.mlir.constant(1 : i64) : i64
    %412 = llvm.alloca %411 x i64 : (i64) -> !llvm.ptr
    llvm.store %410, %412 : i64, !llvm.ptr
    %413 = arith.constant 2 : i32
    %414 = arith.extsi %413 : i32 to i64
    llvm.store %414, %372 : i64, !llvm.ptr
    cf.br ^bb81
    ^bb81:
    %415 = llvm.load %372 : !llvm.ptr -> i64
    %416 = arith.cmpi sle, %415, %346 : i64
    cf.cond_br %416, ^bb82, ^bb83
    ^bb82:
      %418 = llvm.load %372 : !llvm.ptr -> i64
      %419 = llvm.getelementptr %347[%418] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %417 = llvm.load %419 : !llvm.ptr -> i8
      %420 = arith.constant 0 : i32
      %422 = arith.extsi %417 : i8 to i32
      %421 = arith.cmpi eq, %422, %420 : i32
      cf.cond_br %421, ^bb84, ^bb85
      ^bb84:
        %423 = llvm.load %372 : !llvm.ptr -> i64
        %424 = llvm.load %412 : !llvm.ptr -> i64
        %425 = llvm.getelementptr %405[%424] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %423, %425 : i64, !llvm.ptr
        %426 = llvm.load %412 : !llvm.ptr -> i64
        %427 = arith.constant 1 : i32
        %429 = arith.extsi %427 : i32 to i64
        %428 = arith.addi %426, %429 : i64
        llvm.store %428, %412 : i64, !llvm.ptr
        cf.br ^bb86
      ^bb85:
        cf.br ^bb86
      ^bb86:
      %430 = llvm.load %372 : !llvm.ptr -> i64
      %431 = arith.constant 1 : i32
      %433 = arith.extsi %431 : i32 to i64
      %432 = arith.addi %430, %433 : i64
      llvm.store %432, %372 : i64, !llvm.ptr
      cf.br ^bb81
    ^bb83:
    func.call @free(%347) : (!llvm.ptr) -> ()
    %436 = arith.constant 32 : i32
    %437 = arith.constant 8 : i32
    %438 = arith.extsi %436 : i32 to i64
    %439 = arith.extsi %437 : i32 to i64
    %435 = func.call @calloc(%438, %439) : (i64, i64) -> !llvm.ptr
    %441 = arith.constant 1 : i32
    %443 = arith.extsi %441 : i32 to i64
    %442 = arith.subi %arg1, %443 : i64
    %440 = func.call @prime_factors_into(%442, %435) : (i64, !llvm.ptr) -> i64
    %444 = arith.constant 1 : i32
    %446 = arith.extsi %444 : i32 to i64
    %445 = arith.addi %arg0, %446 : i64
    %447 = arith.divsi %445, %arg1 : i64
    %449 = arith.constant 1 : i32
    %451 = arith.extsi %449 : i32 to i64
    %450 = arith.addi %447, %451 : i64
    %452 = arith.constant 1 : i32
    %453 = arith.extsi %452 : i32 to i64
    %448 = func.call @calloc(%450, %453) : (i64, i64) -> !llvm.ptr
    %454 = llvm.mlir.zero : !llvm.ptr
    %455 = llvm.icmp "eq" %448, %454 : !llvm.ptr
    cf.cond_br %455, ^bb87, ^bb88
    ^bb87:
      %456 = arith.constant 1 : i32
      %458 = arith.constant 0 : i32
      %457 = arith.subi %458, %456 : i32
      %459 = arith.extsi %457 : i32 to i64
      func.return %459 : i64
    ^bb88:
      cf.br ^bb89
    ^bb89:
    %460 = arith.constant 1 : i32
    %461 = arith.constant 0 : i32
    %462 = arith.trunci %460 : i32 to i8
    %463 = arith.extsi %461 : i32 to i64
    %464 = llvm.getelementptr %448[%463] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %462, %464 : i8, !llvm.ptr
    %465 = arith.constant 0 : i32
    %466 = arith.extsi %465 : i32 to i64
    %467 = llvm.mlir.constant(1 : i64) : i64
    %468 = llvm.alloca %467 x i64 : (i64) -> !llvm.ptr
    llvm.store %466, %468 : i64, !llvm.ptr
    cf.br ^bb90
    ^bb90:
    %469 = llvm.load %468 : !llvm.ptr -> i64
    %470 = llvm.load %412 : !llvm.ptr -> i64
    %471 = arith.cmpi slt, %469, %470 : i64
    cf.cond_br %471, ^bb91, ^bb92
    ^bb91:
      %473 = llvm.load %468 : !llvm.ptr -> i64
      %474 = llvm.getelementptr %405[%473] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %472 = llvm.load %474 : !llvm.ptr -> i64
      %475 = arith.cmpi ne, %472, %arg1 : i64
      cf.cond_br %475, ^bb93, ^bb94
      ^bb93:
        %477 = arith.remsi %arg1, %472 : i64
        %478 = arith.constant 2 : i32
        %480 = arith.extsi %478 : i32 to i64
        %479 = arith.subi %472, %480 : i64
        %476 = func.call @modpow(%477, %479, %472) : (i64, i64, i64) -> i64
        %481 = arith.muli %472, %472 : i64
        %482 = arith.constant 1 : i32
        %484 = arith.extsi %482 : i32 to i64
        %483 = arith.addi %481, %484 : i64
        %485 = arith.addi %483, %arg1 : i64
        %486 = arith.constant 1 : i32
        %488 = arith.extsi %486 : i32 to i64
        %487 = arith.subi %485, %488 : i64
        %489 = arith.divsi %487, %arg1 : i64
        %490 = llvm.mlir.constant(1 : i64) : i64
        %491 = llvm.alloca %490 x i64 : (i64) -> !llvm.ptr
        llvm.store %476, %491 : i64, !llvm.ptr
        %492 = llvm.load %491 : !llvm.ptr -> i64
        %493 = arith.cmpi slt, %492, %489 : i64
        cf.cond_br %493, ^bb96, ^bb97
        ^bb96:
          %494 = llvm.load %491 : !llvm.ptr -> i64
          %495 = llvm.load %491 : !llvm.ptr -> i64
          %496 = arith.subi %489, %495 : i64
          %497 = arith.addi %496, %472 : i64
          %498 = arith.constant 1 : i32
          %500 = arith.extsi %498 : i32 to i64
          %499 = arith.subi %497, %500 : i64
          %501 = arith.divsi %499, %472 : i64
          %502 = arith.muli %501, %472 : i64
          %503 = arith.addi %494, %502 : i64
          llvm.store %503, %491 : i64, !llvm.ptr
          cf.br ^bb98
        ^bb97:
          cf.br ^bb98
        ^bb98:
        %504 = llvm.load %491 : !llvm.ptr -> i64
        %505 = llvm.mlir.constant(1 : i64) : i64
        %506 = llvm.alloca %505 x i64 : (i64) -> !llvm.ptr
        llvm.store %504, %506 : i64, !llvm.ptr
        cf.br ^bb99
        ^bb99:
        %507 = llvm.load %506 : !llvm.ptr -> i64
        %508 = arith.cmpi sle, %507, %447 : i64
        cf.cond_br %508, ^bb100, ^bb101
        ^bb100:
          %509 = arith.constant 1 : i32
          %510 = llvm.load %506 : !llvm.ptr -> i64
          %511 = arith.trunci %509 : i32 to i8
          %512 = llvm.getelementptr %448[%510] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %511, %512 : i8, !llvm.ptr
          %513 = llvm.load %506 : !llvm.ptr -> i64
          %514 = arith.addi %513, %472 : i64
          llvm.store %514, %506 : i64, !llvm.ptr
          cf.br ^bb99
        ^bb101:
        cf.br ^bb95
      ^bb94:
        cf.br ^bb95
      ^bb95:
      %515 = llvm.load %468 : !llvm.ptr -> i64
      %516 = arith.constant 1 : i32
      %518 = arith.extsi %516 : i32 to i64
      %517 = arith.addi %515, %518 : i64
      llvm.store %517, %468 : i64, !llvm.ptr
      cf.br ^bb90
    ^bb92:
    %519 = arith.constant 10 : i32
    %521 = arith.extsi %519 : i32 to i64
    %520 = arith.divsi %447, %521 : i64
    %522 = arith.constant 1000 : i32
    %524 = arith.extsi %522 : i32 to i64
    %523 = arith.addi %520, %524 : i64
    %525 = llvm.mlir.constant(1 : i64) : i64
    %526 = llvm.alloca %525 x i64 : (i64) -> !llvm.ptr
    llvm.store %523, %526 : i64, !llvm.ptr
    %528 = llvm.load %526 : !llvm.ptr -> i64
    %529 = arith.constant 8 : i32
    %530 = arith.extsi %529 : i32 to i64
    %527 = func.call @calloc(%528, %530) : (i64, i64) -> !llvm.ptr
    %531 = arith.constant 0 : i32
    %532 = arith.extsi %531 : i32 to i64
    %533 = llvm.mlir.constant(1 : i64) : i64
    %534 = llvm.alloca %533 x i64 : (i64) -> !llvm.ptr
    llvm.store %532, %534 : i64, !llvm.ptr
    %535 = arith.constant 1 : i32
    %536 = arith.extsi %535 : i32 to i64
    %537 = llvm.mlir.constant(1 : i64) : i64
    %538 = llvm.alloca %537 x i64 : (i64) -> !llvm.ptr
    llvm.store %536, %538 : i64, !llvm.ptr
    cf.br ^bb102(%527 : !llvm.ptr)
    ^bb102(%539: !llvm.ptr):
    %540 = llvm.load %538 : !llvm.ptr -> i64
    %541 = arith.cmpi sle, %540, %447 : i64
    cf.cond_br %541, ^bb103(%539 : !llvm.ptr), ^bb104(%539 : !llvm.ptr)
    ^bb103(%542: !llvm.ptr):
      %544 = llvm.load %538 : !llvm.ptr -> i64
      %545 = llvm.getelementptr %448[%544] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %543 = llvm.load %545 : !llvm.ptr -> i8
      %546 = arith.constant 0 : i32
      %548 = arith.extsi %543 : i8 to i32
      %547 = arith.cmpi eq, %548, %546 : i32
      cf.cond_br %547, ^bb105, ^bb106
      ^bb105:
        %549 = llvm.load %534 : !llvm.ptr -> i64
        %550 = llvm.load %526 : !llvm.ptr -> i64
        %551 = arith.cmpi sge, %549, %550 : i64
        %552 = scf.if %551 -> (!llvm.ptr) {
          %553 = llvm.load %526 : !llvm.ptr -> i64
          %554 = arith.constant 2 : i32
          %556 = arith.extsi %554 : i32 to i64
          %555 = arith.muli %553, %556 : i64
          llvm.store %555, %526 : i64, !llvm.ptr
          %558 = llvm.load %526 : !llvm.ptr -> i64
          %559 = arith.constant 8 : i32
          %561 = arith.extsi %559 : i32 to i64
          %560 = arith.muli %558, %561 : i64
          %557 = func.call @realloc(%542, %560) : (!llvm.ptr, i64) -> !llvm.ptr
          scf.yield %557 : !llvm.ptr
        } else {
          scf.yield %542 : !llvm.ptr
        }
        %562 = llvm.load %538 : !llvm.ptr -> i64
        %563 = arith.muli %arg1, %562 : i64
        %564 = arith.constant 1 : i32
        %566 = arith.extsi %564 : i32 to i64
        %565 = arith.subi %563, %566 : i64
        %567 = llvm.load %534 : !llvm.ptr -> i64
        %568 = llvm.getelementptr %552[%567] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %565, %568 : i64, !llvm.ptr
        %569 = llvm.load %534 : !llvm.ptr -> i64
        %570 = arith.constant 1 : i32
        %572 = arith.extsi %570 : i32 to i64
        %571 = arith.addi %569, %572 : i64
        llvm.store %571, %534 : i64, !llvm.ptr
        cf.br ^bb107(%552 : !llvm.ptr)
      ^bb106:
        cf.br ^bb107(%542 : !llvm.ptr)
      ^bb107(%573: !llvm.ptr):
      %574 = llvm.load %538 : !llvm.ptr -> i64
      %575 = arith.constant 1 : i32
      %577 = arith.extsi %575 : i32 to i64
      %576 = arith.addi %574, %577 : i64
      llvm.store %576, %538 : i64, !llvm.ptr
      cf.br ^bb102(%573 : !llvm.ptr)
    ^bb104(%578: !llvm.ptr):
    func.call @free(%448) : (!llvm.ptr) -> ()
    %580 = arith.constant 100000 : i32
    %581 = arith.extsi %580 : i32 to i64
    %582 = llvm.mlir.constant(1 : i64) : i64
    %583 = llvm.alloca %582 x i64 : (i64) -> !llvm.ptr
    llvm.store %581, %583 : i64, !llvm.ptr
    %585 = llvm.load %583 : !llvm.ptr -> i64
    %586 = arith.constant 8 : i32
    %587 = arith.extsi %586 : i32 to i64
    %584 = func.call @calloc(%585, %587) : (i64, i64) -> !llvm.ptr
    %589 = llvm.load %583 : !llvm.ptr -> i64
    %590 = arith.constant 8 : i32
    %591 = arith.extsi %590 : i32 to i64
    %588 = func.call @calloc(%589, %591) : (i64, i64) -> !llvm.ptr
    %592 = arith.constant 0 : i32
    %593 = arith.extsi %592 : i32 to i64
    %594 = llvm.mlir.constant(1 : i64) : i64
    %595 = llvm.alloca %594 x i64 : (i64) -> !llvm.ptr
    llvm.store %593, %595 : i64, !llvm.ptr
    %596 = arith.constant 0 : i32
    %597 = arith.extsi %596 : i32 to i64
    llvm.store %597, %468 : i64, !llvm.ptr
    cf.br ^bb108(%584, %588 : !llvm.ptr, !llvm.ptr)
    ^bb108(%598: !llvm.ptr, %599: !llvm.ptr):
    %600 = llvm.load %468 : !llvm.ptr -> i64
    %601 = llvm.load %412 : !llvm.ptr -> i64
    %602 = arith.cmpi slt, %600, %601 : i64
    cf.cond_br %602, ^bb109(%598, %599 : !llvm.ptr, !llvm.ptr), ^bb110(%598, %599 : !llvm.ptr, !llvm.ptr)
    ^bb109(%603: !llvm.ptr, %604: !llvm.ptr):
      %606 = llvm.load %468 : !llvm.ptr -> i64
      %607 = llvm.getelementptr %405[%606] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %605 = llvm.load %607 : !llvm.ptr -> i64
      %608 = arith.cmpi ne, %605, %arg1 : i64
      cf.cond_br %608, ^bb111, ^bb112
      ^bb111:
        %609 = arith.remsi %605, %arg1 : i64
        %610 = arith.constant 1 : i32
        %612 = arith.extsi %610 : i32 to i64
        %611 = arith.cmpi ne, %609, %612 : i64
        cf.cond_br %611, ^bb114, ^bb115
        ^bb114:
          %613 = func.call @multiplicative_order(%605, %arg1, %435, %440) : (i64, i64, !llvm.ptr, i64) -> i64
          %614 = arith.constant 1 : i32
          %615 = arith.extsi %614 : i32 to i64
          %616 = llvm.mlir.constant(1 : i64) : i64
          %617 = llvm.alloca %616 x i64 : (i64) -> !llvm.ptr
          llvm.store %615, %617 : i64, !llvm.ptr
          %618 = arith.constant 0 : i32
          %619 = arith.extsi %618 : i32 to i64
          %620 = llvm.mlir.constant(1 : i64) : i64
          %621 = llvm.alloca %620 x i64 : (i64) -> !llvm.ptr
          llvm.store %619, %621 : i64, !llvm.ptr
          cf.br ^bb117(%603, %604 : !llvm.ptr, !llvm.ptr)
          ^bb117(%622: !llvm.ptr, %623: !llvm.ptr):
          %624 = llvm.load %617 : !llvm.ptr -> i64
          %625 = arith.divsi %arg0, %605 : i64
          %626 = arith.cmpi sle, %624, %625 : i64
          cf.cond_br %626, ^bb118(%622, %623 : !llvm.ptr, !llvm.ptr), ^bb119(%622, %623 : !llvm.ptr, !llvm.ptr)
          ^bb118(%627: !llvm.ptr, %628: !llvm.ptr):
            %629 = llvm.load %617 : !llvm.ptr -> i64
            %630 = arith.muli %629, %605 : i64
            llvm.store %630, %617 : i64, !llvm.ptr
            %631 = llvm.load %621 : !llvm.ptr -> i64
            %632 = arith.constant 1 : i32
            %634 = arith.extsi %632 : i32 to i64
            %633 = arith.addi %631, %634 : i64
            llvm.store %633, %621 : i64, !llvm.ptr
            %635 = llvm.load %621 : !llvm.ptr -> i64
            %636 = arith.constant 1 : i32
            %638 = arith.extsi %636 : i32 to i64
            %637 = arith.addi %635, %638 : i64
            %639 = arith.remsi %637, %613 : i64
            %640 = arith.constant 0 : i32
            %642 = arith.extsi %640 : i32 to i64
            %641 = arith.cmpi eq, %639, %642 : i64
            cf.cond_br %641, ^bb120, ^bb121
            ^bb120:
              %643 = arith.constant 2 : i32
              %645 = arith.extsi %643 : i32 to i64
              %644 = arith.cmpi eq, %613, %645 : i64
              %646 = scf.if %644 -> (i1) {
                %647 = llvm.load %621 : !llvm.ptr -> i64
                %648 = arith.constant 1 : i32
                %650 = arith.extsi %648 : i32 to i64
                %649 = arith.cmpi eq, %647, %650 : i64
                scf.yield %649 : i1
              } else {
                %651 = arith.constant false
                scf.yield %651 : i1
              }
              %653 = arith.constant 1 : i1
              %652 = arith.xori %646, %653 : i1
              cf.cond_br %652, ^bb123, ^bb124
              ^bb123:
                %655 = llvm.load %595 : !llvm.ptr -> i64
                %656 = llvm.load %583 : !llvm.ptr -> i64
                %657 = arith.cmpi sge, %655, %656 : i64
                %658, %659 = scf.if %657 -> (!llvm.ptr, !llvm.ptr) {
                  %660 = llvm.load %583 : !llvm.ptr -> i64
                  %661 = arith.constant 2 : i32
                  %663 = arith.extsi %661 : i32 to i64
                  %662 = arith.muli %660, %663 : i64
                  llvm.store %662, %583 : i64, !llvm.ptr
                  %665 = llvm.load %583 : !llvm.ptr -> i64
                  %666 = arith.constant 8 : i32
                  %668 = arith.extsi %666 : i32 to i64
                  %667 = arith.muli %665, %668 : i64
                  %664 = func.call @realloc(%627, %667) : (!llvm.ptr, i64) -> !llvm.ptr
                  %670 = llvm.load %583 : !llvm.ptr -> i64
                  %671 = arith.constant 8 : i32
                  %673 = arith.extsi %671 : i32 to i64
                  %672 = arith.muli %670, %673 : i64
                  %669 = func.call @realloc(%628, %672) : (!llvm.ptr, i64) -> !llvm.ptr
                  scf.yield %664, %669 : !llvm.ptr, !llvm.ptr
                } else {
                  scf.yield %627, %628 : !llvm.ptr, !llvm.ptr
                }
                %674 = llvm.load %595 : !llvm.ptr -> i64
                %675 = llvm.getelementptr %658[%674] : (!llvm.ptr, i64) -> !llvm.ptr, i64
                llvm.store %605, %675 : i64, !llvm.ptr
                %676 = llvm.load %617 : !llvm.ptr -> i64
                %677 = llvm.load %595 : !llvm.ptr -> i64
                %678 = llvm.getelementptr %659[%677] : (!llvm.ptr, i64) -> !llvm.ptr, i64
                llvm.store %676, %678 : i64, !llvm.ptr
                %679 = llvm.load %595 : !llvm.ptr -> i64
                %680 = arith.constant 1 : i32
                %682 = arith.extsi %680 : i32 to i64
                %681 = arith.addi %679, %682 : i64
                llvm.store %681, %595 : i64, !llvm.ptr
                cf.br ^bb125(%658, %659 : !llvm.ptr, !llvm.ptr)
              ^bb124:
                cf.br ^bb125(%627, %628 : !llvm.ptr, !llvm.ptr)
              ^bb125(%683: !llvm.ptr, %684: !llvm.ptr):
              cf.br ^bb122(%683, %684 : !llvm.ptr, !llvm.ptr)
            ^bb121:
              cf.br ^bb122(%627, %628 : !llvm.ptr, !llvm.ptr)
            ^bb122(%685: !llvm.ptr, %686: !llvm.ptr):
            cf.br ^bb117(%685, %686 : !llvm.ptr, !llvm.ptr)
          ^bb119(%687: !llvm.ptr, %688: !llvm.ptr):
          cf.br ^bb116(%687, %688 : !llvm.ptr, !llvm.ptr)
        ^bb115:
          cf.br ^bb116(%603, %604 : !llvm.ptr, !llvm.ptr)
        ^bb116(%689: !llvm.ptr, %690: !llvm.ptr):
        cf.br ^bb113(%689, %690 : !llvm.ptr, !llvm.ptr)
      ^bb112:
        cf.br ^bb113(%603, %604 : !llvm.ptr, !llvm.ptr)
      ^bb113(%691: !llvm.ptr, %692: !llvm.ptr):
      %693 = llvm.load %468 : !llvm.ptr -> i64
      %694 = arith.constant 1 : i32
      %696 = arith.extsi %694 : i32 to i64
      %695 = arith.addi %693, %696 : i64
      llvm.store %695, %468 : i64, !llvm.ptr
      cf.br ^bb108(%691, %692 : !llvm.ptr, !llvm.ptr)
    ^bb110(%697: !llvm.ptr, %698: !llvm.ptr):
    %699 = arith.constant 1 : i32
    %700 = arith.extsi %699 : i32 to i64
    %701 = llvm.mlir.constant(1 : i64) : i64
    %702 = llvm.alloca %701 x i64 : (i64) -> !llvm.ptr
    llvm.store %700, %702 : i64, !llvm.ptr
    cf.br ^bb126
    ^bb126:
    %703 = llvm.load %702 : !llvm.ptr -> i64
    %704 = llvm.load %595 : !llvm.ptr -> i64
    %705 = arith.cmpi slt, %703, %704 : i64
    cf.cond_br %705, ^bb127, ^bb128
    ^bb127:
      %706 = llvm.load %702 : !llvm.ptr -> i64
      %707 = llvm.mlir.constant(1 : i64) : i64
      %708 = llvm.alloca %707 x i64 : (i64) -> !llvm.ptr
      llvm.store %706, %708 : i64, !llvm.ptr
      cf.br ^bb129
      ^bb129:
      %709 = llvm.load %708 : !llvm.ptr -> i64
      %710 = arith.constant 0 : i32
      %712 = arith.extsi %710 : i32 to i64
      %711 = arith.cmpi sgt, %709, %712 : i64
      %713 = scf.if %711 -> (i1) {
        %715 = llvm.load %708 : !llvm.ptr -> i64
        %716 = arith.constant 1 : i32
        %718 = arith.extsi %716 : i32 to i64
        %717 = arith.subi %715, %718 : i64
        %719 = llvm.getelementptr %698[%717] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %714 = llvm.load %719 : !llvm.ptr -> i64
        %721 = llvm.load %708 : !llvm.ptr -> i64
        %722 = llvm.getelementptr %698[%721] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %720 = llvm.load %722 : !llvm.ptr -> i64
        %723 = arith.cmpi sgt, %714, %720 : i64
        scf.yield %723 : i1
      } else {
        %724 = arith.constant false
        scf.yield %724 : i1
      }
      cf.cond_br %713, ^bb130, ^bb131
      ^bb130:
        %726 = llvm.load %708 : !llvm.ptr -> i64
        %727 = llvm.getelementptr %697[%726] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %725 = llvm.load %727 : !llvm.ptr -> i64
        %729 = llvm.load %708 : !llvm.ptr -> i64
        %730 = llvm.getelementptr %698[%729] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %728 = llvm.load %730 : !llvm.ptr -> i64
        %732 = llvm.load %708 : !llvm.ptr -> i64
        %733 = arith.constant 1 : i32
        %735 = arith.extsi %733 : i32 to i64
        %734 = arith.subi %732, %735 : i64
        %736 = llvm.getelementptr %697[%734] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %731 = llvm.load %736 : !llvm.ptr -> i64
        %737 = llvm.load %708 : !llvm.ptr -> i64
        %738 = llvm.getelementptr %697[%737] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %731, %738 : i64, !llvm.ptr
        %740 = llvm.load %708 : !llvm.ptr -> i64
        %741 = arith.constant 1 : i32
        %743 = arith.extsi %741 : i32 to i64
        %742 = arith.subi %740, %743 : i64
        %744 = llvm.getelementptr %698[%742] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %739 = llvm.load %744 : !llvm.ptr -> i64
        %745 = llvm.load %708 : !llvm.ptr -> i64
        %746 = llvm.getelementptr %698[%745] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %739, %746 : i64, !llvm.ptr
        %747 = llvm.load %708 : !llvm.ptr -> i64
        %748 = arith.constant 1 : i32
        %750 = arith.extsi %748 : i32 to i64
        %749 = arith.subi %747, %750 : i64
        %751 = llvm.getelementptr %697[%749] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %725, %751 : i64, !llvm.ptr
        %752 = llvm.load %708 : !llvm.ptr -> i64
        %753 = arith.constant 1 : i32
        %755 = arith.extsi %753 : i32 to i64
        %754 = arith.subi %752, %755 : i64
        %756 = llvm.getelementptr %698[%754] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %728, %756 : i64, !llvm.ptr
        %757 = llvm.load %708 : !llvm.ptr -> i64
        %758 = arith.constant 1 : i32
        %760 = arith.extsi %758 : i32 to i64
        %759 = arith.subi %757, %760 : i64
        llvm.store %759, %708 : i64, !llvm.ptr
        cf.br ^bb129
      ^bb131:
      %761 = llvm.load %702 : !llvm.ptr -> i64
      %762 = arith.constant 1 : i32
      %764 = arith.extsi %762 : i32 to i64
      %763 = arith.addi %761, %764 : i64
      llvm.store %763, %702 : i64, !llvm.ptr
      cf.br ^bb126
    ^bb128:
    %765 = arith.constant 0 : i32
    %766 = arith.extsi %765 : i32 to i64
    %767 = llvm.mlir.constant(1 : i64) : i64
    %768 = llvm.alloca %767 x i64 : (i64) -> !llvm.ptr
    llvm.store %766, %768 : i64, !llvm.ptr
    %769 = arith.constant 0 : i32
    %770 = arith.extsi %769 : i32 to i64
    llvm.store %770, %468 : i64, !llvm.ptr
    cf.br ^bb132
    ^bb132:
    %771 = llvm.load %468 : !llvm.ptr -> i64
    %772 = llvm.load %534 : !llvm.ptr -> i64
    %773 = arith.cmpi slt, %771, %772 : i64
    cf.cond_br %773, ^bb133, ^bb134
    ^bb133:
      %775 = llvm.load %468 : !llvm.ptr -> i64
      %776 = llvm.getelementptr %578[%775] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %774 = llvm.load %776 : !llvm.ptr -> i64
      %777 = llvm.load %768 : !llvm.ptr -> i64
      %778 = func.call @single_event_sum(%arg0, %774, %774) : (i64, i64, i64) -> i64
      %779 = arith.addi %777, %778 : i64
      llvm.store %779, %768 : i64, !llvm.ptr
      %780 = llvm.load %468 : !llvm.ptr -> i64
      %781 = arith.constant 1 : i32
      %783 = arith.extsi %781 : i32 to i64
      %782 = arith.addi %780, %783 : i64
      llvm.store %782, %468 : i64, !llvm.ptr
      cf.br ^bb132
    ^bb134:
    %784 = arith.constant 0 : i32
    %785 = arith.extsi %784 : i32 to i64
    llvm.store %785, %468 : i64, !llvm.ptr
    cf.br ^bb135
    ^bb135:
    %786 = llvm.load %468 : !llvm.ptr -> i64
    %787 = llvm.load %595 : !llvm.ptr -> i64
    %788 = arith.cmpi slt, %786, %787 : i64
    cf.cond_br %788, ^bb136, ^bb137
    ^bb136:
      %789 = llvm.load %768 : !llvm.ptr -> i64
      %792 = llvm.load %468 : !llvm.ptr -> i64
      %793 = llvm.getelementptr %697[%792] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %791 = llvm.load %793 : !llvm.ptr -> i64
      %795 = llvm.load %468 : !llvm.ptr -> i64
      %796 = llvm.getelementptr %698[%795] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %794 = llvm.load %796 : !llvm.ptr -> i64
      %790 = func.call @single_event_sum(%arg0, %791, %794) : (i64, i64, i64) -> i64
      %797 = arith.addi %789, %790 : i64
      llvm.store %797, %768 : i64, !llvm.ptr
      %798 = llvm.load %468 : !llvm.ptr -> i64
      %799 = arith.constant 1 : i32
      %801 = arith.extsi %799 : i32 to i64
      %800 = arith.addi %798, %801 : i64
      llvm.store %800, %468 : i64, !llvm.ptr
      cf.br ^bb135
    ^bb137:
    %802 = arith.constant 0 : i32
    %803 = arith.extsi %802 : i32 to i64
    llvm.store %803, %468 : i64, !llvm.ptr
    cf.br ^bb138
    ^bb138:
    %804 = llvm.load %468 : !llvm.ptr -> i64
    %805 = llvm.load %534 : !llvm.ptr -> i64
    %806 = arith.cmpi slt, %804, %805 : i64
    cf.cond_br %806, ^bb139, ^bb140
    ^bb139:
      %808 = llvm.load %468 : !llvm.ptr -> i64
      %809 = llvm.getelementptr %578[%808] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %807 = llvm.load %809 : !llvm.ptr -> i64
      %810 = arith.muli %807, %807 : i64
      %811 = arith.cmpi sgt, %810, %arg0 : i64
      cf.cond_br %811, ^bb141, ^bb142
      ^bb141:
        cf.br ^bb140
      ^bb142:
        cf.br ^bb143
      ^bb143:
      %812 = llvm.load %468 : !llvm.ptr -> i64
      %813 = arith.constant 1 : i32
      %815 = arith.extsi %813 : i32 to i64
      %814 = arith.addi %812, %815 : i64
      %816 = llvm.mlir.constant(1 : i64) : i64
      %817 = llvm.alloca %816 x i64 : (i64) -> !llvm.ptr
      llvm.store %814, %817 : i64, !llvm.ptr
      %818 = llvm.load %534 : !llvm.ptr -> i64
      %819 = llvm.mlir.constant(1 : i64) : i64
      %820 = llvm.alloca %819 x i64 : (i64) -> !llvm.ptr
      llvm.store %818, %820 : i64, !llvm.ptr
      %821 = arith.divsi %arg0, %807 : i64
      cf.br ^bb144
      ^bb144:
      %822 = llvm.load %817 : !llvm.ptr -> i64
      %823 = llvm.load %820 : !llvm.ptr -> i64
      %824 = arith.cmpi slt, %822, %823 : i64
      cf.cond_br %824, ^bb145, ^bb146
      ^bb145:
        %825 = llvm.load %817 : !llvm.ptr -> i64
        %826 = llvm.load %820 : !llvm.ptr -> i64
        %827 = arith.addi %825, %826 : i64
        %828 = arith.constant 2 : i32
        %830 = arith.extsi %828 : i32 to i64
        %829 = arith.divsi %827, %830 : i64
        %832 = llvm.getelementptr %578[%829] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %831 = llvm.load %832 : !llvm.ptr -> i64
        %833 = arith.cmpi sle, %831, %821 : i64
        cf.cond_br %833, ^bb147, ^bb148
        ^bb147:
          %834 = arith.constant 1 : i32
          %836 = arith.extsi %834 : i32 to i64
          %835 = arith.addi %829, %836 : i64
          llvm.store %835, %817 : i64, !llvm.ptr
          cf.br ^bb149
        ^bb148:
          llvm.store %829, %820 : i64, !llvm.ptr
          cf.br ^bb149
        ^bb149:
        cf.br ^bb144
      ^bb146:
      %837 = llvm.load %468 : !llvm.ptr -> i64
      %838 = arith.constant 1 : i32
      %840 = arith.extsi %838 : i32 to i64
      %839 = arith.addi %837, %840 : i64
      %841 = llvm.mlir.constant(1 : i64) : i64
      %842 = llvm.alloca %841 x i64 : (i64) -> !llvm.ptr
      llvm.store %839, %842 : i64, !llvm.ptr
      cf.br ^bb150
      ^bb150:
      %843 = llvm.load %842 : !llvm.ptr -> i64
      %844 = llvm.load %817 : !llvm.ptr -> i64
      %845 = arith.cmpi slt, %843, %844 : i64
      cf.cond_br %845, ^bb151, ^bb152
      ^bb151:
        %846 = llvm.load %768 : !llvm.ptr -> i64
        %849 = llvm.load %842 : !llvm.ptr -> i64
        %850 = llvm.getelementptr %578[%849] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %848 = llvm.load %850 : !llvm.ptr -> i64
        %852 = llvm.load %842 : !llvm.ptr -> i64
        %853 = llvm.getelementptr %578[%852] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %851 = llvm.load %853 : !llvm.ptr -> i64
        %847 = func.call @pair_event_sum(%arg0, %807, %807, %848, %851) : (i64, i64, i64, i64, i64) -> i64
        %854 = arith.subi %846, %847 : i64
        llvm.store %854, %768 : i64, !llvm.ptr
        %855 = llvm.load %842 : !llvm.ptr -> i64
        %856 = arith.constant 1 : i32
        %858 = arith.extsi %856 : i32 to i64
        %857 = arith.addi %855, %858 : i64
        llvm.store %857, %842 : i64, !llvm.ptr
        cf.br ^bb150
      ^bb152:
      %859 = llvm.load %468 : !llvm.ptr -> i64
      %860 = arith.constant 1 : i32
      %862 = arith.extsi %860 : i32 to i64
      %861 = arith.addi %859, %862 : i64
      llvm.store %861, %468 : i64, !llvm.ptr
      cf.br ^bb138
    ^bb140:
    %863 = arith.constant 0 : i32
    %864 = arith.extsi %863 : i32 to i64
    llvm.store %864, %468 : i64, !llvm.ptr
    cf.br ^bb153
    ^bb153:
    %865 = llvm.load %468 : !llvm.ptr -> i64
    %866 = llvm.load %595 : !llvm.ptr -> i64
    %867 = arith.cmpi slt, %865, %866 : i64
    cf.cond_br %867, ^bb154, ^bb155
    ^bb154:
      %869 = llvm.load %468 : !llvm.ptr -> i64
      %870 = llvm.getelementptr %697[%869] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %868 = llvm.load %870 : !llvm.ptr -> i64
      %872 = llvm.load %468 : !llvm.ptr -> i64
      %873 = llvm.getelementptr %698[%872] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %871 = llvm.load %873 : !llvm.ptr -> i64
      %874 = arith.constant 0 : i32
      %875 = arith.extsi %874 : i32 to i64
      %876 = llvm.mlir.constant(1 : i64) : i64
      %877 = llvm.alloca %876 x i64 : (i64) -> !llvm.ptr
      llvm.store %875, %877 : i64, !llvm.ptr
      %878 = llvm.load %534 : !llvm.ptr -> i64
      %879 = llvm.mlir.constant(1 : i64) : i64
      %880 = llvm.alloca %879 x i64 : (i64) -> !llvm.ptr
      llvm.store %878, %880 : i64, !llvm.ptr
      %881 = arith.divsi %arg0, %871 : i64
      cf.br ^bb156
      ^bb156:
      %882 = llvm.load %877 : !llvm.ptr -> i64
      %883 = llvm.load %880 : !llvm.ptr -> i64
      %884 = arith.cmpi slt, %882, %883 : i64
      cf.cond_br %884, ^bb157, ^bb158
      ^bb157:
        %885 = llvm.load %877 : !llvm.ptr -> i64
        %886 = llvm.load %880 : !llvm.ptr -> i64
        %887 = arith.addi %885, %886 : i64
        %888 = arith.constant 2 : i32
        %890 = arith.extsi %888 : i32 to i64
        %889 = arith.divsi %887, %890 : i64
        %892 = llvm.getelementptr %578[%889] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %891 = llvm.load %892 : !llvm.ptr -> i64
        %893 = arith.cmpi sle, %891, %881 : i64
        cf.cond_br %893, ^bb159, ^bb160
        ^bb159:
          %894 = arith.constant 1 : i32
          %896 = arith.extsi %894 : i32 to i64
          %895 = arith.addi %889, %896 : i64
          llvm.store %895, %877 : i64, !llvm.ptr
          cf.br ^bb161
        ^bb160:
          llvm.store %889, %880 : i64, !llvm.ptr
          cf.br ^bb161
        ^bb161:
        cf.br ^bb156
      ^bb158:
      %897 = arith.constant 0 : i32
      %898 = arith.extsi %897 : i32 to i64
      %899 = llvm.mlir.constant(1 : i64) : i64
      %900 = llvm.alloca %899 x i64 : (i64) -> !llvm.ptr
      llvm.store %898, %900 : i64, !llvm.ptr
      cf.br ^bb162
      ^bb162:
      %901 = llvm.load %900 : !llvm.ptr -> i64
      %902 = llvm.load %877 : !llvm.ptr -> i64
      %903 = arith.cmpi slt, %901, %902 : i64
      cf.cond_br %903, ^bb163, ^bb164
      ^bb163:
        %905 = llvm.load %900 : !llvm.ptr -> i64
        %906 = llvm.getelementptr %578[%905] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %904 = llvm.load %906 : !llvm.ptr -> i64
        %907 = arith.cmpi ne, %904, %868 : i64
        cf.cond_br %907, ^bb165, ^bb166
        ^bb165:
          %908 = llvm.load %768 : !llvm.ptr -> i64
          %909 = func.call @pair_event_sum(%arg0, %868, %871, %904, %904) : (i64, i64, i64, i64, i64) -> i64
          %910 = arith.subi %908, %909 : i64
          llvm.store %910, %768 : i64, !llvm.ptr
          cf.br ^bb167
        ^bb166:
          cf.br ^bb167
        ^bb167:
        %911 = llvm.load %900 : !llvm.ptr -> i64
        %912 = arith.constant 1 : i32
        %914 = arith.extsi %912 : i32 to i64
        %913 = arith.addi %911, %914 : i64
        llvm.store %913, %900 : i64, !llvm.ptr
        cf.br ^bb162
      ^bb164:
      %915 = llvm.load %468 : !llvm.ptr -> i64
      %916 = arith.constant 1 : i32
      %918 = arith.extsi %916 : i32 to i64
      %917 = arith.addi %915, %918 : i64
      llvm.store %917, %468 : i64, !llvm.ptr
      cf.br ^bb153
    ^bb155:
    %919 = arith.constant 0 : i32
    %920 = arith.extsi %919 : i32 to i64
    llvm.store %920, %468 : i64, !llvm.ptr
    cf.br ^bb168
    ^bb168:
    %921 = llvm.load %468 : !llvm.ptr -> i64
    %922 = llvm.load %595 : !llvm.ptr -> i64
    %923 = arith.cmpi slt, %921, %922 : i64
    cf.cond_br %923, ^bb169, ^bb170
    ^bb169:
      %925 = llvm.load %468 : !llvm.ptr -> i64
      %926 = llvm.getelementptr %697[%925] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %924 = llvm.load %926 : !llvm.ptr -> i64
      %928 = llvm.load %468 : !llvm.ptr -> i64
      %929 = llvm.getelementptr %698[%928] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %927 = llvm.load %929 : !llvm.ptr -> i64
      %930 = arith.muli %927, %927 : i64
      %931 = arith.cmpi sgt, %930, %arg0 : i64
      cf.cond_br %931, ^bb171, ^bb172
      ^bb171:
        cf.br ^bb170
      ^bb172:
        cf.br ^bb173
      ^bb173:
      %932 = llvm.load %468 : !llvm.ptr -> i64
      %933 = arith.constant 1 : i32
      %935 = arith.extsi %933 : i32 to i64
      %934 = arith.addi %932, %935 : i64
      %936 = llvm.mlir.constant(1 : i64) : i64
      %937 = llvm.alloca %936 x i64 : (i64) -> !llvm.ptr
      llvm.store %934, %937 : i64, !llvm.ptr
      cf.br ^bb174
      ^bb174:
      %938 = llvm.load %937 : !llvm.ptr -> i64
      %939 = llvm.load %595 : !llvm.ptr -> i64
      %940 = arith.cmpi slt, %938, %939 : i64
      cf.cond_br %940, ^bb175, ^bb176
      ^bb175:
        %942 = llvm.load %937 : !llvm.ptr -> i64
        %943 = llvm.getelementptr %697[%942] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %941 = llvm.load %943 : !llvm.ptr -> i64
        %945 = llvm.load %937 : !llvm.ptr -> i64
        %946 = llvm.getelementptr %698[%945] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %944 = llvm.load %946 : !llvm.ptr -> i64
        %947 = arith.muli %927, %944 : i64
        %948 = arith.cmpi sgt, %947, %arg0 : i64
        cf.cond_br %948, ^bb177, ^bb178
        ^bb177:
          cf.br ^bb176
        ^bb178:
          cf.br ^bb179
        ^bb179:
        %949 = arith.cmpi ne, %924, %941 : i64
        cf.cond_br %949, ^bb180, ^bb181
        ^bb180:
          %950 = llvm.load %768 : !llvm.ptr -> i64
          %951 = func.call @pair_event_sum(%arg0, %924, %927, %941, %944) : (i64, i64, i64, i64, i64) -> i64
          %952 = arith.subi %950, %951 : i64
          llvm.store %952, %768 : i64, !llvm.ptr
          cf.br ^bb182
        ^bb181:
          cf.br ^bb182
        ^bb182:
        %953 = llvm.load %937 : !llvm.ptr -> i64
        %954 = arith.constant 1 : i32
        %956 = arith.extsi %954 : i32 to i64
        %955 = arith.addi %953, %956 : i64
        llvm.store %955, %937 : i64, !llvm.ptr
        cf.br ^bb174
      ^bb176:
      %957 = llvm.load %468 : !llvm.ptr -> i64
      %958 = arith.constant 1 : i32
      %960 = arith.extsi %958 : i32 to i64
      %959 = arith.addi %957, %960 : i64
      llvm.store %959, %468 : i64, !llvm.ptr
      cf.br ^bb168
    ^bb170:
    func.call @free(%698) : (!llvm.ptr) -> ()
    func.call @free(%697) : (!llvm.ptr) -> ()
    func.call @free(%578) : (!llvm.ptr) -> ()
    func.call @free(%435) : (!llvm.ptr) -> ()
    func.call @free(%405) : (!llvm.ptr) -> ()
    %966 = llvm.load %768 : !llvm.ptr -> i64
    func.return %966 : i64
  }
  func.func @main() -> i32 {
    %967 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %969 = arith.constant 95705032704 : i32
    %970 = arith.constant 2017 : i32
    %971 = arith.extsi %969 : i32 to i64
    %972 = arith.extsi %970 : i32 to i64
    %968 = func.call @search(%971, %972) : (i64, i64) -> i64
    %973 = llvm.call @printf(%967, %968) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %974 = arith.constant 0 : i32
    func.return %974 : i32
  }
}