Problem 992

Journey counting on a path graph modulo a prime.

Answer568021234
Output568021234
StatusPASS
Native helperno
Runtime30 ms
Peak memory1344 KB
Time complexityO(n) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n)O(e log v)
Space complexityO(1)O(v)
ApproachFlow solutionKruskal or Prim algorithm
VerdictUnknown

Flow source

# Project Euler 992
# Journey counting on a path graph modulo a prime.

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

const MOD: i64 = 987898789

function mod_pow(a0: i64, e0: i64, mod: i64) -> i64 {
    let mut r: i64 = 1 % mod
    let mut a: i64 = a0 % mod
    if a < 0 { a = a + mod }
    let mut e: i64 = e0
    while e > 0 {
        if (e & 1) != 0 {
            r = ((r as i128) * (a as i128) % (mod as i128)) as i64
        }
        a = ((a as i128) * (a as i128) % (mod as i128)) as i64
        e = e >> 1
    }
    return r
}

function mod_inv(a: i64, mod: i64) -> i64 {
    return mod_pow(a, mod - 2, mod)
}

# Global combinatorics arrays
let mut g_fact: ptr<i64> = null
let mut g_inv_fact: ptr<i64> = null

function build_combinatorics(limit: i64, mod: i64) -> void {
    g_fact[0] = 1 % mod
    let mut i: i64 = 1
    while i <= limit {
        g_fact[i] = ((g_fact[i - 1] as i128) * (i as i128) % (mod as i128)) as i64
        i = i + 1
    }
    g_inv_fact[limit] = mod_inv(g_fact[limit], mod)
    i = limit
    while i >= 1 {
        g_inv_fact[i - 1] = ((g_inv_fact[i] as i128) * (i as i128) % (mod as i128)) as i64
        i = i - 1
    }
}

function comb(n: i64, r: i64) -> i64 {
    if r < 0 || r > n { return 0 }
    return ((g_fact[n] as i128) * (g_inv_fact[r] as i128) % (MOD as i128) * (g_inv_fact[n - r] as i128) % (MOD as i128)) as i64
}

function endpoint_count(n: i64, k: i64, end: i64) -> i64 {
    if n == 0 { return 1 }

    # right[i] for 0 <= i < n
    let right: ptr<i64> = malloc(n * 8)
    if end == 0 {
        right[0] = k - 1
    } else {
        right[0] = k
    }
    if n >= 2 {
        if end == 1 {
            right[1] = 2 - 1
        } else {
            right[1] = 2
        }
    }
    let mut i: i64 = 2
    while i < n {
        let mut val: i64 = 1 + right[i - 2]
        if end == i { val = val - 1 }
        right[i] = val
        i = i + 1
    }

    let mut ways: i64 = 1
    let mut v: i64 = 1
    while v < n {
        let mut out_degree: i64 = k + v
        if end == v { out_degree = out_degree - 1 }
        if v < end {
            ways = ((ways as i128) * (comb(out_degree - 1, right[v] - 1) as i128) % (MOD as i128)) as i64
        } else {
            if v == end {
                ways = ((ways as i128) * (comb(out_degree, right[v]) as i128) % (MOD as i128)) as i64
            } else {
                ways = ((ways as i128) * (comb(out_degree - 1, right[v]) as i128) % (MOD as i128)) as i64
            }
        }
        v = v + 1
    }
    free(right)
    return ways
}

function journey_count(n: i64, k: i64) -> i64 {
    let mut total: i64 = 0
    let mut end: i64 = 0
    while end <= n {
        total = total + endpoint_count(n, k, end)
        if total >= MOD { total = total - MOD }
        end = end + 1
    }
    return total
}

function main() -> i32 {
    let n: i64 = 500
    let ks: array<i64, 5> = [1, 10, 100, 1000, 10000]
    let mut max_k: i64 = 0
    let mut i: i64 = 0
    while i < 5 {
        if ks[i] > max_k { max_k = ks[i] }
        i = i + 1
    }
    g_fact = malloc((max_k + n + 1) * 8)
    g_inv_fact = malloc((max_k + n + 1) * 8)
    build_combinatorics(max_k + n, MOD)

    let mut answer: i64 = 0
    i = 0
    while i < 5 {
        answer = answer + journey_count(n, ks[i])
        if answer >= MOD { answer = answer - MOD }
        i = i + 1
    }

    printf("%lld\n", answer)
    free(g_fact)
    free(g_inv_fact)
    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 mod_pow_i64_i64_i64(int64_t a0, int64_t e0, int64_t mod);
int64_t mod_inv_i64_i64(int64_t a, int64_t mod);
void build_combinatorics_i64_i64(int64_t limit, int64_t mod);
int64_t comb_i64_i64(int64_t n, int64_t r);
int64_t endpoint_count_i64_i64_i64(int64_t n, int64_t k, int64_t end);
int64_t journey_count_i64_i64(int64_t n, int64_t k);
int32_t main(void);

static const int64_t MOD = 987898789;

/* Module statics */
static int64_t* g_fact = NULL;
static int64_t* g_inv_fact = NULL;




int64_t mod_pow_i64_i64_i64(int64_t a0, int64_t e0, int64_t mod) {
    int64_t r = FLOW_CHECKED_MOD((1), (mod));
    int64_t a = FLOW_CHECKED_MOD((a0), (mod));
    if (a < 0) {
        a = (a + mod);
    }
    int64_t e = e0;
    while (e > 0) {
        if ((e & 1) != 0) {
            r = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(r)) * ((__int128)(a)))), (((__int128)(mod))))));
        }
        a = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(a)) * ((__int128)(a)))), (((__int128)(mod))))));
        e = FLOW_CHECKED_SHR((e), (1));
    }
    return r;
}

