Problem 588

Quintinomial Coefficients Q(k) = # odd coeffs in (1+x+x^2+x^3+x^4)^k; sum Q(10^m) for m=1..18.

Answer11651930052
Output11651930052
StatusPASS
Native helperno
Runtime0 ms
Peak memory1088 KB
Time complexityO(n^3) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^3)?
Space complexityO(1)?
ApproachFlow solutionNot curated
VerdictUnknown

Flow source

# Project Euler 588
# Quintinomial Coefficients
# Q(k) = # odd coeffs in (1+x+x^2+x^3+x^4)^k; sum Q(10^m) for m=1..18.

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

function build_trans(active: bool, trans: ptr<i64>) -> void {
    let mut bit: i64 = 0
    while bit < 2 {
        let mut state: i64 = 0
        while state < 16 {
            let mut next_state: i64 = 0
            let mut c: i64 = 0
            while c < 4 {
                if ((state >> c) & 1) != 0 {
                    let mut d: i64 = 0
                    let mut d_hi: i64 = 0
                    if active { d_hi = 4 }
                    while d <= d_hi {
                        let s: i64 = c + d
                        if (s & 1) == bit {
                            let nc: i64 = s >> 1
                            next_state = next_state ^ (1 << nc)
                        }
                        d = d + 1
                    }
                }
                c = c + 1
            }
            trans[bit * 16 + state] = next_state
            state = state + 1
        }
        bit = bit + 1
    }
}

function bit_length(k0: i64) -> i64 {
    let mut k: i64 = k0
    let mut n: i64 = 0
    while k > 0 {
        n = n + 1
        k = k >> 1
    }
    return n
}

function Q(k: i64, t_active: ptr<i64>, t_inactive: ptr<i64>) -> i64 {
    let L: i64 = bit_length(k) + 3
    let dp: ptr<i64> = calloc(16, 8)
    let ndp: ptr<i64> = calloc(16, 8)
    if dp == null || ndp == null { return -1 }
    dp[1] = 1
    let mut i: i64 = 0
    while i < L {
        let mut trans: ptr<i64> = t_inactive
        if ((k >> i) & 1) != 0 {
            trans = t_active
        }
        let mut s: i64 = 0
        while s < 16 {
            ndp[s] = 0
            s = s + 1
        }
        s = 0
        while s < 16 {
            let cnt: i64 = dp[s]
            if cnt != 0 {
                ndp[trans[s]] = ndp[trans[s]] + cnt
                ndp[trans[16 + s]] = ndp[trans[16 + s]] + cnt
            }
            s = s + 1
        }
        s = 0
        while s < 16 {
            dp[s] = ndp[s]
            s = s + 1
        }
        i = i + 1
    }
    let mut ans: i64 = 0
    let mut s2: i64 = 0
    while s2 < 16 {
        if (s2 & 1) != 0 {
            ans = ans + dp[s2]
        }
        s2 = s2 + 1
    }
    free(dp)
    free(ndp)
    return ans
}

function main() -> i32 {
    let t_active: ptr<i64> = calloc(32, 8)
    let t_inactive: ptr<i64> = calloc(32, 8)
    if t_active == null || t_inactive == null { return 1 }
    build_trans(true, t_active)
    build_trans(false, t_inactive)
    let mut total: i64 = 0
    let mut k: i64 = 10
    let mut m: i64 = 0
    while m < 18 {
        total = total + Q(k, t_active, t_inactive)
        k = k * 10
        m = m + 1
    }
    printf("%lld\n", total)
    free(t_active)
    free(t_inactive)
    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; }

void build_trans_bool_ptr_i64(bool active, int64_t* trans);
int64_t bit_length_i64(int64_t k0);
int64_t Q_i64_ptr_i64_ptr_i64(int64_t k, int64_t* t_active, int64_t* t_inactive);
int32_t main(void);



void build_trans_bool_ptr_i64(bool active, int64_t* trans) {
    int64_t bit = 0;
    while (bit < 2) {
        int64_t state = 0;
        while (state < 16) {
            int64_t next_state = 0;
            int64_t c = 0;
            while (c < 4) {
                if ((FLOW_CHECKED_SHR((state), (c)) & 1) != 0) {
                    int64_t d = 0;
                    int64_t d_hi = 0;
                    if (active) {
                        d_hi = 4;
                    }
                    while (d <= d_hi) {
                        int64_t s = (c + d);
                        if ((s & 1) == bit) {
                            int64_t nc = FLOW_CHECKED_SHR((s), (1));
                            next_state = (next_state ^ FLOW_CHECKED_SHL((1), (nc)));
                        }
                        d = (d + 1);
                    }
                }
                c = (c + 1);
            }
            trans[((bit * 16) + state)] = next_state;
            state = (state + 1);
        }
        bit = (bit + 1);
    }
}

int64_t bit_length_i64(int64_t k0) {
    int64_t k = k0;
    int64_t n = 0;
    while (k > 0) {
        n = (n + 1);
        k = FLOW_CHECKED_SHR((k), (1));
    }
    return n;
}

int64_t Q_i64_ptr_i64_ptr_i64(int64_t k, int64_t* t_active, int64_t* t_inactive) {
    int64_t L = (bit_length_i64(k) + 3);
    int64_t* dp = (int64_t*)(calloc(16, 8));
    int64_t* ndp = (int64_t*)(calloc(16, 8));
    if ((dp == NULL || ndp == NULL)) {
        return (-1);
    }
    dp[1] = 1;
    int64_t i = 0;
    while (i < L) {
        int64_t* trans = (int64_t*)(t_inactive);
        if ((FLOW_CHECKED_SHR((k), (i)) & 1) != 0) {
            trans = t_active;
        }
        int64_t s = 0;
        while (s < 16) {
            ndp[s] = 0;
            s = (s + 1);
        }
        s = 0;
        while (s < 16) {
            int64_t cnt = dp[s];
            if (cnt != 0) {
                ndp[trans[s]] = (ndp[trans[s]] + cnt);
                ndp[trans[(16 + s)]] = (ndp[trans[(16 + s)]] + cnt);
            }
            s = (s + 1);
        }
        s = 0;
        while (s < 16) {
            dp[s] = ndp[s];
            s = (s + 1);
        }
        i = (i + 1);
    }
    int64_t ans = 0;
    int64_t s2 = 0;
    while (s2 < 16) {
        if ((s2 & 1) != 0) {
            ans = (ans + dp[s2]);
        }
        s2 = (s2 + 1);
    }
    free(dp);
    free(ndp);
    return ans;
}

int32_t main(void) {
    int64_t* t_active = (int64_t*)(calloc(32, 8));
    int64_t* t_inactive = (int64_t*)(calloc(32, 8));
    if ((t_active == NULL || t_inactive == NULL)) {
        return 1;
    }
    build_trans_bool_ptr_i64(1, t_active);
    build_trans_bool_ptr_i64(0, t_inactive);
    int64_t total = 0;
    int64_t k = 10;
    int64_t m = 0;
    while (m < 18) {
        total = (total + Q_i64_ptr_i64_ptr_i64(k, t_active, t_inactive));
        k = (k * 10);
        m = (m + 1);
    }
    printf("%lld\n", total);
    free(t_active);
    free(t_inactive);
    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 @build_trans(%arg0: i1, %arg1: !llvm.ptr) -> () {
    %0 = arith.constant 0 : i32
    %1 = arith.extsi %0 : i32 to i64
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
    llvm.store %1, %3 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %4 = llvm.load %3 : !llvm.ptr -> i64
    %5 = arith.constant 2 : i32
    %7 = arith.extsi %5 : i32 to i64
    %6 = arith.cmpi slt, %4, %7 : i64
    cf.cond_br %6, ^bb1, ^bb2
    ^bb1:
      %8 = arith.constant 0 : i32
      %9 = arith.extsi %8 : i32 to i64
      %10 = llvm.mlir.constant(1 : i64) : i64
      %11 = llvm.alloca %10 x i64 : (i64) -> !llvm.ptr
      llvm.store %9, %11 : i64, !llvm.ptr
      cf.br ^bb3
      ^bb3:
      %12 = llvm.load %11 : !llvm.ptr -> i64
      %13 = arith.constant 16 : i32
      %15 = arith.extsi %13 : i32 to i64
      %14 = arith.cmpi slt, %12, %15 : i64
      cf.cond_br %14, ^bb4, ^bb5
      ^bb4:
        %16 = arith.constant 0 : i32
        %17 = arith.extsi %16 : i32 to i64
        %18 = llvm.mlir.constant(1 : i64) : i64
        %19 = llvm.alloca %18 x i64 : (i64) -> !llvm.ptr
        llvm.store %17, %19 : i64, !llvm.ptr
        %20 = arith.constant 0 : i32
        %21 = arith.extsi %20 : i32 to i64
        %22 = llvm.mlir.constant(1 : i64) : i64
        %23 = llvm.alloca %22 x i64 : (i64) -> !llvm.ptr
        llvm.store %21, %23 : i64, !llvm.ptr
        cf.br ^bb6
        ^bb6:
        %24 = llvm.load %23 : !llvm.ptr -> i64
        %25 = arith.constant 4 : i32
        %27 = arith.extsi %25 : i32 to i64
        %26 = arith.cmpi slt, %24, %27 : i64
        cf.cond_br %26, ^bb7, ^bb8
        ^bb7:
          %28 = llvm.load %11 : !llvm.ptr -> i64
          %29 = llvm.load %23 : !llvm.ptr -> i64
          %30 = arith.shrsi %28, %29 : i64
          %31 = arith.constant 1 : i32
          %33 = arith.extsi %31 : i32 to i64
          %32 = arith.andi %30, %33 : i64
          %34 = arith.constant 0 : i32
          %36 = arith.extsi %34 : i32 to i64
          %35 = arith.cmpi ne, %32, %36 : i64
          cf.cond_br %35, ^bb9, ^bb10
          ^bb9:
            %37 = arith.constant 0 : i32
            %38 = arith.extsi %37 : i32 to i64
            %39 = llvm.mlir.constant(1 : i64) : i64
            %40 = llvm.alloca %39 x i64 : (i64) -> !llvm.ptr
            llvm.store %38, %40 : i64, !llvm.ptr
            %41 = arith.constant 0 : i32
            %42 = arith.extsi %41 : i32 to i64
            %43 = llvm.mlir.constant(1 : i64) : i64
            %44 = llvm.alloca %43 x i64 : (i64) -> !llvm.ptr
            llvm.store %42, %44 : i64, !llvm.ptr
            cf.cond_br %arg0, ^bb12, ^bb13
            ^bb12:
              %45 = arith.constant 4 : i32
              %46 = arith.extsi %45 : i32 to i64
              llvm.store %46, %44 : i64, !llvm.ptr
              cf.br ^bb14
            ^bb13:
              cf.br ^bb14
            ^bb14:
            cf.br ^bb15
            ^bb15:
            %47 = llvm.load %40 : !llvm.ptr -> i64
            %48 = llvm.load %44 : !llvm.ptr -> i64
            %49 = arith.cmpi sle, %47, %48 : i64
            cf.cond_br %49, ^bb16, ^bb17
            ^bb16:
              %50 = llvm.load %23 : !llvm.ptr -> i64
              %51 = llvm.load %40 : !llvm.ptr -> i64
              %52 = arith.addi %50, %51 : i64
              %53 = arith.constant 1 : i32
              %55 = arith.extsi %53 : i32 to i64
              %54 = arith.andi %52, %55 : i64
              %56 = llvm.load %3 : !llvm.ptr -> i64
              %57 = arith.cmpi eq, %54, %56 : i64
              cf.cond_br %57, ^bb18, ^bb19
              ^bb18:
                %58 = arith.constant 1 : i32
                %60 = arith.extsi %58 : i32 to i64
                %59 = arith.shrsi %52, %60 : i64
                %61 = llvm.load %19 : !llvm.ptr -> i64
                %62 = arith.constant 1 : i32
                %64 = arith.extsi %62 : i32 to i64
                %63 = arith.shli %64, %59 : i64
                %65 = arith.xori %61, %63 : i64
                llvm.store %65, %19 : i64, !llvm.ptr
                cf.br ^bb20
              ^bb19:
                cf.br ^bb20
              ^bb20:
              %66 = llvm.load %40 : !llvm.ptr -> i64
              %67 = arith.constant 1 : i32
              %69 = arith.extsi %67 : i32 to i64
              %68 = arith.addi %66, %69 : i64
              llvm.store %68, %40 : i64, !llvm.ptr
              cf.br ^bb15
            ^bb17:
            cf.br ^bb11
          ^bb10:
            cf.br ^bb11
          ^bb11:
          %70 = llvm.load %23 : !llvm.ptr -> i64
          %71 = arith.constant 1 : i32
          %73 = arith.extsi %71 : i32 to i64
          %72 = arith.addi %70, %73 : i64
          llvm.store %72, %23 : i64, !llvm.ptr
          cf.br ^bb6
        ^bb8:
        %74 = llvm.load %19 : !llvm.ptr -> i64
        %75 = llvm.load %3 : !llvm.ptr -> i64
        %76 = arith.constant 16 : i32
        %78 = arith.extsi %76 : i32 to i64
        %77 = arith.muli %75, %78 : i64
        %79 = llvm.load %11 : !llvm.ptr -> i64
        %80 = arith.addi %77, %79 : i64
        %81 = llvm.getelementptr %arg1[%80] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %74, %81 : i64, !llvm.ptr
        %82 = llvm.load %11 : !llvm.ptr -> i64
        %83 = arith.constant 1 : i32
        %85 = arith.extsi %83 : i32 to i64
        %84 = arith.addi %82, %85 : i64
        llvm.store %84, %11 : i64, !llvm.ptr
        cf.br ^bb3
      ^bb5:
      %86 = llvm.load %3 : !llvm.ptr -> i64
      %87 = arith.constant 1 : i32
      %89 = arith.extsi %87 : i32 to i64
      %88 = arith.addi %86, %89 : i64
      llvm.store %88, %3 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    func.return
  }
  func.func @bit_length(%arg0: i64) -> i64 {
    %90 = llvm.mlir.constant(1 : i64) : i64
    %91 = llvm.alloca %90 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %91 : i64, !llvm.ptr
    %92 = arith.constant 0 : 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
    cf.br ^bb21
    ^bb21:
    %96 = llvm.load %91 : !llvm.ptr -> i64
    %97 = arith.constant 0 : i32
    %99 = arith.extsi %97 : i32 to i64
    %98 = arith.cmpi sgt, %96, %99 : i64
    cf.cond_br %98, ^bb22, ^bb23
    ^bb22:
      %100 = llvm.load %95 : !llvm.ptr -> i64
      %101 = arith.constant 1 : i32
      %103 = arith.extsi %101 : i32 to i64
      %102 = arith.addi %100, %103 : i64
      llvm.store %102, %95 : i64, !llvm.ptr
      %104 = llvm.load %91 : !llvm.ptr -> i64
      %105 = arith.constant 1 : i32
      %107 = arith.extsi %105 : i32 to i64
      %106 = arith.shrsi %104, %107 : i64
      llvm.store %106, %91 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %108 = llvm.load %95 : !llvm.ptr -> i64
    func.return %108 : i64
  }
  func.func @Q(%arg0: i64, %arg1: !llvm.ptr, %arg2: !llvm.ptr) -> i64 {
    %109 = func.call @bit_length(%arg0) : (i64) -> i64
    %110 = arith.constant 3 : i32
    %112 = arith.extsi %110 : i32 to i64
    %111 = arith.addi %109, %112 : i64
    %114 = arith.constant 16 : i32
    %115 = arith.constant 8 : i32
    %116 = arith.extsi %114 : i32 to i64
    %117 = arith.extsi %115 : i32 to i64
    %113 = func.call @calloc(%116, %117) : (i64, i64) -> !llvm.ptr
    %119 = arith.constant 16 : i32
    %120 = arith.constant 8 : i32
    %121 = arith.extsi %119 : i32 to i64
    %122 = arith.extsi %120 : i32 to i64
    %118 = func.call @calloc(%121, %122) : (i64, i64) -> !llvm.ptr
    %123 = llvm.mlir.zero : !llvm.ptr
    %124 = llvm.icmp "eq" %113, %123 : !llvm.ptr
    %125 = scf.if %124 -> (i1) {
      %126 = arith.constant true
      scf.yield %126 : i1
    } else {
      %127 = llvm.mlir.zero : !llvm.ptr
      %128 = llvm.icmp "eq" %118, %127 : !llvm.ptr
      scf.yield %128 : i1
    }
    cf.cond_br %125, ^bb24, ^bb25
    ^bb24:
      %129 = arith.constant 1 : i32
      %131 = arith.constant 0 : i32
      %130 = arith.subi %131, %129 : i32
      %132 = arith.extsi %130 : i32 to i64
      func.return %132 : i64
    ^bb25:
      cf.br ^bb26
    ^bb26:
    %133 = arith.constant 1 : i32
    %134 = arith.constant 1 : i32
    %135 = arith.extsi %133 : i32 to i64
    %136 = arith.extsi %134 : i32 to i64
    %137 = llvm.getelementptr %113[%136] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %135, %137 : i64, !llvm.ptr
    %138 = arith.constant 0 : i32
    %139 = arith.extsi %138 : i32 to i64
    %140 = llvm.mlir.constant(1 : i64) : i64
    %141 = llvm.alloca %140 x i64 : (i64) -> !llvm.ptr
    llvm.store %139, %141 : i64, !llvm.ptr
    cf.br ^bb27
    ^bb27:
    %142 = llvm.load %141 : !llvm.ptr -> i64
    %143 = arith.cmpi slt, %142, %111 : i64
    cf.cond_br %143, ^bb28, ^bb29
    ^bb28:
      %144 = llvm.mlir.constant(1 : i64) : i64
      %145 = llvm.alloca %144 x !llvm.ptr : (i64) -> !llvm.ptr
      llvm.store %arg2, %145 : !llvm.ptr, !llvm.ptr
      %146 = llvm.load %141 : !llvm.ptr -> i64
      %147 = arith.shrsi %arg0, %146 : i64
      %148 = arith.constant 1 : i32
      %150 = arith.extsi %148 : i32 to i64
      %149 = arith.andi %147, %150 : i64
      %151 = arith.constant 0 : i32
      %153 = arith.extsi %151 : i32 to i64
      %152 = arith.cmpi ne, %149, %153 : i64
      cf.cond_br %152, ^bb30, ^bb31
      ^bb30:
        llvm.store %arg1, %145 : !llvm.ptr, !llvm.ptr
        cf.br ^bb32
      ^bb31:
        cf.br ^bb32
      ^bb32:
      %154 = arith.constant 0 : i32
      %155 = arith.extsi %154 : i32 to i64
      %156 = llvm.mlir.constant(1 : i64) : i64
      %157 = llvm.alloca %156 x i64 : (i64) -> !llvm.ptr
      llvm.store %155, %157 : i64, !llvm.ptr
      cf.br ^bb33
      ^bb33:
      %158 = llvm.load %157 : !llvm.ptr -> i64
      %159 = arith.constant 16 : i32
      %161 = arith.extsi %159 : i32 to i64
      %160 = arith.cmpi slt, %158, %161 : i64
      cf.cond_br %160, ^bb34, ^bb35
      ^bb34:
        %162 = arith.constant 0 : i32
        %163 = llvm.load %157 : !llvm.ptr -> i64
        %164 = arith.extsi %162 : i32 to i64
        %165 = llvm.getelementptr %118[%163] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %164, %165 : i64, !llvm.ptr
        %166 = llvm.load %157 : !llvm.ptr -> i64
        %167 = arith.constant 1 : i32
        %169 = arith.extsi %167 : i32 to i64
        %168 = arith.addi %166, %169 : i64
        llvm.store %168, %157 : i64, !llvm.ptr
        cf.br ^bb33
      ^bb35:
      %170 = arith.constant 0 : i32
      %171 = arith.extsi %170 : i32 to i64
      llvm.store %171, %157 : i64, !llvm.ptr
      cf.br ^bb36
      ^bb36:
      %172 = llvm.load %157 : !llvm.ptr -> i64
      %173 = arith.constant 16 : i32
      %175 = arith.extsi %173 : i32 to i64
      %174 = arith.cmpi slt, %172, %175 : i64
      cf.cond_br %174, ^bb37, ^bb38
      ^bb37:
        %177 = llvm.load %157 : !llvm.ptr -> i64
        %178 = llvm.getelementptr %113[%177] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %176 = llvm.load %178 : !llvm.ptr -> i64
        %179 = arith.constant 0 : i32
        %181 = arith.extsi %179 : i32 to i64
        %180 = arith.cmpi ne, %176, %181 : i64
        cf.cond_br %180, ^bb39, ^bb40
        ^bb39:
          %184 = llvm.load %145 : !llvm.ptr -> !llvm.ptr
          %185 = llvm.load %157 : !llvm.ptr -> i64
          %186 = llvm.getelementptr %184[%185] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %183 = llvm.load %186 : !llvm.ptr -> i64
          %187 = llvm.getelementptr %118[%183] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %182 = llvm.load %187 : !llvm.ptr -> i64
          %188 = arith.addi %182, %176 : i64
          %190 = llvm.load %145 : !llvm.ptr -> !llvm.ptr
          %191 = llvm.load %157 : !llvm.ptr -> i64
          %192 = llvm.getelementptr %190[%191] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %189 = llvm.load %192 : !llvm.ptr -> i64
          %193 = llvm.getelementptr %118[%189] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %188, %193 : i64, !llvm.ptr
          %196 = llvm.load %145 : !llvm.ptr -> !llvm.ptr
          %197 = arith.constant 16 : i32
          %198 = llvm.load %157 : !llvm.ptr -> i64
          %200 = arith.extsi %197 : i32 to i64
          %199 = arith.addi %200, %198 : i64
          %201 = llvm.getelementptr %196[%199] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %195 = llvm.load %201 : !llvm.ptr -> i64
          %202 = llvm.getelementptr %118[%195] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %194 = llvm.load %202 : !llvm.ptr -> i64
          %203 = arith.addi %194, %176 : i64
          %205 = llvm.load %145 : !llvm.ptr -> !llvm.ptr
          %206 = arith.constant 16 : i32
          %207 = llvm.load %157 : !llvm.ptr -> i64
          %209 = arith.extsi %206 : i32 to i64
          %208 = arith.addi %209, %207 : i64
          %210 = llvm.getelementptr %205[%208] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %204 = llvm.load %210 : !llvm.ptr -> i64
          %211 = llvm.getelementptr %118[%204] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %203, %211 : i64, !llvm.ptr
          cf.br ^bb41
        ^bb40:
          cf.br ^bb41
        ^bb41:
        %212 = llvm.load %157 : !llvm.ptr -> i64
        %213 = arith.constant 1 : i32
        %215 = arith.extsi %213 : i32 to i64
        %214 = arith.addi %212, %215 : i64
        llvm.store %214, %157 : i64, !llvm.ptr
        cf.br ^bb36
      ^bb38:
      %216 = arith.constant 0 : i32
      %217 = arith.extsi %216 : i32 to i64
      llvm.store %217, %157 : i64, !llvm.ptr
      cf.br ^bb42
      ^bb42:
      %218 = llvm.load %157 : !llvm.ptr -> i64
      %219 = arith.constant 16 : i32
      %221 = arith.extsi %219 : i32 to i64
      %220 = arith.cmpi slt, %218, %221 : i64
      cf.cond_br %220, ^bb43, ^bb44
      ^bb43:
        %223 = llvm.load %157 : !llvm.ptr -> i64
        %224 = llvm.getelementptr %118[%223] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %222 = llvm.load %224 : !llvm.ptr -> i64
        %225 = llvm.load %157 : !llvm.ptr -> i64
        %226 = llvm.getelementptr %113[%225] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %222, %226 : i64, !llvm.ptr
        %227 = llvm.load %157 : !llvm.ptr -> i64
        %228 = arith.constant 1 : i32
        %230 = arith.extsi %228 : i32 to i64
        %229 = arith.addi %227, %230 : i64
        llvm.store %229, %157 : i64, !llvm.ptr
        cf.br ^bb42
      ^bb44:
      %231 = llvm.load %141 : !llvm.ptr -> i64
      %232 = arith.constant 1 : i32
      %234 = arith.extsi %232 : i32 to i64
      %233 = arith.addi %231, %234 : i64
      llvm.store %233, %141 : i64, !llvm.ptr
      cf.br ^bb27
    ^bb29:
    %235 = arith.constant 0 : i32
    %236 = arith.extsi %235 : i32 to i64
    %237 = llvm.mlir.constant(1 : i64) : i64
    %238 = llvm.alloca %237 x i64 : (i64) -> !llvm.ptr
    llvm.store %236, %238 : i64, !llvm.ptr
    %239 = arith.constant 0 : i32
    %240 = arith.extsi %239 : i32 to i64
    %241 = llvm.mlir.constant(1 : i64) : i64
    %242 = llvm.alloca %241 x i64 : (i64) -> !llvm.ptr
    llvm.store %240, %242 : i64, !llvm.ptr
    cf.br ^bb45
    ^bb45:
    %243 = llvm.load %242 : !llvm.ptr -> i64
    %244 = arith.constant 16 : i32
    %246 = arith.extsi %244 : i32 to i64
    %245 = arith.cmpi slt, %243, %246 : i64
    cf.cond_br %245, ^bb46, ^bb47
    ^bb46:
      %247 = llvm.load %242 : !llvm.ptr -> i64
      %248 = arith.constant 1 : i32
      %250 = arith.extsi %248 : i32 to i64
      %249 = arith.andi %247, %250 : i64
      %251 = arith.constant 0 : i32
      %253 = arith.extsi %251 : i32 to i64
      %252 = arith.cmpi ne, %249, %253 : i64
      cf.cond_br %252, ^bb48, ^bb49
      ^bb48:
        %254 = llvm.load %238 : !llvm.ptr -> i64
        %256 = llvm.load %242 : !llvm.ptr -> i64
        %257 = llvm.getelementptr %113[%256] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %255 = llvm.load %257 : !llvm.ptr -> i64
        %258 = arith.addi %254, %255 : i64
        llvm.store %258, %238 : i64, !llvm.ptr
        cf.br ^bb50
      ^bb49:
        cf.br ^bb50
      ^bb50:
      %259 = llvm.load %242 : !llvm.ptr -> i64
      %260 = arith.constant 1 : i32
      %262 = arith.extsi %260 : i32 to i64
      %261 = arith.addi %259, %262 : i64
      llvm.store %261, %242 : i64, !llvm.ptr
      cf.br ^bb45
    ^bb47:
    func.call @free(%113) : (!llvm.ptr) -> ()
    func.call @free(%118) : (!llvm.ptr) -> ()
    %265 = llvm.load %238 : !llvm.ptr -> i64
    func.return %265 : i64
  }
  func.func @main() -> i32 {
    %267 = arith.constant 32 : i32
    %268 = arith.constant 8 : i32
    %269 = arith.extsi %267 : i32 to i64
    %270 = arith.extsi %268 : i32 to i64
    %266 = func.call @calloc(%269, %270) : (i64, i64) -> !llvm.ptr
    %272 = arith.constant 32 : i32
    %273 = arith.constant 8 : i32
    %274 = arith.extsi %272 : i32 to i64
    %275 = arith.extsi %273 : i32 to i64
    %271 = func.call @calloc(%274, %275) : (i64, i64) -> !llvm.ptr
    %276 = llvm.mlir.zero : !llvm.ptr
    %277 = llvm.icmp "eq" %266, %276 : !llvm.ptr
    %278 = scf.if %277 -> (i1) {
      %279 = arith.constant true
      scf.yield %279 : i1
    } else {
      %280 = llvm.mlir.zero : !llvm.ptr
      %281 = llvm.icmp "eq" %271, %280 : !llvm.ptr
      scf.yield %281 : i1
    }
    cf.cond_br %278, ^bb51, ^bb52
    ^bb51:
      %282 = arith.constant 1 : i32
      func.return %282 : i32
    ^bb52:
      cf.br ^bb53
    ^bb53:
    %284 = arith.constant 1 : i1
    func.call @build_trans(%284, %266) : (i1, !llvm.ptr) -> ()
    %286 = arith.constant 0 : i1
    func.call @build_trans(%286, %271) : (i1, !llvm.ptr) -> ()
    %287 = arith.constant 0 : i32
    %288 = arith.extsi %287 : i32 to i64
    %289 = llvm.mlir.constant(1 : i64) : i64
    %290 = llvm.alloca %289 x i64 : (i64) -> !llvm.ptr
    llvm.store %288, %290 : i64, !llvm.ptr
    %291 = arith.constant 10 : i32
    %292 = arith.extsi %291 : i32 to i64
    %293 = llvm.mlir.constant(1 : i64) : i64
    %294 = llvm.alloca %293 x i64 : (i64) -> !llvm.ptr
    llvm.store %292, %294 : i64, !llvm.ptr
    %295 = arith.constant 0 : i32
    %296 = arith.extsi %295 : i32 to i64
    %297 = llvm.mlir.constant(1 : i64) : i64
    %298 = llvm.alloca %297 x i64 : (i64) -> !llvm.ptr
    llvm.store %296, %298 : i64, !llvm.ptr
    cf.br ^bb54
    ^bb54:
    %299 = llvm.load %298 : !llvm.ptr -> i64
    %300 = arith.constant 18 : i32
    %302 = arith.extsi %300 : i32 to i64
    %301 = arith.cmpi slt, %299, %302 : i64
    cf.cond_br %301, ^bb55, ^bb56
    ^bb55:
      %303 = llvm.load %290 : !llvm.ptr -> i64
      %305 = llvm.load %294 : !llvm.ptr -> i64
      %304 = func.call @Q(%305, %266, %271) : (i64, !llvm.ptr, !llvm.ptr) -> i64
      %306 = arith.addi %303, %304 : i64
      llvm.store %306, %290 : i64, !llvm.ptr
      %307 = llvm.load %294 : !llvm.ptr -> i64
      %308 = arith.constant 10 : i32
      %310 = arith.extsi %308 : i32 to i64
      %309 = arith.muli %307, %310 : i64
      llvm.store %309, %294 : i64, !llvm.ptr
      %311 = llvm.load %298 : !llvm.ptr -> i64
      %312 = arith.constant 1 : i32
      %314 = arith.extsi %312 : i32 to i64
      %313 = arith.addi %311, %314 : i64
      llvm.store %313, %298 : i64, !llvm.ptr
      cf.br ^bb54
    ^bb56:
    %315 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %316 = llvm.load %290 : !llvm.ptr -> i64
    %317 = llvm.call @printf(%315, %316) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%266) : (!llvm.ptr) -> ()
    func.call @free(%271) : (!llvm.ptr) -> ()
    %320 = arith.constant 0 : i32
    func.return %320 : i32
  }
}