// File: /workspace/github_c_makefile_star2_O3/mohuangrui[P]ArtraCFD/boundary_treatment.c
// Function: TreatBoundary
void TreatBoundary(const int tn, Space *space, const Model *model)
{
    /*
     * Internal boundary treatment
     * Should be performed first to ensure stencils for diffusive flux
     * discretization are treated correctly, especially for collapsed
     * dimensions.
     */
    TreatImmersedBoundary(tn, space, model);
    /*
     * External boundary treatment
     * When no mixed derivatives are discretized, only cross-type stencils
     * are needed. Then, the corner ghost nodes do not need treatment.
     * However, corner ghost nodes are necessary for the computation of
     * mixed derivatives as in viscous fluxes or for transfer operators
     * within multigrid. To treat the entire ghost region, the boundary
     * treatment should be performed one box layer by one box layer from
     * inside to outside.
     */
    const Partition *const part = &(space->part);
    const IntVec ng = {part->ng[X], part->ng[Y], part->ng[Z]};
    const int R = MaxInt(ng[X], MaxInt(ng[Y], ng[Z]));
    int box[DIMS][LIMIT] = {{0}}; /* range box of numerical boundary */
    for (int r = 0; r <= R; ++r) { /* process layer by layer */
        for (int p = PWB; p <= PBB; ++p) {
            const IntVec N = {part->N[p][X], part->N[p][Y], part->N[p][Z]};
            for (int s = 0; s < DIMS; ++s) { /* compute range box of each layer */
                box[s][MIN] = part->ns[p][s][MIN] + MinInt(r, ng[s]) * (N[s] - !N[s]);
                box[s][MAX] = part->ns[p][s][MAX] + MinInt(r, ng[s]) * (N[s] + !N[s]) - (ng[s] < r) * (!!N[s]);
            }
            if ((box[X][MIN] >= box[X][MAX]) || (box[Y][MIN] >= box[Y][MAX]) || (box[Z][MIN] >= box[Z][MAX])) {
                continue;
            }
            ApplyBoundaryCondition(p, r, box, tn, space, model);
        }
    }
    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rsi, %r14
movl %edi, %ebp
movq %rdx, 0x38(%rsp)
callq 0x11981
movl 0x40(%r14), %r15d
movl %r15d, 0x114(%rsp)
movl 0x44(%r14), %edi
movl %edi, 0x118(%rsp)
movl 0x48(%r14), %esi
movl %esi, 0x11c(%rsp)
callq 0x7db0
movl %r15d, %edi
movl %eax, %esi
callq 0x7db0
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movq $0x0, 0xb0(%rsp)
movl %eax, 0x50(%rsp)
testl %eax, %eax
js 0x2c0a
movslq %ebp, %rax
movq %rax, 0xd8(%rsp)
leaq 0xac(%r14), %rax
movq %rax, 0x158(%rsp)
movq $0x0, 0x40(%rsp)
movl $0x0, 0x24(%rsp)
xorl %ebp, %ebp
leal (,%rbp,2), %eax
movl %eax, 0x54(%rsp)
movl $0x1, %ebx
movq 0x158(%rsp), %rax
movq %rbp, 0x48(%rsp)
movq %rax, 0xb8(%rsp)
movq 0x3c0(%r14), %rax
movq %rbx, 0x30(%rsp)
leaq (%rbx,%rbx,2), %rsi
movq (%rax,%rsi,4), %rcx
movq %rcx, 0x180(%rsp)
movq %rsi, 0x18(%rsp)
movl 0x8(%rax,%rsi,4), %eax
movl %eax, 0x188(%rsp)
xorl %r13d, %r13d
movq 0xb8(%rsp), %rbx
movl -0x4(%rbx,%r13,2), %ebp
movl 0x114(%rsp,%r13), %esi
movl %esi, (%rsp)
movq 0x48(%rsp), %r15
movl %r15d, %edi
callq 0x7da8
movl 0x180(%rsp,%r13), %r12d
cmpl $0x1, %r12d
movl $0x0, %ecx
sbbl %ecx, %ecx
orl %r12d, %ecx
imull %eax, %ecx
addl %ebp, %ecx
movl %ecx, 0xa0(%rsp,%r13,2)
movl (%rbx,%r13,2), %ebp
movl %r15d, %edi
movl (%rsp), %ebx
movl %ebx, %esi
callq 0x7da8
xorl %ecx, %ecx
testl %r12d, %r12d
sete %cl
setne %dl
addl %r12d, %ecx
imull %eax, %ecx
cmpl %r15d, %ebx
setl %al
andb %dl, %al
movzbl %al, %eax
subl %eax, %ebp
addl %ecx, %ebp
movl %ebp, 0xa4(%rsp,%r13,2)
addq $0x4, %r13
cmpq $0xc, %r13
jne 0x2471
movl 0xa0(%rsp), %eax
movl 0xa4(%rsp), %ecx
movl %eax, 0x7c(%rsp)
movl %ecx, 0x98(%rsp)
cmpl %ecx, %eax
movq 0x48(%rsp), %rbp
movq 0x30(%rsp), %rbx
jge 0x2bd1
movl 0xa8(%rsp), %eax
movl 0xac(%rsp), %ecx
movl %eax, 0x68(%rsp)
movl %ecx, 0x78(%rsp)
cmpl %ecx, %eax
jge 0x2bd1
movl 0xb0(%rsp), %edi
movl 0xb4(%rsp), %eax
movl %eax, 0x64(%rsp)
cmpl %eax, %edi
jge 0x2bd1
movq (%r14), %rax
movq %rax, (%rsp)
movq 0x3c8(%r14), %rax
movq 0x18(%rsp), %rsi
movq %rsi, %rcx
shlq $0x4, %rcx
movsd (%rax,%rcx), %xmm0
movsd %xmm0, 0x190(%rsp)
movsd 0x8(%rax,%rcx), %xmm0
movsd %xmm0, 0x198(%rsp)
movsd 0x10(%rax,%rcx), %xmm0
movsd %xmm0, 0x1a0(%rsp)
movsd 0x18(%rax,%rcx), %xmm0
movsd %xmm0, 0x1a8(%rsp)
movsd 0x20(%rax,%rcx), %xmm0
movsd %xmm0, 0x1b0(%rsp)
movsd 0x28(%rax,%rcx), %xmm0
movsd %xmm0, 0x1b8(%rsp)
movq 0x3c0(%r14), %rax
movl (%rax,%rsi,4), %edx
movl 0x4(%rax,%rsi,4), %ecx
movl 0x8(%rax,%rsi,4), %eax
movl 0x2c(%r14), %esi
movl %ecx, 0x14(%rsp)
imull %ecx, %esi
movl %esi, 0x74(%rsp)
movl 0x30(%r14), %ecx
movl %eax, 0x10(%rsp)
imull %eax, %ecx
movl %ecx, 0x60(%rsp)
movl %edx, %eax
negl %eax
movl 0x28(%r14), %ecx
movq %rax, 0x28(%rsp)
imull %eax, %ecx
movq %rcx, 0x160(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x1e0(%rsp)
movaps %xmm0, 0x1d0(%rsp)
movaps %xmm0, 0x1c0(%rsp)
movaps %xmm0, 0x210(%rsp)
movaps %xmm0, 0x200(%rsp)
movaps %xmm0, 0x1f0(%rsp)
movaps %xmm0, 0x100(%rsp)
movaps %xmm0, 0xf0(%rsp)
movaps %xmm0, 0xe0(%rsp)
movaps %xmm0, 0x140(%rsp)
movaps %xmm0, 0x130(%rsp)
movaps %xmm0, 0x120(%rsp)
movsd 0x1697f(%rip), %xmm0    # 0x19008
movsd %xmm0, 0xd0(%rsp)
movq %rdx, %rcx
testl %edx, %edx
je 0x26a6
xorpd %xmm1, %xmm1
movsd %xmm1, 0xd0(%rsp)
movsd %xmm0, 0xc8(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0x26c3
xorpd %xmm1, %xmm1
movsd %xmm1, 0xc8(%rsp)
movsd %xmm0, 0xc0(%rsp)
cmpl $0x0, 0x10(%rsp)
je 0x26df
xorps %xmm0, %xmm0
movsd %xmm0, 0xc0(%rsp)
movl 0x10(%rsp), %eax
movl %eax, %edx
imull %ebp, %edx
movl %edx, 0x5c(%rsp)
movl 0x14(%rsp), %edx
movl %edx, %esi
imull %ebp, %esi
movl %esi, 0x70(%rsp)
movl %eax, %esi
movl 0x54(%rsp), %eax
imull %eax, %esi
movl %esi, 0x58(%rsp)
imull %eax, %edx
movl %edx, 0x6c(%rsp)
movl 0x24(%rsp), %eax
imull %ecx, %eax
movq %rax, 0x168(%rsp)
imull 0x40(%rsp), %ecx
movq %rcx, 0x170(%rsp)
movl %edi, %eax
subl 0x60(%rsp), %eax
movl %eax, 0x80(%rsp)
movl %edi, %eax
subl 0x5c(%rsp), %eax
movl %eax, 0x8c(%rsp)
movl %edi, %eax
subl 0x58(%rsp), %eax
movl %eax, 0x88(%rsp)
movl %edi, %eax
subl 0x10(%rsp), %eax
movl %eax, 0x8(%rsp)
movl 0x68(%rsp), %eax
movl %eax, 0x18(%rsp)
movl %edi, 0x9c(%rsp)
movl 0x18(%rsp), %ecx
movl %ecx, %eax
subl 0x74(%rsp), %eax
movl %eax, 0x84(%rsp)
movl %ecx, %eax
subl 0x70(%rsp), %eax
movl %eax, 0x94(%rsp)
movl %ecx, %eax
subl 0x6c(%rsp), %eax
movl %eax, 0x90(%rsp)
movl %ecx, %eax
subl 0x14(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0x7c(%rsp), %eax
movl %eax, %r15d
movl 0x34(%r14), %r8d
movl 0x38(%r14), %ecx
movl 0x18(%rsp), %esi
movl %r15d, %edx
callq 0x7d53
cltq
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %rax
addq (%rsp), %rax
movq 0xd8(%rsp), %rcx
leaq (%rcx,%rcx,4), %r13
leaq (%rax,%r13,8), %rsi
addq $0x10, %rsi
movq 0x3b8(%r14), %rax
movl (%rax,%rbx,4), %eax
testl %ebp, %ebp
je 0x292c
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jae 0x295e
movq 0x170(%rsp), %rax
leal (%rax,%r15), %edx
movl 0x34(%r14), %r8d
movl 0x38(%r14), %ecx
movl 0x8c(%rsp), %edi
movq %rsi, 0x178(%rsp)
movl 0x94(%rsp), %esi
callq 0x7d53
cltq
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %rax
movq (%rsp), %r12
addq %r12, %rax
movq 0xd8(%rsp), %rcx
leaq (,%rcx,8), %rcx
leaq (%rcx,%rcx,4), %r13
leaq (%rax,%r13), %rdi
addq $0x10, %rdi
movq 0x38(%rsp), %rbp
movsd 0x40(%rbp), %xmm0
movsd 0x48(%rbp), %xmm1
leaq 0xe0(%rsp), %rbx
movq %rbx, %rsi
callq 0x7c16
movq 0x168(%rsp), %rax
leal (%rax,%r15), %edx
movl 0x34(%r14), %r8d
movl 0x38(%r14), %ecx
movl 0x88(%rsp), %edi
movl 0x90(%rsp), %esi
callq 0x7d53
cltq
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %rax
addq %r12, %rax
leaq (%rax,%r13), %rdi
addq $0x10, %rdi
movsd 0x40(%rbp), %xmm0
movsd 0x48(%rbp), %xmm1
leaq 0x1f0(%rsp), %r13
movq %r13, %rsi
callq 0x7c16
movq %r13, %rdi
movq %rbx, %rsi
leaq 0x1c0(%rsp), %rbx
movq %rbx, %rdx
callq 0x12416
movsd 0x1e8(%rsp), %xmm0
mulsd 0x48(%rbp), %xmm0
movsd 0x1e0(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x1c0(%rsp)
movsd 0x40(%rbp), %xmm0
movq 0x48(%rsp), %rbp
movq %rbx, %rdi
movq 0x30(%rsp), %rbx
movq 0x178(%rsp), %rsi
jmp 0x2b35
cmpl $0x3, %eax
ja 0x2b99
movl %eax, %eax
leaq 0x166f2(%rip), %rcx     # 0x19030
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x38(%rsp), %rax
movsd 0x40(%rax), %xmm0
leaq 0x190(%rsp), %rdi
jmp 0x2b35
movq %rbx, %r12
movq %rbp, %rbx
movq %rsi, %rbp
cmpl $0x4, %eax
jne 0x2993
movq 0x160(%rsp), %rax
leal (%rax,%r15), %edx
movl 0x34(%r14), %r8d
movl 0x38(%r14), %ecx
movl 0x80(%rsp), %edi
movl 0x84(%rsp), %esi
jmp 0x2b5e
movq 0x28(%rsp), %rax
leal (%rax,%r15), %edx
movl 0x34(%r14), %r8d
movl 0x38(%r14), %ecx
movl 0x8(%rsp), %edi
jmp 0x2b5a
movq 0x28(%rsp), %rax
leal (%rax,%r15), %edx
movl 0x34(%r14), %r8d
movl 0x38(%r14), %ecx
movl 0x8(%rsp), %edi
movq %rsi, %r12
movl 0xc(%rsp), %esi
callq 0x7d53
cltq
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %rax
addq (%rsp), %rax
leaq (%rax,%r13,8), %rdi
addq $0x10, %rdi
movq 0x38(%rsp), %rbx
movsd 0x40(%rbx), %xmm0
movsd 0x48(%rbx), %xmm1
leaq 0x120(%rsp), %rsi
callq 0x7c16
movsd 0x128(%rsp), %xmm0
mulsd 0xd0(%rsp), %xmm0
movsd %xmm0, 0xe8(%rsp)
movsd 0x130(%rsp), %xmm0
mulsd 0xc8(%rsp), %xmm0
movsd %xmm0, 0xf0(%rsp)
movsd 0x138(%rsp), %xmm0
mulsd 0xc0(%rsp), %xmm0
movsd %xmm0, 0xf8(%rsp)
jmp 0x2ac4
movq 0x28(%rsp), %rax
leal (%rax,%r15), %edx
movl 0x34(%r14), %r8d
movl 0x38(%r14), %ecx
movl 0x8(%rsp), %edi
movq %rsi, %r12
movl 0xc(%rsp), %esi
callq 0x7d53
cltq
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %rax
addq (%rsp), %rax
leaq (%rax,%r13,8), %rdi
addq $0x10, %rdi
movq 0x38(%rsp), %rbx
movsd 0x40(%rbx), %xmm0
movsd 0x48(%rbx), %xmm1
leaq 0x120(%rsp), %rsi
callq 0x7c16
xorpd %xmm0, %xmm0
leaq 0xe8(%rsp), %rax
movupd %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movsd 0x140(%rsp), %xmm0
movsd %xmm0, 0x100(%rsp)
movsd 0x1b8(%rsp), %xmm1
movapd %xmm1, %xmm2
cmpltsd 0x16524(%rip), %xmm2    # 0x19010
movsd 0x148(%rsp), %xmm3
andpd %xmm2, %xmm3
andnpd %xmm1, %xmm2
orpd %xmm3, %xmm2
movlpd %xmm2, 0x108(%rsp)
movsd 0x48(%rbx), %xmm1
mulsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0xe0(%rsp)
movsd 0x40(%rbx), %xmm0
movq 0x30(%rsp), %rbx
leaq 0xe0(%rsp), %rdi
movq %r12, %rsi
callq 0x7cd7
jmp 0x2b99
movq 0x28(%rsp), %rax
leal (%rax,%r15), %edx
movl 0x34(%r14), %r8d
movl 0x38(%r14), %ecx
movl 0x8(%rsp), %edi
movq %rbx, %r12
movq %rbp, %rbx
movq %rsi, %rbp
movl 0xc(%rsp), %esi
callq 0x7d53
cltq
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %rax
addq (%rsp), %rax
movups 0x10(%rax,%r13,8), %xmm0
movupd 0x20(%rax,%r13,8), %xmm1
movups %xmm0, (%rbp)
movupd %xmm1, 0x10(%rbp)
movq 0x30(%rax,%r13,8), %rax
movq %rax, 0x20(%rbp)
movq %rbx, %rbp
movq %r12, %rbx
incl %r15d
cmpl %r15d, 0x98(%rsp)
movl 0x9c(%rsp), %edi
jne 0x27a5
movl 0x18(%rsp), %eax
incl %eax
movl %eax, 0x18(%rsp)
cmpl 0x78(%rsp), %eax
jne 0x2769
incl %edi
cmpl 0x64(%rsp), %edi
jne 0x2729
incq %rbx
movq 0xb8(%rsp), %rax
addq $0x18, %rax
cmpq $0x7, %rbx
jne 0x243a
leal 0x1(%rbp), %eax
addl $-0x2, 0x24(%rsp)
movq 0x40(%rsp), %rcx
decl %ecx
movq %rcx, 0x40(%rsp)
cmpl 0x50(%rsp), %ebp
movl %eax, %ebp
jne 0x241d
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq