Problem 156

Sum of n where f(n,d)=n for digits d=1..9.

Answer21295121502550
Output21295121502550
StatusPASS
Native helperno
Runtime0 ms
Peak memory1104 KB
Time complexityO(2^n) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(2^n)O(n log log n)
Space complexityO(1)O(n)
ApproachFlow solutionSieve or enumeration
VerdictSuboptimal

Flow source

# Project Euler 156
# Sum of n where f(n,d)=n for digits d=1..9.

function count_single(digit: i64, value0: i64) -> i64 {
    if value0 == 0 && digit == 0 { return 1 }
    let mut result: i64 = 0
    let mut value: i64 = value0
    while value > 0 {
        if value % 10 == digit { result = result + 1 }
        value = value / 10
    }
    return result
}

function count_digit(digit: i64, value: i64) -> i64 {
    if value < 10 {
        if value < digit { return 0 }
        return 1
    }
    let mut shift: i64 = 1
    let mut multiplier: i64 = 0
    while shift * 10 <= value {
        shift = shift * 10
        multiplier = multiplier + 1
    }
    multiplier = multiplier * (shift / 10)

    let first: i64 = value / shift
    let remainder: i64 = value % shift
    let mut result: i64 = first * multiplier + count_digit(digit, remainder)
    if digit == first {
        result = result + remainder + 1
    }
    if digit < first && digit > 0 {
        result = result + shift
    }
    return result
}

function find_all(digit: i64, start0: i64, end0: i64) -> i64 {
    let mut start: i64 = start0
    let end: i64 = end0
    let center0: i64 = (start + end) / 2
    if start == center0 {
        let current: i64 = count_digit(digit, start)
        if current == start { return start }
        return 0
    }

    let mut result: i64 = 0
    let mut count_from: i64 = count_digit(digit, start)

    while count_from == start && start < end {
        result = result + start
        start = start + 1
        count_from = count_from + count_single(digit, start)
    }
    if start >= end + 1 {
        return result
    }

    let center: i64 = (start + end) / 2
    let count_center: i64 = count_digit(digit, center)
    let count_to: i64 = count_digit(digit, end)

    if count_center >= start && center >= count_from && center > start {
        result = result + find_all(digit, start, center)
    }
    if count_to >= center && end >= count_center && center < end {
        result = result + find_all(digit, center, end)
    }
    return result
}

function main() -> i32 {
    let limit: i64 = 1000000000000
    let mut total: i64 = 0
    let mut d: i64 = 1
    while d <= 9 {
        total = total + find_all(d, 0, limit)
        d = d + 1
    }
    printf("%lld\n", total)
    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_single_i64_i64(int64_t digit, int64_t value0);
int64_t count_digit_i64_i64(int64_t digit, int64_t value);
int64_t find_all_i64_i64_i64(int64_t digit, int64_t start0, int64_t end0);
int32_t main(void);

int64_t count_single_i64_i64(int64_t digit, int64_t value0) {
    if ((value0 == 0 && digit == 0)) {
        return 1;
    }
    int64_t result = 0;
    int64_t value = value0;
    while (value > 0) {
        if (FLOW_CHECKED_MOD((value), (10)) == digit) {
            result = (result + 1);
        }
        value = FLOW_CHECKED_DIV((value), (10));
    }
    return result;
}

int64_t count_digit_i64_i64(int64_t digit, int64_t value) {
    if (value < 10) {
        if (value < digit) {
            return 0;
        }
        return 1;
    }
    int64_t shift = 1;
    int64_t multiplier = 0;
    while ((shift * 10) <= value) {
        shift = (shift * 10);
        multiplier = (multiplier + 1);
    }
    multiplier = (multiplier * FLOW_CHECKED_DIV((shift), (10)));
    int64_t first = FLOW_CHECKED_DIV((value), (shift));
    int64_t remainder = FLOW_CHECKED_MOD((value), (shift));
    int64_t result = ((first * multiplier) + count_digit_i64_i64(digit, remainder));
    if (digit == first) {
        result = ((result + remainder) + 1);
    }
    if ((digit < first && digit > 0)) {
        result = (result + shift);
    }
    return result;
}

int64_t find_all_i64_i64_i64(int64_t digit, int64_t start0, int64_t end0) {
    int64_t start = start0;
    int64_t end = end0;
    int64_t center0 = FLOW_CHECKED_DIV(((start + end)), (2));
    if (start == center0) {
        int64_t current = count_digit_i64_i64(digit, start);
        if (current == start) {
            return start;
        }
        return 0;
    }
    int64_t result = 0;
    int64_t count_from = count_digit_i64_i64(digit, start);
    while ((count_from == start && start < end)) {
        result = (result + start);
        start = (start + 1);
        count_from = (count_from + count_single_i64_i64(digit, start));
    }
    if (start >= (end + 1)) {
        return result;
    }
    int64_t center = FLOW_CHECKED_DIV(((start + end)), (2));
    int64_t count_center = count_digit_i64_i64(digit, center);
    int64_t count_to = count_digit_i64_i64(digit, end);
    if (((count_center >= start && center >= count_from) && center > start)) {
        result = (result + find_all_i64_i64_i64(digit, start, center));
    }
    if (((count_to >= center && end >= count_center) && center < end)) {
        result = (result + find_all_i64_i64_i64(digit, center, end));
    }
    return result;
}

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