← All problems
Problem 571
Super Pandigital Numbers Sum of the first 10 12-super-pandigital numbers (pandigital in bases 2..12).
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n)O(n!)
Space complexity O(n)O(n)
Approach Flow solution Permutation enumeration or constraint search
Verdict Optimal
Flow source
# Project Euler 571
# Super Pandigital Numbers
# Sum of the first 10 12-super-pandigital numbers (pandigital in bases 2..12).
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
const BASE: i64 = 12
const NEED: i64 = 10
let mut DIGITS: ptr<i64> = null
let mut USED: ptr<i8> = null
let mut FOUND: i64 = 0
let mut TOTAL: i64 = 0
function is_pandigital(number0: i64, base: i64, all_bits: i64) -> i32 {
let mut number: i64 = number0
let mut used: i64 = 0
while number > 0 {
let digit: i64 = number % base
used = used | (1 << digit)
if used == all_bits { return 1 }
number = number / base
}
if used == all_bits { return 1 }
return 0
}
function is_pandigital_base8(number0: i64) -> i32 {
let mut number: i64 = number0
let mut used: i64 = 0
while number > 0 {
used = used | (1 << (number & 7))
if used == 255 { return 1 }
number = number >> 3
}
if used == 255 { return 1 }
return 0
}
function check(current: i64) -> i32 {
if is_pandigital_base8(current) == 0 { return 0 }
let mut b: i64 = 11
while b >= 2 {
if b != 8 {
let all_bits: i64 = (1 << b) - 1
if is_pandigital(current, b, all_bits) == 0 { return 0 }
}
b = b - 1
}
return 1
}
function dfs(pos: i64, current: i64) -> void {
if FOUND >= NEED { return }
if pos == BASE {
if check(current) != 0 {
TOTAL = TOTAL + current
FOUND = FOUND + 1
}
return
}
let mut d: i64 = 0
while d < BASE {
if USED[d] == 0 {
USED[d] = 1
dfs(pos + 1, current * BASE + d)
USED[d] = 0
if FOUND >= NEED { return }
}
d = d + 1
}
}
function main() -> i32 {
DIGITS = calloc(BASE, 8)
USED = calloc(BASE, 1)
if DIGITS == null || USED == null { return 1 }
let mut first: i64 = 1
while first < BASE {
if FOUND >= NEED { break }
USED[first] = 1
dfs(1, first)
USED[first] = 0
first = first + 1
}
printf("%lld\n", TOTAL)
free(DIGITS)
free(USED)
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; }
int32_t is_pandigital_i64_i64_i64(int64_t number0, int64_t base, int64_t all_bits);
int32_t is_pandigital_base8_i64(int64_t number0);
int32_t check_i64(int64_t current);
void dfs_i64_i64(int64_t pos, int64_t current);
int32_t main(void);
static const int64_t BASE = 12;
static const int64_t NEED = 10;
/* Module statics */
static int64_t* DIGITS = NULL;
static int8_t* USED = NULL;
static int64_t FOUND = 0;
static int64_t TOTAL = 0;
int32_t is_pandigital_i64_i64_i64(int64_t number0, int64_t base, int64_t all_bits) {
int64_t number = number0;
int64_t used = 0;
while (number > 0) {
int64_t digit = FLOW_CHECKED_MOD((number), (base));
used = (used | FLOW_CHECKED_SHL((1), (digit)));
if (used == all_bits) {
return 1;
}
number = FLOW_CHECKED_DIV((number), (base));
}
if (used == all_bits) {
return 1;
}
return 0;
}
int32_t is_pandigital_base8_i64(int64_t number0) {
int64_t number = number0;
int64_t used = 0;
while (number > 0) {
used = (used | FLOW_CHECKED_SHL((1), ((number & 7))));
if (used == 255) {
return 1;
}
number = FLOW_CHECKED_SHR((number), (3));
}
if (used == 255) {
return 1;
}
return 0;
}
int32_t check_i64(int64_t current) {
if (is_pandigital_base8_i64(current) == 0) {
return 0;
}
int64_t b = 11;
while (b >= 2) {
if (b != 8) {
int64_t all_bits = (FLOW_CHECKED_SHL((1), (b)) - 1);
if (is_pandigital_i64_i64_i64(current, b, all_bits) == 0) {
return 0;
}
}
b = (b - 1);
}
return 1;
}
void dfs_i64_i64(int64_t pos, int64_t current) {
if (FOUND >= NEED) {
return;
}
if (pos == BASE) {
if (check_i64(current) != 0) {
TOTAL = (TOTAL + current);
FOUND = (FOUND + 1);
}
return;
}
int64_t d = 0;
while (d < BASE) {
if (USED[d] == 0) {
USED[d] = 1;
dfs_i64_i64((pos + 1), ((current * BASE) + d));
USED[d] = 0;
if (FOUND >= NEED) {
return;
}
}
d = (d + 1);
}
}
int32_t main(void) {
DIGITS = calloc(BASE, 8);
USED = calloc(BASE, 1);
if ((DIGITS == NULL || USED == NULL)) {
return 1;
}
int64_t first = 1;
while (first < BASE) {
if (FOUND >= NEED) {
break;
}
USED[first] = 1;
dfs_i64_i64(1, first);
USED[first] = 0;
first = (first + 1);
}
printf("%lld\n", TOTAL);
free(DIGITS);
free(USED);
return 0;
}
Generated MLIR
module {
llvm.func @printf(!llvm.ptr, ...) -> i32
llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
// Constant: BASE
llvm.mlir.global internal constant @BASE(12 : i64) : i64
// Constant: NEED
llvm.mlir.global internal constant @NEED(10 : i64) : i64
// Module static: DIGITS
llvm.mlir.global internal @DIGITS() {addr_space = 0 : i32} : !llvm.ptr {
%0 = llvm.mlir.zero : !llvm.ptr
llvm.return %0 : !llvm.ptr
}
// Module static: USED
llvm.mlir.global internal @USED() {addr_space = 0 : i32} : !llvm.ptr {
%1 = llvm.mlir.zero : !llvm.ptr
llvm.return %1 : !llvm.ptr
}
// Module static: FOUND
llvm.mlir.global internal @FOUND(0 : i64) : i64
// Module static: TOTAL
llvm.mlir.global internal @TOTAL(0 : i64) : i64
func.func @is_pandigital(%arg0: i64, %arg1: i64, %arg2: i64) -> i32 {
%2 = llvm.mlir.constant(1 : i64) : i64
%3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %3 : i64, !llvm.ptr
%4 = arith.constant 0 : i32
%5 = arith.extsi %4 : i32 to i64
%6 = llvm.mlir.constant(1 : i64) : i64
%7 = llvm.alloca %6 x i64 : (i64) -> !llvm.ptr
llvm.store %5, %7 : i64, !llvm.ptr
cf.br ^bb0
^bb0:
%8 = llvm.load %3 : !llvm.ptr -> i64
%9 = arith.constant 0 : i32
%11 = arith.extsi %9 : i32 to i64
%10 = arith.cmpi sgt, %8, %11 : i64
cf.cond_br %10, ^bb1, ^bb2
^bb1:
%12 = llvm.load %3 : !llvm.ptr -> i64
%13 = arith.remsi %12, %arg1 : i64
%14 = llvm.load %7 : !llvm.ptr -> i64
%15 = arith.constant 1 : i32
%17 = arith.extsi %15 : i32 to i64
%16 = arith.shli %17, %13 : i64
%18 = arith.ori %14, %16 : i64
llvm.store %18, %7 : i64, !llvm.ptr
%19 = llvm.load %7 : !llvm.ptr -> i64
%20 = arith.cmpi eq, %19, %arg2 : i64
cf.cond_br %20, ^bb3, ^bb4
^bb3:
%21 = arith.constant 1 : i32
func.return %21 : i32
^bb4:
cf.br ^bb5
^bb5:
%22 = llvm.load %3 : !llvm.ptr -> i64
%23 = arith.divsi %22, %arg1 : i64
llvm.store %23, %3 : i64, !llvm.ptr
cf.br ^bb0
^bb2:
%24 = llvm.load %7 : !llvm.ptr -> i64
%25 = arith.cmpi eq, %24, %arg2 : i64
cf.cond_br %25, ^bb6, ^bb7
^bb6:
%26 = arith.constant 1 : i32
func.return %26 : i32
^bb7:
cf.br ^bb8
^bb8:
%27 = arith.constant 0 : i32
func.return %27 : i32
}
func.func @is_pandigital_base8(%arg0: i64) -> i32 {
%28 = llvm.mlir.constant(1 : i64) : i64
%29 = llvm.alloca %28 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %29 : i64, !llvm.ptr
%30 = arith.constant 0 : i32
%31 = arith.extsi %30 : i32 to i64
%32 = llvm.mlir.constant(1 : i64) : i64
%33 = llvm.alloca %32 x i64 : (i64) -> !llvm.ptr
llvm.store %31, %33 : i64, !llvm.ptr
cf.br ^bb9
^bb9:
%34 = llvm.load %29 : !llvm.ptr -> i64
%35 = arith.constant 0 : i32
%37 = arith.extsi %35 : i32 to i64
%36 = arith.cmpi sgt, %34, %37 : i64
cf.cond_br %36, ^bb10, ^bb11
^bb10:
%38 = llvm.load %33 : !llvm.ptr -> i64
%39 = arith.constant 1 : i32
%40 = llvm.load %29 : !llvm.ptr -> i64
%41 = arith.constant 7 : i32
%43 = arith.extsi %41 : i32 to i64
%42 = arith.andi %40, %43 : i64
%45 = arith.extsi %39 : i32 to i64
%44 = arith.shli %45, %42 : i64
%46 = arith.ori %38, %44 : i64
llvm.store %46, %33 : i64, !llvm.ptr
%47 = llvm.load %33 : !llvm.ptr -> i64
%48 = arith.constant 255 : i32
%50 = arith.extsi %48 : i32 to i64
%49 = arith.cmpi eq, %47, %50 : i64
cf.cond_br %49, ^bb12, ^bb13
^bb12:
%51 = arith.constant 1 : i32
func.return %51 : i32
^bb13:
cf.br ^bb14
^bb14:
%52 = llvm.load %29 : !llvm.ptr -> i64
%53 = arith.constant 3 : i32
%55 = arith.extsi %53 : i32 to i64
%54 = arith.shrsi %52, %55 : i64
llvm.store %54, %29 : i64, !llvm.ptr
cf.br ^bb9
^bb11:
%56 = llvm.load %33 : !llvm.ptr -> i64
%57 = arith.constant 255 : i32
%59 = arith.extsi %57 : i32 to i64
%58 = arith.cmpi eq, %56, %59 : i64
cf.cond_br %58, ^bb15, ^bb16
^bb15:
%60 = arith.constant 1 : i32
func.return %60 : i32
^bb16:
cf.br ^bb17
^bb17:
%61 = arith.constant 0 : i32
func.return %61 : i32
}
func.func @check(%arg0: i64) -> i32 {
%62 = func.call @is_pandigital_base8(%arg0) : (i64) -> i32
%63 = arith.constant 0 : i32
%64 = arith.cmpi eq, %62, %63 : i32
cf.cond_br %64, ^bb18, ^bb19
^bb18:
%65 = arith.constant 0 : i32
func.return %65 : i32
^bb19:
cf.br ^bb20
^bb20:
%66 = arith.constant 11 : 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 ^bb21
^bb21:
%70 = llvm.load %69 : !llvm.ptr -> i64
%71 = arith.constant 2 : i32
%73 = arith.extsi %71 : i32 to i64
%72 = arith.cmpi sge, %70, %73 : i64
cf.cond_br %72, ^bb22, ^bb23
^bb22:
%74 = llvm.load %69 : !llvm.ptr -> i64
%75 = arith.constant 8 : i32
%77 = arith.extsi %75 : i32 to i64
%76 = arith.cmpi ne, %74, %77 : i64
cf.cond_br %76, ^bb24, ^bb25
^bb24:
%78 = arith.constant 1 : i32
%79 = llvm.load %69 : !llvm.ptr -> i64
%81 = arith.extsi %78 : i32 to i64
%80 = arith.shli %81, %79 : i64
%82 = arith.constant 1 : i32
%84 = arith.extsi %82 : i32 to i64
%83 = arith.subi %80, %84 : i64
%86 = llvm.load %69 : !llvm.ptr -> i64
%85 = func.call @is_pandigital(%arg0, %86, %83) : (i64, i64, i64) -> i32
%87 = arith.constant 0 : i32
%88 = arith.cmpi eq, %85, %87 : i32
cf.cond_br %88, ^bb27, ^bb28
^bb27:
%89 = arith.constant 0 : i32
func.return %89 : i32
^bb28:
cf.br ^bb29
^bb29:
cf.br ^bb26
^bb25:
cf.br ^bb26
^bb26:
%90 = llvm.load %69 : !llvm.ptr -> i64
%91 = arith.constant 1 : i32
%93 = arith.extsi %91 : i32 to i64
%92 = arith.subi %90, %93 : i64
llvm.store %92, %69 : i64, !llvm.ptr
cf.br ^bb21
^bb23:
%94 = arith.constant 1 : i32
func.return %94 : i32
}
func.func @dfs(%arg0: i64, %arg1: i64) -> () {
%95 = llvm.mlir.addressof @FOUND : !llvm.ptr
%96 = llvm.load %95 : !llvm.ptr -> i64
%97 = llvm.mlir.addressof @NEED : !llvm.ptr
%98 = llvm.load %97 : !llvm.ptr -> i64
%99 = arith.cmpi sge, %96, %98 : i64
cf.cond_br %99, ^bb30, ^bb31
^bb30:
func.return
^bb31:
cf.br ^bb32
^bb32:
%100 = llvm.mlir.addressof @BASE : !llvm.ptr
%101 = llvm.load %100 : !llvm.ptr -> i64
%102 = arith.cmpi eq, %arg0, %101 : i64
cf.cond_br %102, ^bb33, ^bb34
^bb33:
%103 = func.call @check(%arg1) : (i64) -> i32
%104 = arith.constant 0 : i32
%105 = arith.cmpi ne, %103, %104 : i32
cf.cond_br %105, ^bb36, ^bb37
^bb36:
%106 = llvm.mlir.addressof @TOTAL : !llvm.ptr
%107 = llvm.load %106 : !llvm.ptr -> i64
%108 = arith.addi %107, %arg1 : i64
%109 = llvm.mlir.addressof @TOTAL : !llvm.ptr
llvm.store %108, %109 : i64, !llvm.ptr
%110 = llvm.mlir.addressof @FOUND : !llvm.ptr
%111 = llvm.load %110 : !llvm.ptr -> i64
%112 = arith.constant 1 : i32
%114 = arith.extsi %112 : i32 to i64
%113 = arith.addi %111, %114 : i64
%115 = llvm.mlir.addressof @FOUND : !llvm.ptr
llvm.store %113, %115 : i64, !llvm.ptr
cf.br ^bb38
^bb37:
cf.br ^bb38
^bb38:
func.return
^bb34:
cf.br ^bb35
^bb35:
%116 = arith.constant 0 : i32
%117 = arith.extsi %116 : i32 to i64
%118 = llvm.mlir.constant(1 : i64) : i64
%119 = llvm.alloca %118 x i64 : (i64) -> !llvm.ptr
llvm.store %117, %119 : i64, !llvm.ptr
cf.br ^bb39
^bb39:
%120 = llvm.load %119 : !llvm.ptr -> i64
%121 = llvm.mlir.addressof @BASE : !llvm.ptr
%122 = llvm.load %121 : !llvm.ptr -> i64
%123 = arith.cmpi slt, %120, %122 : i64
cf.cond_br %123, ^bb40, ^bb41
^bb40:
%125 = llvm.mlir.addressof @USED : !llvm.ptr
%126 = llvm.load %125 : !llvm.ptr -> !llvm.ptr
%127 = llvm.load %119 : !llvm.ptr -> i64
%128 = llvm.getelementptr %126[%127] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%124 = llvm.load %128 : !llvm.ptr -> i8
%129 = arith.constant 0 : i32
%131 = arith.extsi %124 : i8 to i32
%130 = arith.cmpi eq, %131, %129 : i32
cf.cond_br %130, ^bb42, ^bb43
^bb42:
%132 = arith.constant 1 : i32
%133 = llvm.mlir.addressof @USED : !llvm.ptr
%134 = llvm.load %133 : !llvm.ptr -> !llvm.ptr
%135 = llvm.load %119 : !llvm.ptr -> i64
%136 = arith.trunci %132 : i32 to i8
%137 = llvm.getelementptr %134[%135] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %136, %137 : i8, !llvm.ptr
%139 = arith.constant 1 : i32
%141 = arith.extsi %139 : i32 to i64
%140 = arith.addi %arg0, %141 : i64
%142 = llvm.mlir.addressof @BASE : !llvm.ptr
%143 = llvm.load %142 : !llvm.ptr -> i64
%144 = arith.muli %arg1, %143 : i64
%145 = llvm.load %119 : !llvm.ptr -> i64
%146 = arith.addi %144, %145 : i64
func.call @dfs(%140, %146) : (i64, i64) -> ()
%147 = arith.constant 0 : i32
%148 = llvm.mlir.addressof @USED : !llvm.ptr
%149 = llvm.load %148 : !llvm.ptr -> !llvm.ptr
%150 = llvm.load %119 : !llvm.ptr -> i64
%151 = arith.trunci %147 : i32 to i8
%152 = llvm.getelementptr %149[%150] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %151, %152 : i8, !llvm.ptr
%153 = llvm.mlir.addressof @FOUND : !llvm.ptr
%154 = llvm.load %153 : !llvm.ptr -> i64
%155 = llvm.mlir.addressof @NEED : !llvm.ptr
%156 = llvm.load %155 : !llvm.ptr -> i64
%157 = arith.cmpi sge, %154, %156 : i64
cf.cond_br %157, ^bb45, ^bb46
^bb45:
func.return
^bb46:
cf.br ^bb47
^bb47:
cf.br ^bb44
^bb43:
cf.br ^bb44
^bb44:
%158 = llvm.load %119 : !llvm.ptr -> i64
%159 = arith.constant 1 : i32
%161 = arith.extsi %159 : i32 to i64
%160 = arith.addi %158, %161 : i64
llvm.store %160, %119 : i64, !llvm.ptr
cf.br ^bb39
^bb41:
func.return
}
func.func @main() -> i32 {
%163 = llvm.mlir.addressof @BASE : !llvm.ptr
%164 = llvm.load %163 : !llvm.ptr -> i64
%165 = arith.constant 8 : i32
%166 = arith.extsi %165 : i32 to i64
%162 = func.call @calloc(%164, %166) : (i64, i64) -> !llvm.ptr
%167 = llvm.mlir.addressof @DIGITS : !llvm.ptr
llvm.store %162, %167 : !llvm.ptr, !llvm.ptr
%169 = llvm.mlir.addressof @BASE : !llvm.ptr
%170 = llvm.load %169 : !llvm.ptr -> i64
%171 = arith.constant 1 : i32
%172 = arith.extsi %171 : i32 to i64
%168 = func.call @calloc(%170, %172) : (i64, i64) -> !llvm.ptr
%173 = llvm.mlir.addressof @USED : !llvm.ptr
llvm.store %168, %173 : !llvm.ptr, !llvm.ptr
%174 = llvm.mlir.addressof @DIGITS : !llvm.ptr
%175 = llvm.load %174 : !llvm.ptr -> !llvm.ptr
%176 = llvm.mlir.zero : !llvm.ptr
%177 = llvm.icmp "eq" %175, %176 : !llvm.ptr
%178 = scf.if %177 -> (i1) {
%179 = arith.constant true
scf.yield %179 : i1
} else {
%180 = llvm.mlir.addressof @USED : !llvm.ptr
%181 = llvm.load %180 : !llvm.ptr -> !llvm.ptr
%182 = llvm.mlir.zero : !llvm.ptr
%183 = llvm.icmp "eq" %181, %182 : !llvm.ptr
scf.yield %183 : i1
}
cf.cond_br %178, ^bb48, ^bb49
^bb48:
%184 = arith.constant 1 : i32
func.return %184 : i32
^bb49:
cf.br ^bb50
^bb50:
%185 = arith.constant 1 : i32
%186 = arith.extsi %185 : i32 to i64
%187 = llvm.mlir.constant(1 : i64) : i64
%188 = llvm.alloca %187 x i64 : (i64) -> !llvm.ptr
llvm.store %186, %188 : i64, !llvm.ptr
cf.br ^bb51
^bb51:
%189 = llvm.load %188 : !llvm.ptr -> i64
%190 = llvm.mlir.addressof @BASE : !llvm.ptr
%191 = llvm.load %190 : !llvm.ptr -> i64
%192 = arith.cmpi slt, %189, %191 : i64
cf.cond_br %192, ^bb52, ^bb53
^bb52:
%193 = llvm.mlir.addressof @FOUND : !llvm.ptr
%194 = llvm.load %193 : !llvm.ptr -> i64
%195 = llvm.mlir.addressof @NEED : !llvm.ptr
%196 = llvm.load %195 : !llvm.ptr -> i64
%197 = arith.cmpi sge, %194, %196 : i64
cf.cond_br %197, ^bb54, ^bb55
^bb54:
cf.br ^bb53
^bb55:
cf.br ^bb56
^bb56:
%198 = arith.constant 1 : i32
%199 = llvm.mlir.addressof @USED : !llvm.ptr
%200 = llvm.load %199 : !llvm.ptr -> !llvm.ptr
%201 = llvm.load %188 : !llvm.ptr -> i64
%202 = arith.trunci %198 : i32 to i8
%203 = llvm.getelementptr %200[%201] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %202, %203 : i8, !llvm.ptr
%205 = arith.constant 1 : i32
%206 = llvm.load %188 : !llvm.ptr -> i64
%207 = arith.extsi %205 : i32 to i64
func.call @dfs(%207, %206) : (i64, i64) -> ()
%208 = arith.constant 0 : i32
%209 = llvm.mlir.addressof @USED : !llvm.ptr
%210 = llvm.load %209 : !llvm.ptr -> !llvm.ptr
%211 = llvm.load %188 : !llvm.ptr -> i64
%212 = arith.trunci %208 : i32 to i8
%213 = llvm.getelementptr %210[%211] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %212, %213 : i8, !llvm.ptr
%214 = llvm.load %188 : !llvm.ptr -> i64
%215 = arith.constant 1 : i32
%217 = arith.extsi %215 : i32 to i64
%216 = arith.addi %214, %217 : i64
llvm.store %216, %188 : i64, !llvm.ptr
cf.br ^bb51
^bb53:
%218 = llvm.mlir.addressof @str_0 : !llvm.ptr
%219 = llvm.mlir.addressof @TOTAL : !llvm.ptr
%220 = llvm.load %219 : !llvm.ptr -> i64
%221 = llvm.call @printf(%218, %220) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
%223 = llvm.mlir.addressof @DIGITS : !llvm.ptr
%224 = llvm.load %223 : !llvm.ptr -> !llvm.ptr
func.call @free(%224) : (!llvm.ptr) -> ()
%226 = llvm.mlir.addressof @USED : !llvm.ptr
%227 = llvm.load %226 : !llvm.ptr -> !llvm.ptr
func.call @free(%227) : (!llvm.ptr) -> ()
%228 = arith.constant 0 : i32
func.return %228 : i32
}
}