Problem 220

Heighway Dragon D_50 position after 10^12 steps: x,y

Answer139776,963904
Output139776,963904
StatusPASS
Native helperno
Runtime0 ms
Peak memory1088 KB
Time complexityO(n) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n)O(log n)
Space complexityO(n^2)O(log n)
ApproachFlow solutionRecursive curve computation
VerdictSuboptimal

Flow source

# Project Euler 220
# Heighway Dragon D_50 position after 10^12 steps: x,y

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

function rot_cw_x(x: i64, y: i64, k: i32) -> i64 {
    let kk: i32 = k & 3
    if kk == 0 { return x }
    if kk == 1 { return y }
    if kk == 2 { return 0 - x }
    return 0 - y
}

function rot_cw_y(x: i64, y: i64, k: i32) -> i64 {
    let kk: i32 = k & 3
    if kk == 0 { return y }
    if kk == 1 { return 0 - x }
    if kk == 2 { return 0 - y }
    return x
}

function main() -> i32 {
    let MAXN: i32 = 50
    let Asteps: ptr<i64> = calloc(MAXN as i64 + 1, 8)
    let Adx: ptr<i64> = calloc(MAXN as i64 + 1, 8)
    let Ady: ptr<i64> = calloc(MAXN as i64 + 1, 8)
    let Arot: ptr<i32> = calloc(MAXN as i64 + 1, 4)
    let Bsteps: ptr<i64> = calloc(MAXN as i64 + 1, 8)
    let Bdx: ptr<i64> = calloc(MAXN as i64 + 1, 8)
    let Bdy: ptr<i64> = calloc(MAXN as i64 + 1, 8)
    let Brot: ptr<i32> = calloc(MAXN as i64 + 1, 4)
    if Asteps == null || Bsteps == null { return 1 }

    let mut n: i32 = 1
    while n <= MAXN {
        # A(n) = A(n-1) R B(n-1) F R
        let mut s: i64 = Asteps[n - 1]
        let mut dx: i64 = Adx[n - 1]
        let mut dy: i64 = Ady[n - 1]
        let mut rot: i32 = Arot[n - 1]
        # R
        rot = (rot + 1) & 3
        # B(n-1)
        let bx: i64 = rot_cw_x(Bdx[n - 1], Bdy[n - 1], rot)
        let by: i64 = rot_cw_y(Bdx[n - 1], Bdy[n - 1], rot)
        dx = dx + bx
        dy = dy + by
        s = s + Bsteps[n - 1]
        rot = (rot + Brot[n - 1]) & 3
        # F
        let fx: i64 = rot_cw_x(0, 1, rot)
        let fy: i64 = rot_cw_y(0, 1, rot)
        dx = dx + fx
        dy = dy + fy
        s = s + 1
        # R
        rot = (rot + 1) & 3
        Asteps[n] = s
        Adx[n] = dx
        Ady[n] = dy
        Arot[n] = rot

        # B(n) = L F A(n-1) L B(n-1)
        s = 0
        dx = 0
        dy = 0
        rot = 0
        # L
        rot = (rot + 3) & 3
        # F
        fx = rot_cw_x(0, 1, rot)
        fy = rot_cw_y(0, 1, rot)
        dx = dx + fx
        dy = dy + fy
        s = s + 1
        # A(n-1)
        let ax: i64 = rot_cw_x(Adx[n - 1], Ady[n - 1], rot)
        let ay: i64 = rot_cw_y(Adx[n - 1], Ady[n - 1], rot)
        dx = dx + ax
        dy = dy + ay
        s = s + Asteps[n - 1]
        rot = (rot + Arot[n - 1]) & 3
        # L
        rot = (rot + 3) & 3
        # B(n-1)
        bx = rot_cw_x(Bdx[n - 1], Bdy[n - 1], rot)
        by = rot_cw_y(Bdx[n - 1], Bdy[n - 1], rot)
        dx = dx + bx
        dy = dy + by
        s = s + Bsteps[n - 1]
        rot = (rot + Brot[n - 1]) & 3
        Bsteps[n] = s
        Bdx[n] = dx
        Bdy[n] = dy
        Brot[n] = rot
        n = n + 1
    }

    # Execute D_50 = F + a^50 with k=10^12 steps using explicit stack
    let mut k: i64 = 1000000000000
    let mut x: i64 = 0
    let mut y: i64 = 0
    let mut d: i32 = 0  # up
    # F first
    if k > 0 {
        if d == 0 { y = y + 1 }
        elif d == 1 { x = x + 1 }
        elif d == 2 { y = y - 1 }
        else { x = x - 1 }
        k = k - 1
    }

    # stack of (sym, depth): sym 0=a 1=b 2=F 3=L 4=R
    let st_sym: ptr<i32> = calloc(200, 4)
    let st_dep: ptr<i32> = calloc(200, 4)
    let mut sp: i32 = 0
    st_sym[0] = 0
    st_dep[0] = 50
    sp = 1

    while sp > 0 && k > 0 {
        sp = sp - 1
        let sym: i32 = st_sym[sp]
        let dep: i32 = st_dep[sp]
        if sym == 2 {
            if d == 0 { y = y + 1 }
            elif d == 1 { x = x + 1 }
            elif d == 2 { y = y - 1 }
            else { x = x - 1 }
            k = k - 1
        } elif sym == 3 {
            d = (d + 3) & 3
        } elif sym == 4 {
            d = (d + 1) & 3
        } elif dep == 0 {
            # a/b at depth 0: noop
        } else {
            let steps: i64 = Asteps[dep]
            if sym == 1 { steps = Bsteps[dep] }
            if k >= steps {
                let tdx: i64 = Adx[dep]
                let tdy: i64 = Ady[dep]
                let trot: i32 = Arot[dep]
                if sym == 1 {
                    tdx = Bdx[dep]
                    tdy = Bdy[dep]
                    trot = Brot[dep]
                }
                let gx: i64 = rot_cw_x(tdx, tdy, d)
                let gy: i64 = rot_cw_y(tdx, tdy, d)
                x = x + gx
                y = y + gy
                d = (d + trot) & 3
                k = k - steps
            } else {
                # expand production in reverse for stack
                if sym == 0 {
                    # a -> a R b F R
                    st_sym[sp] = 4; st_dep[sp] = 0; sp = sp + 1
                    st_sym[sp] = 2; st_dep[sp] = 0; sp = sp + 1
                    st_sym[sp] = 1; st_dep[sp] = dep - 1; sp = sp + 1
                    st_sym[sp] = 4; st_dep[sp] = 0; sp = sp + 1
                    st_sym[sp] = 0; st_dep[sp] = dep - 1; sp = sp + 1
                } else {
                    # b -> L F a L b
                    st_sym[sp] = 1; st_dep[sp] = dep - 1; sp = sp + 1
                    st_sym[sp] = 3; st_dep[sp] = 0; sp = sp + 1
                    st_sym[sp] = 0; st_dep[sp] = dep - 1; sp = sp + 1
                    st_sym[sp] = 2; st_dep[sp] = 0; sp = sp + 1
                    st_sym[sp] = 3; st_dep[sp] = 0; sp = sp + 1
                }
            }
        }
    }
    printf("%lld,%lld\n", x, y)
    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 rot_cw_x_i64_i64_i32(int64_t x, int64_t y, int32_t k);
int64_t rot_cw_y_i64_i64_i32(int64_t x, int64_t y, int32_t k);
int32_t main(void);



int64_t rot_cw_x_i64_i64_i32(int64_t x, int64_t y, int32_t k) {
    int32_t kk = (k & 3);
    if (kk == 0) {
        return x;
    }
    if (kk == 1) {
        return y;
    }
    if (kk == 2) {
        return (0 - x);
    }
    return (0 - y);
}

int64_t rot_cw_y_i64_i64_i32(int64_t x, int64_t y, int32_t k) {
    int32_t kk = (k & 3);
    if (kk == 0) {
        return y;
    }
    if (kk == 1) {
        return (0 - x);
    }
    if (kk == 2) {
        return (0 - y);
    }
    return x;
}

int32_t main(void) {
    int32_t MAXN = 50;
    int64_t* Asteps = (int64_t*)(calloc((((int64_t)(MAXN)) + 1), 8));
    int64_t* Adx = (int64_t*)(calloc((((int64_t)(MAXN)) + 1), 8));
    int64_t* Ady = (int64_t*)(calloc((((int64_t)(MAXN)) + 1), 8));
    int32_t* Arot = (int32_t*)(calloc((((int64_t)(MAXN)) + 1), 4));
    int64_t* Bsteps = (int64_t*)(calloc((((int64_t)(MAXN)) + 1), 8));
    int64_t* Bdx = (int64_t*)(calloc((((int64_t)(MAXN)) + 1), 8));
    int64_t* Bdy = (int64_t*)(calloc((((int64_t)(MAXN)) + 1), 8));
    int32_t* Brot = (int32_t*)(calloc((((int64_t)(MAXN)) + 1), 4));
    if ((Asteps == NULL || Bsteps == NULL)) {
        return 1;
    }
    int32_t n = 1;
    while (n <= MAXN) {
        int64_t s = Asteps[(n - 1)];
        int64_t dx = Adx[(n - 1)];
        int64_t dy = Ady[(n - 1)];
        int32_t rot = Arot[(n - 1)];
        rot = ((rot + 1) & 3);
        int64_t bx = rot_cw_x_i64_i64_i32(Bdx[(n - 1)], Bdy[(n - 1)], rot);
        int64_t by = rot_cw_y_i64_i64_i32(Bdx[(n - 1)], Bdy[(n - 1)], rot);
        dx = (dx + bx);
        dy = (dy + by);
        s = (s + Bsteps[(n - 1)]);
        rot = ((rot + Brot[(n - 1)]) & 3);
        int64_t fx = rot_cw_x_i64_i64_i32(0, 1, rot);
        int64_t fy = rot_cw_y_i64_i64_i32(0, 1, rot);
        dx = (dx + fx);
        dy = (dy + fy);
        s = (s + 1);
        rot = ((rot + 1) & 3);
        Asteps[n] = s;
        Adx[n] = dx;
        Ady[n] = dy;
        Arot[n] = rot;
        s = 0;
        dx = 0;
        dy = 0;
        rot = 0;
        rot = ((rot + 3) & 3);
        fx = rot_cw_x_i64_i64_i32(0, 1, rot);
        fy = rot_cw_y_i64_i64_i32(0, 1, rot);
        dx = (dx + fx);
        dy = (dy + fy);
        s = (s + 1);
        int64_t ax = rot_cw_x_i64_i64_i32(Adx[(n - 1)], Ady[(n - 1)], rot);
        int64_t ay = rot_cw_y_i64_i64_i32(Adx[(n - 1)], Ady[(n - 1)], rot);
        dx = (dx + ax);
        dy = (dy + ay);
        s = (s + Asteps[(n - 1)]);
        rot = ((rot + Arot[(n - 1)]) & 3);
        rot = ((rot + 3) & 3);
        bx = rot_cw_x_i64_i64_i32(Bdx[(n - 1)], Bdy[(n - 1)], rot);
        by = rot_cw_y_i64_i64_i32(Bdx[(n - 1)], Bdy[(n - 1)], rot);
        dx = (dx + bx);
        dy = (dy + by);
        s = (s + Bsteps[(n - 1)]);
        rot = ((rot + Brot[(n - 1)]) & 3);
        Bsteps[n] = s;
        Bdx[n] = dx;
        Bdy[n] = dy;
        Brot[n] = rot;
        n = (n + 1);
    }
    int64_t k = 1000000000000;
    int64_t x = 0;
    int64_t y = 0;
    int32_t d = 0;
    if (k > 0) {
        if (d == 0) {
            y = (y + 1);
        } else if (d == 1) {
            x = (x + 1);
        } else if (d == 2) {
            y = (y - 1);
        } else {
            x = (x - 1);
        }
        k = (k - 1);
    }
    int32_t* st_sym = (int32_t*)(calloc(200, 4));
    int32_t* st_dep = (int32_t*)(calloc(200, 4));
    int32_t sp = 0;
    st_sym[0] = 0;
    st_dep[0] = 50;
    sp = 1;
    while ((sp > 0 && k > 0)) {
        sp = (sp - 1);
        int32_t sym = st_sym[sp];
        int32_t dep = st_dep[sp];
        if (sym == 2) {
            if (d == 0) {
                y = (y + 1);
            } else if (d == 1) {
                x = (x + 1);
            } else if (d == 2) {
                y = (y - 1);
            } else {
                x = (x - 1);
            }
            k = (k - 1);
        } else if (sym == 3) {
            d = ((d + 3) & 3);
        } else if (sym == 4) {
            d = ((d + 1) & 3);
        } else if (dep == 0) {
        } else {
            int64_t steps = Asteps[dep];
            if (sym == 1) {
                steps = Bsteps[dep];
            }
            if (k >= steps) {
                int64_t tdx = Adx[dep];
                int64_t tdy = Ady[dep];
                int32_t trot = Arot[dep];
                if (sym == 1) {
                    tdx = Bdx[dep];
                    tdy = Bdy[dep];
                    trot = Brot[dep];
                }
                int64_t gx = rot_cw_x_i64_i64_i32(tdx, tdy, d);
                int64_t gy = rot_cw_y_i64_i64_i32(tdx, tdy, d);
                x = (x + gx);
                y = (y + gy);
                d = ((d + trot) & 3);
                k = (k - steps);
            } else {
                if (sym == 0) {
                    st_sym[sp] = 4;
                    st_dep[sp] = 0;
                    sp = (sp + 1);
                    st_sym[sp] = 2;
                    st_dep[sp] = 0;
                    sp = (sp + 1);
                    st_sym[sp] = 1;
                    st_dep[sp] = (dep - 1);
                    sp = (sp + 1);
                    st_sym[sp] = 4;
                    st_dep[sp] = 0;
                    sp = (sp + 1);
                    st_sym[sp] = 0;
                    st_dep[sp] = (dep - 1);
                    sp = (sp + 1);
                } else {
                    st_sym[sp] = 1;
                    st_dep[sp] = (dep - 1);
                    sp = (sp + 1);
                    st_sym[sp] = 3;
                    st_dep[sp] = 0;
                    sp = (sp + 1);
                    st_sym[sp] = 0;
                    st_dep[sp] = (dep - 1);
                    sp = (sp + 1);
                    st_sym[sp] = 2;
                    st_dep[sp] = 0;
                    sp = (sp + 1);
                    st_sym[sp] = 3;
                    st_dep[sp] = 0;
                    sp = (sp + 1);
                }
            }
        }
    }
    printf("%lld,%lld\n", x, y);
    return 0;
}

Generated MLIR

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