// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
movl %edi, -0x2c(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
movl 0x68(%rax), %eax
movl %eax, -0x64(%rbp)
movq -0x48(%rbp), %rax
movl 0x70(%rax), %eax
movl %eax, -0x60(%rbp)
movq -0x48(%rbp), %rax
movl 0x78(%rax), %eax
movl %eax, -0x5c(%rbp)
movq -0x48(%rbp), %rax
movl 0x6c(%rax), %eax
movl %eax, -0x70(%rbp)
movq -0x48(%rbp), %rax
movl 0x74(%rax), %eax
movl %eax, -0x6c(%rbp)
movq -0x48(%rbp), %rax
movl 0x7c(%rax), %eax
movl %eax, -0x68(%rbp)
movq -0x48(%rbp), %rax
movsd 0x3c8(%rax), %xmm0
movsd %xmm0, -0x90(%rbp)
movq -0x48(%rbp), %rax
movsd 0x3d8(%rax), %xmm0
movsd %xmm0, -0x88(%rbp)
movq -0x48(%rbp), %rax
movsd 0x3e8(%rax), %xmm0
movsd %xmm0, -0x80(%rbp)
movq -0x48(%rbp), %rax
movsd 0x30(%rax), %xmm0
movsd %xmm0, -0xb0(%rbp)
movq -0x48(%rbp), %rax
movsd 0x38(%rax), %xmm0
movsd %xmm0, -0xa8(%rbp)
movq -0x48(%rbp), %rax
movsd 0x40(%rax), %xmm0
movsd %xmm0, -0xa0(%rbp)
movq -0x48(%rbp), %rax
movsd 0x48(%rax), %xmm0
movsd %xmm0, -0xd0(%rbp)
movq -0x48(%rbp), %rax
movsd 0x50(%rax), %xmm0
movsd %xmm0, -0xc8(%rbp)
movq -0x48(%rbp), %rax
movsd 0x58(%rax), %xmm0
movsd %xmm0, -0xc0(%rbp)
movq -0x48(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0xdc(%rbp)
movq -0x48(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0xd8(%rbp)
movq -0x48(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0xd4(%rbp)
movq $0x0, -0xe8(%rbp)
movl $0x0, -0xec(%rbp)
leaq -0xf8(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x20d0
leaq -0x104(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x20d0
leaq -0x120(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x20d0
leaq -0x140(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x20d0
leaq -0x160(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x20d0
leaq -0x180(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x20d0
leaq -0x1b0(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x20d0
leaq -0x1e0(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x20d0
leaq -0x210(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x20d0
xorps %xmm0, %xmm0
movsd %xmm0, -0x218(%rbp)
leaq -0x230(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x20d0
movl $0x0, -0x234(%rbp)
movl -0x234(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x19f87
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x234(%rbp), %rcx
imulq $0x238, %rcx, %rcx      # imm = 0x238
addq %rcx, %rax
movq %rax, -0xe8(%rbp)
movl $0x0, -0x238(%rbp)
cmpl $0x3, -0x238(%rbp)
jge 0x19b5b
movq -0xe8(%rbp), %rax
addq $0x1d0, %rax            # imm = 0x1D0
movslq -0x238(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movslq -0x238(%rbp), %rax
movsd -0x90(%rbp,%rax,8), %xmm1
movslq -0x238(%rbp), %rax
movsd -0xd0(%rbp,%rax,8), %xmm2
movslq -0x238(%rbp), %rax
movl -0xdc(%rbp,%rax,4), %edi
callq 0x95b0
movl %eax, %edi
movslq -0x238(%rbp), %rax
movl -0x64(%rbp,%rax,4), %esi
movslq -0x238(%rbp), %rax
movl -0x70(%rbp,%rax,4), %edx
callq 0x95f0
movl %eax, %ecx
movslq -0x238(%rbp), %rax
movl %ecx, -0x230(%rbp,%rax,8)
movq -0xe8(%rbp), %rax
addq $0x1d0, %rax            # imm = 0x1D0
movslq -0x238(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movslq -0x238(%rbp), %rax
movsd -0x90(%rbp,%rax,8), %xmm1
movslq -0x238(%rbp), %rax
movsd -0xd0(%rbp,%rax,8), %xmm2
movslq -0x238(%rbp), %rax
movl -0xdc(%rbp,%rax,4), %edi
callq 0x95b0
movl %eax, %edi
movslq -0x238(%rbp), %rax
movl -0x64(%rbp,%rax,4), %esi
movslq -0x238(%rbp), %rax
movl -0x70(%rbp,%rax,4), %edx
callq 0x95f0
movl %eax, %ecx
addl $0x1, %ecx
movslq -0x238(%rbp), %rax
movl %ecx, -0x22c(%rbp,%rax,8)
movl -0x238(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x238(%rbp)
jmp 0x19a38
movl $0x1, -0x23c(%rbp)
movl -0x23c(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0x24(%rcx), %eax
jg 0x19f71
movl -0x220(%rbp), %eax
movl %eax, -0x240(%rbp)
movl -0x240(%rbp), %eax
cmpl -0x21c(%rbp), %eax
jge 0x19f5b
movl -0x228(%rbp), %eax
movl %eax, -0x244(%rbp)
movl -0x244(%rbp), %eax
cmpl -0x224(%rbp), %eax
jge 0x19f45
movl -0x230(%rbp), %eax
movl %eax, -0x248(%rbp)
movl -0x248(%rbp), %eax
cmpl -0x22c(%rbp), %eax
jge 0x19f2f
movl -0x240(%rbp), %edi
movl -0x244(%rbp), %esi
movl -0x248(%rbp), %edx
movq -0x48(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x48(%rbp), %rax
movl 0xc(%rax), %r8d
callq 0x9500
movl %eax, -0xec(%rbp)
movl -0x23c(%rbp), %eax
movq -0x50(%rbp), %rcx
movslq -0xec(%rbp), %rdx
imulq $0x88, %rdx, %rdx
addq %rdx, %rcx
cmpl 0xc(%rcx), %eax
jne 0x19c40
movl -0x234(%rbp), %eax
addl $0x1, %eax
movq -0x50(%rbp), %rcx
movslq -0xec(%rbp), %rdx
imulq $0x88, %rdx, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
je 0x19c45
jmp 0x19f1b
movl -0x248(%rbp), %edi
movsd -0x90(%rbp), %xmm0
movsd -0xb0(%rbp), %xmm1
movl -0xdc(%rbp), %esi
callq 0x9690
movsd %xmm0, -0x120(%rbp)
movl -0x244(%rbp), %edi
movsd -0x88(%rbp), %xmm0
movsd -0xa8(%rbp), %xmm1
movl -0xd8(%rbp), %esi
callq 0x9690
movsd %xmm0, -0x118(%rbp)
movl -0x240(%rbp), %edi
movsd -0x80(%rbp), %xmm0
movsd -0xa0(%rbp), %xmm1
movl -0xd4(%rbp), %esi
callq 0x9690
movsd %xmm0, -0x110(%rbp)
movq -0x40(%rbp), %rax
movl 0x20(%rax), %eax
cmpl -0x23c(%rbp), %eax
jl 0x19e21
leaq -0x120(%rbp), %rdi
movq -0x50(%rbp), %rax
movslq -0xec(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %esi
movq -0xe8(%rbp), %rdx
leaq -0x140(%rbp), %rcx
leaq -0x160(%rbp), %r8
leaq -0x180(%rbp), %r9
callq 0x104e0
movsd -0x160(%rbp), %xmm0
movsd -0x90(%rbp), %xmm1
movsd -0xd0(%rbp), %xmm2
movl -0xdc(%rbp), %edi
callq 0x95b0
movl %eax, -0xf8(%rbp)
movsd -0x158(%rbp), %xmm0
movsd -0x88(%rbp), %xmm1
movsd -0xc8(%rbp), %xmm2
movl -0xd8(%rbp), %edi
callq 0x95b0
movl %eax, -0xf4(%rbp)
movsd -0x150(%rbp), %xmm0
movsd -0x80(%rbp), %xmm1
movsd -0xc0(%rbp), %xmm2
movl -0xd4(%rbp), %edi
callq 0x95b0
movl %eax, -0xf0(%rbp)
movl -0x2c(%rbp), %edi
leaq -0xf8(%rbp), %rsi
leaq -0x160(%rbp), %rdx
movq -0xe8(%rbp), %r13
movq -0x48(%rbp), %r12
movq -0x50(%rbp), %r15
movq -0x40(%rbp), %r14
leaq -0x140(%rbp), %rbx
leaq -0x180(%rbp), %r11
leaq -0x1e0(%rbp), %r10
leaq -0x210(%rbp), %rax
movl $0x2, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
xorl %r9d, %r9d
movq %r13, (%rsp)
movq %r12, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq %r11, 0x28(%rsp)
movq %r10, 0x30(%rsp)
movq %rax, 0x38(%rsp)
callq 0x19fa0
leaq -0x210(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
leaq -0x1b0(%rbp), %rdx
callq 0x1a3c0
jmp 0x19ebd
movl -0x248(%rbp), %eax
movl %eax, -0x104(%rbp)
movl -0x244(%rbp), %eax
movl %eax, -0x100(%rbp)
movl -0x240(%rbp), %eax
movl %eax, -0xfc(%rbp)
movl -0x2c(%rbp), %edi
leaq -0x104(%rbp), %rsi
leaq -0x120(%rbp), %rdx
movl -0x23c(%rbp), %r8d
subl $0x1, %r8d
movl -0x234(%rbp), %r9d
addl $0x1, %r9d
movq -0x48(%rbp), %rbx
movq -0x50(%rbp), %r11
movq -0x40(%rbp), %r10
leaq -0x1b0(%rbp), %rax
movl $0x1, %ecx
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x1a470
movsd %xmm0, -0x218(%rbp)
movsd -0x218(%rbp), %xmm0
leaq -0x1b0(%rbp), %rsi
movl $0x6, %edi
callq 0x9c60
movsd -0x190(%rbp), %xmm0
movsd -0x188(%rbp), %xmm1
movq -0x40(%rbp), %rax
mulsd 0x48(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x1b0(%rbp)
movq -0x40(%rbp), %rax
movsd 0x40(%rax), %xmm0
leaq -0x1b0(%rbp), %rdi
movq -0x50(%rbp), %rsi
movslq -0xec(%rbp), %rax
imulq $0x88, %rax, %rax
addq %rax, %rsi
addq $0x10, %rsi
movslq -0x2c(%rbp), %rax
imulq $0x28, %rax, %rax
addq %rax, %rsi
callq 0x9400
movl -0x248(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x248(%rbp)
jmp 0x19bc0
jmp 0x19f31
movl -0x244(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x244(%rbp)
jmp 0x19ba2
jmp 0x19f47
movl -0x240(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x240(%rbp)
jmp 0x19b84
jmp 0x19f5d
movl -0x23c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x23c(%rbp)
jmp 0x19b65
jmp 0x19f73
movl -0x234(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x234(%rbp)
jmp 0x199fc
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)