Problem 703

S(20) mod 1001001011. Functional graph with 2^20 states, topological peel then cycle DP.

Answer843437991
Output843437991
StatusPASS
Native helperno
Runtime50 ms
Peak memory31040 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(e log v)
Space complexityO(n^2)O(v)
ApproachFlow solutionKruskal or Prim algorithm
VerdictUnknown

Flow source

# Project Euler 703 - Circular Logic II
# S(20) mod 1001001011. Functional graph with 2^20 states,
# topological peel then cycle DP.

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

const MOD: i64 = 1001001011

function main() -> i32 {
    let n: i32 = 20
    let N: i64 = 1 << n

    let succ: ptr<i32> = malloc(N * 4) as ptr<i32>
    let indeg: ptr<i32> = calloc(N, 4) as ptr<i32>

    let mask: i32 = (1 << (n - 1)) - 1
    let shift: i32 = n - 3

    let mut s: i64 = 0
    while s < N {
        let t: i32 = (s as i32) >> shift
        let newbit: i32 = ((t >> 2) & 1) & (((t >> 1) & 1) ^ (t & 1))
        let ns: i32 = (((s as i32) & mask) << 1) | newbit
        succ[s] = ns
        indeg[ns] = indeg[ns] + 1
        s = s + 1
    }

    let acc0: ptr<i64> = malloc(N * 8) as ptr<i64>
    let acc1: ptr<i64> = malloc(N * 8) as ptr<i64>
    let mut i: i64 = 0
    while i < N {
        acc0[i] = 1
        acc1[i] = 1
        i = i + 1
    }

    let in_cycle: ptr<i8> = malloc(N) as ptr<i8>
    memset(in_cycle as ptr<void>, 1, N)

    let q: ptr<i32> = malloc(N * 4) as ptr<i32>
    let mut qh: i64 = 0
    let mut qt: i64 = 0
    let mut ii: i64 = 0
    while ii < N {
        if indeg[ii] == 0 {
            q[qt] = ii as i32
            qt = qt + 1
        }
        ii = ii + 1
    }

    while qh < qt {
        let u: i64 = q[qh] as i64
        qh = qh + 1
        if in_cycle[u] == 0 {
            continue
        }
        in_cycle[u] = 0
        let p: i64 = succ[u] as i64
        let dp0: i64 = acc0[u]
        let dp1: i64 = acc1[u]
        acc0[p] = ((acc0[p] as i128) * ((dp0 + dp1) % MOD) % MOD) as i64
        acc1[p] = ((acc1[p] as i128) * dp0 % MOD) as i64
        indeg[p] = indeg[p] - 1
        if indeg[p] == 0 {
            q[qt] = p as i32
            qt = qt + 1
        }
    }

    let visited: ptr<i8> = calloc(N, 1) as ptr<i8>
    let mut ans: i64 = 1
    let cycle: ptr<i32> = malloc(N * 4) as ptr<i32>

    let mut v: i64 = 0
    while v < N {
        if in_cycle[v] == 1 && visited[v] == 0 {
            let mut k: i64 = 0
            let mut u: i64 = v
            while visited[u] == 0 {
                visited[u] = 1
                cycle[k] = u as i32
                k = k + 1
                u = succ[u] as i64
            }

            # case1: cycle[0] contributes acc0
            let mut prev0: i64 = acc0[cycle[0] as i64] % MOD
            let mut prev1: i64 = 0
            let mut ci: i64 = 1
            while ci < k {
                let cur0: i64 = (((prev0 + prev1) % MOD) * (acc0[cycle[ci] as i64] % MOD)) % MOD
                let cur1: i64 = (prev0 * (acc1[cycle[ci] as i64] % MOD)) % MOD
                prev0 = cur0
                prev1 = cur1
                ci = ci + 1
            }
            let case1: i64 = (prev0 + prev1) % MOD

            # case2: cycle[0] contributes acc1
            prev0 = 0
            prev1 = acc1[cycle[0] as i64] % MOD
            ci = 1
            while ci < k {
                let cur0: i64 = (((prev0 + prev1) % MOD) * (acc0[cycle[ci] as i64] % MOD)) % MOD
                let cur1: i64 = (prev0 * (acc1[cycle[ci] as i64] % MOD)) % MOD
                prev0 = cur0
                prev1 = cur1
                ci = ci + 1
            }
            let case2: i64 = prev0

            ans = (ans * ((case1 + case2) % MOD)) % MOD
        }
        v = v + 1
    }

    printf("%lld\n", ans)

    free(succ as ptr<void>)
    free(indeg as ptr<void>)
    free(acc0 as ptr<void>)
    free(acc1 as ptr<void>)
    free(in_cycle as ptr<void>)
    free(q as ptr<void>)
    free(visited as ptr<void>)
    free(cycle as ptr<void>)
    return 0
}

Generated C

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
    while (flow_temp_head) {
        flow_temp_node* n = flow_temp_head;
        flow_temp_head = n->next;
        free(n);
    }
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
    flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
    if (!node) return NULL;
    node->next = flow_temp_head;
    flow_temp_head = node;
    if (!flow_temp_atexit_set) {
        flow_temp_atexit_set = 1;
        atexit(flow_temp_free_all);
    }
    return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
    size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
    char* r = (char*)flow_temp_alloc(la + lb + 1);
    if (!r) return NULL;
    if (la) memcpy(r, a, la);
    if (lb) memcpy(r + la, b, lb);
    r[la + lb] = '\0';
    return r;
}

#define __flow_in_arr(arr, val) __extension__ ({ \
    int _found = 0; \
    size_t _n = sizeof(arr)/sizeof((arr)[0]); \
    for (size_t _i = 0; _i < _n; _i++) { \
        if ((arr)[_i] == (val)) { _found = 1; break; } \
    } _found; })

/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
    fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
    abort();
#if defined(__GNUC__) || defined(__clang__)
    __builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")

#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif

#include <math.h>

void* _ui_state = NULL;

static inline float i32_to_f32(int32_t v) { return (float)v; }

/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }

int32_t main(void);

static const int64_t MOD = 1001001011;





int32_t main(void) {
    int32_t n = 20;
    int64_t N = FLOW_CHECKED_SHL((1), (n));
    int32_t* succ = (int32_t*)(((int32_t*)(malloc((N * 4)))));
    int32_t* indeg = (int32_t*)(((int32_t*)(calloc(N, 4))));
    int32_t mask = (FLOW_CHECKED_SHL((1), ((n - 1))) - 1);
    int32_t shift = (n - 3);
    int64_t s = 0;
    while (s < N) {
        int32_t t = FLOW_CHECKED_SHR((((int32_t)(s))), (shift));
        int32_t newbit = ((FLOW_CHECKED_SHR((t), (2)) & 1) & ((FLOW_CHECKED_SHR((t), (1)) & 1) ^ (t & 1)));
        int32_t ns = (FLOW_CHECKED_SHL(((((int32_t)(s)) & mask)), (1)) | newbit);
        succ[s] = ns;
        indeg[ns] = (indeg[ns] + 1);
        s = (s + 1);
    }
    int64_t* acc0 = (int64_t*)(((int64_t*)(malloc((N * 8)))));
    int64_t* acc1 = (int64_t*)(((int64_t*)(malloc((N * 8)))));
    int64_t i = 0;
    while (i < N) {
        acc0[i] = 1;
        acc1[i] = 1;
        i = (i + 1);
    }
    int8_t* in_cycle = (int8_t*)(((int8_t*)(malloc(N))));
    memset(((void*)(in_cycle)), 1, N);
    int32_t* q = (int32_t*)(((int32_t*)(malloc((N * 4)))));
    int64_t qh = 0;
    int64_t qt = 0;
    int64_t ii = 0;
    while (ii < N) {
        if (indeg[ii] == 0) {
            q[qt] = ((int32_t)(ii));
            qt = (qt + 1);
        }
        ii = (ii + 1);
    }
    while (qh < qt) {
        int64_t u = ((int64_t)(q[qh]));
        qh = (qh + 1);
        if (in_cycle[u] == 0) {
            continue;
        }
        in_cycle[u] = 0;
        int64_t p = ((int64_t)(succ[u]));
        int64_t dp0 = acc0[u];
        int64_t dp1 = acc1[u];
        acc0[p] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(acc0[p])) * FLOW_CHECKED_MOD(((dp0 + dp1)), (MOD)))), (MOD))));
        acc1[p] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(acc1[p])) * dp0)), (MOD))));
        indeg[p] = (indeg[p] - 1);
        if (indeg[p] == 0) {
            q[qt] = ((int32_t)(p));
            qt = (qt + 1);
        }
    }
    int8_t* visited = (int8_t*)(((int8_t*)(calloc(N, 1))));
    int64_t ans = 1;
    int32_t* cycle = (int32_t*)(((int32_t*)(malloc((N * 4)))));
    int64_t v = 0;
    while (v < N) {
        if ((in_cycle[v] == 1 && visited[v] == 0)) {
            int64_t k = 0;
            int64_t u = v;
            while (visited[u] == 0) {
                visited[u] = 1;
                cycle[k] = ((int32_t)(u));
                k = (k + 1);
                u = ((int64_t)(succ[u]));
            }
            int64_t prev0 = FLOW_CHECKED_MOD((acc0[((int64_t)(cycle[0]))]), (MOD));
            int64_t prev1 = 0;
            int64_t ci = 1;
            while (ci < k) {
                int64_t cur0 = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((prev0 + prev1)), (MOD)) * FLOW_CHECKED_MOD((acc0[((int64_t)(cycle[ci]))]), (MOD)))), (MOD));
                int64_t cur1 = FLOW_CHECKED_MOD(((prev0 * FLOW_CHECKED_MOD((acc1[((int64_t)(cycle[ci]))]), (MOD)))), (MOD));
                prev0 = cur0;
                prev1 = cur1;
                ci = (ci + 1);
            }
            int64_t case1 = FLOW_CHECKED_MOD(((prev0 + prev1)), (MOD));
            prev0 = 0;
            prev1 = FLOW_CHECKED_MOD((acc1[((int64_t)(cycle[0]))]), (MOD));
            ci = 1;
            while (ci < k) {
                int64_t cur0 = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((prev0 + prev1)), (MOD)) * FLOW_CHECKED_MOD((acc0[((int64_t)(cycle[ci]))]), (MOD)))), (MOD));
                int64_t cur1 = FLOW_CHECKED_MOD(((prev0 * FLOW_CHECKED_MOD((acc1[((int64_t)(cycle[ci]))]), (MOD)))), (MOD));
                prev0 = cur0;
                prev1 = cur1;
                ci = (ci + 1);
            }
            int64_t case2 = prev0;
            ans = FLOW_CHECKED_MOD(((ans * FLOW_CHECKED_MOD(((case1 + case2)), (MOD)))), (MOD));
        }
        v = (v + 1);
    }
    printf("%lld\n", ans);
    free(((void*)(succ)));
    free(((void*)(indeg)));
    free(((void*)(acc0)));
    free(((void*)(acc1)));
    free(((void*)(in_cycle)));
    free(((void*)(q)));
    free(((void*)(visited)));
    free(((void*)(cycle)));
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func private @malloc(i64) -> !llvm.ptr
  func.func private @memset(!llvm.ptr, i64, i64) -> !llvm.ptr
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(1001001011 : i64) : i64
  func.func @main() -> i32 {
    %0 = arith.constant 20 : i32
    %1 = arith.constant 1 : i32
    %2 = arith.shli %1, %0 : i32
    %3 = arith.extsi %2 : i32 to i64
    %5 = arith.constant 4 : i32
    %7 = arith.extsi %5 : i32 to i64
    %6 = arith.muli %3, %7 : i64
    %4 = func.call @malloc(%6) : (i64) -> !llvm.ptr
    %9 = arith.constant 4 : i32
    %10 = arith.extsi %9 : i32 to i64
    %8 = func.call @calloc(%3, %10) : (i64, i64) -> !llvm.ptr
    %11 = arith.constant 1 : i32
    %12 = arith.constant 1 : i32
    %13 = arith.subi %0, %12 : i32
    %14 = arith.shli %11, %13 : i32
    %15 = arith.constant 1 : i32
    %16 = arith.subi %14, %15 : i32
    %17 = arith.constant 3 : i32
    %18 = arith.subi %0, %17 : i32
    %19 = arith.constant 0 : i32
    %20 = arith.extsi %19 : i32 to i64
    %21 = llvm.mlir.constant(1 : i64) : i64
    %22 = llvm.alloca %21 x i64 : (i64) -> !llvm.ptr
    llvm.store %20, %22 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %23 = llvm.load %22 : !llvm.ptr -> i64
    %24 = arith.cmpi slt, %23, %3 : i64
    cf.cond_br %24, ^bb1, ^bb2
    ^bb1:
      %25 = llvm.load %22 : !llvm.ptr -> i64
      %26 = arith.trunci %25 : i64 to i32
      %27 = arith.shrsi %26, %18 : i32
      %28 = arith.constant 2 : i32
      %29 = arith.shrsi %27, %28 : i32
      %30 = arith.constant 1 : i32
      %31 = arith.andi %29, %30 : i32
      %32 = arith.constant 1 : i32
      %33 = arith.shrsi %27, %32 : i32
      %34 = arith.constant 1 : i32
      %35 = arith.andi %33, %34 : i32
      %36 = arith.constant 1 : i32
      %37 = arith.andi %27, %36 : i32
      %38 = arith.xori %35, %37 : i32
      %39 = arith.andi %31, %38 : i32
      %40 = llvm.load %22 : !llvm.ptr -> i64
      %41 = arith.trunci %40 : i64 to i32
      %42 = arith.andi %41, %16 : i32
      %43 = arith.constant 1 : i32
      %44 = arith.shli %42, %43 : i32
      %45 = arith.ori %44, %39 : i32
      %46 = llvm.load %22 : !llvm.ptr -> i64
      %47 = llvm.getelementptr %4[%46] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %45, %47 : i32, !llvm.ptr
      %49 = arith.extsi %45 : i32 to i64
      %50 = llvm.getelementptr %8[%49] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %48 = llvm.load %50 : !llvm.ptr -> i32
      %51 = arith.constant 1 : i32
      %52 = arith.addi %48, %51 : i32
      %53 = arith.extsi %45 : i32 to i64
      %54 = llvm.getelementptr %8[%53] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %52, %54 : i32, !llvm.ptr
      %55 = llvm.load %22 : !llvm.ptr -> i64
      %56 = arith.constant 1 : i32
      %58 = arith.extsi %56 : i32 to i64
      %57 = arith.addi %55, %58 : i64
      llvm.store %57, %22 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %60 = arith.constant 8 : i32
    %62 = arith.extsi %60 : i32 to i64
    %61 = arith.muli %3, %62 : i64
    %59 = func.call @malloc(%61) : (i64) -> !llvm.ptr
    %64 = arith.constant 8 : i32
    %66 = arith.extsi %64 : i32 to i64
    %65 = arith.muli %3, %66 : i64
    %63 = func.call @malloc(%65) : (i64) -> !llvm.ptr
    %67 = arith.constant 0 : i32
    %68 = arith.extsi %67 : i32 to i64
    %69 = llvm.mlir.constant(1 : i64) : i64
    %70 = llvm.alloca %69 x i64 : (i64) -> !llvm.ptr
    llvm.store %68, %70 : i64, !llvm.ptr
    cf.br ^bb3
    ^bb3:
    %71 = llvm.load %70 : !llvm.ptr -> i64
    %72 = arith.cmpi slt, %71, %3 : i64
    cf.cond_br %72, ^bb4, ^bb5
    ^bb4:
      %73 = arith.constant 1 : i32
      %74 = llvm.load %70 : !llvm.ptr -> i64
      %75 = arith.extsi %73 : i32 to i64
      %76 = llvm.getelementptr %59[%74] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %75, %76 : i64, !llvm.ptr
      %77 = arith.constant 1 : i32
      %78 = llvm.load %70 : !llvm.ptr -> i64
      %79 = arith.extsi %77 : i32 to i64
      %80 = llvm.getelementptr %63[%78] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %79, %80 : i64, !llvm.ptr
      %81 = llvm.load %70 : !llvm.ptr -> i64
      %82 = arith.constant 1 : i32
      %84 = arith.extsi %82 : i32 to i64
      %83 = arith.addi %81, %84 : i64
      llvm.store %83, %70 : i64, !llvm.ptr
      cf.br ^bb3
    ^bb5:
    %85 = func.call @malloc(%3) : (i64) -> !llvm.ptr
    %87 = arith.constant 1 : i32
    %88 = arith.extsi %87 : i32 to i64
    %86 = func.call @memset(%85, %88, %3) : (!llvm.ptr, i64, i64) -> !llvm.ptr
    %90 = arith.constant 4 : i32
    %92 = arith.extsi %90 : i32 to i64
    %91 = arith.muli %3, %92 : i64
    %89 = func.call @malloc(%91) : (i64) -> !llvm.ptr
    %93 = arith.constant 0 : i32
    %94 = arith.extsi %93 : i32 to i64
    %95 = llvm.mlir.constant(1 : i64) : i64
    %96 = llvm.alloca %95 x i64 : (i64) -> !llvm.ptr
    llvm.store %94, %96 : i64, !llvm.ptr
    %97 = arith.constant 0 : i32
    %98 = arith.extsi %97 : i32 to i64
    %99 = llvm.mlir.constant(1 : i64) : i64
    %100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
    llvm.store %98, %100 : i64, !llvm.ptr
    %101 = arith.constant 0 : i32
    %102 = arith.extsi %101 : i32 to i64
    %103 = llvm.mlir.constant(1 : i64) : i64
    %104 = llvm.alloca %103 x i64 : (i64) -> !llvm.ptr
    llvm.store %102, %104 : i64, !llvm.ptr
    cf.br ^bb6
    ^bb6:
    %105 = llvm.load %104 : !llvm.ptr -> i64
    %106 = arith.cmpi slt, %105, %3 : i64
    cf.cond_br %106, ^bb7, ^bb8
    ^bb7:
      %108 = llvm.load %104 : !llvm.ptr -> i64
      %109 = llvm.getelementptr %8[%108] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %107 = llvm.load %109 : !llvm.ptr -> i32
      %110 = arith.constant 0 : i32
      %111 = arith.cmpi eq, %107, %110 : i32
      cf.cond_br %111, ^bb9, ^bb10
      ^bb9:
        %112 = llvm.load %104 : !llvm.ptr -> i64
        %113 = arith.trunci %112 : i64 to i32
        %114 = llvm.load %100 : !llvm.ptr -> i64
        %115 = llvm.getelementptr %89[%114] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %113, %115 : i32, !llvm.ptr
        %116 = llvm.load %100 : !llvm.ptr -> i64
        %117 = arith.constant 1 : i32
        %119 = arith.extsi %117 : i32 to i64
        %118 = arith.addi %116, %119 : i64
        llvm.store %118, %100 : i64, !llvm.ptr
        cf.br ^bb11
      ^bb10:
        cf.br ^bb11
      ^bb11:
      %120 = llvm.load %104 : !llvm.ptr -> i64
      %121 = arith.constant 1 : i32
      %123 = arith.extsi %121 : i32 to i64
      %122 = arith.addi %120, %123 : i64
      llvm.store %122, %104 : i64, !llvm.ptr
      cf.br ^bb6
    ^bb8:
    cf.br ^bb12
    ^bb12:
    %124 = llvm.load %96 : !llvm.ptr -> i64
    %125 = llvm.load %100 : !llvm.ptr -> i64
    %126 = arith.cmpi slt, %124, %125 : i64
    cf.cond_br %126, ^bb13, ^bb14
    ^bb13:
      %128 = llvm.load %96 : !llvm.ptr -> i64
      %129 = llvm.getelementptr %89[%128] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %127 = llvm.load %129 : !llvm.ptr -> i32
      %130 = arith.extsi %127 : i32 to i64
      %131 = llvm.load %96 : !llvm.ptr -> i64
      %132 = arith.constant 1 : i32
      %134 = arith.extsi %132 : i32 to i64
      %133 = arith.addi %131, %134 : i64
      llvm.store %133, %96 : i64, !llvm.ptr
      %136 = llvm.getelementptr %85[%130] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %135 = llvm.load %136 : !llvm.ptr -> i8
      %137 = arith.constant 0 : i32
      %139 = arith.extsi %135 : i8 to i32
      %138 = arith.cmpi eq, %139, %137 : i32
      cf.cond_br %138, ^bb15, ^bb16
      ^bb15:
        cf.br ^bb12
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %140 = arith.constant 0 : i32
      %141 = arith.trunci %140 : i32 to i8
      %142 = llvm.getelementptr %85[%130] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %141, %142 : i8, !llvm.ptr
      %144 = llvm.getelementptr %4[%130] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %143 = llvm.load %144 : !llvm.ptr -> i32
      %145 = arith.extsi %143 : i32 to i64
      %147 = llvm.getelementptr %59[%130] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %146 = llvm.load %147 : !llvm.ptr -> i64
      %149 = llvm.getelementptr %63[%130] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %148 = llvm.load %149 : !llvm.ptr -> i64
      %151 = llvm.getelementptr %59[%145] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %150 = llvm.load %151 : !llvm.ptr -> i64
      %152 = arith.extsi %150 : i64 to i128
      %153 = arith.addi %146, %148 : i64
      %154 = llvm.mlir.addressof @MOD : !llvm.ptr
      %155 = llvm.load %154 : !llvm.ptr -> i64
      %156 = arith.remsi %153, %155 : i64
      %158 = arith.trunci %152 : i128 to i64
      %157 = arith.muli %158, %156 : i64
      %159 = llvm.mlir.addressof @MOD : !llvm.ptr
      %160 = llvm.load %159 : !llvm.ptr -> i64
      %161 = arith.remsi %157, %160 : i64
      %162 = llvm.getelementptr %59[%145] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %161, %162 : i64, !llvm.ptr
      %164 = llvm.getelementptr %63[%145] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %163 = llvm.load %164 : !llvm.ptr -> i64
      %165 = arith.extsi %163 : i64 to i128
      %167 = arith.trunci %165 : i128 to i64
      %166 = arith.muli %167, %146 : i64
      %168 = llvm.mlir.addressof @MOD : !llvm.ptr
      %169 = llvm.load %168 : !llvm.ptr -> i64
      %170 = arith.remsi %166, %169 : i64
      %171 = llvm.getelementptr %63[%145] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %170, %171 : i64, !llvm.ptr
      %173 = llvm.getelementptr %8[%145] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %172 = llvm.load %173 : !llvm.ptr -> i32
      %174 = arith.constant 1 : i32
      %175 = arith.subi %172, %174 : i32
      %176 = llvm.getelementptr %8[%145] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %175, %176 : i32, !llvm.ptr
      %178 = llvm.getelementptr %8[%145] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %177 = llvm.load %178 : !llvm.ptr -> i32
      %179 = arith.constant 0 : i32
      %180 = arith.cmpi eq, %177, %179 : i32
      cf.cond_br %180, ^bb18, ^bb19
      ^bb18:
        %181 = arith.trunci %145 : i64 to i32
        %182 = llvm.load %100 : !llvm.ptr -> i64
        %183 = llvm.getelementptr %89[%182] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %181, %183 : i32, !llvm.ptr
        %184 = llvm.load %100 : !llvm.ptr -> i64
        %185 = arith.constant 1 : i32
        %187 = arith.extsi %185 : i32 to i64
        %186 = arith.addi %184, %187 : i64
        llvm.store %186, %100 : i64, !llvm.ptr
        cf.br ^bb20
      ^bb19:
        cf.br ^bb20
      ^bb20:
      cf.br ^bb12
    ^bb14:
    %189 = arith.constant 1 : i32
    %190 = arith.extsi %189 : i32 to i64
    %188 = func.call @calloc(%3, %190) : (i64, i64) -> !llvm.ptr
    %191 = arith.constant 1 : i32
    %192 = arith.extsi %191 : i32 to i64
    %193 = llvm.mlir.constant(1 : i64) : i64
    %194 = llvm.alloca %193 x i64 : (i64) -> !llvm.ptr
    llvm.store %192, %194 : i64, !llvm.ptr
    %196 = arith.constant 4 : i32
    %198 = arith.extsi %196 : i32 to i64
    %197 = arith.muli %3, %198 : i64
    %195 = func.call @malloc(%197) : (i64) -> !llvm.ptr
    %199 = arith.constant 0 : i32
    %200 = arith.extsi %199 : i32 to i64
    %201 = llvm.mlir.constant(1 : i64) : i64
    %202 = llvm.alloca %201 x i64 : (i64) -> !llvm.ptr
    llvm.store %200, %202 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %203 = llvm.load %202 : !llvm.ptr -> i64
    %204 = arith.cmpi slt, %203, %3 : i64
    cf.cond_br %204, ^bb22, ^bb23
    ^bb22:
      %206 = llvm.load %202 : !llvm.ptr -> i64
      %207 = llvm.getelementptr %85[%206] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %205 = llvm.load %207 : !llvm.ptr -> i8
      %208 = arith.constant 1 : i32
      %210 = arith.extsi %205 : i8 to i32
      %209 = arith.cmpi eq, %210, %208 : i32
      %211 = scf.if %209 -> (i1) {
        %213 = llvm.load %202 : !llvm.ptr -> i64
        %214 = llvm.getelementptr %188[%213] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        %212 = llvm.load %214 : !llvm.ptr -> i8
        %215 = arith.constant 0 : i32
        %217 = arith.extsi %212 : i8 to i32
        %216 = arith.cmpi eq, %217, %215 : i32
        scf.yield %216 : i1
      } else {
        %218 = arith.constant false
        scf.yield %218 : i1
      }
      cf.cond_br %211, ^bb24, ^bb25
      ^bb24:
        %219 = arith.constant 0 : i32
        %220 = arith.extsi %219 : i32 to i64
        %221 = llvm.mlir.constant(1 : i64) : i64
        %222 = llvm.alloca %221 x i64 : (i64) -> !llvm.ptr
        llvm.store %220, %222 : i64, !llvm.ptr
        %223 = llvm.load %202 : !llvm.ptr -> i64
        %224 = llvm.mlir.constant(1 : i64) : i64
        %225 = llvm.alloca %224 x i64 : (i64) -> !llvm.ptr
        llvm.store %223, %225 : i64, !llvm.ptr
        cf.br ^bb27
        ^bb27:
        %227 = llvm.load %225 : !llvm.ptr -> i64
        %228 = llvm.getelementptr %188[%227] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        %226 = llvm.load %228 : !llvm.ptr -> i8
        %229 = arith.constant 0 : i32
        %231 = arith.extsi %226 : i8 to i32
        %230 = arith.cmpi eq, %231, %229 : i32
        cf.cond_br %230, ^bb28, ^bb29
        ^bb28:
          %232 = arith.constant 1 : i32
          %233 = llvm.load %225 : !llvm.ptr -> i64
          %234 = arith.trunci %232 : i32 to i8
          %235 = llvm.getelementptr %188[%233] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %234, %235 : i8, !llvm.ptr
          %236 = llvm.load %225 : !llvm.ptr -> i64
          %237 = arith.trunci %236 : i64 to i32
          %238 = llvm.load %222 : !llvm.ptr -> i64
          %239 = llvm.getelementptr %195[%238] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          llvm.store %237, %239 : i32, !llvm.ptr
          %240 = llvm.load %222 : !llvm.ptr -> i64
          %241 = arith.constant 1 : i32
          %243 = arith.extsi %241 : i32 to i64
          %242 = arith.addi %240, %243 : i64
          llvm.store %242, %222 : i64, !llvm.ptr
          %245 = llvm.load %225 : !llvm.ptr -> i64
          %246 = llvm.getelementptr %4[%245] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          %244 = llvm.load %246 : !llvm.ptr -> i32
          %247 = arith.extsi %244 : i32 to i64
          llvm.store %247, %225 : i64, !llvm.ptr
          cf.br ^bb27
        ^bb29:
        %250 = arith.constant 0 : i32
        %251 = arith.extsi %250 : i32 to i64
        %252 = llvm.getelementptr %195[%251] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %249 = llvm.load %252 : !llvm.ptr -> i32
        %253 = arith.extsi %249 : i32 to i64
        %254 = llvm.getelementptr %59[%253] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %248 = llvm.load %254 : !llvm.ptr -> i64
        %255 = llvm.mlir.addressof @MOD : !llvm.ptr
        %256 = llvm.load %255 : !llvm.ptr -> i64
        %257 = arith.remsi %248, %256 : i64
        %258 = llvm.mlir.constant(1 : i64) : i64
        %259 = llvm.alloca %258 x i64 : (i64) -> !llvm.ptr
        llvm.store %257, %259 : i64, !llvm.ptr
        %260 = arith.constant 0 : i32
        %261 = arith.extsi %260 : i32 to i64
        %262 = llvm.mlir.constant(1 : i64) : i64
        %263 = llvm.alloca %262 x i64 : (i64) -> !llvm.ptr
        llvm.store %261, %263 : i64, !llvm.ptr
        %264 = arith.constant 1 : i32
        %265 = arith.extsi %264 : i32 to i64
        %266 = llvm.mlir.constant(1 : i64) : i64
        %267 = llvm.alloca %266 x i64 : (i64) -> !llvm.ptr
        llvm.store %265, %267 : i64, !llvm.ptr
        cf.br ^bb30
        ^bb30:
        %268 = llvm.load %267 : !llvm.ptr -> i64
        %269 = llvm.load %222 : !llvm.ptr -> i64
        %270 = arith.cmpi slt, %268, %269 : i64
        cf.cond_br %270, ^bb31, ^bb32
        ^bb31:
          %271 = llvm.load %259 : !llvm.ptr -> i64
          %272 = llvm.load %263 : !llvm.ptr -> i64
          %273 = arith.addi %271, %272 : i64
          %274 = llvm.mlir.addressof @MOD : !llvm.ptr
          %275 = llvm.load %274 : !llvm.ptr -> i64
          %276 = arith.remsi %273, %275 : i64
          %279 = llvm.load %267 : !llvm.ptr -> i64
          %280 = llvm.getelementptr %195[%279] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          %278 = llvm.load %280 : !llvm.ptr -> i32
          %281 = arith.extsi %278 : i32 to i64
          %282 = llvm.getelementptr %59[%281] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %277 = llvm.load %282 : !llvm.ptr -> i64
          %283 = llvm.mlir.addressof @MOD : !llvm.ptr
          %284 = llvm.load %283 : !llvm.ptr -> i64
          %285 = arith.remsi %277, %284 : i64
          %286 = arith.muli %276, %285 : i64
          %287 = llvm.mlir.addressof @MOD : !llvm.ptr
          %288 = llvm.load %287 : !llvm.ptr -> i64
          %289 = arith.remsi %286, %288 : i64
          %290 = llvm.load %259 : !llvm.ptr -> i64
          %293 = llvm.load %267 : !llvm.ptr -> i64
          %294 = llvm.getelementptr %195[%293] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          %292 = llvm.load %294 : !llvm.ptr -> i32
          %295 = arith.extsi %292 : i32 to i64
          %296 = llvm.getelementptr %63[%295] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %291 = llvm.load %296 : !llvm.ptr -> i64
          %297 = llvm.mlir.addressof @MOD : !llvm.ptr
          %298 = llvm.load %297 : !llvm.ptr -> i64
          %299 = arith.remsi %291, %298 : i64
          %300 = arith.muli %290, %299 : i64
          %301 = llvm.mlir.addressof @MOD : !llvm.ptr
          %302 = llvm.load %301 : !llvm.ptr -> i64
          %303 = arith.remsi %300, %302 : i64
          llvm.store %289, %259 : i64, !llvm.ptr
          llvm.store %303, %263 : i64, !llvm.ptr
          %304 = llvm.load %267 : !llvm.ptr -> i64
          %305 = arith.constant 1 : i32
          %307 = arith.extsi %305 : i32 to i64
          %306 = arith.addi %304, %307 : i64
          llvm.store %306, %267 : i64, !llvm.ptr
          cf.br ^bb30
        ^bb32:
        %308 = llvm.load %259 : !llvm.ptr -> i64
        %309 = llvm.load %263 : !llvm.ptr -> i64
        %310 = arith.addi %308, %309 : i64
        %311 = llvm.mlir.addressof @MOD : !llvm.ptr
        %312 = llvm.load %311 : !llvm.ptr -> i64
        %313 = arith.remsi %310, %312 : i64
        %314 = arith.constant 0 : i32
        %315 = arith.extsi %314 : i32 to i64
        llvm.store %315, %259 : i64, !llvm.ptr
        %318 = arith.constant 0 : i32
        %319 = arith.extsi %318 : i32 to i64
        %320 = llvm.getelementptr %195[%319] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %317 = llvm.load %320 : !llvm.ptr -> i32
        %321 = arith.extsi %317 : i32 to i64
        %322 = llvm.getelementptr %63[%321] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %316 = llvm.load %322 : !llvm.ptr -> i64
        %323 = llvm.mlir.addressof @MOD : !llvm.ptr
        %324 = llvm.load %323 : !llvm.ptr -> i64
        %325 = arith.remsi %316, %324 : i64
        llvm.store %325, %263 : i64, !llvm.ptr
        %326 = arith.constant 1 : i32
        %327 = arith.extsi %326 : i32 to i64
        llvm.store %327, %267 : i64, !llvm.ptr
        cf.br ^bb33
        ^bb33:
        %328 = llvm.load %267 : !llvm.ptr -> i64
        %329 = llvm.load %222 : !llvm.ptr -> i64
        %330 = arith.cmpi slt, %328, %329 : i64
        cf.cond_br %330, ^bb34, ^bb35
        ^bb34:
          %331 = llvm.load %259 : !llvm.ptr -> i64
          %332 = llvm.load %263 : !llvm.ptr -> i64
          %333 = arith.addi %331, %332 : i64
          %334 = llvm.mlir.addressof @MOD : !llvm.ptr
          %335 = llvm.load %334 : !llvm.ptr -> i64
          %336 = arith.remsi %333, %335 : i64
          %339 = llvm.load %267 : !llvm.ptr -> i64
          %340 = llvm.getelementptr %195[%339] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          %338 = llvm.load %340 : !llvm.ptr -> i32
          %341 = arith.extsi %338 : i32 to i64
          %342 = llvm.getelementptr %59[%341] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %337 = llvm.load %342 : !llvm.ptr -> i64
          %343 = llvm.mlir.addressof @MOD : !llvm.ptr
          %344 = llvm.load %343 : !llvm.ptr -> i64
          %345 = arith.remsi %337, %344 : i64
          %346 = arith.muli %336, %345 : i64
          %347 = llvm.mlir.addressof @MOD : !llvm.ptr
          %348 = llvm.load %347 : !llvm.ptr -> i64
          %349 = arith.remsi %346, %348 : i64
          %350 = llvm.load %259 : !llvm.ptr -> i64
          %353 = llvm.load %267 : !llvm.ptr -> i64
          %354 = llvm.getelementptr %195[%353] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          %352 = llvm.load %354 : !llvm.ptr -> i32
          %355 = arith.extsi %352 : i32 to i64
          %356 = llvm.getelementptr %63[%355] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %351 = llvm.load %356 : !llvm.ptr -> i64
          %357 = llvm.mlir.addressof @MOD : !llvm.ptr
          %358 = llvm.load %357 : !llvm.ptr -> i64
          %359 = arith.remsi %351, %358 : i64
          %360 = arith.muli %350, %359 : i64
          %361 = llvm.mlir.addressof @MOD : !llvm.ptr
          %362 = llvm.load %361 : !llvm.ptr -> i64
          %363 = arith.remsi %360, %362 : i64
          llvm.store %349, %259 : i64, !llvm.ptr
          llvm.store %363, %263 : i64, !llvm.ptr
          %364 = llvm.load %267 : !llvm.ptr -> i64
          %365 = arith.constant 1 : i32
          %367 = arith.extsi %365 : i32 to i64
          %366 = arith.addi %364, %367 : i64
          llvm.store %366, %267 : i64, !llvm.ptr
          cf.br ^bb33
        ^bb35:
        %368 = llvm.load %259 : !llvm.ptr -> i64
        %369 = llvm.load %194 : !llvm.ptr -> i64
        %370 = arith.addi %313, %368 : i64
        %371 = llvm.mlir.addressof @MOD : !llvm.ptr
        %372 = llvm.load %371 : !llvm.ptr -> i64
        %373 = arith.remsi %370, %372 : i64
        %374 = arith.muli %369, %373 : i64
        %375 = llvm.mlir.addressof @MOD : !llvm.ptr
        %376 = llvm.load %375 : !llvm.ptr -> i64
        %377 = arith.remsi %374, %376 : i64
        llvm.store %377, %194 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %378 = llvm.load %202 : !llvm.ptr -> i64
      %379 = arith.constant 1 : i32
      %381 = arith.extsi %379 : i32 to i64
      %380 = arith.addi %378, %381 : i64
      llvm.store %380, %202 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %382 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %383 = llvm.load %194 : !llvm.ptr -> i64
    %384 = llvm.call @printf(%382, %383) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%4) : (!llvm.ptr) -> ()
    func.call @free(%8) : (!llvm.ptr) -> ()
    func.call @free(%59) : (!llvm.ptr) -> ()
    func.call @free(%63) : (!llvm.ptr) -> ()
    func.call @free(%85) : (!llvm.ptr) -> ()
    func.call @free(%89) : (!llvm.ptr) -> ()
    func.call @free(%188) : (!llvm.ptr) -> ()
    func.call @free(%195) : (!llvm.ptr) -> ()
    %393 = arith.constant 0 : i32
    func.return %393 : i32
  }
}