Problem 240

Dice top: 20d12, top 10 sum to 70.

Answer7448717393364181966
Output7448717393364181966
StatusPASS
Native helperno
Runtime40 ms
Peak memory1136 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 solutionDice distribution DP
VerdictUnknown

Flow source

# Project Euler 240
# Dice top: 20d12, top 10 sum to 70.

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

let mut NUM_DICE: i32 = 20
let mut MAX_POINTS: i32 = 12
let mut NUM_TOP: i32 = 10
let mut SUM_TOP: i32 = 70
let mut FACT: ptr<i64> = null
let mut DICES: ptr<i32> = null

function count_ways() -> i64 {
    let how: ptr<i32> = calloc((MAX_POINTS + 1) as i64, 4)
    let mut i: i32 = 0
    while i < NUM_DICE {
        how[DICES[i]] = how[DICES[i]] + 1
        i = i + 1
    }
    let mut result: i64 = FACT[NUM_DICE]
    i = 1
    while i <= MAX_POINTS {
        if how[i] > 1 {
            result = result / FACT[how[i]]
        }
        i = i + 1
    }
    free(how)
    return result
}

function search(len: i32) -> i64 {
    if len == NUM_DICE {
        return count_ways()
    }
    if len == NUM_TOP {
        let mut s: i32 = 0
        let mut i: i32 = 0
        while i < NUM_TOP {
            s = s + DICES[i]
            i = i + 1
        }
        if s != SUM_TOP { return 0 }
    }
    let mut max_dice: i32 = MAX_POINTS
    if len > 0 { max_dice = DICES[len - 1] }
    let mut result: i64 = 0
    let mut dice: i32 = 1
    while dice <= max_dice {
        DICES[len] = dice
        result = result + search(len + 1)
        dice = dice + 1
    }
    return result
}

function main() -> i32 {
    FACT = calloc((NUM_DICE + 1) as i64, 8)
    DICES = calloc(NUM_DICE as i64, 4)
    if FACT == null || DICES == null { return 1 }
    FACT[0] = 1
    let mut i: i32 = 1
    let mut cur: i64 = 1
    while i <= NUM_DICE {
        cur = cur * (i as i64)
        FACT[i] = cur
        i = i + 1
    }
    printf("%lld\n", search(0))
    free(FACT); free(DICES)
    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 count_ways(void);
int64_t search_i32(int32_t len);
int32_t main(void);

/* Module statics */
static int32_t NUM_DICE = 20;
static int32_t MAX_POINTS = 12;
static int32_t NUM_TOP = 10;
static int32_t SUM_TOP = 70;
static int64_t* FACT = NULL;
static int32_t* DICES = NULL;



int64_t count_ways(void) {
    int32_t* how = (int32_t*)(calloc(((int64_t)((MAX_POINTS + 1))), 4));
    int32_t i = 0;
    while (i < NUM_DICE) {
        how[DICES[i]] = (how[DICES[i]] + 1);
        i = (i + 1);
    }
    int64_t result = FACT[NUM_DICE];
    i = 1;
    while (i <= MAX_POINTS) {
        if (how[i] > 1) {
            result = FLOW_CHECKED_DIV((result), (FACT[how[i]]));
        }
        i = (i + 1);
    }
    free(how);
    return result;
}

int64_t search_i32(int32_t len) {
    if (len == NUM_DICE) {
        return count_ways();
    }
    if (len == NUM_TOP) {
        int32_t s = 0;
        int32_t i = 0;
        while (i < NUM_TOP) {
            s = (s + DICES[i]);
            i = (i + 1);
        }
        if (s != SUM_TOP) {
            return 0;
        }
    }
    int32_t max_dice = MAX_POINTS;
    if (len > 0) {
        max_dice = DICES[(len - 1)];
    }
    int64_t result = 0;
    int32_t dice = 1;
    while (dice <= max_dice) {
        DICES[len] = dice;
        result = (result + search_i32((len + 1)));
        dice = (dice + 1);
    }
    return result;
}

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