Problem 466

Distinct Terms in a Multiplication Table — P(64, 10^16). Partition by maximal divisor d <= m; count r <= n avoiding forbidden divisibility via inclusion-exclusion with LCM pruning + memoization.

Answer258381958195474745
Output258381958195474745
StatusPASS
Native helperno
Runtime860 ms
Peak memory98944 KB
Time complexityO(n log n) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n log n)O(1)
Space complexityO(n^2)O(1)
ApproachFlow solutionClosed-form formula
VerdictSuboptimal

Flow source

# Project Euler 466
# Distinct Terms in a Multiplication Table — P(64, 10^16).
# Partition by maximal divisor d <= m; count r <= n avoiding forbidden
# divisibility via inclusion-exclusion with LCM pruning + memoization.

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

let mut G_n: i64 = 0
let mut G_divs: ptr<i64> = null
let mut G_ndiv: i64 = 0
let mut G_memo_k1: ptr<i64> = null
let mut G_memo_k2: ptr<i64> = null
let mut G_memo_v: ptr<i64> = null
let mut G_memo_u: ptr<i8> = null
let mut G_memo_cap: i64 = 4000037

function gcd64(a0: i64, b0: i64) -> i64 {
    let mut a: i64 = a0
    let mut b: i64 = b0
    while b != 0 {
        let t: i64 = a % b
        a = b
        b = t
    }
    if a < 0 { return 0 - a }
    return a
}

function memo_clear() -> void {
    let mut i: i64 = 0
    while i < G_memo_cap {
        G_memo_u[i] = 0
        i = i + 1
    }
}

function ie_count(start: i64, cur: i64) -> i64 {
    # Count r in 1..G_n divisible by some G_divs[start..] via IE, given current lcm=cur.
    let key1: i64 = start
    let key2: i64 = cur
    let mut slot: i64 = (key1 * 1315423911 + key2) % G_memo_cap
    if slot < 0 { slot = 0 - slot }
    while G_memo_u[slot] != 0 {
        if G_memo_k1[slot] == key1 && G_memo_k2[slot] == key2 {
            return G_memo_v[slot]
        }
        slot = slot + 1
        if slot == G_memo_cap { slot = 0 }
    }
    let mut total: i64 = 0
    let mut i: i64 = start
    while i < G_ndiv {
        let d: i64 = G_divs[i]
        let g: i64 = gcd64(cur, d)
        let dg: i64 = d / g
        if dg > G_n / cur {
            i = i + 1
        } else {
            let nl: i64 = cur / g * d
            total = total + G_n / nl - ie_count(i + 1, nl)
            i = i + 1
        }
    }
    G_memo_u[slot] = 1
    G_memo_k1[slot] = key1
    G_memo_k2[slot] = key2
    G_memo_v[slot] = total
    return total
}

function build_forbidden(d: i64, m: i64, out: ptr<i64>) -> i64 {
    # Collect e/gcd(e,d) for e=d+1..m, then keep minimal under divisibility.
    let raw: ptr<i64> = calloc(m + 1, 8)
    let mut nraw: i64 = 0
    let mut e: i64 = d + 1
    while e <= m {
        let v: i64 = e / gcd64(e, d)
        if v > 1 {
            raw[nraw] = v
            nraw = nraw + 1
        }
        e = e + 1
    }
    # sort ascending (insertion)
    let mut i: i64 = 1
    while i < nraw {
        let key: i64 = raw[i]
        let mut j: i64 = i
        while j > 0 && raw[j - 1] > key {
            raw[j] = raw[j - 1]
            j = j - 1
        }
        raw[j] = key
        i = i + 1
    }
    # unique
    let mut nu: i64 = 0
    i = 0
    while i < nraw {
        if nu == 0 || raw[i] != raw[nu - 1] {
            raw[nu] = raw[i]
            nu = nu + 1
        }
        i = i + 1
    }
    # minimal under divisibility
    let mut nout: i64 = 0
    i = 0
    while i < nu {
        let x: i64 = raw[i]
        let mut red: i64 = 0
        let mut k: i64 = 0
        while k < nout {
            if x % out[k] == 0 {
                red = 1
            }
            k = k + 1
        }
        if red == 0 {
            out[nout] = x
            nout = nout + 1
        }
        i = i + 1
    }
    free(raw)
    # sort descending for better LCM pruning
    i = 0
    while i < nout {
        let mut j: i64 = i + 1
        while j < nout {
            if out[j] > out[i] {
                let tmp: i64 = out[i]
                out[i] = out[j]
                out[j] = tmp
            }
            j = j + 1
        }
        i = i + 1
    }
    return nout
}

function count_bad(n: i64, divs: ptr<i64>, ndiv: i64) -> i64 {
    if ndiv == 0 { return 0 }
    G_n = n
    G_divs = divs
    G_ndiv = ndiv
    memo_clear()
    return ie_count(0, 1)
}

function P(m: i64, n: i64) -> i64 {
    let divs: ptr<i64> = calloc(m + 1, 8)
    let mut total: i64 = 0
    let mut d: i64 = 1
    while d <= m {
        let nd: i64 = build_forbidden(d, m, divs)
        let bad: i64 = count_bad(n, divs, nd)
        total = total + n - bad
        d = d + 1
    }
    free(divs)
    return total
}

function main() -> i32 {
    G_memo_k1 = calloc(G_memo_cap, 8)
    G_memo_k2 = calloc(G_memo_cap, 8)
    G_memo_v = calloc(G_memo_cap, 8)
    G_memo_u = calloc(G_memo_cap, 1)
    if G_memo_k1 == null || G_memo_k2 == null || G_memo_v == null || G_memo_u == null {
        return 1
    }
    printf("%lld\n", P(64, 10000000000000000))
    free(G_memo_u)
    free(G_memo_v)
    free(G_memo_k2)
    free(G_memo_k1)
    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 gcd64_i64_i64(int64_t a0, int64_t b0);
void memo_clear(void);
int64_t ie_count_i64_i64(int64_t start, int64_t cur);
int64_t build_forbidden_i64_i64_ptr_i64(int64_t d, int64_t m, int64_t* out);
int64_t count_bad_i64_ptr_i64_i64(int64_t n, int64_t* divs, int64_t ndiv);
int64_t P_i64_i64(int64_t m, int64_t n);
int32_t main(void);

/* Module statics */
static int64_t G_n = 0;
static int64_t* G_divs = NULL;
static int64_t G_ndiv = 0;
static int64_t* G_memo_k1 = NULL;
static int64_t* G_memo_k2 = NULL;
static int64_t* G_memo_v = NULL;
static int8_t* G_memo_u = NULL;
static int64_t G_memo_cap = 4000037;



int64_t gcd64_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;
    }
    if (a < 0) {
        return (0 - a);
    }
    return a;
}

void memo_clear(void) {
    int64_t i = 0;
    while (i < G_memo_cap) {
        G_memo_u[i] = 0;
        i = (i + 1);
    }
}

int64_t ie_count_i64_i64(int64_t start, int64_t cur) {
    int64_t key1 = start;
    int64_t key2 = cur;
    int64_t slot = FLOW_CHECKED_MOD((((key1 * 1315423911) + key2)), (G_memo_cap));
    if (slot < 0) {
        slot = (0 - slot);
    }
    while (G_memo_u[slot] != 0) {
        if ((G_memo_k1[slot] == key1 && G_memo_k2[slot] == key2)) {
            return G_memo_v[slot];
        }
        slot = (slot + 1);
        if (slot == G_memo_cap) {
            slot = 0;
        }
    }
    int64_t total = 0;
    int64_t i = start;
    while (i < G_ndiv) {
        int64_t d = G_divs[i];
        int64_t g = gcd64_i64_i64(cur, d);
        int64_t dg = FLOW_CHECKED_DIV((d), (g));
        if (dg > FLOW_CHECKED_DIV((G_n), (cur))) {
            i = (i + 1);
        } else {
            int64_t nl = (FLOW_CHECKED_DIV((cur), (g)) * d);
            total = ((total + FLOW_CHECKED_DIV((G_n), (nl))) - ie_count_i64_i64((i + 1), nl));
            i = (i + 1);
        }
    }
    G_memo_u[slot] = 1;
    G_memo_k1[slot] = key1;
    G_memo_k2[slot] = key2;
    G_memo_v[slot] = total;
    return total;
}

int64_t build_forbidden_i64_i64_ptr_i64(int64_t d, int64_t m, int64_t* out) {
    int64_t* raw = (int64_t*)(calloc((m + 1), 8));
    int64_t nraw = 0;
    int64_t e = (d + 1);
    while (e <= m) {
        int64_t v = FLOW_CHECKED_DIV((e), (gcd64_i64_i64(e, d)));
        if (v > 1) {
            raw[nraw] = v;
            nraw = (nraw + 1);
        }
        e = (e + 1);
    }
    int64_t i = 1;
    while (i < nraw) {
        int64_t key = raw[i];
        int64_t j = i;
        while ((j > 0 && raw[(j - 1)] > key)) {
            raw[j] = raw[(j - 1)];
            j = (j - 1);
        }
        raw[j] = key;
        i = (i + 1);
    }
    int64_t nu = 0;
    i = 0;
    while (i < nraw) {
        if ((nu == 0 || raw[i] != raw[(nu - 1)])) {
            raw[nu] = raw[i];
            nu = (nu + 1);
        }
        i = (i + 1);
    }
    int64_t nout = 0;
    i = 0;
    while (i < nu) {
        int64_t x = raw[i];
        int64_t red = 0;
        int64_t k = 0;
        while (k < nout) {
            if (FLOW_CHECKED_MOD((x), (out[k])) == 0) {
                red = 1;
            }
            k = (k + 1);
        }
        if (red == 0) {
            out[nout] = x;
            nout = (nout + 1);
        }
        i = (i + 1);
    }
    free(raw);
    i = 0;
    while (i < nout) {
        int64_t j = (i + 1);
        while (j < nout) {
            if (out[j] > out[i]) {
                int64_t tmp = out[i];
                out[i] = out[j];
                out[j] = tmp;
            }
            j = (j + 1);
        }
        i = (i + 1);
    }
    return nout;
}

int64_t count_bad_i64_ptr_i64_i64(int64_t n, int64_t* divs, int64_t ndiv) {
    if (ndiv == 0) {
        return 0;
    }
    G_n = n;
    G_divs = divs;
    G_ndiv = ndiv;
    memo_clear();
    return ie_count_i64_i64(0, 1);
}

int64_t P_i64_i64(int64_t m, int64_t n) {
    int64_t* divs = (int64_t*)(calloc((m + 1), 8));
    int64_t total = 0;
    int64_t d = 1;
    while (d <= m) {
        int64_t nd = build_forbidden_i64_i64_ptr_i64(d, m, divs);
        int64_t bad = count_bad_i64_ptr_i64_i64(n, divs, nd);
        total = ((total + n) - bad);
        d = (d + 1);
    }
    free(divs);
    return total;
}

int32_t main(void) {
    G_memo_k1 = calloc(G_memo_cap, 8);
    G_memo_k2 = calloc(G_memo_cap, 8);
    G_memo_v = calloc(G_memo_cap, 8);
    G_memo_u = calloc(G_memo_cap, 1);
    if ((((G_memo_k1 == NULL || G_memo_k2 == NULL) || G_memo_v == NULL) || G_memo_u == NULL)) {
        return 1;
    }
    printf("%lld\n", P_i64_i64(64, 10000000000000000));
    free(G_memo_u);
    free(G_memo_v);
    free(G_memo_k2);
    free(G_memo_k1);
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  // Module static: G_n
  llvm.mlir.global internal @G_n(0 : i64) : i64
  // Module static: G_divs
  llvm.mlir.global internal @G_divs() {addr_space = 0 : i32} : !llvm.ptr {
    %0 = llvm.mlir.zero : !llvm.ptr
    llvm.return %0 : !llvm.ptr
  }
  // Module static: G_ndiv
  llvm.mlir.global internal @G_ndiv(0 : i64) : i64
  // Module static: G_memo_k1
  llvm.mlir.global internal @G_memo_k1() {addr_space = 0 : i32} : !llvm.ptr {
    %1 = llvm.mlir.zero : !llvm.ptr
    llvm.return %1 : !llvm.ptr
  }
  // Module static: G_memo_k2
  llvm.mlir.global internal @G_memo_k2() {addr_space = 0 : i32} : !llvm.ptr {
    %2 = llvm.mlir.zero : !llvm.ptr
    llvm.return %2 : !llvm.ptr
  }
  // Module static: G_memo_v
  llvm.mlir.global internal @G_memo_v() {addr_space = 0 : i32} : !llvm.ptr {
    %3 = llvm.mlir.zero : !llvm.ptr
    llvm.return %3 : !llvm.ptr
  }
  // Module static: G_memo_u
  llvm.mlir.global internal @G_memo_u() {addr_space = 0 : i32} : !llvm.ptr {
    %4 = llvm.mlir.zero : !llvm.ptr
    llvm.return %4 : !llvm.ptr
  }
  // Module static: G_memo_cap
  llvm.mlir.global internal @G_memo_cap(4000037 : i64) : i64
  func.func @gcd64(%arg0: i64, %arg1: i64) -> i64 {
    %5 = llvm.mlir.constant(1 : i64) : i64
    %6 = llvm.alloca %5 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %6 : i64, !llvm.ptr
    %7 = llvm.mlir.constant(1 : i64) : i64
    %8 = llvm.alloca %7 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %8 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %9 = llvm.load %8 : !llvm.ptr -> i64
    %10 = arith.constant 0 : i32
    %12 = arith.extsi %10 : i32 to i64
    %11 = arith.cmpi ne, %9, %12 : i64
    cf.cond_br %11, ^bb1, ^bb2
    ^bb1:
      %13 = llvm.load %6 : !llvm.ptr -> i64
      %14 = llvm.load %8 : !llvm.ptr -> i64
      %15 = arith.remsi %13, %14 : i64
      %16 = llvm.load %8 : !llvm.ptr -> i64
      llvm.store %16, %6 : i64, !llvm.ptr
      llvm.store %15, %8 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %17 = llvm.load %6 : !llvm.ptr -> i64
    %18 = arith.constant 0 : i32
    %20 = arith.extsi %18 : i32 to i64
    %19 = arith.cmpi slt, %17, %20 : i64
    cf.cond_br %19, ^bb3, ^bb4
    ^bb3:
      %21 = arith.constant 0 : i32
      %22 = llvm.load %6 : !llvm.ptr -> i64
      %24 = arith.extsi %21 : i32 to i64
      %23 = arith.subi %24, %22 : i64
      func.return %23 : i64
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %25 = llvm.load %6 : !llvm.ptr -> i64
    func.return %25 : i64
  }
  func.func @memo_clear() -> () {
    %26 = arith.constant 0 : i32
    %27 = arith.extsi %26 : i32 to i64
    %28 = llvm.mlir.constant(1 : i64) : i64
    %29 = llvm.alloca %28 x i64 : (i64) -> !llvm.ptr
    llvm.store %27, %29 : i64, !llvm.ptr
    cf.br ^bb6
    ^bb6:
    %30 = llvm.load %29 : !llvm.ptr -> i64
    %31 = llvm.mlir.addressof @G_memo_cap : !llvm.ptr
    %32 = llvm.load %31 : !llvm.ptr -> i64
    %33 = arith.cmpi slt, %30, %32 : i64
    cf.cond_br %33, ^bb7, ^bb8
    ^bb7:
      %34 = arith.constant 0 : i32
      %35 = llvm.mlir.addressof @G_memo_u : !llvm.ptr
      %36 = llvm.load %35 : !llvm.ptr -> !llvm.ptr
      %37 = llvm.load %29 : !llvm.ptr -> i64
      %38 = arith.trunci %34 : i32 to i8
      %39 = llvm.getelementptr %36[%37] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %38, %39 : i8, !llvm.ptr
      %40 = llvm.load %29 : !llvm.ptr -> i64
      %41 = arith.constant 1 : i32
      %43 = arith.extsi %41 : i32 to i64
      %42 = arith.addi %40, %43 : i64
      llvm.store %42, %29 : i64, !llvm.ptr
      cf.br ^bb6
    ^bb8:
    func.return
  }
  func.func @ie_count(%arg0: i64, %arg1: i64) -> i64 {
    %44 = arith.constant 1315423911 : i32
    %46 = arith.extsi %44 : i32 to i64
    %45 = arith.muli %arg0, %46 : i64
    %47 = arith.addi %45, %arg1 : i64
    %48 = llvm.mlir.addressof @G_memo_cap : !llvm.ptr
    %49 = llvm.load %48 : !llvm.ptr -> i64
    %50 = arith.remsi %47, %49 : i64
    %51 = llvm.mlir.constant(1 : i64) : i64
    %52 = llvm.alloca %51 x i64 : (i64) -> !llvm.ptr
    llvm.store %50, %52 : i64, !llvm.ptr
    %53 = llvm.load %52 : !llvm.ptr -> i64
    %54 = arith.constant 0 : i32
    %56 = arith.extsi %54 : i32 to i64
    %55 = arith.cmpi slt, %53, %56 : i64
    cf.cond_br %55, ^bb9, ^bb10
    ^bb9:
      %57 = arith.constant 0 : i32
      %58 = llvm.load %52 : !llvm.ptr -> i64
      %60 = arith.extsi %57 : i32 to i64
      %59 = arith.subi %60, %58 : i64
      llvm.store %59, %52 : i64, !llvm.ptr
      cf.br ^bb11
    ^bb10:
      cf.br ^bb11
    ^bb11:
    cf.br ^bb12
    ^bb12:
    %62 = llvm.mlir.addressof @G_memo_u : !llvm.ptr
    %63 = llvm.load %62 : !llvm.ptr -> !llvm.ptr
    %64 = llvm.load %52 : !llvm.ptr -> i64
    %65 = llvm.getelementptr %63[%64] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    %61 = llvm.load %65 : !llvm.ptr -> i8
    %66 = arith.constant 0 : i32
    %68 = arith.extsi %61 : i8 to i32
    %67 = arith.cmpi ne, %68, %66 : i32
    cf.cond_br %67, ^bb13, ^bb14
    ^bb13:
      %70 = llvm.mlir.addressof @G_memo_k1 : !llvm.ptr
      %71 = llvm.load %70 : !llvm.ptr -> !llvm.ptr
      %72 = llvm.load %52 : !llvm.ptr -> i64
      %73 = llvm.getelementptr %71[%72] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %69 = llvm.load %73 : !llvm.ptr -> i64
      %74 = arith.cmpi eq, %69, %arg0 : i64
      %75 = scf.if %74 -> (i1) {
        %77 = llvm.mlir.addressof @G_memo_k2 : !llvm.ptr
        %78 = llvm.load %77 : !llvm.ptr -> !llvm.ptr
        %79 = llvm.load %52 : !llvm.ptr -> i64
        %80 = llvm.getelementptr %78[%79] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %76 = llvm.load %80 : !llvm.ptr -> i64
        %81 = arith.cmpi eq, %76, %arg1 : i64
        scf.yield %81 : i1
      } else {
        %82 = arith.constant false
        scf.yield %82 : i1
      }
      cf.cond_br %75, ^bb15, ^bb16
      ^bb15:
        %84 = llvm.mlir.addressof @G_memo_v : !llvm.ptr
        %85 = llvm.load %84 : !llvm.ptr -> !llvm.ptr
        %86 = llvm.load %52 : !llvm.ptr -> i64
        %87 = llvm.getelementptr %85[%86] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %83 = llvm.load %87 : !llvm.ptr -> i64
        func.return %83 : i64
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %88 = llvm.load %52 : !llvm.ptr -> i64
      %89 = arith.constant 1 : i32
      %91 = arith.extsi %89 : i32 to i64
      %90 = arith.addi %88, %91 : i64
      llvm.store %90, %52 : i64, !llvm.ptr
      %92 = llvm.load %52 : !llvm.ptr -> i64
      %93 = llvm.mlir.addressof @G_memo_cap : !llvm.ptr
      %94 = llvm.load %93 : !llvm.ptr -> i64
      %95 = arith.cmpi eq, %92, %94 : i64
      cf.cond_br %95, ^bb18, ^bb19
      ^bb18:
        %96 = arith.constant 0 : i32
        %97 = arith.extsi %96 : i32 to i64
        llvm.store %97, %52 : i64, !llvm.ptr
        cf.br ^bb20
      ^bb19:
        cf.br ^bb20
      ^bb20:
      cf.br ^bb12
    ^bb14:
    %98 = arith.constant 0 : i32
    %99 = arith.extsi %98 : i32 to i64
    %100 = llvm.mlir.constant(1 : i64) : i64
    %101 = llvm.alloca %100 x i64 : (i64) -> !llvm.ptr
    llvm.store %99, %101 : i64, !llvm.ptr
    %102 = llvm.mlir.constant(1 : i64) : i64
    %103 = llvm.alloca %102 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %103 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %104 = llvm.load %103 : !llvm.ptr -> i64
    %105 = llvm.mlir.addressof @G_ndiv : !llvm.ptr
    %106 = llvm.load %105 : !llvm.ptr -> i64
    %107 = arith.cmpi slt, %104, %106 : i64
    cf.cond_br %107, ^bb22, ^bb23
    ^bb22:
      %109 = llvm.mlir.addressof @G_divs : !llvm.ptr
      %110 = llvm.load %109 : !llvm.ptr -> !llvm.ptr
      %111 = llvm.load %103 : !llvm.ptr -> i64
      %112 = llvm.getelementptr %110[%111] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %108 = llvm.load %112 : !llvm.ptr -> i64
      %113 = func.call @gcd64(%arg1, %108) : (i64, i64) -> i64
      %114 = arith.divsi %108, %113 : i64
      %115 = llvm.mlir.addressof @G_n : !llvm.ptr
      %116 = llvm.load %115 : !llvm.ptr -> i64
      %117 = arith.divsi %116, %arg1 : i64
      %118 = arith.cmpi sgt, %114, %117 : i64
      cf.cond_br %118, ^bb24, ^bb25
      ^bb24:
        %119 = llvm.load %103 : !llvm.ptr -> i64
        %120 = arith.constant 1 : i32
        %122 = arith.extsi %120 : i32 to i64
        %121 = arith.addi %119, %122 : i64
        llvm.store %121, %103 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        %123 = arith.divsi %arg1, %113 : i64
        %124 = arith.muli %123, %108 : i64
        %125 = llvm.load %101 : !llvm.ptr -> i64
        %126 = llvm.mlir.addressof @G_n : !llvm.ptr
        %127 = llvm.load %126 : !llvm.ptr -> i64
        %128 = arith.divsi %127, %124 : i64
        %129 = arith.addi %125, %128 : i64
        %131 = llvm.load %103 : !llvm.ptr -> i64
        %132 = arith.constant 1 : i32
        %134 = arith.extsi %132 : i32 to i64
        %133 = arith.addi %131, %134 : i64
        %130 = func.call @ie_count(%133, %124) : (i64, i64) -> i64
        %135 = arith.subi %129, %130 : i64
        llvm.store %135, %101 : i64, !llvm.ptr
        %136 = llvm.load %103 : !llvm.ptr -> i64
        %137 = arith.constant 1 : i32
        %139 = arith.extsi %137 : i32 to i64
        %138 = arith.addi %136, %139 : i64
        llvm.store %138, %103 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb26:
      cf.br ^bb21
    ^bb23:
    %140 = arith.constant 1 : i32
    %141 = llvm.mlir.addressof @G_memo_u : !llvm.ptr
    %142 = llvm.load %141 : !llvm.ptr -> !llvm.ptr
    %143 = llvm.load %52 : !llvm.ptr -> i64
    %144 = arith.trunci %140 : i32 to i8
    %145 = llvm.getelementptr %142[%143] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %144, %145 : i8, !llvm.ptr
    %146 = llvm.mlir.addressof @G_memo_k1 : !llvm.ptr
    %147 = llvm.load %146 : !llvm.ptr -> !llvm.ptr
    %148 = llvm.load %52 : !llvm.ptr -> i64
    %149 = llvm.getelementptr %147[%148] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %arg0, %149 : i64, !llvm.ptr
    %150 = llvm.mlir.addressof @G_memo_k2 : !llvm.ptr
    %151 = llvm.load %150 : !llvm.ptr -> !llvm.ptr
    %152 = llvm.load %52 : !llvm.ptr -> i64
    %153 = llvm.getelementptr %151[%152] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %arg1, %153 : i64, !llvm.ptr
    %154 = llvm.load %101 : !llvm.ptr -> i64
    %155 = llvm.mlir.addressof @G_memo_v : !llvm.ptr
    %156 = llvm.load %155 : !llvm.ptr -> !llvm.ptr
    %157 = llvm.load %52 : !llvm.ptr -> i64
    %158 = llvm.getelementptr %156[%157] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %154, %158 : i64, !llvm.ptr
    %159 = llvm.load %101 : !llvm.ptr -> i64
    func.return %159 : i64
  }
  func.func @build_forbidden(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr) -> i64 {
    %161 = arith.constant 1 : i32
    %163 = arith.extsi %161 : i32 to i64
    %162 = arith.addi %arg1, %163 : i64
    %164 = arith.constant 8 : i32
    %165 = arith.extsi %164 : i32 to i64
    %160 = func.call @calloc(%162, %165) : (i64, i64) -> !llvm.ptr
    %166 = arith.constant 0 : i32
    %167 = arith.extsi %166 : i32 to i64
    %168 = llvm.mlir.constant(1 : i64) : i64
    %169 = llvm.alloca %168 x i64 : (i64) -> !llvm.ptr
    llvm.store %167, %169 : i64, !llvm.ptr
    %170 = arith.constant 1 : i32
    %172 = arith.extsi %170 : i32 to i64
    %171 = arith.addi %arg0, %172 : i64
    %173 = llvm.mlir.constant(1 : i64) : i64
    %174 = llvm.alloca %173 x i64 : (i64) -> !llvm.ptr
    llvm.store %171, %174 : i64, !llvm.ptr
    cf.br ^bb27
    ^bb27:
    %175 = llvm.load %174 : !llvm.ptr -> i64
    %176 = arith.cmpi sle, %175, %arg1 : i64
    cf.cond_br %176, ^bb28, ^bb29
    ^bb28:
      %177 = llvm.load %174 : !llvm.ptr -> i64
      %179 = llvm.load %174 : !llvm.ptr -> i64
      %178 = func.call @gcd64(%179, %arg0) : (i64, i64) -> i64
      %180 = arith.divsi %177, %178 : i64
      %181 = arith.constant 1 : i32
      %183 = arith.extsi %181 : i32 to i64
      %182 = arith.cmpi sgt, %180, %183 : i64
      cf.cond_br %182, ^bb30, ^bb31
      ^bb30:
        %184 = llvm.load %169 : !llvm.ptr -> i64
        %185 = llvm.getelementptr %160[%184] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %180, %185 : i64, !llvm.ptr
        %186 = llvm.load %169 : !llvm.ptr -> i64
        %187 = arith.constant 1 : i32
        %189 = arith.extsi %187 : i32 to i64
        %188 = arith.addi %186, %189 : i64
        llvm.store %188, %169 : i64, !llvm.ptr
        cf.br ^bb32
      ^bb31:
        cf.br ^bb32
      ^bb32:
      %190 = llvm.load %174 : !llvm.ptr -> i64
      %191 = arith.constant 1 : i32
      %193 = arith.extsi %191 : i32 to i64
      %192 = arith.addi %190, %193 : i64
      llvm.store %192, %174 : i64, !llvm.ptr
      cf.br ^bb27
    ^bb29:
    %194 = arith.constant 1 : i32
    %195 = arith.extsi %194 : i32 to i64
    %196 = llvm.mlir.constant(1 : i64) : i64
    %197 = llvm.alloca %196 x i64 : (i64) -> !llvm.ptr
    llvm.store %195, %197 : i64, !llvm.ptr
    cf.br ^bb33
    ^bb33:
    %198 = llvm.load %197 : !llvm.ptr -> i64
    %199 = llvm.load %169 : !llvm.ptr -> i64
    %200 = arith.cmpi slt, %198, %199 : i64
    cf.cond_br %200, ^bb34, ^bb35
    ^bb34:
      %202 = llvm.load %197 : !llvm.ptr -> i64
      %203 = llvm.getelementptr %160[%202] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %201 = llvm.load %203 : !llvm.ptr -> i64
      %204 = llvm.load %197 : !llvm.ptr -> i64
      %205 = llvm.mlir.constant(1 : i64) : i64
      %206 = llvm.alloca %205 x i64 : (i64) -> !llvm.ptr
      llvm.store %204, %206 : i64, !llvm.ptr
      cf.br ^bb36
      ^bb36:
      %207 = llvm.load %206 : !llvm.ptr -> i64
      %208 = arith.constant 0 : i32
      %210 = arith.extsi %208 : i32 to i64
      %209 = arith.cmpi sgt, %207, %210 : i64
      %211 = scf.if %209 -> (i1) {
        %213 = llvm.load %206 : !llvm.ptr -> i64
        %214 = arith.constant 1 : i32
        %216 = arith.extsi %214 : i32 to i64
        %215 = arith.subi %213, %216 : i64
        %217 = llvm.getelementptr %160[%215] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %212 = llvm.load %217 : !llvm.ptr -> i64
        %218 = arith.cmpi sgt, %212, %201 : i64
        scf.yield %218 : i1
      } else {
        %219 = arith.constant false
        scf.yield %219 : i1
      }
      cf.cond_br %211, ^bb37, ^bb38
      ^bb37:
        %221 = llvm.load %206 : !llvm.ptr -> i64
        %222 = arith.constant 1 : i32
        %224 = arith.extsi %222 : i32 to i64
        %223 = arith.subi %221, %224 : i64
        %225 = llvm.getelementptr %160[%223] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %220 = llvm.load %225 : !llvm.ptr -> i64
        %226 = llvm.load %206 : !llvm.ptr -> i64
        %227 = llvm.getelementptr %160[%226] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %220, %227 : i64, !llvm.ptr
        %228 = llvm.load %206 : !llvm.ptr -> i64
        %229 = arith.constant 1 : i32
        %231 = arith.extsi %229 : i32 to i64
        %230 = arith.subi %228, %231 : i64
        llvm.store %230, %206 : i64, !llvm.ptr
        cf.br ^bb36
      ^bb38:
      %232 = llvm.load %206 : !llvm.ptr -> i64
      %233 = llvm.getelementptr %160[%232] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %201, %233 : i64, !llvm.ptr
      %234 = llvm.load %197 : !llvm.ptr -> i64
      %235 = arith.constant 1 : i32
      %237 = arith.extsi %235 : i32 to i64
      %236 = arith.addi %234, %237 : i64
      llvm.store %236, %197 : i64, !llvm.ptr
      cf.br ^bb33
    ^bb35:
    %238 = arith.constant 0 : i32
    %239 = arith.extsi %238 : i32 to i64
    %240 = llvm.mlir.constant(1 : i64) : i64
    %241 = llvm.alloca %240 x i64 : (i64) -> !llvm.ptr
    llvm.store %239, %241 : i64, !llvm.ptr
    %242 = arith.constant 0 : i32
    %243 = arith.extsi %242 : i32 to i64
    llvm.store %243, %197 : i64, !llvm.ptr
    cf.br ^bb39
    ^bb39:
    %244 = llvm.load %197 : !llvm.ptr -> i64
    %245 = llvm.load %169 : !llvm.ptr -> i64
    %246 = arith.cmpi slt, %244, %245 : i64
    cf.cond_br %246, ^bb40, ^bb41
    ^bb40:
      %247 = llvm.load %241 : !llvm.ptr -> i64
      %248 = arith.constant 0 : i32
      %250 = arith.extsi %248 : i32 to i64
      %249 = arith.cmpi eq, %247, %250 : i64
      %251 = scf.if %249 -> (i1) {
        %252 = arith.constant true
        scf.yield %252 : i1
      } else {
        %254 = llvm.load %197 : !llvm.ptr -> i64
        %255 = llvm.getelementptr %160[%254] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %253 = llvm.load %255 : !llvm.ptr -> i64
        %257 = llvm.load %241 : !llvm.ptr -> i64
        %258 = arith.constant 1 : i32
        %260 = arith.extsi %258 : i32 to i64
        %259 = arith.subi %257, %260 : i64
        %261 = llvm.getelementptr %160[%259] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %256 = llvm.load %261 : !llvm.ptr -> i64
        %262 = arith.cmpi ne, %253, %256 : i64
        scf.yield %262 : i1
      }
      cf.cond_br %251, ^bb42, ^bb43
      ^bb42:
        %264 = llvm.load %197 : !llvm.ptr -> i64
        %265 = llvm.getelementptr %160[%264] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %263 = llvm.load %265 : !llvm.ptr -> i64
        %266 = llvm.load %241 : !llvm.ptr -> i64
        %267 = llvm.getelementptr %160[%266] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %263, %267 : i64, !llvm.ptr
        %268 = llvm.load %241 : !llvm.ptr -> i64
        %269 = arith.constant 1 : i32
        %271 = arith.extsi %269 : i32 to i64
        %270 = arith.addi %268, %271 : i64
        llvm.store %270, %241 : i64, !llvm.ptr
        cf.br ^bb44
      ^bb43:
        cf.br ^bb44
      ^bb44:
      %272 = llvm.load %197 : !llvm.ptr -> i64
      %273 = arith.constant 1 : i32
      %275 = arith.extsi %273 : i32 to i64
      %274 = arith.addi %272, %275 : i64
      llvm.store %274, %197 : i64, !llvm.ptr
      cf.br ^bb39
    ^bb41:
    %276 = arith.constant 0 : i32
    %277 = arith.extsi %276 : i32 to i64
    %278 = llvm.mlir.constant(1 : i64) : i64
    %279 = llvm.alloca %278 x i64 : (i64) -> !llvm.ptr
    llvm.store %277, %279 : i64, !llvm.ptr
    %280 = arith.constant 0 : i32
    %281 = arith.extsi %280 : i32 to i64
    llvm.store %281, %197 : i64, !llvm.ptr
    cf.br ^bb45
    ^bb45:
    %282 = llvm.load %197 : !llvm.ptr -> i64
    %283 = llvm.load %241 : !llvm.ptr -> i64
    %284 = arith.cmpi slt, %282, %283 : i64
    cf.cond_br %284, ^bb46, ^bb47
    ^bb46:
      %286 = llvm.load %197 : !llvm.ptr -> i64
      %287 = llvm.getelementptr %160[%286] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %285 = llvm.load %287 : !llvm.ptr -> i64
      %288 = arith.constant 0 : i32
      %289 = arith.extsi %288 : i32 to i64
      %290 = llvm.mlir.constant(1 : i64) : i64
      %291 = llvm.alloca %290 x i64 : (i64) -> !llvm.ptr
      llvm.store %289, %291 : i64, !llvm.ptr
      %292 = arith.constant 0 : i32
      %293 = arith.extsi %292 : i32 to i64
      %294 = llvm.mlir.constant(1 : i64) : i64
      %295 = llvm.alloca %294 x i64 : (i64) -> !llvm.ptr
      llvm.store %293, %295 : i64, !llvm.ptr
      cf.br ^bb48
      ^bb48:
      %296 = llvm.load %295 : !llvm.ptr -> i64
      %297 = llvm.load %279 : !llvm.ptr -> i64
      %298 = arith.cmpi slt, %296, %297 : i64
      cf.cond_br %298, ^bb49, ^bb50
      ^bb49:
        %300 = llvm.load %295 : !llvm.ptr -> i64
        %301 = llvm.getelementptr %arg2[%300] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %299 = llvm.load %301 : !llvm.ptr -> i64
        %302 = arith.remsi %285, %299 : i64
        %303 = arith.constant 0 : i32
        %305 = arith.extsi %303 : i32 to i64
        %304 = arith.cmpi eq, %302, %305 : i64
        cf.cond_br %304, ^bb51, ^bb52
        ^bb51:
          %306 = arith.constant 1 : i32
          %307 = arith.extsi %306 : i32 to i64
          llvm.store %307, %291 : i64, !llvm.ptr
          cf.br ^bb53
        ^bb52:
          cf.br ^bb53
        ^bb53:
        %308 = llvm.load %295 : !llvm.ptr -> i64
        %309 = arith.constant 1 : i32
        %311 = arith.extsi %309 : i32 to i64
        %310 = arith.addi %308, %311 : i64
        llvm.store %310, %295 : i64, !llvm.ptr
        cf.br ^bb48
      ^bb50:
      %312 = llvm.load %291 : !llvm.ptr -> i64
      %313 = arith.constant 0 : i32
      %315 = arith.extsi %313 : i32 to i64
      %314 = arith.cmpi eq, %312, %315 : i64
      cf.cond_br %314, ^bb54, ^bb55
      ^bb54:
        %316 = llvm.load %279 : !llvm.ptr -> i64
        %317 = llvm.getelementptr %arg2[%316] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %285, %317 : i64, !llvm.ptr
        %318 = llvm.load %279 : !llvm.ptr -> i64
        %319 = arith.constant 1 : i32
        %321 = arith.extsi %319 : i32 to i64
        %320 = arith.addi %318, %321 : i64
        llvm.store %320, %279 : i64, !llvm.ptr
        cf.br ^bb56
      ^bb55:
        cf.br ^bb56
      ^bb56:
      %322 = llvm.load %197 : !llvm.ptr -> i64
      %323 = arith.constant 1 : i32
      %325 = arith.extsi %323 : i32 to i64
      %324 = arith.addi %322, %325 : i64
      llvm.store %324, %197 : i64, !llvm.ptr
      cf.br ^bb45
    ^bb47:
    func.call @free(%160) : (!llvm.ptr) -> ()
    %327 = arith.constant 0 : i32
    %328 = arith.extsi %327 : i32 to i64
    llvm.store %328, %197 : i64, !llvm.ptr
    cf.br ^bb57
    ^bb57:
    %329 = llvm.load %197 : !llvm.ptr -> i64
    %330 = llvm.load %279 : !llvm.ptr -> i64
    %331 = arith.cmpi slt, %329, %330 : i64
    cf.cond_br %331, ^bb58, ^bb59
    ^bb58:
      %332 = llvm.load %197 : !llvm.ptr -> i64
      %333 = arith.constant 1 : i32
      %335 = arith.extsi %333 : i32 to i64
      %334 = arith.addi %332, %335 : i64
      %336 = llvm.mlir.constant(1 : i64) : i64
      %337 = llvm.alloca %336 x i64 : (i64) -> !llvm.ptr
      llvm.store %334, %337 : i64, !llvm.ptr
      cf.br ^bb60
      ^bb60:
      %338 = llvm.load %337 : !llvm.ptr -> i64
      %339 = llvm.load %279 : !llvm.ptr -> i64
      %340 = arith.cmpi slt, %338, %339 : i64
      cf.cond_br %340, ^bb61, ^bb62
      ^bb61:
        %342 = llvm.load %337 : !llvm.ptr -> i64
        %343 = llvm.getelementptr %arg2[%342] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %341 = llvm.load %343 : !llvm.ptr -> i64
        %345 = llvm.load %197 : !llvm.ptr -> i64
        %346 = llvm.getelementptr %arg2[%345] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %344 = llvm.load %346 : !llvm.ptr -> i64
        %347 = arith.cmpi sgt, %341, %344 : i64
        cf.cond_br %347, ^bb63, ^bb64
        ^bb63:
          %349 = llvm.load %197 : !llvm.ptr -> i64
          %350 = llvm.getelementptr %arg2[%349] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %348 = llvm.load %350 : !llvm.ptr -> i64
          %352 = llvm.load %337 : !llvm.ptr -> i64
          %353 = llvm.getelementptr %arg2[%352] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %351 = llvm.load %353 : !llvm.ptr -> i64
          %354 = llvm.load %197 : !llvm.ptr -> i64
          %355 = llvm.getelementptr %arg2[%354] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %351, %355 : i64, !llvm.ptr
          %356 = llvm.load %337 : !llvm.ptr -> i64
          %357 = llvm.getelementptr %arg2[%356] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %348, %357 : i64, !llvm.ptr
          cf.br ^bb65
        ^bb64:
          cf.br ^bb65
        ^bb65:
        %358 = llvm.load %337 : !llvm.ptr -> i64
        %359 = arith.constant 1 : i32
        %361 = arith.extsi %359 : i32 to i64
        %360 = arith.addi %358, %361 : i64
        llvm.store %360, %337 : i64, !llvm.ptr
        cf.br ^bb60
      ^bb62:
      %362 = llvm.load %197 : !llvm.ptr -> i64
      %363 = arith.constant 1 : i32
      %365 = arith.extsi %363 : i32 to i64
      %364 = arith.addi %362, %365 : i64
      llvm.store %364, %197 : i64, !llvm.ptr
      cf.br ^bb57
    ^bb59:
    %366 = llvm.load %279 : !llvm.ptr -> i64
    func.return %366 : i64
  }
  func.func @count_bad(%arg0: i64, %arg1: !llvm.ptr, %arg2: i64) -> i64 {
    %367 = arith.constant 0 : i32
    %369 = arith.extsi %367 : i32 to i64
    %368 = arith.cmpi eq, %arg2, %369 : i64
    cf.cond_br %368, ^bb66, ^bb67
    ^bb66:
      %370 = arith.constant 0 : i32
      %371 = arith.extsi %370 : i32 to i64
      func.return %371 : i64
    ^bb67:
      cf.br ^bb68
    ^bb68:
    %372 = llvm.mlir.addressof @G_n : !llvm.ptr
    llvm.store %arg0, %372 : i64, !llvm.ptr
    %373 = llvm.mlir.addressof @G_divs : !llvm.ptr
    llvm.store %arg1, %373 : !llvm.ptr, !llvm.ptr
    %374 = llvm.mlir.addressof @G_ndiv : !llvm.ptr
    llvm.store %arg2, %374 : i64, !llvm.ptr
    func.call @memo_clear() : () -> ()
    %377 = arith.constant 0 : i32
    %378 = arith.constant 1 : i32
    %379 = arith.extsi %377 : i32 to i64
    %380 = arith.extsi %378 : i32 to i64
    %376 = func.call @ie_count(%379, %380) : (i64, i64) -> i64
    func.return %376 : i64
  }
  func.func @P(%arg0: i64, %arg1: i64) -> i64 {
    %382 = arith.constant 1 : i32
    %384 = arith.extsi %382 : i32 to i64
    %383 = arith.addi %arg0, %384 : i64
    %385 = arith.constant 8 : i32
    %386 = arith.extsi %385 : i32 to i64
    %381 = func.call @calloc(%383, %386) : (i64, i64) -> !llvm.ptr
    %387 = arith.constant 0 : i32
    %388 = arith.extsi %387 : i32 to i64
    %389 = llvm.mlir.constant(1 : i64) : i64
    %390 = llvm.alloca %389 x i64 : (i64) -> !llvm.ptr
    llvm.store %388, %390 : i64, !llvm.ptr
    %391 = arith.constant 1 : i32
    %392 = arith.extsi %391 : i32 to i64
    %393 = llvm.mlir.constant(1 : i64) : i64
    %394 = llvm.alloca %393 x i64 : (i64) -> !llvm.ptr
    llvm.store %392, %394 : i64, !llvm.ptr
    cf.br ^bb69
    ^bb69:
    %395 = llvm.load %394 : !llvm.ptr -> i64
    %396 = arith.cmpi sle, %395, %arg0 : i64
    cf.cond_br %396, ^bb70, ^bb71
    ^bb70:
      %398 = llvm.load %394 : !llvm.ptr -> i64
      %397 = func.call @build_forbidden(%398, %arg0, %381) : (i64, i64, !llvm.ptr) -> i64
      %399 = func.call @count_bad(%arg1, %381, %397) : (i64, !llvm.ptr, i64) -> i64
      %400 = llvm.load %390 : !llvm.ptr -> i64
      %401 = arith.addi %400, %arg1 : i64
      %402 = arith.subi %401, %399 : i64
      llvm.store %402, %390 : i64, !llvm.ptr
      %403 = llvm.load %394 : !llvm.ptr -> i64
      %404 = arith.constant 1 : i32
      %406 = arith.extsi %404 : i32 to i64
      %405 = arith.addi %403, %406 : i64
      llvm.store %405, %394 : i64, !llvm.ptr
      cf.br ^bb69
    ^bb71:
    func.call @free(%381) : (!llvm.ptr) -> ()
    %408 = llvm.load %390 : !llvm.ptr -> i64
    func.return %408 : i64
  }
  func.func @main() -> i32 {
    %410 = llvm.mlir.addressof @G_memo_cap : !llvm.ptr
    %411 = llvm.load %410 : !llvm.ptr -> i64
    %412 = arith.constant 8 : i32
    %413 = arith.extsi %412 : i32 to i64
    %409 = func.call @calloc(%411, %413) : (i64, i64) -> !llvm.ptr
    %414 = llvm.mlir.addressof @G_memo_k1 : !llvm.ptr
    llvm.store %409, %414 : !llvm.ptr, !llvm.ptr
    %416 = llvm.mlir.addressof @G_memo_cap : !llvm.ptr
    %417 = llvm.load %416 : !llvm.ptr -> i64
    %418 = arith.constant 8 : i32
    %419 = arith.extsi %418 : i32 to i64
    %415 = func.call @calloc(%417, %419) : (i64, i64) -> !llvm.ptr
    %420 = llvm.mlir.addressof @G_memo_k2 : !llvm.ptr
    llvm.store %415, %420 : !llvm.ptr, !llvm.ptr
    %422 = llvm.mlir.addressof @G_memo_cap : !llvm.ptr
    %423 = llvm.load %422 : !llvm.ptr -> i64
    %424 = arith.constant 8 : i32
    %425 = arith.extsi %424 : i32 to i64
    %421 = func.call @calloc(%423, %425) : (i64, i64) -> !llvm.ptr
    %426 = llvm.mlir.addressof @G_memo_v : !llvm.ptr
    llvm.store %421, %426 : !llvm.ptr, !llvm.ptr
    %428 = llvm.mlir.addressof @G_memo_cap : !llvm.ptr
    %429 = llvm.load %428 : !llvm.ptr -> i64
    %430 = arith.constant 1 : i32
    %431 = arith.extsi %430 : i32 to i64
    %427 = func.call @calloc(%429, %431) : (i64, i64) -> !llvm.ptr
    %432 = llvm.mlir.addressof @G_memo_u : !llvm.ptr
    llvm.store %427, %432 : !llvm.ptr, !llvm.ptr
    %433 = llvm.mlir.addressof @G_memo_k1 : !llvm.ptr
    %434 = llvm.load %433 : !llvm.ptr -> !llvm.ptr
    %435 = llvm.mlir.zero : !llvm.ptr
    %436 = llvm.icmp "eq" %434, %435 : !llvm.ptr
    %437 = scf.if %436 -> (i1) {
      %438 = arith.constant true
      scf.yield %438 : i1
    } else {
      %439 = llvm.mlir.addressof @G_memo_k2 : !llvm.ptr
      %440 = llvm.load %439 : !llvm.ptr -> !llvm.ptr
      %441 = llvm.mlir.zero : !llvm.ptr
      %442 = llvm.icmp "eq" %440, %441 : !llvm.ptr
      scf.yield %442 : i1
    }
    %443 = scf.if %437 -> (i1) {
      %444 = arith.constant true
      scf.yield %444 : i1
    } else {
      %445 = llvm.mlir.addressof @G_memo_v : !llvm.ptr
      %446 = llvm.load %445 : !llvm.ptr -> !llvm.ptr
      %447 = llvm.mlir.zero : !llvm.ptr
      %448 = llvm.icmp "eq" %446, %447 : !llvm.ptr
      scf.yield %448 : i1
    }
    %449 = scf.if %443 -> (i1) {
      %450 = arith.constant true
      scf.yield %450 : i1
    } else {
      %451 = llvm.mlir.addressof @G_memo_u : !llvm.ptr
      %452 = llvm.load %451 : !llvm.ptr -> !llvm.ptr
      %453 = llvm.mlir.zero : !llvm.ptr
      %454 = llvm.icmp "eq" %452, %453 : !llvm.ptr
      scf.yield %454 : i1
    }
    cf.cond_br %449, ^bb72, ^bb73
    ^bb72:
      %455 = arith.constant 1 : i32
      func.return %455 : i32
    ^bb73:
      cf.br ^bb74
    ^bb74:
    %456 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %458 = arith.constant 64 : i32
    %459 = arith.constant 9999995705032704 : i32
    %460 = arith.extsi %458 : i32 to i64
    %461 = arith.extsi %459 : i32 to i64
    %457 = func.call @P(%460, %461) : (i64, i64) -> i64
    %462 = llvm.call @printf(%456, %457) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %464 = llvm.mlir.addressof @G_memo_u : !llvm.ptr
    %465 = llvm.load %464 : !llvm.ptr -> !llvm.ptr
    func.call @free(%465) : (!llvm.ptr) -> ()
    %467 = llvm.mlir.addressof @G_memo_v : !llvm.ptr
    %468 = llvm.load %467 : !llvm.ptr -> !llvm.ptr
    func.call @free(%468) : (!llvm.ptr) -> ()
    %470 = llvm.mlir.addressof @G_memo_k2 : !llvm.ptr
    %471 = llvm.load %470 : !llvm.ptr -> !llvm.ptr
    func.call @free(%471) : (!llvm.ptr) -> ()
    %473 = llvm.mlir.addressof @G_memo_k1 : !llvm.ptr
    %474 = llvm.load %473 : !llvm.ptr -> !llvm.ptr
    func.call @free(%474) : (!llvm.ptr) -> ()
    %475 = arith.constant 0 : i32
    func.return %475 : i32
  }
}