// File: /workspace/github_c_makefile_star2_O2/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 $0x368, %rsp            # imm = 0x368
movq %rdx, 0xe8(%rsp)
movq %rsi, %r14
movq (%rsi), %rbp
movl 0x90(%rsi), %eax
movl %eax, 0x124(%rsp)
movl 0x98(%rsi), %eax
movl %eax, 0x128(%rsp)
movl 0xa0(%rsi), %eax
movl %eax, 0x12c(%rsp)
movl 0x94(%rsi), %eax
movl %eax, 0x118(%rsp)
movl 0x9c(%rsi), %eax
movl %eax, 0x11c(%rsp)
movl 0xa4(%rsi), %eax
movl %eax, 0x120(%rsp)
movsd 0x3f0(%rsi), %xmm0
movsd %xmm0, 0x130(%rsp)
movsd 0x400(%rsi), %xmm0
movsd %xmm0, 0x138(%rsp)
movsd 0x410(%rsi), %xmm0
movsd %xmm0, 0x140(%rsp)
movsd 0x58(%rsi), %xmm0
movsd %xmm0, 0x1f8(%rsp)
movsd 0x60(%rsi), %xmm0
movsd %xmm0, 0x1f0(%rsp)
movsd 0x68(%rsi), %xmm0
movsd %xmm0, 0x1e8(%rsp)
movups 0x70(%rsi), %xmm0
movaps %xmm0, 0x330(%rsp)
movsd 0x80(%rsi), %xmm1
movsd %xmm1, 0x1d0(%rsp)
movsd %xmm1, 0x340(%rsp)
movl 0x40(%rsi), %ecx
movl %ecx, 0x10c(%rsp)
movl 0x44(%rsi), %edx
movl %edx, 0x110(%rsp)
movl 0x48(%rsi), %esi
leaq 0xb0(%rsp), %rax
andl $0x0, 0x8(%rax)
andq $0x0, (%rax)
leaq 0xa0(%rsp), %rax
andl $0x0, 0x8(%rax)
movl %esi, 0x114(%rsp)
andq $0x0, (%rax)
leaq 0x1b0(%rsp), %rax
andq $0x0, 0x10(%rax)
xorpd %xmm1, %xmm1
movapd %xmm1, (%rax)
leaq 0x190(%rsp), %rax
movapd %xmm1, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x170(%rsp), %rax
movapd %xmm1, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x230(%rsp), %rax
andq $0x0, 0x10(%rax)
movapd %xmm1, (%rax)
leaq 0x290(%rsp), %rax
movapd %xmm1, 0x20(%rax)
movapd %xmm1, 0x10(%rax)
movapd %xmm1, (%rax)
leaq 0x300(%rsp), %rax
movapd %xmm1, 0x20(%rax)
movapd %xmm1, 0x10(%rax)
movapd %xmm1, (%rax)
leaq 0x200(%rsp), %rax
movapd %xmm1, 0x20(%rax)
movapd %xmm1, 0x10(%rax)
movapd %xmm1, (%rax)
andq $0x0, 0x90(%rsp)
movapd %xmm1, 0x80(%rsp)
movaps %xmm0, 0x2f0(%rsp)
movhlps %xmm0, %xmm0            # xmm0 = xmm0[1,1]
movaps %xmm0, 0x2e0(%rsp)
movl %edi, 0x1c(%rsp)
movslq %edi, %rax
imulq $0x28, %rax, %rax
movq %rax, 0x1e0(%rsp)
leaq 0x28(%r14), %rax
movq %rax, 0xe0(%rsp)
movl $0x1d8, %eax            # imm = 0x1D8
movq %rax, 0xd8(%rsp)
xorl %r12d, %r12d
movq %rbp, 0x30(%rsp)
movl %ecx, 0x68(%rsp)
movl %edx, 0x24(%rsp)
movq %r14, 0x40(%rsp)
movl %esi, 0x20(%rsp)
movslq 0x8(%r14), %rax
cmpq %rax, %r12
jge 0x115d3
movq 0x18(%r14), %rcx
imulq $0x238, %r12, %rax      # imm = 0x238
addq %rcx, %rax
movq %rax, 0x48(%rsp)
addq 0xd8(%rsp), %rcx
movq %rcx, 0x8(%rsp)
xorl %ebp, %ebp
movq %r12, 0x28(%rsp)
cmpq $0xc, %rbp
je 0x10eb6
movq 0x8(%rsp), %rbx
movsd -0x8(%rbx,%rbp,4), %xmm0
movsd 0x130(%rsp,%rbp,2), %xmm1
movsd %xmm1, 0x38(%rsp)
movsd 0x330(%rsp,%rbp,2), %xmm2
movsd %xmm2, 0x10(%rsp)
movl 0x10c(%rsp,%rbp), %r15d
movl %r15d, %edi
callq 0x761c
movl 0x124(%rsp,%rbp), %r12d
movl 0x118(%rsp,%rbp), %r13d
movl %eax, %edi
movl %r12d, %esi
movl %r13d, %edx
callq 0x7633
movl %eax, 0x80(%rsp,%rbp,2)
movsd (%rbx,%rbp,4), %xmm0
movsd 0x38(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
movl %r15d, %edi
callq 0x761c
movl %eax, %edi
movl %r12d, %esi
movq 0x28(%rsp), %r12
movl %r13d, %edx
callq 0x7633
incl %eax
movl %eax, 0x84(%rsp,%rbp,2)
addq $0x4, %rbp
jmp 0x10e12
incq %r12
movq 0x48(%rsp), %rax
addq $0xb0, %rax
movq %rax, 0x1d8(%rsp)
movl 0x90(%rsp), %eax
movl %eax, 0x50(%rsp)
movl 0x94(%rsp), %eax
movl %eax, 0x58(%rsp)
movl 0x88(%rsp), %eax
movl %eax, 0x54(%rsp)
movl 0x8c(%rsp), %eax
movl %eax, 0x60(%rsp)
movl 0x80(%rsp), %eax
movl %eax, 0x5c(%rsp)
movl 0x84(%rsp), %r15d
movsd 0x130(%rsp), %xmm0
movsd 0x138(%rsp), %xmm1
pushq $0x1
popq %rax
movq 0x30(%rsp), %rbp
movq %r12, 0x28(%rsp)
movl %r15d, 0x6c(%rsp)
movsd %xmm0, 0xf8(%rsp)
movsd %xmm1, 0xf0(%rsp)
cmpl 0x4c(%r14), %eax
jg 0x115c2
movq %rax, 0x8(%rsp)
decl %eax
movl %eax, 0x64(%rsp)
movl 0x50(%rsp), %eax
movl 0x54(%rsp), %esi
movl %eax, 0x10(%rsp)
cmpl 0x58(%rsp), %eax
jge 0x115b6
movl 0x5c(%rsp), %r13d
cmpl 0x60(%rsp), %esi
movl %esi, 0x38(%rsp)
jl 0x1159b
jmp 0x115ab
movl 0x34(%r14), %r8d
movl 0x38(%r14), %ecx
movl 0x10(%rsp), %edi
movl %r13d, %edx
callq 0x75ec
cltq
imulq $0x88, %rax, %rbx
movq 0x8(%rsp), %rax
cmpl 0xc(%rbp,%rbx), %eax
jne 0x11594
addq %rbp, %rbx
movl (%rbx), %eax
cmpq %rax, %r12
jne 0x11594
movl %r13d, %edi
movsd 0xf8(%rsp), %xmm0
movsd 0x1f8(%rsp), %xmm1
movl 0x68(%rsp), %r15d
movl %r15d, %esi
callq 0x7651
movsd %xmm0, 0x1b0(%rsp)
movl 0x38(%rsp), %r14d
movl %r14d, %edi
movsd 0xf0(%rsp), %xmm0
movsd 0x1f0(%rsp), %xmm1
movl 0x24(%rsp), %esi
callq 0x7651
movsd %xmm0, 0x1b8(%rsp)
movsd 0x140(%rsp), %xmm0
movl 0x10(%rsp), %r12d
movl %r12d, %edi
movsd %xmm0, 0x70(%rsp)
movsd 0x1e8(%rsp), %xmm1
movl 0x20(%rsp), %esi
callq 0x7651
movsd %xmm0, 0x1c0(%rsp)
movq 0xe8(%rsp), %rbp
movq 0x8(%rsp), %rax
cmpl %eax, 0x20(%rbp)
jge 0x110df
movl %r13d, 0xa0(%rsp)
movl %r14d, 0xa4(%rsp)
movl %r12d, 0xa8(%rsp)
movl 0x1c(%rsp), %edi
leaq 0xa0(%rsp), %rsi
leaq 0x1b0(%rsp), %rdx
pushq $0x1
popq %rcx
movl 0x64(%rsp), %r8d
movq 0x28(%rsp), %r12
movl %r12d, %r9d
leaq 0x290(%rsp), %r15
pushq %r15
pushq %rbp
pushq 0x40(%rsp)
pushq 0xf8(%rsp)
callq 0x11618
addq $0x20, %rsp
pushq $0x6
popq %rdi
movq %r15, %rsi
callq 0x786c
movsd 0x2b0(%rsp), %xmm0
movsd 0x2b8(%rsp), %xmm1
movq 0x40(%rsp), %r14
jmp 0x1155b
movl 0x4(%rbx), %esi
leaq 0x1b0(%rsp), %rdi
movq 0x48(%rsp), %r12
movq %r12, %rdx
leaq 0x190(%rsp), %rcx
leaq 0x170(%rsp), %r14
movq %r14, %r8
leaq 0x230(%rsp), %r9
callq 0xad8e
movsd 0x170(%rsp), %xmm0
movsd 0xf8(%rsp), %xmm1
movaps 0x2f0(%rsp), %xmm2
movl %r15d, %edi
callq 0x761c
movl %eax, 0xb0(%rsp)
movsd 0x178(%rsp), %xmm0
movsd 0xf0(%rsp), %xmm1
movaps 0x2e0(%rsp), %xmm2
movl 0x24(%rsp), %edi
callq 0x761c
movl %eax, 0xb4(%rsp)
movsd 0x180(%rsp), %xmm0
movsd 0x70(%rsp), %xmm1
movsd 0x1d0(%rsp), %xmm2
movl 0x20(%rsp), %edi
callq 0x761c
movl %eax, 0xb8(%rsp)
movl 0x1c(%rsp), %edi
leaq 0xb0(%rsp), %rsi
movq %r14, %rdx
pushq $0x2
popq %rcx
pushq $-0x1
popq %r8
xorl %r9d, %r9d
leaq 0x200(%rsp), %rax
pushq %rax
pushq %rbp
pushq 0x40(%rsp)
pushq 0xf8(%rsp)
callq 0x11618
addq $0x20, %rsp
movsd %xmm0, 0x100(%rsp)
movsd 0x6e33(%rip), %xmm1     # 0x18008
divsd %xmm0, %xmm1
movapd %xmm1, 0x70(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0xc0(%rsp)
andq $0x0, 0xd0(%rsp)
movsd 0x190(%rsp), %xmm0
movsd 0x198(%rsp), %xmm1
subsd 0x20(%r12), %xmm0
movsd %xmm0, 0x2c0(%rsp)
subsd 0x28(%r12), %xmm1
movsd %xmm1, 0x2c8(%rsp)
movsd 0x1a0(%rsp), %xmm0
subsd 0x30(%r12), %xmm0
movsd %xmm0, 0x2d0(%rsp)
movq 0x1d8(%rsp), %rdi
leaq 0x2c0(%rsp), %rsi
leaq 0xc0(%rsp), %r14
movq %r14, %rdx
callq 0x775d
movsd 0x80(%r12), %xmm3
addsd 0xc0(%rsp), %xmm3
movsd %xmm3, 0xc0(%rsp)
movsd 0x88(%r12), %xmm2
addsd 0xc8(%rsp), %xmm2
movsd %xmm2, 0xc8(%rsp)
movsd 0x90(%r12), %xmm0
addsd 0xd0(%rsp), %xmm0
movsd %xmm0, 0xd0(%rsp)
movsd 0x1b8(%r12), %xmm1
ucomisd 0x6d4a(%rip), %xmm1     # 0x18010
jbe 0x112d1
unpcklpd %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0]
jmp 0x1140c
movupd 0x208(%rsp), %xmm0
movapd 0x70(%rsp), %xmm2
movapd %xmm2, %xmm1
unpcklpd %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0]
mulpd %xmm0, %xmm1
movapd %xmm1, 0x350(%rsp)
movsd 0x218(%rsp), %xmm0
mulsd %xmm2, %xmm0
movsd %xmm0, 0x360(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x270(%rsp)
andq $0x0, 0x280(%rsp)
movapd %xmm0, 0x250(%rsp)
andq $0x0, 0x260(%rsp)
leaq 0x230(%rsp), %rbp
movq %rbp, %rdi
leaq 0x270(%rsp), %r15
movq %r15, %rsi
leaq 0x250(%rsp), %r12
movq %r12, %rdx
callq 0x779f
movq %r14, %rdi
movq %rbp, %rsi
callq 0x76cc
movapd %xmm0, 0x160(%rsp)
leaq 0x350(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x76cc
movapd %xmm0, 0x150(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x76cc
movapd 0x150(%rsp), %xmm5
movapd %xmm5, %xmm2
unpcklpd %xmm5, %xmm2            # xmm2 = xmm2[0],xmm5[0]
mulpd 0x270(%rsp), %xmm2
movapd 0x160(%rsp), %xmm4
movapd %xmm4, %xmm1
unpcklpd %xmm4, %xmm1            # xmm1 = xmm1[0],xmm4[0]
mulpd 0x230(%rsp), %xmm1
addpd %xmm2, %xmm1
movapd %xmm0, %xmm3
unpcklpd %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
mulpd 0x250(%rsp), %xmm3
addpd %xmm1, %xmm3
movapd %xmm5, %xmm2
mulsd 0x280(%rsp), %xmm2
movapd %xmm4, %xmm1
mulsd 0x240(%rsp), %xmm1
addsd %xmm2, %xmm1
mulsd 0x260(%rsp), %xmm0
addsd %xmm1, %xmm0
movq 0x40(%rsp), %r14
movapd %xmm3, 0x150(%rsp)
movapd %xmm0, 0x160(%rsp)
movupd %xmm3, 0x308(%rsp)
movsd %xmm0, 0x318(%rsp)
movsd 0x220(%rsp), %xmm1
movapd 0x70(%rsp), %xmm2
mulsd %xmm2, %xmm1
movsd %xmm1, 0x320(%rsp)
mulsd 0x228(%rsp), %xmm2
movq 0x48(%rsp), %rax
movsd 0x1b0(%rax), %xmm0
movapd %xmm0, %xmm1
cmpltsd 0x6b9c(%rip), %xmm1     # 0x18010
andpd %xmm1, %xmm2
andnpd %xmm0, %xmm1
orpd %xmm2, %xmm1
movlpd %xmm1, 0x328(%rsp)
movsd 0x88(%r14), %xmm0
movsd %xmm0, 0x70(%rsp)
leaq 0x170(%rsp), %rdi
leaq 0x190(%rsp), %rsi
callq 0x7710
movaps %xmm0, %xmm1
leaq 0x300(%rsp), %rdi
movsd 0x70(%rsp), %xmm0
leaq 0x100(%rsp), %rsi
leaq 0x200(%rsp), %r15
movq %r15, %rdx
callq 0x11a41
movsd 0x100(%rsp), %xmm0
pushq $0x6
popq %rdi
movq %r15, %rsi
callq 0x786c
movapd 0x150(%rsp), %xmm1
addpd %xmm1, %xmm1
movupd 0x208(%rsp), %xmm0
subpd %xmm0, %xmm1
movupd %xmm1, 0x298(%rsp)
movapd 0x160(%rsp), %xmm0
addsd %xmm0, %xmm0
subsd 0x218(%rsp), %xmm0
movsd %xmm0, 0x2a8(%rsp)
movapd 0x220(%rsp), %xmm0
movapd %xmm0, 0x2b0(%rsp)
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
movq 0xe8(%rsp), %rbp
leaq 0x290(%rsp), %r15
movq 0x28(%rsp), %r12
mulsd 0x48(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x290(%rsp)
movsd 0x40(%rbp), %xmm0
movq 0x1e0(%rsp), %rax
leaq (%rbx,%rax), %rsi
addq $0x10, %rsi
movq %r15, %rdi
callq 0x7570
movq 0x30(%rsp), %rbp
movl 0x6c(%rsp), %r15d
incl %r13d
movl 0x38(%rsp), %esi
cmpl %r15d, %r13d
jl 0x10f84
incl %esi
jmp 0x10f6c
movl 0x10(%rsp), %eax
incl %eax
jmp 0x10f5a
movq 0x8(%rsp), %rax
incl %eax
jmp 0x10f41
addq $0x238, 0xd8(%rsp) # imm = 0x238
jmp 0x10dde
addq $0x368, %rsp            # imm = 0x368
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq