Problem 170

Largest 0-9 pandigital formed by concatenating products of a common factor.

Answer9857164023
Output9857164023
StatusPASS
Native helperno
Runtime0 ms
Peak memory1072 KB
Time complexityO(n^3) (estimated)
Space complexityO(1) (estimated)

Performance comparison

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

Flow source

# Project Euler 170
# Largest 0-9 pandigital formed by concatenating products of a common factor.

import euler.nt { gcd }

function is_pandigital_mask(x0: i64) -> bool {
    let mut used: i32 = 0
    let mut x: i64 = x0
    let mut digits: i32 = 0
    while x > 0 {
        let d: i32 = (x % 10) as i32
        let bit: i32 = 1 << d
        if (used & bit) != 0 { return false }
        used = used | bit
        digits = digits + 1
        x = x / 10
    }
    return digits == 10 && used == 1023
}

function is_pandigital_var(x0: i64) -> bool {
    let mut used: i32 = 0
    let mut x: i64 = x0
    if x == 0 { return false }
    while x > 0 {
        let d: i32 = (x % 10) as i32
        let bit: i32 = 1 << d
        if (used & bit) != 0 { return false }
        used = used | bit
        x = x / 10
    }
    return true
}

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

function concat3(a: i64, b: i64, c: i64) -> i64 {
    let mut powb: i64 = 1
    let mut t: i64 = b
    if t == 0 { powb = 10 } else {
        while t > 0 { powb = powb * 10; t = t / 10 }
    }
    let mut powc: i64 = 1
    t = c
    if t == 0 { powc = 10 } else {
        while t > 0 { powc = powc * 10; t = t / 10 }
    }
    return (a * powb + b) * powc + c
}

function pow10(n: i32) -> i64 {
    let mut r: i64 = 1
    for i in 0..n {
        r = r * 10
    }
    return r
}

function prev_perm(d: ptr<i8>) -> bool {
    let mut i: i32 = 8
    while i >= 0 && d[i] <= d[i + 1] {
        i = i - 1
    }
    if i < 0 { return false }
    let mut j: i32 = 9
    while d[j] >= d[i] {
        j = j - 1
    }
    let tmp: i8 = d[i]
    d[i] = d[j]
    d[j] = tmp
    let mut a: i32 = i + 1
    let mut b: i32 = 9
    while a < b {
        let t2: i8 = d[a]
        d[a] = d[b]
        d[b] = t2
        a = a + 1
        b = b - 1
    }
    return true
}

function digits_to_num(d: ptr<i8>) -> i64 {
    let mut n: i64 = 0
    for i in 0..10 {
        n = n * 10 + (d[i] as i64)
    }
    return n
}

function main() -> i32 {
    let mut d: array<i8, 10> = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
    while true {
        let current: i64 = digits_to_num(d)
        for split in 1..10 {
            if d[0] != 0 && d[split] != 0 {
                let left: i64 = 0
                for i in 0..split {
                    left = left * 10 + (d[i] as i64)
                }
                let right: i64 = 0
                for i in split..10 {
                    right = right * 10 + (d[i] as i64)
                }
                let shared: i64 = gcd(left, right)
                for factor in 3..(shared + 1) step 3 {
                    if left % factor == 0 && right % factor == 0 {
                        let one: i64 = left / factor
                        let two: i64 = right / factor
                        let seq: i64 = concat3(factor, one, two)
                        if digit_len(seq) == 10 && is_pandigital_mask(seq) {
                            printf("%lld\n", current)
                            return 0
                        }
                    }
                }
            }
        }
        if prev_perm(d) == false { break }
    }
    printf("0\n")
    return 1
}

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 gcd_i64_i64(int64_t a0, int64_t b0);
int64_t lcm_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64(int64_t n);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t n);
bool is_pandigital_mask_i64(int64_t x0);
bool is_pandigital_var_i64(int64_t x0);
int32_t digit_len_i64(int64_t x0);
int64_t concat3_i64_i64_i64(int64_t a, int64_t b, int64_t c);
int64_t pow10_i32(int32_t n);
bool prev_perm_ptr_i8(int8_t* d);
int64_t digits_to_num_ptr_i8(int8_t* d);
int32_t main(void);

int64_t gcd_i64_i64(int64_t a0, int64_t b0) {
    int64_t a = a0;
    int64_t b = b0;
    while (b != 0) {
        int64_t t = FLOW_CHECKED_MOD((a), (b));
        a = b;
        b = t;
    }
    return a;
}

int64_t lcm_i64_i64(int64_t a, int64_t b) {
    if ((a == 0 || b == 0)) {
        return 0;
    }
    return (FLOW_CHECKED_DIV((a), (gcd_i64_i64(a, b))) * b);
}

int64_t isqrt_i64(int64_t n) {
    if (n < 2) {
        return n;
    }
    int64_t x = n;
    int64_t y = FLOW_CHECKED_DIV(((x + 1)), (2));
    while (y < x) {
        x = y;
        y = FLOW_CHECKED_DIV(((x + FLOW_CHECKED_DIV((n), (x)))), (2));
    }
    return x;
}

int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod) {
    int64_t a = FLOW_CHECKED_MOD((a0), (mod));
    int64_t b = FLOW_CHECKED_MOD((b0), (mod));
    int64_t result = 0;
    while (b > 0) {
        if (FLOW_CHECKED_MOD((b), (2)) == 1) {
            result = FLOW_CHECKED_MOD(((result + a)), (mod));
        }
        a = FLOW_CHECKED_MOD(((a * 2)), (mod));
        b = FLOW_CHECKED_DIV((b), (2));
    }
    return result;
}

int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
    if (mod == 1) {
        return 0;
    }
    int64_t result = 1;
    int64_t b = FLOW_CHECKED_MOD((base), (mod));
    int64_t e = exp;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            result = mulmod_i64_i64_i64(result, b, mod);
        }
        b = mulmod_i64_i64_i64(b, b, mod);
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return result;
}

bool is_prime_i64(int64_t n) {
    if (n < 2) {
        return 0;
    }
    if (n < 4) {
        return 1;
    }
    if ((FLOW_CHECKED_MOD((n), (2)) == 0 || FLOW_CHECKED_MOD((n), (3)) == 0)) {
        return 0;
    }
    int64_t i = 5;
    while ((i * i) <= n) {
        if ((FLOW_CHECKED_MOD((n), (i)) == 0 || FLOW_CHECKED_MOD((n), ((i + 2))) == 0)) {
            return 0;
        }
        i = (i + 6);
    }
    return 1;
}

bool is_pandigital_mask_i64(int64_t x0) {
    int32_t used = 0;
    int64_t x = x0;
    int32_t digits = 0;
    while (x > 0) {
        int32_t d = ((int32_t)(FLOW_CHECKED_MOD((x), (10))));
        int32_t bit = FLOW_CHECKED_SHL((1), (d));
        if ((used & bit) != 0) {
            return 0;
        }
        used = (used | bit);
        digits = (digits + 1);
        x = FLOW_CHECKED_DIV((x), (10));
    }
    return (digits == 10 && used == 1023);
}

bool is_pandigital_var_i64(int64_t x0) {
    int32_t used = 0;
    int64_t x = x0;
    if (x == 0) {
        return 0;
    }
    while (x > 0) {
        int32_t d = ((int32_t)(FLOW_CHECKED_MOD((x), (10))));
        int32_t bit = FLOW_CHECKED_SHL((1), (d));
        if ((used & bit) != 0) {
            return 0;
        }
        used = (used | bit);
        x = FLOW_CHECKED_DIV((x), (10));
    }
    return 1;
}

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

int64_t concat3_i64_i64_i64(int64_t a, int64_t b, int64_t c) {
    int64_t powb = 1;
    int64_t t = b;
    if (t == 0) {
        powb = 10;
    } else {
        while (t > 0) {
            powb = (powb * 10);
            t = FLOW_CHECKED_DIV((t), (10));
        }
    }
    int64_t powc = 1;
    t = c;
    if (t == 0) {
        powc = 10;
    } else {
        while (t > 0) {
            powc = (powc * 10);
            t = FLOW_CHECKED_DIV((t), (10));
        }
    }
    return ((((a * powb) + b) * powc) + c);
}

int64_t pow10_i32(int32_t n) {
    int64_t r = 1;
    int32_t __flow_step_1 = 1;
    for (int32_t i = 0; (0 <= n) ? i < n : i > n; i += (0 <= n) ? 1 : -1) {
        r = (r * 10);
    }
    return r;
}

bool prev_perm_ptr_i8(int8_t* d) {
    int32_t i = 8;
    while ((i >= 0 && d[i] <= d[(i + 1)])) {
        i = (i - 1);
    }
    if (i < 0) {
        return 0;
    }
    int32_t j = 9;
    while (d[j] >= d[i]) {
        j = (j - 1);
    }
    int8_t tmp = d[i];
    d[i] = d[j];
    d[j] = tmp;
    int32_t a = (i + 1);
    int32_t b = 9;
    while (a < b) {
        int8_t t2 = d[a];
        d[a] = d[b];
        d[b] = t2;
        a = (a + 1);
        b = (b - 1);
    }
    return 1;
}

int64_t digits_to_num_ptr_i8(int8_t* d) {
    int64_t n = 0;
    int32_t __flow_step_2 = 1;
    for (int32_t i = 0; (0 <= 10) ? i < 10 : i > 10; i += (0 <= 10) ? 1 : -1) {
        n = ((n * 10) + ((int64_t)(d[i])));
    }
    return n;
}

int32_t main(void) {
    int8_t d[10] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
    while (1) {
        int64_t current = digits_to_num_ptr_i8(d);
        int32_t __flow_step_3 = 1;
        for (int32_t split = 1; (1 <= 10) ? split < 10 : split > 10; split += (1 <= 10) ? 1 : -1) {
            if (((((unsigned)(0) < 10) ? d[0] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(0), 10), flow_fault_handler("array index out of bounds"), d[0])) != 0 && (((unsigned)(split) < 10) ? d[split] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(split), 10), flow_fault_handler("array index out of bounds"), d[0])) != 0)) {
                int64_t left = 0;
                int32_t __flow_step_4 = 1;
                for (int32_t i = 0; (0 <= split) ? i < split : i > split; i += (0 <= split) ? 1 : -1) {
                    left = ((left * 10) + ((int64_t)((((unsigned)(i) < 10) ? d[i] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(i), 10), flow_fault_handler("array index out of bounds"), d[0])))));
                }
                int64_t right = 0;
                int32_t __flow_step_5 = 1;
                for (int32_t i = split; (split <= 10) ? i < 10 : i > 10; i += (split <= 10) ? 1 : -1) {
                    right = ((right * 10) + ((int64_t)((((unsigned)(i) < 10) ? d[i] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(i), 10), flow_fault_handler("array index out of bounds"), d[0])))));
                }
                int64_t shared = gcd_i64_i64(left, right);
                int32_t __flow_step_6 = 3;
                for (int32_t factor = 3; (__flow_step_6 > 0) ? factor < (shared + 1) : factor > (shared + 1); factor += __flow_step_6) {
                    if ((FLOW_CHECKED_MOD((left), (factor)) == 0 && FLOW_CHECKED_MOD((right), (factor)) == 0)) {
                        int64_t one = FLOW_CHECKED_DIV((left), (factor));
                        int64_t two = FLOW_CHECKED_DIV((right), (factor));
                        int64_t seq = concat3_i64_i64_i64(factor, one, two);
                        if ((digit_len_i64(seq) == 10 && is_pandigital_mask_i64(seq))) {
                            printf("%lld\n", current);
                            return 0;
                        }
                    }
                }
            }
        }
        if (prev_perm_ptr_i8(d) == 0) {
            break;
        }
    }
    printf("0\n");
    return 1;
}

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>
  llvm.mlir.global internal constant @str_1("0\n\00") {addr_space = 0 : i32} : !llvm.array<3 x i8>
  func.func @gcd(%arg0: i64, %arg1: i64) -> i64 {
    %0 = llvm.mlir.constant(1 : i64) : i64
    %1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %1 : i64, !llvm.ptr
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %3 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %4 = llvm.load %3 : !llvm.ptr -> i64
    %5 = arith.constant 0 : i32
    %7 = arith.extsi %5 : i32 to i64
    %6 = arith.cmpi ne, %4, %7 : i64
    cf.cond_br %6, ^bb1, ^bb2
    ^bb1:
      %8 = llvm.load %1 : !llvm.ptr -> i64
      %9 = llvm.load %3 : !llvm.ptr -> i64
      %10 = arith.remsi %8, %9 : i64
      %11 = llvm.load %3 : !llvm.ptr -> i64
      llvm.store %11, %1 : i64, !llvm.ptr
      llvm.store %10, %3 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %12 = llvm.load %1 : !llvm.ptr -> i64
    func.return %12 : i64
  }
  func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
    %13 = arith.constant 0 : i32
    %15 = arith.extsi %13 : i32 to i64
    %14 = arith.cmpi eq, %arg0, %15 : i64
    %16 = scf.if %14 -> (i1) {
      %17 = arith.constant true
      scf.yield %17 : i1
    } else {
      %18 = arith.constant 0 : i32
      %20 = arith.extsi %18 : i32 to i64
      %19 = arith.cmpi eq, %arg1, %20 : i64
      scf.yield %19 : i1
    }
    cf.cond_br %16, ^bb3, ^bb4
    ^bb3:
      %21 = arith.constant 0 : i32
      %22 = arith.extsi %21 : i32 to i64
      func.return %22 : i64
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
    %24 = arith.divsi %arg0, %23 : i64
    %25 = arith.muli %24, %arg1 : i64
    func.return %25 : i64
  }
  func.func @isqrt(%arg0: i64) -> i64 {
    %26 = arith.constant 2 : i32
    %28 = arith.extsi %26 : i32 to i64
    %27 = arith.cmpi slt, %arg0, %28 : i64
    cf.cond_br %27, ^bb6, ^bb7
    ^bb6:
      func.return %arg0 : i64
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %29 = llvm.mlir.constant(1 : i64) : i64
    %30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %30 : i64, !llvm.ptr
    %31 = llvm.load %30 : !llvm.ptr -> i64
    %32 = arith.constant 1 : i32
    %34 = arith.extsi %32 : i32 to i64
    %33 = arith.addi %31, %34 : i64
    %35 = arith.constant 2 : i32
    %37 = arith.extsi %35 : i32 to i64
    %36 = arith.divsi %33, %37 : i64
    %38 = llvm.mlir.constant(1 : i64) : i64
    %39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
    llvm.store %36, %39 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %40 = llvm.load %39 : !llvm.ptr -> i64
    %41 = llvm.load %30 : !llvm.ptr -> i64
    %42 = arith.cmpi slt, %40, %41 : i64
    cf.cond_br %42, ^bb10, ^bb11
    ^bb10:
      %43 = llvm.load %39 : !llvm.ptr -> i64
      llvm.store %43, %30 : i64, !llvm.ptr
      %44 = llvm.load %30 : !llvm.ptr -> i64
      %45 = llvm.load %30 : !llvm.ptr -> i64
      %46 = arith.divsi %arg0, %45 : i64
      %47 = arith.addi %44, %46 : i64
      %48 = arith.constant 2 : i32
      %50 = arith.extsi %48 : i32 to i64
      %49 = arith.divsi %47, %50 : i64
      llvm.store %49, %39 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %51 = llvm.load %30 : !llvm.ptr -> i64
    func.return %51 : i64
  }
  func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %52 = arith.remsi %arg0, %arg2 : i64
    %53 = llvm.mlir.constant(1 : i64) : i64
    %54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
    llvm.store %52, %54 : i64, !llvm.ptr
    %55 = arith.remsi %arg1, %arg2 : i64
    %56 = llvm.mlir.constant(1 : i64) : i64
    %57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
    llvm.store %55, %57 : i64, !llvm.ptr
    %58 = arith.constant 0 : i32
    %59 = arith.extsi %58 : i32 to i64
    %60 = llvm.mlir.constant(1 : i64) : i64
    %61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
    llvm.store %59, %61 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %62 = llvm.load %57 : !llvm.ptr -> i64
    %63 = arith.constant 0 : i32
    %65 = arith.extsi %63 : i32 to i64
    %64 = arith.cmpi sgt, %62, %65 : i64
    cf.cond_br %64, ^bb13, ^bb14
    ^bb13:
      %66 = llvm.load %57 : !llvm.ptr -> i64
      %67 = arith.constant 2 : i32
      %69 = arith.extsi %67 : i32 to i64
      %68 = arith.remsi %66, %69 : i64
      %70 = arith.constant 1 : i32
      %72 = arith.extsi %70 : i32 to i64
      %71 = arith.cmpi eq, %68, %72 : i64
      cf.cond_br %71, ^bb15, ^bb16
      ^bb15:
        %73 = llvm.load %61 : !llvm.ptr -> i64
        %74 = llvm.load %54 : !llvm.ptr -> i64
        %75 = arith.addi %73, %74 : i64
        %76 = arith.remsi %75, %arg2 : i64
        llvm.store %76, %61 : i64, !llvm.ptr
        cf.br ^bb17
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %77 = llvm.load %54 : !llvm.ptr -> i64
      %78 = arith.constant 2 : i32
      %80 = arith.extsi %78 : i32 to i64
      %79 = arith.muli %77, %80 : i64
      %81 = arith.remsi %79, %arg2 : i64
      llvm.store %81, %54 : i64, !llvm.ptr
      %82 = llvm.load %57 : !llvm.ptr -> i64
      %83 = arith.constant 2 : i32
      %85 = arith.extsi %83 : i32 to i64
      %84 = arith.divsi %82, %85 : i64
      llvm.store %84, %57 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %86 = llvm.load %61 : !llvm.ptr -> i64
    func.return %86 : i64
  }
  func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %87 = arith.constant 1 : i32
    %89 = arith.extsi %87 : i32 to i64
    %88 = arith.cmpi eq, %arg2, %89 : i64
    cf.cond_br %88, ^bb18, ^bb19
    ^bb18:
      %90 = arith.constant 0 : i32
      %91 = arith.extsi %90 : i32 to i64
      func.return %91 : i64
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %92 = arith.constant 1 : i32
    %93 = arith.extsi %92 : i32 to i64
    %94 = llvm.mlir.constant(1 : i64) : i64
    %95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
    llvm.store %93, %95 : i64, !llvm.ptr
    %96 = arith.remsi %arg0, %arg2 : i64
    %97 = llvm.mlir.constant(1 : i64) : i64
    %98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
    llvm.store %96, %98 : i64, !llvm.ptr
    %99 = llvm.mlir.constant(1 : i64) : i64
    %100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %100 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %101 = llvm.load %100 : !llvm.ptr -> i64
    %102 = arith.constant 0 : i32
    %104 = arith.extsi %102 : i32 to i64
    %103 = arith.cmpi sgt, %101, %104 : i64
    cf.cond_br %103, ^bb22, ^bb23
    ^bb22:
      %105 = llvm.load %100 : !llvm.ptr -> i64
      %106 = arith.constant 2 : i32
      %108 = arith.extsi %106 : i32 to i64
      %107 = arith.remsi %105, %108 : i64
      %109 = arith.constant 1 : i32
      %111 = arith.extsi %109 : i32 to i64
      %110 = arith.cmpi eq, %107, %111 : i64
      cf.cond_br %110, ^bb24, ^bb25
      ^bb24:
        %113 = llvm.load %95 : !llvm.ptr -> i64
        %114 = llvm.load %98 : !llvm.ptr -> i64
        %112 = func.call @mulmod(%113, %114, %arg2) : (i64, i64, i64) -> i64
        llvm.store %112, %95 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %116 = llvm.load %98 : !llvm.ptr -> i64
      %117 = llvm.load %98 : !llvm.ptr -> i64
      %115 = func.call @mulmod(%116, %117, %arg2) : (i64, i64, i64) -> i64
      llvm.store %115, %98 : i64, !llvm.ptr
      %118 = llvm.load %100 : !llvm.ptr -> i64
      %119 = arith.constant 2 : i32
      %121 = arith.extsi %119 : i32 to i64
      %120 = arith.divsi %118, %121 : i64
      llvm.store %120, %100 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %122 = llvm.load %95 : !llvm.ptr -> i64
    func.return %122 : i64
  }
  func.func @is_prime(%arg0: i64) -> i1 {
    %123 = arith.constant 2 : i32
    %125 = arith.extsi %123 : i32 to i64
    %124 = arith.cmpi slt, %arg0, %125 : i64
    cf.cond_br %124, ^bb27, ^bb28
    ^bb27:
      %126 = arith.constant 0 : i1
      func.return %126 : i1
    ^bb28:
      cf.br ^bb29
    ^bb29:
    %127 = arith.constant 4 : i32
    %129 = arith.extsi %127 : i32 to i64
    %128 = arith.cmpi slt, %arg0, %129 : i64
    cf.cond_br %128, ^bb30, ^bb31
    ^bb30:
      %130 = arith.constant 1 : i1
      func.return %130 : i1
    ^bb31:
      cf.br ^bb32
    ^bb32:
    %131 = arith.constant 2 : i32
    %133 = arith.extsi %131 : i32 to i64
    %132 = arith.remsi %arg0, %133 : i64
    %134 = arith.constant 0 : i32
    %136 = arith.extsi %134 : i32 to i64
    %135 = arith.cmpi eq, %132, %136 : i64
    %137 = scf.if %135 -> (i1) {
      %138 = arith.constant true
      scf.yield %138 : i1
    } else {
      %139 = arith.constant 3 : i32
      %141 = arith.extsi %139 : i32 to i64
      %140 = arith.remsi %arg0, %141 : i64
      %142 = arith.constant 0 : i32
      %144 = arith.extsi %142 : i32 to i64
      %143 = arith.cmpi eq, %140, %144 : i64
      scf.yield %143 : i1
    }
    cf.cond_br %137, ^bb33, ^bb34
    ^bb33:
      %145 = arith.constant 0 : i1
      func.return %145 : i1
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %146 = arith.constant 5 : i32
    %147 = arith.extsi %146 : i32 to i64
    %148 = llvm.mlir.constant(1 : i64) : i64
    %149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
    llvm.store %147, %149 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %150 = llvm.load %149 : !llvm.ptr -> i64
    %151 = llvm.load %149 : !llvm.ptr -> i64
    %152 = arith.muli %150, %151 : i64
    %153 = arith.cmpi sle, %152, %arg0 : i64
    cf.cond_br %153, ^bb37, ^bb38
    ^bb37:
      %154 = llvm.load %149 : !llvm.ptr -> i64
      %155 = arith.remsi %arg0, %154 : i64
      %156 = arith.constant 0 : i32
      %158 = arith.extsi %156 : i32 to i64
      %157 = arith.cmpi eq, %155, %158 : i64
      %159 = scf.if %157 -> (i1) {
        %160 = arith.constant true
        scf.yield %160 : i1
      } else {
        %161 = llvm.load %149 : !llvm.ptr -> i64
        %162 = arith.constant 2 : i32
        %164 = arith.extsi %162 : i32 to i64
        %163 = arith.addi %161, %164 : i64
        %165 = arith.remsi %arg0, %163 : i64
        %166 = arith.constant 0 : i32
        %168 = arith.extsi %166 : i32 to i64
        %167 = arith.cmpi eq, %165, %168 : i64
        scf.yield %167 : i1
      }
      cf.cond_br %159, ^bb39, ^bb40
      ^bb39:
        %169 = arith.constant 0 : i1
        func.return %169 : i1
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %170 = llvm.load %149 : !llvm.ptr -> i64
      %171 = arith.constant 6 : i32
      %173 = arith.extsi %171 : i32 to i64
      %172 = arith.addi %170, %173 : i64
      llvm.store %172, %149 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %174 = arith.constant 1 : i1
    func.return %174 : i1
  }
  func.func @is_pandigital_mask(%arg0: i64) -> i1 {
    %175 = arith.constant 0 : i32
    %176 = llvm.mlir.constant(1 : i64) : i64
    %177 = llvm.alloca %176 x i32 : (i64) -> !llvm.ptr
    llvm.store %175, %177 : i32, !llvm.ptr
    %178 = llvm.mlir.constant(1 : i64) : i64
    %179 = llvm.alloca %178 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %179 : i64, !llvm.ptr
    %180 = arith.constant 0 : i32
    %181 = llvm.mlir.constant(1 : i64) : i64
    %182 = llvm.alloca %181 x i32 : (i64) -> !llvm.ptr
    llvm.store %180, %182 : i32, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %183 = llvm.load %179 : !llvm.ptr -> i64
    %184 = arith.constant 0 : i32
    %186 = arith.extsi %184 : i32 to i64
    %185 = arith.cmpi sgt, %183, %186 : i64
    cf.cond_br %185, ^bb43, ^bb44
    ^bb43:
      %187 = llvm.load %179 : !llvm.ptr -> i64
      %188 = arith.constant 10 : i32
      %190 = arith.extsi %188 : i32 to i64
      %189 = arith.remsi %187, %190 : i64
      %191 = arith.trunci %189 : i64 to i32
      %192 = arith.constant 1 : i32
      %193 = arith.shli %192, %191 : i32
      %194 = llvm.load %177 : !llvm.ptr -> i32
      %195 = arith.andi %194, %193 : i32
      %196 = arith.constant 0 : i32
      %197 = arith.cmpi ne, %195, %196 : i32
      cf.cond_br %197, ^bb45, ^bb46
      ^bb45:
        %198 = arith.constant 0 : i1
        func.return %198 : i1
      ^bb46:
        cf.br ^bb47
      ^bb47:
      %199 = llvm.load %177 : !llvm.ptr -> i32
      %200 = arith.ori %199, %193 : i32
      llvm.store %200, %177 : i32, !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
      %204 = llvm.load %179 : !llvm.ptr -> i64
      %205 = arith.constant 10 : i32
      %207 = arith.extsi %205 : i32 to i64
      %206 = arith.divsi %204, %207 : i64
      llvm.store %206, %179 : i64, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    %208 = llvm.load %182 : !llvm.ptr -> i32
    %209 = arith.constant 10 : i32
    %210 = arith.cmpi eq, %208, %209 : i32
    %211 = scf.if %210 -> (i1) {
      %212 = llvm.load %177 : !llvm.ptr -> i32
      %213 = arith.constant 1023 : i32
      %214 = arith.cmpi eq, %212, %213 : i32
      scf.yield %214 : i1
    } else {
      %215 = arith.constant false
      scf.yield %215 : i1
    }
    func.return %211 : i1
  }
  func.func @is_pandigital_var(%arg0: i64) -> i1 {
    %216 = arith.constant 0 : i32
    %217 = llvm.mlir.constant(1 : i64) : i64
    %218 = llvm.alloca %217 x i32 : (i64) -> !llvm.ptr
    llvm.store %216, %218 : i32, !llvm.ptr
    %219 = llvm.mlir.constant(1 : i64) : i64
    %220 = llvm.alloca %219 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %220 : i64, !llvm.ptr
    %221 = llvm.load %220 : !llvm.ptr -> i64
    %222 = arith.constant 0 : i32
    %224 = arith.extsi %222 : i32 to i64
    %223 = arith.cmpi eq, %221, %224 : i64
    cf.cond_br %223, ^bb48, ^bb49
    ^bb48:
      %225 = arith.constant 0 : i1
      func.return %225 : i1
    ^bb49:
      cf.br ^bb50
    ^bb50:
    cf.br ^bb51
    ^bb51:
    %226 = llvm.load %220 : !llvm.ptr -> i64
    %227 = arith.constant 0 : i32
    %229 = arith.extsi %227 : i32 to i64
    %228 = arith.cmpi sgt, %226, %229 : i64
    cf.cond_br %228, ^bb52, ^bb53
    ^bb52:
      %230 = llvm.load %220 : !llvm.ptr -> i64
      %231 = arith.constant 10 : i32
      %233 = arith.extsi %231 : i32 to i64
      %232 = arith.remsi %230, %233 : i64
      %234 = arith.trunci %232 : i64 to i32
      %235 = arith.constant 1 : i32
      %236 = arith.shli %235, %234 : i32
      %237 = llvm.load %218 : !llvm.ptr -> i32
      %238 = arith.andi %237, %236 : i32
      %239 = arith.constant 0 : i32
      %240 = arith.cmpi ne, %238, %239 : i32
      cf.cond_br %240, ^bb54, ^bb55
      ^bb54:
        %241 = arith.constant 0 : i1
        func.return %241 : i1
      ^bb55:
        cf.br ^bb56
      ^bb56:
      %242 = llvm.load %218 : !llvm.ptr -> i32
      %243 = arith.ori %242, %236 : i32
      llvm.store %243, %218 : i32, !llvm.ptr
      %244 = llvm.load %220 : !llvm.ptr -> i64
      %245 = arith.constant 10 : i32
      %247 = arith.extsi %245 : i32 to i64
      %246 = arith.divsi %244, %247 : i64
      llvm.store %246, %220 : i64, !llvm.ptr
      cf.br ^bb51
    ^bb53:
    %248 = arith.constant 1 : i1
    func.return %248 : i1
  }
  func.func @digit_len(%arg0: i64) -> i32 {
    %249 = arith.constant 0 : i32
    %251 = arith.extsi %249 : i32 to i64
    %250 = arith.cmpi eq, %arg0, %251 : i64
    cf.cond_br %250, ^bb57, ^bb58
    ^bb57:
      %252 = arith.constant 1 : i32
      func.return %252 : i32
    ^bb58:
      cf.br ^bb59
    ^bb59:
    %253 = arith.constant 0 : i32
    %254 = llvm.mlir.constant(1 : i64) : i64
    %255 = llvm.alloca %254 x i32 : (i64) -> !llvm.ptr
    llvm.store %253, %255 : i32, !llvm.ptr
    %256 = llvm.mlir.constant(1 : i64) : i64
    %257 = llvm.alloca %256 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %257 : i64, !llvm.ptr
    cf.br ^bb60
    ^bb60:
    %258 = llvm.load %257 : !llvm.ptr -> i64
    %259 = arith.constant 0 : i32
    %261 = arith.extsi %259 : i32 to i64
    %260 = arith.cmpi sgt, %258, %261 : i64
    cf.cond_br %260, ^bb61, ^bb62
    ^bb61:
      %262 = llvm.load %255 : !llvm.ptr -> i32
      %263 = arith.constant 1 : i32
      %264 = arith.addi %262, %263 : i32
      llvm.store %264, %255 : i32, !llvm.ptr
      %265 = llvm.load %257 : !llvm.ptr -> i64
      %266 = arith.constant 10 : i32
      %268 = arith.extsi %266 : i32 to i64
      %267 = arith.divsi %265, %268 : i64
      llvm.store %267, %257 : i64, !llvm.ptr
      cf.br ^bb60
    ^bb62:
    %269 = llvm.load %255 : !llvm.ptr -> i32
    func.return %269 : i32
  }
  func.func @concat3(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %270 = arith.constant 1 : i32
    %271 = arith.extsi %270 : i32 to i64
    %272 = llvm.mlir.constant(1 : i64) : i64
    %273 = llvm.alloca %272 x i64 : (i64) -> !llvm.ptr
    llvm.store %271, %273 : i64, !llvm.ptr
    %274 = llvm.mlir.constant(1 : i64) : i64
    %275 = llvm.alloca %274 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %275 : i64, !llvm.ptr
    %276 = llvm.load %275 : !llvm.ptr -> i64
    %277 = arith.constant 0 : i32
    %279 = arith.extsi %277 : i32 to i64
    %278 = arith.cmpi eq, %276, %279 : i64
    cf.cond_br %278, ^bb63, ^bb64
    ^bb63:
      %280 = arith.constant 10 : i32
      %281 = arith.extsi %280 : i32 to i64
      llvm.store %281, %273 : i64, !llvm.ptr
      cf.br ^bb65
    ^bb64:
      cf.br ^bb66
      ^bb66:
      %282 = llvm.load %275 : !llvm.ptr -> i64
      %283 = arith.constant 0 : i32
      %285 = arith.extsi %283 : i32 to i64
      %284 = arith.cmpi sgt, %282, %285 : i64
      cf.cond_br %284, ^bb67, ^bb68
      ^bb67:
        %286 = llvm.load %273 : !llvm.ptr -> i64
        %287 = arith.constant 10 : i32
        %289 = arith.extsi %287 : i32 to i64
        %288 = arith.muli %286, %289 : i64
        llvm.store %288, %273 : i64, !llvm.ptr
        %290 = llvm.load %275 : !llvm.ptr -> i64
        %291 = arith.constant 10 : i32
        %293 = arith.extsi %291 : i32 to i64
        %292 = arith.divsi %290, %293 : i64
        llvm.store %292, %275 : i64, !llvm.ptr
        cf.br ^bb66
      ^bb68:
      cf.br ^bb65
    ^bb65:
    %294 = arith.constant 1 : i32
    %295 = arith.extsi %294 : i32 to i64
    %296 = llvm.mlir.constant(1 : i64) : i64
    %297 = llvm.alloca %296 x i64 : (i64) -> !llvm.ptr
    llvm.store %295, %297 : i64, !llvm.ptr
    llvm.store %arg2, %275 : i64, !llvm.ptr
    %298 = llvm.load %275 : !llvm.ptr -> i64
    %299 = arith.constant 0 : i32
    %301 = arith.extsi %299 : i32 to i64
    %300 = arith.cmpi eq, %298, %301 : i64
    cf.cond_br %300, ^bb69, ^bb70
    ^bb69:
      %302 = arith.constant 10 : i32
      %303 = arith.extsi %302 : i32 to i64
      llvm.store %303, %297 : i64, !llvm.ptr
      cf.br ^bb71
    ^bb70:
      cf.br ^bb72
      ^bb72:
      %304 = llvm.load %275 : !llvm.ptr -> i64
      %305 = arith.constant 0 : i32
      %307 = arith.extsi %305 : i32 to i64
      %306 = arith.cmpi sgt, %304, %307 : i64
      cf.cond_br %306, ^bb73, ^bb74
      ^bb73:
        %308 = llvm.load %297 : !llvm.ptr -> i64
        %309 = arith.constant 10 : i32
        %311 = arith.extsi %309 : i32 to i64
        %310 = arith.muli %308, %311 : i64
        llvm.store %310, %297 : i64, !llvm.ptr
        %312 = llvm.load %275 : !llvm.ptr -> i64
        %313 = arith.constant 10 : i32
        %315 = arith.extsi %313 : i32 to i64
        %314 = arith.divsi %312, %315 : i64
        llvm.store %314, %275 : i64, !llvm.ptr
        cf.br ^bb72
      ^bb74:
      cf.br ^bb71
    ^bb71:
    %316 = llvm.load %273 : !llvm.ptr -> i64
    %317 = arith.muli %arg0, %316 : i64
    %318 = arith.addi %317, %arg1 : i64
    %319 = llvm.load %297 : !llvm.ptr -> i64
    %320 = arith.muli %318, %319 : i64
    %321 = arith.addi %320, %arg2 : i64
    func.return %321 : i64
  }
  func.func @pow10(%arg0: i32) -> i64 {
    %322 = arith.constant 1 : i32
    %323 = arith.extsi %322 : i32 to i64
    %324 = llvm.mlir.constant(1 : i64) : i64
    %325 = llvm.alloca %324 x i64 : (i64) -> !llvm.ptr
    llvm.store %323, %325 : i64, !llvm.ptr
    %326 = arith.constant 0 : i32
    %327 = arith.index_cast %326 : i32 to index
    %328 = arith.index_cast %arg0 : i32 to index
    %330 = arith.constant 1 : index
    %331 = arith.constant -1 : index
    %332 = arith.cmpi sle, %327, %328 : index
    %329 = arith.select %332, %330, %331 : index
    cf.br ^bb75(%327 : index)
    ^bb75(%333: index):
    %334 = arith.cmpi slt, %333, %328 : index
    %335 = arith.cmpi sgt, %333, %328 : index
    %336 = arith.select %332, %334, %335 : i1
    cf.cond_br %336, ^bb76(%333 : index), ^bb77(%333 : index)
    ^bb76(%337: index):
      %338 = llvm.load %325 : !llvm.ptr -> i64
      %339 = arith.constant 10 : i32
      %341 = arith.extsi %339 : i32 to i64
      %340 = arith.muli %338, %341 : i64
      llvm.store %340, %325 : i64, !llvm.ptr
      %342 = arith.addi %337, %329 : index
      cf.br ^bb75(%342 : index)
    ^bb77(%343: index):
    %344 = llvm.load %325 : !llvm.ptr -> i64
    func.return %344 : i64
  }
  func.func @prev_perm(%arg0: !llvm.ptr) -> i1 {
    %345 = arith.constant 8 : i32
    %346 = llvm.mlir.constant(1 : i64) : i64
    %347 = llvm.alloca %346 x i32 : (i64) -> !llvm.ptr
    llvm.store %345, %347 : i32, !llvm.ptr
    cf.br ^bb78
    ^bb78:
    %348 = llvm.load %347 : !llvm.ptr -> i32
    %349 = arith.constant 0 : i32
    %350 = arith.cmpi sge, %348, %349 : i32
    %351 = scf.if %350 -> (i1) {
      %353 = llvm.load %347 : !llvm.ptr -> i32
      %354 = arith.extsi %353 : i32 to i64
      %355 = llvm.getelementptr %arg0[%354] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %352 = llvm.load %355 : !llvm.ptr -> i8
      %357 = llvm.load %347 : !llvm.ptr -> i32
      %358 = arith.constant 1 : i32
      %359 = arith.addi %357, %358 : i32
      %360 = arith.extsi %359 : i32 to i64
      %361 = llvm.getelementptr %arg0[%360] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %356 = llvm.load %361 : !llvm.ptr -> i8
      %363 = arith.extsi %352 : i8 to i32
      %364 = arith.extsi %356 : i8 to i32
      %362 = arith.cmpi sle, %363, %364 : i32
      scf.yield %362 : i1
    } else {
      %365 = arith.constant false
      scf.yield %365 : i1
    }
    cf.cond_br %351, ^bb79, ^bb80
    ^bb79:
      %366 = llvm.load %347 : !llvm.ptr -> i32
      %367 = arith.constant 1 : i32
      %368 = arith.subi %366, %367 : i32
      llvm.store %368, %347 : i32, !llvm.ptr
      cf.br ^bb78
    ^bb80:
    %369 = llvm.load %347 : !llvm.ptr -> i32
    %370 = arith.constant 0 : i32
    %371 = arith.cmpi slt, %369, %370 : i32
    cf.cond_br %371, ^bb81, ^bb82
    ^bb81:
      %372 = arith.constant 0 : i1
      func.return %372 : i1
    ^bb82:
      cf.br ^bb83
    ^bb83:
    %373 = arith.constant 9 : i32
    %374 = llvm.mlir.constant(1 : i64) : i64
    %375 = llvm.alloca %374 x i32 : (i64) -> !llvm.ptr
    llvm.store %373, %375 : i32, !llvm.ptr
    cf.br ^bb84
    ^bb84:
    %377 = llvm.load %375 : !llvm.ptr -> i32
    %378 = arith.extsi %377 : i32 to i64
    %379 = llvm.getelementptr %arg0[%378] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    %376 = llvm.load %379 : !llvm.ptr -> i8
    %381 = llvm.load %347 : !llvm.ptr -> i32
    %382 = arith.extsi %381 : i32 to i64
    %383 = llvm.getelementptr %arg0[%382] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    %380 = llvm.load %383 : !llvm.ptr -> i8
    %385 = arith.extsi %376 : i8 to i32
    %386 = arith.extsi %380 : i8 to i32
    %384 = arith.cmpi sge, %385, %386 : i32
    cf.cond_br %384, ^bb85, ^bb86
    ^bb85:
      %387 = llvm.load %375 : !llvm.ptr -> i32
      %388 = arith.constant 1 : i32
      %389 = arith.subi %387, %388 : i32
      llvm.store %389, %375 : i32, !llvm.ptr
      cf.br ^bb84
    ^bb86:
    %391 = llvm.load %347 : !llvm.ptr -> i32
    %392 = arith.extsi %391 : i32 to i64
    %393 = llvm.getelementptr %arg0[%392] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    %390 = llvm.load %393 : !llvm.ptr -> i8
    %395 = llvm.load %375 : !llvm.ptr -> i32
    %396 = arith.extsi %395 : i32 to i64
    %397 = llvm.getelementptr %arg0[%396] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    %394 = llvm.load %397 : !llvm.ptr -> i8
    %398 = llvm.load %347 : !llvm.ptr -> i32
    %399 = arith.extsi %398 : i32 to i64
    %400 = llvm.getelementptr %arg0[%399] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %394, %400 : i8, !llvm.ptr
    %401 = llvm.load %375 : !llvm.ptr -> i32
    %402 = arith.extsi %401 : i32 to i64
    %403 = llvm.getelementptr %arg0[%402] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %390, %403 : i8, !llvm.ptr
    %404 = llvm.load %347 : !llvm.ptr -> i32
    %405 = arith.constant 1 : i32
    %406 = arith.addi %404, %405 : i32
    %407 = llvm.mlir.constant(1 : i64) : i64
    %408 = llvm.alloca %407 x i32 : (i64) -> !llvm.ptr
    llvm.store %406, %408 : i32, !llvm.ptr
    %409 = arith.constant 9 : i32
    %410 = llvm.mlir.constant(1 : i64) : i64
    %411 = llvm.alloca %410 x i32 : (i64) -> !llvm.ptr
    llvm.store %409, %411 : i32, !llvm.ptr
    cf.br ^bb87
    ^bb87:
    %412 = llvm.load %408 : !llvm.ptr -> i32
    %413 = llvm.load %411 : !llvm.ptr -> i32
    %414 = arith.cmpi slt, %412, %413 : i32
    cf.cond_br %414, ^bb88, ^bb89
    ^bb88:
      %416 = llvm.load %408 : !llvm.ptr -> i32
      %417 = arith.extsi %416 : i32 to i64
      %418 = llvm.getelementptr %arg0[%417] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %415 = llvm.load %418 : !llvm.ptr -> i8
      %420 = llvm.load %411 : !llvm.ptr -> i32
      %421 = arith.extsi %420 : i32 to i64
      %422 = llvm.getelementptr %arg0[%421] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %419 = llvm.load %422 : !llvm.ptr -> i8
      %423 = llvm.load %408 : !llvm.ptr -> i32
      %424 = arith.extsi %423 : i32 to i64
      %425 = llvm.getelementptr %arg0[%424] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %419, %425 : i8, !llvm.ptr
      %426 = llvm.load %411 : !llvm.ptr -> i32
      %427 = arith.extsi %426 : i32 to i64
      %428 = llvm.getelementptr %arg0[%427] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %415, %428 : i8, !llvm.ptr
      %429 = llvm.load %408 : !llvm.ptr -> i32
      %430 = arith.constant 1 : i32
      %431 = arith.addi %429, %430 : i32
      llvm.store %431, %408 : i32, !llvm.ptr
      %432 = llvm.load %411 : !llvm.ptr -> i32
      %433 = arith.constant 1 : i32
      %434 = arith.subi %432, %433 : i32
      llvm.store %434, %411 : i32, !llvm.ptr
      cf.br ^bb87
    ^bb89:
    %435 = arith.constant 1 : i1
    func.return %435 : i1
  }
  func.func @digits_to_num(%arg0: !llvm.ptr) -> i64 {
    %436 = arith.constant 0 : i32
    %437 = arith.extsi %436 : i32 to i64
    %438 = llvm.mlir.constant(1 : i64) : i64
    %439 = llvm.alloca %438 x i64 : (i64) -> !llvm.ptr
    llvm.store %437, %439 : i64, !llvm.ptr
    %440 = arith.constant 0 : i32
    %441 = arith.constant 10 : i32
    %442 = arith.index_cast %440 : i32 to index
    %443 = arith.index_cast %441 : i32 to index
    %445 = arith.constant 1 : index
    %446 = arith.constant -1 : index
    %447 = arith.cmpi sle, %442, %443 : index
    %444 = arith.select %447, %445, %446 : index
    cf.br ^bb90(%442 : index)
    ^bb90(%448: index):
    %449 = arith.cmpi slt, %448, %443 : index
    %450 = arith.cmpi sgt, %448, %443 : index
    %451 = arith.select %447, %449, %450 : i1
    cf.cond_br %451, ^bb91(%448 : index), ^bb92(%448 : index)
    ^bb91(%452: index):
      %453 = llvm.load %439 : !llvm.ptr -> i64
      %454 = arith.constant 10 : i32
      %456 = arith.extsi %454 : i32 to i64
      %455 = arith.muli %453, %456 : i64
      %458 = arith.index_cast %452 : index to i64
      %459 = llvm.getelementptr %arg0[%458] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %457 = llvm.load %459 : !llvm.ptr -> i8
      %460 = arith.extsi %457 : i8 to i64
      %461 = arith.addi %455, %460 : i64
      llvm.store %461, %439 : i64, !llvm.ptr
      %462 = arith.addi %452, %444 : index
      cf.br ^bb90(%462 : index)
    ^bb92(%463: index):
    %464 = llvm.load %439 : !llvm.ptr -> i64
    func.return %464 : i64
  }
  func.func @main() -> i32 {
    %466 = arith.constant 9 : i32
    %467 = arith.constant 8 : i32
    %468 = arith.constant 7 : i32
    %469 = arith.constant 6 : i32
    %470 = arith.constant 5 : i32
    %471 = arith.constant 4 : i32
    %472 = arith.constant 3 : i32
    %473 = arith.constant 2 : i32
    %474 = arith.constant 1 : i32
    %475 = arith.constant 0 : i32
    %476 = llvm.mlir.constant(1 : i64) : i64
    %477 = llvm.alloca %476 x !llvm.array<10 x i8> : (i64) -> !llvm.ptr
    %478 = llvm.mlir.zero : !llvm.array<10 x i8>
    llvm.store %478, %477 : !llvm.array<10 x i8>, !llvm.ptr
    %479 = arith.trunci %466 : i32 to i8
    %480 = arith.trunci %467 : i32 to i8
    %481 = arith.trunci %468 : i32 to i8
    %482 = arith.trunci %469 : i32 to i8
    %483 = arith.trunci %470 : i32 to i8
    %484 = arith.trunci %471 : i32 to i8
    %485 = arith.trunci %472 : i32 to i8
    %486 = arith.trunci %473 : i32 to i8
    %487 = arith.trunci %474 : i32 to i8
    %488 = arith.trunci %475 : i32 to i8
    %489 = llvm.mlir.constant(0 : i64) : i64
    %490 = llvm.getelementptr %477[0, %489] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<10 x i8>
    llvm.store %479, %490 : i8, !llvm.ptr
    %491 = llvm.mlir.constant(1 : i64) : i64
    %492 = llvm.getelementptr %477[0, %491] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<10 x i8>
    llvm.store %480, %492 : i8, !llvm.ptr
    %493 = llvm.mlir.constant(2 : i64) : i64
    %494 = llvm.getelementptr %477[0, %493] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<10 x i8>
    llvm.store %481, %494 : i8, !llvm.ptr
    %495 = llvm.mlir.constant(3 : i64) : i64
    %496 = llvm.getelementptr %477[0, %495] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<10 x i8>
    llvm.store %482, %496 : i8, !llvm.ptr
    %497 = llvm.mlir.constant(4 : i64) : i64
    %498 = llvm.getelementptr %477[0, %497] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<10 x i8>
    llvm.store %483, %498 : i8, !llvm.ptr
    %499 = llvm.mlir.constant(5 : i64) : i64
    %500 = llvm.getelementptr %477[0, %499] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<10 x i8>
    llvm.store %484, %500 : i8, !llvm.ptr
    %501 = llvm.mlir.constant(6 : i64) : i64
    %502 = llvm.getelementptr %477[0, %501] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<10 x i8>
    llvm.store %485, %502 : i8, !llvm.ptr
    %503 = llvm.mlir.constant(7 : i64) : i64
    %504 = llvm.getelementptr %477[0, %503] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<10 x i8>
    llvm.store %486, %504 : i8, !llvm.ptr
    %505 = llvm.mlir.constant(8 : i64) : i64
    %506 = llvm.getelementptr %477[0, %505] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<10 x i8>
    llvm.store %487, %506 : i8, !llvm.ptr
    %507 = llvm.mlir.constant(9 : i64) : i64
    %508 = llvm.getelementptr %477[0, %507] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<10 x i8>
    llvm.store %488, %508 : i8, !llvm.ptr
    cf.br ^bb93
    ^bb93:
    %509 = arith.constant 1 : i1
    cf.cond_br %509, ^bb94, ^bb95
    ^bb94:
      %510 = func.call @digits_to_num(%477) : (!llvm.ptr) -> i64
      %511 = arith.constant 1 : i32
      %512 = arith.constant 10 : i32
      %513 = arith.index_cast %511 : i32 to index
      %514 = arith.index_cast %512 : i32 to index
      %516 = arith.constant 1 : index
      %517 = arith.constant -1 : index
      %518 = arith.cmpi sle, %513, %514 : index
      %515 = arith.select %518, %516, %517 : index
      cf.br ^bb96(%513 : index)
      ^bb96(%519: index):
      %520 = arith.cmpi slt, %519, %514 : index
      %521 = arith.cmpi sgt, %519, %514 : index
      %522 = arith.select %518, %520, %521 : i1
      cf.cond_br %522, ^bb97(%519 : index), ^bb98(%519 : index)
      ^bb97(%523: index):
        %525 = arith.constant 0 : i32
        %526 = arith.extsi %525 : i32 to i64
        %527 = llvm.getelementptr %477[0, %526] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<10 x i8>
        %524 = llvm.load %527 : !llvm.ptr -> i8
        %528 = arith.constant 0 : i32
        %530 = arith.extsi %524 : i8 to i32
        %529 = arith.cmpi ne, %530, %528 : i32
        %531 = scf.if %529 -> (i1) {
          %533 = arith.index_cast %523 : index to i64
          %534 = llvm.getelementptr %477[0, %533] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<10 x i8>
          %532 = llvm.load %534 : !llvm.ptr -> i8
          %535 = arith.constant 0 : i32
          %537 = arith.extsi %532 : i8 to i32
          %536 = arith.cmpi ne, %537, %535 : i32
          scf.yield %536 : i1
        } else {
          %538 = arith.constant false
          scf.yield %538 : i1
        }
        cf.cond_br %531, ^bb99, ^bb100
        ^bb99:
          %539 = arith.constant 0 : i32
          %540 = arith.extsi %539 : i32 to i64
          %541 = arith.constant 0 : i32
          %542 = arith.index_cast %541 : i32 to index
          %543 = arith.index_cast %523 : i32 to index
          %545 = arith.constant 1 : index
          %546 = arith.constant -1 : index
          %547 = arith.cmpi sle, %542, %543 : index
          %544 = arith.select %547, %545, %546 : index
          cf.br ^bb102(%542, %540 : index, i64)
          ^bb102(%548: index, %549: i64):
          %550 = arith.cmpi slt, %548, %543 : index
          %551 = arith.cmpi sgt, %548, %543 : index
          %552 = arith.select %547, %550, %551 : i1
          cf.cond_br %552, ^bb103(%548, %549 : index, i64), ^bb104(%548, %549 : index, i64)
          ^bb103(%553: index, %554: i64):
            %555 = arith.constant 10 : i32
            %557 = arith.extsi %555 : i32 to i64
            %556 = arith.muli %554, %557 : i64
            %559 = arith.index_cast %553 : index to i64
            %560 = llvm.getelementptr %477[0, %559] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<10 x i8>
            %558 = llvm.load %560 : !llvm.ptr -> i8
            %561 = arith.extsi %558 : i8 to i64
            %562 = arith.addi %556, %561 : i64
            %563 = arith.addi %553, %544 : index
            cf.br ^bb102(%563, %562 : index, i64)
          ^bb104(%564: index, %565: i64):
          %566 = arith.constant 0 : i32
          %567 = arith.extsi %566 : i32 to i64
          %568 = arith.constant 10 : i32
          %569 = arith.index_cast %523 : i32 to index
          %570 = arith.index_cast %568 : i32 to index
          %572 = arith.constant 1 : index
          %573 = arith.constant -1 : index
          %574 = arith.cmpi sle, %569, %570 : index
          %571 = arith.select %574, %572, %573 : index
          cf.br ^bb105(%569, %567 : index, i64)
          ^bb105(%575: index, %576: i64):
          %577 = arith.cmpi slt, %575, %570 : index
          %578 = arith.cmpi sgt, %575, %570 : index
          %579 = arith.select %574, %577, %578 : i1
          cf.cond_br %579, ^bb106(%575, %576 : index, i64), ^bb107(%575, %576 : index, i64)
          ^bb106(%580: index, %581: i64):
            %582 = arith.constant 10 : i32
            %584 = arith.extsi %582 : i32 to i64
            %583 = arith.muli %581, %584 : i64
            %586 = arith.index_cast %580 : index to i64
            %587 = llvm.getelementptr %477[0, %586] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<10 x i8>
            %585 = llvm.load %587 : !llvm.ptr -> i8
            %588 = arith.extsi %585 : i8 to i64
            %589 = arith.addi %583, %588 : i64
            %590 = arith.addi %580, %571 : index
            cf.br ^bb105(%590, %589 : index, i64)
          ^bb107(%591: index, %592: i64):
          %593 = func.call @gcd(%565, %592) : (i64, i64) -> i64
          %594 = arith.constant 3 : i32
          %595 = arith.constant 1 : i32
          %597 = arith.extsi %595 : i32 to i64
          %596 = arith.addi %593, %597 : i64
          %598 = arith.index_cast %594 : i32 to index
          %599 = arith.index_cast %596 : i32 to index
          %600 = arith.constant 3 : index
          cf.br ^bb108(%598 : index)
          ^bb108(%601: index):
          %602 = arith.cmpi slt, %601, %599 : index
          cf.cond_br %602, ^bb109(%601 : index), ^bb110(%601 : index)
          ^bb109(%603: index):
            %605 = arith.trunci %565 : i64 to i32
            %606 = arith.index_cast %603 : index to i32
            %604 = arith.remsi %605, %606 : i32
            %607 = arith.constant 0 : i32
            %608 = arith.cmpi eq, %604, %607 : i32
            %609 = scf.if %608 -> (i1) {
              %611 = arith.trunci %592 : i64 to i32
              %612 = arith.index_cast %603 : index to i32
              %610 = arith.remsi %611, %612 : i32
              %613 = arith.constant 0 : i32
              %614 = arith.cmpi eq, %610, %613 : i32
              scf.yield %614 : i1
            } else {
              %615 = arith.constant false
              scf.yield %615 : i1
            }
            cf.cond_br %609, ^bb111, ^bb112
            ^bb111:
              %617 = arith.trunci %565 : i64 to i32
              %618 = arith.index_cast %603 : index to i32
              %616 = arith.divsi %617, %618 : i32
              %619 = arith.extsi %616 : i32 to i64
              %621 = arith.trunci %592 : i64 to i32
              %622 = arith.index_cast %603 : index to i32
              %620 = arith.divsi %621, %622 : i32
              %623 = arith.extsi %620 : i32 to i64
              %625 = arith.index_cast %603 : index to i64
              %624 = func.call @concat3(%625, %619, %623) : (i64, i64, i64) -> i64
              %626 = func.call @digit_len(%624) : (i64) -> i32
              %627 = arith.constant 10 : i32
              %628 = arith.cmpi eq, %626, %627 : i32
              %629 = scf.if %628 -> (i1) {
                %630 = func.call @is_pandigital_mask(%624) : (i64) -> i1
                scf.yield %630 : i1
              } else {
                %631 = arith.constant false
                scf.yield %631 : i1
              }
              cf.cond_br %629, ^bb114, ^bb115
              ^bb114:
                %632 = llvm.mlir.addressof @str_0 : !llvm.ptr
                %633 = llvm.call @printf(%632, %510) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
                %634 = arith.constant 0 : i32
                func.return %634 : i32
              ^bb115:
                cf.br ^bb116
              ^bb116:
              cf.br ^bb113
            ^bb112:
              cf.br ^bb113
            ^bb113:
            %635 = arith.addi %603, %600 : index
            cf.br ^bb108(%635 : index)
          ^bb110(%636: index):
          cf.br ^bb101
        ^bb100:
          cf.br ^bb101
        ^bb101:
        %637 = arith.addi %523, %515 : index
        cf.br ^bb96(%637 : index)
      ^bb98(%638: index):
      %639 = func.call @prev_perm(%477) : (!llvm.ptr) -> i1
      %640 = arith.constant 0 : i1
      %641 = arith.cmpi eq, %639, %640 : i1
      cf.cond_br %641, ^bb117, ^bb118
      ^bb117:
        cf.br ^bb95
      ^bb118:
        cf.br ^bb119
      ^bb119:
      cf.br ^bb93
    ^bb95:
    %642 = llvm.mlir.addressof @str_1 : !llvm.ptr
    %643 = llvm.call @printf(%642) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr) -> i32
    %644 = arith.constant 1 : i32
    func.return %644 : i32
  }
}