int64_t mod_inv_i64_i64(int64_t a, int64_t mod) {
    return mod_pow_i64_i64_i64(a, (mod - 2), mod);
}

void build_combinatorics_i64_i64(int64_t limit, int64_t mod) {
    g_fact[0] = FLOW_CHECKED_MOD((1), (mod));
    int64_t i = 1;
    while (i <= limit) {
        g_fact[i] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(g_fact[(i - 1)])) * ((__int128)(i)))), (((__int128)(mod))))));
        i = (i + 1);
    }
    g_inv_fact[limit] = mod_inv_i64_i64(g_fact[limit], mod);
    i = limit;
    while (i >= 1) {
        g_inv_fact[(i - 1)] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(g_inv_fact[i])) * ((__int128)(i)))), (((__int128)(mod))))));
        i = (i - 1);
    }
}

int64_t comb_i64_i64(int64_t n, int64_t r) {
    if ((r < 0 || r > n)) {
        return 0;
    }
    return ((int64_t)(FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((((__int128)(g_fact[n])) * ((__int128)(g_inv_fact[r])))), (((__int128)(MOD)))) * ((__int128)(g_inv_fact[(n - r)])))), (((__int128)(MOD))))));
}

int64_t endpoint_count_i64_i64_i64(int64_t n, int64_t k, int64_t end) {
    if (n == 0) {
        return 1;
    }
    int64_t* right = (int64_t*)(malloc((n * 8)));
    if (end == 0) {
        right[0] = (k - 1);
    } else {
        right[0] = k;
    }
    if (n >= 2) {
        if (end == 1) {
            right[1] = (2 - 1);
        } else {
            right[1] = 2;
        }
    }
    int64_t i = 2;
    while (i < n) {
        int64_t val = (1 + right[(i - 2)]);
        if (end == i) {
            val = (val - 1);
        }
        right[i] = val;
        i = (i + 1);
    }
    int64_t ways = 1;
    int64_t v = 1;
    while (v < n) {
        int64_t out_degree = (k + v);
        if (end == v) {
            out_degree = (out_degree - 1);
        }
        if (v < end) {
            ways = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(ways)) * ((__int128)(comb_i64_i64((out_degree - 1), (right[v] - 1)))))), (((__int128)(MOD))))));
        } else {
            if (v == end) {
                ways = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(ways)) * ((__int128)(comb_i64_i64(out_degree, right[v]))))), (((__int128)(MOD))))));
            } else {
                ways = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(ways)) * ((__int128)(comb_i64_i64((out_degree - 1), right[v]))))), (((__int128)(MOD))))));
            }
        }
        v = (v + 1);
    }
    free(right);
    return ways;
}

int64_t journey_count_i64_i64(int64_t n, int64_t k) {
    int64_t total = 0;
    int64_t end = 0;
    while (end <= n) {
        total = (total + endpoint_count_i64_i64_i64(n, k, end));
        if (total >= MOD) {
            total = (total - MOD);
        }
        end = (end + 1);
    }
    return total;
}

int32_t main(void) {
    int64_t n = 500;
    int64_t ks[5] = { 1, 10, 100, 1000, 10000 };
    int64_t max_k = 0;
    int64_t i = 0;
    while (i < 5) {
        if ((((unsigned)(i) < 5) ? ks[i] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(i), 5), flow_fault_handler("array index out of bounds"), ks[0])) > max_k) {
            max_k = (((unsigned)(i) < 5) ? ks[i] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(i), 5), flow_fault_handler("array index out of bounds"), ks[0]));
        }
        i = (i + 1);
    }
    g_fact = malloc((((max_k + n) + 1) * 8));
    g_inv_fact = malloc((((max_k + n) + 1) * 8));
    build_combinatorics_i64_i64((max_k + n), MOD);
    int64_t answer = 0;
    i = 0;
    while (i < 5) {
        answer = (answer + journey_count_i64_i64(n, (((unsigned)(i) < 5) ? ks[i] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(i), 5), flow_fault_handler("array index out of bounds"), ks[0]))));
        if (answer >= MOD) {
            answer = (answer - MOD);
        }
        i = (i + 1);
    }
    printf("%lld\n", answer);
    free(g_fact);
    free(g_inv_fact);
    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 private @malloc(i64) -> !llvm.ptr
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(987898789 : i64) : i64
  func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %0 = arith.constant 1 : i32
    %2 = arith.extsi %0 : i32 to i64
    %1 = arith.remsi %2, %arg2 : i64
    %3 = llvm.mlir.constant(1 : i64) : i64
    %4 = llvm.alloca %3 x i64 : (i64) -> !llvm.ptr
    llvm.store %1, %4 : i64, !llvm.ptr
    %5 = arith.remsi %arg0, %arg2 : i64
    %6 = llvm.mlir.constant(1 : i64) : i64
    %7 = llvm.alloca %6 x i64 : (i64) -> !llvm.ptr
    llvm.store %5, %7 : i64, !llvm.ptr
    %8 = llvm.load %7 : !llvm.ptr -> i64
    %9 = arith.constant 0 : i32
    %11 = arith.extsi %9 : i32 to i64
    %10 = arith.cmpi slt, %8, %11 : i64
    cf.cond_br %10, ^bb0, ^bb1
    ^bb0:
      %12 = llvm.load %7 : !llvm.ptr -> i64
      %13 = arith.addi %12, %arg2 : i64
      llvm.store %13, %7 : i64, !llvm.ptr
      cf.br ^bb2
    ^bb1:
      cf.br ^bb2
    ^bb2:
    %14 = llvm.mlir.constant(1 : i64) : i64
    %15 = llvm.alloca %14 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %15 : i64, !llvm.ptr
    cf.br ^bb3
    ^bb3:
    %16 = llvm.load %15 : !llvm.ptr -> i64
    %17 = arith.constant 0 : i32
    %19 = arith.extsi %17 : i32 to i64
    %18 = arith.cmpi sgt, %16, %19 : i64
    cf.cond_br %18, ^bb4, ^bb5
    ^bb4:
      %20 = llvm.load %15 : !llvm.ptr -> i64
      %21 = arith.constant 1 : i32
      %23 = arith.extsi %21 : i32 to i64
      %22 = arith.andi %20, %23 : i64
      %24 = arith.constant 0 : i32
      %26 = arith.extsi %24 : i32 to i64
      %25 = arith.cmpi ne, %22, %26 : i64
      cf.cond_br %25, ^bb6, ^bb7
      ^bb6:
        %27 = llvm.load %4 : !llvm.ptr -> i64
        %28 = arith.extsi %27 : i64 to i128
        %29 = llvm.load %7 : !llvm.ptr -> i64
        %30 = arith.extsi %29 : i64 to i128
        %32 = arith.trunci %28 : i128 to i64
        %33 = arith.trunci %30 : i128 to i64
        %31 = arith.muli %32, %33 : i64
        %34 = arith.extsi %arg2 : i64 to i128
        %36 = arith.trunci %34 : i128 to i64
        %35 = arith.remsi %31, %36 : i64
        llvm.store %35, %4 : i64, !llvm.ptr
        cf.br ^bb8
      ^bb7:
        cf.br ^bb8
      ^bb8:
      %37 = llvm.load %7 : !llvm.ptr -> i64
      %38 = arith.extsi %37 : i64 to i128
      %39 = llvm.load %7 : !llvm.ptr -> i64
      %40 = arith.extsi %39 : i64 to i128
      %42 = arith.trunci %38 : i128 to i64
      %43 = arith.trunci %40 : i128 to i64
      %41 = arith.muli %42, %43 : i64
      %44 = arith.extsi %arg2 : i64 to i128
      %46 = arith.trunci %44 : i128 to i64
      %45 = arith.remsi %41, %46 : i64
      llvm.store %45, %7 : i64, !llvm.ptr
      %47 = llvm.load %15 : !llvm.ptr -> i64
      %48 = arith.constant 1 : i32
      %50 = arith.extsi %48 : i32 to i64
      %49 = arith.shrsi %47, %50 : i64
      llvm.store %49, %15 : i64, !llvm.ptr
      cf.br ^bb3
    ^bb5:
    %51 = llvm.load %4 : !llvm.ptr -> i64
    func.return %51 : i64
  }
  func.func @mod_inv(%arg0: i64, %arg1: i64) -> i64 {
    %53 = arith.constant 2 : i32
    %55 = arith.extsi %53 : i32 to i64
    %54 = arith.subi %arg1, %55 : i64
    %52 = func.call @mod_pow(%arg0, %54, %arg1) : (i64, i64, i64) -> i64
    func.return %52 : i64
  }
  // Module static: g_fact
  llvm.mlir.global internal @g_fact() {addr_space = 0 : i32} : !llvm.ptr {
    %56 = llvm.mlir.zero : !llvm.ptr
    llvm.return %56 : !llvm.ptr
  }
  // Module static: g_inv_fact
  llvm.mlir.global internal @g_inv_fact() {addr_space = 0 : i32} : !llvm.ptr {
    %57 = llvm.mlir.zero : !llvm.ptr
    llvm.return %57 : !llvm.ptr
  }
  func.func @build_combinatorics(%arg0: i64, %arg1: i64) -> () {
    %58 = arith.constant 1 : i32
    %60 = arith.extsi %58 : i32 to i64
    %59 = arith.remsi %60, %arg1 : i64
    %61 = llvm.mlir.addressof @g_fact : !llvm.ptr
    %62 = llvm.load %61 : !llvm.ptr -> !llvm.ptr
    %63 = arith.constant 0 : i32
    %64 = arith.extsi %63 : i32 to i64
    %65 = llvm.getelementptr %62[%64] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %59, %65 : i64, !llvm.ptr
    %66 = arith.constant 1 : i32
    %67 = arith.extsi %66 : i32 to i64
    %68 = llvm.mlir.constant(1 : i64) : i64
    %69 = llvm.alloca %68 x i64 : (i64) -> !llvm.ptr
    llvm.store %67, %69 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %70 = llvm.load %69 : !llvm.ptr -> i64
    %71 = arith.cmpi sle, %70, %arg0 : i64
    cf.cond_br %71, ^bb10, ^bb11
    ^bb10:
      %73 = llvm.mlir.addressof @g_fact : !llvm.ptr
      %74 = llvm.load %73 : !llvm.ptr -> !llvm.ptr
      %75 = llvm.load %69 : !llvm.ptr -> i64
      %76 = arith.constant 1 : i32
      %78 = arith.extsi %76 : i32 to i64
      %77 = arith.subi %75, %78 : i64
      %79 = llvm.getelementptr %74[%77] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %72 = llvm.load %79 : !llvm.ptr -> i64
      %80 = arith.extsi %72 : i64 to i128
      %81 = llvm.load %69 : !llvm.ptr -> i64
      %82 = arith.extsi %81 : i64 to i128
      %84 = arith.trunci %80 : i128 to i64
      %85 = arith.trunci %82 : i128 to i64
      %83 = arith.muli %84, %85 : i64
      %86 = arith.extsi %arg1 : i64 to i128
      %88 = arith.trunci %86 : i128 to i64
      %87 = arith.remsi %83, %88 : i64
      %89 = llvm.mlir.addressof @g_fact : !llvm.ptr
      %90 = llvm.load %89 : !llvm.ptr -> !llvm.ptr
      %91 = llvm.load %69 : !llvm.ptr -> i64
      %92 = llvm.getelementptr %90[%91] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %87, %92 : i64, !llvm.ptr
      %93 = llvm.load %69 : !llvm.ptr -> i64
      %94 = arith.constant 1 : i32
      %96 = arith.extsi %94 : i32 to i64
      %95 = arith.addi %93, %96 : i64
      llvm.store %95, %69 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %99 = llvm.mlir.addressof @g_fact : !llvm.ptr
    %100 = llvm.load %99 : !llvm.ptr -> !llvm.ptr
    %101 = llvm.getelementptr %100[%arg0] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %98 = llvm.load %101 : !llvm.ptr -> i64
    %97 = func.call @mod_inv(%98, %arg1) : (i64, i64) -> i64
    %102 = llvm.mlir.addressof @g_inv_fact : !llvm.ptr
    %103 = llvm.load %102 : !llvm.ptr -> !llvm.ptr
    %104 = llvm.getelementptr %103[%arg0] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %97, %104 : i64, !llvm.ptr
    llvm.store %arg0, %69 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %105 = llvm.load %69 : !llvm.ptr -> i64
    %106 = arith.constant 1 : i32
    %108 = arith.extsi %106 : i32 to i64
    %107 = arith.cmpi sge, %105, %108 : i64
    cf.cond_br %107, ^bb13, ^bb14
    ^bb13:
      %110 = llvm.mlir.addressof @g_inv_fact : !llvm.ptr
      %111 = llvm.load %110 : !llvm.ptr -> !llvm.ptr
      %112 = llvm.load %69 : !llvm.ptr -> i64
      %113 = llvm.getelementptr %111[%112] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %109 = llvm.load %113 : !llvm.ptr -> i64
      %114 = arith.extsi %109 : i64 to i128
      %115 = llvm.load %69 : !llvm.ptr -> i64
      %116 = arith.extsi %115 : i64 to i128
      %118 = arith.trunci %114 : i128 to i64
      %119 = arith.trunci %116 : i128 to i64
      %117 = arith.muli %118, %119 : i64
      %120 = arith.extsi %arg1 : i64 to i128
      %122 = arith.trunci %120 : i128 to i64
      %121 = arith.remsi %117, %122 : i64
      %123 = llvm.mlir.addressof @g_inv_fact : !llvm.ptr
      %124 = llvm.load %123 : !llvm.ptr -> !llvm.ptr
      %125 = llvm.load %69 : !llvm.ptr -> i64
      %126 = arith.constant 1 : i32
      %128 = arith.extsi %126 : i32 to i64
      %127 = arith.subi %125, %128 : i64
      %129 = llvm.getelementptr %124[%127] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %121, %129 : i64, !llvm.ptr
      %130 = llvm.load %69 : !llvm.ptr -> i64
      %131 = arith.constant 1 : i32
      %133 = arith.extsi %131 : i32 to i64
      %132 = arith.subi %130, %133 : i64
      llvm.store %132, %69 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    func.return
  }
  func.func @comb(%arg0: i64, %arg1: i64) -> i64 {
    %134 = arith.constant 0 : i32
    %136 = arith.extsi %134 : i32 to i64
    %135 = arith.cmpi slt, %arg1, %136 : i64
    %137 = scf.if %135 -> (i1) {
      %138 = arith.constant true
      scf.yield %138 : i1
    } else {
      %139 = arith.cmpi sgt, %arg1, %arg0 : i64
      scf.yield %139 : i1
    }
    cf.cond_br %137, ^bb15, ^bb16
    ^bb15:
      %140 = arith.constant 0 : i32
      %141 = arith.extsi %140 : i32 to i64
      func.return %141 : i64
    ^bb16:
      cf.br ^bb17
    ^bb17:
    %143 = llvm.mlir.addressof @g_fact : !llvm.ptr
    %144 = llvm.load %143 : !llvm.ptr -> !llvm.ptr
    %145 = llvm.getelementptr %144[%arg0] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %142 = llvm.load %145 : !llvm.ptr -> i64
    %146 = arith.extsi %142 : i64 to i128
    %148 = llvm.mlir.addressof @g_inv_fact : !llvm.ptr
    %149 = llvm.load %148 : !llvm.ptr -> !llvm.ptr
    %150 = llvm.getelementptr %149[%arg1] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %147 = llvm.load %150 : !llvm.ptr -> i64
    %151 = arith.extsi %147 : i64 to i128
    %153 = arith.trunci %146 : i128 to i64
    %154 = arith.trunci %151 : i128 to i64
    %152 = arith.muli %153, %154 : i64
    %155 = llvm.mlir.addressof @MOD : !llvm.ptr
    %156 = llvm.load %155 : !llvm.ptr -> i64
    %157 = arith.extsi %156 : i64 to i128
    %159 = arith.trunci %157 : i128 to i64
    %158 = arith.remsi %152, %159 : i64
    %161 = llvm.mlir.addressof @g_inv_fact : !llvm.ptr
    %162 = llvm.load %161 : !llvm.ptr -> !llvm.ptr
    %163 = arith.subi %arg0, %arg1 : i64
    %164 = llvm.getelementptr %162[%163] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %160 = llvm.load %164 : !llvm.ptr -> i64
    %165 = arith.extsi %160 : i64 to i128
    %167 = arith.trunci %165 : i128 to i64
    %166 = arith.muli %158, %167 : i64
    %168 = llvm.mlir.addressof @MOD : !llvm.ptr
    %169 = llvm.load %168 : !llvm.ptr -> i64
    %170 = arith.extsi %169 : i64 to i128
    %172 = arith.trunci %170 : i128 to i64
    %171 = arith.remsi %166, %172 : i64
    func.return %171 : i64
  }
  func.func @endpoint_count(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %173 = arith.constant 0 : i32
    %175 = arith.extsi %173 : i32 to i64
    %174 = arith.cmpi eq, %arg0, %175 : i64
    cf.cond_br %174, ^bb18, ^bb19
    ^bb18:
      %176 = arith.constant 1 : i32
      %177 = arith.extsi %176 : i32 to i64
      func.return %177 : i64
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %179 = arith.constant 8 : i32
    %181 = arith.extsi %179 : i32 to i64
    %180 = arith.muli %arg0, %181 : i64
    %178 = func.call @malloc(%180) : (i64) -> !llvm.ptr
    %182 = arith.constant 0 : i32
    %184 = arith.extsi %182 : i32 to i64
    %183 = arith.cmpi eq, %arg2, %184 : i64
    cf.cond_br %183, ^bb21, ^bb22
    ^bb21:
      %185 = arith.constant 1 : i32
      %187 = arith.extsi %185 : i32 to i64
      %186 = arith.subi %arg1, %187 : i64
      %188 = arith.constant 0 : i32
      %189 = arith.extsi %188 : i32 to i64
      %190 = llvm.getelementptr %178[%189] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %186, %190 : i64, !llvm.ptr
      cf.br ^bb23
    ^bb22:
      %191 = arith.constant 0 : i32
      %192 = arith.extsi %191 : i32 to i64
      %193 = llvm.getelementptr %178[%192] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %arg1, %193 : i64, !llvm.ptr
      cf.br ^bb23
    ^bb23:
    %194 = arith.constant 2 : i32
    %196 = arith.extsi %194 : i32 to i64
    %195 = arith.cmpi sge, %arg0, %196 : i64
    cf.cond_br %195, ^bb24, ^bb25
    ^bb24:
      %197 = arith.constant 1 : i32
      %199 = arith.extsi %197 : i32 to i64
      %198 = arith.cmpi eq, %arg2, %199 : i64
      cf.cond_br %198, ^bb27, ^bb28
      ^bb27:
        %200 = arith.constant 2 : i32
        %201 = arith.constant 1 : i32
        %202 = arith.subi %200, %201 : i32
        %203 = arith.constant 1 : i32
        %204 = arith.extsi %202 : i32 to i64
        %205 = arith.extsi %203 : i32 to i64
        %206 = llvm.getelementptr %178[%205] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %204, %206 : i64, !llvm.ptr
        cf.br ^bb29
      ^bb28:
        %207 = arith.constant 2 : i32
        %208 = arith.constant 1 : i32
        %209 = arith.extsi %207 : i32 to i64
        %210 = arith.extsi %208 : i32 to i64
        %211 = llvm.getelementptr %178[%210] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %209, %211 : i64, !llvm.ptr
        cf.br ^bb29
      ^bb29:
      cf.br ^bb26
    ^bb25:
      cf.br ^bb26
    ^bb26:
    %212 = arith.constant 2 : i32
    %213 = arith.extsi %212 : i32 to i64
    %214 = llvm.mlir.constant(1 : i64) : i64
    %215 = llvm.alloca %214 x i64 : (i64) -> !llvm.ptr
    llvm.store %213, %215 : i64, !llvm.ptr
    cf.br ^bb30
    ^bb30:
    %216 = llvm.load %215 : !llvm.ptr -> i64
    %217 = arith.cmpi slt, %216, %arg0 : i64
    cf.cond_br %217, ^bb31, ^bb32
    ^bb31:
      %218 = arith.constant 1 : i32
      %220 = llvm.load %215 : !llvm.ptr -> i64
      %221 = arith.constant 2 : i32
      %223 = arith.extsi %221 : i32 to i64
      %222 = arith.subi %220, %223 : i64
      %224 = llvm.getelementptr %178[%222] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %219 = llvm.load %224 : !llvm.ptr -> i64
      %226 = arith.extsi %218 : i32 to i64
      %225 = arith.addi %226, %219 : i64
      %227 = llvm.mlir.constant(1 : i64) : i64
      %228 = llvm.alloca %227 x i64 : (i64) -> !llvm.ptr
      llvm.store %225, %228 : i64, !llvm.ptr
      %229 = llvm.load %215 : !llvm.ptr -> i64
      %230 = arith.cmpi eq, %arg2, %229 : i64
      cf.cond_br %230, ^bb33, ^bb34
      ^bb33:
        %231 = llvm.load %228 : !llvm.ptr -> i64
        %232 = arith.constant 1 : i32
        %234 = arith.extsi %232 : i32 to i64
        %233 = arith.subi %231, %234 : i64
        llvm.store %233, %228 : i64, !llvm.ptr
        cf.br ^bb35
      ^bb34:
        cf.br ^bb35
      ^bb35:
      %235 = llvm.load %228 : !llvm.ptr -> i64
      %236 = llvm.load %215 : !llvm.ptr -> i64
      %237 = llvm.getelementptr %178[%236] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %235, %237 : i64, !llvm.ptr
      %238 = llvm.load %215 : !llvm.ptr -> i64
      %239 = arith.constant 1 : i32
      %241 = arith.extsi %239 : i32 to i64
      %240 = arith.addi %238, %241 : i64
      llvm.store %240, %215 : i64, !llvm.ptr
      cf.br ^bb30
    ^bb32:
    %242 = arith.constant 1 : i32
    %243 = arith.extsi %242 : i32 to i64
    %244 = llvm.mlir.constant(1 : i64) : i64
    %245 = llvm.alloca %244 x i64 : (i64) -> !llvm.ptr
    llvm.store %243, %245 : i64, !llvm.ptr
    %246 = arith.constant 1 : i32
    %247 = arith.extsi %246 : i32 to i64
    %248 = llvm.mlir.constant(1 : i64) : i64
    %249 = llvm.alloca %248 x i64 : (i64) -> !llvm.ptr
    llvm.store %247, %249 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %250 = llvm.load %249 : !llvm.ptr -> i64
    %251 = arith.cmpi slt, %250, %arg0 : i64
    cf.cond_br %251, ^bb37, ^bb38
    ^bb37:
      %252 = llvm.load %249 : !llvm.ptr -> i64
      %253 = arith.addi %arg1, %252 : i64
      %254 = llvm.mlir.constant(1 : i64) : i64
      %255 = llvm.alloca %254 x i64 : (i64) -> !llvm.ptr
      llvm.store %253, %255 : i64, !llvm.ptr
      %256 = llvm.load %249 : !llvm.ptr -> i64
      %257 = arith.cmpi eq, %arg2, %256 : i64
      cf.cond_br %257, ^bb39, ^bb40
      ^bb39:
        %258 = llvm.load %255 : !llvm.ptr -> i64
        %259 = arith.constant 1 : i32
        %261 = arith.extsi %259 : i32 to i64
        %260 = arith.subi %258, %261 : i64
        llvm.store %260, %255 : i64, !llvm.ptr
        cf.br ^bb41
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %262 = llvm.load %249 : !llvm.ptr -> i64
      %263 = arith.cmpi slt, %262, %arg2 : i64
      cf.cond_br %263, ^bb42, ^bb43
      ^bb42:
        %264 = llvm.load %245 : !llvm.ptr -> i64
        %265 = arith.extsi %264 : i64 to i128
        %267 = llvm.load %255 : !llvm.ptr -> i64
        %268 = arith.constant 1 : i32
        %270 = arith.extsi %268 : i32 to i64
        %269 = arith.subi %267, %270 : i64
        %272 = llvm.load %249 : !llvm.ptr -> i64
        %273 = llvm.getelementptr %178[%272] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %271 = llvm.load %273 : !llvm.ptr -> i64
        %274 = arith.constant 1 : i32
        %276 = arith.extsi %274 : i32 to i64
        %275 = arith.subi %271, %276 : i64
        %266 = func.call @comb(%269, %275) : (i64, i64) -> i64
        %277 = arith.extsi %266 : i64 to i128
        %279 = arith.trunci %265 : i128 to i64
        %280 = arith.trunci %277 : i128 to i64
        %278 = arith.muli %279, %280 : i64
        %281 = llvm.mlir.addressof @MOD : !llvm.ptr
        %282 = llvm.load %281 : !llvm.ptr -> i64
        %283 = arith.extsi %282 : i64 to i128
        %285 = arith.trunci %283 : i128 to i64
        %284 = arith.remsi %278, %285 : i64
        llvm.store %284, %245 : i64, !llvm.ptr
        cf.br ^bb44
      ^bb43:
        %286 = llvm.load %249 : !llvm.ptr -> i64
        %287 = arith.cmpi eq, %286, %arg2 : i64
        cf.cond_br %287, ^bb45, ^bb46
        ^bb45:
          %288 = llvm.load %245 : !llvm.ptr -> i64
          %289 = arith.extsi %288 : i64 to i128
          %291 = llvm.load %255 : !llvm.ptr -> i64
          %293 = llvm.load %249 : !llvm.ptr -> i64
          %294 = llvm.getelementptr %178[%293] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %292 = llvm.load %294 : !llvm.ptr -> i64
          %290 = func.call @comb(%291, %292) : (i64, i64) -> i64
          %295 = arith.extsi %290 : i64 to i128
          %297 = arith.trunci %289 : i128 to i64
          %298 = arith.trunci %295 : i128 to i64
          %296 = arith.muli %297, %298 : i64
          %299 = llvm.mlir.addressof @MOD : !llvm.ptr
          %300 = llvm.load %299 : !llvm.ptr -> i64
          %301 = arith.extsi %300 : i64 to i128
          %303 = arith.trunci %301 : i128 to i64
          %302 = arith.remsi %296, %303 : i64
          llvm.store %302, %245 : i64, !llvm.ptr
          cf.br ^bb47
        ^bb46:
          %304 = llvm.load %245 : !llvm.ptr -> i64
          %305 = arith.extsi %304 : i64 to i128
          %307 = llvm.load %255 : !llvm.ptr -> i64
          %308 = arith.constant 1 : i32
          %310 = arith.extsi %308 : i32 to i64
          %309 = arith.subi %307, %310 : i64
          %312 = llvm.load %249 : !llvm.ptr -> i64
          %313 = llvm.getelementptr %178[%312] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %311 = llvm.load %313 : !llvm.ptr -> i64
          %306 = func.call @comb(%309, %311) : (i64, i64) -> i64
          %314 = arith.extsi %306 : i64 to i128
          %316 = arith.trunci %305 : i128 to i64
          %317 = arith.trunci %314 : i128 to i64
          %315 = arith.muli %316, %317 : i64
          %318 = llvm.mlir.addressof @MOD : !llvm.ptr
          %319 = llvm.load %318 : !llvm.ptr -> i64
          %320 = arith.extsi %319 : i64 to i128
          %322 = arith.trunci %320 : i128 to i64
          %321 = arith.remsi %315, %322 : i64
          llvm.store %321, %245 : i64, !llvm.ptr
          cf.br ^bb47
        ^bb47:
        cf.br ^bb44
      ^bb44:
      %323 = llvm.load %249 : !llvm.ptr -> i64
      %324 = arith.constant 1 : i32
      %326 = arith.extsi %324 : i32 to i64
      %325 = arith.addi %323, %326 : i64
      llvm.store %325, %249 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    func.call @free(%178) : (!llvm.ptr) -> ()
    %328 = llvm.load %245 : !llvm.ptr -> i64
    func.return %328 : i64
  }
  func.func @journey_count(%arg0: i64, %arg1: i64) -> i64 {
    %329 = arith.constant 0 : i32
    %330 = arith.extsi %329 : i32 to i64
    %331 = llvm.mlir.constant(1 : i64) : i64
    %332 = llvm.alloca %331 x i64 : (i64) -> !llvm.ptr
    llvm.store %330, %332 : i64, !llvm.ptr
    %333 = arith.constant 0 : i32
    %334 = arith.extsi %333 : i32 to i64
    %335 = llvm.mlir.constant(1 : i64) : i64
    %336 = llvm.alloca %335 x i64 : (i64) -> !llvm.ptr
    llvm.store %334, %336 : i64, !llvm.ptr
    cf.br ^bb48
    ^bb48:
    %337 = llvm.load %336 : !llvm.ptr -> i64
    %338 = arith.cmpi sle, %337, %arg0 : i64
    cf.cond_br %338, ^bb49, ^bb50
    ^bb49:
      %339 = llvm.load %332 : !llvm.ptr -> i64
      %341 = llvm.load %336 : !llvm.ptr -> i64
      %340 = func.call @endpoint_count(%arg0, %arg1, %341) : (i64, i64, i64) -> i64
      %342 = arith.addi %339, %340 : i64
      llvm.store %342, %332 : i64, !llvm.ptr
      %343 = llvm.load %332 : !llvm.ptr -> i64
      %344 = llvm.mlir.addressof @MOD : !llvm.ptr
      %345 = llvm.load %344 : !llvm.ptr -> i64
      %346 = arith.cmpi sge, %343, %345 : i64
      cf.cond_br %346, ^bb51, ^bb52
      ^bb51:
        %347 = llvm.load %332 : !llvm.ptr -> i64
        %348 = llvm.mlir.addressof @MOD : !llvm.ptr
        %349 = llvm.load %348 : !llvm.ptr -> i64
        %350 = arith.subi %347, %349 : i64
        llvm.store %350, %332 : i64, !llvm.ptr
        cf.br ^bb53
      ^bb52:
        cf.br ^bb53
      ^bb53:
      %351 = llvm.load %336 : !llvm.ptr -> i64
      %352 = arith.constant 1 : i32
      %354 = arith.extsi %352 : i32 to i64
      %353 = arith.addi %351, %354 : i64
      llvm.store %353, %336 : i64, !llvm.ptr
      cf.br ^bb48
    ^bb50:
    %355 = llvm.load %332 : !llvm.ptr -> i64
    func.return %355 : i64
  }
  func.func @main() -> i32 {
    %356 = arith.constant 500 : i32
    %357 = arith.extsi %356 : i32 to i64
    %359 = arith.constant 1 : i32
    %360 = arith.constant 10 : i32
    %361 = arith.constant 100 : i32
    %362 = arith.constant 1000 : i32
    %363 = arith.constant 10000 : i32
    %364 = llvm.mlir.constant(1 : i64) : i64
    %365 = llvm.alloca %364 x !llvm.array<5 x i64> : (i64) -> !llvm.ptr
    %366 = llvm.mlir.zero : !llvm.array<5 x i64>
    llvm.store %366, %365 : !llvm.array<5 x i64>, !llvm.ptr
    %367 = arith.extsi %359 : i32 to i64
    %368 = arith.extsi %360 : i32 to i64
    %369 = arith.extsi %361 : i32 to i64
    %370 = arith.extsi %362 : i32 to i64
    %371 = arith.extsi %363 : i32 to i64
    %372 = llvm.mlir.constant(0 : i64) : i64
    %373 = llvm.getelementptr %365[0, %372] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %367, %373 : i64, !llvm.ptr
    %374 = llvm.mlir.constant(1 : i64) : i64
    %375 = llvm.getelementptr %365[0, %374] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %368, %375 : i64, !llvm.ptr
    %376 = llvm.mlir.constant(2 : i64) : i64
    %377 = llvm.getelementptr %365[0, %376] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %369, %377 : i64, !llvm.ptr
    %378 = llvm.mlir.constant(3 : i64) : i64
    %379 = llvm.getelementptr %365[0, %378] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %370, %379 : i64, !llvm.ptr
    %380 = llvm.mlir.constant(4 : i64) : i64
    %381 = llvm.getelementptr %365[0, %380] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %371, %381 : i64, !llvm.ptr
    %382 = arith.constant 0 : i32
    %383 = arith.extsi %382 : i32 to i64
    %384 = llvm.mlir.constant(1 : i64) : i64
    %385 = llvm.alloca %384 x i64 : (i64) -> !llvm.ptr
    llvm.store %383, %385 : i64, !llvm.ptr
    %386 = arith.constant 0 : i32
    %387 = arith.extsi %386 : i32 to i64
    %388 = llvm.mlir.constant(1 : i64) : i64
    %389 = llvm.alloca %388 x i64 : (i64) -> !llvm.ptr
    llvm.store %387, %389 : i64, !llvm.ptr
    cf.br ^bb54
    ^bb54:
    %390 = llvm.load %389 : !llvm.ptr -> i64
    %391 = arith.constant 5 : i32
    %393 = arith.extsi %391 : i32 to i64
    %392 = arith.cmpi slt, %390, %393 : i64
    cf.cond_br %392, ^bb55, ^bb56
    ^bb55:
      %395 = llvm.load %389 : !llvm.ptr -> i64
      %396 = llvm.getelementptr %365[0, %395] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
      %394 = llvm.load %396 : !llvm.ptr -> i64
      %397 = llvm.load %385 : !llvm.ptr -> i64
      %398 = arith.cmpi sgt, %394, %397 : i64
      cf.cond_br %398, ^bb57, ^bb58
      ^bb57:
        %400 = llvm.load %389 : !llvm.ptr -> i64
        %401 = llvm.getelementptr %365[0, %400] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
        %399 = llvm.load %401 : !llvm.ptr -> i64
        llvm.store %399, %385 : i64, !llvm.ptr
        cf.br ^bb59
      ^bb58:
        cf.br ^bb59
      ^bb59:
      %402 = llvm.load %389 : !llvm.ptr -> i64
      %403 = arith.constant 1 : i32
      %405 = arith.extsi %403 : i32 to i64
      %404 = arith.addi %402, %405 : i64
      llvm.store %404, %389 : i64, !llvm.ptr
      cf.br ^bb54
    ^bb56:
    %407 = llvm.load %385 : !llvm.ptr -> i64
    %408 = arith.addi %407, %357 : i64
    %409 = arith.constant 1 : i32
    %411 = arith.extsi %409 : i32 to i64
    %410 = arith.addi %408, %411 : i64
    %412 = arith.constant 8 : i32
    %414 = arith.extsi %412 : i32 to i64
    %413 = arith.muli %410, %414 : i64
    %406 = func.call @malloc(%413) : (i64) -> !llvm.ptr
    %415 = llvm.mlir.addressof @g_fact : !llvm.ptr
    llvm.store %406, %415 : !llvm.ptr, !llvm.ptr
    %417 = llvm.load %385 : !llvm.ptr -> i64
    %418 = arith.addi %417, %357 : i64
    %419 = arith.constant 1 : i32
    %421 = arith.extsi %419 : i32 to i64
    %420 = arith.addi %418, %421 : i64
    %422 = arith.constant 8 : i32
    %424 = arith.extsi %422 : i32 to i64
    %423 = arith.muli %420, %424 : i64
    %416 = func.call @malloc(%423) : (i64) -> !llvm.ptr
    %425 = llvm.mlir.addressof @g_inv_fact : !llvm.ptr
    llvm.store %416, %425 : !llvm.ptr, !llvm.ptr
    %427 = llvm.load %385 : !llvm.ptr -> i64
    %428 = arith.addi %427, %357 : i64
    %429 = llvm.mlir.addressof @MOD : !llvm.ptr
    %430 = llvm.load %429 : !llvm.ptr -> i64
    func.call @build_combinatorics(%428, %430) : (i64, i64) -> ()
    %431 = arith.constant 0 : i32
    %432 = arith.extsi %431 : i32 to i64
    %433 = llvm.mlir.constant(1 : i64) : i64
    %434 = llvm.alloca %433 x i64 : (i64) -> !llvm.ptr
    llvm.store %432, %434 : i64, !llvm.ptr
    %435 = arith.constant 0 : i32
    %436 = arith.extsi %435 : i32 to i64
    llvm.store %436, %389 : i64, !llvm.ptr
    cf.br ^bb60
    ^bb60:
    %437 = llvm.load %389 : !llvm.ptr -> i64
    %438 = arith.constant 5 : i32
    %440 = arith.extsi %438 : i32 to i64
    %439 = arith.cmpi slt, %437, %440 : i64
    cf.cond_br %439, ^bb61, ^bb62
    ^bb61:
      %441 = llvm.load %434 : !llvm.ptr -> i64
      %444 = llvm.load %389 : !llvm.ptr -> i64
      %445 = llvm.getelementptr %365[0, %444] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
      %443 = llvm.load %445 : !llvm.ptr -> i64
      %442 = func.call @journey_count(%357, %443) : (i64, i64) -> i64
      %446 = arith.addi %441, %442 : i64
      llvm.store %446, %434 : i64, !llvm.ptr
      %447 = llvm.load %434 : !llvm.ptr -> i64
      %448 = llvm.mlir.addressof @MOD : !llvm.ptr
      %449 = llvm.load %448 : !llvm.ptr -> i64
      %450 = arith.cmpi sge, %447, %449 : i64
      cf.cond_br %450, ^bb63, ^bb64
      ^bb63:
        %451 = llvm.load %434 : !llvm.ptr -> i64
        %452 = llvm.mlir.addressof @MOD : !llvm.ptr
        %453 = llvm.load %452 : !llvm.ptr -> i64
        %454 = arith.subi %451, %453 : i64
        llvm.store %454, %434 : i64, !llvm.ptr
        cf.br ^bb65
      ^bb64:
        cf.br ^bb65
      ^bb65:
      %455 = llvm.load %389 : !llvm.ptr -> i64
      %456 = arith.constant 1 : i32
      %458 = arith.extsi %456 : i32 to i64
      %457 = arith.addi %455, %458 : i64
      llvm.store %457, %389 : i64, !llvm.ptr
      cf.br ^bb60
    ^bb62:
    %459 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %460 = llvm.load %434 : !llvm.ptr -> i64
    %461 = llvm.call @printf(%459, %460) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %463 = llvm.mlir.addressof @g_fact : !llvm.ptr
    %464 = llvm.load %463 : !llvm.ptr -> !llvm.ptr
    func.call @free(%464) : (!llvm.ptr) -> ()
    %466 = llvm.mlir.addressof @g_inv_fact : !llvm.ptr
    %467 = llvm.load %466 : !llvm.ptr -> !llvm.ptr
    func.call @free(%467) : (!llvm.ptr) -> ()
    %468 = arith.constant 0 : i32
    func.return %468 : i32
  }
}