Problem 304

Sum F(p) mod 1234567891011 for first 100000 primes p > 10^14.

Answer283988410192
Output283988410192
StatusPASS
Native helperno
Runtime6290 ms
Peak memory1104 KB
Time complexityO(n) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n)?
Space complexityO(1)?
ApproachFlow solutionNot curated
VerdictUnknown

Flow source

# Project Euler 304
# Sum F(p) mod 1234567891011 for first 100000 primes p > 10^14.

function mulmod(a0: i64, b0: i64, mod: i64) -> i64 {
    let mut a: i64 = a0 % mod
    if a < 0 { a = a + mod }
    let mut b: i64 = b0 % mod
    if b < 0 { b = b + mod }
    let mut r: i64 = 0
    while b > 0 {
        if (b & 1) == 1 {
            r = r + a
            if r >= mod { r = r - mod }
        }
        a = a * 2
        if a >= mod { a = a - mod }
        b = b >> 1
    }
    return r
}

function modpow(base: i64, exp: i64, mod: i64) -> i64 {
    let mut r: i64 = 1
    let mut b: i64 = base % mod
    let mut e: i64 = exp
    while e > 0 {
        if (e & 1) == 1 { r = mulmod(r, b, mod) }
        b = mulmod(b, b, mod)
        e = e >> 1
    }
    return r
}

function is_prime(p: i64) -> bool {
    if p < 2 { return false }
    if p % 2 == 0 { return p == 2 }
    if p % 3 == 0 { return p == 3 }
    if p % 5 == 0 { return p == 5 }
    if p % 7 == 0 { return p == 7 }
    if p % 11 == 0 { return p == 11 }
    if p % 13 == 0 { return p == 13 }
    if p % 17 == 0 { return p == 17 }
    let mut d: i64 = p - 1
    let mut shift: i32 = 0
    while (d & 1) == 0 {
        d = d >> 1
        shift = shift + 1
    }
    # bases for 64-bit
    # fixed arrays may fail — use sequential checks
    let mut bi: i32 = 0
    while bi < 7 {
        let base: i64 = 0
        match bi {
            0 => { base = 2 }
            1 => { base = 325 }
            2 => { base = 9375 }
            3 => { base = 28178 }
            4 => { base = 450775 }
            5 => { base = 9780504 }
            _ => { base = 1795265022 }
        }
        let a: i64 = base % p
        if a == 0 {
            bi = bi + 1
            continue
        }
        let mut x: i64 = modpow(a, d, p)
        if x == 1 || x == p - 1 {
            bi = bi + 1
            continue
        }
        let mut ok: bool = false
        let mut r: i32 = 0
        while r < shift - 1 {
            x = mulmod(x, x, p)
            if x == p - 1 {
                ok = true
                break
            }
            if x == 1 { return false }
            r = r + 1
        }
        if !ok { return false }
        bi = bi + 1
    }
    return true
}

function fibonacci(n0: i64, mod: i64) -> i64 {
    if n0 == 0 { return 0 }
    # find top bit
    let mut bit: i64 = 1
    while bit <= n0 / 2 {
        bit = bit << 1
    }
    let mut a: i64 = 0
    let mut b: i64 = 1
    while bit > 0 {
        let next_a: i64 = mulmod(a, (2 * b - a + mod) % mod, mod)
        b = (mulmod(a, a, mod) + mulmod(b, b, mod)) % mod
        a = next_a
        if (n0 & bit) != 0 {
            let na: i64 = b
            b = (a + b) % mod
            a = na
        }
        bit = bit >> 1
    }
    return a
}

function main() -> i32 {
    let mod: i64 = 1234567891011
    let mut n: i64 = 100000000000000
    let mut last: i64 = fibonacci(n - 1, mod)
    let mut current: i64 = fibonacci(n, mod)
    let mut total: i64 = 0
    let mut count: i64 = 0
    while count < 100000 {
        n = n + 1
        let next_v: i64 = (last + current) % mod
        last = current
        current = next_v
        if is_prime(n) {
            total = (total + current) % mod
            count = count + 1
        }
    }
    printf("%lld\n", total)
    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 mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t modpow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t p);
int64_t fibonacci_i64_i64(int64_t n0, int64_t mod);
int32_t main(void);

int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod) {
    int64_t a = FLOW_CHECKED_MOD((a0), (mod));
    if (a < 0) {
        a = (a + mod);
    }
    int64_t b = FLOW_CHECKED_MOD((b0), (mod));
    if (b < 0) {
        b = (b + mod);
    }
    int64_t r = 0;
    while (b > 0) {
        if ((b & 1) == 1) {
            r = (r + a);
            if (r >= mod) {
                r = (r - mod);
            }
        }
        a = (a * 2);
        if (a >= mod) {
            a = (a - mod);
        }
        b = FLOW_CHECKED_SHR((b), (1));
    }
    return r;
}

int64_t modpow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
    int64_t r = 1;
    int64_t b = FLOW_CHECKED_MOD((base), (mod));
    int64_t e = exp;
    while (e > 0) {
        if ((e & 1) == 1) {
            r = mulmod_i64_i64_i64(r, b, mod);
        }
        b = mulmod_i64_i64_i64(b, b, mod);
        e = FLOW_CHECKED_SHR((e), (1));
    }
    return r;
}

bool is_prime_i64(int64_t p) {
    if (p < 2) {
        return 0;
    }
    if (FLOW_CHECKED_MOD((p), (2)) == 0) {
        return p == 2;
    }
    if (FLOW_CHECKED_MOD((p), (3)) == 0) {
        return p == 3;
    }
    if (FLOW_CHECKED_MOD((p), (5)) == 0) {
        return p == 5;
    }
    if (FLOW_CHECKED_MOD((p), (7)) == 0) {
        return p == 7;
    }
    if (FLOW_CHECKED_MOD((p), (11)) == 0) {
        return p == 11;
    }
    if (FLOW_CHECKED_MOD((p), (13)) == 0) {
        return p == 13;
    }
    if (FLOW_CHECKED_MOD((p), (17)) == 0) {
        return p == 17;
    }
    int64_t d = (p - 1);
    int32_t shift = 0;
    while ((d & 1) == 0) {
        d = FLOW_CHECKED_SHR((d), (1));
        shift = (shift + 1);
    }
    int32_t bi = 0;
    while (bi < 7) {
        int64_t base = 0;
        { // match block
            if ((bi) == 0) {
                base = 2;
            } else if ((bi) == 1) {
                base = 325;
            } else if ((bi) == 2) {
                base = 9375;
            } else if ((bi) == 3) {
                base = 28178;
            } else if ((bi) == 4) {
                base = 450775;
            } else if ((bi) == 5) {
                base = 9780504;
            } else { // exhaustive
                base = 1795265022;
            }
        } // end match
        int64_t a = FLOW_CHECKED_MOD((base), (p));
        if (a == 0) {
            bi = (bi + 1);
            continue;
        }
        int64_t x = modpow_i64_i64_i64(a, d, p);
        if ((x == 1 || x == (p - 1))) {
            bi = (bi + 1);
            continue;
        }
        bool ok = 0;
        int32_t r = 0;
        while (r < (shift - 1)) {
            x = mulmod_i64_i64_i64(x, x, p);
            if (x == (p - 1)) {
                ok = 1;
                break;
            }
            if (x == 1) {
                return 0;
            }
            r = (r + 1);
        }
        if ((!(ok))) {
            return 0;
        }
        bi = (bi + 1);
    }
    return 1;
}

int64_t fibonacci_i64_i64(int64_t n0, int64_t mod) {
    if (n0 == 0) {
        return 0;
    }
    int64_t bit = 1;
    while (bit <= FLOW_CHECKED_DIV((n0), (2))) {
        bit = FLOW_CHECKED_SHL((bit), (1));
    }
    int64_t a = 0;
    int64_t b = 1;
    while (bit > 0) {
        int64_t next_a = mulmod_i64_i64_i64(a, FLOW_CHECKED_MOD(((((2 * b) - a) + mod)), (mod)), mod);
        b = FLOW_CHECKED_MOD(((mulmod_i64_i64_i64(a, a, mod) + mulmod_i64_i64_i64(b, b, mod))), (mod));
        a = next_a;
        if ((n0 & bit) != 0) {
            int64_t na = b;
            b = FLOW_CHECKED_MOD(((a + b)), (mod));
            a = na;
        }
        bit = FLOW_CHECKED_SHR((bit), (1));
    }
    return a;
}

int32_t main(void) {
    int64_t mod = 1234567891011;
    int64_t n = 100000000000000;
    int64_t last = fibonacci_i64_i64((n - 1), mod);
    int64_t current = fibonacci_i64_i64(n, mod);
    int64_t total = 0;
    int64_t count = 0;
    while (count < 100000) {
        n = (n + 1);
        int64_t next_v = FLOW_CHECKED_MOD(((last + current)), (mod));
        last = current;
        current = next_v;
        if (is_prime_i64(n)) {
            total = FLOW_CHECKED_MOD(((total + current)), (mod));
            count = (count + 1);
        }
    }
    printf("%lld\n", total);
    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 @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %0 = arith.remsi %arg0, %arg2 : i64
    %1 = llvm.mlir.constant(1 : i64) : i64
    %2 = llvm.alloca %1 x i64 : (i64) -> !llvm.ptr
    llvm.store %0, %2 : i64, !llvm.ptr
    %3 = llvm.load %2 : !llvm.ptr -> i64
    %4 = arith.constant 0 : i32
    %6 = arith.extsi %4 : i32 to i64
    %5 = arith.cmpi slt, %3, %6 : i64
    cf.cond_br %5, ^bb0, ^bb1
    ^bb0:
      %7 = llvm.load %2 : !llvm.ptr -> i64
      %8 = arith.addi %7, %arg2 : i64
      llvm.store %8, %2 : i64, !llvm.ptr
      cf.br ^bb2
    ^bb1:
      cf.br ^bb2
    ^bb2:
    %9 = arith.remsi %arg1, %arg2 : i64
    %10 = llvm.mlir.constant(1 : i64) : i64
    %11 = llvm.alloca %10 x i64 : (i64) -> !llvm.ptr
    llvm.store %9, %11 : i64, !llvm.ptr
    %12 = llvm.load %11 : !llvm.ptr -> i64
    %13 = arith.constant 0 : i32
    %15 = arith.extsi %13 : i32 to i64
    %14 = arith.cmpi slt, %12, %15 : i64
    cf.cond_br %14, ^bb3, ^bb4
    ^bb3:
      %16 = llvm.load %11 : !llvm.ptr -> i64
      %17 = arith.addi %16, %arg2 : i64
      llvm.store %17, %11 : i64, !llvm.ptr
      cf.br ^bb5
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %18 = arith.constant 0 : i32
    %19 = arith.extsi %18 : i32 to i64
    %20 = llvm.mlir.constant(1 : i64) : i64
    %21 = llvm.alloca %20 x i64 : (i64) -> !llvm.ptr
    llvm.store %19, %21 : i64, !llvm.ptr
    cf.br ^bb6
    ^bb6:
    %22 = llvm.load %11 : !llvm.ptr -> i64
    %23 = arith.constant 0 : i32
    %25 = arith.extsi %23 : i32 to i64
    %24 = arith.cmpi sgt, %22, %25 : i64
    cf.cond_br %24, ^bb7, ^bb8
    ^bb7:
      %26 = llvm.load %11 : !llvm.ptr -> i64
      %27 = arith.constant 1 : i32
      %29 = arith.extsi %27 : i32 to i64
      %28 = arith.andi %26, %29 : i64
      %30 = arith.constant 1 : i32
      %32 = arith.extsi %30 : i32 to i64
      %31 = arith.cmpi eq, %28, %32 : i64
      cf.cond_br %31, ^bb9, ^bb10
      ^bb9:
        %33 = llvm.load %21 : !llvm.ptr -> i64
        %34 = llvm.load %2 : !llvm.ptr -> i64
        %35 = arith.addi %33, %34 : i64
        llvm.store %35, %21 : i64, !llvm.ptr
        %36 = llvm.load %21 : !llvm.ptr -> i64
        %37 = arith.cmpi sge, %36, %arg2 : i64
        cf.cond_br %37, ^bb12, ^bb13
        ^bb12:
          %38 = llvm.load %21 : !llvm.ptr -> i64
          %39 = arith.subi %38, %arg2 : i64
          llvm.store %39, %21 : i64, !llvm.ptr
          cf.br ^bb14
        ^bb13:
          cf.br ^bb14
        ^bb14:
        cf.br ^bb11
      ^bb10:
        cf.br ^bb11
      ^bb11:
      %40 = llvm.load %2 : !llvm.ptr -> i64
      %41 = arith.constant 2 : i32
      %43 = arith.extsi %41 : i32 to i64
      %42 = arith.muli %40, %43 : i64
      llvm.store %42, %2 : i64, !llvm.ptr
      %44 = llvm.load %2 : !llvm.ptr -> i64
      %45 = arith.cmpi sge, %44, %arg2 : i64
      cf.cond_br %45, ^bb15, ^bb16
      ^bb15:
        %46 = llvm.load %2 : !llvm.ptr -> i64
        %47 = arith.subi %46, %arg2 : i64
        llvm.store %47, %2 : i64, !llvm.ptr
        cf.br ^bb17
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %48 = llvm.load %11 : !llvm.ptr -> i64
      %49 = arith.constant 1 : i32
      %51 = arith.extsi %49 : i32 to i64
      %50 = arith.shrsi %48, %51 : i64
      llvm.store %50, %11 : i64, !llvm.ptr
      cf.br ^bb6
    ^bb8:
    %52 = llvm.load %21 : !llvm.ptr -> i64
    func.return %52 : i64
  }
  func.func @modpow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %53 = arith.constant 1 : i32
    %54 = arith.extsi %53 : i32 to i64
    %55 = llvm.mlir.constant(1 : i64) : i64
    %56 = llvm.alloca %55 x i64 : (i64) -> !llvm.ptr
    llvm.store %54, %56 : i64, !llvm.ptr
    %57 = arith.remsi %arg0, %arg2 : i64
    %58 = llvm.mlir.constant(1 : i64) : i64
    %59 = llvm.alloca %58 x i64 : (i64) -> !llvm.ptr
    llvm.store %57, %59 : i64, !llvm.ptr
    %60 = llvm.mlir.constant(1 : i64) : i64
    %61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %61 : i64, !llvm.ptr
    cf.br ^bb18
    ^bb18:
    %62 = llvm.load %61 : !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, ^bb19, ^bb20
    ^bb19:
      %66 = llvm.load %61 : !llvm.ptr -> i64
      %67 = arith.constant 1 : i32
      %69 = arith.extsi %67 : i32 to i64
      %68 = arith.andi %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, ^bb21, ^bb22
      ^bb21:
        %74 = llvm.load %56 : !llvm.ptr -> i64
        %75 = llvm.load %59 : !llvm.ptr -> i64
        %73 = func.call @mulmod(%74, %75, %arg2) : (i64, i64, i64) -> i64
        llvm.store %73, %56 : i64, !llvm.ptr
        cf.br ^bb23
      ^bb22:
        cf.br ^bb23
      ^bb23:
      %77 = llvm.load %59 : !llvm.ptr -> i64
      %78 = llvm.load %59 : !llvm.ptr -> i64
      %76 = func.call @mulmod(%77, %78, %arg2) : (i64, i64, i64) -> i64
      llvm.store %76, %59 : i64, !llvm.ptr
      %79 = llvm.load %61 : !llvm.ptr -> i64
      %80 = arith.constant 1 : i32
      %82 = arith.extsi %80 : i32 to i64
      %81 = arith.shrsi %79, %82 : i64
      llvm.store %81, %61 : i64, !llvm.ptr
      cf.br ^bb18
    ^bb20:
    %83 = llvm.load %56 : !llvm.ptr -> i64
    func.return %83 : i64
  }
  func.func @is_prime(%arg0: i64) -> i1 {
    %84 = arith.constant 2 : i32
    %86 = arith.extsi %84 : i32 to i64
    %85 = arith.cmpi slt, %arg0, %86 : i64
    cf.cond_br %85, ^bb24, ^bb25
    ^bb24:
      %87 = arith.constant 0 : i1
      func.return %87 : i1
    ^bb25:
      cf.br ^bb26
    ^bb26:
    %88 = arith.constant 2 : i32
    %90 = arith.extsi %88 : i32 to i64
    %89 = arith.remsi %arg0, %90 : i64
    %91 = arith.constant 0 : i32
    %93 = arith.extsi %91 : i32 to i64
    %92 = arith.cmpi eq, %89, %93 : i64
    cf.cond_br %92, ^bb27, ^bb28
    ^bb27:
      %94 = arith.constant 2 : i32
      %96 = arith.extsi %94 : i32 to i64
      %95 = arith.cmpi eq, %arg0, %96 : i64
      func.return %95 : i1
    ^bb28:
      cf.br ^bb29
    ^bb29:
    %97 = arith.constant 3 : i32
    %99 = arith.extsi %97 : i32 to i64
    %98 = arith.remsi %arg0, %99 : i64
    %100 = arith.constant 0 : i32
    %102 = arith.extsi %100 : i32 to i64
    %101 = arith.cmpi eq, %98, %102 : i64
    cf.cond_br %101, ^bb30, ^bb31
    ^bb30:
      %103 = arith.constant 3 : i32
      %105 = arith.extsi %103 : i32 to i64
      %104 = arith.cmpi eq, %arg0, %105 : i64
      func.return %104 : i1
    ^bb31:
      cf.br ^bb32
    ^bb32:
    %106 = arith.constant 5 : i32
    %108 = arith.extsi %106 : i32 to i64
    %107 = arith.remsi %arg0, %108 : i64
    %109 = arith.constant 0 : i32
    %111 = arith.extsi %109 : i32 to i64
    %110 = arith.cmpi eq, %107, %111 : i64
    cf.cond_br %110, ^bb33, ^bb34
    ^bb33:
      %112 = arith.constant 5 : i32
      %114 = arith.extsi %112 : i32 to i64
      %113 = arith.cmpi eq, %arg0, %114 : i64
      func.return %113 : i1
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %115 = arith.constant 7 : i32
    %117 = arith.extsi %115 : i32 to i64
    %116 = arith.remsi %arg0, %117 : i64
    %118 = arith.constant 0 : i32
    %120 = arith.extsi %118 : i32 to i64
    %119 = arith.cmpi eq, %116, %120 : i64
    cf.cond_br %119, ^bb36, ^bb37
    ^bb36:
      %121 = arith.constant 7 : i32
      %123 = arith.extsi %121 : i32 to i64
      %122 = arith.cmpi eq, %arg0, %123 : i64
      func.return %122 : i1
    ^bb37:
      cf.br ^bb38
    ^bb38:
    %124 = arith.constant 11 : i32
    %126 = arith.extsi %124 : i32 to i64
    %125 = arith.remsi %arg0, %126 : i64
    %127 = arith.constant 0 : i32
    %129 = arith.extsi %127 : i32 to i64
    %128 = arith.cmpi eq, %125, %129 : i64
    cf.cond_br %128, ^bb39, ^bb40
    ^bb39:
      %130 = arith.constant 11 : i32
      %132 = arith.extsi %130 : i32 to i64
      %131 = arith.cmpi eq, %arg0, %132 : i64
      func.return %131 : i1
    ^bb40:
      cf.br ^bb41
    ^bb41:
    %133 = arith.constant 13 : i32
    %135 = arith.extsi %133 : i32 to i64
    %134 = arith.remsi %arg0, %135 : i64
    %136 = arith.constant 0 : i32
    %138 = arith.extsi %136 : i32 to i64
    %137 = arith.cmpi eq, %134, %138 : i64
    cf.cond_br %137, ^bb42, ^bb43
    ^bb42:
      %139 = arith.constant 13 : i32
      %141 = arith.extsi %139 : i32 to i64
      %140 = arith.cmpi eq, %arg0, %141 : i64
      func.return %140 : i1
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %142 = arith.constant 17 : i32
    %144 = arith.extsi %142 : i32 to i64
    %143 = arith.remsi %arg0, %144 : i64
    %145 = arith.constant 0 : i32
    %147 = arith.extsi %145 : i32 to i64
    %146 = arith.cmpi eq, %143, %147 : i64
    cf.cond_br %146, ^bb45, ^bb46
    ^bb45:
      %148 = arith.constant 17 : i32
      %150 = arith.extsi %148 : i32 to i64
      %149 = arith.cmpi eq, %arg0, %150 : i64
      func.return %149 : i1
    ^bb46:
      cf.br ^bb47
    ^bb47:
    %151 = arith.constant 1 : i32
    %153 = arith.extsi %151 : i32 to i64
    %152 = arith.subi %arg0, %153 : i64
    %154 = llvm.mlir.constant(1 : i64) : i64
    %155 = llvm.alloca %154 x i64 : (i64) -> !llvm.ptr
    llvm.store %152, %155 : i64, !llvm.ptr
    %156 = arith.constant 0 : i32
    %157 = llvm.mlir.constant(1 : i64) : i64
    %158 = llvm.alloca %157 x i32 : (i64) -> !llvm.ptr
    llvm.store %156, %158 : i32, !llvm.ptr
    cf.br ^bb48
    ^bb48:
    %159 = llvm.load %155 : !llvm.ptr -> i64
    %160 = arith.constant 1 : i32
    %162 = arith.extsi %160 : i32 to i64
    %161 = arith.andi %159, %162 : i64
    %163 = arith.constant 0 : i32
    %165 = arith.extsi %163 : i32 to i64
    %164 = arith.cmpi eq, %161, %165 : i64
    cf.cond_br %164, ^bb49, ^bb50
    ^bb49:
      %166 = llvm.load %155 : !llvm.ptr -> i64
      %167 = arith.constant 1 : i32
      %169 = arith.extsi %167 : i32 to i64
      %168 = arith.shrsi %166, %169 : i64
      llvm.store %168, %155 : i64, !llvm.ptr
      %170 = llvm.load %158 : !llvm.ptr -> i32
      %171 = arith.constant 1 : i32
      %172 = arith.addi %170, %171 : i32
      llvm.store %172, %158 : i32, !llvm.ptr
      cf.br ^bb48
    ^bb50:
    %173 = arith.constant 0 : i32
    %174 = llvm.mlir.constant(1 : i64) : i64
    %175 = llvm.alloca %174 x i32 : (i64) -> !llvm.ptr
    llvm.store %173, %175 : i32, !llvm.ptr
    cf.br ^bb51
    ^bb51:
    %176 = llvm.load %175 : !llvm.ptr -> i32
    %177 = arith.constant 7 : i32
    %178 = arith.cmpi slt, %176, %177 : i32
    cf.cond_br %178, ^bb52, ^bb53
    ^bb52:
      %179 = arith.constant 0 : i32
      %180 = arith.extsi %179 : i32 to i64
      %181 = llvm.load %175 : !llvm.ptr -> i32
      %182 = arith.constant 0 : i32
      %183 = arith.cmpi eq, %181, %182 : i32
      cf.cond_br %183, ^bb54, ^bb55
^bb54:
        %184 = arith.constant 2 : i32
        %185 = arith.extsi %184 : i32 to i64
        cf.br ^bb68(%185 : i64)
^bb55:
      %186 = arith.constant 1 : i32
      %187 = arith.cmpi eq, %181, %186 : i32
      cf.cond_br %187, ^bb56, ^bb57
^bb56:
        %188 = arith.constant 325 : i32
        %189 = arith.extsi %188 : i32 to i64
        cf.br ^bb68(%189 : i64)
^bb57:
      %190 = arith.constant 2 : i32
      %191 = arith.cmpi eq, %181, %190 : i32
      cf.cond_br %191, ^bb58, ^bb59
^bb58:
        %192 = arith.constant 9375 : i32
        %193 = arith.extsi %192 : i32 to i64
        cf.br ^bb68(%193 : i64)
^bb59:
      %194 = arith.constant 3 : i32
      %195 = arith.cmpi eq, %181, %194 : i32
      cf.cond_br %195, ^bb60, ^bb61
^bb60:
        %196 = arith.constant 28178 : i32
        %197 = arith.extsi %196 : i32 to i64
        cf.br ^bb68(%197 : i64)
^bb61:
      %198 = arith.constant 4 : i32
      %199 = arith.cmpi eq, %181, %198 : i32
      cf.cond_br %199, ^bb62, ^bb63
^bb62:
        %200 = arith.constant 450775 : i32
        %201 = arith.extsi %200 : i32 to i64
        cf.br ^bb68(%201 : i64)
^bb63:
      %202 = arith.constant 5 : i32
      %203 = arith.cmpi eq, %181, %202 : i32
      cf.cond_br %203, ^bb64, ^bb65
^bb64:
        %204 = arith.constant 9780504 : i32
        %205 = arith.extsi %204 : i32 to i64
        cf.br ^bb68(%205 : i64)
^bb65:
      %206 = arith.constant 1 : i1
      cf.cond_br %206, ^bb66, ^bb67
^bb66:
        %207 = arith.constant 1795265022 : i32
        %208 = arith.extsi %207 : i32 to i64
        cf.br ^bb68(%208 : i64)
^bb67:
      cf.br ^bb68(%180 : i64)
^bb68(%209: i64):
      %210 = arith.remsi %209, %arg0 : i64
      %211 = arith.constant 0 : i32
      %213 = arith.extsi %211 : i32 to i64
      %212 = arith.cmpi eq, %210, %213 : i64
      cf.cond_br %212, ^bb69, ^bb70
      ^bb69:
        %214 = llvm.load %175 : !llvm.ptr -> i32
        %215 = arith.constant 1 : i32
        %216 = arith.addi %214, %215 : i32
        llvm.store %216, %175 : i32, !llvm.ptr
        cf.br ^bb51
      ^bb70:
        cf.br ^bb71
      ^bb71:
      %218 = llvm.load %155 : !llvm.ptr -> i64
      %217 = func.call @modpow(%210, %218, %arg0) : (i64, i64, i64) -> i64
      %219 = llvm.mlir.constant(1 : i64) : i64
      %220 = llvm.alloca %219 x i64 : (i64) -> !llvm.ptr
      llvm.store %217, %220 : i64, !llvm.ptr
      %221 = llvm.load %220 : !llvm.ptr -> i64
      %222 = arith.constant 1 : i32
      %224 = arith.extsi %222 : i32 to i64
      %223 = arith.cmpi eq, %221, %224 : i64
      %225 = scf.if %223 -> (i1) {
        %226 = arith.constant true
        scf.yield %226 : i1
      } else {
        %227 = llvm.load %220 : !llvm.ptr -> i64
        %228 = arith.constant 1 : i32
        %230 = arith.extsi %228 : i32 to i64
        %229 = arith.subi %arg0, %230 : i64
        %231 = arith.cmpi eq, %227, %229 : i64
        scf.yield %231 : i1
      }
      cf.cond_br %225, ^bb72, ^bb73
      ^bb72:
        %232 = llvm.load %175 : !llvm.ptr -> i32
        %233 = arith.constant 1 : i32
        %234 = arith.addi %232, %233 : i32
        llvm.store %234, %175 : i32, !llvm.ptr
        cf.br ^bb51
      ^bb73:
        cf.br ^bb74
      ^bb74:
      %235 = arith.constant 0 : i1
      %236 = llvm.mlir.constant(1 : i64) : i64
      %237 = llvm.alloca %236 x i1 : (i64) -> !llvm.ptr
      llvm.store %235, %237 : i1, !llvm.ptr
      %238 = arith.constant 0 : i32
      %239 = llvm.mlir.constant(1 : i64) : i64
      %240 = llvm.alloca %239 x i32 : (i64) -> !llvm.ptr
      llvm.store %238, %240 : i32, !llvm.ptr
      cf.br ^bb75
      ^bb75:
      %241 = llvm.load %240 : !llvm.ptr -> i32
      %242 = llvm.load %158 : !llvm.ptr -> i32
      %243 = arith.constant 1 : i32
      %244 = arith.subi %242, %243 : i32
      %245 = arith.cmpi slt, %241, %244 : i32
      cf.cond_br %245, ^bb76, ^bb77
      ^bb76:
        %247 = llvm.load %220 : !llvm.ptr -> i64
        %248 = llvm.load %220 : !llvm.ptr -> i64
        %246 = func.call @mulmod(%247, %248, %arg0) : (i64, i64, i64) -> i64
        llvm.store %246, %220 : i64, !llvm.ptr
        %249 = llvm.load %220 : !llvm.ptr -> i64
        %250 = arith.constant 1 : i32
        %252 = arith.extsi %250 : i32 to i64
        %251 = arith.subi %arg0, %252 : i64
        %253 = arith.cmpi eq, %249, %251 : i64
        cf.cond_br %253, ^bb78, ^bb79
        ^bb78:
          %254 = arith.constant 1 : i1
          llvm.store %254, %237 : i1, !llvm.ptr
          cf.br ^bb77
        ^bb79:
          cf.br ^bb80
        ^bb80:
        %255 = llvm.load %220 : !llvm.ptr -> i64
        %256 = arith.constant 1 : i32
        %258 = arith.extsi %256 : i32 to i64
        %257 = arith.cmpi eq, %255, %258 : i64
        cf.cond_br %257, ^bb81, ^bb82
        ^bb81:
          %259 = arith.constant 0 : i1
          func.return %259 : i1
        ^bb82:
          cf.br ^bb83
        ^bb83:
        %260 = llvm.load %240 : !llvm.ptr -> i32
        %261 = arith.constant 1 : i32
        %262 = arith.addi %260, %261 : i32
        llvm.store %262, %240 : i32, !llvm.ptr
        cf.br ^bb75
      ^bb77:
      %263 = llvm.load %237 : !llvm.ptr -> i1
      %265 = arith.constant 1 : i1
      %264 = arith.xori %263, %265 : i1
      cf.cond_br %264, ^bb84, ^bb85
      ^bb84:
        %267 = arith.constant 0 : i1
        func.return %267 : i1
      ^bb85:
        cf.br ^bb86
      ^bb86:
      %268 = llvm.load %175 : !llvm.ptr -> i32
      %269 = arith.constant 1 : i32
      %270 = arith.addi %268, %269 : i32
      llvm.store %270, %175 : i32, !llvm.ptr
      cf.br ^bb51
    ^bb53:
    %271 = arith.constant 1 : i1
    func.return %271 : i1
  }
  func.func @fibonacci(%arg0: i64, %arg1: i64) -> i64 {
    %272 = arith.constant 0 : i32
    %274 = arith.extsi %272 : i32 to i64
    %273 = arith.cmpi eq, %arg0, %274 : i64
    cf.cond_br %273, ^bb87, ^bb88
    ^bb87:
      %275 = arith.constant 0 : i32
      %276 = arith.extsi %275 : i32 to i64
      func.return %276 : i64
    ^bb88:
      cf.br ^bb89
    ^bb89:
    %277 = arith.constant 1 : i32
    %278 = arith.extsi %277 : i32 to i64
    %279 = llvm.mlir.constant(1 : i64) : i64
    %280 = llvm.alloca %279 x i64 : (i64) -> !llvm.ptr
    llvm.store %278, %280 : i64, !llvm.ptr
    cf.br ^bb90
    ^bb90:
    %281 = llvm.load %280 : !llvm.ptr -> i64
    %282 = arith.constant 2 : i32
    %284 = arith.extsi %282 : i32 to i64
    %283 = arith.divsi %arg0, %284 : i64
    %285 = arith.cmpi sle, %281, %283 : i64
    cf.cond_br %285, ^bb91, ^bb92
    ^bb91:
      %286 = llvm.load %280 : !llvm.ptr -> i64
      %287 = arith.constant 1 : i32
      %289 = arith.extsi %287 : i32 to i64
      %288 = arith.shli %286, %289 : i64
      llvm.store %288, %280 : i64, !llvm.ptr
      cf.br ^bb90
    ^bb92:
    %290 = arith.constant 0 : i32
    %291 = arith.extsi %290 : i32 to i64
    %292 = llvm.mlir.constant(1 : i64) : i64
    %293 = llvm.alloca %292 x i64 : (i64) -> !llvm.ptr
    llvm.store %291, %293 : i64, !llvm.ptr
    %294 = arith.constant 1 : i32
    %295 = arith.extsi %294 : i32 to i64
    %296 = llvm.mlir.constant(1 : i64) : i64
    %297 = llvm.alloca %296 x i64 : (i64) -> !llvm.ptr
    llvm.store %295, %297 : i64, !llvm.ptr
    cf.br ^bb93
    ^bb93:
    %298 = llvm.load %280 : !llvm.ptr -> i64
    %299 = arith.constant 0 : i32
    %301 = arith.extsi %299 : i32 to i64
    %300 = arith.cmpi sgt, %298, %301 : i64
    cf.cond_br %300, ^bb94, ^bb95
    ^bb94:
      %303 = llvm.load %293 : !llvm.ptr -> i64
      %304 = arith.constant 2 : i32
      %305 = llvm.load %297 : !llvm.ptr -> i64
      %307 = arith.extsi %304 : i32 to i64
      %306 = arith.muli %307, %305 : i64
      %308 = llvm.load %293 : !llvm.ptr -> i64
      %309 = arith.subi %306, %308 : i64
      %310 = arith.addi %309, %arg1 : i64
      %311 = arith.remsi %310, %arg1 : i64
      %302 = func.call @mulmod(%303, %311, %arg1) : (i64, i64, i64) -> i64
      %313 = llvm.load %293 : !llvm.ptr -> i64
      %314 = llvm.load %293 : !llvm.ptr -> i64
      %312 = func.call @mulmod(%313, %314, %arg1) : (i64, i64, i64) -> i64
      %316 = llvm.load %297 : !llvm.ptr -> i64
      %317 = llvm.load %297 : !llvm.ptr -> i64
      %315 = func.call @mulmod(%316, %317, %arg1) : (i64, i64, i64) -> i64
      %318 = arith.addi %312, %315 : i64
      %319 = arith.remsi %318, %arg1 : i64
      llvm.store %319, %297 : i64, !llvm.ptr
      llvm.store %302, %293 : i64, !llvm.ptr
      %320 = llvm.load %280 : !llvm.ptr -> i64
      %321 = arith.andi %arg0, %320 : i64
      %322 = arith.constant 0 : i32
      %324 = arith.extsi %322 : i32 to i64
      %323 = arith.cmpi ne, %321, %324 : i64
      cf.cond_br %323, ^bb96, ^bb97
      ^bb96:
        %325 = llvm.load %297 : !llvm.ptr -> i64
        %326 = llvm.load %293 : !llvm.ptr -> i64
        %327 = llvm.load %297 : !llvm.ptr -> i64
        %328 = arith.addi %326, %327 : i64
        %329 = arith.remsi %328, %arg1 : i64
        llvm.store %329, %297 : i64, !llvm.ptr
        llvm.store %325, %293 : i64, !llvm.ptr
        cf.br ^bb98
      ^bb97:
        cf.br ^bb98
      ^bb98:
      %330 = llvm.load %280 : !llvm.ptr -> i64
      %331 = arith.constant 1 : i32
      %333 = arith.extsi %331 : i32 to i64
      %332 = arith.shrsi %330, %333 : i64
      llvm.store %332, %280 : i64, !llvm.ptr
      cf.br ^bb93
    ^bb95:
    %334 = llvm.load %293 : !llvm.ptr -> i64
    func.return %334 : i64
  }
  func.func @main() -> i32 {
    %335 = arith.constant 1230272923715 : i32
    %336 = arith.extsi %335 : i32 to i64
    %337 = arith.constant 99995705032704 : i32
    %338 = arith.extsi %337 : i32 to i64
    %339 = llvm.mlir.constant(1 : i64) : i64
    %340 = llvm.alloca %339 x i64 : (i64) -> !llvm.ptr
    llvm.store %338, %340 : i64, !llvm.ptr
    %342 = llvm.load %340 : !llvm.ptr -> i64
    %343 = arith.constant 1 : i32
    %345 = arith.extsi %343 : i32 to i64
    %344 = arith.subi %342, %345 : i64
    %341 = func.call @fibonacci(%344, %336) : (i64, i64) -> i64
    %346 = llvm.mlir.constant(1 : i64) : i64
    %347 = llvm.alloca %346 x i64 : (i64) -> !llvm.ptr
    llvm.store %341, %347 : i64, !llvm.ptr
    %349 = llvm.load %340 : !llvm.ptr -> i64
    %348 = func.call @fibonacci(%349, %336) : (i64, i64) -> i64
    %350 = llvm.mlir.constant(1 : i64) : i64
    %351 = llvm.alloca %350 x i64 : (i64) -> !llvm.ptr
    llvm.store %348, %351 : i64, !llvm.ptr
    %352 = arith.constant 0 : i32
    %353 = arith.extsi %352 : i32 to i64
    %354 = llvm.mlir.constant(1 : i64) : i64
    %355 = llvm.alloca %354 x i64 : (i64) -> !llvm.ptr
    llvm.store %353, %355 : i64, !llvm.ptr
    %356 = arith.constant 0 : i32
    %357 = arith.extsi %356 : i32 to i64
    %358 = llvm.mlir.constant(1 : i64) : i64
    %359 = llvm.alloca %358 x i64 : (i64) -> !llvm.ptr
    llvm.store %357, %359 : i64, !llvm.ptr
    cf.br ^bb99
    ^bb99:
    %360 = llvm.load %359 : !llvm.ptr -> i64
    %361 = arith.constant 100000 : i32
    %363 = arith.extsi %361 : i32 to i64
    %362 = arith.cmpi slt, %360, %363 : i64
    cf.cond_br %362, ^bb100, ^bb101
    ^bb100:
      %364 = llvm.load %340 : !llvm.ptr -> i64
      %365 = arith.constant 1 : i32
      %367 = arith.extsi %365 : i32 to i64
      %366 = arith.addi %364, %367 : i64
      llvm.store %366, %340 : i64, !llvm.ptr
      %368 = llvm.load %347 : !llvm.ptr -> i64
      %369 = llvm.load %351 : !llvm.ptr -> i64
      %370 = arith.addi %368, %369 : i64
      %371 = arith.remsi %370, %336 : i64
      %372 = llvm.load %351 : !llvm.ptr -> i64
      llvm.store %372, %347 : i64, !llvm.ptr
      llvm.store %371, %351 : i64, !llvm.ptr
      %374 = llvm.load %340 : !llvm.ptr -> i64
      %373 = func.call @is_prime(%374) : (i64) -> i1
      cf.cond_br %373, ^bb102, ^bb103
      ^bb102:
        %375 = llvm.load %355 : !llvm.ptr -> i64
        %376 = llvm.load %351 : !llvm.ptr -> i64
        %377 = arith.addi %375, %376 : i64
        %378 = arith.remsi %377, %336 : i64
        llvm.store %378, %355 : i64, !llvm.ptr
        %379 = llvm.load %359 : !llvm.ptr -> i64
        %380 = arith.constant 1 : i32
        %382 = arith.extsi %380 : i32 to i64
        %381 = arith.addi %379, %382 : i64
        llvm.store %381, %359 : i64, !llvm.ptr
        cf.br ^bb104
      ^bb103:
        cf.br ^bb104
      ^bb104:
      cf.br ^bb99
    ^bb101:
    %383 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %384 = llvm.load %355 : !llvm.ptr -> i64
    %385 = llvm.call @printf(%383, %384) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %386 = arith.constant 0 : i32
    func.return %386 : i32
  }
}