Problem 739

Coefficient recurrence: f(10^8) mod 10^9+7.

Answer711399016
Output711399016
StatusPASS
Native helperno
Runtime3810 ms
Peak memory7568 KB
Time complexityO(n^2) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n log n)
Space complexityO(n)O(n)
ApproachFlow solutionModular DP or matrix exponentiation
VerdictSuboptimal

Flow source

# Project Euler 739
# Coefficient recurrence: f(10^8) mod 10^9+7.

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

const MOD: i64 = 1000000007
const INV2: i64 = 500000004

function modpow(b: i64, e: i64) -> i64 {
    let mut r: i64 = 1
    let mut bb: i64 = b % MOD
    let mut ee: i64 = e
    while ee > 0 {
        if ee % 2 == 1 {
            r = r * bb % MOD
        }
        bb = bb * bb % MOD
        ee = ee / 2
    }
    return r
}

function inverses_consecutive(start: i64, length: i32, invs: ptr<i64>) -> void {
    let pref: ptr<i64> = calloc((length as i64 + 1), 8)
    pref[0] = 1
    let mut x: i64 = start
    let mut i: i32 = 0
    while i < length {
        pref[i + 1] = pref[i] * x % MOD
        x = x + 1
        i = i + 1
    }
    let mut inv_total: i64 = modpow(pref[length], MOD - 2)
    x = start + (length as i64) - 1
    let mut j: i32 = length - 1
    while j >= 0 {
        invs[j] = inv_total * pref[j] % MOD * INV2 % MOD
        inv_total = inv_total * x % MOD
        x = x - 1
        j = j - 1
    }
    free(pref)
}

function main() -> i32 {
    let n: i64 = 100000000
    let m: i64 = n - 1
    let mut a0: i64 = 1
    let mut a1: i64 = 3
    let mut a2: i64 = 7
    let mut a3: i64 = 21
    let mut steps: i64 = m - 3
    let mut c0: i64 = 2
    let mut c1: i64 = 26
    let mut c2: i64 = 62
    let mut c3: i64 = 50
    let mut denom: i64 = 4
    let BLOCK: i32 = 200000
    let invs: ptr<i64> = calloc(BLOCK as i64, 8)
    while steps > 0 {
        let L: i32 = if steps > (BLOCK as i64) { BLOCK } else { steps as i32 }
        inverses_consecutive(denom, L, invs)
        let mut j: i32 = 0
        while j < L {
            let t: i64 = (c3 * a3 % MOD - c0 * a0 % MOD - c1 * a1 % MOD - c2 * a2 % MOD) % MOD
            if t < 0 {
                t = t + MOD
            }
            let a4: i64 = t * invs[j] % MOD
            a0 = a1
            a1 = a2
            a2 = a3
            a3 = a4
            c0 = c0 + 4
            c1 = c1 + 23
            c2 = c2 + 22
            c3 = c3 + 15
            denom = denom + 1
            j = j + 1
        }
        steps = steps - (L as i64)
    }
    free(invs)
    printf("%lld\n", a3)
    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 modpow_i64_i64(int64_t b, int64_t e);
void inverses_consecutive_i64_i32_ptr_i64(int64_t start, int32_t length, int64_t* invs);
int32_t main(void);

static const int64_t MOD = 1000000007;
static const int64_t INV2 = 500000004;



int64_t modpow_i64_i64(int64_t b, int64_t e) {
    int64_t r = 1;
    int64_t bb = FLOW_CHECKED_MOD((b), (MOD));
    int64_t ee = e;
    while (ee > 0) {
        if (FLOW_CHECKED_MOD((ee), (2)) == 1) {
            r = FLOW_CHECKED_MOD(((r * bb)), (MOD));
        }
        bb = FLOW_CHECKED_MOD(((bb * bb)), (MOD));
        ee = FLOW_CHECKED_DIV((ee), (2));
    }
    return r;
}

void inverses_consecutive_i64_i32_ptr_i64(int64_t start, int32_t length, int64_t* invs) {
    int64_t* pref = (int64_t*)(calloc((((int64_t)(length)) + 1), 8));
    pref[0] = 1;
    int64_t x = start;
    int32_t i = 0;
    while (i < length) {
        pref[(i + 1)] = FLOW_CHECKED_MOD(((pref[i] * x)), (MOD));
        x = (x + 1);
        i = (i + 1);
    }
    int64_t inv_total = modpow_i64_i64(pref[length], (MOD - 2));
    x = ((start + ((int64_t)(length))) - 1);
    int32_t j = (length - 1);
    while (j >= 0) {
        invs[j] = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((inv_total * pref[j])), (MOD)) * INV2)), (MOD));
        inv_total = FLOW_CHECKED_MOD(((inv_total * x)), (MOD));
        x = (x - 1);
        j = (j - 1);
    }
    free(pref);
}

int32_t main(void) {
    int64_t n = 100000000;
    int64_t m = (n - 1);
    int64_t a0 = 1;
    int64_t a1 = 3;
    int64_t a2 = 7;
    int64_t a3 = 21;
    int64_t steps = (m - 3);
    int64_t c0 = 2;
    int64_t c1 = 26;
    int64_t c2 = 62;
    int64_t c3 = 50;
    int64_t denom = 4;
    int32_t BLOCK = 200000;
    int64_t* invs = (int64_t*)(calloc(((int64_t)(BLOCK)), 8));
    while (steps > 0) {
        int32_t L = ((steps > ((int64_t)(BLOCK))) ? (BLOCK) : (((int32_t)(steps))));
        inverses_consecutive_i64_i32_ptr_i64(denom, L, invs);
        int32_t j = 0;
        while (j < L) {
            int64_t t = FLOW_CHECKED_MOD(((((FLOW_CHECKED_MOD(((c3 * a3)), (MOD)) - FLOW_CHECKED_MOD(((c0 * a0)), (MOD))) - FLOW_CHECKED_MOD(((c1 * a1)), (MOD))) - FLOW_CHECKED_MOD(((c2 * a2)), (MOD)))), (MOD));
            if (t < 0) {
                t = (t + MOD);
            }
            int64_t a4 = FLOW_CHECKED_MOD(((t * invs[j])), (MOD));
            a0 = a1;
            a1 = a2;
            a2 = a3;
            a3 = a4;
            c0 = (c0 + 4);
            c1 = (c1 + 23);
            c2 = (c2 + 22);
            c3 = (c3 + 15);
            denom = (denom + 1);
            j = (j + 1);
        }
        steps = (steps - ((int64_t)(L)));
    }
    free(invs);
    printf("%lld\n", a3);
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
  // Constant: INV2
  llvm.mlir.global internal constant @INV2(500000004 : i64) : i64
  func.func @modpow(%arg0: i64, %arg1: i64) -> i64 {
    %0 = arith.constant 1 : i32
    %1 = arith.extsi %0 : i32 to i64
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
    llvm.store %1, %3 : i64, !llvm.ptr
    %4 = llvm.mlir.addressof @MOD : !llvm.ptr
    %5 = llvm.load %4 : !llvm.ptr -> i64
    %6 = arith.remsi %arg0, %5 : i64
    %7 = llvm.mlir.constant(1 : i64) : i64
    %8 = llvm.alloca %7 x i64 : (i64) -> !llvm.ptr
    llvm.store %6, %8 : i64, !llvm.ptr
    %9 = llvm.mlir.constant(1 : i64) : i64
    %10 = llvm.alloca %9 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %10 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %11 = llvm.load %10 : !llvm.ptr -> i64
    %12 = arith.constant 0 : i32
    %14 = arith.extsi %12 : i32 to i64
    %13 = arith.cmpi sgt, %11, %14 : i64
    cf.cond_br %13, ^bb1, ^bb2
    ^bb1:
      %15 = llvm.load %10 : !llvm.ptr -> i64
      %16 = arith.constant 2 : i32
      %18 = arith.extsi %16 : i32 to i64
      %17 = arith.remsi %15, %18 : i64
      %19 = arith.constant 1 : i32
      %21 = arith.extsi %19 : i32 to i64
      %20 = arith.cmpi eq, %17, %21 : i64
      cf.cond_br %20, ^bb3, ^bb4
      ^bb3:
        %22 = llvm.load %3 : !llvm.ptr -> i64
        %23 = llvm.load %8 : !llvm.ptr -> i64
        %24 = arith.muli %22, %23 : i64
        %25 = llvm.mlir.addressof @MOD : !llvm.ptr
        %26 = llvm.load %25 : !llvm.ptr -> i64
        %27 = arith.remsi %24, %26 : i64
        llvm.store %27, %3 : i64, !llvm.ptr
        cf.br ^bb5
      ^bb4:
        cf.br ^bb5
      ^bb5:
      %28 = llvm.load %8 : !llvm.ptr -> i64
      %29 = llvm.load %8 : !llvm.ptr -> i64
      %30 = arith.muli %28, %29 : i64
      %31 = llvm.mlir.addressof @MOD : !llvm.ptr
      %32 = llvm.load %31 : !llvm.ptr -> i64
      %33 = arith.remsi %30, %32 : i64
      llvm.store %33, %8 : i64, !llvm.ptr
      %34 = llvm.load %10 : !llvm.ptr -> i64
      %35 = arith.constant 2 : i32
      %37 = arith.extsi %35 : i32 to i64
      %36 = arith.divsi %34, %37 : i64
      llvm.store %36, %10 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %38 = llvm.load %3 : !llvm.ptr -> i64
    func.return %38 : i64
  }
  func.func @inverses_consecutive(%arg0: i64, %arg1: i32, %arg2: !llvm.ptr) -> () {
    %40 = arith.extsi %arg1 : i32 to i64
    %41 = arith.constant 1 : i32
    %43 = arith.extsi %41 : i32 to i64
    %42 = arith.addi %40, %43 : i64
    %44 = arith.constant 8 : i32
    %45 = arith.extsi %44 : i32 to i64
    %39 = func.call @calloc(%42, %45) : (i64, i64) -> !llvm.ptr
    %46 = arith.constant 1 : i32
    %47 = arith.constant 0 : i32
    %48 = arith.extsi %46 : i32 to i64
    %49 = arith.extsi %47 : i32 to i64
    %50 = llvm.getelementptr %39[%49] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %48, %50 : i64, !llvm.ptr
    %51 = llvm.mlir.constant(1 : i64) : i64
    %52 = llvm.alloca %51 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %52 : i64, !llvm.ptr
    %53 = arith.constant 0 : i32
    %54 = llvm.mlir.constant(1 : i64) : i64
    %55 = llvm.alloca %54 x i32 : (i64) -> !llvm.ptr
    llvm.store %53, %55 : i32, !llvm.ptr
    cf.br ^bb6
    ^bb6:
    %56 = llvm.load %55 : !llvm.ptr -> i32
    %57 = arith.cmpi slt, %56, %arg1 : i32
    cf.cond_br %57, ^bb7, ^bb8
    ^bb7:
      %59 = llvm.load %55 : !llvm.ptr -> i32
      %60 = arith.extsi %59 : i32 to i64
      %61 = llvm.getelementptr %39[%60] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %58 = llvm.load %61 : !llvm.ptr -> i64
      %62 = llvm.load %52 : !llvm.ptr -> i64
      %63 = arith.muli %58, %62 : i64
      %64 = llvm.mlir.addressof @MOD : !llvm.ptr
      %65 = llvm.load %64 : !llvm.ptr -> i64
      %66 = arith.remsi %63, %65 : i64
      %67 = llvm.load %55 : !llvm.ptr -> i32
      %68 = arith.constant 1 : i32
      %69 = arith.addi %67, %68 : i32
      %70 = arith.extsi %69 : i32 to i64
      %71 = llvm.getelementptr %39[%70] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %66, %71 : i64, !llvm.ptr
      %72 = llvm.load %52 : !llvm.ptr -> i64
      %73 = arith.constant 1 : i32
      %75 = arith.extsi %73 : i32 to i64
      %74 = arith.addi %72, %75 : i64
      llvm.store %74, %52 : i64, !llvm.ptr
      %76 = llvm.load %55 : !llvm.ptr -> i32
      %77 = arith.constant 1 : i32
      %78 = arith.addi %76, %77 : i32
      llvm.store %78, %55 : i32, !llvm.ptr
      cf.br ^bb6
    ^bb8:
    %81 = arith.extsi %arg1 : i32 to i64
    %82 = llvm.getelementptr %39[%81] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %80 = llvm.load %82 : !llvm.ptr -> i64
    %83 = llvm.mlir.addressof @MOD : !llvm.ptr
    %84 = llvm.load %83 : !llvm.ptr -> i64
    %85 = arith.constant 2 : i32
    %87 = arith.extsi %85 : i32 to i64
    %86 = arith.subi %84, %87 : i64
    %79 = func.call @modpow(%80, %86) : (i64, i64) -> i64
    %88 = llvm.mlir.constant(1 : i64) : i64
    %89 = llvm.alloca %88 x i64 : (i64) -> !llvm.ptr
    llvm.store %79, %89 : i64, !llvm.ptr
    %90 = arith.extsi %arg1 : i32 to i64
    %91 = arith.addi %arg0, %90 : i64
    %92 = arith.constant 1 : i32
    %94 = arith.extsi %92 : i32 to i64
    %93 = arith.subi %91, %94 : i64
    llvm.store %93, %52 : i64, !llvm.ptr
    %95 = arith.constant 1 : i32
    %96 = arith.subi %arg1, %95 : i32
    %97 = llvm.mlir.constant(1 : i64) : i64
    %98 = llvm.alloca %97 x i32 : (i64) -> !llvm.ptr
    llvm.store %96, %98 : i32, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %99 = llvm.load %98 : !llvm.ptr -> i32
    %100 = arith.constant 0 : i32
    %101 = arith.cmpi sge, %99, %100 : i32
    cf.cond_br %101, ^bb10, ^bb11
    ^bb10:
      %102 = llvm.load %89 : !llvm.ptr -> i64
      %104 = llvm.load %98 : !llvm.ptr -> i32
      %105 = arith.extsi %104 : i32 to i64
      %106 = llvm.getelementptr %39[%105] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %103 = llvm.load %106 : !llvm.ptr -> i64
      %107 = arith.muli %102, %103 : i64
      %108 = llvm.mlir.addressof @MOD : !llvm.ptr
      %109 = llvm.load %108 : !llvm.ptr -> i64
      %110 = arith.remsi %107, %109 : i64
      %111 = llvm.mlir.addressof @INV2 : !llvm.ptr
      %112 = llvm.load %111 : !llvm.ptr -> i64
      %113 = arith.muli %110, %112 : i64
      %114 = llvm.mlir.addressof @MOD : !llvm.ptr
      %115 = llvm.load %114 : !llvm.ptr -> i64
      %116 = arith.remsi %113, %115 : i64
      %117 = llvm.load %98 : !llvm.ptr -> i32
      %118 = arith.extsi %117 : i32 to i64
      %119 = llvm.getelementptr %arg2[%118] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %116, %119 : i64, !llvm.ptr
      %120 = llvm.load %89 : !llvm.ptr -> i64
      %121 = llvm.load %52 : !llvm.ptr -> i64
      %122 = arith.muli %120, %121 : i64
      %123 = llvm.mlir.addressof @MOD : !llvm.ptr
      %124 = llvm.load %123 : !llvm.ptr -> i64
      %125 = arith.remsi %122, %124 : i64
      llvm.store %125, %89 : i64, !llvm.ptr
      %126 = llvm.load %52 : !llvm.ptr -> i64
      %127 = arith.constant 1 : i32
      %129 = arith.extsi %127 : i32 to i64
      %128 = arith.subi %126, %129 : i64
      llvm.store %128, %52 : i64, !llvm.ptr
      %130 = llvm.load %98 : !llvm.ptr -> i32
      %131 = arith.constant 1 : i32
      %132 = arith.subi %130, %131 : i32
      llvm.store %132, %98 : i32, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    func.call @free(%39) : (!llvm.ptr) -> ()
    func.return
  }
  func.func @main() -> i32 {
    %134 = arith.constant 100000000 : i32
    %135 = arith.extsi %134 : i32 to i64
    %136 = arith.constant 1 : i32
    %138 = arith.extsi %136 : i32 to i64
    %137 = arith.subi %135, %138 : i64
    %139 = arith.constant 1 : i32
    %140 = arith.extsi %139 : i32 to i64
    %141 = llvm.mlir.constant(1 : i64) : i64
    %142 = llvm.alloca %141 x i64 : (i64) -> !llvm.ptr
    llvm.store %140, %142 : i64, !llvm.ptr
    %143 = arith.constant 3 : i32
    %144 = arith.extsi %143 : i32 to i64
    %145 = llvm.mlir.constant(1 : i64) : i64
    %146 = llvm.alloca %145 x i64 : (i64) -> !llvm.ptr
    llvm.store %144, %146 : i64, !llvm.ptr
    %147 = arith.constant 7 : i32
    %148 = arith.extsi %147 : i32 to i64
    %149 = llvm.mlir.constant(1 : i64) : i64
    %150 = llvm.alloca %149 x i64 : (i64) -> !llvm.ptr
    llvm.store %148, %150 : i64, !llvm.ptr
    %151 = arith.constant 21 : i32
    %152 = arith.extsi %151 : i32 to i64
    %153 = llvm.mlir.constant(1 : i64) : i64
    %154 = llvm.alloca %153 x i64 : (i64) -> !llvm.ptr
    llvm.store %152, %154 : i64, !llvm.ptr
    %155 = arith.constant 3 : i32
    %157 = arith.extsi %155 : i32 to i64
    %156 = arith.subi %137, %157 : i64
    %158 = llvm.mlir.constant(1 : i64) : i64
    %159 = llvm.alloca %158 x i64 : (i64) -> !llvm.ptr
    llvm.store %156, %159 : i64, !llvm.ptr
    %160 = arith.constant 2 : i32
    %161 = arith.extsi %160 : i32 to i64
    %162 = llvm.mlir.constant(1 : i64) : i64
    %163 = llvm.alloca %162 x i64 : (i64) -> !llvm.ptr
    llvm.store %161, %163 : i64, !llvm.ptr
    %164 = arith.constant 26 : i32
    %165 = arith.extsi %164 : i32 to i64
    %166 = llvm.mlir.constant(1 : i64) : i64
    %167 = llvm.alloca %166 x i64 : (i64) -> !llvm.ptr
    llvm.store %165, %167 : i64, !llvm.ptr
    %168 = arith.constant 62 : i32
    %169 = arith.extsi %168 : i32 to i64
    %170 = llvm.mlir.constant(1 : i64) : i64
    %171 = llvm.alloca %170 x i64 : (i64) -> !llvm.ptr
    llvm.store %169, %171 : i64, !llvm.ptr
    %172 = arith.constant 50 : i32
    %173 = arith.extsi %172 : i32 to i64
    %174 = llvm.mlir.constant(1 : i64) : i64
    %175 = llvm.alloca %174 x i64 : (i64) -> !llvm.ptr
    llvm.store %173, %175 : i64, !llvm.ptr
    %176 = arith.constant 4 : i32
    %177 = arith.extsi %176 : i32 to i64
    %178 = llvm.mlir.constant(1 : i64) : i64
    %179 = llvm.alloca %178 x i64 : (i64) -> !llvm.ptr
    llvm.store %177, %179 : i64, !llvm.ptr
    %180 = arith.constant 200000 : i32
    %182 = arith.extsi %180 : i32 to i64
    %183 = arith.constant 8 : i32
    %184 = arith.extsi %183 : i32 to i64
    %181 = func.call @calloc(%182, %184) : (i64, i64) -> !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %185 = llvm.load %159 : !llvm.ptr -> i64
    %186 = arith.constant 0 : i32
    %188 = arith.extsi %186 : i32 to i64
    %187 = arith.cmpi sgt, %185, %188 : i64
    cf.cond_br %187, ^bb13, ^bb14
    ^bb13:
      %189 = llvm.load %159 : !llvm.ptr -> i64
      %190 = arith.extsi %180 : i32 to i64
      %191 = arith.cmpi sgt, %189, %190 : i64
      %192 = scf.if %191 -> (i32) {
        scf.yield %180 : i32
      } else {
        %193 = llvm.load %159 : !llvm.ptr -> i64
        %194 = arith.trunci %193 : i64 to i32
        scf.yield %194 : i32
      }
      %196 = llvm.load %179 : !llvm.ptr -> i64
      func.call @inverses_consecutive(%196, %192, %181) : (i64, i32, !llvm.ptr) -> ()
      %197 = arith.constant 0 : i32
      %198 = llvm.mlir.constant(1 : i64) : i64
      %199 = llvm.alloca %198 x i32 : (i64) -> !llvm.ptr
      llvm.store %197, %199 : i32, !llvm.ptr
      cf.br ^bb15
      ^bb15:
      %200 = llvm.load %199 : !llvm.ptr -> i32
      %201 = arith.cmpi slt, %200, %192 : i32
      cf.cond_br %201, ^bb16, ^bb17
      ^bb16:
        %202 = llvm.load %175 : !llvm.ptr -> i64
        %203 = llvm.load %154 : !llvm.ptr -> i64
        %204 = arith.muli %202, %203 : i64
        %205 = llvm.mlir.addressof @MOD : !llvm.ptr
        %206 = llvm.load %205 : !llvm.ptr -> i64
        %207 = arith.remsi %204, %206 : i64
        %208 = llvm.load %163 : !llvm.ptr -> i64
        %209 = llvm.load %142 : !llvm.ptr -> i64
        %210 = arith.muli %208, %209 : i64
        %211 = llvm.mlir.addressof @MOD : !llvm.ptr
        %212 = llvm.load %211 : !llvm.ptr -> i64
        %213 = arith.remsi %210, %212 : i64
        %214 = arith.subi %207, %213 : i64
        %215 = llvm.load %167 : !llvm.ptr -> i64
        %216 = llvm.load %146 : !llvm.ptr -> i64
        %217 = arith.muli %215, %216 : i64
        %218 = llvm.mlir.addressof @MOD : !llvm.ptr
        %219 = llvm.load %218 : !llvm.ptr -> i64
        %220 = arith.remsi %217, %219 : i64
        %221 = arith.subi %214, %220 : i64
        %222 = llvm.load %171 : !llvm.ptr -> i64
        %223 = llvm.load %150 : !llvm.ptr -> i64
        %224 = arith.muli %222, %223 : i64
        %225 = llvm.mlir.addressof @MOD : !llvm.ptr
        %226 = llvm.load %225 : !llvm.ptr -> i64
        %227 = arith.remsi %224, %226 : i64
        %228 = arith.subi %221, %227 : i64
        %229 = llvm.mlir.addressof @MOD : !llvm.ptr
        %230 = llvm.load %229 : !llvm.ptr -> i64
        %231 = arith.remsi %228, %230 : i64
        %232 = arith.constant 0 : i32
        %234 = arith.extsi %232 : i32 to i64
        %233 = arith.cmpi slt, %231, %234 : i64
        %235 = scf.if %233 -> (i64) {
          %236 = llvm.mlir.addressof @MOD : !llvm.ptr
          %237 = llvm.load %236 : !llvm.ptr -> i64
          %238 = arith.addi %231, %237 : i64
          scf.yield %238 : i64
        } else {
          scf.yield %231 : i64
        }
        %240 = llvm.load %199 : !llvm.ptr -> i32
        %241 = arith.extsi %240 : i32 to i64
        %242 = llvm.getelementptr %181[%241] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %239 = llvm.load %242 : !llvm.ptr -> i64
        %243 = arith.muli %235, %239 : i64
        %244 = llvm.mlir.addressof @MOD : !llvm.ptr
        %245 = llvm.load %244 : !llvm.ptr -> i64
        %246 = arith.remsi %243, %245 : i64
        %247 = llvm.load %146 : !llvm.ptr -> i64
        llvm.store %247, %142 : i64, !llvm.ptr
        %248 = llvm.load %150 : !llvm.ptr -> i64
        llvm.store %248, %146 : i64, !llvm.ptr
        %249 = llvm.load %154 : !llvm.ptr -> i64
        llvm.store %249, %150 : i64, !llvm.ptr
        llvm.store %246, %154 : i64, !llvm.ptr
        %250 = llvm.load %163 : !llvm.ptr -> i64
        %251 = arith.constant 4 : i32
        %253 = arith.extsi %251 : i32 to i64
        %252 = arith.addi %250, %253 : i64
        llvm.store %252, %163 : i64, !llvm.ptr
        %254 = llvm.load %167 : !llvm.ptr -> i64
        %255 = arith.constant 23 : i32
        %257 = arith.extsi %255 : i32 to i64
        %256 = arith.addi %254, %257 : i64
        llvm.store %256, %167 : i64, !llvm.ptr
        %258 = llvm.load %171 : !llvm.ptr -> i64
        %259 = arith.constant 22 : i32
        %261 = arith.extsi %259 : i32 to i64
        %260 = arith.addi %258, %261 : i64
        llvm.store %260, %171 : i64, !llvm.ptr
        %262 = llvm.load %175 : !llvm.ptr -> i64
        %263 = arith.constant 15 : i32
        %265 = arith.extsi %263 : i32 to i64
        %264 = arith.addi %262, %265 : i64
        llvm.store %264, %175 : i64, !llvm.ptr
        %266 = llvm.load %179 : !llvm.ptr -> i64
        %267 = arith.constant 1 : i32
        %269 = arith.extsi %267 : i32 to i64
        %268 = arith.addi %266, %269 : i64
        llvm.store %268, %179 : i64, !llvm.ptr
        %270 = llvm.load %199 : !llvm.ptr -> i32
        %271 = arith.constant 1 : i32
        %272 = arith.addi %270, %271 : i32
        llvm.store %272, %199 : i32, !llvm.ptr
        cf.br ^bb15
      ^bb17:
      %273 = llvm.load %159 : !llvm.ptr -> i64
      %274 = arith.extsi %192 : i32 to i64
      %275 = arith.subi %273, %274 : i64
      llvm.store %275, %159 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    func.call @free(%181) : (!llvm.ptr) -> ()
    %277 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %278 = llvm.load %154 : !llvm.ptr -> i64
    %279 = llvm.call @printf(%277, %278) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %280 = arith.constant 0 : i32
    func.return %280 : i32
  }
}