Problem 602

Product of Head Counts — Eulerian number A(n, k-1) mod 1e9+7.

Answer269496760
Output269496760
StatusPASS
Native helperno
Runtime1670 ms
Peak memory16752 KB
Time complexityO(n) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n)O(n * s)
Space complexityO(n)O(s)
ApproachFlow solutionDP over cycle structure
VerdictUnknown

Flow source

# Project Euler 602
# Product of Head Counts — Eulerian number A(n, k-1) mod 1e9+7.

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 r: i64 = 1
    let mut b: i64 = base0 % mod
    if b < 0 { b = b + mod }
    let mut e: i64 = exp0
    while e > 0 {
        if (e & 1) == 1 {
            let t: i128 = (r as i128) * (b as i128) % (mod as i128)
            r = t as i64
        }
        let t2: i128 = (b as i128) * (b as i128) % (mod as i128)
        b = t2 as i64
        e = e / 2
    }
    return r
}

function eulerian(n: i64, m: i64) -> i64 {
    if n <= 0 { return 0 }
    if m < 0 || m >= n { return 0 }
    let M: i64 = m + 1
    let inv: ptr<i32> = calloc(M + 2, 4)
    if inv == null { return -1 }
    inv[1] = 1
    for i in 2..(M + 2) {
        let t: i64 = (MOD - (MOD / i) * (inv[MOD % i] as i64) % MOD) % MOD
        inv[i] = t as i32
    }
    let mut comb: i64 = 1
    let mut res: i64 = 0
    let n1: i64 = n + 1
    for j in 0..(M + 1) {
        let base: i64 = M - j
        if base != 0 {
            let term: i64 = (comb * modpow(base, n, MOD)) % MOD
            if (j & 1) == 1 {
                res = res - term
                if res < 0 { res = res + MOD }
            } else {
                res = res + term
                if res >= MOD { res = res - MOD }
            }
        }
        if j < M {
            comb = (comb * (n1 - j)) % MOD
            comb = (comb * (inv[j + 1] as i64)) % MOD
        }
    }
    free(inv)
    return res
}

function main() -> i32 {
    printf("%lld\n", eulerian(10000000, 3999999))
    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_i64(int64_t base0, int64_t exp0, int64_t mod);
int64_t eulerian_i64_i64(int64_t n, int64_t m);
int32_t main(void);

static const int64_t MOD = 1000000007;



int64_t modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod) {
    int64_t r = 1;
    int64_t b = FLOW_CHECKED_MOD((base0), (mod));
    if (b < 0) {
        b = (b + mod);
    }
    int64_t e = exp0;
    while (e > 0) {
        if ((e & 1) == 1) {
            __int128 t = FLOW_CHECKED_MOD(((((__int128)(r)) * ((__int128)(b)))), (((__int128)(mod))));
            r = ((int64_t)(t));
        }
        __int128 t2 = FLOW_CHECKED_MOD(((((__int128)(b)) * ((__int128)(b)))), (((__int128)(mod))));
        b = ((int64_t)(t2));
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return r;
}

int64_t eulerian_i64_i64(int64_t n, int64_t m) {
    if (n <= 0) {
        return 0;
    }
    if ((m < 0 || m >= n)) {
        return 0;
    }
    int64_t M = (m + 1);
    int32_t* inv = (int32_t*)(calloc((M + 2), 4));
    if (inv == NULL) {
        return (-1);
    }
    inv[1] = 1;
    int32_t __flow_step_1 = 1;
    for (int32_t i = 2; (2 <= (M + 2)) ? i < (M + 2) : i > (M + 2); i += (2 <= (M + 2)) ? 1 : -1) {
        int64_t t = FLOW_CHECKED_MOD(((MOD - FLOW_CHECKED_MOD(((FLOW_CHECKED_DIV((MOD), (i)) * ((int64_t)(inv[FLOW_CHECKED_MOD((MOD), (i))])))), (MOD)))), (MOD));
        inv[i] = ((int32_t)(t));
    }
    int64_t comb = 1;
    int64_t res = 0;
    int64_t n1 = (n + 1);
    int32_t __flow_step_2 = 1;
    for (int32_t j = 0; (0 <= (M + 1)) ? j < (M + 1) : j > (M + 1); j += (0 <= (M + 1)) ? 1 : -1) {
        int64_t base = (M - j);
        if (base != 0) {
            int64_t term = FLOW_CHECKED_MOD(((comb * modpow_i64_i64_i64(base, n, MOD))), (MOD));
            if ((j & 1) == 1) {
                res = (res - term);
                if (res < 0) {
                    res = (res + MOD);
                }
            } else {
                res = (res + term);
                if (res >= MOD) {
                    res = (res - MOD);
                }
            }
        }
        if (j < M) {
            comb = FLOW_CHECKED_MOD(((comb * (n1 - j))), (MOD));
            comb = FLOW_CHECKED_MOD(((comb * ((int64_t)(inv[(j + 1)])))), (MOD));
        }
    }
    free(inv);
    return res;
}

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