Problem 062

Smallest cube for which exactly five permutations of its digits are cube.

Answer127035954683
Output127035954683
StatusPASS
Native helperno
Runtime40 ms
Peak memory1344 KB
Time complexityO(n) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n)O(n!)
Space complexityO(n^2)O(n)
ApproachFlow solutionPermutation enumeration or constraint search
VerdictOptimal

Flow source

# Project Euler 062
# Smallest cube for which exactly five permutations of its digits are cube.

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

function digit_sig_into(n: i64, sigs: ptr<i8>, row: i32) -> void {
    let cnt: ptr<i32> = calloc(10, 4)
    if cnt == null { return }
    let mut x: i64 = n
    if x == 0 {
        cnt[0] = 1
    }
    while x > 0 {
        let d: i32 = (x % 10) as i32
        cnt[d] = cnt[d] + 1
        x = x / 10
    }
    let mut i: i32 = 0
    while i < 10 {
        sigs[row * 10 + i] = cnt[i] as i8
        i = i + 1
    }
    free(cnt)
}

function sig_eq(sigs: ptr<i8>, a: i32, b: i32) -> bool {
    let mut i: i32 = 0
    while i < 10 {
        if sigs[a * 10 + i] != sigs[b * 10 + i] { return false }
        i = i + 1
    }
    return true
}

function num_digits(n: i64) -> i32 {
    if n == 0 { return 1 }
    let mut c: i32 = 0
    let mut x: i64 = n
    while x > 0 {
        c = c + 1
        x = x / 10
    }
    return c
}

function main() -> i32 {
    let limit: i32 = 10000
    let sigs: ptr<i8> = calloc((limit * 10) as i64, 1)
    let cubes: ptr<i64> = calloc(limit as i64, 8)
    let seen: ptr<i8> = calloc(limit as i64, 1)
    if sigs == null || cubes == null || seen == null { return 1 }

    let mut n: i32 = 1
    while n < limit {
        let ni: i64 = n as i64
        let c: i64 = ni * ni * ni
        cubes[n] = c
        digit_sig_into(c, sigs, n)
        n = n + 1
    }

    let mut ans: i64 = 0
    let mut i: i32 = 1
    while i < limit {
        if seen[i] != 0 {
            i = i + 1
            continue
        }
        let digs_i: i32 = num_digits(cubes[i])
        let mut cnt: i32 = 1
        let mut j: i32 = i + 1
        while j < limit {
            let digs_j: i32 = num_digits(cubes[j])
            if digs_j > digs_i { break }
            if sig_eq(sigs, i, j) {
                cnt = cnt + 1
                seen[j] = 1
            }
            j = j + 1
        }
        seen[i] = 1
        if cnt == 5 {
            ans = cubes[i]
            break
        }
        i = i + 1
    }
    printf("%lld\n", ans)
    free(seen)
    free(cubes)
    free(sigs)
    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 digit_sig_into_i64_ptr_i8_i32(int64_t n, int8_t* sigs, int32_t row);
bool sig_eq_ptr_i8_i32_i32(int8_t* sigs, int32_t a, int32_t b);
int32_t num_digits_i64(int64_t n);
int32_t main(void);



void digit_sig_into_i64_ptr_i8_i32(int64_t n, int8_t* sigs, int32_t row) {
    int32_t* cnt = (int32_t*)(calloc(10, 4));
    if (cnt == NULL) {
        return;
    }
    int64_t x = n;
    if (x == 0) {
        cnt[0] = 1;
    }
    while (x > 0) {
        int32_t d = ((int32_t)(FLOW_CHECKED_MOD((x), (10))));
        cnt[d] = (cnt[d] + 1);
        x = FLOW_CHECKED_DIV((x), (10));
    }
    int32_t i = 0;
    while (i < 10) {
        sigs[((row * 10) + i)] = ((int8_t)(cnt[i]));
        i = (i + 1);
    }
    free(cnt);
}

bool sig_eq_ptr_i8_i32_i32(int8_t* sigs, int32_t a, int32_t b) {
    int32_t i = 0;
    while (i < 10) {
        if (sigs[((a * 10) + i)] != sigs[((b * 10) + i)]) {
            return 0;
        }
        i = (i + 1);
    }
    return 1;
}

int32_t num_digits_i64(int64_t n) {
    if (n == 0) {
        return 1;
    }
    int32_t c = 0;
    int64_t x = n;
    while (x > 0) {
        c = (c + 1);
        x = FLOW_CHECKED_DIV((x), (10));
    }
    return c;
}

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