// File: /workspace/github_c_makefile_star2_O0/mohuangrui[P]ArtraCFD/domain_partition.c
// Function: PartitionDomain
void PartitionDomain(Space *space)
{
    Partition *const part = &(space->part);
    /*
     * Outward facing surface unit normal vector of domain boundary
     * Surface normal vector can provide great advantage: every surface can
     * be treated uniformly if operations are incorporated with surface
     * normal vector. For example, (NX, NY, NZ) is the outward facing unit
     * normal vector at surface point (i, j, k), then its neighbour node
     * (ih, jh, kh) is more inner than current node if
     * (ih - i) * NX + (jh - j) * NY + (kh - k) * NZ < 0.
     */
    const int N[NBC][DIMS] = {{0, 0, 0}, {-1, 0, 0}, {1, 0, 0},
        {0, -1, 0}, {0, 1, 0}, {0, 0, -1}, {0, 0, 1}};
    for (int p = 0; p < NBC; ++p) {
        for (int s = 0; s < DIMS; ++s) {
            part->N[p][s] = N[p][s];
        }
    }
    /*
     * Define the index control array of each partition
     * min and max are used to define domain index range and are widely
     * used in for loop control. To reduce loop comparisons, use a
     * reachable value for min, and unreachable value for max. To count
     * the total valid objects, simply do (max - min).
     *
     * Index range
     * Entire domain (includes exterior ghost): [0, n);
     * Lower exterior ghost: [0, ng);
     * Normal nodes: [ng, n-ng);
     *      Lower boundary: [ng, ng+1);
     *      Interior node layers: [ng+1, n-ng-1);
     *      Upper Boundary: [n-ng-1, n-ng);
     * Upper exterior ghost: [n-ng, n);
     *
     * The computational domain are categorized into three main regions:
     * interior region, boundary region, and ghost region. In general,
     * the interior region is where normal computation is performed;
     * the boundary region is where physical boundary condition is enforced;
     * the ghost region is where numerical boundary treatment is performed.
     *
     * When the periodic boundary condition is applied to a direction, then
     * the interior region in this direction should be extended to include
     * the boundary region, which will then participate normal computation.
     */
    for (int s = 0, q = PWB; s < DIMS; ++s, q = q + 2) {
        /* interior region */
        if (PERIODIC == part->typeBC[q]) { /* extended interior range */
            part->ns[PIN][s][MIN] = part->ng[s];
            part->ns[PIN][s][MAX] = part->n[s] - part->ng[s];
        } else { /* normal interior range */
            part->ns[PIN][s][MIN] = part->ng[s] + 1;
            part->ns[PIN][s][MAX] = part->n[s] - part->ng[s] - 1;
        }
        /* boundary box */
        for (int p = PWB; p <= PBB; ++p) {
            part->ns[p][s][MIN] = part->ng[s];
            part->ns[p][s][MAX] = part->n[s] - part->ng[s];
        }
        /* ghost box */
        for (int p = PWG; p <= PBG; ++p) {
            part->ns[p][s][MIN] = 0;
            part->ns[p][s][MAX] = part->n[s];
        }
        /* physical region */
        part->ns[PHY][s][MIN] = part->ng[s];
        part->ns[PHY][s][MAX] = part->n[s] - part->ng[s];
        /* all region */
        part->ns[PAL][s][MIN] = 0;
        part->ns[PAL][s][MAX] = part->n[s];
    }
    /* adjust boundary box to the boundary region of each direction */
    for (int p = PWB, s = 0; p <= PBB; p = p + 2, ++s) {
        part->ns[p][s][MAX] = part->ns[p][s][MIN] + 1;
    }
    for (int p = PEB, s = 0; p <= PBB; p = p + 2, ++s) {
        part->ns[p][s][MIN] = part->ns[p][s][MAX] - 1;
    }
    /* adjust ghost box to the ghost region of each direction */
    for (int p = PWG, s = 0; p <= PBG; p = p + 2, ++s) {
        part->ns[p][s][MAX] = part->ng[s];
    }
    for (int p = PEG, s = 0; p <= PBG; p = p + 2, ++s) {
        part->ns[p][s][MIN] = part->n[s] - part->ng[s];
    }
    /* computational node range with dimension priority */
    const int np[DIMS][DIMS][LIMIT] = {
        {
            {part->ns[PIN][X][MIN], part->ns[PIN][X][MAX]},
            {part->ns[PIN][Y][MIN], part->ns[PIN][Y][MAX]},
            {part->ns[PIN][Z][MIN], part->ns[PIN][Z][MAX]}
        },
        {
            {part->ns[PIN][Y][MIN], part->ns[PIN][Y][MAX]},
            {part->ns[PIN][X][MIN], part->ns[PIN][X][MAX]},
            {part->ns[PIN][Z][MIN], part->ns[PIN][Z][MAX]}
        },
        {
            {part->ns[PIN][Z][MIN], part->ns[PIN][Z][MAX]},
            {part->ns[PIN][X][MIN], part->ns[PIN][X][MAX]},
            {part->ns[PIN][Y][MIN], part->ns[PIN][Y][MAX]}
        }
    };
    for (int n = 0; n < DIMS; ++n) {
        for (int s = 0; s < DIMS; ++s) {
            for (int m = 0; m < LIMIT; ++m) {
                part->np[n][s][m] = np[n][s][m];
            }
        }
    }
    /* search path for interfacial node */
    const int path[PATHN][DIMS] = { /* searching path */
        {-1, 0, 0}, {1, 0, 0}, {0, -1, 0}, {0, 1, 0}, {0, 0, -1}, {0, 0, 1},
        {-1, -1, 0}, {1, -1, 0}, {-1, 1, 0}, {1, 1, 0},
        {-1, 0, -1}, {1, 0, -1}, {-1, 0, 1}, {1, 0, 1},
        {0, -1, -1}, {0, 1, -1}, {0, -1, 1}, {0, 1, 1},
        {-2, 0, 0}, {2, 0, 0}, {0, -2, 0}, {0, 2, 0}, {0, 0, -2}, {0, 0, 2},
        {-3, 0, 0}, {3, 0, 0}, {0, -3, 0}, {0, 3, 0}, {0, 0, -3}, {0, 0, 3}
    };
    for (int n = 0; n < PATHN; ++n) {
        for (int s = 0; s < DIMS; ++s) {
            part->path[n][s] = path[n][s];
        }
    }
    const int base = 6; /* base directions in searching path */
    part->pathSep[1] = base; /* end index for layer 1 */
    part->pathSep[2] = part->pathSep[1] + 18; /* end index for layer 2 */
    part->pathSep[3] = part->pathSep[2] + base; /* end index for layer 3 */
    /* max search path for a spatial scheme */
    part->pathSep[0] = part->pathSep[part->gl];
    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x10(%rbp)
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x54, %edx
callq 0x20d0
movl $0xffffffff, -0x64(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x58(%rbp)
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x3c(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x20(%rbp)
movl $0x0, -0x74(%rbp)
cmpl $0x7, -0x74(%rbp)
jge 0x1462a
movl $0x0, -0x78(%rbp)
cmpl $0x3, -0x78(%rbp)
jge 0x1461d
movslq -0x74(%rbp), %rcx
leaq -0x70(%rbp), %rax
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movslq -0x78(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movq 0x398(%rax), %rax
movslq -0x74(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movslq -0x78(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x145d9
jmp 0x1461f
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x145cc
movl $0x0, -0x7c(%rbp)
movl $0x1, -0x80(%rbp)
cmpl $0x3, -0x7c(%rbp)
jge 0x14854
movq -0x10(%rbp), %rax
movq 0x390(%rax), %rcx
movslq -0x80(%rbp), %rdx
movl $0x4, %eax
cmpl (%rcx,%rdx,4), %eax
jne 0x14699
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl 0x18(%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl %edx, 0x68(%rax,%rcx,8)
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl 0xc(%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
subl 0x18(%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl %edx, 0x6c(%rax,%rcx,8)
jmp 0x146db
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl 0x18(%rax,%rcx,4), %edx
addl $0x1, %edx
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl %edx, 0x68(%rax,%rcx,8)
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl 0xc(%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
subl 0x18(%rax,%rcx,4), %edx
subl $0x1, %edx
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl %edx, 0x6c(%rax,%rcx,8)
movl $0x1, -0x84(%rbp)
cmpl $0x6, -0x84(%rbp)
jg 0x1475e
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl 0x18(%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
addq $0x68, %rax
movslq -0x84(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq -0x7c(%rbp), %rcx
movl %edx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl 0xc(%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
subl 0x18(%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
addq $0x68, %rax
movslq -0x84(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq -0x7c(%rbp), %rcx
movl %edx, 0x4(%rax,%rcx,8)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x146e5
movl $0x7, -0x88(%rbp)
cmpl $0xc, -0x88(%rbp)
jg 0x147cd
movq -0x10(%rbp), %rax
addq $0x68, %rax
movslq -0x88(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq -0x7c(%rbp), %rcx
movl $0x0, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl 0xc(%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
addq $0x68, %rax
movslq -0x88(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq -0x7c(%rbp), %rcx
movl %edx, 0x4(%rax,%rcx,8)
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x14768
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl 0x18(%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl %edx, 0x1a0(%rax,%rcx,8)
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl 0xc(%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
subl 0x18(%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl %edx, 0x1a4(%rax,%rcx,8)
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl $0x0, 0x1b8(%rax,%rcx,8)
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl 0xc(%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl %edx, 0x1bc(%rax,%rcx,8)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
movl -0x80(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x80(%rbp)
jmp 0x14638
movl $0x1, -0x8c(%rbp)
movl $0x0, -0x90(%rbp)
cmpl $0x6, -0x8c(%rbp)
jg 0x148d5
movq -0x10(%rbp), %rax
addq $0x68, %rax
movslq -0x8c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq -0x90(%rbp), %rcx
movl (%rax,%rcx,8), %edx
addl $0x1, %edx
movq -0x10(%rbp), %rax
addq $0x68, %rax
movslq -0x8c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq -0x90(%rbp), %rcx
movl %edx, 0x4(%rax,%rcx,8)
movl -0x8c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x8c(%rbp)
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x14868
movl $0x2, -0x94(%rbp)
movl $0x0, -0x98(%rbp)
cmpl $0x6, -0x94(%rbp)
jg 0x14956
movq -0x10(%rbp), %rax
addq $0x68, %rax
movslq -0x94(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq -0x98(%rbp), %rcx
movl 0x4(%rax,%rcx,8), %edx
subl $0x1, %edx
movq -0x10(%rbp), %rax
addq $0x68, %rax
movslq -0x94(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq -0x98(%rbp), %rcx
movl %edx, (%rax,%rcx,8)
movl -0x94(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x94(%rbp)
movl -0x98(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x98(%rbp)
jmp 0x148e9
movl $0x7, -0x9c(%rbp)
movl $0x0, -0xa0(%rbp)
cmpl $0xc, -0x9c(%rbp)
jg 0x149c3
movq -0x10(%rbp), %rax
movslq -0xa0(%rbp), %rcx
movl 0x18(%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
addq $0x68, %rax
movslq -0x9c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq -0xa0(%rbp), %rcx
movl %edx, 0x4(%rax,%rcx,8)
movl -0x9c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x9c(%rbp)
movl -0xa0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0x1496a
movl $0x8, -0xa4(%rbp)
movl $0x0, -0xa8(%rbp)
cmpl $0xc, -0xa4(%rbp)
jg 0x14a3e
movq -0x10(%rbp), %rax
movslq -0xa8(%rbp), %rcx
movl 0xc(%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movslq -0xa8(%rbp), %rcx
subl 0x18(%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
addq $0x68, %rax
movslq -0xa4(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq -0xa8(%rbp), %rcx
movl %edx, (%rax,%rcx,8)
movl -0xa4(%rbp), %eax
addl $0x2, %eax
movl %eax, -0xa4(%rbp)
movl -0xa8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
jmp 0x149d7
movq -0x10(%rbp), %rax
movl 0x68(%rax), %eax
movl %eax, -0xf0(%rbp)
movq -0x10(%rbp), %rax
movl 0x6c(%rax), %eax
movl %eax, -0xec(%rbp)
movq -0x10(%rbp), %rax
movl 0x70(%rax), %eax
movl %eax, -0xe8(%rbp)
movq -0x10(%rbp), %rax
movl 0x74(%rax), %eax
movl %eax, -0xe4(%rbp)
movq -0x10(%rbp), %rax
movl 0x78(%rax), %eax
movl %eax, -0xe0(%rbp)
movq -0x10(%rbp), %rax
movl 0x7c(%rax), %eax
movl %eax, -0xdc(%rbp)
movq -0x10(%rbp), %rax
movl 0x70(%rax), %eax
movl %eax, -0xd8(%rbp)
movq -0x10(%rbp), %rax
movl 0x74(%rax), %eax
movl %eax, -0xd4(%rbp)
movq -0x10(%rbp), %rax
movl 0x68(%rax), %eax
movl %eax, -0xd0(%rbp)
movq -0x10(%rbp), %rax
movl 0x6c(%rax), %eax
movl %eax, -0xcc(%rbp)
movq -0x10(%rbp), %rax
movl 0x78(%rax), %eax
movl %eax, -0xc8(%rbp)
movq -0x10(%rbp), %rax
movl 0x7c(%rax), %eax
movl %eax, -0xc4(%rbp)
movq -0x10(%rbp), %rax
movl 0x78(%rax), %eax
movl %eax, -0xc0(%rbp)
movq -0x10(%rbp), %rax
movl 0x7c(%rax), %eax
movl %eax, -0xbc(%rbp)
movq -0x10(%rbp), %rax
movl 0x68(%rax), %eax
movl %eax, -0xb8(%rbp)
movq -0x10(%rbp), %rax
movl 0x6c(%rax), %eax
movl %eax, -0xb4(%rbp)
movq -0x10(%rbp), %rax
movl 0x70(%rax), %eax
movl %eax, -0xb0(%rbp)
movq -0x10(%rbp), %rax
movl 0x74(%rax), %eax
movl %eax, -0xac(%rbp)
movl $0x0, -0xf4(%rbp)
cmpl $0x3, -0xf4(%rbp)
jge 0x14c03
movl $0x0, -0xf8(%rbp)
cmpl $0x3, -0xf8(%rbp)
jge 0x14bed
movl $0x0, -0xfc(%rbp)
cmpl $0x2, -0xfc(%rbp)
jge 0x14bd7
movslq -0xf4(%rbp), %rcx
leaq -0xf0(%rbp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq -0xf8(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0xfc(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
addq $0x1d0, %rax            # imm = 0x1D0
movslq -0xf4(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq -0xf8(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0xfc(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0xfc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xfc(%rbp)
jmp 0x14b60
jmp 0x14bd9
movl -0xf8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf8(%rbp)
jmp 0x14b49
jmp 0x14bef
movl -0xf4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4(%rbp)
jmp 0x14b32
leaq -0x270(%rbp), %rdi
leaq 0x1301f(%rip), %rsi     # 0x27c30
movl $0x168, %edx            # imm = 0x168
callq 0x2150
movl $0x0, -0x274(%rbp)
cmpl $0x1e, -0x274(%rbp)
jge 0x14ca9
movl $0x0, -0x278(%rbp)
cmpl $0x3, -0x278(%rbp)
jge 0x14c93
movslq -0x274(%rbp), %rcx
leaq -0x270(%rbp), %rax
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movslq -0x278(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
addq $0x218, %rax            # imm = 0x218
movslq -0x274(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movslq -0x278(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x278(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x278(%rbp)
jmp 0x14c38
jmp 0x14c95
movl -0x274(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x274(%rbp)
jmp 0x14c25
movl $0x6, -0x27c(%rbp)
movq -0x10(%rbp), %rax
movl $0x6, 0x384(%rax)
movq -0x10(%rbp), %rax
movl 0x384(%rax), %ecx
addl $0x12, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x388(%rax)
movq -0x10(%rbp), %rax
movl 0x388(%rax), %ecx
addl $0x6, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x38c(%rax)
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x24(%rcx), %rcx
movl 0x380(%rax,%rcx,4), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x380(%rax)
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop