// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x197d0
movq -0x10(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x24(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x28(%rbp), %edi
movl -0x24(%rbp), %esi
callq 0x9660
movl -0x6c(%rbp), %edi
movl %eax, %esi
callq 0x9660
movl %eax, -0x30(%rbp)
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x20d0
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x30(%rbp), %eax
jg 0x2577
movl $0x1, -0x58(%rbp)
cmpl $0x6, -0x58(%rbp)
jg 0x2567
movq -0x20(%rbp), %rax
movq 0x398(%rax), %rax
movslq -0x58(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x64(%rbp)
movq -0x20(%rbp), %rax
movq 0x398(%rax), %rax
movslq -0x58(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x60(%rbp)
movq -0x20(%rbp), %rax
movq 0x398(%rax), %rax
movslq -0x58(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x5c(%rbp)
movl $0x0, -0x68(%rbp)
cmpl $0x3, -0x68(%rbp)
jge 0x2525
movq -0x20(%rbp), %rax
addq $0x68, %rax
movslq -0x58(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq -0x68(%rbp), %rcx
movl (%rax,%rcx,8), %eax
movl %eax, -0x74(%rbp)
movl -0x54(%rbp), %edi
movslq -0x68(%rbp), %rax
movl -0x2c(%rbp,%rax,4), %esi
callq 0x9630
movl -0x74(%rbp), %ecx
movslq -0x68(%rbp), %rdx
movl -0x64(%rbp,%rdx,4), %edx
movslq -0x68(%rbp), %rsi
cmpl $0x0, -0x64(%rbp,%rsi,4)
setne %sil
xorb $-0x1, %sil
andb $0x1, %sil
movzbl %sil, %esi
subl %esi, %edx
imull %edx, %eax
addl %eax, %ecx
movslq -0x68(%rbp), %rax
movl %ecx, -0x50(%rbp,%rax,8)
movq -0x20(%rbp), %rax
addq $0x68, %rax
movslq -0x58(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq -0x68(%rbp), %rcx
movl 0x4(%rax,%rcx,8), %eax
movl %eax, -0x70(%rbp)
movl -0x54(%rbp), %edi
movslq -0x68(%rbp), %rax
movl -0x2c(%rbp,%rax,4), %esi
callq 0x9630
movl -0x70(%rbp), %ecx
movslq -0x68(%rbp), %rdx
movl -0x64(%rbp,%rdx,4), %edx
movslq -0x68(%rbp), %rsi
cmpl $0x0, -0x64(%rbp,%rsi,4)
setne %sil
xorb $-0x1, %sil
andb $0x1, %sil
movzbl %sil, %esi
addl %esi, %edx
imull %edx, %eax
addl %eax, %ecx
movslq -0x68(%rbp), %rax
movl -0x2c(%rbp,%rax,4), %eax
cmpl -0x54(%rbp), %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
movslq -0x68(%rbp), %rdx
cmpl $0x0, -0x64(%rbp,%rdx,4)
setne %dl
xorb $-0x1, %dl
xorb $-0x1, %dl
andb $0x1, %dl
movzbl %dl, %edx
imull %edx, %eax
subl %eax, %ecx
movslq -0x68(%rbp), %rax
movl %ecx, -0x4c(%rbp,%rax,8)
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x241c
movl -0x50(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x253d
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x253d
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jl 0x253f
jmp 0x2559
movl -0x58(%rbp), %edi
movl -0x54(%rbp), %esi
leaq -0x50(%rbp), %rdx
movl -0x4(%rbp), %ecx
movq -0x10(%rbp), %r8
movq -0x18(%rbp), %r9
callq 0x2580
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x23b8
jmp 0x2569
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x23a5
addq $0x80, %rsp
popq %rbp
retq