Problem 572

Idempotent Matrices Count 3x3 integer matrices M with M^2=M and entries in [-n,n]; n=200.

Answer19737656
Output19737656
StatusPASS
Native helperno
Runtime190 ms
Peak memory1136 KB
Time complexityO(n^5) (estimated)
Space complexityO(1) (estimated)

Performance comparison

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

Flow source

# Project Euler 572
# Idempotent Matrices
# Count 3x3 integer matrices M with M^2=M and entries in [-n,n]; n=200.

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

function abs64(x: i64) -> i64 {
    if x < 0 { return 0 - x }
    return x
}

function floor_div(a: i64, b: i64) -> i64 {
    # floor division for possibly negative a,b
    let mut q: i64 = a / b
    let r: i64 = a % b
    if r != 0 && ((a < 0) != (b < 0)) {
        q = q - 1
    }
    return q
}

function ceil_div(a: i64, b: i64) -> i64 {
    return 0 - floor_div(0 - a, b)
}

function egcd(a0: i64, b0: i64, out_x: ptr<i64>, out_y: ptr<i64>) -> i64 {
    let mut a: i64 = a0
    let mut b: i64 = b0
    let mut x0: i64 = 1
    let mut y0: i64 = 0
    let mut x1: i64 = 0
    let mut y1: i64 = 1
    while b != 0 {
        let q: i64 = a / b
        let t: i64 = a - q * b
        a = b
        b = t
        let nx: i64 = x0 - q * x1
        x0 = x1
        x1 = nx
        let ny: i64 = y0 - q * y1
        y0 = y1
        y1 = ny
    }
    if a < 0 {
        a = 0 - a
        x0 = 0 - x0
        y0 = 0 - y0
    }
    out_x[0] = x0
    out_y[0] = y0
    return a
}

function t_bounds(base: i64, step: i64, low: i64, high: i64, out_lo: ptr<i64>, out_hi: ptr<i64>) -> void {
    if step > 0 {
        out_lo[0] = ceil_div(low - base, step)
        out_hi[0] = floor_div(high - base, step)
    } else {
        out_lo[0] = ceil_div(high - base, step)
        out_hi[0] = floor_div(low - base, step)
    }
}

function count_2d(A: i64, B: i64, C: i64, Ly: i64, Ry: i64, Lz: i64, Rz: i64) -> i64 {
    if Ly > Ry || Lz > Rz { return 0 }
    if A == 0 {
        if B == 0 {
            if C == 0 { return (Ry - Ly + 1) * (Rz - Lz + 1) }
            return 0
        }
        if C % B != 0 { return 0 }
        let z: i64 = C / B
        if Lz <= z && z <= Rz { return Ry - Ly + 1 }
        return 0
    }
    if B == 0 {
        if C % A != 0 { return 0 }
        let y: i64 = C / A
        if Ly <= y && y <= Ry { return Rz - Lz + 1 }
        return 0
    }
    let xy: ptr<i64> = calloc(2, 8)
    let ox: ptr<i64> = calloc(1,8)
    let oy: ptr<i64> = calloc(1,8)
    let g: i64 = egcd(A, B, ox, oy)
    xy[0]=ox[0]
    xy[1]=oy[0]
    free(ox)
    free(oy)
    if g == 0 || C % g != 0 { free(xy); return 0 }
    let k: i64 = C / g
    let y0: i64 = xy[0] * k
    let z0: i64 = xy[1] * k
    let step_y: i64 = B / g
    let step_z: i64 = 0 - A / g
    let lohi: ptr<i64> = calloc(4, 8)
    let o1: ptr<i64> = calloc(1,8)
    let o2: ptr<i64> = calloc(1,8)
    let o3: ptr<i64> = calloc(1,8)
    let o4: ptr<i64> = calloc(1,8)
    t_bounds(y0, step_y, Ly, Ry, o1, o2)
    t_bounds(z0, step_z, Lz, Rz, o3, o4)
    lohi[0]=o1[0]; lohi[1]=o2[0]; lohi[2]=o3[0]; lohi[3]=o4[0]
    free(o1); free(o2); free(o3); free(o4)
    let lo: i64 = lohi[0]
    if lohi[2] > lo { lo = lohi[2] }
    let hi: i64 = lohi[1]
    if lohi[3] < hi { hi = lohi[3] }
    free(xy)
    free(lohi)
    if hi < lo { return 0 }
    return hi - lo + 1
}

function count_3d(a: i64, b: i64, c: i64, Lx: i64, Rx: i64, Ly: i64, Ry: i64, Lz: i64, Rz: i64) -> i64 {
    if Lx > Rx || Ly > Ry || Lz > Rz { return 0 }
    if a == 0 && b == 0 && c == 0 { return 0 }
    let nnz: i64 = 0
    if a != 0 { nnz = nnz + 1 }
    if b != 0 { nnz = nnz + 1 }
    if c != 0 { nnz = nnz + 1 }
    if nnz == 1 {
        if a != 0 {
            if 1 % a != 0 { return 0 }
            let x: i64 = 1 / a
            if Lx <= x && x <= Rx { return (Ry - Ly + 1) * (Rz - Lz + 1) }
            return 0
        }
        if b != 0 {
            if 1 % b != 0 { return 0 }
            let y: i64 = 1 / b
            if Ly <= y && y <= Ry { return (Rx - Lx + 1) * (Rz - Lz + 1) }
            return 0
        }
        if 1 % c != 0 { return 0 }
        let z: i64 = 1 / c
        if Lz <= z && z <= Rz { return (Rx - Lx + 1) * (Ry - Ly + 1) }
        return 0
    }
    if nnz == 2 {
        if a == 0 { return count_2d(b, c, 1, Ly, Ry, Lz, Rz) * (Rx - Lx + 1) }
        if b == 0 { return count_2d(a, c, 1, Lx, Rx, Lz, Rz) * (Ry - Ly + 1) }
        return count_2d(a, b, 1, Lx, Rx, Ly, Ry) * (Rz - Lz + 1)
    }
    let lenx: i64 = Rx - Lx + 1
    let leny: i64 = Ry - Ly + 1
    let lenz: i64 = Rz - Lz + 1
    let mut total: i64 = 0
    if lenx <= leny && lenx <= lenz {
        let mut x: i64 = Lx
        while x <= Rx {
            total = total + count_2d(b, c, 1 - a * x, Ly, Ry, Lz, Rz)
            x = x + 1
        }
    } elif leny <= lenx && leny <= lenz {
        let mut y: i64 = Ly
        while y <= Ry {
            total = total + count_2d(a, c, 1 - b * y, Lx, Rx, Lz, Rz)
            y = y + 1
        }
    } else {
        let mut z: i64 = Lz
        while z <= Rz {
            total = total + count_2d(a, b, 1 - c * z, Lx, Rx, Ly, Ry)
            z = z + 1
        }
    }
    return total
}

function isqrt(n: i64) -> i64 {
    if n <= 0 { return 0 }
    let mut x: i64 = n
    let mut y: i64 = (x + 1) / 2
    while y < x {
        x = y
        y = (x + n / x) / 2
    }
    return x
}

function count_rank1(n: i64) -> i64 {
    let T: i64 = isqrt(n)
    let mut S: i64 = 0
    let mut O: i64 = 0
    let mut a: i64 = 0 - T
    while a <= T {
        let mut b: i64 = 0 - T
        while b <= T {
            let mut c: i64 = 0 - T
            while c <= T {
                if not (a == 0 && b == 0 && c == 0) {
                    let U: i64 = abs64(a)
                    if abs64(b) > U { U = abs64(b) }
                    if abs64(c) > U { U = abs64(c) }
                    let B: i64 = n / U
                    S = S + count_3d(a, b, c, 0 - B, B, 0 - B, B, 0 - B, B)
                    O = O + count_3d(a, b, c, 0 - T, T, 0 - T, T, 0 - T, T)
                }
                c = c + 1
            }
            b = b + 1
        }
        a = a + 1
    }
    return (2 * S - O) / 2
}

function div_interval(low: i64, high: i64, coef: i64, out_L: ptr<i64>, out_R: ptr<i64>) -> void {
    if coef > 0 {
        out_L[0] = ceil_div(low, coef)
        out_R[0] = floor_div(high, coef)
    } else {
        out_L[0] = ceil_div(high, coef)
        out_R[0] = floor_div(low, coef)
    }
}

function count_rank2(n: i64) -> i64 {
    let T: i64 = isqrt(n)
    let mut SA: i64 = 0
    let mut overlap: i64 = 0
    let tmp: ptr<i64> = calloc(2, 8)
    let mut a: i64 = 0 - T
    while a <= T {
        let mut b: i64 = 0 - T
        while b <= T {
            let mut c: i64 = 0 - T
            while c <= T {
                if not (a == 0 && b == 0 && c == 0) {
                    let u0: i64 = a
                    let u1: i64 = b
                    let u2: i64 = c
                    let low: i64 = 1 - n
                    let high: i64 = 1 + n
                    let mut L0: i64 = 0
                    let mut R0: i64 = 0
                    let mut L1: i64 = 0
                    let mut R1: i64 = 0
                    let mut L2: i64 = 0
                    let mut R2: i64 = 0
                    let mut ok: i32 = 1
                    let mut j: i64 = 0
                    while j < 3 {
                        let mut off: i64 = n
                        let mut i: i64 = 0
                        while i < 3 {
                            if i != j {
                                let ui: i64 = u0
                                if i == 1 { ui = u1 }
                                if i == 2 { ui = u2 }
                                if ui != 0 {
                                    let t: i64 = n / abs64(ui)
                                    if t < off { off = t }
                                }
                            }
                            i = i + 1
                        }
                        let mut L: i64 = 0 - off
                        let mut R: i64 = off
                        let uj: i64 = u0
                        if j == 1 { uj = u1 }
                        if j == 2 { uj = u2 }
                        if uj != 0 {
                            let dL: ptr<i64> = calloc(1,8)
                            let dR: ptr<i64> = calloc(1,8)
                            div_interval(low, high, uj, dL, dR)
                            tmp[0]=dL[0]; tmp[1]=dR[0]
                            free(dL); free(dR)
                            let Ld: i64 = tmp[0]
                            let Rd: i64 = tmp[1]
                            if Ld > Rd {
                                let sw: i64 = Ld
                                Ld = Rd
                                Rd = sw
                            }
                            if Ld > L { L = Ld }
                            if Rd < R { R = Rd }
                        }
                        if j == 0 { L0 = L; R0 = R }
                        if j == 1 { L1 = L; R1 = R }
                        if j == 2 { L2 = L; R2 = R }
                        if L > R { ok = 0 }
                        j = j + 1
                    }
                    if ok != 0 {
                        SA = SA + count_3d(a, b, c, L0, R0, L1, R1, L2, R2)
                        let mut L0b: i64 = L0
                        let mut R0b: i64 = R0
                        let mut L1b: i64 = L1
                        let mut R1b: i64 = R1
                        let mut L2b: i64 = L2
                        let mut R2b: i64 = R2
                        if L0b < 0 - T { L0b = 0 - T }
                        if R0b > T { R0b = T }
                        if L1b < 0 - T { L1b = 0 - T }
                        if R1b > T { R1b = T }
                        if L2b < 0 - T { L2b = 0 - T }
                        if R2b > T { R2b = T }
                        if L0b <= R0b && L1b <= R1b && L2b <= R2b {
                            overlap = overlap + count_3d(a, b, c, L0b, R0b, L1b, R1b, L2b, R2b)
                        }
                    }
                }
                c = c + 1
            }
            b = b + 1
        }
        a = a + 1
    }
    free(tmp)
    return (2 * SA - overlap) / 2
}

function C(n: i64) -> i64 {
    if n == 0 { return 1 }
    return 2 + count_rank1(n) + count_rank2(n)
}

function main() -> i32 {
    printf("%lld\n", C(200))
    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 abs64_i64(int64_t x);
int64_t floor_div_i64_i64(int64_t a, int64_t b);
int64_t ceil_div_i64_i64(int64_t a, int64_t b);
int64_t egcd_i64_i64_ptr_i64_ptr_i64(int64_t a0, int64_t b0, int64_t* out_x, int64_t* out_y);
void t_bounds_i64_i64_i64_i64_ptr_i64_ptr_i64(int64_t base, int64_t step, int64_t low, int64_t high, int64_t* out_lo, int64_t* out_hi);
int64_t count_2d_i64_i64_i64_i64_i64_i64_i64(int64_t A, int64_t B, int64_t C, int64_t Ly, int64_t Ry, int64_t Lz, int64_t Rz);
int64_t count_3d_i64_i64_i64_i64_i64_i64_i64_i64_i64(int64_t a, int64_t b, int64_t c, int64_t Lx, int64_t Rx, int64_t Ly, int64_t Ry, int64_t Lz, int64_t Rz);
int64_t isqrt_i64(int64_t n);
int64_t count_rank1_i64(int64_t n);
void div_interval_i64_i64_i64_ptr_i64_ptr_i64(int64_t low, int64_t high, int64_t coef, int64_t* out_L, int64_t* out_R);
int64_t count_rank2_i64(int64_t n);
int64_t C_i64(int64_t n);
int32_t main(void);



int64_t abs64_i64(int64_t x) {
    if (x < 0) {
        return (0 - x);
    }
    return x;
}

int64_t floor_div_i64_i64(int64_t a, int64_t b) {
    int64_t q = FLOW_CHECKED_DIV((a), (b));
    int64_t r = FLOW_CHECKED_MOD((a), (b));
    if ((r != 0 && a < 0 != b < 0)) {
        q = (q - 1);
    }
    return q;
}

int64_t ceil_div_i64_i64(int64_t a, int64_t b) {
    return (0 - floor_div_i64_i64((0 - a), b));
}

int64_t egcd_i64_i64_ptr_i64_ptr_i64(int64_t a0, int64_t b0, int64_t* out_x, int64_t* out_y) {
    int64_t a = a0;
    int64_t b = b0;
    int64_t x0 = 1;
    int64_t y0 = 0;
    int64_t x1 = 0;
    int64_t y1 = 1;
    while (b != 0) {
        int64_t q = FLOW_CHECKED_DIV((a), (b));
        int64_t t = (a - (q * b));
        a = b;
        b = t;
        int64_t nx = (x0 - (q * x1));
        x0 = x1;
        x1 = nx;
        int64_t ny = (y0 - (q * y1));
        y0 = y1;
        y1 = ny;
    }
    if (a < 0) {
        a = (0 - a);
        x0 = (0 - x0);
        y0 = (0 - y0);
    }
    out_x[0] = x0;
    out_y[0] = y0;
    return a;
}

void t_bounds_i64_i64_i64_i64_ptr_i64_ptr_i64(int64_t base, int64_t step, int64_t low, int64_t high, int64_t* out_lo, int64_t* out_hi) {
    if (step > 0) {
        out_lo[0] = ceil_div_i64_i64((low - base), step);
        out_hi[0] = floor_div_i64_i64((high - base), step);
    } else {
        out_lo[0] = ceil_div_i64_i64((high - base), step);
        out_hi[0] = floor_div_i64_i64((low - base), step);
    }
}

int64_t count_2d_i64_i64_i64_i64_i64_i64_i64(int64_t A, int64_t B, int64_t C, int64_t Ly, int64_t Ry, int64_t Lz, int64_t Rz) {
    if ((Ly > Ry || Lz > Rz)) {
        return 0;
    }
    if (A == 0) {
        if (B == 0) {
            if (C == 0) {
                return (((Ry - Ly) + 1) * ((Rz - Lz) + 1));
            }
            return 0;
        }
        if (FLOW_CHECKED_MOD((C), (B)) != 0) {
            return 0;
        }
        int64_t z = FLOW_CHECKED_DIV((C), (B));
        if ((Lz <= z && z <= Rz)) {
            return ((Ry - Ly) + 1);
        }
        return 0;
    }
    if (B == 0) {
        if (FLOW_CHECKED_MOD((C), (A)) != 0) {
            return 0;
        }
        int64_t y = FLOW_CHECKED_DIV((C), (A));
        if ((Ly <= y && y <= Ry)) {
            return ((Rz - Lz) + 1);
        }
        return 0;
    }
    int64_t* xy = (int64_t*)(calloc(2, 8));
    int64_t* ox = (int64_t*)(calloc(1, 8));
    int64_t* oy = (int64_t*)(calloc(1, 8));
    int64_t g = egcd_i64_i64_ptr_i64_ptr_i64(A, B, ox, oy);
    xy[0] = ox[0];
    xy[1] = oy[0];
    free(ox);
    free(oy);
    if ((g == 0 || FLOW_CHECKED_MOD((C), (g)) != 0)) {
        free(xy);
        return 0;
    }
    int64_t k = FLOW_CHECKED_DIV((C), (g));
    int64_t y0 = (xy[0] * k);
    int64_t z0 = (xy[1] * k);
    int64_t step_y = FLOW_CHECKED_DIV((B), (g));
    int64_t step_z = (0 - FLOW_CHECKED_DIV((A), (g)));
    int64_t* lohi = (int64_t*)(calloc(4, 8));
    int64_t* o1 = (int64_t*)(calloc(1, 8));
    int64_t* o2 = (int64_t*)(calloc(1, 8));
    int64_t* o3 = (int64_t*)(calloc(1, 8));
    int64_t* o4 = (int64_t*)(calloc(1, 8));
    t_bounds_i64_i64_i64_i64_ptr_i64_ptr_i64(y0, step_y, Ly, Ry, o1, o2);
    t_bounds_i64_i64_i64_i64_ptr_i64_ptr_i64(z0, step_z, Lz, Rz, o3, o4);
    lohi[0] = o1[0];
    lohi[1] = o2[0];
    lohi[2] = o3[0];
    lohi[3] = o4[0];
    free(o1);
    free(o2);
    free(o3);
    free(o4);
    int64_t lo = lohi[0];
    if (lohi[2] > lo) {
        lo = lohi[2];
    }
    int64_t hi = lohi[1];
    if (lohi[3] < hi) {
        hi = lohi[3];
    }
    free(xy);
    free(lohi);
    if (hi < lo) {
        return 0;
    }
    return ((hi - lo) + 1);
}

int64_t count_3d_i64_i64_i64_i64_i64_i64_i64_i64_i64(int64_t a, int64_t b, int64_t c, int64_t Lx, int64_t Rx, int64_t Ly, int64_t Ry, int64_t Lz, int64_t Rz) {
    if (((Lx > Rx || Ly > Ry) || Lz > Rz)) {
        return 0;
    }
    if (((a == 0 && b == 0) && c == 0)) {
        return 0;
    }
    int64_t nnz = 0;
    if (a != 0) {
        nnz = (nnz + 1);
    }
    if (b != 0) {
        nnz = (nnz + 1);
    }
    if (c != 0) {
        nnz = (nnz + 1);
    }
    if (nnz == 1) {
        if (a != 0) {
            if (FLOW_CHECKED_MOD((1), (a)) != 0) {
                return 0;
            }
            int64_t x = FLOW_CHECKED_DIV((1), (a));
            if ((Lx <= x && x <= Rx)) {
                return (((Ry - Ly) + 1) * ((Rz - Lz) + 1));
            }
            return 0;
        }
        if (b != 0) {
            if (FLOW_CHECKED_MOD((1), (b)) != 0) {
                return 0;
            }
            int64_t y = FLOW_CHECKED_DIV((1), (b));
            if ((Ly <= y && y <= Ry)) {
                return (((Rx - Lx) + 1) * ((Rz - Lz) + 1));
            }
            return 0;
        }
        if (FLOW_CHECKED_MOD((1), (c)) != 0) {
            return 0;
        }
        int64_t z = FLOW_CHECKED_DIV((1), (c));
        if ((Lz <= z && z <= Rz)) {
            return (((Rx - Lx) + 1) * ((Ry - Ly) + 1));
        }
        return 0;
    }
    if (nnz == 2) {
        if (a == 0) {
            return (count_2d_i64_i64_i64_i64_i64_i64_i64(b, c, 1, Ly, Ry, Lz, Rz) * ((Rx - Lx) + 1));
        }
        if (b == 0) {
            return (count_2d_i64_i64_i64_i64_i64_i64_i64(a, c, 1, Lx, Rx, Lz, Rz) * ((Ry - Ly) + 1));
        }
        return (count_2d_i64_i64_i64_i64_i64_i64_i64(a, b, 1, Lx, Rx, Ly, Ry) * ((Rz - Lz) + 1));
    }
    int64_t lenx = ((Rx - Lx) + 1);
    int64_t leny = ((Ry - Ly) + 1);
    int64_t lenz = ((Rz - Lz) + 1);
    int64_t total = 0;
    if ((lenx <= leny && lenx <= lenz)) {
        int64_t x = Lx;
        while (x <= Rx) {
            total = (total + count_2d_i64_i64_i64_i64_i64_i64_i64(b, c, (1 - (a * x)), Ly, Ry, Lz, Rz));
            x = (x + 1);
        }
    } else if ((leny <= lenx && leny <= lenz)) {
        int64_t y = Ly;
        while (y <= Ry) {
            total = (total + count_2d_i64_i64_i64_i64_i64_i64_i64(a, c, (1 - (b * y)), Lx, Rx, Lz, Rz));
            y = (y + 1);
        }
    } else {
        int64_t z = Lz;
        while (z <= Rz) {
            total = (total + count_2d_i64_i64_i64_i64_i64_i64_i64(a, b, (1 - (c * z)), Lx, Rx, Ly, Ry));
            z = (z + 1);
        }
    }
    return total;
}

int64_t isqrt_i64(int64_t n) {
    if (n <= 0) {
        return 0;
    }
    int64_t x = n;
    int64_t y = FLOW_CHECKED_DIV(((x + 1)), (2));
    while (y < x) {
        x = y;
        y = FLOW_CHECKED_DIV(((x + FLOW_CHECKED_DIV((n), (x)))), (2));
    }
    return x;
}

int64_t count_rank1_i64(int64_t n) {
    int64_t T = isqrt_i64(n);
    int64_t S = 0;
    int64_t O = 0;
    int64_t a = (0 - T);
    while (a <= T) {
        int64_t b = (0 - T);
        while (b <= T) {
            int64_t c = (0 - T);
            while (c <= T) {
                if ((!(((a == 0 && b == 0) && c == 0)))) {
                    int64_t U = abs64_i64(a);
                    if (abs64_i64(b) > U) {
                        U = abs64_i64(b);
                    }
                    if (abs64_i64(c) > U) {
                        U = abs64_i64(c);
                    }
                    int64_t B = FLOW_CHECKED_DIV((n), (U));
                    S = (S + count_3d_i64_i64_i64_i64_i64_i64_i64_i64_i64(a, b, c, (0 - B), B, (0 - B), B, (0 - B), B));
                    O = (O + count_3d_i64_i64_i64_i64_i64_i64_i64_i64_i64(a, b, c, (0 - T), T, (0 - T), T, (0 - T), T));
                }
                c = (c + 1);
            }
            b = (b + 1);
        }
        a = (a + 1);
    }
    return FLOW_CHECKED_DIV((((2 * S) - O)), (2));
}

void div_interval_i64_i64_i64_ptr_i64_ptr_i64(int64_t low, int64_t high, int64_t coef, int64_t* out_L, int64_t* out_R) {
    if (coef > 0) {
        out_L[0] = ceil_div_i64_i64(low, coef);
        out_R[0] = floor_div_i64_i64(high, coef);
    } else {
        out_L[0] = ceil_div_i64_i64(high, coef);
        out_R[0] = floor_div_i64_i64(low, coef);
    }
}

int64_t count_rank2_i64(int64_t n) {
    int64_t T = isqrt_i64(n);
    int64_t SA = 0;
    int64_t overlap = 0;
    int64_t* tmp = (int64_t*)(calloc(2, 8));
    int64_t a = (0 - T);
    while (a <= T) {
        int64_t b = (0 - T);
        while (b <= T) {
            int64_t c = (0 - T);
            while (c <= T) {
                if ((!(((a == 0 && b == 0) && c == 0)))) {
                    int64_t u0 = a;
                    int64_t u1 = b;
                    int64_t u2 = c;
                    int64_t low = (1 - n);
                    int64_t high = (1 + n);
                    int64_t L0 = 0;
                    int64_t R0 = 0;
                    int64_t L1 = 0;
                    int64_t R1 = 0;
                    int64_t L2 = 0;
                    int64_t R2 = 0;
                    int32_t ok = 1;
                    int64_t j = 0;
                    while (j < 3) {
                        int64_t off = n;
                        int64_t i = 0;
                        while (i < 3) {
                            if (i != j) {
                                int64_t ui = u0;
                                if (i == 1) {
                                    ui = u1;
                                }
                                if (i == 2) {
                                    ui = u2;
                                }
                                if (ui != 0) {
                                    int64_t t = FLOW_CHECKED_DIV((n), (abs64_i64(ui)));
                                    if (t < off) {
                                        off = t;
                                    }
                                }
                            }
                            i = (i + 1);
                        }
                        int64_t L = (0 - off);
                        int64_t R = off;
                        int64_t uj = u0;
                        if (j == 1) {
                            uj = u1;
                        }
                        if (j == 2) {
                            uj = u2;
                        }
                        if (uj != 0) {
                            int64_t* dL = (int64_t*)(calloc(1, 8));
                            int64_t* dR = (int64_t*)(calloc(1, 8));
                            div_interval_i64_i64_i64_ptr_i64_ptr_i64(low, high, uj, dL, dR);
                            tmp[0] = dL[0];
                            tmp[1] = dR[0];
                            free(dL);
                            free(dR);
                            int64_t Ld = tmp[0];
                            int64_t Rd = tmp[1];
                            if (Ld > Rd) {
                                int64_t sw = Ld;
                                Ld = Rd;
                                Rd = sw;
                            }
                            if (Ld > L) {
                                L = Ld;
                            }
                            if (Rd < R) {
                                R = Rd;
                            }
                        }
                        if (j == 0) {
                            L0 = L;
                            R0 = R;
                        }
                        if (j == 1) {
                            L1 = L;
                            R1 = R;
                        }
                        if (j == 2) {
                            L2 = L;
                            R2 = R;
                        }
                        if (L > R) {
                            ok = 0;
                        }
                        j = (j + 1);
                    }
                    if (ok != 0) {
                        SA = (SA + count_3d_i64_i64_i64_i64_i64_i64_i64_i64_i64(a, b, c, L0, R0, L1, R1, L2, R2));
                        int64_t L0b = L0;
                        int64_t R0b = R0;
                        int64_t L1b = L1;
                        int64_t R1b = R1;
                        int64_t L2b = L2;
                        int64_t R2b = R2;
                        if (L0b < (0 - T)) {
                            L0b = (0 - T);
                        }
                        if (R0b > T) {
                            R0b = T;
                        }
                        if (L1b < (0 - T)) {
                            L1b = (0 - T);
                        }
                        if (R1b > T) {
                            R1b = T;
                        }
                        if (L2b < (0 - T)) {
                            L2b = (0 - T);
                        }
                        if (R2b > T) {
                            R2b = T;
                        }
                        if (((L0b <= R0b && L1b <= R1b) && L2b <= R2b)) {
                            overlap = (overlap + count_3d_i64_i64_i64_i64_i64_i64_i64_i64_i64(a, b, c, L0b, R0b, L1b, R1b, L2b, R2b));
                        }
                    }
                }
                c = (c + 1);
            }
            b = (b + 1);
        }
        a = (a + 1);
    }
    free(tmp);
    return FLOW_CHECKED_DIV((((2 * SA) - overlap)), (2));
}

int64_t C_i64(int64_t n) {
    if (n == 0) {
        return 1;
    }
    return ((2 + count_rank1_i64(n)) + count_rank2_i64(n));
}

int32_t main(void) {
    printf("%lld\n", C_i64(200));
    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 @abs64(%arg0: i64) -> i64 {
    %0 = arith.constant 0 : i32
    %2 = arith.extsi %0 : i32 to i64
    %1 = arith.cmpi slt, %arg0, %2 : i64
    cf.cond_br %1, ^bb0, ^bb1
    ^bb0:
      %3 = arith.constant 0 : i32
      %5 = arith.extsi %3 : i32 to i64
      %4 = arith.subi %5, %arg0 : i64
      func.return %4 : i64
    ^bb1:
      cf.br ^bb2
    ^bb2:
    func.return %arg0 : i64
  }
  func.func @floor_div(%arg0: i64, %arg1: i64) -> i64 {
    %6 = arith.divsi %arg0, %arg1 : i64
    %7 = llvm.mlir.constant(1 : i64) : i64
    %8 = llvm.alloca %7 x i64 : (i64) -> !llvm.ptr
    llvm.store %6, %8 : i64, !llvm.ptr
    %9 = arith.remsi %arg0, %arg1 : i64
    %10 = arith.constant 0 : i32
    %12 = arith.extsi %10 : i32 to i64
    %11 = arith.cmpi ne, %9, %12 : i64
    %13 = scf.if %11 -> (i1) {
      %14 = arith.constant 0 : i32
      %16 = arith.extsi %14 : i32 to i64
      %15 = arith.cmpi slt, %arg0, %16 : i64
      %17 = arith.constant 0 : i32
      %19 = arith.extsi %17 : i32 to i64
      %18 = arith.cmpi slt, %arg1, %19 : i64
      %20 = arith.cmpi ne, %15, %18 : i1
      scf.yield %20 : i1
    } else {
      %21 = arith.constant false
      scf.yield %21 : i1
    }
    cf.cond_br %13, ^bb3, ^bb4
    ^bb3:
      %22 = llvm.load %8 : !llvm.ptr -> i64
      %23 = arith.constant 1 : i32
      %25 = arith.extsi %23 : i32 to i64
      %24 = arith.subi %22, %25 : i64
      llvm.store %24, %8 : i64, !llvm.ptr
      cf.br ^bb5
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %26 = llvm.load %8 : !llvm.ptr -> i64
    func.return %26 : i64
  }
  func.func @ceil_div(%arg0: i64, %arg1: i64) -> i64 {
    %27 = arith.constant 0 : i32
    %29 = arith.constant 0 : i32
    %31 = arith.extsi %29 : i32 to i64
    %30 = arith.subi %31, %arg0 : i64
    %28 = func.call @floor_div(%30, %arg1) : (i64, i64) -> i64
    %33 = arith.extsi %27 : i32 to i64
    %32 = arith.subi %33, %28 : i64
    func.return %32 : i64
  }
  func.func @egcd(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr, %arg3: !llvm.ptr) -> i64 {
    %34 = llvm.mlir.constant(1 : i64) : i64
    %35 = llvm.alloca %34 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %35 : i64, !llvm.ptr
    %36 = llvm.mlir.constant(1 : i64) : i64
    %37 = llvm.alloca %36 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %37 : i64, !llvm.ptr
    %38 = arith.constant 1 : i32
    %39 = arith.extsi %38 : i32 to i64
    %40 = llvm.mlir.constant(1 : i64) : i64
    %41 = llvm.alloca %40 x i64 : (i64) -> !llvm.ptr
    llvm.store %39, %41 : i64, !llvm.ptr
    %42 = arith.constant 0 : i32
    %43 = arith.extsi %42 : i32 to i64
    %44 = llvm.mlir.constant(1 : i64) : i64
    %45 = llvm.alloca %44 x i64 : (i64) -> !llvm.ptr
    llvm.store %43, %45 : i64, !llvm.ptr
    %46 = arith.constant 0 : i32
    %47 = arith.extsi %46 : i32 to i64
    %48 = llvm.mlir.constant(1 : i64) : i64
    %49 = llvm.alloca %48 x i64 : (i64) -> !llvm.ptr
    llvm.store %47, %49 : i64, !llvm.ptr
    %50 = arith.constant 1 : i32
    %51 = arith.extsi %50 : i32 to i64
    %52 = llvm.mlir.constant(1 : i64) : i64
    %53 = llvm.alloca %52 x i64 : (i64) -> !llvm.ptr
    llvm.store %51, %53 : i64, !llvm.ptr
    cf.br ^bb6
    ^bb6:
    %54 = llvm.load %37 : !llvm.ptr -> i64
    %55 = arith.constant 0 : i32
    %57 = arith.extsi %55 : i32 to i64
    %56 = arith.cmpi ne, %54, %57 : i64
    cf.cond_br %56, ^bb7, ^bb8
    ^bb7:
      %58 = llvm.load %35 : !llvm.ptr -> i64
      %59 = llvm.load %37 : !llvm.ptr -> i64
      %60 = arith.divsi %58, %59 : i64
      %61 = llvm.load %35 : !llvm.ptr -> i64
      %62 = llvm.load %37 : !llvm.ptr -> i64
      %63 = arith.muli %60, %62 : i64
      %64 = arith.subi %61, %63 : i64
      %65 = llvm.load %37 : !llvm.ptr -> i64
      llvm.store %65, %35 : i64, !llvm.ptr
      llvm.store %64, %37 : i64, !llvm.ptr
      %66 = llvm.load %41 : !llvm.ptr -> i64
      %67 = llvm.load %49 : !llvm.ptr -> i64
      %68 = arith.muli %60, %67 : i64
      %69 = arith.subi %66, %68 : i64
      %70 = llvm.load %49 : !llvm.ptr -> i64
      llvm.store %70, %41 : i64, !llvm.ptr
      llvm.store %69, %49 : i64, !llvm.ptr
      %71 = llvm.load %45 : !llvm.ptr -> i64
      %72 = llvm.load %53 : !llvm.ptr -> i64
      %73 = arith.muli %60, %72 : i64
      %74 = arith.subi %71, %73 : i64
      %75 = llvm.load %53 : !llvm.ptr -> i64
      llvm.store %75, %45 : i64, !llvm.ptr
      llvm.store %74, %53 : i64, !llvm.ptr
      cf.br ^bb6
    ^bb8:
    %76 = llvm.load %35 : !llvm.ptr -> i64
    %77 = arith.constant 0 : i32
    %79 = arith.extsi %77 : i32 to i64
    %78 = arith.cmpi slt, %76, %79 : i64
    cf.cond_br %78, ^bb9, ^bb10
    ^bb9:
      %80 = arith.constant 0 : i32
      %81 = llvm.load %35 : !llvm.ptr -> i64
      %83 = arith.extsi %80 : i32 to i64
      %82 = arith.subi %83, %81 : i64
      llvm.store %82, %35 : i64, !llvm.ptr
      %84 = arith.constant 0 : i32
      %85 = llvm.load %41 : !llvm.ptr -> i64
      %87 = arith.extsi %84 : i32 to i64
      %86 = arith.subi %87, %85 : i64
      llvm.store %86, %41 : i64, !llvm.ptr
      %88 = arith.constant 0 : i32
      %89 = llvm.load %45 : !llvm.ptr -> i64
      %91 = arith.extsi %88 : i32 to i64
      %90 = arith.subi %91, %89 : i64
      llvm.store %90, %45 : i64, !llvm.ptr
      cf.br ^bb11
    ^bb10:
      cf.br ^bb11
    ^bb11:
    %92 = llvm.load %41 : !llvm.ptr -> i64
    %93 = arith.constant 0 : i32
    %94 = arith.extsi %93 : i32 to i64
    %95 = llvm.getelementptr %arg2[%94] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %92, %95 : i64, !llvm.ptr
    %96 = llvm.load %45 : !llvm.ptr -> i64
    %97 = arith.constant 0 : i32
    %98 = arith.extsi %97 : i32 to i64
    %99 = llvm.getelementptr %arg3[%98] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %96, %99 : i64, !llvm.ptr
    %100 = llvm.load %35 : !llvm.ptr -> i64
    func.return %100 : i64
  }
  func.func @t_bounds(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: !llvm.ptr, %arg5: !llvm.ptr) -> () {
    %101 = arith.constant 0 : i32
    %103 = arith.extsi %101 : i32 to i64
    %102 = arith.cmpi sgt, %arg1, %103 : i64
    cf.cond_br %102, ^bb12, ^bb13
    ^bb12:
      %105 = arith.subi %arg2, %arg0 : i64
      %104 = func.call @ceil_div(%105, %arg1) : (i64, i64) -> i64
      %106 = arith.constant 0 : i32
      %107 = arith.extsi %106 : i32 to i64
      %108 = llvm.getelementptr %arg4[%107] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %104, %108 : i64, !llvm.ptr
      %110 = arith.subi %arg3, %arg0 : i64
      %109 = func.call @floor_div(%110, %arg1) : (i64, i64) -> i64
      %111 = arith.constant 0 : i32
      %112 = arith.extsi %111 : i32 to i64
      %113 = llvm.getelementptr %arg5[%112] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %109, %113 : i64, !llvm.ptr
      cf.br ^bb14
    ^bb13:
      %115 = arith.subi %arg3, %arg0 : i64
      %114 = func.call @ceil_div(%115, %arg1) : (i64, i64) -> i64
      %116 = arith.constant 0 : i32
      %117 = arith.extsi %116 : i32 to i64
      %118 = llvm.getelementptr %arg4[%117] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %114, %118 : i64, !llvm.ptr
      %120 = arith.subi %arg2, %arg0 : i64
      %119 = func.call @floor_div(%120, %arg1) : (i64, i64) -> i64
      %121 = arith.constant 0 : i32
      %122 = arith.extsi %121 : i32 to i64
      %123 = llvm.getelementptr %arg5[%122] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %119, %123 : i64, !llvm.ptr
      cf.br ^bb14
    ^bb14:
    func.return
  }
  func.func @count_2d(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: i64, %arg5: i64, %arg6: i64) -> i64 {
    %124 = arith.cmpi sgt, %arg3, %arg4 : i64
    %125 = scf.if %124 -> (i1) {
      %126 = arith.constant true
      scf.yield %126 : i1
    } else {
      %127 = arith.cmpi sgt, %arg5, %arg6 : i64
      scf.yield %127 : i1
    }
    cf.cond_br %125, ^bb15, ^bb16
    ^bb15:
      %128 = arith.constant 0 : i32
      %129 = arith.extsi %128 : i32 to i64
      func.return %129 : i64
    ^bb16:
      cf.br ^bb17
    ^bb17:
    %130 = arith.constant 0 : i32
    %132 = arith.extsi %130 : i32 to i64
    %131 = arith.cmpi eq, %arg0, %132 : i64
    cf.cond_br %131, ^bb18, ^bb19
    ^bb18:
      %133 = arith.constant 0 : i32
      %135 = arith.extsi %133 : i32 to i64
      %134 = arith.cmpi eq, %arg1, %135 : i64
      cf.cond_br %134, ^bb21, ^bb22
      ^bb21:
        %136 = arith.constant 0 : i32
        %138 = arith.extsi %136 : i32 to i64
        %137 = arith.cmpi eq, %arg2, %138 : i64
        cf.cond_br %137, ^bb24, ^bb25
        ^bb24:
          %139 = arith.subi %arg4, %arg3 : i64
          %140 = arith.constant 1 : i32
          %142 = arith.extsi %140 : i32 to i64
          %141 = arith.addi %139, %142 : i64
          %143 = arith.subi %arg6, %arg5 : i64
          %144 = arith.constant 1 : i32
          %146 = arith.extsi %144 : i32 to i64
          %145 = arith.addi %143, %146 : i64
          %147 = arith.muli %141, %145 : i64
          func.return %147 : i64
        ^bb25:
          cf.br ^bb26
        ^bb26:
        %148 = arith.constant 0 : i32
        %149 = arith.extsi %148 : i32 to i64
        func.return %149 : i64
      ^bb22:
        cf.br ^bb23
      ^bb23:
      %150 = arith.remsi %arg2, %arg1 : i64
      %151 = arith.constant 0 : i32
      %153 = arith.extsi %151 : i32 to i64
      %152 = arith.cmpi ne, %150, %153 : i64
      cf.cond_br %152, ^bb27, ^bb28
      ^bb27:
        %154 = arith.constant 0 : i32
        %155 = arith.extsi %154 : i32 to i64
        func.return %155 : i64
      ^bb28:
        cf.br ^bb29
      ^bb29:
      %156 = arith.divsi %arg2, %arg1 : i64
      %157 = arith.cmpi sle, %arg5, %156 : i64
      %158 = scf.if %157 -> (i1) {
        %159 = arith.cmpi sle, %156, %arg6 : i64
        scf.yield %159 : i1
      } else {
        %160 = arith.constant false
        scf.yield %160 : i1
      }
      cf.cond_br %158, ^bb30, ^bb31
      ^bb30:
        %161 = arith.subi %arg4, %arg3 : i64
        %162 = arith.constant 1 : i32
        %164 = arith.extsi %162 : i32 to i64
        %163 = arith.addi %161, %164 : i64
        func.return %163 : i64
      ^bb31:
        cf.br ^bb32
      ^bb32:
      %165 = arith.constant 0 : i32
      %166 = arith.extsi %165 : i32 to i64
      func.return %166 : i64
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %167 = arith.constant 0 : i32
    %169 = arith.extsi %167 : i32 to i64
    %168 = arith.cmpi eq, %arg1, %169 : i64
    cf.cond_br %168, ^bb33, ^bb34
    ^bb33:
      %170 = arith.remsi %arg2, %arg0 : i64
      %171 = arith.constant 0 : i32
      %173 = arith.extsi %171 : i32 to i64
      %172 = arith.cmpi ne, %170, %173 : i64
      cf.cond_br %172, ^bb36, ^bb37
      ^bb36:
        %174 = arith.constant 0 : i32
        %175 = arith.extsi %174 : i32 to i64
        func.return %175 : i64
      ^bb37:
        cf.br ^bb38
      ^bb38:
      %176 = arith.divsi %arg2, %arg0 : i64
      %177 = arith.cmpi sle, %arg3, %176 : i64
      %178 = scf.if %177 -> (i1) {
        %179 = arith.cmpi sle, %176, %arg4 : i64
        scf.yield %179 : i1
      } else {
        %180 = arith.constant false
        scf.yield %180 : i1
      }
      cf.cond_br %178, ^bb39, ^bb40
      ^bb39:
        %181 = arith.subi %arg6, %arg5 : i64
        %182 = arith.constant 1 : i32
        %184 = arith.extsi %182 : i32 to i64
        %183 = arith.addi %181, %184 : i64
        func.return %183 : i64
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %185 = arith.constant 0 : i32
      %186 = arith.extsi %185 : i32 to i64
      func.return %186 : i64
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %188 = arith.constant 2 : i32
    %189 = arith.constant 8 : i32
    %190 = arith.extsi %188 : i32 to i64
    %191 = arith.extsi %189 : i32 to i64
    %187 = func.call @calloc(%190, %191) : (i64, i64) -> !llvm.ptr
    %193 = arith.constant 1 : i32
    %194 = arith.constant 8 : i32
    %195 = arith.extsi %193 : i32 to i64
    %196 = arith.extsi %194 : i32 to i64
    %192 = func.call @calloc(%195, %196) : (i64, i64) -> !llvm.ptr
    %198 = arith.constant 1 : i32
    %199 = arith.constant 8 : i32
    %200 = arith.extsi %198 : i32 to i64
    %201 = arith.extsi %199 : i32 to i64
    %197 = func.call @calloc(%200, %201) : (i64, i64) -> !llvm.ptr
    %202 = func.call @egcd(%arg0, %arg1, %192, %197) : (i64, i64, !llvm.ptr, !llvm.ptr) -> i64
    %204 = arith.constant 0 : i32
    %205 = arith.extsi %204 : i32 to i64
    %206 = llvm.getelementptr %192[%205] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %203 = llvm.load %206 : !llvm.ptr -> i64
    %207 = arith.constant 0 : i32
    %208 = arith.extsi %207 : i32 to i64
    %209 = llvm.getelementptr %187[%208] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %203, %209 : i64, !llvm.ptr
    %211 = arith.constant 0 : i32
    %212 = arith.extsi %211 : i32 to i64
    %213 = llvm.getelementptr %197[%212] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %210 = llvm.load %213 : !llvm.ptr -> i64
    %214 = arith.constant 1 : i32
    %215 = arith.extsi %214 : i32 to i64
    %216 = llvm.getelementptr %187[%215] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %210, %216 : i64, !llvm.ptr
    func.call @free(%192) : (!llvm.ptr) -> ()
    func.call @free(%197) : (!llvm.ptr) -> ()
    %219 = arith.constant 0 : i32
    %221 = arith.extsi %219 : i32 to i64
    %220 = arith.cmpi eq, %202, %221 : i64
    %222 = scf.if %220 -> (i1) {
      %223 = arith.constant true
      scf.yield %223 : i1
    } else {
      %224 = arith.remsi %arg2, %202 : i64
      %225 = arith.constant 0 : i32
      %227 = arith.extsi %225 : i32 to i64
      %226 = arith.cmpi ne, %224, %227 : i64
      scf.yield %226 : i1
    }
    cf.cond_br %222, ^bb42, ^bb43
    ^bb42:
      func.call @free(%187) : (!llvm.ptr) -> ()
      %229 = arith.constant 0 : i32
      %230 = arith.extsi %229 : i32 to i64
      func.return %230 : i64
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %231 = arith.divsi %arg2, %202 : i64
    %233 = arith.constant 0 : i32
    %234 = arith.extsi %233 : i32 to i64
    %235 = llvm.getelementptr %187[%234] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %232 = llvm.load %235 : !llvm.ptr -> i64
    %236 = arith.muli %232, %231 : i64
    %238 = arith.constant 1 : i32
    %239 = arith.extsi %238 : i32 to i64
    %240 = llvm.getelementptr %187[%239] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %237 = llvm.load %240 : !llvm.ptr -> i64
    %241 = arith.muli %237, %231 : i64
    %242 = arith.divsi %arg1, %202 : i64
    %243 = arith.constant 0 : i32
    %244 = arith.divsi %arg0, %202 : i64
    %246 = arith.extsi %243 : i32 to i64
    %245 = arith.subi %246, %244 : i64
    %248 = arith.constant 4 : i32
    %249 = arith.constant 8 : i32
    %250 = arith.extsi %248 : i32 to i64
    %251 = arith.extsi %249 : i32 to i64
    %247 = func.call @calloc(%250, %251) : (i64, i64) -> !llvm.ptr
    %253 = arith.constant 1 : i32
    %254 = arith.constant 8 : i32
    %255 = arith.extsi %253 : i32 to i64
    %256 = arith.extsi %254 : i32 to i64
    %252 = func.call @calloc(%255, %256) : (i64, i64) -> !llvm.ptr
    %258 = arith.constant 1 : i32
    %259 = arith.constant 8 : i32
    %260 = arith.extsi %258 : i32 to i64
    %261 = arith.extsi %259 : i32 to i64
    %257 = func.call @calloc(%260, %261) : (i64, i64) -> !llvm.ptr
    %263 = arith.constant 1 : i32
    %264 = arith.constant 8 : i32
    %265 = arith.extsi %263 : i32 to i64
    %266 = arith.extsi %264 : i32 to i64
    %262 = func.call @calloc(%265, %266) : (i64, i64) -> !llvm.ptr
    %268 = arith.constant 1 : i32
    %269 = arith.constant 8 : i32
    %270 = arith.extsi %268 : i32 to i64
    %271 = arith.extsi %269 : i32 to i64
    %267 = func.call @calloc(%270, %271) : (i64, i64) -> !llvm.ptr
    func.call @t_bounds(%236, %242, %arg3, %arg4, %252, %257) : (i64, i64, i64, i64, !llvm.ptr, !llvm.ptr) -> ()
    func.call @t_bounds(%241, %245, %arg5, %arg6, %262, %267) : (i64, i64, i64, i64, !llvm.ptr, !llvm.ptr) -> ()
    %275 = arith.constant 0 : i32
    %276 = arith.extsi %275 : i32 to i64
    %277 = llvm.getelementptr %252[%276] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %274 = llvm.load %277 : !llvm.ptr -> i64
    %278 = arith.constant 0 : i32
    %279 = arith.extsi %278 : i32 to i64
    %280 = llvm.getelementptr %247[%279] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %274, %280 : i64, !llvm.ptr
    %282 = arith.constant 0 : i32
    %283 = arith.extsi %282 : i32 to i64
    %284 = llvm.getelementptr %257[%283] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %281 = llvm.load %284 : !llvm.ptr -> i64
    %285 = arith.constant 1 : i32
    %286 = arith.extsi %285 : i32 to i64
    %287 = llvm.getelementptr %247[%286] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %281, %287 : i64, !llvm.ptr
    %289 = arith.constant 0 : i32
    %290 = arith.extsi %289 : i32 to i64
    %291 = llvm.getelementptr %262[%290] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %288 = llvm.load %291 : !llvm.ptr -> i64
    %292 = arith.constant 2 : i32
    %293 = arith.extsi %292 : i32 to i64
    %294 = llvm.getelementptr %247[%293] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %288, %294 : i64, !llvm.ptr
    %296 = arith.constant 0 : i32
    %297 = arith.extsi %296 : i32 to i64
    %298 = llvm.getelementptr %267[%297] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %295 = llvm.load %298 : !llvm.ptr -> i64
    %299 = arith.constant 3 : i32
    %300 = arith.extsi %299 : i32 to i64
    %301 = llvm.getelementptr %247[%300] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %295, %301 : i64, !llvm.ptr
    func.call @free(%252) : (!llvm.ptr) -> ()
    func.call @free(%257) : (!llvm.ptr) -> ()
    func.call @free(%262) : (!llvm.ptr) -> ()
    func.call @free(%267) : (!llvm.ptr) -> ()
    %307 = arith.constant 0 : i32
    %308 = arith.extsi %307 : i32 to i64
    %309 = llvm.getelementptr %247[%308] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %306 = llvm.load %309 : !llvm.ptr -> i64
    %311 = arith.constant 2 : i32
    %312 = arith.extsi %311 : i32 to i64
    %313 = llvm.getelementptr %247[%312] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %310 = llvm.load %313 : !llvm.ptr -> i64
    %314 = arith.cmpi sgt, %310, %306 : i64
    %315 = scf.if %314 -> (i64) {
      %317 = arith.constant 2 : i32
      %318 = arith.extsi %317 : i32 to i64
      %319 = llvm.getelementptr %247[%318] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %316 = llvm.load %319 : !llvm.ptr -> i64
      scf.yield %316 : i64
    } else {
      scf.yield %306 : i64
    }
    %321 = arith.constant 1 : i32
    %322 = arith.extsi %321 : i32 to i64
    %323 = llvm.getelementptr %247[%322] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %320 = llvm.load %323 : !llvm.ptr -> i64
    %325 = arith.constant 3 : i32
    %326 = arith.extsi %325 : i32 to i64
    %327 = llvm.getelementptr %247[%326] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %324 = llvm.load %327 : !llvm.ptr -> i64
    %328 = arith.cmpi slt, %324, %320 : i64
    %329 = scf.if %328 -> (i64) {
      %331 = arith.constant 3 : i32
      %332 = arith.extsi %331 : i32 to i64
      %333 = llvm.getelementptr %247[%332] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %330 = llvm.load %333 : !llvm.ptr -> i64
      scf.yield %330 : i64
    } else {
      scf.yield %320 : i64
    }
    func.call @free(%187) : (!llvm.ptr) -> ()
    func.call @free(%247) : (!llvm.ptr) -> ()
    %336 = arith.cmpi slt, %329, %315 : i64
    cf.cond_br %336, ^bb45, ^bb46
    ^bb45:
      %337 = arith.constant 0 : i32
      %338 = arith.extsi %337 : i32 to i64
      func.return %338 : i64
    ^bb46:
      cf.br ^bb47
    ^bb47:
    %339 = arith.subi %329, %315 : i64
    %340 = arith.constant 1 : i32
    %342 = arith.extsi %340 : i32 to i64
    %341 = arith.addi %339, %342 : i64
    func.return %341 : i64
  }
  func.func @count_3d(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: i64, %arg5: i64, %arg6: i64, %arg7: i64, %arg8: i64) -> i64 {
    %343 = arith.cmpi sgt, %arg3, %arg4 : i64
    %344 = scf.if %343 -> (i1) {
      %345 = arith.constant true
      scf.yield %345 : i1
    } else {
      %346 = arith.cmpi sgt, %arg5, %arg6 : i64
      scf.yield %346 : i1
    }
    %347 = scf.if %344 -> (i1) {
      %348 = arith.constant true
      scf.yield %348 : i1
    } else {
      %349 = arith.cmpi sgt, %arg7, %arg8 : i64
      scf.yield %349 : i1
    }
    cf.cond_br %347, ^bb48, ^bb49
    ^bb48:
      %350 = arith.constant 0 : i32
      %351 = arith.extsi %350 : i32 to i64
      func.return %351 : i64
    ^bb49:
      cf.br ^bb50
    ^bb50:
    %352 = arith.constant 0 : i32
    %354 = arith.extsi %352 : i32 to i64
    %353 = arith.cmpi eq, %arg0, %354 : i64
    %355 = scf.if %353 -> (i1) {
      %356 = arith.constant 0 : i32
      %358 = arith.extsi %356 : i32 to i64
      %357 = arith.cmpi eq, %arg1, %358 : i64
      scf.yield %357 : i1
    } else {
      %359 = arith.constant false
      scf.yield %359 : i1
    }
    %360 = scf.if %355 -> (i1) {
      %361 = arith.constant 0 : i32
      %363 = arith.extsi %361 : i32 to i64
      %362 = arith.cmpi eq, %arg2, %363 : i64
      scf.yield %362 : i1
    } else {
      %364 = arith.constant false
      scf.yield %364 : i1
    }
    cf.cond_br %360, ^bb51, ^bb52
    ^bb51:
      %365 = arith.constant 0 : i32
      %366 = arith.extsi %365 : i32 to i64
      func.return %366 : i64
    ^bb52:
      cf.br ^bb53
    ^bb53:
    %367 = arith.constant 0 : i32
    %368 = arith.extsi %367 : i32 to i64
    %369 = arith.constant 0 : i32
    %371 = arith.extsi %369 : i32 to i64
    %370 = arith.cmpi ne, %arg0, %371 : i64
    %372 = scf.if %370 -> (i64) {
      %373 = arith.constant 1 : i32
      %375 = arith.extsi %373 : i32 to i64
      %374 = arith.addi %368, %375 : i64
      scf.yield %374 : i64
    } else {
      scf.yield %368 : i64
    }
    %376 = arith.constant 0 : i32
    %378 = arith.extsi %376 : i32 to i64
    %377 = arith.cmpi ne, %arg1, %378 : i64
    %379 = scf.if %377 -> (i64) {
      %380 = arith.constant 1 : i32
      %382 = arith.extsi %380 : i32 to i64
      %381 = arith.addi %372, %382 : i64
      scf.yield %381 : i64
    } else {
      scf.yield %372 : i64
    }
    %383 = arith.constant 0 : i32
    %385 = arith.extsi %383 : i32 to i64
    %384 = arith.cmpi ne, %arg2, %385 : i64
    %386 = scf.if %384 -> (i64) {
      %387 = arith.constant 1 : i32
      %389 = arith.extsi %387 : i32 to i64
      %388 = arith.addi %379, %389 : i64
      scf.yield %388 : i64
    } else {
      scf.yield %379 : i64
    }
    %390 = arith.constant 1 : i32
    %392 = arith.extsi %390 : i32 to i64
    %391 = arith.cmpi eq, %386, %392 : i64
    cf.cond_br %391, ^bb54, ^bb55
    ^bb54:
      %393 = arith.constant 0 : i32
      %395 = arith.extsi %393 : i32 to i64
      %394 = arith.cmpi ne, %arg0, %395 : i64
      cf.cond_br %394, ^bb57, ^bb58
      ^bb57:
        %396 = arith.constant 1 : i32
        %398 = arith.extsi %396 : i32 to i64
        %397 = arith.remsi %398, %arg0 : i64
        %399 = arith.constant 0 : i32
        %401 = arith.extsi %399 : i32 to i64
        %400 = arith.cmpi ne, %397, %401 : i64
        cf.cond_br %400, ^bb60, ^bb61
        ^bb60:
          %402 = arith.constant 0 : i32
          %403 = arith.extsi %402 : i32 to i64
          func.return %403 : i64
        ^bb61:
          cf.br ^bb62
        ^bb62:
        %404 = arith.constant 1 : i32
        %406 = arith.extsi %404 : i32 to i64
        %405 = arith.divsi %406, %arg0 : i64
        %407 = arith.cmpi sle, %arg3, %405 : i64
        %408 = scf.if %407 -> (i1) {
          %409 = arith.cmpi sle, %405, %arg4 : i64
          scf.yield %409 : i1
        } else {
          %410 = arith.constant false
          scf.yield %410 : i1
        }
        cf.cond_br %408, ^bb63, ^bb64
        ^bb63:
          %411 = arith.subi %arg6, %arg5 : i64
          %412 = arith.constant 1 : i32
          %414 = arith.extsi %412 : i32 to i64
          %413 = arith.addi %411, %414 : i64
          %415 = arith.subi %arg8, %arg7 : i64
          %416 = arith.constant 1 : i32
          %418 = arith.extsi %416 : i32 to i64
          %417 = arith.addi %415, %418 : i64
          %419 = arith.muli %413, %417 : i64
          func.return %419 : i64
        ^bb64:
          cf.br ^bb65
        ^bb65:
        %420 = arith.constant 0 : i32
        %421 = arith.extsi %420 : i32 to i64
        func.return %421 : i64
      ^bb58:
        cf.br ^bb59
      ^bb59:
      %422 = arith.constant 0 : i32
      %424 = arith.extsi %422 : i32 to i64
      %423 = arith.cmpi ne, %arg1, %424 : i64
      cf.cond_br %423, ^bb66, ^bb67
      ^bb66:
        %425 = arith.constant 1 : i32
        %427 = arith.extsi %425 : i32 to i64
        %426 = arith.remsi %427, %arg1 : i64
        %428 = arith.constant 0 : i32
        %430 = arith.extsi %428 : i32 to i64
        %429 = arith.cmpi ne, %426, %430 : i64
        cf.cond_br %429, ^bb69, ^bb70
        ^bb69:
          %431 = arith.constant 0 : i32
          %432 = arith.extsi %431 : i32 to i64
          func.return %432 : i64
        ^bb70:
          cf.br ^bb71
        ^bb71:
        %433 = arith.constant 1 : i32
        %435 = arith.extsi %433 : i32 to i64
        %434 = arith.divsi %435, %arg1 : i64
        %436 = arith.cmpi sle, %arg5, %434 : i64
        %437 = scf.if %436 -> (i1) {
          %438 = arith.cmpi sle, %434, %arg6 : i64
          scf.yield %438 : i1
        } else {
          %439 = arith.constant false
          scf.yield %439 : i1
        }
        cf.cond_br %437, ^bb72, ^bb73
        ^bb72:
          %440 = arith.subi %arg4, %arg3 : i64
          %441 = arith.constant 1 : i32
          %443 = arith.extsi %441 : i32 to i64
          %442 = arith.addi %440, %443 : i64
          %444 = arith.subi %arg8, %arg7 : i64
          %445 = arith.constant 1 : i32
          %447 = arith.extsi %445 : i32 to i64
          %446 = arith.addi %444, %447 : i64
          %448 = arith.muli %442, %446 : i64
          func.return %448 : i64
        ^bb73:
          cf.br ^bb74
        ^bb74:
        %449 = arith.constant 0 : i32
        %450 = arith.extsi %449 : i32 to i64
        func.return %450 : i64
      ^bb67:
        cf.br ^bb68
      ^bb68:
      %451 = arith.constant 1 : i32
      %453 = arith.extsi %451 : i32 to i64
      %452 = arith.remsi %453, %arg2 : i64
      %454 = arith.constant 0 : i32
      %456 = arith.extsi %454 : i32 to i64
      %455 = arith.cmpi ne, %452, %456 : i64
      cf.cond_br %455, ^bb75, ^bb76
      ^bb75:
        %457 = arith.constant 0 : i32
        %458 = arith.extsi %457 : i32 to i64
        func.return %458 : i64
      ^bb76:
        cf.br ^bb77
      ^bb77:
      %459 = arith.constant 1 : i32
      %461 = arith.extsi %459 : i32 to i64
      %460 = arith.divsi %461, %arg2 : i64
      %462 = arith.cmpi sle, %arg7, %460 : i64
      %463 = scf.if %462 -> (i1) {
        %464 = arith.cmpi sle, %460, %arg8 : i64
        scf.yield %464 : i1
      } else {
        %465 = arith.constant false
        scf.yield %465 : i1
      }
      cf.cond_br %463, ^bb78, ^bb79
      ^bb78:
        %466 = arith.subi %arg4, %arg3 : i64
        %467 = arith.constant 1 : i32
        %469 = arith.extsi %467 : i32 to i64
        %468 = arith.addi %466, %469 : i64
        %470 = arith.subi %arg6, %arg5 : i64
        %471 = arith.constant 1 : i32
        %473 = arith.extsi %471 : i32 to i64
        %472 = arith.addi %470, %473 : i64
        %474 = arith.muli %468, %472 : i64
        func.return %474 : i64
      ^bb79:
        cf.br ^bb80
      ^bb80:
      %475 = arith.constant 0 : i32
      %476 = arith.extsi %475 : i32 to i64
      func.return %476 : i64
    ^bb55:
      cf.br ^bb56
    ^bb56:
    %477 = arith.constant 2 : i32
    %479 = arith.extsi %477 : i32 to i64
    %478 = arith.cmpi eq, %386, %479 : i64
    cf.cond_br %478, ^bb81, ^bb82
    ^bb81:
      %480 = arith.constant 0 : i32
      %482 = arith.extsi %480 : i32 to i64
      %481 = arith.cmpi eq, %arg0, %482 : i64
      cf.cond_br %481, ^bb84, ^bb85
      ^bb84:
        %484 = arith.constant 1 : i32
        %485 = arith.extsi %484 : i32 to i64
        %483 = func.call @count_2d(%arg1, %arg2, %485, %arg5, %arg6, %arg7, %arg8) : (i64, i64, i64, i64, i64, i64, i64) -> i64
        %486 = arith.subi %arg4, %arg3 : i64
        %487 = arith.constant 1 : i32
        %489 = arith.extsi %487 : i32 to i64
        %488 = arith.addi %486, %489 : i64
        %490 = arith.muli %483, %488 : i64
        func.return %490 : i64
      ^bb85:
        cf.br ^bb86
      ^bb86:
      %491 = arith.constant 0 : i32
      %493 = arith.extsi %491 : i32 to i64
      %492 = arith.cmpi eq, %arg1, %493 : i64
      cf.cond_br %492, ^bb87, ^bb88
      ^bb87:
        %495 = arith.constant 1 : i32
        %496 = arith.extsi %495 : i32 to i64
        %494 = func.call @count_2d(%arg0, %arg2, %496, %arg3, %arg4, %arg7, %arg8) : (i64, i64, i64, i64, i64, i64, i64) -> i64
        %497 = arith.subi %arg6, %arg5 : i64
        %498 = arith.constant 1 : i32
        %500 = arith.extsi %498 : i32 to i64
        %499 = arith.addi %497, %500 : i64
        %501 = arith.muli %494, %499 : i64
        func.return %501 : i64
      ^bb88:
        cf.br ^bb89
      ^bb89:
      %503 = arith.constant 1 : i32
      %504 = arith.extsi %503 : i32 to i64
      %502 = func.call @count_2d(%arg0, %arg1, %504, %arg3, %arg4, %arg5, %arg6) : (i64, i64, i64, i64, i64, i64, i64) -> i64
      %505 = arith.subi %arg8, %arg7 : i64
      %506 = arith.constant 1 : i32
      %508 = arith.extsi %506 : i32 to i64
      %507 = arith.addi %505, %508 : i64
      %509 = arith.muli %502, %507 : i64
      func.return %509 : i64
    ^bb82:
      cf.br ^bb83
    ^bb83:
    %510 = arith.subi %arg4, %arg3 : i64
    %511 = arith.constant 1 : i32
    %513 = arith.extsi %511 : i32 to i64
    %512 = arith.addi %510, %513 : i64
    %514 = arith.subi %arg6, %arg5 : i64
    %515 = arith.constant 1 : i32
    %517 = arith.extsi %515 : i32 to i64
    %516 = arith.addi %514, %517 : i64
    %518 = arith.subi %arg8, %arg7 : i64
    %519 = arith.constant 1 : i32
    %521 = arith.extsi %519 : i32 to i64
    %520 = arith.addi %518, %521 : i64
    %522 = arith.constant 0 : i32
    %523 = arith.extsi %522 : i32 to i64
    %524 = llvm.mlir.constant(1 : i64) : i64
    %525 = llvm.alloca %524 x i64 : (i64) -> !llvm.ptr
    llvm.store %523, %525 : i64, !llvm.ptr
    %526 = arith.cmpi sle, %512, %516 : i64
    %527 = scf.if %526 -> (i1) {
      %528 = arith.cmpi sle, %512, %520 : i64
      scf.yield %528 : i1
    } else {
      %529 = arith.constant false
      scf.yield %529 : i1
    }
    cf.cond_br %527, ^bb90, ^bb91
    ^bb90:
      %530 = llvm.mlir.constant(1 : i64) : i64
      %531 = llvm.alloca %530 x i64 : (i64) -> !llvm.ptr
      llvm.store %arg3, %531 : i64, !llvm.ptr
      cf.br ^bb93
      ^bb93:
      %532 = llvm.load %531 : !llvm.ptr -> i64
      %533 = arith.cmpi sle, %532, %arg4 : i64
      cf.cond_br %533, ^bb94, ^bb95
      ^bb94:
        %534 = llvm.load %525 : !llvm.ptr -> i64
        %536 = arith.constant 1 : i32
        %537 = llvm.load %531 : !llvm.ptr -> i64
        %538 = arith.muli %arg0, %537 : i64
        %540 = arith.extsi %536 : i32 to i64
        %539 = arith.subi %540, %538 : i64
        %535 = func.call @count_2d(%arg1, %arg2, %539, %arg5, %arg6, %arg7, %arg8) : (i64, i64, i64, i64, i64, i64, i64) -> i64
        %541 = arith.addi %534, %535 : i64
        llvm.store %541, %525 : i64, !llvm.ptr
        %542 = llvm.load %531 : !llvm.ptr -> i64
        %543 = arith.constant 1 : i32
        %545 = arith.extsi %543 : i32 to i64
        %544 = arith.addi %542, %545 : i64
        llvm.store %544, %531 : i64, !llvm.ptr
        cf.br ^bb93
      ^bb95:
      cf.br ^bb92
    ^bb91:
      %546 = arith.cmpi sle, %516, %512 : i64
      %547 = scf.if %546 -> (i1) {
        %548 = arith.cmpi sle, %516, %520 : i64
        scf.yield %548 : i1
      } else {
        %549 = arith.constant false
        scf.yield %549 : i1
      }
      cf.cond_br %547, ^bb97, ^bb96
    ^bb97:
      %550 = llvm.mlir.constant(1 : i64) : i64
      %551 = llvm.alloca %550 x i64 : (i64) -> !llvm.ptr
      llvm.store %arg5, %551 : i64, !llvm.ptr
      cf.br ^bb98
      ^bb98:
      %552 = llvm.load %551 : !llvm.ptr -> i64
      %553 = arith.cmpi sle, %552, %arg6 : i64
      cf.cond_br %553, ^bb99, ^bb100
      ^bb99:
        %554 = llvm.load %525 : !llvm.ptr -> i64
        %556 = arith.constant 1 : i32
        %557 = llvm.load %551 : !llvm.ptr -> i64
        %558 = arith.muli %arg1, %557 : i64
        %560 = arith.extsi %556 : i32 to i64
        %559 = arith.subi %560, %558 : i64
        %555 = func.call @count_2d(%arg0, %arg2, %559, %arg3, %arg4, %arg7, %arg8) : (i64, i64, i64, i64, i64, i64, i64) -> i64
        %561 = arith.addi %554, %555 : i64
        llvm.store %561, %525 : i64, !llvm.ptr
        %562 = llvm.load %551 : !llvm.ptr -> i64
        %563 = arith.constant 1 : i32
        %565 = arith.extsi %563 : i32 to i64
        %564 = arith.addi %562, %565 : i64
        llvm.store %564, %551 : i64, !llvm.ptr
        cf.br ^bb98
      ^bb100:
      cf.br ^bb92
    ^bb96:
      %566 = llvm.mlir.constant(1 : i64) : i64
      %567 = llvm.alloca %566 x i64 : (i64) -> !llvm.ptr
      llvm.store %arg7, %567 : i64, !llvm.ptr
      cf.br ^bb101
      ^bb101:
      %568 = llvm.load %567 : !llvm.ptr -> i64
      %569 = arith.cmpi sle, %568, %arg8 : i64
      cf.cond_br %569, ^bb102, ^bb103
      ^bb102:
        %570 = llvm.load %525 : !llvm.ptr -> i64
        %572 = arith.constant 1 : i32
        %573 = llvm.load %567 : !llvm.ptr -> i64
        %574 = arith.muli %arg2, %573 : i64
        %576 = arith.extsi %572 : i32 to i64
        %575 = arith.subi %576, %574 : i64
        %571 = func.call @count_2d(%arg0, %arg1, %575, %arg3, %arg4, %arg5, %arg6) : (i64, i64, i64, i64, i64, i64, i64) -> i64
        %577 = arith.addi %570, %571 : i64
        llvm.store %577, %525 : i64, !llvm.ptr
        %578 = llvm.load %567 : !llvm.ptr -> i64
        %579 = arith.constant 1 : i32
        %581 = arith.extsi %579 : i32 to i64
        %580 = arith.addi %578, %581 : i64
        llvm.store %580, %567 : i64, !llvm.ptr
        cf.br ^bb101
      ^bb103:
      cf.br ^bb92
    ^bb92:
    %582 = llvm.load %525 : !llvm.ptr -> i64
    func.return %582 : i64
  }
  func.func @isqrt(%arg0: i64) -> i64 {
    %583 = arith.constant 0 : i32
    %585 = arith.extsi %583 : i32 to i64
    %584 = arith.cmpi sle, %arg0, %585 : i64
    cf.cond_br %584, ^bb104, ^bb105
    ^bb104:
      %586 = arith.constant 0 : i32
      %587 = arith.extsi %586 : i32 to i64
      func.return %587 : i64
    ^bb105:
      cf.br ^bb106
    ^bb106:
    %588 = llvm.mlir.constant(1 : i64) : i64
    %589 = llvm.alloca %588 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %589 : i64, !llvm.ptr
    %590 = llvm.load %589 : !llvm.ptr -> i64
    %591 = arith.constant 1 : i32
    %593 = arith.extsi %591 : i32 to i64
    %592 = arith.addi %590, %593 : i64
    %594 = arith.constant 2 : i32
    %596 = arith.extsi %594 : i32 to i64
    %595 = arith.divsi %592, %596 : i64
    %597 = llvm.mlir.constant(1 : i64) : i64
    %598 = llvm.alloca %597 x i64 : (i64) -> !llvm.ptr
    llvm.store %595, %598 : i64, !llvm.ptr
    cf.br ^bb107
    ^bb107:
    %599 = llvm.load %598 : !llvm.ptr -> i64
    %600 = llvm.load %589 : !llvm.ptr -> i64
    %601 = arith.cmpi slt, %599, %600 : i64
    cf.cond_br %601, ^bb108, ^bb109
    ^bb108:
      %602 = llvm.load %598 : !llvm.ptr -> i64
      llvm.store %602, %589 : i64, !llvm.ptr
      %603 = llvm.load %589 : !llvm.ptr -> i64
      %604 = llvm.load %589 : !llvm.ptr -> i64
      %605 = arith.divsi %arg0, %604 : i64
      %606 = arith.addi %603, %605 : i64
      %607 = arith.constant 2 : i32
      %609 = arith.extsi %607 : i32 to i64
      %608 = arith.divsi %606, %609 : i64
      llvm.store %608, %598 : i64, !llvm.ptr
      cf.br ^bb107
    ^bb109:
    %610 = llvm.load %589 : !llvm.ptr -> i64
    func.return %610 : i64
  }
  func.func @count_rank1(%arg0: i64) -> i64 {
    %611 = func.call @isqrt(%arg0) : (i64) -> i64
    %612 = arith.constant 0 : i32
    %613 = arith.extsi %612 : i32 to i64
    %614 = llvm.mlir.constant(1 : i64) : i64
    %615 = llvm.alloca %614 x i64 : (i64) -> !llvm.ptr
    llvm.store %613, %615 : i64, !llvm.ptr
    %616 = arith.constant 0 : i32
    %617 = arith.extsi %616 : i32 to i64
    %618 = llvm.mlir.constant(1 : i64) : i64
    %619 = llvm.alloca %618 x i64 : (i64) -> !llvm.ptr
    llvm.store %617, %619 : i64, !llvm.ptr
    %620 = arith.constant 0 : i32
    %622 = arith.extsi %620 : i32 to i64
    %621 = arith.subi %622, %611 : i64
    %623 = llvm.mlir.constant(1 : i64) : i64
    %624 = llvm.alloca %623 x i64 : (i64) -> !llvm.ptr
    llvm.store %621, %624 : i64, !llvm.ptr
    cf.br ^bb110
    ^bb110:
    %625 = llvm.load %624 : !llvm.ptr -> i64
    %626 = arith.cmpi sle, %625, %611 : i64
    cf.cond_br %626, ^bb111, ^bb112
    ^bb111:
      %627 = arith.constant 0 : i32
      %629 = arith.extsi %627 : i32 to i64
      %628 = arith.subi %629, %611 : i64
      %630 = llvm.mlir.constant(1 : i64) : i64
      %631 = llvm.alloca %630 x i64 : (i64) -> !llvm.ptr
      llvm.store %628, %631 : i64, !llvm.ptr
      cf.br ^bb113
      ^bb113:
      %632 = llvm.load %631 : !llvm.ptr -> i64
      %633 = arith.cmpi sle, %632, %611 : i64
      cf.cond_br %633, ^bb114, ^bb115
      ^bb114:
        %634 = arith.constant 0 : i32
        %636 = arith.extsi %634 : i32 to i64
        %635 = arith.subi %636, %611 : i64
        %637 = llvm.mlir.constant(1 : i64) : i64
        %638 = llvm.alloca %637 x i64 : (i64) -> !llvm.ptr
        llvm.store %635, %638 : i64, !llvm.ptr
        cf.br ^bb116
        ^bb116:
        %639 = llvm.load %638 : !llvm.ptr -> i64
        %640 = arith.cmpi sle, %639, %611 : i64
        cf.cond_br %640, ^bb117, ^bb118
        ^bb117:
          %641 = llvm.load %624 : !llvm.ptr -> i64
          %642 = arith.constant 0 : i32
          %644 = arith.extsi %642 : i32 to i64
          %643 = arith.cmpi eq, %641, %644 : i64
          %645 = scf.if %643 -> (i1) {
            %646 = llvm.load %631 : !llvm.ptr -> i64
            %647 = arith.constant 0 : i32
            %649 = arith.extsi %647 : i32 to i64
            %648 = arith.cmpi eq, %646, %649 : i64
            scf.yield %648 : i1
          } else {
            %650 = arith.constant false
            scf.yield %650 : i1
          }
          %651 = scf.if %645 -> (i1) {
            %652 = llvm.load %638 : !llvm.ptr -> i64
            %653 = arith.constant 0 : i32
            %655 = arith.extsi %653 : i32 to i64
            %654 = arith.cmpi eq, %652, %655 : i64
            scf.yield %654 : i1
          } else {
            %656 = arith.constant false
            scf.yield %656 : i1
          }
          %658 = arith.constant 1 : i1
          %657 = arith.xori %651, %658 : i1
          cf.cond_br %657, ^bb119, ^bb120
          ^bb119:
            %661 = llvm.load %624 : !llvm.ptr -> i64
            %660 = func.call @abs64(%661) : (i64) -> i64
            %663 = llvm.load %631 : !llvm.ptr -> i64
            %662 = func.call @abs64(%663) : (i64) -> i64
            %664 = arith.cmpi sgt, %662, %660 : i64
            %665 = scf.if %664 -> (i64) {
              %667 = llvm.load %631 : !llvm.ptr -> i64
              %666 = func.call @abs64(%667) : (i64) -> i64
              scf.yield %666 : i64
            } else {
              scf.yield %660 : i64
            }
            %669 = llvm.load %638 : !llvm.ptr -> i64
            %668 = func.call @abs64(%669) : (i64) -> i64
            %670 = arith.cmpi sgt, %668, %665 : i64
            %671 = scf.if %670 -> (i64) {
              %673 = llvm.load %638 : !llvm.ptr -> i64
              %672 = func.call @abs64(%673) : (i64) -> i64
              scf.yield %672 : i64
            } else {
              scf.yield %665 : i64
            }
            %674 = arith.divsi %arg0, %671 : i64
            %675 = llvm.load %615 : !llvm.ptr -> i64
            %677 = llvm.load %624 : !llvm.ptr -> i64
            %678 = llvm.load %631 : !llvm.ptr -> i64
            %679 = llvm.load %638 : !llvm.ptr -> i64
            %680 = arith.constant 0 : i32
            %682 = arith.extsi %680 : i32 to i64
            %681 = arith.subi %682, %674 : i64
            %683 = arith.constant 0 : i32
            %685 = arith.extsi %683 : i32 to i64
            %684 = arith.subi %685, %674 : i64
            %686 = arith.constant 0 : i32
            %688 = arith.extsi %686 : i32 to i64
            %687 = arith.subi %688, %674 : i64
            %676 = func.call @count_3d(%677, %678, %679, %681, %674, %684, %674, %687, %674) : (i64, i64, i64, i64, i64, i64, i64, i64, i64) -> i64
            %689 = arith.addi %675, %676 : i64
            llvm.store %689, %615 : i64, !llvm.ptr
            %690 = llvm.load %619 : !llvm.ptr -> i64
            %692 = llvm.load %624 : !llvm.ptr -> i64
            %693 = llvm.load %631 : !llvm.ptr -> i64
            %694 = llvm.load %638 : !llvm.ptr -> i64
            %695 = arith.constant 0 : i32
            %697 = arith.extsi %695 : i32 to i64
            %696 = arith.subi %697, %611 : i64
            %698 = arith.constant 0 : i32
            %700 = arith.extsi %698 : i32 to i64
            %699 = arith.subi %700, %611 : i64
            %701 = arith.constant 0 : i32
            %703 = arith.extsi %701 : i32 to i64
            %702 = arith.subi %703, %611 : i64
            %691 = func.call @count_3d(%692, %693, %694, %696, %611, %699, %611, %702, %611) : (i64, i64, i64, i64, i64, i64, i64, i64, i64) -> i64
            %704 = arith.addi %690, %691 : i64
            llvm.store %704, %619 : i64, !llvm.ptr
            cf.br ^bb121
          ^bb120:
            cf.br ^bb121
          ^bb121:
          %705 = llvm.load %638 : !llvm.ptr -> i64
          %706 = arith.constant 1 : i32
          %708 = arith.extsi %706 : i32 to i64
          %707 = arith.addi %705, %708 : i64
          llvm.store %707, %638 : i64, !llvm.ptr
          cf.br ^bb116
        ^bb118:
        %709 = llvm.load %631 : !llvm.ptr -> i64
        %710 = arith.constant 1 : i32
        %712 = arith.extsi %710 : i32 to i64
        %711 = arith.addi %709, %712 : i64
        llvm.store %711, %631 : i64, !llvm.ptr
        cf.br ^bb113
      ^bb115:
      %713 = llvm.load %624 : !llvm.ptr -> i64
      %714 = arith.constant 1 : i32
      %716 = arith.extsi %714 : i32 to i64
      %715 = arith.addi %713, %716 : i64
      llvm.store %715, %624 : i64, !llvm.ptr
      cf.br ^bb110
    ^bb112:
    %717 = arith.constant 2 : i32
    %718 = llvm.load %615 : !llvm.ptr -> i64
    %720 = arith.extsi %717 : i32 to i64
    %719 = arith.muli %720, %718 : i64
    %721 = llvm.load %619 : !llvm.ptr -> i64
    %722 = arith.subi %719, %721 : i64
    %723 = arith.constant 2 : i32
    %725 = arith.extsi %723 : i32 to i64
    %724 = arith.divsi %722, %725 : i64
    func.return %724 : i64
  }
  func.func @div_interval(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: !llvm.ptr, %arg4: !llvm.ptr) -> () {
    %726 = arith.constant 0 : i32
    %728 = arith.extsi %726 : i32 to i64
    %727 = arith.cmpi sgt, %arg2, %728 : i64
    cf.cond_br %727, ^bb122, ^bb123
    ^bb122:
      %729 = func.call @ceil_div(%arg0, %arg2) : (i64, i64) -> i64
      %730 = arith.constant 0 : i32
      %731 = arith.extsi %730 : i32 to i64
      %732 = llvm.getelementptr %arg3[%731] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %729, %732 : i64, !llvm.ptr
      %733 = func.call @floor_div(%arg1, %arg2) : (i64, i64) -> i64
      %734 = arith.constant 0 : i32
      %735 = arith.extsi %734 : i32 to i64
      %736 = llvm.getelementptr %arg4[%735] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %733, %736 : i64, !llvm.ptr
      cf.br ^bb124
    ^bb123:
      %737 = func.call @ceil_div(%arg1, %arg2) : (i64, i64) -> i64
      %738 = arith.constant 0 : i32
      %739 = arith.extsi %738 : i32 to i64
      %740 = llvm.getelementptr %arg3[%739] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %737, %740 : i64, !llvm.ptr
      %741 = func.call @floor_div(%arg0, %arg2) : (i64, i64) -> i64
      %742 = arith.constant 0 : i32
      %743 = arith.extsi %742 : i32 to i64
      %744 = llvm.getelementptr %arg4[%743] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %741, %744 : i64, !llvm.ptr
      cf.br ^bb124
    ^bb124:
    func.return
  }
  func.func @count_rank2(%arg0: i64) -> i64 {
    %745 = func.call @isqrt(%arg0) : (i64) -> i64
    %746 = arith.constant 0 : i32
    %747 = arith.extsi %746 : i32 to i64
    %748 = llvm.mlir.constant(1 : i64) : i64
    %749 = llvm.alloca %748 x i64 : (i64) -> !llvm.ptr
    llvm.store %747, %749 : i64, !llvm.ptr
    %750 = arith.constant 0 : i32
    %751 = arith.extsi %750 : i32 to i64
    %752 = llvm.mlir.constant(1 : i64) : i64
    %753 = llvm.alloca %752 x i64 : (i64) -> !llvm.ptr
    llvm.store %751, %753 : i64, !llvm.ptr
    %755 = arith.constant 2 : i32
    %756 = arith.constant 8 : i32
    %757 = arith.extsi %755 : i32 to i64
    %758 = arith.extsi %756 : i32 to i64
    %754 = func.call @calloc(%757, %758) : (i64, i64) -> !llvm.ptr
    %759 = arith.constant 0 : i32
    %761 = arith.extsi %759 : i32 to i64
    %760 = arith.subi %761, %745 : i64
    %762 = llvm.mlir.constant(1 : i64) : i64
    %763 = llvm.alloca %762 x i64 : (i64) -> !llvm.ptr
    llvm.store %760, %763 : i64, !llvm.ptr
    cf.br ^bb125
    ^bb125:
    %764 = llvm.load %763 : !llvm.ptr -> i64
    %765 = arith.cmpi sle, %764, %745 : i64
    cf.cond_br %765, ^bb126, ^bb127
    ^bb126:
      %766 = arith.constant 0 : i32
      %768 = arith.extsi %766 : i32 to i64
      %767 = arith.subi %768, %745 : i64
      %769 = llvm.mlir.constant(1 : i64) : i64
      %770 = llvm.alloca %769 x i64 : (i64) -> !llvm.ptr
      llvm.store %767, %770 : i64, !llvm.ptr
      cf.br ^bb128
      ^bb128:
      %771 = llvm.load %770 : !llvm.ptr -> i64
      %772 = arith.cmpi sle, %771, %745 : i64
      cf.cond_br %772, ^bb129, ^bb130
      ^bb129:
        %773 = arith.constant 0 : i32
        %775 = arith.extsi %773 : i32 to i64
        %774 = arith.subi %775, %745 : i64
        %776 = llvm.mlir.constant(1 : i64) : i64
        %777 = llvm.alloca %776 x i64 : (i64) -> !llvm.ptr
        llvm.store %774, %777 : i64, !llvm.ptr
        cf.br ^bb131
        ^bb131:
        %778 = llvm.load %777 : !llvm.ptr -> i64
        %779 = arith.cmpi sle, %778, %745 : i64
        cf.cond_br %779, ^bb132, ^bb133
        ^bb132:
          %780 = llvm.load %763 : !llvm.ptr -> i64
          %781 = arith.constant 0 : i32
          %783 = arith.extsi %781 : i32 to i64
          %782 = arith.cmpi eq, %780, %783 : i64
          %784 = scf.if %782 -> (i1) {
            %785 = llvm.load %770 : !llvm.ptr -> i64
            %786 = arith.constant 0 : i32
            %788 = arith.extsi %786 : i32 to i64
            %787 = arith.cmpi eq, %785, %788 : i64
            scf.yield %787 : i1
          } else {
            %789 = arith.constant false
            scf.yield %789 : i1
          }
          %790 = scf.if %784 -> (i1) {
            %791 = llvm.load %777 : !llvm.ptr -> i64
            %792 = arith.constant 0 : i32
            %794 = arith.extsi %792 : i32 to i64
            %793 = arith.cmpi eq, %791, %794 : i64
            scf.yield %793 : i1
          } else {
            %795 = arith.constant false
            scf.yield %795 : i1
          }
          %797 = arith.constant 1 : i1
          %796 = arith.xori %790, %797 : i1
          cf.cond_br %796, ^bb134, ^bb135
          ^bb134:
            %799 = llvm.load %763 : !llvm.ptr -> i64
            %800 = llvm.load %770 : !llvm.ptr -> i64
            %801 = llvm.load %777 : !llvm.ptr -> i64
            %802 = arith.constant 1 : i32
            %804 = arith.extsi %802 : i32 to i64
            %803 = arith.subi %804, %arg0 : i64
            %805 = arith.constant 1 : i32
            %807 = arith.extsi %805 : i32 to i64
            %806 = arith.addi %807, %arg0 : i64
            %808 = arith.constant 0 : i32
            %809 = arith.extsi %808 : i32 to i64
            %810 = llvm.mlir.constant(1 : i64) : i64
            %811 = llvm.alloca %810 x i64 : (i64) -> !llvm.ptr
            llvm.store %809, %811 : i64, !llvm.ptr
            %812 = arith.constant 0 : i32
            %813 = arith.extsi %812 : i32 to i64
            %814 = llvm.mlir.constant(1 : i64) : i64
            %815 = llvm.alloca %814 x i64 : (i64) -> !llvm.ptr
            llvm.store %813, %815 : i64, !llvm.ptr
            %816 = arith.constant 0 : i32
            %817 = arith.extsi %816 : i32 to i64
            %818 = llvm.mlir.constant(1 : i64) : i64
            %819 = llvm.alloca %818 x i64 : (i64) -> !llvm.ptr
            llvm.store %817, %819 : i64, !llvm.ptr
            %820 = arith.constant 0 : i32
            %821 = arith.extsi %820 : i32 to i64
            %822 = llvm.mlir.constant(1 : i64) : i64
            %823 = llvm.alloca %822 x i64 : (i64) -> !llvm.ptr
            llvm.store %821, %823 : i64, !llvm.ptr
            %824 = arith.constant 0 : i32
            %825 = arith.extsi %824 : i32 to i64
            %826 = llvm.mlir.constant(1 : i64) : i64
            %827 = llvm.alloca %826 x i64 : (i64) -> !llvm.ptr
            llvm.store %825, %827 : i64, !llvm.ptr
            %828 = arith.constant 0 : i32
            %829 = arith.extsi %828 : i32 to i64
            %830 = llvm.mlir.constant(1 : i64) : i64
            %831 = llvm.alloca %830 x i64 : (i64) -> !llvm.ptr
            llvm.store %829, %831 : i64, !llvm.ptr
            %832 = arith.constant 1 : i32
            %833 = llvm.mlir.constant(1 : i64) : i64
            %834 = llvm.alloca %833 x i32 : (i64) -> !llvm.ptr
            llvm.store %832, %834 : i32, !llvm.ptr
            %835 = arith.constant 0 : i32
            %836 = arith.extsi %835 : i32 to i64
            %837 = llvm.mlir.constant(1 : i64) : i64
            %838 = llvm.alloca %837 x i64 : (i64) -> !llvm.ptr
            llvm.store %836, %838 : i64, !llvm.ptr
            cf.br ^bb137
            ^bb137:
            %839 = llvm.load %838 : !llvm.ptr -> i64
            %840 = arith.constant 3 : i32
            %842 = arith.extsi %840 : i32 to i64
            %841 = arith.cmpi slt, %839, %842 : i64
            cf.cond_br %841, ^bb138, ^bb139
            ^bb138:
              %843 = llvm.mlir.constant(1 : i64) : i64
              %844 = llvm.alloca %843 x i64 : (i64) -> !llvm.ptr
              llvm.store %arg0, %844 : i64, !llvm.ptr
              %845 = arith.constant 0 : i32
              %846 = arith.extsi %845 : i32 to i64
              %847 = llvm.mlir.constant(1 : i64) : i64
              %848 = llvm.alloca %847 x i64 : (i64) -> !llvm.ptr
              llvm.store %846, %848 : i64, !llvm.ptr
              cf.br ^bb140
              ^bb140:
              %849 = llvm.load %848 : !llvm.ptr -> i64
              %850 = arith.constant 3 : i32
              %852 = arith.extsi %850 : i32 to i64
              %851 = arith.cmpi slt, %849, %852 : i64
              cf.cond_br %851, ^bb141, ^bb142
              ^bb141:
                %853 = llvm.load %848 : !llvm.ptr -> i64
                %854 = llvm.load %838 : !llvm.ptr -> i64
                %855 = arith.cmpi ne, %853, %854 : i64
                cf.cond_br %855, ^bb143, ^bb144
                ^bb143:
                  %856 = llvm.load %848 : !llvm.ptr -> i64
                  %857 = arith.constant 1 : i32
                  %859 = arith.extsi %857 : i32 to i64
                  %858 = arith.cmpi eq, %856, %859 : i64
                  %860 = scf.if %858 -> (i64) {
                    scf.yield %800 : i64
                  } else {
                    scf.yield %799 : i64
                  }
                  %861 = llvm.load %848 : !llvm.ptr -> i64
                  %862 = arith.constant 2 : i32
                  %864 = arith.extsi %862 : i32 to i64
                  %863 = arith.cmpi eq, %861, %864 : i64
                  %865 = scf.if %863 -> (i64) {
                    scf.yield %801 : i64
                  } else {
                    scf.yield %860 : i64
                  }
                  %866 = arith.constant 0 : i32
                  %868 = arith.extsi %866 : i32 to i64
                  %867 = arith.cmpi ne, %865, %868 : i64
                  cf.cond_br %867, ^bb146, ^bb147
                  ^bb146:
                    %869 = func.call @abs64(%865) : (i64) -> i64
                    %870 = arith.divsi %arg0, %869 : i64
                    %871 = llvm.load %844 : !llvm.ptr -> i64
                    %872 = arith.cmpi slt, %870, %871 : i64
                    cf.cond_br %872, ^bb149, ^bb150
                    ^bb149:
                      llvm.store %870, %844 : i64, !llvm.ptr
                      cf.br ^bb151
                    ^bb150:
                      cf.br ^bb151
                    ^bb151:
                    cf.br ^bb148
                  ^bb147:
                    cf.br ^bb148
                  ^bb148:
                  cf.br ^bb145
                ^bb144:
                  cf.br ^bb145
                ^bb145:
                %873 = llvm.load %848 : !llvm.ptr -> i64
                %874 = arith.constant 1 : i32
                %876 = arith.extsi %874 : i32 to i64
                %875 = arith.addi %873, %876 : i64
                llvm.store %875, %848 : i64, !llvm.ptr
                cf.br ^bb140
              ^bb142:
              %877 = arith.constant 0 : i32
              %878 = llvm.load %844 : !llvm.ptr -> i64
              %880 = arith.extsi %877 : i32 to i64
              %879 = arith.subi %880, %878 : i64
              %881 = llvm.mlir.constant(1 : i64) : i64
              %882 = llvm.alloca %881 x i64 : (i64) -> !llvm.ptr
              llvm.store %879, %882 : i64, !llvm.ptr
              %883 = llvm.load %844 : !llvm.ptr -> i64
              %884 = llvm.mlir.constant(1 : i64) : i64
              %885 = llvm.alloca %884 x i64 : (i64) -> !llvm.ptr
              llvm.store %883, %885 : i64, !llvm.ptr
              %886 = llvm.load %838 : !llvm.ptr -> i64
              %887 = arith.constant 1 : i32
              %889 = arith.extsi %887 : i32 to i64
              %888 = arith.cmpi eq, %886, %889 : i64
              %890 = scf.if %888 -> (i64) {
                scf.yield %800 : i64
              } else {
                scf.yield %799 : i64
              }
              %891 = llvm.load %838 : !llvm.ptr -> i64
              %892 = arith.constant 2 : i32
              %894 = arith.extsi %892 : i32 to i64
              %893 = arith.cmpi eq, %891, %894 : i64
              %895 = scf.if %893 -> (i64) {
                scf.yield %801 : i64
              } else {
                scf.yield %890 : i64
              }
              %896 = arith.constant 0 : i32
              %898 = arith.extsi %896 : i32 to i64
              %897 = arith.cmpi ne, %895, %898 : i64
              cf.cond_br %897, ^bb152, ^bb153
              ^bb152:
                %900 = arith.constant 1 : i32
                %901 = arith.constant 8 : i32
                %902 = arith.extsi %900 : i32 to i64
                %903 = arith.extsi %901 : i32 to i64
                %899 = func.call @calloc(%902, %903) : (i64, i64) -> !llvm.ptr
                %905 = arith.constant 1 : i32
                %906 = arith.constant 8 : i32
                %907 = arith.extsi %905 : i32 to i64
                %908 = arith.extsi %906 : i32 to i64
                %904 = func.call @calloc(%907, %908) : (i64, i64) -> !llvm.ptr
                func.call @div_interval(%803, %806, %895, %899, %904) : (i64, i64, i64, !llvm.ptr, !llvm.ptr) -> ()
                %911 = arith.constant 0 : i32
                %912 = arith.extsi %911 : i32 to i64
                %913 = llvm.getelementptr %899[%912] : (!llvm.ptr, i64) -> !llvm.ptr, i64
                %910 = llvm.load %913 : !llvm.ptr -> i64
                %914 = arith.constant 0 : i32
                %915 = arith.extsi %914 : i32 to i64
                %916 = llvm.getelementptr %754[%915] : (!llvm.ptr, i64) -> !llvm.ptr, i64
                llvm.store %910, %916 : i64, !llvm.ptr
                %918 = arith.constant 0 : i32
                %919 = arith.extsi %918 : i32 to i64
                %920 = llvm.getelementptr %904[%919] : (!llvm.ptr, i64) -> !llvm.ptr, i64
                %917 = llvm.load %920 : !llvm.ptr -> i64
                %921 = arith.constant 1 : i32
                %922 = arith.extsi %921 : i32 to i64
                %923 = llvm.getelementptr %754[%922] : (!llvm.ptr, i64) -> !llvm.ptr, i64
                llvm.store %917, %923 : i64, !llvm.ptr
                func.call @free(%899) : (!llvm.ptr) -> ()
                func.call @free(%904) : (!llvm.ptr) -> ()
                %927 = arith.constant 0 : i32
                %928 = arith.extsi %927 : i32 to i64
                %929 = llvm.getelementptr %754[%928] : (!llvm.ptr, i64) -> !llvm.ptr, i64
                %926 = llvm.load %929 : !llvm.ptr -> i64
                %931 = arith.constant 1 : i32
                %932 = arith.extsi %931 : i32 to i64
                %933 = llvm.getelementptr %754[%932] : (!llvm.ptr, i64) -> !llvm.ptr, i64
                %930 = llvm.load %933 : !llvm.ptr -> i64
                %934 = arith.cmpi sgt, %926, %930 : i64
                %935, %936 = scf.if %934 -> (i64, i64) {
                  scf.yield %930, %926 : i64, i64
                } else {
                  scf.yield %926, %930 : i64, i64
                }
                %937 = llvm.load %882 : !llvm.ptr -> i64
                %938 = arith.cmpi sgt, %935, %937 : i64
                cf.cond_br %938, ^bb155, ^bb156
                ^bb155:
                  llvm.store %935, %882 : i64, !llvm.ptr
                  cf.br ^bb157
                ^bb156:
                  cf.br ^bb157
                ^bb157:
                %939 = llvm.load %885 : !llvm.ptr -> i64
                %940 = arith.cmpi slt, %936, %939 : i64
                cf.cond_br %940, ^bb158, ^bb159
                ^bb158:
                  llvm.store %936, %885 : i64, !llvm.ptr
                  cf.br ^bb160
                ^bb159:
                  cf.br ^bb160
                ^bb160:
                cf.br ^bb154
              ^bb153:
                cf.br ^bb154
              ^bb154:
              %941 = llvm.load %838 : !llvm.ptr -> i64
              %942 = arith.constant 0 : i32
              %944 = arith.extsi %942 : i32 to i64
              %943 = arith.cmpi eq, %941, %944 : i64
              cf.cond_br %943, ^bb161, ^bb162
              ^bb161:
                %945 = llvm.load %882 : !llvm.ptr -> i64
                llvm.store %945, %811 : i64, !llvm.ptr
                %946 = llvm.load %885 : !llvm.ptr -> i64
                llvm.store %946, %815 : i64, !llvm.ptr
                cf.br ^bb163
              ^bb162:
                cf.br ^bb163
              ^bb163:
              %947 = llvm.load %838 : !llvm.ptr -> i64
              %948 = arith.constant 1 : i32
              %950 = arith.extsi %948 : i32 to i64
              %949 = arith.cmpi eq, %947, %950 : i64
              cf.cond_br %949, ^bb164, ^bb165
              ^bb164:
                %951 = llvm.load %882 : !llvm.ptr -> i64
                llvm.store %951, %819 : i64, !llvm.ptr
                %952 = llvm.load %885 : !llvm.ptr -> i64
                llvm.store %952, %823 : i64, !llvm.ptr
                cf.br ^bb166
              ^bb165:
                cf.br ^bb166
              ^bb166:
              %953 = llvm.load %838 : !llvm.ptr -> i64
              %954 = arith.constant 2 : i32
              %956 = arith.extsi %954 : i32 to i64
              %955 = arith.cmpi eq, %953, %956 : i64
              cf.cond_br %955, ^bb167, ^bb168
              ^bb167:
                %957 = llvm.load %882 : !llvm.ptr -> i64
                llvm.store %957, %827 : i64, !llvm.ptr
                %958 = llvm.load %885 : !llvm.ptr -> i64
                llvm.store %958, %831 : i64, !llvm.ptr
                cf.br ^bb169
              ^bb168:
                cf.br ^bb169
              ^bb169:
              %959 = llvm.load %882 : !llvm.ptr -> i64
              %960 = llvm.load %885 : !llvm.ptr -> i64
              %961 = arith.cmpi sgt, %959, %960 : i64
              cf.cond_br %961, ^bb170, ^bb171
              ^bb170:
                %962 = arith.constant 0 : i32
                llvm.store %962, %834 : i32, !llvm.ptr
                cf.br ^bb172
              ^bb171:
                cf.br ^bb172
              ^bb172:
              %963 = llvm.load %838 : !llvm.ptr -> i64
              %964 = arith.constant 1 : i32
              %966 = arith.extsi %964 : i32 to i64
              %965 = arith.addi %963, %966 : i64
              llvm.store %965, %838 : i64, !llvm.ptr
              cf.br ^bb137
            ^bb139:
            %967 = llvm.load %834 : !llvm.ptr -> i32
            %968 = arith.constant 0 : i32
            %969 = arith.cmpi ne, %967, %968 : i32
            cf.cond_br %969, ^bb173, ^bb174
            ^bb173:
              %970 = llvm.load %749 : !llvm.ptr -> i64
              %972 = llvm.load %763 : !llvm.ptr -> i64
              %973 = llvm.load %770 : !llvm.ptr -> i64
              %974 = llvm.load %777 : !llvm.ptr -> i64
              %975 = llvm.load %811 : !llvm.ptr -> i64
              %976 = llvm.load %815 : !llvm.ptr -> i64
              %977 = llvm.load %819 : !llvm.ptr -> i64
              %978 = llvm.load %823 : !llvm.ptr -> i64
              %979 = llvm.load %827 : !llvm.ptr -> i64
              %980 = llvm.load %831 : !llvm.ptr -> i64
              %971 = func.call @count_3d(%972, %973, %974, %975, %976, %977, %978, %979, %980) : (i64, i64, i64, i64, i64, i64, i64, i64, i64) -> i64
              %981 = arith.addi %970, %971 : i64
              llvm.store %981, %749 : i64, !llvm.ptr
              %982 = llvm.load %811 : !llvm.ptr -> i64
              %983 = llvm.mlir.constant(1 : i64) : i64
              %984 = llvm.alloca %983 x i64 : (i64) -> !llvm.ptr
              llvm.store %982, %984 : i64, !llvm.ptr
              %985 = llvm.load %815 : !llvm.ptr -> i64
              %986 = llvm.mlir.constant(1 : i64) : i64
              %987 = llvm.alloca %986 x i64 : (i64) -> !llvm.ptr
              llvm.store %985, %987 : i64, !llvm.ptr
              %988 = llvm.load %819 : !llvm.ptr -> i64
              %989 = llvm.mlir.constant(1 : i64) : i64
              %990 = llvm.alloca %989 x i64 : (i64) -> !llvm.ptr
              llvm.store %988, %990 : i64, !llvm.ptr
              %991 = llvm.load %823 : !llvm.ptr -> i64
              %992 = llvm.mlir.constant(1 : i64) : i64
              %993 = llvm.alloca %992 x i64 : (i64) -> !llvm.ptr
              llvm.store %991, %993 : i64, !llvm.ptr
              %994 = llvm.load %827 : !llvm.ptr -> i64
              %995 = llvm.mlir.constant(1 : i64) : i64
              %996 = llvm.alloca %995 x i64 : (i64) -> !llvm.ptr
              llvm.store %994, %996 : i64, !llvm.ptr
              %997 = llvm.load %831 : !llvm.ptr -> i64
              %998 = llvm.mlir.constant(1 : i64) : i64
              %999 = llvm.alloca %998 x i64 : (i64) -> !llvm.ptr
              llvm.store %997, %999 : i64, !llvm.ptr
              %1000 = llvm.load %984 : !llvm.ptr -> i64
              %1001 = arith.constant 0 : i32
              %1003 = arith.extsi %1001 : i32 to i64
              %1002 = arith.subi %1003, %745 : i64
              %1004 = arith.cmpi slt, %1000, %1002 : i64
              cf.cond_br %1004, ^bb176, ^bb177
              ^bb176:
                %1005 = arith.constant 0 : i32
                %1007 = arith.extsi %1005 : i32 to i64
                %1006 = arith.subi %1007, %745 : i64
                llvm.store %1006, %984 : i64, !llvm.ptr
                cf.br ^bb178
              ^bb177:
                cf.br ^bb178
              ^bb178:
              %1008 = llvm.load %987 : !llvm.ptr -> i64
              %1009 = arith.cmpi sgt, %1008, %745 : i64
              cf.cond_br %1009, ^bb179, ^bb180
              ^bb179:
                llvm.store %745, %987 : i64, !llvm.ptr
                cf.br ^bb181
              ^bb180:
                cf.br ^bb181
              ^bb181:
              %1010 = llvm.load %990 : !llvm.ptr -> i64
              %1011 = arith.constant 0 : i32
              %1013 = arith.extsi %1011 : i32 to i64
              %1012 = arith.subi %1013, %745 : i64
              %1014 = arith.cmpi slt, %1010, %1012 : i64
              cf.cond_br %1014, ^bb182, ^bb183
              ^bb182:
                %1015 = arith.constant 0 : i32
                %1017 = arith.extsi %1015 : i32 to i64
                %1016 = arith.subi %1017, %745 : i64
                llvm.store %1016, %990 : i64, !llvm.ptr
                cf.br ^bb184
              ^bb183:
                cf.br ^bb184
              ^bb184:
              %1018 = llvm.load %993 : !llvm.ptr -> i64
              %1019 = arith.cmpi sgt, %1018, %745 : i64
              cf.cond_br %1019, ^bb185, ^bb186
              ^bb185:
                llvm.store %745, %993 : i64, !llvm.ptr
                cf.br ^bb187
              ^bb186:
                cf.br ^bb187
              ^bb187:
              %1020 = llvm.load %996 : !llvm.ptr -> i64
              %1021 = arith.constant 0 : i32
              %1023 = arith.extsi %1021 : i32 to i64
              %1022 = arith.subi %1023, %745 : i64
              %1024 = arith.cmpi slt, %1020, %1022 : i64
              cf.cond_br %1024, ^bb188, ^bb189
              ^bb188:
                %1025 = arith.constant 0 : i32
                %1027 = arith.extsi %1025 : i32 to i64
                %1026 = arith.subi %1027, %745 : i64
                llvm.store %1026, %996 : i64, !llvm.ptr
                cf.br ^bb190
              ^bb189:
                cf.br ^bb190
              ^bb190:
              %1028 = llvm.load %999 : !llvm.ptr -> i64
              %1029 = arith.cmpi sgt, %1028, %745 : i64
              cf.cond_br %1029, ^bb191, ^bb192
              ^bb191:
                llvm.store %745, %999 : i64, !llvm.ptr
                cf.br ^bb193
              ^bb192:
                cf.br ^bb193
              ^bb193:
              %1030 = llvm.load %984 : !llvm.ptr -> i64
              %1031 = llvm.load %987 : !llvm.ptr -> i64
              %1032 = arith.cmpi sle, %1030, %1031 : i64
              %1033 = scf.if %1032 -> (i1) {
                %1034 = llvm.load %990 : !llvm.ptr -> i64
                %1035 = llvm.load %993 : !llvm.ptr -> i64
                %1036 = arith.cmpi sle, %1034, %1035 : i64
                scf.yield %1036 : i1
              } else {
                %1037 = arith.constant false
                scf.yield %1037 : i1
              }
              %1038 = scf.if %1033 -> (i1) {
                %1039 = llvm.load %996 : !llvm.ptr -> i64
                %1040 = llvm.load %999 : !llvm.ptr -> i64
                %1041 = arith.cmpi sle, %1039, %1040 : i64
                scf.yield %1041 : i1
              } else {
                %1042 = arith.constant false
                scf.yield %1042 : i1
              }
              cf.cond_br %1038, ^bb194, ^bb195
              ^bb194:
                %1043 = llvm.load %753 : !llvm.ptr -> i64
                %1045 = llvm.load %763 : !llvm.ptr -> i64
                %1046 = llvm.load %770 : !llvm.ptr -> i64
                %1047 = llvm.load %777 : !llvm.ptr -> i64
                %1048 = llvm.load %984 : !llvm.ptr -> i64
                %1049 = llvm.load %987 : !llvm.ptr -> i64
                %1050 = llvm.load %990 : !llvm.ptr -> i64
                %1051 = llvm.load %993 : !llvm.ptr -> i64
                %1052 = llvm.load %996 : !llvm.ptr -> i64
                %1053 = llvm.load %999 : !llvm.ptr -> i64
                %1044 = func.call @count_3d(%1045, %1046, %1047, %1048, %1049, %1050, %1051, %1052, %1053) : (i64, i64, i64, i64, i64, i64, i64, i64, i64) -> i64
                %1054 = arith.addi %1043, %1044 : i64
                llvm.store %1054, %753 : i64, !llvm.ptr
                cf.br ^bb196
              ^bb195:
                cf.br ^bb196
              ^bb196:
              cf.br ^bb175
            ^bb174:
              cf.br ^bb175
            ^bb175:
            cf.br ^bb136
          ^bb135:
            cf.br ^bb136
          ^bb136:
          %1055 = llvm.load %777 : !llvm.ptr -> i64
          %1056 = arith.constant 1 : i32
          %1058 = arith.extsi %1056 : i32 to i64
          %1057 = arith.addi %1055, %1058 : i64
          llvm.store %1057, %777 : i64, !llvm.ptr
          cf.br ^bb131
        ^bb133:
        %1059 = llvm.load %770 : !llvm.ptr -> i64
        %1060 = arith.constant 1 : i32
        %1062 = arith.extsi %1060 : i32 to i64
        %1061 = arith.addi %1059, %1062 : i64
        llvm.store %1061, %770 : i64, !llvm.ptr
        cf.br ^bb128
      ^bb130:
      %1063 = llvm.load %763 : !llvm.ptr -> i64
      %1064 = arith.constant 1 : i32
      %1066 = arith.extsi %1064 : i32 to i64
      %1065 = arith.addi %1063, %1066 : i64
      llvm.store %1065, %763 : i64, !llvm.ptr
      cf.br ^bb125
    ^bb127:
    func.call @free(%754) : (!llvm.ptr) -> ()
    %1068 = arith.constant 2 : i32
    %1069 = llvm.load %749 : !llvm.ptr -> i64
    %1071 = arith.extsi %1068 : i32 to i64
    %1070 = arith.muli %1071, %1069 : i64
    %1072 = llvm.load %753 : !llvm.ptr -> i64
    %1073 = arith.subi %1070, %1072 : i64
    %1074 = arith.constant 2 : i32
    %1076 = arith.extsi %1074 : i32 to i64
    %1075 = arith.divsi %1073, %1076 : i64
    func.return %1075 : i64
  }
  func.func @C(%arg0: i64) -> i64 {
    %1077 = arith.constant 0 : i32
    %1079 = arith.extsi %1077 : i32 to i64
    %1078 = arith.cmpi eq, %arg0, %1079 : i64
    cf.cond_br %1078, ^bb197, ^bb198
    ^bb197:
      %1080 = arith.constant 1 : i32
      %1081 = arith.extsi %1080 : i32 to i64
      func.return %1081 : i64
    ^bb198:
      cf.br ^bb199
    ^bb199:
    %1082 = arith.constant 2 : i32
    %1083 = func.call @count_rank1(%arg0) : (i64) -> i64
    %1085 = arith.extsi %1082 : i32 to i64
    %1084 = arith.addi %1085, %1083 : i64
    %1086 = func.call @count_rank2(%arg0) : (i64) -> i64
    %1087 = arith.addi %1084, %1086 : i64
    func.return %1087 : i64
  }
  func.func @main() -> i32 {
    %1088 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %1090 = arith.constant 200 : i32
    %1091 = arith.extsi %1090 : i32 to i64
    %1089 = func.call @C(%1091) : (i64) -> i64
    %1092 = llvm.call @printf(%1088, %1089) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %1093 = arith.constant 0 : i32
    func.return %1093 : i32
  }
}