// File: /workspace/github_c_makefile_star2_O2/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 $0x238, %rsp            # imm = 0x238
movq %rsi, %r14
movl %edi, %ebp
movq %rdx, 0x40(%rsp)
callq 0x10bbc
movl 0x40(%r14), %r15d
movl %r15d, 0x124(%rsp)
movl 0x44(%r14), %edi
movl %edi, 0x128(%rsp)
movl 0x48(%r14), %esi
movl %esi, 0x12c(%rsp)
callq 0x7649
movl %r15d, %edi
movl %eax, %esi
callq 0x7649
movl %eax, 0x60(%rsp)
xorps %xmm0, %xmm0
andq $0x0, 0xc0(%rsp)
movaps %xmm0, 0xb0(%rsp)
movslq %ebp, %rax
movq %rax, 0x188(%rsp)
leaq 0xac(%r14), %rax
movq %rax, 0x168(%rsp)
movq $0x0, 0x48(%rsp)
movl $0x0, 0x34(%rsp)
xorl %ebp, %ebp
cmpl 0x60(%rsp), %ebp
jg 0x2bd6
leal (,%rbp,2), %eax
movl %eax, 0x64(%rsp)
movq 0x168(%rsp), %rax
movq %rax, 0xd0(%rsp)
pushq $0x1
popq %rax
movq %rax, 0x28(%rsp)
movq %rbp, 0x50(%rsp)
cmpq $0x7, 0x28(%rsp)
je 0x2bbe
movq 0x3c0(%r14), %rax
imulq $0xc, 0x28(%rsp), %rdx
movq (%rax,%rdx), %rcx
movq %rcx, 0x190(%rsp)
movq %rdx, 0x58(%rsp)
movl 0x8(%rax,%rdx), %eax
movl %eax, 0x198(%rsp)
xorl %r12d, %r12d
cmpq $0xc, %r12
je 0x24d2
movq 0xd0(%rsp), %r13
movl -0x4(%r13,%r12,2), %eax
movl %eax, 0x8(%rsp)
movl 0x124(%rsp,%r12), %ebp
movq 0x50(%rsp), %rbx
movl %ebx, %edi
movl %ebp, %esi
callq 0x7641
movl 0x190(%rsp,%r12), %r15d
cmpl $0x1, %r15d
movl $0x0, %ecx
sbbl %ecx, %ecx
orl %r15d, %ecx
imull %eax, %ecx
addl 0x8(%rsp), %ecx
movl %ecx, 0xb0(%rsp,%r12,2)
movl (%r13,%r12,2), %r13d
movl %ebx, %edi
movl %ebp, %esi
callq 0x7641
xorl %ecx, %ecx
testl %r15d, %r15d
sete %cl
setne %dl
addl %r15d, %ecx
imull %eax, %ecx
cmpl %ebx, %ebp
setl %al
andb %dl, %al
movzbl %al, %eax
subl %eax, %r13d
addl %ecx, %r13d
movl %r13d, 0xb4(%rsp,%r12,2)
addq $0x4, %r12
jmp 0x243c
movl 0xb0(%rsp), %eax
movl 0xb4(%rsp), %ecx
movl %eax, 0x88(%rsp)
movl %ecx, 0xac(%rsp)
cmpl %ecx, %eax
movq 0x50(%rsp), %rbp
jge 0x2bab
movl 0xb8(%rsp), %eax
movl 0xbc(%rsp), %ecx
movl %eax, 0x78(%rsp)
movl %ecx, 0x8c(%rsp)
cmpl %ecx, %eax
jge 0x2bab
movl 0xc0(%rsp), %edi
movl 0xc4(%rsp), %eax
movl %eax, 0x74(%rsp)
cmpl %eax, %edi
jge 0x2bab
movq (%r14), %rax
movq %rax, 0x8(%rsp)
movq 0x3c8(%r14), %rax
imulq $0x30, 0x28(%rsp), %rcx
movsd (%rax,%rcx), %xmm0
movsd %xmm0, 0x1a0(%rsp)
movsd 0x8(%rax,%rcx), %xmm0
movsd %xmm0, 0x1a8(%rsp)
movsd 0x10(%rax,%rcx), %xmm0
movsd %xmm0, 0x1b0(%rsp)
movsd 0x18(%rax,%rcx), %xmm0
movsd %xmm0, 0x1b8(%rsp)
movsd 0x20(%rax,%rcx), %xmm0
movsd %xmm0, 0x1c0(%rsp)
movsd 0x28(%rax,%rcx), %xmm0
movsd %xmm0, 0x1c8(%rsp)
movq 0x3c0(%r14), %rax
movq 0x58(%rsp), %rsi
movl (%rax,%rsi), %edx
movl 0x4(%rax,%rsi), %ecx
movl 0x8(%rax,%rsi), %eax
movl 0x2c(%r14), %esi
movl %ecx, 0x1c(%rsp)
imull %ecx, %esi
movl %esi, 0x84(%rsp)
movl 0x30(%r14), %ecx
movl %eax, 0x18(%rsp)
imull %eax, %ecx
movl %ecx, 0x70(%rsp)
movl %edx, %eax
negl %eax
movl 0x28(%r14), %ecx
movq %rax, 0x38(%rsp)
imull %eax, %ecx
movq %rcx, 0x170(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x1f0(%rsp)
movaps %xmm0, 0x1e0(%rsp)
movaps %xmm0, 0x1d0(%rsp)
movaps %xmm0, 0x220(%rsp)
movaps %xmm0, 0x210(%rsp)
movaps %xmm0, 0x200(%rsp)
movaps %xmm0, 0x110(%rsp)
movaps %xmm0, 0x100(%rsp)
movaps %xmm0, 0xf0(%rsp)
movaps %xmm0, 0x150(%rsp)
movaps %xmm0, 0x140(%rsp)
movaps %xmm0, 0x130(%rsp)
movsd 0x159a9(%rip), %xmm0    # 0x18008
movsd %xmm0, 0xe8(%rsp)
movq %rdx, %rcx
testl %edx, %edx
je 0x267b
xorps %xmm0, %xmm0
movsd %xmm0, 0xe8(%rsp)
movsd 0x15985(%rip), %xmm0    # 0x18008
movsd %xmm0, 0xe0(%rsp)
cmpl $0x0, 0x1c(%rsp)
je 0x269f
xorps %xmm0, %xmm0
movsd %xmm0, 0xe0(%rsp)
movsd 0x15961(%rip), %xmm0    # 0x18008
movsd %xmm0, 0xd8(%rsp)
cmpl $0x0, 0x18(%rsp)
je 0x26c3
xorps %xmm0, %xmm0
movsd %xmm0, 0xd8(%rsp)
movl 0x18(%rsp), %eax
movl %eax, %edx
imull %ebp, %edx
movl %edx, 0x6c(%rsp)
movl 0x1c(%rsp), %edx
movl %edx, %esi
imull %ebp, %esi
movl %esi, 0x80(%rsp)
movl %eax, %esi
movl 0x64(%rsp), %eax
imull %eax, %esi
movl %esi, 0x68(%rsp)
imull %eax, %edx
movl %edx, 0x7c(%rsp)
movl 0x34(%rsp), %eax
imull %ecx, %eax
movq %rax, 0x178(%rsp)
imull 0x48(%rsp), %ecx
movq %rcx, 0x180(%rsp)
cmpl 0x74(%rsp), %edi
jge 0x2bab
movl %edi, %eax
subl 0x70(%rsp), %eax
movl %eax, 0x90(%rsp)
movl %edi, %eax
subl 0x6c(%rsp), %eax
movl %eax, 0x9c(%rsp)
movl %edi, %eax
subl 0x68(%rsp), %eax
movl %eax, 0x98(%rsp)
movl %edi, %eax
subl 0x18(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x78(%rsp), %r12d
movl %edi, 0x58(%rsp)
cmpl 0x8c(%rsp), %r12d
jge 0x2ba4
movl %r12d, %eax
subl 0x84(%rsp), %eax
movl %eax, 0x94(%rsp)
movl %r12d, %eax
subl 0x80(%rsp), %eax
movl %eax, 0xa4(%rsp)
movl %r12d, %eax
subl 0x7c(%rsp), %eax
movl %eax, 0xa0(%rsp)
movl %r12d, %eax
subl 0x1c(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x88(%rsp), %eax
movl %eax, %r15d
movl %r12d, 0xa8(%rsp)
cmpl 0xac(%rsp), %r15d
jge 0x2b9c
movl 0x34(%r14), %r8d
movl 0x38(%r14), %ecx
movl %r12d, %esi
movl %r15d, %edx
callq 0x75ec
cltq
imulq $0x88, %rax, %rax
addq 0x8(%rsp), %rax
imulq $0x28, 0x188(%rsp), %r13
leaq (%rax,%r13), %rsi
addq $0x10, %rsi
movq 0x3b8(%r14), %rax
movq 0x28(%rsp), %rcx
movl (%rax,%rcx,4), %eax
testl %ebp, %ebp
je 0x291f
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jae 0x2951
movq 0x180(%rsp), %rax
leal (%rax,%r15), %edx
movl 0x34(%r14), %r8d
movl 0x38(%r14), %ecx
movl 0x9c(%rsp), %edi
movq %rsi, 0x20(%rsp)
movl 0xa4(%rsp), %esi
callq 0x75ec
cltq
imulq $0x88, %rax, %rax
movq 0x8(%rsp), %r12
addq %r12, %rax
leaq (%rax,%r13), %rdi
addq $0x10, %rdi
movq 0x40(%rsp), %rbp
movsd 0x40(%rbp), %xmm0
movsd 0x48(%rbp), %xmm1
leaq 0xf0(%rsp), %rbx
movq %rbx, %rsi
callq 0x74af
movq 0x178(%rsp), %rax
leal (%rax,%r15), %edx
movl 0x34(%r14), %r8d
movl 0x38(%r14), %ecx
movl 0x98(%rsp), %edi
movl 0xa0(%rsp), %esi
callq 0x75ec
cltq
imulq $0x88, %rax, %rax
addq %r12, %rax
movl 0xa8(%rsp), %r12d
leaq (%rax,%r13), %rdi
addq $0x10, %rdi
movsd 0x40(%rbp), %xmm0
movsd 0x48(%rbp), %xmm1
leaq 0x200(%rsp), %r13
movq %r13, %rsi
callq 0x74af
movq %r13, %rdi
movq %rbx, %rsi
leaq 0x1d0(%rsp), %rbx
movq %rbx, %rdx
callq 0x115e5
movsd 0x1f8(%rsp), %xmm0
mulsd 0x48(%rbp), %xmm0
movsd 0x1f0(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x1d0(%rsp)
movsd 0x40(%rbp), %xmm0
movq 0x50(%rsp), %rbp
movq %rbx, %rdi
jmp 0x2b3f
cmpl $0x3, %eax
ja 0x2b49
movl %eax, %eax
leaq 0x156ff(%rip), %rcx     # 0x18030
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x40(%rsp), %rax
movsd 0x40(%rax), %xmm0
leaq 0x1a0(%rsp), %rdi
jmp 0x2b44
movq %rbp, %rbx
movq %rsi, %rbp
cmpl $0x4, %eax
jne 0x2980
movq 0x170(%rsp), %rax
leal (%rax,%r15), %edx
movl 0x34(%r14), %r8d
movl 0x38(%r14), %ecx
movl 0x90(%rsp), %edi
movl 0x94(%rsp), %esi
jmp 0x2999
movq 0x38(%rsp), %rax
leal (%rax,%r15), %edx
movl 0x34(%r14), %r8d
movl 0x38(%r14), %ecx
movl 0x10(%rsp), %edi
movl 0x14(%rsp), %esi
callq 0x75ec
cltq
imulq $0x88, %rax, %rax
addq 0x8(%rsp), %rax
leaq (%rax,%r13), %rdi
addq $0x10, %rdi
movq %rbp, %rsi
callq 0x2be8
movq %rbx, %rbp
jmp 0x2b49
movq 0x38(%rsp), %rax
leal (%rax,%r15), %edx
movl 0x34(%r14), %r8d
movl 0x38(%r14), %ecx
movl 0x10(%rsp), %edi
movq %rsi, 0x20(%rsp)
movl 0x14(%rsp), %esi
callq 0x75ec
cltq
imulq $0x88, %rax, %rax
addq 0x8(%rsp), %rax
leaq (%rax,%r13), %rdi
addq $0x10, %rdi
movq 0x40(%rsp), %rbx
movsd 0x40(%rbx), %xmm0
movsd 0x48(%rbx), %xmm1
leaq 0x130(%rsp), %rsi
callq 0x74af
movsd 0x138(%rsp), %xmm0
mulsd 0xe8(%rsp), %xmm0
movsd %xmm0, 0xf8(%rsp)
movsd 0x140(%rsp), %xmm0
mulsd 0xe0(%rsp), %xmm0
movsd %xmm0, 0x100(%rsp)
movsd 0x148(%rsp), %xmm0
mulsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0x108(%rsp)
jmp 0x2ad6
movq 0x38(%rsp), %rax
leal (%rax,%r15), %edx
movl 0x34(%r14), %r8d
movl 0x38(%r14), %ecx
movl 0x10(%rsp), %edi
movq %rsi, 0x20(%rsp)
movl 0x14(%rsp), %esi
callq 0x75ec
cltq
imulq $0x88, %rax, %rax
addq 0x8(%rsp), %rax
leaq (%rax,%r13), %rdi
addq $0x10, %rdi
movq 0x40(%rsp), %rbx
movsd 0x40(%rbx), %xmm0
movsd 0x48(%rbx), %xmm1
leaq 0x130(%rsp), %rsi
callq 0x74af
leaq 0xf8(%rsp), %rax
andq $0x0, 0x10(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movsd 0x150(%rsp), %xmm0
movsd %xmm0, 0x110(%rsp)
movsd 0x1c8(%rsp), %xmm1
movapd %xmm1, %xmm2
cmpltsd 0x15512(%rip), %xmm2    # 0x18010
movsd 0x158(%rsp), %xmm3
andpd %xmm2, %xmm3
andnpd %xmm1, %xmm2
orpd %xmm3, %xmm2
movlpd %xmm2, 0x118(%rsp)
movsd 0x48(%rbx), %xmm1
mulsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0xf0(%rsp)
movsd 0x40(%rbx), %xmm0
leaq 0xf0(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x7570
incl %r15d
movl 0x58(%rsp), %edi
jmp 0x27af
movq 0x38(%rsp), %rax
leal (%rax,%r15), %edx
movl 0x34(%r14), %r8d
movl 0x38(%r14), %ecx
movl 0x10(%rsp), %edi
movq %rbp, %rbx
movq %rsi, %rbp
movl 0x14(%rsp), %esi
callq 0x75ec
cltq
imulq $0x88, %rax, %rax
addq 0x8(%rsp), %rax
leaq (%rax,%r13), %rdi
addq $0x10, %rdi
movq %rbp, %rsi
movq %rbx, %rbp
callq 0x2be8
jmp 0x2b49
incl %r12d
jmp 0x2754
incl %edi
jmp 0x2710
incq 0x28(%rsp)
addq $0x18, 0xd0(%rsp)
jmp 0x2404
incl %ebp
addl $-0x2, 0x34(%rsp)
movq 0x48(%rsp), %rax
decl %eax
movq %rax, 0x48(%rsp)
jmp 0x23d2
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq