Problem 258

g_{10^18} mod 20092010 for lagged Fibonacci.

Answer12747994
Output12747994
StatusPASS
Native helperno
Runtime100 ms
Peak memory1216 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(log n)
Space complexityO(n^2)O(1)
ApproachFlow solutionMatrix exponentiation
VerdictSuboptimal

Flow source

# Project Euler 258
# g_{10^18} mod 20092010 for lagged Fibonacci.

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

function mul_poly(a: ptr<i64>, b: ptr<i64>, out: ptr<i64>) -> void {
    let MOD: i64 = 20092010
    let D: i64 = 2000
    let mut c: ptr<i64> = calloc(2 * D - 1, 8)
    let mut i: i64 = 0
    while i < D {
        if a[i] != 0 {
            let mut j: i64 = 0
            while j < D {
                if b[j] != 0 {
                    c[i + j] = c[i + j] + a[i] * b[j]
                }
                j = j + 1
            }
        }
        i = i + 1
    }
    # fold x^D = x + 1
    i = 0
    while i < D {
        out[i] = c[i] % MOD
        i = i + 1
    }
    i = 0
    while i < D - 1 {
        let hi: i64 = c[D + i] % MOD
        out[i] = (out[i] + hi) % MOD
        out[i + 1] = (out[i + 1] + hi) % MOD
        i = i + 1
    }
    # one more fold pass in case of carry into degree D
    # after first fold, degrees stay < D; but sums may need another fold if we added to create overflow in sense of poly - actually max degree stays D-1
    free(c)
}

function main() -> i32 {
    let MOD: i64 = 20092010
    let D: i64 = 2000
    let n: i64 = 1000000000000000000
    let a: ptr<i64> = calloc(D, 8)
    let r: ptr<i64> = calloc(D, 8)
    let tmp: ptr<i64> = calloc(D, 8)
    if a == null || r == null || tmp == null { return 1 }
    # a = x = [0,1,0,...]
    a[1] = 1
    # r = 1
    r[0] = 1
    let mut e: i64 = n
    while e > 0 {
        if e % 2 == 1 {
            mul_poly(r, a, tmp)
            let mut i: i64 = 0
            while i < D {
                r[i] = tmp[i]
                i = i + 1
            }
        }
        mul_poly(a, a, tmp)
        let mut i: i64 = 0
        while i < D {
            a[i] = tmp[i]
            i = i + 1
        }
        e = e / 2
    }
    # g_n = sum of coefficients (initial all 1s)
    let mut sum: i64 = 0
    let mut i: i64 = 0
    while i < D {
        sum = (sum + r[i]) % MOD
        i = i + 1
    }
    printf("%lld\n", sum)
    free(a); free(r); free(tmp)
    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; }

void mul_poly_ptr_i64_ptr_i64_ptr_i64(int64_t* a, int64_t* b, int64_t* out);
int32_t main(void);



void mul_poly_ptr_i64_ptr_i64_ptr_i64(int64_t* a, int64_t* b, int64_t* out) {
    int64_t MOD = 20092010;
    int64_t D = 2000;
    int64_t* c = (int64_t*)(calloc(((2 * D) - 1), 8));
    int64_t i = 0;
    while (i < D) {
        if (a[i] != 0) {
            int64_t j = 0;
            while (j < D) {
                if (b[j] != 0) {
                    c[(i + j)] = (c[(i + j)] + (a[i] * b[j]));
                }
                j = (j + 1);
            }
        }
        i = (i + 1);
    }
    i = 0;
    while (i < D) {
        out[i] = FLOW_CHECKED_MOD((c[i]), (MOD));
        i = (i + 1);
    }
    i = 0;
    while (i < (D - 1)) {
        int64_t hi = FLOW_CHECKED_MOD((c[(D + i)]), (MOD));
        out[i] = FLOW_CHECKED_MOD(((out[i] + hi)), (MOD));
        out[(i + 1)] = FLOW_CHECKED_MOD(((out[(i + 1)] + hi)), (MOD));
        i = (i + 1);
    }
    free(c);
}

int32_t main(void) {
    int64_t MOD = 20092010;
    int64_t D = 2000;
    int64_t n = 1000000000000000000;
    int64_t* a = (int64_t*)(calloc(D, 8));
    int64_t* r = (int64_t*)(calloc(D, 8));
    int64_t* tmp = (int64_t*)(calloc(D, 8));
    if (((a == NULL || r == NULL) || tmp == NULL)) {
        return 1;
    }
    a[1] = 1;
    r[0] = 1;
    int64_t e = n;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            mul_poly_ptr_i64_ptr_i64_ptr_i64(r, a, tmp);
            int64_t i = 0;
            while (i < D) {
                r[i] = tmp[i];
                i = (i + 1);
            }
        }
        mul_poly_ptr_i64_ptr_i64_ptr_i64(a, a, tmp);
        int64_t i = 0;
        while (i < D) {
            a[i] = tmp[i];
            i = (i + 1);
        }
        e = FLOW_CHECKED_DIV((e), (2));
    }
    int64_t sum = 0;
    int64_t i = 0;
    while (i < D) {
        sum = FLOW_CHECKED_MOD(((sum + r[i])), (MOD));
        i = (i + 1);
    }
    printf("%lld\n", sum);
    free(a);
    free(r);
    free(tmp);
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func @mul_poly(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: !llvm.ptr) -> () {
    %0 = arith.constant 20092010 : i32
    %1 = arith.extsi %0 : i32 to i64
    %2 = arith.constant 2000 : i32
    %3 = arith.extsi %2 : i32 to i64
    %5 = arith.constant 2 : i32
    %7 = arith.extsi %5 : i32 to i64
    %6 = arith.muli %7, %3 : i64
    %8 = arith.constant 1 : i32
    %10 = arith.extsi %8 : i32 to i64
    %9 = arith.subi %6, %10 : i64
    %11 = arith.constant 8 : i32
    %12 = arith.extsi %11 : i32 to i64
    %4 = func.call @calloc(%9, %12) : (i64, i64) -> !llvm.ptr
    %13 = llvm.mlir.constant(1 : i64) : i64
    %14 = llvm.alloca %13 x !llvm.ptr : (i64) -> !llvm.ptr
    llvm.store %4, %14 : !llvm.ptr, !llvm.ptr
    %15 = arith.constant 0 : i32
    %16 = arith.extsi %15 : i32 to i64
    %17 = llvm.mlir.constant(1 : i64) : i64
    %18 = llvm.alloca %17 x i64 : (i64) -> !llvm.ptr
    llvm.store %16, %18 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %19 = llvm.load %18 : !llvm.ptr -> i64
    %20 = arith.cmpi slt, %19, %3 : i64
    cf.cond_br %20, ^bb1, ^bb2
    ^bb1:
      %22 = llvm.load %18 : !llvm.ptr -> i64
      %23 = llvm.getelementptr %arg0[%22] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %21 = llvm.load %23 : !llvm.ptr -> i64
      %24 = arith.constant 0 : i32
      %26 = arith.extsi %24 : i32 to i64
      %25 = arith.cmpi ne, %21, %26 : i64
      cf.cond_br %25, ^bb3, ^bb4
      ^bb3:
        %27 = arith.constant 0 : i32
        %28 = arith.extsi %27 : i32 to i64
        %29 = llvm.mlir.constant(1 : i64) : i64
        %30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
        llvm.store %28, %30 : i64, !llvm.ptr
        cf.br ^bb6
        ^bb6:
        %31 = llvm.load %30 : !llvm.ptr -> i64
        %32 = arith.cmpi slt, %31, %3 : i64
        cf.cond_br %32, ^bb7, ^bb8
        ^bb7:
          %34 = llvm.load %30 : !llvm.ptr -> i64
          %35 = llvm.getelementptr %arg1[%34] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %33 = llvm.load %35 : !llvm.ptr -> i64
          %36 = arith.constant 0 : i32
          %38 = arith.extsi %36 : i32 to i64
          %37 = arith.cmpi ne, %33, %38 : i64
          cf.cond_br %37, ^bb9, ^bb10
          ^bb9:
            %40 = llvm.load %14 : !llvm.ptr -> !llvm.ptr
            %41 = llvm.load %18 : !llvm.ptr -> i64
            %42 = llvm.load %30 : !llvm.ptr -> i64
            %43 = arith.addi %41, %42 : i64
            %44 = llvm.getelementptr %40[%43] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %39 = llvm.load %44 : !llvm.ptr -> i64
            %46 = llvm.load %18 : !llvm.ptr -> i64
            %47 = llvm.getelementptr %arg0[%46] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %45 = llvm.load %47 : !llvm.ptr -> i64
            %49 = llvm.load %30 : !llvm.ptr -> i64
            %50 = llvm.getelementptr %arg1[%49] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %48 = llvm.load %50 : !llvm.ptr -> i64
            %51 = arith.muli %45, %48 : i64
            %52 = arith.addi %39, %51 : i64
            %53 = llvm.load %14 : !llvm.ptr -> !llvm.ptr
            %54 = llvm.load %18 : !llvm.ptr -> i64
            %55 = llvm.load %30 : !llvm.ptr -> i64
            %56 = arith.addi %54, %55 : i64
            %57 = llvm.getelementptr %53[%56] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            llvm.store %52, %57 : i64, !llvm.ptr
            cf.br ^bb11
          ^bb10:
            cf.br ^bb11
          ^bb11:
          %58 = llvm.load %30 : !llvm.ptr -> i64
          %59 = arith.constant 1 : i32
          %61 = arith.extsi %59 : i32 to i64
          %60 = arith.addi %58, %61 : i64
          llvm.store %60, %30 : i64, !llvm.ptr
          cf.br ^bb6
        ^bb8:
        cf.br ^bb5
      ^bb4:
        cf.br ^bb5
      ^bb5:
      %62 = llvm.load %18 : !llvm.ptr -> i64
      %63 = arith.constant 1 : i32
      %65 = arith.extsi %63 : i32 to i64
      %64 = arith.addi %62, %65 : i64
      llvm.store %64, %18 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %66 = arith.constant 0 : i32
    %67 = arith.extsi %66 : i32 to i64
    llvm.store %67, %18 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %68 = llvm.load %18 : !llvm.ptr -> i64
    %69 = arith.cmpi slt, %68, %3 : i64
    cf.cond_br %69, ^bb13, ^bb14
    ^bb13:
      %71 = llvm.load %14 : !llvm.ptr -> !llvm.ptr
      %72 = llvm.load %18 : !llvm.ptr -> i64
      %73 = llvm.getelementptr %71[%72] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %70 = llvm.load %73 : !llvm.ptr -> i64
      %74 = arith.remsi %70, %1 : i64
      %75 = llvm.load %18 : !llvm.ptr -> i64
      %76 = llvm.getelementptr %arg2[%75] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %74, %76 : i64, !llvm.ptr
      %77 = llvm.load %18 : !llvm.ptr -> i64
      %78 = arith.constant 1 : i32
      %80 = arith.extsi %78 : i32 to i64
      %79 = arith.addi %77, %80 : i64
      llvm.store %79, %18 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %81 = arith.constant 0 : i32
    %82 = arith.extsi %81 : i32 to i64
    llvm.store %82, %18 : i64, !llvm.ptr
    cf.br ^bb15
    ^bb15:
    %83 = llvm.load %18 : !llvm.ptr -> i64
    %84 = arith.constant 1 : i32
    %86 = arith.extsi %84 : i32 to i64
    %85 = arith.subi %3, %86 : i64
    %87 = arith.cmpi slt, %83, %85 : i64
    cf.cond_br %87, ^bb16, ^bb17
    ^bb16:
      %89 = llvm.load %14 : !llvm.ptr -> !llvm.ptr
      %90 = llvm.load %18 : !llvm.ptr -> i64
      %91 = arith.addi %3, %90 : i64
      %92 = llvm.getelementptr %89[%91] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %88 = llvm.load %92 : !llvm.ptr -> i64
      %93 = arith.remsi %88, %1 : i64
      %95 = llvm.load %18 : !llvm.ptr -> i64
      %96 = llvm.getelementptr %arg2[%95] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %94 = llvm.load %96 : !llvm.ptr -> i64
      %97 = arith.addi %94, %93 : i64
      %98 = arith.remsi %97, %1 : i64
      %99 = llvm.load %18 : !llvm.ptr -> i64
      %100 = llvm.getelementptr %arg2[%99] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %98, %100 : i64, !llvm.ptr
      %102 = llvm.load %18 : !llvm.ptr -> i64
      %103 = arith.constant 1 : i32
      %105 = arith.extsi %103 : i32 to i64
      %104 = arith.addi %102, %105 : i64
      %106 = llvm.getelementptr %arg2[%104] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %101 = llvm.load %106 : !llvm.ptr -> i64
      %107 = arith.addi %101, %93 : i64
      %108 = arith.remsi %107, %1 : i64
      %109 = llvm.load %18 : !llvm.ptr -> i64
      %110 = arith.constant 1 : i32
      %112 = arith.extsi %110 : i32 to i64
      %111 = arith.addi %109, %112 : i64
      %113 = llvm.getelementptr %arg2[%111] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %108, %113 : i64, !llvm.ptr
      %114 = llvm.load %18 : !llvm.ptr -> i64
      %115 = arith.constant 1 : i32
      %117 = arith.extsi %115 : i32 to i64
      %116 = arith.addi %114, %117 : i64
      llvm.store %116, %18 : i64, !llvm.ptr
      cf.br ^bb15
    ^bb17:
    %119 = llvm.load %14 : !llvm.ptr -> !llvm.ptr
    func.call @free(%119) : (!llvm.ptr) -> ()
    func.return
  }
  func.func @main() -> i32 {
    %120 = arith.constant 20092010 : i32
    %121 = arith.extsi %120 : i32 to i64
    %122 = arith.constant 2000 : i32
    %123 = arith.extsi %122 : i32 to i64
    %124 = arith.constant 999999995705032704 : i32
    %125 = arith.extsi %124 : i32 to i64
    %127 = arith.constant 8 : i32
    %128 = arith.extsi %127 : i32 to i64
    %126 = func.call @calloc(%123, %128) : (i64, i64) -> !llvm.ptr
    %130 = arith.constant 8 : i32
    %131 = arith.extsi %130 : i32 to i64
    %129 = func.call @calloc(%123, %131) : (i64, i64) -> !llvm.ptr
    %133 = arith.constant 8 : i32
    %134 = arith.extsi %133 : i32 to i64
    %132 = func.call @calloc(%123, %134) : (i64, i64) -> !llvm.ptr
    %135 = llvm.mlir.zero : !llvm.ptr
    %136 = llvm.icmp "eq" %126, %135 : !llvm.ptr
    %137 = scf.if %136 -> (i1) {
      %138 = arith.constant true
      scf.yield %138 : i1
    } else {
      %139 = llvm.mlir.zero : !llvm.ptr
      %140 = llvm.icmp "eq" %129, %139 : !llvm.ptr
      scf.yield %140 : i1
    }
    %141 = scf.if %137 -> (i1) {
      %142 = arith.constant true
      scf.yield %142 : i1
    } else {
      %143 = llvm.mlir.zero : !llvm.ptr
      %144 = llvm.icmp "eq" %132, %143 : !llvm.ptr
      scf.yield %144 : i1
    }
    cf.cond_br %141, ^bb18, ^bb19
    ^bb18:
      %145 = arith.constant 1 : i32
      func.return %145 : i32
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %146 = arith.constant 1 : i32
    %147 = arith.constant 1 : i32
    %148 = arith.extsi %146 : i32 to i64
    %149 = arith.extsi %147 : i32 to i64
    %150 = llvm.getelementptr %126[%149] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %148, %150 : i64, !llvm.ptr
    %151 = arith.constant 1 : i32
    %152 = arith.constant 0 : i32
    %153 = arith.extsi %151 : i32 to i64
    %154 = arith.extsi %152 : i32 to i64
    %155 = llvm.getelementptr %129[%154] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %153, %155 : i64, !llvm.ptr
    %156 = llvm.mlir.constant(1 : i64) : i64
    %157 = llvm.alloca %156 x i64 : (i64) -> !llvm.ptr
    llvm.store %125, %157 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %158 = llvm.load %157 : !llvm.ptr -> i64
    %159 = arith.constant 0 : i32
    %161 = arith.extsi %159 : i32 to i64
    %160 = arith.cmpi sgt, %158, %161 : i64
    cf.cond_br %160, ^bb22, ^bb23
    ^bb22:
      %162 = llvm.load %157 : !llvm.ptr -> i64
      %163 = arith.constant 2 : i32
      %165 = arith.extsi %163 : i32 to i64
      %164 = arith.remsi %162, %165 : i64
      %166 = arith.constant 1 : i32
      %168 = arith.extsi %166 : i32 to i64
      %167 = arith.cmpi eq, %164, %168 : i64
      cf.cond_br %167, ^bb24, ^bb25
      ^bb24:
        func.call @mul_poly(%129, %126, %132) : (!llvm.ptr, !llvm.ptr, !llvm.ptr) -> ()
        %170 = arith.constant 0 : i32
        %171 = arith.extsi %170 : i32 to i64
        %172 = llvm.mlir.constant(1 : i64) : i64
        %173 = llvm.alloca %172 x i64 : (i64) -> !llvm.ptr
        llvm.store %171, %173 : i64, !llvm.ptr
        cf.br ^bb27
        ^bb27:
        %174 = llvm.load %173 : !llvm.ptr -> i64
        %175 = arith.cmpi slt, %174, %123 : i64
        cf.cond_br %175, ^bb28, ^bb29
        ^bb28:
          %177 = llvm.load %173 : !llvm.ptr -> i64
          %178 = llvm.getelementptr %132[%177] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %176 = llvm.load %178 : !llvm.ptr -> i64
          %179 = llvm.load %173 : !llvm.ptr -> i64
          %180 = llvm.getelementptr %129[%179] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %176, %180 : i64, !llvm.ptr
          %181 = llvm.load %173 : !llvm.ptr -> i64
          %182 = arith.constant 1 : i32
          %184 = arith.extsi %182 : i32 to i64
          %183 = arith.addi %181, %184 : i64
          llvm.store %183, %173 : i64, !llvm.ptr
          cf.br ^bb27
        ^bb29:
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      func.call @mul_poly(%126, %126, %132) : (!llvm.ptr, !llvm.ptr, !llvm.ptr) -> ()
      %186 = arith.constant 0 : i32
      %187 = arith.extsi %186 : i32 to i64
      %188 = llvm.mlir.constant(1 : i64) : i64
      %189 = llvm.alloca %188 x i64 : (i64) -> !llvm.ptr
      llvm.store %187, %189 : i64, !llvm.ptr
      cf.br ^bb30
      ^bb30:
      %190 = llvm.load %189 : !llvm.ptr -> i64
      %191 = arith.cmpi slt, %190, %123 : i64
      cf.cond_br %191, ^bb31, ^bb32
      ^bb31:
        %193 = llvm.load %189 : !llvm.ptr -> i64
        %194 = llvm.getelementptr %132[%193] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %192 = llvm.load %194 : !llvm.ptr -> i64
        %195 = llvm.load %189 : !llvm.ptr -> i64
        %196 = llvm.getelementptr %126[%195] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %192, %196 : i64, !llvm.ptr
        %197 = llvm.load %189 : !llvm.ptr -> i64
        %198 = arith.constant 1 : i32
        %200 = arith.extsi %198 : i32 to i64
        %199 = arith.addi %197, %200 : i64
        llvm.store %199, %189 : i64, !llvm.ptr
        cf.br ^bb30
      ^bb32:
      %201 = llvm.load %157 : !llvm.ptr -> i64
      %202 = arith.constant 2 : i32
      %204 = arith.extsi %202 : i32 to i64
      %203 = arith.divsi %201, %204 : i64
      llvm.store %203, %157 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %205 = arith.constant 0 : i32
    %206 = arith.extsi %205 : i32 to i64
    %207 = llvm.mlir.constant(1 : i64) : i64
    %208 = llvm.alloca %207 x i64 : (i64) -> !llvm.ptr
    llvm.store %206, %208 : i64, !llvm.ptr
    %209 = arith.constant 0 : i32
    %210 = arith.extsi %209 : i32 to i64
    %211 = llvm.mlir.constant(1 : i64) : i64
    %212 = llvm.alloca %211 x i64 : (i64) -> !llvm.ptr
    llvm.store %210, %212 : i64, !llvm.ptr
    cf.br ^bb33
    ^bb33:
    %213 = llvm.load %212 : !llvm.ptr -> i64
    %214 = arith.cmpi slt, %213, %123 : i64
    cf.cond_br %214, ^bb34, ^bb35
    ^bb34:
      %215 = llvm.load %208 : !llvm.ptr -> i64
      %217 = llvm.load %212 : !llvm.ptr -> i64
      %218 = llvm.getelementptr %129[%217] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %216 = llvm.load %218 : !llvm.ptr -> i64
      %219 = arith.addi %215, %216 : i64
      %220 = arith.remsi %219, %121 : i64
      llvm.store %220, %208 : i64, !llvm.ptr
      %221 = llvm.load %212 : !llvm.ptr -> i64
      %222 = arith.constant 1 : i32
      %224 = arith.extsi %222 : i32 to i64
      %223 = arith.addi %221, %224 : i64
      llvm.store %223, %212 : i64, !llvm.ptr
      cf.br ^bb33
    ^bb35:
    %225 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %226 = llvm.load %208 : !llvm.ptr -> i64
    %227 = llvm.call @printf(%225, %226) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%126) : (!llvm.ptr) -> ()
    func.call @free(%129) : (!llvm.ptr) -> ()
    func.call @free(%132) : (!llvm.ptr) -> ()
    %231 = arith.constant 0 : i32
    func.return %231 : i32
  }
}