// File: /workspace/github_c_makefile_star2_O1/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 $0x308, %rsp            # imm = 0x308
movl %edi, 0x4(%rsp)
movq (%rsi), %r12
movl 0x90(%rsi), %eax
movl %eax, 0x134(%rsp)
movl 0x98(%rsi), %eax
movl %eax, 0x138(%rsp)
movl 0xa0(%rsi), %eax
movl %eax, 0x13c(%rsp)
movl 0x94(%rsi), %eax
movl %eax, 0x128(%rsp)
movl 0x9c(%rsi), %eax
movl %eax, 0x12c(%rsp)
movl 0xa4(%rsi), %eax
movl %eax, 0x130(%rsp)
movsd 0x3f0(%rsi), %xmm0
movsd %xmm0, 0x1c0(%rsp)
movsd 0x400(%rsi), %xmm0
movsd %xmm0, 0x1c8(%rsp)
movsd 0x410(%rsi), %xmm0
movsd %xmm0, 0x1d0(%rsp)
movsd 0x58(%rsi), %xmm0
movsd %xmm0, 0x2c0(%rsp)
movsd 0x60(%rsi), %xmm0
movsd %xmm0, 0x2b8(%rsp)
movsd 0x68(%rsi), %xmm0
movsd %xmm0, 0x2b0(%rsp)
movsd 0x70(%rsi), %xmm0
movsd %xmm0, 0x1a0(%rsp)
movsd 0x78(%rsi), %xmm0
movsd %xmm0, 0x1a8(%rsp)
movsd 0x80(%rsi), %xmm0
movsd %xmm0, 0x1b0(%rsp)
movl 0x40(%rsi), %eax
movl %eax, 0x44(%rsp)
movl 0x44(%rsi), %eax
movl %eax, 0x48(%rsp)
movl 0x48(%rsi), %eax
movl %eax, 0x4c(%rsp)
xorl %eax, %eax
movl %eax, 0xa8(%rsp)
movq %rax, 0xa0(%rsp)
movl %eax, 0x98(%rsp)
movq %rax, 0x90(%rsp)
movq %rax, 0x190(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x180(%rsp)
movq %rax, 0x170(%rsp)
movapd %xmm0, 0x160(%rsp)
movq %rax, 0x150(%rsp)
movapd %xmm0, 0x140(%rsp)
movq %rax, 0x270(%rsp)
movapd %xmm0, 0x260(%rsp)
movapd %xmm0, 0x250(%rsp)
movapd %xmm0, 0x240(%rsp)
movapd %xmm0, 0x230(%rsp)
movapd %xmm0, 0x220(%rsp)
movapd %xmm0, 0x210(%rsp)
movapd %xmm0, 0x200(%rsp)
movapd %xmm0, 0x110(%rsp)
movapd %xmm0, 0x100(%rsp)
movapd %xmm0, 0xf0(%rsp)
movq %rax, 0x60(%rsp)
movapd %xmm0, 0x50(%rsp)
cmpl %eax, 0x8(%rsi)
jle 0x12750
movq %rdx, %rbx
movq %rsi, %r15
leaq 0x28(%rsi), %rax
movq %rax, 0xe0(%rsp)
movslq 0x4(%rsp), %rax
movq %rax, 0x2a8(%rsp)
movl $0x1d8, %ecx            # imm = 0x1D8
xorl %edx, %edx
movq %rsi, 0x20(%rsp)
movq %r12, 0x70(%rsp)
movq %rbx, 0xd8(%rsp)
movq %rbx, %r13
movq 0x18(%r15), %r14
movq %rdx, 0xd0(%rsp)
imulq $0x238, %rdx, %rax      # imm = 0x238
addq %r14, %rax
movq %rax, 0x78(%rsp)
movq %rcx, 0x298(%rsp)
addq %rcx, %r14
xorl %r12d, %r12d
movsd -0x8(%r14,%r12,4), %xmm0
movsd 0x1c0(%rsp,%r12,2), %xmm1
movsd %xmm1, 0x38(%rsp)
movsd 0x1a0(%rsp,%r12,2), %xmm2
movsd %xmm2, 0x30(%rsp)
movl 0x44(%rsp,%r12), %ebx
movl %ebx, %edi
callq 0x7ed3
movl 0x134(%rsp,%r12), %ebp
movl 0x128(%rsp,%r12), %r15d
movl %eax, %edi
movl %ebp, %esi
movl %r15d, %edx
callq 0x7eea
movl %eax, 0x50(%rsp,%r12,2)
movsd (%r14,%r12,4), %xmm0
movsd 0x38(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movl %ebx, %edi
callq 0x7ed3
movl %eax, %edi
movl %ebp, %esi
movl %r15d, %edx
callq 0x7eea
incl %eax
movl %eax, 0x54(%rsp,%r12,2)
addq $0x4, %r12
cmpq $0xc, %r12
jne 0x11f0f
movq 0x20(%rsp), %r15
cmpl $0x0, 0x4c(%r15)
movq %r13, %rbx
movq 0x70(%rsp), %r12
jle 0x12729
movq 0xd0(%rsp), %rax
incq %rax
movq %rax, 0xe8(%rsp)
movq 0x78(%rsp), %rax
addq $0xb0, %rax
movq %rax, 0x2a0(%rsp)
movl $0x1, %ebp
movl 0x60(%rsp), %edi
cmpl 0x64(%rsp), %edi
jge 0x1271a
leal -0x1(%rbp), %eax
movl %eax, 0xac(%rsp)
movq %rbp, 0x2c8(%rsp)
movl 0x58(%rsp), %esi
cmpl 0x5c(%rsp), %esi
movl %edi, 0x30(%rsp)
jge 0x1270e
movl 0x50(%rsp), %r13d
cmpl 0x54(%rsp), %r13d
movl %esi, 0x38(%rsp)
jge 0x12702
movl 0x34(%r15), %r8d
movl 0x38(%r15), %ecx
movl %r13d, %edx
callq 0x7ea3
cltq
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %rcx
cmpl 0xc(%r12,%rcx), %ebp
jne 0x126ec
addq %r12, %rcx
movl (%rcx), %eax
cmpq %rax, 0xe8(%rsp)
jne 0x126ec
movq %rcx, 0x88(%rsp)
movsd 0x1c0(%rsp), %xmm0
movq %rbx, %r14
movl 0x44(%rsp), %esi
movl %r13d, %edi
movsd %xmm0, 0x80(%rsp)
movsd 0x2c0(%rsp), %xmm1
movl %esi, 0x18(%rsp)
callq 0x7f08
movsd %xmm0, 0x180(%rsp)
movsd 0x1c8(%rsp), %xmm0
movl 0x48(%rsp), %esi
movl 0x38(%rsp), %r12d
movl %r12d, %edi
movsd %xmm0, 0x8(%rsp)
movsd 0x2b8(%rsp), %xmm1
movl %esi, 0x10(%rsp)
callq 0x7f08
movsd %xmm0, 0x188(%rsp)
movsd 0x1d0(%rsp), %xmm0
movq %rbp, %r15
movl 0x4c(%rsp), %ebp
movl 0x30(%rsp), %ebx
movl %ebx, %edi
movsd %xmm0, 0x28(%rsp)
movsd 0x2b0(%rsp), %xmm1
movl %ebp, %esi
callq 0x7f08
movsd %xmm0, 0x190(%rsp)
cmpl %r15d, 0x20(%r14)
jge 0x12198
movl %r13d, 0x90(%rsp)
movl %r12d, 0x94(%rsp)
movl %ebx, 0x98(%rsp)
movl 0x4(%rsp), %edi
leaq 0x90(%rsp), %rsi
leaq 0x180(%rsp), %rdx
movl $0x1, %ecx
movl 0xac(%rsp), %r8d
movq 0xe8(%rsp), %r9
leaq 0x230(%rsp), %rbp
pushq %rbp
movq 0xe0(%rsp), %rbx
pushq %rbx
movq 0x80(%rsp), %r12
pushq %r12
pushq 0xf8(%rsp)
callq 0x127b0
addq $0x20, %rsp
movl $0x6, %edi
movq %rbp, %rsi
callq 0x821f
movq 0x20(%rsp), %r15
jmp 0x12697
movq 0x88(%rsp), %rax
movl 0x4(%rax), %esi
leaq 0x180(%rsp), %rdi
movq 0x78(%rsp), %r15
movq %r15, %rdx
leaq 0x160(%rsp), %rcx
leaq 0x140(%rsp), %rbx
movq %rbx, %r8
leaq 0x260(%rsp), %r9
movq %r9, %r14
callq 0xba2d
movsd 0x140(%rsp), %xmm0
movsd 0x1a0(%rsp), %xmm2
movsd 0x80(%rsp), %xmm1
movl 0x18(%rsp), %edi
callq 0x7ed3
movl %eax, 0xa0(%rsp)
movsd 0x148(%rsp), %xmm0
movsd 0x1a8(%rsp), %xmm2
movsd 0x8(%rsp), %xmm1
movl 0x10(%rsp), %edi
callq 0x7ed3
movl %eax, 0xa4(%rsp)
movsd 0x150(%rsp), %xmm0
movsd 0x1b0(%rsp), %xmm2
movsd 0x28(%rsp), %xmm1
movl %ebp, %edi
callq 0x7ed3
movl %eax, 0xa8(%rsp)
movl 0x4(%rsp), %edi
leaq 0xa0(%rsp), %rsi
movq %rbx, %rdx
movl $0x2, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
xorl %r9d, %r9d
leaq 0xf0(%rsp), %rax
pushq %rax
movq 0xe0(%rsp), %rbx
pushq %rbx
movq 0x80(%rsp), %r12
pushq %r12
pushq 0xf8(%rsp)
callq 0x127b0
addq $0x20, %rsp
movapd %xmm0, %xmm1
movsd 0x7d64(%rip), %xmm0     # 0x1a008
movsd %xmm1, 0x80(%rsp)
divsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0xb0(%rsp)
movq $0x0, 0xc0(%rsp)
movsd 0x160(%rsp), %xmm0
movsd 0x168(%rsp), %xmm1
subsd 0x20(%r15), %xmm0
movsd %xmm0, 0x2f0(%rsp)
subsd 0x28(%r15), %xmm1
movsd %xmm1, 0x2f8(%rsp)
movsd 0x170(%rsp), %xmm0
subsd 0x30(%r15), %xmm0
movsd %xmm0, 0x300(%rsp)
movq 0x2a0(%rsp), %rdi
leaq 0x2f0(%rsp), %rsi
leaq 0xb0(%rsp), %rbp
movq %rbp, %rdx
callq 0x8054
movsd 0x80(%r15), %xmm2
addsd 0xb0(%rsp), %xmm2
movsd %xmm2, 0xb0(%rsp)
movsd 0x88(%r15), %xmm3
addsd 0xb8(%rsp), %xmm3
movsd %xmm3, 0xb8(%rsp)
movsd 0x90(%r15), %xmm1
addsd 0xc0(%rsp), %xmm1
movsd %xmm1, 0xc0(%rsp)
movsd 0x1b8(%r15), %xmm0
ucomisd 0x7c76(%rip), %xmm0     # 0x1a010
jbe 0x123c8
movsd %xmm2, 0x28(%rsp)
movsd %xmm2, 0x208(%rsp)
movsd %xmm3, 0x210(%rsp)
movsd %xmm1, 0x8(%rsp)
movsd %xmm1, 0x218(%rsp)
jmp 0x12549
movsd 0xf8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x2d0(%rsp)
movsd 0x100(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x2d8(%rsp)
movsd 0x108(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x2e0(%rsp)
xorl %eax, %eax
movq %rax, 0x290(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x280(%rsp)
movq %rax, 0x1f0(%rsp)
movapd %xmm0, 0x1e0(%rsp)
movq %r14, %rdi
leaq 0x280(%rsp), %r15
movq %r15, %rsi
leaq 0x1e0(%rsp), %rdx
callq 0x80a7
movq %rbp, %rdi
movq %r14, %rsi
callq 0x7f86
movsd %xmm0, 0x8(%rsp)
leaq 0x2d0(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
callq 0x7f86
movsd %xmm0, 0x18(%rsp)
movq %rbp, %rdi
leaq 0x1e0(%rsp), %rsi
callq 0x7f86
movsd 0x280(%rsp), %xmm2
movsd 0x18(%rsp), %xmm3
mulsd %xmm3, %xmm2
movsd 0x260(%rsp), %xmm1
movsd 0x8(%rsp), %xmm4
mulsd %xmm4, %xmm1
addsd %xmm2, %xmm1
movsd 0x1e0(%rsp), %xmm2
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, 0x28(%rsp)
movsd %xmm2, 0x208(%rsp)
movsd 0x288(%rsp), %xmm2
mulsd %xmm3, %xmm2
movapd %xmm3, %xmm5
movsd 0x268(%rsp), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm2, %xmm1
movsd 0x1e8(%rsp), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm1, %xmm3
mulsd 0x290(%rsp), %xmm5
movsd %xmm3, 0x210(%rsp)
movapd %xmm4, %xmm1
mulsd 0x270(%rsp), %xmm1
addsd %xmm5, %xmm1
mulsd 0x1f0(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm0, 0x218(%rsp)
movq 0x20(%rsp), %r15
movsd 0x110(%rsp), %xmm0
movsd 0x10(%rsp), %xmm2
mulsd %xmm2, %xmm0
movsd %xmm0, 0x220(%rsp)
movq 0x78(%rsp), %rax
movsd 0x1b0(%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
leaq 0x230(%rsp), %rbp
movsd %xmm3, 0x18(%rsp)
jbe 0x125a7
movapd %xmm2, %xmm1
mulsd 0x118(%rsp), %xmm1
movsd %xmm1, 0x228(%rsp)
jmp 0x125b0
movsd %xmm0, 0x228(%rsp)
movsd 0x88(%r15), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x140(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x7fe0
movsd 0x10(%rsp), %xmm1
maxsd %xmm0, %xmm1
movsd 0x7a22(%rip), %xmm2     # 0x1a008
divsd %xmm1, %xmm2
xorl %eax, %eax
movsd 0x200(%rsp,%rax,8), %xmm1
mulsd %xmm2, %xmm1
addsd 0xf0(%rsp,%rax,8), %xmm1
movsd %xmm1, 0xf0(%rsp,%rax,8)
incq %rax
cmpq $0x6, %rax
jne 0x125ec
movsd 0x80(%rsp), %xmm0
addsd %xmm2, %xmm0
movl $0x6, %edi
leaq 0xf0(%rsp), %rsi
callq 0x821f
movsd 0x28(%rsp), %xmm0
addsd %xmm0, %xmm0
subsd 0xf8(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
addsd %xmm1, %xmm1
subsd 0x100(%rsp), %xmm1
movsd %xmm0, 0x238(%rsp)
movsd 0x8(%rsp), %xmm0
addsd %xmm0, %xmm0
subsd 0x108(%rsp), %xmm0
movsd %xmm1, 0x240(%rsp)
movsd %xmm0, 0x248(%rsp)
movaps 0x110(%rsp), %xmm0
movaps %xmm0, 0x250(%rsp)
movq 0x88(%rsp), %rcx
movsd 0x250(%rsp), %xmm0
movsd 0x258(%rsp), %xmm1
mulsd 0x48(%rbx), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x230(%rsp)
movsd 0x40(%rbx), %xmm0
movq 0x2a8(%rsp), %rax
leaq (%rax,%rax,4), %rax
leaq (%rcx,%rax,8), %rsi
addq $0x10, %rsi
movq %rbp, %rdi
callq 0x7e2a
movq 0x2c8(%rsp), %rbp
incl %r13d
cmpl 0x54(%rsp), %r13d
movl 0x30(%rsp), %edi
movl 0x38(%rsp), %esi
jl 0x12026
incl %esi
cmpl 0x5c(%rsp), %esi
jl 0x12012
incl %edi
cmpl 0x64(%rsp), %edi
jl 0x12000
leal 0x1(%rbp), %eax
cmpl 0x4c(%r15), %ebp
movl %eax, %ebp
jl 0x11fe0
movq 0xd0(%rsp), %rdx
incq %rdx
movslq 0x8(%r15), %rax
movq 0x298(%rsp), %rcx
addq $0x238, %rcx            # imm = 0x238
cmpq %rax, %rdx
jl 0x11ee3
addq $0x308, %rsp            # imm = 0x308
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq