Problem 560

Coprime Nim L(10^7,10^7) mod 10^9+7 via Grundy frequencies + FWHT XOR power.

Answer994345168
Output994345168
StatusPASS
Native helperno
Runtime430 ms
Peak memory31456 KB
Time complexityO(n^3) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^3)O(n * k)
Space complexityO(n)O(n)
ApproachFlow solutionKey search and XOR decryption
VerdictUnknown

Flow source

# Project Euler 560
# Coprime Nim
# L(10^7,10^7) mod 10^9+7 via Grundy frequencies + FWHT XOR power.

import euler.nt { isqrt }

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

const MOD: i64 = 1000000007

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 fwht(a: ptr<i64>, n: i64) -> void {
    let mut h: i64 = 1
    while h < n {
        let step: i64 = h << 1
        let mut i: i64 = 0
        while i < n {
            let mut j: i64 = i
            while j < i + h {
                let x: i64 = a[j]
                let y: i64 = a[j + h]
                let mut s: i64 = x + y
                if s >= MOD { s = s - MOD }
                let mut d: i64 = x - y
                if d < 0 { d = d + MOD }
                a[j] = s
                a[j + h] = d
                j = j + 1
            }
            i = i + step
        }
        h = step
    }
}

function compute_L(n: i64, k: i64) -> i64 {
    let N: i64 = n - 1
    let even_count: i64 = N / 2
    let odd_len: i64 = (N + 1) / 2
    let spf: ptr<i32> = calloc(odd_len, 4)
    if spf == null { return -1 }

    # counts of odd primes as spf; grow dynamically with cap
    let mut cap: i64 = 800000
    let counts: ptr<i32> = calloc(cap, 4)
    if counts == null { free(spf); return -1 }
    let mut P: i64 = 1  # counts[0] dummy; P = number of primes including 2

    let limit: i64 = isqrt(N)
    let i_end: i64 = (limit - 1) / 2
    let mut i: i64 = 1
    while i <= i_end {
        if spf[i] == 0 {
            let p: i32 = (2 * i + 1) as i32
            spf[i] = p
            if P >= cap { return -1 }
            counts[P] = 1
            P = P + 1
            let start: i64 = ((p as i64) * (p as i64) - 1) / 2
            let step: i64 = p as i64
            let mut j: i64 = start
            while j < odd_len {
                if spf[j] == 0 {
                    spf[j] = p
                    counts[P - 1] = counts[P - 1] + 1
                }
                j = j + step
            }
        }
        i = i + 1
    }
    i = 1
    while i < odd_len {
        if spf[i] == 0 {
            if P >= cap { return -1 }
            counts[P] = 1
            P = P + 1
            spf[i] = (2 * i + 1) as i32
        }
        i = i + 1
    }

    # M = next power of 2 >= P+1
    let mut M: i64 = 1
    while M < P + 1 {
        M = M << 1
    }
    let a: ptr<i64> = calloc(M, 8)
    if a == null { free(counts); free(spf); return -1 }
    a[0] = even_count % MOD
    a[1] = 1
    let mut idx: i64 = 2
    while idx <= P {
        a[idx] = (counts[idx - 1] as i64) % MOD
        idx = idx + 1
    }

    fwht(a, M)
    let mut total: i64 = 0
    idx = 0
    while idx < M {
        total = (total + modpow(a[idx], k, MOD)) % MOD
        idx = idx + 1
    }
    total = (total * modpow(M, MOD - 2, MOD)) % MOD

    free(a)
    free(counts)
    free(spf)
    return total
}

function main() -> i32 {
    printf("%lld\n", compute_L(10000000, 10000000))
    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 modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod);
void fwht_ptr_i64_i64(int64_t* a, int64_t n);
int64_t compute_L_i64_i64(int64_t n, int64_t k);
int32_t main(void);

static const int64_t MOD = 1000000007;

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 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;
}

void fwht_ptr_i64_i64(int64_t* a, int64_t n) {
    int64_t h = 1;
    while (h < n) {
        int64_t step = FLOW_CHECKED_SHL((h), (1));
        int64_t i = 0;
        while (i < n) {
            int64_t j = i;
            while (j < (i + h)) {
                int64_t x = a[j];
                int64_t y = a[(j + h)];
                int64_t s = (x + y);
                if (s >= MOD) {
                    s = (s - MOD);
                }
                int64_t d = (x - y);
                if (d < 0) {
                    d = (d + MOD);
                }
                a[j] = s;
                a[(j + h)] = d;
                j = (j + 1);
            }
            i = (i + step);
        }
        h = step;
    }
}

int64_t compute_L_i64_i64(int64_t n, int64_t k) {
    int64_t N = (n - 1);
    int64_t even_count = FLOW_CHECKED_DIV((N), (2));
    int64_t odd_len = FLOW_CHECKED_DIV(((N + 1)), (2));
    int32_t* spf = (int32_t*)(calloc(odd_len, 4));
    if (spf == NULL) {
        return (-1);
    }
    int64_t cap = 800000;
    int32_t* counts = (int32_t*)(calloc(cap, 4));
    if (counts == NULL) {
        free(spf);
        return (-1);
    }
    int64_t P = 1;
    int64_t limit = isqrt_i64(N);
    int64_t i_end = FLOW_CHECKED_DIV(((limit - 1)), (2));
    int64_t i = 1;
    while (i <= i_end) {
        if (spf[i] == 0) {
            int32_t p = ((int32_t)(((2 * i) + 1)));
            spf[i] = p;
            if (P >= cap) {
                return (-1);
            }
            counts[P] = 1;
            P = (P + 1);
            int64_t start = FLOW_CHECKED_DIV((((((int64_t)(p)) * ((int64_t)(p))) - 1)), (2));
            int64_t step = ((int64_t)(p));
            int64_t j = start;
            while (j < odd_len) {
                if (spf[j] == 0) {
                    spf[j] = p;
                    counts[(P - 1)] = (counts[(P - 1)] + 1);
                }
                j = (j + step);
            }
        }
        i = (i + 1);
    }
    i = 1;
    while (i < odd_len) {
        if (spf[i] == 0) {
            if (P >= cap) {
                return (-1);
            }
            counts[P] = 1;
            P = (P + 1);
            spf[i] = ((int32_t)(((2 * i) + 1)));
        }
        i = (i + 1);
    }
    int64_t M = 1;
    while (M < (P + 1)) {
        M = FLOW_CHECKED_SHL((M), (1));
    }
    int64_t* a = (int64_t*)(calloc(M, 8));
    if (a == NULL) {
        free(counts);
        free(spf);
        return (-1);
    }
    a[0] = FLOW_CHECKED_MOD((even_count), (MOD));
    a[1] = 1;
    int64_t idx = 2;
    while (idx <= P) {
        a[idx] = FLOW_CHECKED_MOD((((int64_t)(counts[(idx - 1)]))), (MOD));
        idx = (idx + 1);
    }
    fwht_ptr_i64_i64(a, M);
    int64_t total = 0;
    idx = 0;
    while (idx < M) {
        total = FLOW_CHECKED_MOD(((total + modpow_i64_i64_i64(a[idx], k, MOD))), (MOD));
        idx = (idx + 1);
    }
    total = FLOW_CHECKED_MOD(((total * modpow_i64_i64_i64(M, (MOD - 2), MOD))), (MOD));
    free(a);
    free(counts);
    free(spf);
    return total;
}

int32_t main(void) {
    printf("%lld\n", compute_L_i64_i64(10000000, 10000000));
    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) -> ()
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
  func.func @modpow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %175 = arith.constant 1 : i32
    %176 = arith.extsi %175 : i32 to i64
    %177 = llvm.mlir.constant(1 : i64) : i64
    %178 = llvm.alloca %177 x i64 : (i64) -> !llvm.ptr
    llvm.store %176, %178 : i64, !llvm.ptr
    %179 = arith.remsi %arg0, %arg2 : i64
    %180 = llvm.mlir.constant(1 : i64) : i64
    %181 = llvm.alloca %180 x i64 : (i64) -> !llvm.ptr
    llvm.store %179, %181 : i64, !llvm.ptr
    %182 = llvm.mlir.constant(1 : i64) : i64
    %183 = llvm.alloca %182 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %183 : i64, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %184 = llvm.load %183 : !llvm.ptr -> i64
    %185 = arith.constant 0 : i32
    %187 = arith.extsi %185 : i32 to i64
    %186 = arith.cmpi sgt, %184, %187 : i64
    cf.cond_br %186, ^bb43, ^bb44
    ^bb43:
      %188 = llvm.load %183 : !llvm.ptr -> i64
      %189 = arith.constant 1 : i32
      %191 = arith.extsi %189 : i32 to i64
      %190 = arith.andi %188, %191 : i64
      %192 = arith.constant 0 : i32
      %194 = arith.extsi %192 : i32 to i64
      %193 = arith.cmpi ne, %190, %194 : i64
      cf.cond_br %193, ^bb45, ^bb46
      ^bb45:
        %195 = llvm.load %178 : !llvm.ptr -> i64
        %196 = arith.extsi %195 : i64 to i128
        %197 = llvm.load %181 : !llvm.ptr -> i64
        %198 = arith.extsi %197 : i64 to i128
        %200 = arith.trunci %196 : i128 to i64
        %201 = arith.trunci %198 : i128 to i64
        %199 = arith.muli %200, %201 : i64
        %202 = arith.extsi %arg2 : i64 to i128
        %204 = arith.trunci %202 : i128 to i64
        %203 = arith.remsi %199, %204 : i64
        llvm.store %203, %178 : i64, !llvm.ptr
        cf.br ^bb47
      ^bb46:
        cf.br ^bb47
      ^bb47:
      %205 = llvm.load %181 : !llvm.ptr -> i64
      %206 = arith.extsi %205 : i64 to i128
      %207 = llvm.load %181 : !llvm.ptr -> i64
      %208 = arith.extsi %207 : i64 to i128
      %210 = arith.trunci %206 : i128 to i64
      %211 = arith.trunci %208 : i128 to i64
      %209 = arith.muli %210, %211 : i64
      %212 = arith.extsi %arg2 : i64 to i128
      %214 = arith.trunci %212 : i128 to i64
      %213 = arith.remsi %209, %214 : i64
      llvm.store %213, %181 : i64, !llvm.ptr
      %215 = llvm.load %183 : !llvm.ptr -> i64
      %216 = arith.constant 1 : i32
      %218 = arith.extsi %216 : i32 to i64
      %217 = arith.shrsi %215, %218 : i64
      llvm.store %217, %183 : i64, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    %219 = llvm.load %178 : !llvm.ptr -> i64
    func.return %219 : i64
  }
  func.func @fwht(%arg0: !llvm.ptr, %arg1: i64) -> () {
    %220 = arith.constant 1 : i32
    %221 = arith.extsi %220 : i32 to i64
    %222 = llvm.mlir.constant(1 : i64) : i64
    %223 = llvm.alloca %222 x i64 : (i64) -> !llvm.ptr
    llvm.store %221, %223 : i64, !llvm.ptr
    cf.br ^bb48
    ^bb48:
    %224 = llvm.load %223 : !llvm.ptr -> i64
    %225 = arith.cmpi slt, %224, %arg1 : i64
    cf.cond_br %225, ^bb49, ^bb50
    ^bb49:
      %226 = llvm.load %223 : !llvm.ptr -> i64
      %227 = arith.constant 1 : i32
      %229 = arith.extsi %227 : i32 to i64
      %228 = arith.shli %226, %229 : i64
      %230 = arith.constant 0 : i32
      %231 = arith.extsi %230 : i32 to i64
      %232 = llvm.mlir.constant(1 : i64) : i64
      %233 = llvm.alloca %232 x i64 : (i64) -> !llvm.ptr
      llvm.store %231, %233 : i64, !llvm.ptr
      cf.br ^bb51
      ^bb51:
      %234 = llvm.load %233 : !llvm.ptr -> i64
      %235 = arith.cmpi slt, %234, %arg1 : i64
      cf.cond_br %235, ^bb52, ^bb53
      ^bb52:
        %236 = llvm.load %233 : !llvm.ptr -> i64
        %237 = llvm.mlir.constant(1 : i64) : i64
        %238 = llvm.alloca %237 x i64 : (i64) -> !llvm.ptr
        llvm.store %236, %238 : i64, !llvm.ptr
        cf.br ^bb54
        ^bb54:
        %239 = llvm.load %238 : !llvm.ptr -> i64
        %240 = llvm.load %233 : !llvm.ptr -> i64
        %241 = llvm.load %223 : !llvm.ptr -> i64
        %242 = arith.addi %240, %241 : i64
        %243 = arith.cmpi slt, %239, %242 : i64
        cf.cond_br %243, ^bb55, ^bb56
        ^bb55:
          %245 = llvm.load %238 : !llvm.ptr -> i64
          %246 = llvm.getelementptr %arg0[%245] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %244 = llvm.load %246 : !llvm.ptr -> i64
          %248 = llvm.load %238 : !llvm.ptr -> i64
          %249 = llvm.load %223 : !llvm.ptr -> i64
          %250 = arith.addi %248, %249 : i64
          %251 = llvm.getelementptr %arg0[%250] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %247 = llvm.load %251 : !llvm.ptr -> i64
          %252 = arith.addi %244, %247 : i64
          %253 = llvm.mlir.constant(1 : i64) : i64
          %254 = llvm.alloca %253 x i64 : (i64) -> !llvm.ptr
          llvm.store %252, %254 : i64, !llvm.ptr
          %255 = llvm.load %254 : !llvm.ptr -> i64
          %256 = llvm.mlir.addressof @MOD : !llvm.ptr
          %257 = llvm.load %256 : !llvm.ptr -> i64
          %258 = arith.cmpi sge, %255, %257 : i64
          cf.cond_br %258, ^bb57, ^bb58
          ^bb57:
            %259 = llvm.load %254 : !llvm.ptr -> i64
            %260 = llvm.mlir.addressof @MOD : !llvm.ptr
            %261 = llvm.load %260 : !llvm.ptr -> i64
            %262 = arith.subi %259, %261 : i64
            llvm.store %262, %254 : i64, !llvm.ptr
            cf.br ^bb59
          ^bb58:
            cf.br ^bb59
          ^bb59:
          %263 = arith.subi %244, %247 : i64
          %264 = llvm.mlir.constant(1 : i64) : i64
          %265 = llvm.alloca %264 x i64 : (i64) -> !llvm.ptr
          llvm.store %263, %265 : i64, !llvm.ptr
          %266 = llvm.load %265 : !llvm.ptr -> i64
          %267 = arith.constant 0 : i32
          %269 = arith.extsi %267 : i32 to i64
          %268 = arith.cmpi slt, %266, %269 : i64
          cf.cond_br %268, ^bb60, ^bb61
          ^bb60:
            %270 = llvm.load %265 : !llvm.ptr -> i64
            %271 = llvm.mlir.addressof @MOD : !llvm.ptr
            %272 = llvm.load %271 : !llvm.ptr -> i64
            %273 = arith.addi %270, %272 : i64
            llvm.store %273, %265 : i64, !llvm.ptr
            cf.br ^bb62
          ^bb61:
            cf.br ^bb62
          ^bb62:
          %274 = llvm.load %254 : !llvm.ptr -> i64
          %275 = llvm.load %238 : !llvm.ptr -> i64
          %276 = llvm.getelementptr %arg0[%275] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %274, %276 : i64, !llvm.ptr
          %277 = llvm.load %265 : !llvm.ptr -> i64
          %278 = llvm.load %238 : !llvm.ptr -> i64
          %279 = llvm.load %223 : !llvm.ptr -> i64
          %280 = arith.addi %278, %279 : i64
          %281 = llvm.getelementptr %arg0[%280] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %277, %281 : i64, !llvm.ptr
          %282 = llvm.load %238 : !llvm.ptr -> i64
          %283 = arith.constant 1 : i32
          %285 = arith.extsi %283 : i32 to i64
          %284 = arith.addi %282, %285 : i64
          llvm.store %284, %238 : i64, !llvm.ptr
          cf.br ^bb54
        ^bb56:
        %286 = llvm.load %233 : !llvm.ptr -> i64
        %287 = arith.addi %286, %228 : i64
        llvm.store %287, %233 : i64, !llvm.ptr
        cf.br ^bb51
      ^bb53:
      llvm.store %228, %223 : i64, !llvm.ptr
      cf.br ^bb48
    ^bb50:
    func.return
  }
  func.func @compute_L(%arg0: i64, %arg1: i64) -> i64 {
    %288 = arith.constant 1 : i32
    %290 = arith.extsi %288 : i32 to i64
    %289 = arith.subi %arg0, %290 : i64
    %291 = arith.constant 2 : i32
    %293 = arith.extsi %291 : i32 to i64
    %292 = arith.divsi %289, %293 : i64
    %294 = arith.constant 1 : i32
    %296 = arith.extsi %294 : i32 to i64
    %295 = arith.addi %289, %296 : i64
    %297 = arith.constant 2 : i32
    %299 = arith.extsi %297 : i32 to i64
    %298 = arith.divsi %295, %299 : i64
    %301 = arith.constant 4 : i32
    %302 = arith.extsi %301 : i32 to i64
    %300 = func.call @calloc(%298, %302) : (i64, i64) -> !llvm.ptr
    %303 = llvm.mlir.zero : !llvm.ptr
    %304 = llvm.icmp "eq" %300, %303 : !llvm.ptr
    cf.cond_br %304, ^bb63, ^bb64
    ^bb63:
      %305 = arith.constant 1 : i32
      %307 = arith.constant 0 : i32
      %306 = arith.subi %307, %305 : i32
      %308 = arith.extsi %306 : i32 to i64
      func.return %308 : i64
    ^bb64:
      cf.br ^bb65
    ^bb65:
    %309 = arith.constant 800000 : i32
    %310 = arith.extsi %309 : i32 to i64
    %311 = llvm.mlir.constant(1 : i64) : i64
    %312 = llvm.alloca %311 x i64 : (i64) -> !llvm.ptr
    llvm.store %310, %312 : i64, !llvm.ptr
    %314 = llvm.load %312 : !llvm.ptr -> i64
    %315 = arith.constant 4 : i32
    %316 = arith.extsi %315 : i32 to i64
    %313 = func.call @calloc(%314, %316) : (i64, i64) -> !llvm.ptr
    %317 = llvm.mlir.zero : !llvm.ptr
    %318 = llvm.icmp "eq" %313, %317 : !llvm.ptr
    cf.cond_br %318, ^bb66, ^bb67
    ^bb66:
      func.call @free(%300) : (!llvm.ptr) -> ()
      %320 = arith.constant 1 : i32
      %322 = arith.constant 0 : i32
      %321 = arith.subi %322, %320 : i32
      %323 = arith.extsi %321 : i32 to i64
      func.return %323 : i64
    ^bb67:
      cf.br ^bb68
    ^bb68:
    %324 = arith.constant 1 : i32
    %325 = arith.extsi %324 : i32 to i64
    %326 = llvm.mlir.constant(1 : i64) : i64
    %327 = llvm.alloca %326 x i64 : (i64) -> !llvm.ptr
    llvm.store %325, %327 : i64, !llvm.ptr
    %328 = func.call @isqrt(%289) : (i64) -> i64
    %329 = arith.constant 1 : i32
    %331 = arith.extsi %329 : i32 to i64
    %330 = arith.subi %328, %331 : i64
    %332 = arith.constant 2 : i32
    %334 = arith.extsi %332 : i32 to i64
    %333 = arith.divsi %330, %334 : i64
    %335 = arith.constant 1 : i32
    %336 = arith.extsi %335 : i32 to i64
    %337 = llvm.mlir.constant(1 : i64) : i64
    %338 = llvm.alloca %337 x i64 : (i64) -> !llvm.ptr
    llvm.store %336, %338 : i64, !llvm.ptr
    cf.br ^bb69
    ^bb69:
    %339 = llvm.load %338 : !llvm.ptr -> i64
    %340 = arith.cmpi sle, %339, %333 : i64
    cf.cond_br %340, ^bb70, ^bb71
    ^bb70:
      %342 = llvm.load %338 : !llvm.ptr -> i64
      %343 = llvm.getelementptr %300[%342] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %341 = llvm.load %343 : !llvm.ptr -> i32
      %344 = arith.constant 0 : i32
      %345 = arith.cmpi eq, %341, %344 : i32
      cf.cond_br %345, ^bb72, ^bb73
      ^bb72:
        %346 = arith.constant 2 : i32
        %347 = llvm.load %338 : !llvm.ptr -> i64
        %349 = arith.extsi %346 : i32 to i64
        %348 = arith.muli %349, %347 : i64
        %350 = arith.constant 1 : i32
        %352 = arith.extsi %350 : i32 to i64
        %351 = arith.addi %348, %352 : i64
        %353 = arith.trunci %351 : i64 to i32
        %354 = llvm.load %338 : !llvm.ptr -> i64
        %355 = llvm.getelementptr %300[%354] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %353, %355 : i32, !llvm.ptr
        %356 = llvm.load %327 : !llvm.ptr -> i64
        %357 = llvm.load %312 : !llvm.ptr -> i64
        %358 = arith.cmpi sge, %356, %357 : i64
        cf.cond_br %358, ^bb75, ^bb76
        ^bb75:
          %359 = arith.constant 1 : i32
          %361 = arith.constant 0 : i32
          %360 = arith.subi %361, %359 : i32
          %362 = arith.extsi %360 : i32 to i64
          func.return %362 : i64
        ^bb76:
          cf.br ^bb77
        ^bb77:
        %363 = arith.constant 1 : i32
        %364 = llvm.load %327 : !llvm.ptr -> i64
        %365 = llvm.getelementptr %313[%364] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %363, %365 : i32, !llvm.ptr
        %366 = llvm.load %327 : !llvm.ptr -> i64
        %367 = arith.constant 1 : i32
        %369 = arith.extsi %367 : i32 to i64
        %368 = arith.addi %366, %369 : i64
        llvm.store %368, %327 : i64, !llvm.ptr
        %370 = arith.extsi %353 : i32 to i64
        %371 = arith.extsi %353 : i32 to i64
        %372 = arith.muli %370, %371 : i64
        %373 = arith.constant 1 : i32
        %375 = arith.extsi %373 : i32 to i64
        %374 = arith.subi %372, %375 : i64
        %376 = arith.constant 2 : i32
        %378 = arith.extsi %376 : i32 to i64
        %377 = arith.divsi %374, %378 : i64
        %379 = arith.extsi %353 : i32 to i64
        %380 = llvm.mlir.constant(1 : i64) : i64
        %381 = llvm.alloca %380 x i64 : (i64) -> !llvm.ptr
        llvm.store %377, %381 : i64, !llvm.ptr
        cf.br ^bb78
        ^bb78:
        %382 = llvm.load %381 : !llvm.ptr -> i64
        %383 = arith.cmpi slt, %382, %298 : i64
        cf.cond_br %383, ^bb79, ^bb80
        ^bb79:
          %385 = llvm.load %381 : !llvm.ptr -> i64
          %386 = llvm.getelementptr %300[%385] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          %384 = llvm.load %386 : !llvm.ptr -> i32
          %387 = arith.constant 0 : i32
          %388 = arith.cmpi eq, %384, %387 : i32
          cf.cond_br %388, ^bb81, ^bb82
          ^bb81:
            %389 = llvm.load %381 : !llvm.ptr -> i64
            %390 = llvm.getelementptr %300[%389] : (!llvm.ptr, i64) -> !llvm.ptr, i32
            llvm.store %353, %390 : i32, !llvm.ptr
            %392 = llvm.load %327 : !llvm.ptr -> i64
            %393 = arith.constant 1 : i32
            %395 = arith.extsi %393 : i32 to i64
            %394 = arith.subi %392, %395 : i64
            %396 = llvm.getelementptr %313[%394] : (!llvm.ptr, i64) -> !llvm.ptr, i32
            %391 = llvm.load %396 : !llvm.ptr -> i32
            %397 = arith.constant 1 : i32
            %398 = arith.addi %391, %397 : i32
            %399 = llvm.load %327 : !llvm.ptr -> i64
            %400 = arith.constant 1 : i32
            %402 = arith.extsi %400 : i32 to i64
            %401 = arith.subi %399, %402 : i64
            %403 = llvm.getelementptr %313[%401] : (!llvm.ptr, i64) -> !llvm.ptr, i32
            llvm.store %398, %403 : i32, !llvm.ptr
            cf.br ^bb83
          ^bb82:
            cf.br ^bb83
          ^bb83:
          %404 = llvm.load %381 : !llvm.ptr -> i64
          %405 = arith.addi %404, %379 : i64
          llvm.store %405, %381 : i64, !llvm.ptr
          cf.br ^bb78
        ^bb80:
        cf.br ^bb74
      ^bb73:
        cf.br ^bb74
      ^bb74:
      %406 = llvm.load %338 : !llvm.ptr -> i64
      %407 = arith.constant 1 : i32
      %409 = arith.extsi %407 : i32 to i64
      %408 = arith.addi %406, %409 : i64
      llvm.store %408, %338 : i64, !llvm.ptr
      cf.br ^bb69
    ^bb71:
    %410 = arith.constant 1 : i32
    %411 = arith.extsi %410 : i32 to i64
    llvm.store %411, %338 : i64, !llvm.ptr
    cf.br ^bb84
    ^bb84:
    %412 = llvm.load %338 : !llvm.ptr -> i64
    %413 = arith.cmpi slt, %412, %298 : i64
    cf.cond_br %413, ^bb85, ^bb86
    ^bb85:
      %415 = llvm.load %338 : !llvm.ptr -> i64
      %416 = llvm.getelementptr %300[%415] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %414 = llvm.load %416 : !llvm.ptr -> i32
      %417 = arith.constant 0 : i32
      %418 = arith.cmpi eq, %414, %417 : i32
      cf.cond_br %418, ^bb87, ^bb88
      ^bb87:
        %419 = llvm.load %327 : !llvm.ptr -> i64
        %420 = llvm.load %312 : !llvm.ptr -> i64
        %421 = arith.cmpi sge, %419, %420 : i64
        cf.cond_br %421, ^bb90, ^bb91
        ^bb90:
          %422 = arith.constant 1 : i32
          %424 = arith.constant 0 : i32
          %423 = arith.subi %424, %422 : i32
          %425 = arith.extsi %423 : i32 to i64
          func.return %425 : i64
        ^bb91:
          cf.br ^bb92
        ^bb92:
        %426 = arith.constant 1 : i32
        %427 = llvm.load %327 : !llvm.ptr -> i64
        %428 = llvm.getelementptr %313[%427] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %426, %428 : i32, !llvm.ptr
        %429 = llvm.load %327 : !llvm.ptr -> i64
        %430 = arith.constant 1 : i32
        %432 = arith.extsi %430 : i32 to i64
        %431 = arith.addi %429, %432 : i64
        llvm.store %431, %327 : i64, !llvm.ptr
        %433 = arith.constant 2 : i32
        %434 = llvm.load %338 : !llvm.ptr -> i64
        %436 = arith.extsi %433 : i32 to i64
        %435 = arith.muli %436, %434 : i64
        %437 = arith.constant 1 : i32
        %439 = arith.extsi %437 : i32 to i64
        %438 = arith.addi %435, %439 : i64
        %440 = arith.trunci %438 : i64 to i32
        %441 = llvm.load %338 : !llvm.ptr -> i64
        %442 = llvm.getelementptr %300[%441] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %440, %442 : i32, !llvm.ptr
        cf.br ^bb89
      ^bb88:
        cf.br ^bb89
      ^bb89:
      %443 = llvm.load %338 : !llvm.ptr -> i64
      %444 = arith.constant 1 : i32
      %446 = arith.extsi %444 : i32 to i64
      %445 = arith.addi %443, %446 : i64
      llvm.store %445, %338 : i64, !llvm.ptr
      cf.br ^bb84
    ^bb86:
    %447 = arith.constant 1 : i32
    %448 = arith.extsi %447 : i32 to i64
    %449 = llvm.mlir.constant(1 : i64) : i64
    %450 = llvm.alloca %449 x i64 : (i64) -> !llvm.ptr
    llvm.store %448, %450 : i64, !llvm.ptr
    cf.br ^bb93
    ^bb93:
    %451 = llvm.load %450 : !llvm.ptr -> i64
    %452 = llvm.load %327 : !llvm.ptr -> i64
    %453 = arith.constant 1 : i32
    %455 = arith.extsi %453 : i32 to i64
    %454 = arith.addi %452, %455 : i64
    %456 = arith.cmpi slt, %451, %454 : i64
    cf.cond_br %456, ^bb94, ^bb95
    ^bb94:
      %457 = llvm.load %450 : !llvm.ptr -> i64
      %458 = arith.constant 1 : i32
      %460 = arith.extsi %458 : i32 to i64
      %459 = arith.shli %457, %460 : i64
      llvm.store %459, %450 : i64, !llvm.ptr
      cf.br ^bb93
    ^bb95:
    %462 = llvm.load %450 : !llvm.ptr -> i64
    %463 = arith.constant 8 : i32
    %464 = arith.extsi %463 : i32 to i64
    %461 = func.call @calloc(%462, %464) : (i64, i64) -> !llvm.ptr
    %465 = llvm.mlir.zero : !llvm.ptr
    %466 = llvm.icmp "eq" %461, %465 : !llvm.ptr
    cf.cond_br %466, ^bb96, ^bb97
    ^bb96:
      func.call @free(%313) : (!llvm.ptr) -> ()
      func.call @free(%300) : (!llvm.ptr) -> ()
      %469 = arith.constant 1 : i32
      %471 = arith.constant 0 : i32
      %470 = arith.subi %471, %469 : i32
      %472 = arith.extsi %470 : i32 to i64
      func.return %472 : i64
    ^bb97:
      cf.br ^bb98
    ^bb98:
    %473 = llvm.mlir.addressof @MOD : !llvm.ptr
    %474 = llvm.load %473 : !llvm.ptr -> i64
    %475 = arith.remsi %292, %474 : i64
    %476 = arith.constant 0 : i32
    %477 = arith.extsi %476 : i32 to i64
    %478 = llvm.getelementptr %461[%477] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %475, %478 : i64, !llvm.ptr
    %479 = arith.constant 1 : i32
    %480 = arith.constant 1 : i32
    %481 = arith.extsi %479 : i32 to i64
    %482 = arith.extsi %480 : i32 to i64
    %483 = llvm.getelementptr %461[%482] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %481, %483 : i64, !llvm.ptr
    %484 = arith.constant 2 : i32
    %485 = arith.extsi %484 : i32 to i64
    %486 = llvm.mlir.constant(1 : i64) : i64
    %487 = llvm.alloca %486 x i64 : (i64) -> !llvm.ptr
    llvm.store %485, %487 : i64, !llvm.ptr
    cf.br ^bb99
    ^bb99:
    %488 = llvm.load %487 : !llvm.ptr -> i64
    %489 = llvm.load %327 : !llvm.ptr -> i64
    %490 = arith.cmpi sle, %488, %489 : i64
    cf.cond_br %490, ^bb100, ^bb101
    ^bb100:
      %492 = llvm.load %487 : !llvm.ptr -> i64
      %493 = arith.constant 1 : i32
      %495 = arith.extsi %493 : i32 to i64
      %494 = arith.subi %492, %495 : i64
      %496 = llvm.getelementptr %313[%494] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %491 = llvm.load %496 : !llvm.ptr -> i32
      %497 = arith.extsi %491 : i32 to i64
      %498 = llvm.mlir.addressof @MOD : !llvm.ptr
      %499 = llvm.load %498 : !llvm.ptr -> i64
      %500 = arith.remsi %497, %499 : i64
      %501 = llvm.load %487 : !llvm.ptr -> i64
      %502 = llvm.getelementptr %461[%501] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %500, %502 : i64, !llvm.ptr
      %503 = llvm.load %487 : !llvm.ptr -> i64
      %504 = arith.constant 1 : i32
      %506 = arith.extsi %504 : i32 to i64
      %505 = arith.addi %503, %506 : i64
      llvm.store %505, %487 : i64, !llvm.ptr
      cf.br ^bb99
    ^bb101:
    %508 = llvm.load %450 : !llvm.ptr -> i64
    func.call @fwht(%461, %508) : (!llvm.ptr, i64) -> ()
    %509 = arith.constant 0 : i32
    %510 = arith.extsi %509 : i32 to i64
    %511 = llvm.mlir.constant(1 : i64) : i64
    %512 = llvm.alloca %511 x i64 : (i64) -> !llvm.ptr
    llvm.store %510, %512 : i64, !llvm.ptr
    %513 = arith.constant 0 : i32
    %514 = arith.extsi %513 : i32 to i64
    llvm.store %514, %487 : i64, !llvm.ptr
    cf.br ^bb102
    ^bb102:
    %515 = llvm.load %487 : !llvm.ptr -> i64
    %516 = llvm.load %450 : !llvm.ptr -> i64
    %517 = arith.cmpi slt, %515, %516 : i64
    cf.cond_br %517, ^bb103, ^bb104
    ^bb103:
      %518 = llvm.load %512 : !llvm.ptr -> i64
      %521 = llvm.load %487 : !llvm.ptr -> i64
      %522 = llvm.getelementptr %461[%521] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %520 = llvm.load %522 : !llvm.ptr -> i64
      %523 = llvm.mlir.addressof @MOD : !llvm.ptr
      %524 = llvm.load %523 : !llvm.ptr -> i64
      %519 = func.call @modpow(%520, %arg1, %524) : (i64, i64, i64) -> i64
      %525 = arith.addi %518, %519 : i64
      %526 = llvm.mlir.addressof @MOD : !llvm.ptr
      %527 = llvm.load %526 : !llvm.ptr -> i64
      %528 = arith.remsi %525, %527 : i64
      llvm.store %528, %512 : i64, !llvm.ptr
      %529 = llvm.load %487 : !llvm.ptr -> i64
      %530 = arith.constant 1 : i32
      %532 = arith.extsi %530 : i32 to i64
      %531 = arith.addi %529, %532 : i64
      llvm.store %531, %487 : i64, !llvm.ptr
      cf.br ^bb102
    ^bb104:
    %533 = llvm.load %512 : !llvm.ptr -> i64
    %535 = llvm.load %450 : !llvm.ptr -> i64
    %536 = llvm.mlir.addressof @MOD : !llvm.ptr
    %537 = llvm.load %536 : !llvm.ptr -> i64
    %538 = arith.constant 2 : i32
    %540 = arith.extsi %538 : i32 to i64
    %539 = arith.subi %537, %540 : i64
    %541 = llvm.mlir.addressof @MOD : !llvm.ptr
    %542 = llvm.load %541 : !llvm.ptr -> i64
    %534 = func.call @modpow(%535, %539, %542) : (i64, i64, i64) -> i64
    %543 = arith.muli %533, %534 : i64
    %544 = llvm.mlir.addressof @MOD : !llvm.ptr
    %545 = llvm.load %544 : !llvm.ptr -> i64
    %546 = arith.remsi %543, %545 : i64
    llvm.store %546, %512 : i64, !llvm.ptr
    func.call @free(%461) : (!llvm.ptr) -> ()
    func.call @free(%313) : (!llvm.ptr) -> ()
    func.call @free(%300) : (!llvm.ptr) -> ()
    %550 = llvm.load %512 : !llvm.ptr -> i64
    func.return %550 : i64
  }
  func.func @main() -> i32 {
    %551 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %553 = arith.constant 10000000 : i32
    %554 = arith.constant 10000000 : i32
    %555 = arith.extsi %553 : i32 to i64
    %556 = arith.extsi %554 : i32 to i64
    %552 = func.call @compute_L(%555, %556) : (i64, i64) -> i64
    %557 = llvm.call @printf(%551, %552) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %558 = arith.constant 0 : i32
    func.return %558 : i32
  }
}