// File: /workspace/github_c_makefile_star2_O3/mohuangrui[P]ArtraCFD/immersed_boundary.c
// Function: TreatImmersedBoundary
void TreatImmersedBoundary(const int tn, Space *space, const Model *model)
{
    const Partition *const part = &(space->part);
    Node *const node = space->node;
    const Geometry *const geo = &(space->geo);
    const IntVec nMin = {part->ns[PIN][X][MIN], part->ns[PIN][Y][MIN], part->ns[PIN][Z][MIN]};
    const IntVec nMax = {part->ns[PIN][X][MAX], part->ns[PIN][Y][MAX], part->ns[PIN][Z][MAX]};
    const RealVec sMin = {part->domain[X][MIN], part->domain[Y][MIN], part->domain[Z][MIN]};
    const RealVec d = {part->d[X], part->d[Y], part->d[Z]};
    const RealVec dd = {part->dd[X], part->dd[Y], part->dd[Z]};
    const IntVec ng = {part->ng[X], part->ng[Y], part->ng[Z]};
    const Polyhedron *poly = NULL;
    int idx = 0; /* linear array index math variable */
    IntVec nI = {0}; /* image node */
    IntVec nG = {0}; /* ghost node */
    RealVec pG = {0.0}; /* ghost point */
    RealVec pO = {0.0}; /* boundary point */
    RealVec pI = {0.0}; /* image point */
    RealVec N = {0.0}; /* normal */
    Real UoG[DIMUo] = {0.0};
    Real UoO[DIMUo] = {0.0};
    Real UoI[DIMUo] = {0.0};
    Real weightSum = 0.0;
    int box[DIMS][LIMIT] = {{0}}; /* bounding box in node space */
    for (int n = 0; n < geo->totN; ++n) {
        poly = geo->poly + n;
        /* determine search range according to bounding box of polyhedron and valid node space */
        for (int s = 0; s < DIMS; ++s) {
            box[s][MIN] = ConfineSpace(MapNode(poly->box[s][MIN], sMin[s], dd[s], ng[s]), nMin[s], nMax[s]);
            box[s][MAX] = ConfineSpace(MapNode(poly->box[s][MAX], sMin[s], dd[s], ng[s]), nMin[s], nMax[s]) + 1;
        }
        /* treat ghost nodes */
        for (int r = 1; r <= part->gl; ++r) { /* layer by layer treatment */
            for (int k = box[Z][MIN]; k < box[Z][MAX]; ++k) {
                for (int j = box[Y][MIN]; j < box[Y][MAX]; ++j) {
                    for (int i = box[X][MIN]; i < box[X][MAX]; ++i) {
                        idx = IndexNode(k, j, i, part->n[Y], part->n[X]);
                        if ((r != node[idx].gst) || (n + 1 != node[idx].did)) {
                            continue;
                        }
                        pG[X] = MapPoint(i, sMin[X], d[X], ng[X]);
                        pG[Y] = MapPoint(j, sMin[Y], d[Y], ng[Y]);
                        pG[Z] = MapPoint(k, sMin[Z], d[Z], ng[Z]);
                        if (model->ibmLayer >= r) { /* immersed boundary treatment */
                            ComputeGeometricData(pG, node[idx].fid, poly, pO, pI, N);
                            nI[X] = MapNode(pI[X], sMin[X], dd[X], ng[X]);
                            nI[Y] = MapNode(pI[Y], sMin[Y], dd[Y], ng[Y]);
                            nI[Z] = MapNode(pI[Z], sMin[Z], dd[Z], ng[Z]);
                            /*
                             * When extremely strong discontinuities exist in the
                             * domain of dependence of inverse distance weighting,
                             * WENO's idea may be adopted to avoid discontinuous
                             * stencils and to only use smooth stencils. However,
                             * the algorithm will be too complex.
                             */
                            ReconstructFlow(tn, nI, pI, R, TYPED, 0, poly, part, node, model, pO, N, UoO, UoI);
                            DoMethodOfImage(UoI, UoO, UoG);
                        } else { /* inverse distance weighting */
                            nG[X] = i; nG[Y] = j; nG[Z] = k;
                            weightSum = InverseDistanceWeighting(tn, nG, pG, 1, r - 1, n + 1, part, node, model, UoG);
                            Normalize(DIMUo, weightSum, UoG);
                        }
                        UoG[0] = UoG[4] / (UoG[5] * model->gasR); /* compute density */
                        MapConservative(model->gamma, UoG, node[idx].U[tn]);
                    }
                }
            }
        }
    }
    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x358, %rsp            # imm = 0x358
movq %rdx, 0xf0(%rsp)
movq %rsi, %r14
movl %edi, 0xc(%rsp)
movq (%rsi), %r15
movl 0x90(%rsi), %eax
movl %eax, 0x114(%rsp)
movl 0x98(%rsi), %eax
movl %eax, 0x118(%rsp)
movl 0xa0(%rsi), %eax
movl %eax, 0x11c(%rsp)
movl 0x94(%rsi), %eax
movl %eax, 0x108(%rsp)
movl 0x9c(%rsi), %eax
movl %eax, 0x10c(%rsp)
movl 0xa4(%rsi), %eax
movl %eax, 0x110(%rsp)
movsd 0x3f0(%rsi), %xmm0
movsd %xmm0, 0x300(%rsp)
movsd 0x400(%rsi), %xmm1
movsd %xmm1, 0x308(%rsp)
movsd 0x410(%rsi), %xmm2
movsd %xmm2, 0x310(%rsp)
movsd 0x58(%rsi), %xmm3
movsd %xmm3, 0x238(%rsp)
movsd 0x60(%rsi), %xmm3
movsd %xmm3, 0x230(%rsp)
movsd 0x68(%rsi), %xmm3
movsd %xmm3, 0x228(%rsp)
movups 0x70(%rsi), %xmm3
movaps %xmm3, 0x1c0(%rsp)
movaps %xmm3, 0x2e0(%rsp)
movsd 0x80(%rsi), %xmm3
movsd %xmm3, 0x208(%rsp)
movsd %xmm3, 0x2f0(%rsp)
movl 0x40(%rsi), %edx
movl %edx, 0xfc(%rsp)
movl 0x44(%rsi), %esi
movl %esi, 0x100(%rsp)
movl 0x48(%r14), %edi
movl %edi, 0x104(%rsp)
xorl %eax, %eax
movl %eax, 0x70(%rsp)
movq %rax, 0x68(%rsp)
movl %eax, 0x60(%rsp)
movq %rax, 0x58(%rsp)
movq %rax, 0x1b0(%rsp)
xorpd %xmm3, %xmm3
movapd %xmm3, 0x1a0(%rsp)
movq %rax, 0x190(%rsp)
movapd %xmm3, 0x180(%rsp)
movq %rax, 0x170(%rsp)
movapd %xmm3, 0x160(%rsp)
movq %rax, 0x200(%rsp)
movapd %xmm3, 0x1f0(%rsp)
movapd %xmm3, 0x260(%rsp)
movapd %xmm3, 0x250(%rsp)
movapd %xmm3, 0x240(%rsp)
movapd %xmm3, 0x2d0(%rsp)
movapd %xmm3, 0x2c0(%rsp)
movapd %xmm3, 0x2b0(%rsp)
movapd %xmm3, 0x150(%rsp)
movapd %xmm3, 0x140(%rsp)
movapd %xmm3, 0x130(%rsp)
movq %rax, 0xa0(%rsp)
movapd %xmm3, 0x90(%rsp)
cmpl %eax, 0x8(%r14)
jle 0x12404
leaq 0x28(%r14), %rax
movq %rax, 0xd0(%rsp)
movslq 0xc(%rsp), %rax
movq %rax, 0x220(%rsp)
movapd 0x1c0(%rsp), %xmm3
unpckhpd %xmm3, %xmm3            # xmm3 = xmm3[1,1]
movapd %xmm3, 0x1c0(%rsp)
xorl %r13d, %r13d
movq %r15, 0x38(%rsp)
movsd %xmm0, 0xe8(%rsp)
movsd %xmm1, 0xe0(%rsp)
movsd %xmm2, 0xd8(%rsp)
movl %edx, 0x88(%rsp)
movl %esi, 0x34(%rsp)
movq %r14, 0x48(%rsp)
movl %edi, 0x30(%rsp)
movq 0x18(%r14), %rax
movq %r13, 0x18(%rsp)
imulq $0x238, %r13, %rcx      # imm = 0x238
leaq (%rax,%rcx), %rdx
movq %rdx, 0x50(%rsp)
leaq (%rax,%rcx), %rbx
addq $0x1d8, %rbx            # imm = 0x1D8
xorl %r15d, %r15d
movsd -0x8(%rbx,%r15,4), %xmm0
movsd 0x300(%rsp,%r15,2), %xmm1
movsd %xmm1, 0x40(%rsp)
movsd 0x2e0(%rsp,%r15,2), %xmm2
movsd %xmm2, 0x10(%rsp)
movl 0xfc(%rsp,%r15), %ebp
movl %ebp, %edi
callq 0x7d83
movl 0x114(%rsp,%r15), %r12d
movl 0x108(%rsp,%r15), %r13d
movl %eax, %edi
movl %r12d, %esi
movl %r13d, %edx
callq 0x7d9a
movl %eax, 0x90(%rsp,%r15,2)
movsd (%rbx,%r15,4), %xmm0
movsd 0x40(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
movl %ebp, %edi
callq 0x7d83
movl %eax, %edi
movl %r12d, %esi
movl %r13d, %edx
callq 0x7d9a
incl %eax
movl %eax, 0x94(%rsp,%r15,2)
addq $0x4, %r15
cmpq $0xc, %r15
jne 0x11bf1
movl 0x4c(%r14), %eax
testl %eax, %eax
jle 0x123ef
movl 0xa0(%rsp), %r8d
movl 0xa4(%rsp), %ecx
movl %ecx, 0x28(%rsp)
movl 0x98(%rsp), %ecx
movl %ecx, 0x7c(%rsp)
movl 0x9c(%rsp), %ecx
movl %ecx, 0x2c(%rsp)
movl 0x90(%rsp), %ecx
movl %ecx, 0x80(%rsp)
movl 0x94(%rsp), %r12d
movq 0x18(%rsp), %r13
incq %r13
movq 0x50(%rsp), %rcx
addq $0xb0, %rcx
movq %rcx, 0x210(%rsp)
movl $0x1, %ecx
movq %rcx, 0x20(%rsp)
movq 0x38(%rsp), %r15
movq %r13, 0x18(%rsp)
movl %r8d, 0x78(%rsp)
movl %r12d, 0x8c(%rsp)
cmpl 0x28(%rsp), %r8d
jge 0x123d6
movq 0x20(%rsp), %rax
decl %eax
movl %eax, 0x84(%rsp)
movl %r8d, 0x10(%rsp)
movl 0x7c(%rsp), %eax
movl %eax, %esi
cmpl 0x2c(%rsp), %eax
jge 0x123b9
movl 0x80(%rsp), %eax
movl %eax, %ebp
cmpl %r12d, %eax
movl %esi, 0x40(%rsp)
jge 0x123ad
movl 0x34(%r14), %r8d
movl 0x38(%r14), %ecx
movl 0x10(%rsp), %edi
movl %ebp, %edx
callq 0x7d53
cltq
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %rbx
movq 0x20(%rsp), %rax
cmpl 0xc(%r15,%rbx), %eax
jne 0x1239e
addq %r15, %rbx
movl (%rbx), %eax
cmpq %rax, %r13
jne 0x1239e
movl %ebp, %edi
movsd 0xe8(%rsp), %xmm0
movsd 0x238(%rsp), %xmm1
movl 0x88(%rsp), %r12d
movl %r12d, %esi
callq 0x7db8
movsd %xmm0, 0x1a0(%rsp)
movl 0x40(%rsp), %r14d
movl %r14d, %edi
movsd 0xe0(%rsp), %xmm0
movsd 0x230(%rsp), %xmm1
movl 0x34(%rsp), %esi
callq 0x7db8
movsd %xmm0, 0x1a8(%rsp)
movl 0x10(%rsp), %r13d
movl %r13d, %edi
movsd 0xd8(%rsp), %xmm0
movsd 0x228(%rsp), %xmm1
movl 0x30(%rsp), %esi
callq 0x7db8
movsd %xmm0, 0x1b0(%rsp)
movq 0xf0(%rsp), %r15
movq 0x20(%rsp), %rax
cmpl %eax, 0x20(%r15)
jge 0x11ea9
movl %ebp, 0x58(%rsp)
movl %r14d, 0x5c(%rsp)
movl %r13d, 0x60(%rsp)
movl 0xc(%rsp), %edi
leaq 0x58(%rsp), %rsi
leaq 0x1a0(%rsp), %rdx
movl $0x1, %ecx
movl 0x84(%rsp), %r8d
movq 0x18(%rsp), %r13
movl %r13d, %r9d
leaq 0x240(%rsp), %r12
pushq %r12
pushq %r15
pushq 0x48(%rsp)
pushq 0xe8(%rsp)
callq 0x12449
addq $0x20, %rsp
movl $0x6, %edi
movq %r12, %rsi
callq 0x8053
movsd 0x260(%rsp), %xmm0
movsd 0x268(%rsp), %xmm1
movq 0x48(%rsp), %r14
jmp 0x1235c
movl 0x4(%rbx), %esi
leaq 0x1a0(%rsp), %rdi
movq 0x50(%rsp), %r13
movq %r13, %rdx
leaq 0x180(%rsp), %rcx
leaq 0x160(%rsp), %r14
movq %r14, %r8
leaq 0x1f0(%rsp), %r9
callq 0xb5ce
movsd 0x160(%rsp), %xmm0
movsd 0x2e0(%rsp), %xmm2
movsd 0xe8(%rsp), %xmm1
movl %r12d, %edi
callq 0x7d83
movl %eax, 0x68(%rsp)
movsd 0x168(%rsp), %xmm0
movsd 0xe0(%rsp), %xmm1
movaps 0x1c0(%rsp), %xmm2
movl 0x34(%rsp), %edi
callq 0x7d83
movl %eax, 0x6c(%rsp)
movsd 0x170(%rsp), %xmm0
movsd 0xd8(%rsp), %xmm1
movsd 0x208(%rsp), %xmm2
movl 0x30(%rsp), %edi
callq 0x7d83
movl %eax, 0x70(%rsp)
movl 0xc(%rsp), %edi
leaq 0x68(%rsp), %rsi
movq %r14, %rdx
movl $0x2, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
xorl %r9d, %r9d
leaq 0x130(%rsp), %rax
pushq %rax
pushq %r15
pushq 0x48(%rsp)
pushq 0xe8(%rsp)
callq 0x12449
addq $0x20, %rsp
movapd %xmm0, %xmm1
movsd 0x7071(%rip), %xmm0     # 0x19008
movsd %xmm1, 0x218(%rsp)
divsd %xmm1, %xmm0
movapd %xmm0, 0x120(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0xb0(%rsp)
movq $0x0, 0xc0(%rsp)
movsd 0x180(%rsp), %xmm0
movsd 0x188(%rsp), %xmm1
subsd 0x20(%r13), %xmm0
movsd %xmm0, 0x320(%rsp)
subsd 0x28(%r13), %xmm1
movsd %xmm1, 0x328(%rsp)
movsd 0x190(%rsp), %xmm0
subsd 0x30(%r13), %xmm0
movsd %xmm0, 0x330(%rsp)
movq 0x210(%rsp), %rdi
leaq 0x320(%rsp), %rsi
leaq 0xb0(%rsp), %r14
movq %r14, %rdx
callq 0x7eee
movsd 0x80(%r13), %xmm3
addsd 0xb0(%rsp), %xmm3
movsd %xmm3, 0xb0(%rsp)
movsd 0x88(%r13), %xmm2
addsd 0xb8(%rsp), %xmm2
movsd %xmm2, 0xb8(%rsp)
movsd 0x90(%r13), %xmm0
addsd 0xc0(%rsp), %xmm0
movsd %xmm0, 0xc0(%rsp)
movsd 0x1b8(%r13), %xmm1
ucomisd 0x6f80(%rip), %xmm1     # 0x19010
jbe 0x1209b
unpcklpd %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0]
jmp 0x121d9
movupd 0x138(%rsp), %xmm0
movapd 0x120(%rsp), %xmm2
movapd %xmm2, %xmm1
unpcklpd %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0]
mulpd %xmm0, %xmm1
movapd %xmm1, 0x340(%rsp)
movsd 0x148(%rsp), %xmm0
mulsd %xmm2, %xmm0
movsd %xmm0, 0x350(%rsp)
xorl %eax, %eax
movq %rax, 0x2a0(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x290(%rsp)
movq %rax, 0x280(%rsp)
movapd %xmm0, 0x270(%rsp)
leaq 0x1f0(%rsp), %r13
movq %r13, %rdi
leaq 0x290(%rsp), %r15
movq %r15, %rsi
leaq 0x270(%rsp), %r12
movq %r12, %rdx
callq 0x7f30
movq %r14, %rdi
movq %r13, %rsi
callq 0x7e36
movapd %xmm0, 0x1e0(%rsp)
leaq 0x340(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x7e36
movapd %xmm0, 0x1d0(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x7e36
movapd 0x1d0(%rsp), %xmm5
movapd %xmm5, %xmm2
unpcklpd %xmm5, %xmm2            # xmm2 = xmm2[0],xmm5[0]
mulpd 0x290(%rsp), %xmm2
movapd 0x1e0(%rsp), %xmm4
movapd %xmm4, %xmm1
unpcklpd %xmm4, %xmm1            # xmm1 = xmm1[0],xmm4[0]
mulpd 0x1f0(%rsp), %xmm1
addpd %xmm2, %xmm1
movapd %xmm0, %xmm3
unpcklpd %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
mulpd 0x270(%rsp), %xmm3
addpd %xmm1, %xmm3
movapd %xmm5, %xmm2
mulsd 0x2a0(%rsp), %xmm2
movapd %xmm4, %xmm1
mulsd 0x200(%rsp), %xmm1
addsd %xmm2, %xmm1
mulsd 0x280(%rsp), %xmm0
addsd %xmm1, %xmm0
movq 0x48(%rsp), %r14
movapd %xmm3, 0x1d0(%rsp)
movupd %xmm3, 0x2b8(%rsp)
movapd %xmm0, 0x1e0(%rsp)
movsd %xmm0, 0x2c8(%rsp)
movsd 0x150(%rsp), %xmm0
movapd 0x120(%rsp), %xmm2
mulsd %xmm2, %xmm0
movsd %xmm0, 0x2d0(%rsp)
mulsd 0x158(%rsp), %xmm2
movq 0x50(%rsp), %rax
movsd 0x1b0(%rax), %xmm0
movapd %xmm0, %xmm1
cmpltsd 0x6dcc(%rip), %xmm1     # 0x19010
andpd %xmm1, %xmm2
andnpd %xmm0, %xmm1
orpd %xmm2, %xmm1
movlpd %xmm1, 0x2d8(%rsp)
movsd 0x88(%r14), %xmm0
movsd %xmm0, 0x120(%rsp)
leaq 0x160(%rsp), %rdi
leaq 0x180(%rsp), %rsi
callq 0x7e85
movsd 0x120(%rsp), %xmm1
maxsd %xmm0, %xmm1
movsd 0x6d73(%rip), %xmm3     # 0x19008
divsd %xmm1, %xmm3
movapd %xmm3, %xmm1
unpcklpd %xmm3, %xmm1            # xmm1 = xmm1[0],xmm3[0]
xorl %eax, %eax
leaq 0x240(%rsp), %r12
movq 0x18(%rsp), %r13
movapd 0x2b0(%rsp,%rax,8), %xmm2
mulpd %xmm1, %xmm2
addpd 0x130(%rsp,%rax,8), %xmm2
movapd %xmm2, 0x130(%rsp,%rax,8)
addq $0x2, %rax
cmpq $0x6, %rax
jne 0x122b0
movsd 0x218(%rsp), %xmm0
addsd %xmm3, %xmm0
movl $0x6, %edi
leaq 0x130(%rsp), %rsi
callq 0x8053
movapd 0x1d0(%rsp), %xmm1
addpd %xmm1, %xmm1
movupd 0x138(%rsp), %xmm0
subpd %xmm0, %xmm1
movupd %xmm1, 0x248(%rsp)
movapd 0x1e0(%rsp), %xmm0
addsd %xmm0, %xmm0
subsd 0x148(%rsp), %xmm0
movsd %xmm0, 0x258(%rsp)
movapd 0x150(%rsp), %xmm0
movapd %xmm0, 0x260(%rsp)
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
movq 0xf0(%rsp), %r15
mulsd 0x48(%r15), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x240(%rsp)
movsd 0x40(%r15), %xmm0
movq 0x220(%rsp), %rax
leaq (%rax,%rax,4), %rax
leaq (%rbx,%rax,8), %rsi
addq $0x10, %rsi
movq %r12, %rdi
callq 0x7cd7
movq 0x38(%rsp), %r15
movl 0x8c(%rsp), %r12d
incl %ebp
cmpl %r12d, %ebp
movl 0x40(%rsp), %esi
jne 0x11d56
incl %esi
cmpl 0x2c(%rsp), %esi
jne 0x11d40
movl 0x10(%rsp), %eax
incl %eax
movl %eax, 0x10(%rsp)
cmpl 0x28(%rsp), %eax
jne 0x11d30
movl 0x4c(%r14), %eax
movl 0x78(%rsp), %r8d
movq 0x20(%rsp), %r9
leal 0x1(%r9), %ecx
cmpl %eax, %r9d
movq %rcx, 0x20(%rsp)
jl 0x11d12
jmp 0x123f7
movq 0x18(%rsp), %r13
incq %r13
movslq 0x8(%r14), %rax
cmpq %rax, %r13
jl 0x11bca
addq $0x358, %rsp            # imm = 0x358
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq