Problem 736

Paths to equality: r(x,y) = (x+1, 2y), s(x,y) = (2x, y+1). Starting from (45,90), find the final value of the unique path to equality of smallest odd length (coordinates unequal at every point before the last). Method: a word with R r-ops and S s-ops, written as m_0 r's, s, m_1 r's, s, ..., s, m_S r's, gives x_final = 45*2^S + sum_j m_j * 2^(S-j) y_final = 90*2^R + sum_{j=1..S} 2^(R - (m_0+...+m_{j-1})) Odd path length n = R+S+1 forces R+S even, and writing the equality as (45+A)*2^S = (90+B)*2^R with A = sum m_j 2^-j <= R and B <= S shows: R-S >= 2 needs R >= 136 (n >= 271), R-S <= -2 needs S >= 91 (n >= 181), so the minimum comes from R = S, where x_final = y_final becomes sum_j m_j * 2^(S-j) - sum_j 2^(m_{j}+...+m_S ... ) = 45*2^S i.e. X - Y = 45*2^S. A depth-first search over the compositions m_0..m_S with interval pruning finds the smallest S with a valid word (checking the no-early-equality condition by simulation). The same search with R = S-1 reproduces the stated example: length 10, final value 1476. First odd solution: S = R = 48, length 97, unique.

Answer25332747903959376
Output25332747903959376
StatusPASS
Native helperno
Runtime0 ms
Peak memory1072 KB
Time complexityO(n^2) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n log n)
Space complexityO(1)O(n)
ApproachFlow solutionSearch with pruning or sieve
VerdictSuboptimal

Flow source

# Project Euler 736
# Paths to equality: r(x,y) = (x+1, 2y), s(x,y) = (2x, y+1). Starting from
# (45,90), find the final value of the unique path to equality of smallest
# odd length (coordinates unequal at every point before the last).
#
# Method: a word with R r-ops and S s-ops, written as m_0 r's, s, m_1 r's,
# s, ..., s, m_S r's, gives
#   x_final = 45*2^S + sum_j m_j * 2^(S-j)
#   y_final = 90*2^R + sum_{j=1..S} 2^(R - (m_0+...+m_{j-1}))
# Odd path length n = R+S+1 forces R+S even, and writing the equality as
# (45+A)*2^S = (90+B)*2^R with A = sum m_j 2^-j <= R and B <= S shows:
# R-S >= 2 needs R >= 136 (n >= 271), R-S <= -2 needs S >= 91 (n >= 181),
# so the minimum comes from R = S, where x_final = y_final becomes
#   sum_j m_j * 2^(S-j) - sum_j 2^(m_{j}+...+m_S ... ) = 45*2^S
# i.e. X - Y = 45*2^S. A depth-first search over the compositions m_0..m_S
# with interval pruning finds the smallest S with a valid word (checking the
# no-early-equality condition by simulation). The same search with R = S-1
# reproduces the stated example: length 10, final value 1476. First odd
# solution: S = R = 48, length 97, unique.

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

# Simulate the word given by gaps m[0..S] (R = S), verify coordinates stay
# unequal until the final point and equal there. Returns final value or -1.
function check(m: ptr<i64>, S: i64) -> i64 {
    let mut x: i64 = 45
    let mut y: i64 = 90
    let total: i64 = 2 * S
    let mut done: i64 = 0
    for j in 0..S+1 {
        for t in 0..m[j] {
            x = x + 1
            y = y * 2
            done = done + 1
            if done < total && x == y {
                return -1
            }
        }
        if j < S {
            x = x * 2
            y = y + 1
            done = done + 1
            if done < total && x == y {
                return -1
            }
        }
    }
    if x == y {
        return x
    }
    return -1
}

# DFS over gap counts m[j], j = 0..S, with R = S r-ops in total.
# diff = (partial X) - (partial Y); need diff == target at the end.
# The y-term added when placing m_j is 2^(remaining r's after this gap).
function dfs(j: i64, rem: i64, diff: i64, S: i64, target: i64,
             m: ptr<i64>, p2: ptr<i64>) -> i64 {
    if j == S {
        m[S] = rem
        if diff + rem == target {
            return check(m, S)
        }
        return -1
    }
    let w: i64 = p2[S - j]
    let t: i64 = S - j - 1
    for mj in 0..rem+1 {
        let rem2: i64 = rem - mj
        let nd: i64 = diff + mj * w - p2[rem2]
        # Remaining X in [rem2, rem2*2^(S-j-1)], remaining Y in [t, t*2^rem2]
        let lo: i64 = nd + rem2 - t * p2[rem2]
        let hi: i64 = nd + rem2 * p2[S - j - 1] - t
        if lo <= target && target <= hi {
            m[j] = mj
            let v: i64 = dfs(j + 1, rem2, nd, S, target, m, p2)
            if v >= 0 {
                return v
            }
        }
    }
    return -1
}

function main() -> i32 {
    let p2: ptr<i64> = calloc(64, 8)
    p2[0] = 1
    for i in 1..54 {
        p2[i] = p2[i - 1] * 2
    }
    let m: ptr<i64> = calloc(64, 8)
    let mut ans: i64 = -1
    let mut S: i64 = 1
    while S <= 52 && ans < 0 {
        let target: i64 = 45 * p2[S]
        ans = dfs(0, S, 0, S, target, m, p2)
        S = S + 1
    }
    printf("%lld\n", ans)
    free(m)
    free(p2)
    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 check_ptr_i64_i64(int64_t* m, int64_t S);
int64_t dfs_i64_i64_i64_i64_i64_ptr_i64_ptr_i64(int64_t j, int64_t rem, int64_t diff, int64_t S, int64_t target, int64_t* m, int64_t* p2);
int32_t main(void);



int64_t check_ptr_i64_i64(int64_t* m, int64_t S) {
    int64_t x = 45;
    int64_t y = 90;
    int64_t total = (2 * S);
    int64_t done = 0;
    int32_t __flow_step_1 = 1;
    for (int32_t j = 0; (0 <= (S + 1)) ? j < (S + 1) : j > (S + 1); j += (0 <= (S + 1)) ? 1 : -1) {
        int32_t __flow_step_2 = 1;
        for (int32_t t = 0; (0 <= m[j]) ? t < m[j] : t > m[j]; t += (0 <= m[j]) ? 1 : -1) {
            x = (x + 1);
            y = (y * 2);
            done = (done + 1);
            if ((done < total && x == y)) {
                return (-1);
            }
        }
        if (j < S) {
            x = (x * 2);
            y = (y + 1);
            done = (done + 1);
            if ((done < total && x == y)) {
                return (-1);
            }
        }
    }
    if (x == y) {
        return x;
    }
    return (-1);
}

int64_t dfs_i64_i64_i64_i64_i64_ptr_i64_ptr_i64(int64_t j, int64_t rem, int64_t diff, int64_t S, int64_t target, int64_t* m, int64_t* p2) {
    if (j == S) {
        m[S] = rem;
        if ((diff + rem) == target) {
            return check_ptr_i64_i64(m, S);
        }
        return (-1);
    }
    int64_t w = p2[(S - j)];
    int64_t t = ((S - j) - 1);
    int32_t __flow_step_3 = 1;
    for (int32_t mj = 0; (0 <= (rem + 1)) ? mj < (rem + 1) : mj > (rem + 1); mj += (0 <= (rem + 1)) ? 1 : -1) {
        int64_t rem2 = (rem - mj);
        int64_t nd = ((diff + (mj * w)) - p2[rem2]);
        int64_t lo = ((nd + rem2) - (t * p2[rem2]));
        int64_t hi = ((nd + (rem2 * p2[((S - j) - 1)])) - t);
        if ((lo <= target && target <= hi)) {
            m[j] = mj;
            int64_t v = dfs_i64_i64_i64_i64_i64_ptr_i64_ptr_i64((j + 1), rem2, nd, S, target, m, p2);
            if (v >= 0) {
                return v;
            }
        }
    }
    return (-1);
}

int32_t main(void) {
    int64_t* p2 = (int64_t*)(calloc(64, 8));
    p2[0] = 1;
    int32_t __flow_step_4 = 1;
    for (int32_t i = 1; (1 <= 54) ? i < 54 : i > 54; i += (1 <= 54) ? 1 : -1) {
        p2[i] = (p2[(i - 1)] * 2);
    }
    int64_t* m = (int64_t*)(calloc(64, 8));
    int64_t ans = (-1);
    int64_t S = 1;
    while ((S <= 52 && ans < 0)) {
        int64_t target = (45 * p2[S]);
        ans = dfs_i64_i64_i64_i64_i64_ptr_i64_ptr_i64(0, S, 0, S, target, m, p2);
        S = (S + 1);
    }
    printf("%lld\n", ans);
    free(m);
    free(p2);
    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 @check(%arg0: !llvm.ptr, %arg1: i64) -> i64 {
    %0 = arith.constant 45 : 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
    %4 = arith.constant 90 : i32
    %5 = arith.extsi %4 : i32 to i64
    %6 = llvm.mlir.constant(1 : i64) : i64
    %7 = llvm.alloca %6 x i64 : (i64) -> !llvm.ptr
    llvm.store %5, %7 : i64, !llvm.ptr
    %8 = arith.constant 2 : i32
    %10 = arith.extsi %8 : i32 to i64
    %9 = arith.muli %10, %arg1 : i64
    %11 = arith.constant 0 : i32
    %12 = arith.extsi %11 : i32 to i64
    %13 = llvm.mlir.constant(1 : i64) : i64
    %14 = llvm.alloca %13 x i64 : (i64) -> !llvm.ptr
    llvm.store %12, %14 : i64, !llvm.ptr
    %15 = arith.constant 0 : i32
    %16 = arith.constant 1 : i32
    %18 = arith.extsi %16 : i32 to i64
    %17 = arith.addi %arg1, %18 : i64
    %19 = arith.index_cast %15 : i32 to index
    %20 = arith.index_cast %17 : i32 to index
    %22 = arith.constant 1 : index
    %23 = arith.constant -1 : index
    %24 = arith.cmpi sle, %19, %20 : index
    %21 = arith.select %24, %22, %23 : index
    cf.br ^bb0(%19 : index)
    ^bb0(%25: index):
    %26 = arith.cmpi slt, %25, %20 : index
    %27 = arith.cmpi sgt, %25, %20 : index
    %28 = arith.select %24, %26, %27 : i1
    cf.cond_br %28, ^bb1(%25 : index), ^bb2(%25 : index)
    ^bb1(%29: index):
      %30 = arith.constant 0 : i32
      %32 = arith.index_cast %29 : index to i64
      %33 = llvm.getelementptr %arg0[%32] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %31 = llvm.load %33 : !llvm.ptr -> i64
      %34 = arith.index_cast %30 : i32 to index
      %35 = arith.index_cast %31 : i32 to index
      %37 = arith.constant 1 : index
      %38 = arith.constant -1 : index
      %39 = arith.cmpi sle, %34, %35 : index
      %36 = arith.select %39, %37, %38 : index
      cf.br ^bb3(%34 : index)
      ^bb3(%40: index):
      %41 = arith.cmpi slt, %40, %35 : index
      %42 = arith.cmpi sgt, %40, %35 : index
      %43 = arith.select %39, %41, %42 : i1
      cf.cond_br %43, ^bb4(%40 : index), ^bb5(%40 : index)
      ^bb4(%44: index):
        %45 = llvm.load %3 : !llvm.ptr -> i64
        %46 = arith.constant 1 : i32
        %48 = arith.extsi %46 : i32 to i64
        %47 = arith.addi %45, %48 : i64
        llvm.store %47, %3 : i64, !llvm.ptr
        %49 = llvm.load %7 : !llvm.ptr -> i64
        %50 = arith.constant 2 : i32
        %52 = arith.extsi %50 : i32 to i64
        %51 = arith.muli %49, %52 : i64
        llvm.store %51, %7 : i64, !llvm.ptr
        %53 = llvm.load %14 : !llvm.ptr -> i64
        %54 = arith.constant 1 : i32
        %56 = arith.extsi %54 : i32 to i64
        %55 = arith.addi %53, %56 : i64
        llvm.store %55, %14 : i64, !llvm.ptr
        %57 = llvm.load %14 : !llvm.ptr -> i64
        %58 = arith.cmpi slt, %57, %9 : i64
        %59 = scf.if %58 -> (i1) {
          %60 = llvm.load %3 : !llvm.ptr -> i64
          %61 = llvm.load %7 : !llvm.ptr -> i64
          %62 = arith.cmpi eq, %60, %61 : i64
          scf.yield %62 : i1
        } else {
          %63 = arith.constant false
          scf.yield %63 : i1
        }
        cf.cond_br %59, ^bb6, ^bb7
        ^bb6:
          %64 = arith.constant 1 : i32
          %66 = arith.constant 0 : i32
          %65 = arith.subi %66, %64 : i32
          %67 = arith.extsi %65 : i32 to i64
          func.return %67 : i64
        ^bb7:
          cf.br ^bb8
        ^bb8:
        %68 = arith.addi %44, %36 : index
        cf.br ^bb3(%68 : index)
      ^bb5(%69: index):
      %71 = arith.index_cast %29 : index to i32
      %72 = arith.trunci %arg1 : i64 to i32
      %70 = arith.cmpi slt, %71, %72 : i32
      cf.cond_br %70, ^bb9, ^bb10
      ^bb9:
        %73 = llvm.load %3 : !llvm.ptr -> i64
        %74 = arith.constant 2 : i32
        %76 = arith.extsi %74 : i32 to i64
        %75 = arith.muli %73, %76 : i64
        llvm.store %75, %3 : i64, !llvm.ptr
        %77 = llvm.load %7 : !llvm.ptr -> i64
        %78 = arith.constant 1 : i32
        %80 = arith.extsi %78 : i32 to i64
        %79 = arith.addi %77, %80 : i64
        llvm.store %79, %7 : i64, !llvm.ptr
        %81 = llvm.load %14 : !llvm.ptr -> i64
        %82 = arith.constant 1 : i32
        %84 = arith.extsi %82 : i32 to i64
        %83 = arith.addi %81, %84 : i64
        llvm.store %83, %14 : i64, !llvm.ptr
        %85 = llvm.load %14 : !llvm.ptr -> i64
        %86 = arith.cmpi slt, %85, %9 : i64
        %87 = scf.if %86 -> (i1) {
          %88 = llvm.load %3 : !llvm.ptr -> i64
          %89 = llvm.load %7 : !llvm.ptr -> i64
          %90 = arith.cmpi eq, %88, %89 : i64
          scf.yield %90 : i1
        } else {
          %91 = arith.constant false
          scf.yield %91 : i1
        }
        cf.cond_br %87, ^bb12, ^bb13
        ^bb12:
          %92 = arith.constant 1 : i32
          %94 = arith.constant 0 : i32
          %93 = arith.subi %94, %92 : i32
          %95 = arith.extsi %93 : i32 to i64
          func.return %95 : i64
        ^bb13:
          cf.br ^bb14
        ^bb14:
        cf.br ^bb11
      ^bb10:
        cf.br ^bb11
      ^bb11:
      %96 = arith.addi %29, %21 : index
      cf.br ^bb0(%96 : index)
    ^bb2(%97: index):
    %98 = llvm.load %3 : !llvm.ptr -> i64
    %99 = llvm.load %7 : !llvm.ptr -> i64
    %100 = arith.cmpi eq, %98, %99 : i64
    cf.cond_br %100, ^bb15, ^bb16
    ^bb15:
      %101 = llvm.load %3 : !llvm.ptr -> i64
      func.return %101 : i64
    ^bb16:
      cf.br ^bb17
    ^bb17:
    %102 = arith.constant 1 : i32
    %104 = arith.constant 0 : i32
    %103 = arith.subi %104, %102 : i32
    %105 = arith.extsi %103 : i32 to i64
    func.return %105 : i64
  }
  func.func @dfs(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: i64, %arg5: !llvm.ptr, %arg6: !llvm.ptr) -> i64 {
    %106 = arith.cmpi eq, %arg0, %arg3 : i64
    cf.cond_br %106, ^bb18, ^bb19
    ^bb18:
      %107 = llvm.getelementptr %arg5[%arg3] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %arg1, %107 : i64, !llvm.ptr
      %108 = arith.addi %arg2, %arg1 : i64
      %109 = arith.cmpi eq, %108, %arg4 : i64
      cf.cond_br %109, ^bb21, ^bb22
      ^bb21:
        %110 = func.call @check(%arg5, %arg3) : (!llvm.ptr, i64) -> i64
        func.return %110 : i64
      ^bb22:
        cf.br ^bb23
      ^bb23:
      %111 = arith.constant 1 : i32
      %113 = arith.constant 0 : i32
      %112 = arith.subi %113, %111 : i32
      %114 = arith.extsi %112 : i32 to i64
      func.return %114 : i64
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %116 = arith.subi %arg3, %arg0 : i64
    %117 = llvm.getelementptr %arg6[%116] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %115 = llvm.load %117 : !llvm.ptr -> i64
    %118 = arith.subi %arg3, %arg0 : i64
    %119 = arith.constant 1 : i32
    %121 = arith.extsi %119 : i32 to i64
    %120 = arith.subi %118, %121 : i64
    %122 = arith.constant 0 : i32
    %123 = arith.constant 1 : i32
    %125 = arith.extsi %123 : i32 to i64
    %124 = arith.addi %arg1, %125 : i64
    %126 = arith.index_cast %122 : i32 to index
    %127 = arith.index_cast %124 : i32 to index
    %129 = arith.constant 1 : index
    %130 = arith.constant -1 : index
    %131 = arith.cmpi sle, %126, %127 : index
    %128 = arith.select %131, %129, %130 : index
    cf.br ^bb24(%126 : index)
    ^bb24(%132: index):
    %133 = arith.cmpi slt, %132, %127 : index
    %134 = arith.cmpi sgt, %132, %127 : index
    %135 = arith.select %131, %133, %134 : i1
    cf.cond_br %135, ^bb25(%132 : index), ^bb26(%132 : index)
    ^bb25(%136: index):
      %138 = arith.trunci %arg1 : i64 to i32
      %139 = arith.index_cast %136 : index to i32
      %137 = arith.subi %138, %139 : i32
      %140 = arith.extsi %137 : i32 to i64
      %142 = arith.index_cast %136 : index to i32
      %143 = arith.trunci %115 : i64 to i32
      %141 = arith.muli %142, %143 : i32
      %145 = arith.extsi %141 : i32 to i64
      %144 = arith.addi %arg2, %145 : i64
      %147 = llvm.getelementptr %arg6[%140] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %146 = llvm.load %147 : !llvm.ptr -> i64
      %148 = arith.subi %144, %146 : i64
      %149 = arith.addi %148, %140 : i64
      %151 = llvm.getelementptr %arg6[%140] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %150 = llvm.load %151 : !llvm.ptr -> i64
      %152 = arith.muli %120, %150 : i64
      %153 = arith.subi %149, %152 : i64
      %155 = arith.subi %arg3, %arg0 : i64
      %156 = arith.constant 1 : i32
      %158 = arith.extsi %156 : i32 to i64
      %157 = arith.subi %155, %158 : i64
      %159 = llvm.getelementptr %arg6[%157] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %154 = llvm.load %159 : !llvm.ptr -> i64
      %160 = arith.muli %140, %154 : i64
      %161 = arith.addi %148, %160 : i64
      %162 = arith.subi %161, %120 : i64
      %163 = arith.cmpi sle, %153, %arg4 : i64
      %164 = scf.if %163 -> (i1) {
        %165 = arith.cmpi sle, %arg4, %162 : i64
        scf.yield %165 : i1
      } else {
        %166 = arith.constant false
        scf.yield %166 : i1
      }
      cf.cond_br %164, ^bb27, ^bb28
      ^bb27:
        %167 = arith.index_cast %136 : index to i64
        %168 = llvm.getelementptr %arg5[%arg0] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %167, %168 : i64, !llvm.ptr
        %170 = arith.constant 1 : i32
        %172 = arith.extsi %170 : i32 to i64
        %171 = arith.addi %arg0, %172 : i64
        %169 = func.call @dfs(%171, %140, %148, %arg3, %arg4, %arg5, %arg6) : (i64, i64, i64, i64, i64, !llvm.ptr, !llvm.ptr) -> i64
        %173 = arith.constant 0 : i32
        %175 = arith.extsi %173 : i32 to i64
        %174 = arith.cmpi sge, %169, %175 : i64
        cf.cond_br %174, ^bb30, ^bb31
        ^bb30:
          func.return %169 : i64
        ^bb31:
          cf.br ^bb32
        ^bb32:
        cf.br ^bb29
      ^bb28:
        cf.br ^bb29
      ^bb29:
      %176 = arith.addi %136, %128 : index
      cf.br ^bb24(%176 : index)
    ^bb26(%177: index):
    %178 = arith.constant 1 : i32
    %180 = arith.constant 0 : i32
    %179 = arith.subi %180, %178 : i32
    %181 = arith.extsi %179 : i32 to i64
    func.return %181 : i64
  }
  func.func @main() -> i32 {
    %183 = arith.constant 64 : i32
    %184 = arith.constant 8 : i32
    %185 = arith.extsi %183 : i32 to i64
    %186 = arith.extsi %184 : i32 to i64
    %182 = func.call @calloc(%185, %186) : (i64, i64) -> !llvm.ptr
    %187 = arith.constant 1 : i32
    %188 = arith.constant 0 : i32
    %189 = arith.extsi %187 : i32 to i64
    %190 = arith.extsi %188 : i32 to i64
    %191 = llvm.getelementptr %182[%190] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %189, %191 : i64, !llvm.ptr
    %192 = arith.constant 1 : i32
    %193 = arith.constant 54 : i32
    %194 = arith.index_cast %192 : i32 to index
    %195 = arith.index_cast %193 : i32 to index
    %197 = arith.constant 1 : index
    %198 = arith.constant -1 : index
    %199 = arith.cmpi sle, %194, %195 : index
    %196 = arith.select %199, %197, %198 : index
    cf.br ^bb33(%194 : index)
    ^bb33(%200: index):
    %201 = arith.cmpi slt, %200, %195 : index
    %202 = arith.cmpi sgt, %200, %195 : index
    %203 = arith.select %199, %201, %202 : i1
    cf.cond_br %203, ^bb34(%200 : index), ^bb35(%200 : index)
    ^bb34(%204: index):
      %206 = arith.constant 1 : i32
      %208 = arith.index_cast %204 : index to i32
      %207 = arith.subi %208, %206 : i32
      %209 = arith.extsi %207 : i32 to i64
      %210 = llvm.getelementptr %182[%209] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %205 = llvm.load %210 : !llvm.ptr -> i64
      %211 = arith.constant 2 : i32
      %213 = arith.extsi %211 : i32 to i64
      %212 = arith.muli %205, %213 : i64
      %214 = arith.index_cast %204 : index to i64
      %215 = llvm.getelementptr %182[%214] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %212, %215 : i64, !llvm.ptr
      %216 = arith.addi %204, %196 : index
      cf.br ^bb33(%216 : index)
    ^bb35(%217: index):
    %219 = arith.constant 64 : i32
    %220 = arith.constant 8 : i32
    %221 = arith.extsi %219 : i32 to i64
    %222 = arith.extsi %220 : i32 to i64
    %218 = func.call @calloc(%221, %222) : (i64, i64) -> !llvm.ptr
    %223 = arith.constant 1 : i32
    %225 = arith.constant 0 : i32
    %224 = arith.subi %225, %223 : i32
    %226 = arith.extsi %224 : i32 to i64
    %227 = llvm.mlir.constant(1 : i64) : i64
    %228 = llvm.alloca %227 x i64 : (i64) -> !llvm.ptr
    llvm.store %226, %228 : i64, !llvm.ptr
    %229 = arith.constant 1 : i32
    %230 = arith.extsi %229 : i32 to i64
    %231 = llvm.mlir.constant(1 : i64) : i64
    %232 = llvm.alloca %231 x i64 : (i64) -> !llvm.ptr
    llvm.store %230, %232 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %233 = llvm.load %232 : !llvm.ptr -> i64
    %234 = arith.constant 52 : i32
    %236 = arith.extsi %234 : i32 to i64
    %235 = arith.cmpi sle, %233, %236 : i64
    %237 = scf.if %235 -> (i1) {
      %238 = llvm.load %228 : !llvm.ptr -> i64
      %239 = arith.constant 0 : i32
      %241 = arith.extsi %239 : i32 to i64
      %240 = arith.cmpi slt, %238, %241 : i64
      scf.yield %240 : i1
    } else {
      %242 = arith.constant false
      scf.yield %242 : i1
    }
    cf.cond_br %237, ^bb37, ^bb38
    ^bb37:
      %243 = arith.constant 45 : i32
      %245 = llvm.load %232 : !llvm.ptr -> i64
      %246 = llvm.getelementptr %182[%245] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %244 = llvm.load %246 : !llvm.ptr -> i64
      %248 = arith.extsi %243 : i32 to i64
      %247 = arith.muli %248, %244 : i64
      %250 = arith.constant 0 : i32
      %251 = llvm.load %232 : !llvm.ptr -> i64
      %252 = arith.constant 0 : i32
      %253 = llvm.load %232 : !llvm.ptr -> i64
      %254 = arith.extsi %250 : i32 to i64
      %255 = arith.extsi %252 : i32 to i64
      %249 = func.call @dfs(%254, %251, %255, %253, %247, %218, %182) : (i64, i64, i64, i64, i64, !llvm.ptr, !llvm.ptr) -> i64
      llvm.store %249, %228 : i64, !llvm.ptr
      %256 = llvm.load %232 : !llvm.ptr -> i64
      %257 = arith.constant 1 : i32
      %259 = arith.extsi %257 : i32 to i64
      %258 = arith.addi %256, %259 : i64
      llvm.store %258, %232 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %260 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %261 = llvm.load %228 : !llvm.ptr -> i64
    %262 = llvm.call @printf(%260, %261) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%218) : (!llvm.ptr) -> ()
    func.call @free(%182) : (!llvm.ptr) -> ()
    %265 = arith.constant 0 : i32
    func.return %265 : i32
  }
}