// File: /workspace/github_c_makefile_star2_O3/mohuangrui[P]ArtraCFD/immersed_boundary.c
// Function: InverseDistanceWeighting
static Real InverseDistanceWeighting(const int tn, const int n[restrict], const Real p[restrict],
        const int h, const int type, const int did, const Partition *const part,
        const Node *const node, const Model *model, Real Uo[restrict])
{
    int idx = 0; /* linear array index math variable */
    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 IntVec ng = {part->ng[X], part->ng[Y], part->ng[Z]};
    Real Uoh[DIMUo] = {0.0}; /* primitive at neighbouring node */
    RealVec ph = {0.0}; /* neighbouring point */
    IntVec nh = {0}; /* neighbouring node */
    Real weightSum = 0.0;
    memset(Uo, 0, DIMUo * sizeof(*Uo));
    /*
     * Search nodes with required "type" in the domain specified by the center node
     * "n" and initial range "h" as interpolation stencils for the interpolated point "p".
     * To preserve symmetry, the search range in each direction should be symmetric, and
     * the search operator on each direction index should be symmetric. In addition,
     * any temporal priority should be strictly prevented in treating the solution nodes.
     */
    for (int r = h, tally = 0; 0 == tally; ++r) {
        for (int kh = -r; kh <= r; ++kh) {
            for (int jh = -r; jh <= r; ++jh) {
                for (int ih = -r; ih <= r; ++ih) {
                    nh[X] = n[X] + ih;
                    nh[Y] = n[Y] + jh;
                    nh[Z] = n[Z] + kh;
                    if (!InPartBox(nh[Z], nh[Y], nh[X], part->ns[PIN])) {
                        continue;
                    }
                    idx = IndexNode(nh[Z], nh[Y], nh[X], part->n[Y], part->n[X]);
                    /* be aware of the validity of ih = jh = kh = 0 */
                    if (did != node[idx].did) {
                        continue; /* skip node not in target domain */
                    }
                    switch (type) {
                        case TYPED: /* use node in target domain */
                            break;
                        case TYPEF: /* use original node in target domain to avoid priority */
                            if ((did != node[idx].gst) || (0 > node[idx].fid)) {
                                continue; /* skip changed node either reconstructed or not */
                            }
                            break;
                        default: /* use node in target domain layer */
                            if (type != node[idx].gst) {
                                continue;
                            }
                            break;
                    }
                    ++tally;
                    ph[X] = MapPoint(nh[X], sMin[X], d[X], ng[X]);
                    ph[Y] = MapPoint(nh[Y], sMin[Y], d[Y], ng[Y]);
                    ph[Z] = MapPoint(nh[Z], sMin[Z], d[Z], ng[Z]);
                    MapPrimitive(model->gamma, model->gasR, node[idx].U[tn], Uoh);
                    ApplyWeighting(Uoh, part->tinyL, Dist2(p, ph), &weightSum, Uo);
                }
            }
        }
    }
    return weightSum;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movl %r9d, 0xc(%rsp)
movl %r8d, 0x24(%rsp)
movl %ecx, %r12d
movq %rdx, 0x80(%rsp)
movq 0x148(%rsp), %rbx
movq 0x130(%rsp), %rax
movsd 0x3c8(%rax), %xmm0
movsd %xmm0, 0x78(%rsp)
movsd 0x3d8(%rax), %xmm0
movsd %xmm0, 0x70(%rsp)
movsd 0x3e8(%rax), %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0x30(%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0x38(%rax), %xmm0
movsd %xmm0, 0x58(%rsp)
movsd 0x40(%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
movl 0x18(%rax), %ecx
movl %ecx, 0x20(%rsp)
movl 0x1c(%rax), %ecx
movl %ecx, 0x1c(%rsp)
movl 0x20(%rax), %ecx
movl %ecx, 0x18(%rsp)
xorpd %xmm0, %xmm0
leaq 0xc0(%rsp), %rcx
movapd %xmm0, 0x20(%rcx)
movapd %xmm0, 0x10(%rcx)
movapd %xmm0, (%rcx)
leaq 0xa0(%rsp), %rcx
movapd %xmm0, (%rcx)
movq $0x0, 0x10(%rcx)
movupd %xmm0, 0x20(%rbx)
movupd %xmm0, 0x10(%rbx)
movupd %xmm0, (%rbx)
movslq %edi, %rcx
movq %rcx, 0x48(%rsp)
movl (%rsi), %ecx
movq %rcx, 0x98(%rsp)
movl 0x4(%rsi), %ecx
movq %rcx, 0x38(%rsp)
movl 0x8(%rsi), %ecx
movq %rcx, 0x28(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
addq $0x68, %rax
movq %rax, 0x90(%rsp)
decl %r12d
incl %r12d
js 0x12556
movl %r12d, %eax
negl %eax
movl $0x0, 0x8(%rsp)
movl %eax, 0x4(%rsp)
movl %eax, %ecx
movl %r12d, (%rsp)
movq 0x28(%rsp), %rax
movq %rcx, 0x30(%rsp)
leal (%rax,%rcx), %r13d
movl 0x4(%rsp), %eax
movl %eax, %ecx
movq 0x38(%rsp), %rax
movq %rcx, 0x40(%rsp)
leal (%rax,%rcx), %r15d
movl 0x4(%rsp), %eax
movl %eax, %r14d
movq 0x98(%rsp), %rax
leal (%rax,%r14), %ebp
movl %r13d, %edi
movl %r15d, %esi
movl %ebp, %edx
movq 0x90(%rsp), %rcx
callq 0x7d60
testl %eax, %eax
je 0x12758
movq 0x130(%rsp), %rax
movl 0xc(%rax), %r8d
movl 0x10(%rax), %ecx
movl %r13d, %edi
movl %r15d, %esi
movl %ebp, %edx
callq 0x7d53
cltq
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %r12
movl 0xc(%rsp), %eax
movq 0x138(%rsp), %rcx
cmpl %eax, (%rcx,%r12)
jne 0x12754
addq %rcx, %r12
movl 0x24(%rsp), %eax
cmpl $-0x1, %eax
je 0x1263b
cmpl $-0x2, %eax
jne 0x12630
movl 0xc(%rsp), %eax
cmpl %eax, 0xc(%r12)
jne 0x12754
cmpl $0x0, 0x4(%r12)
jns 0x1263b
jmp 0x12754
cmpl %eax, 0xc(%r12)
jne 0x12754
movl %ebp, %edi
movsd 0x78(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
movl 0x20(%rsp), %esi
callq 0x7db8
movsd %xmm0, 0xa0(%rsp)
movl %r15d, %edi
movsd 0x70(%rsp), %xmm0
movsd 0x58(%rsp), %xmm1
movl 0x1c(%rsp), %esi
callq 0x7db8
movsd %xmm0, 0xa8(%rsp)
movl %r13d, %edi
movsd 0x68(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
movl 0x18(%rsp), %esi
callq 0x7db8
movsd %xmm0, 0xb0(%rsp)
movq 0x140(%rsp), %rax
movsd 0x40(%rax), %xmm0
movsd 0x48(%rax), %xmm1
movq 0x48(%rsp), %rax
leaq (%rax,%rax,4), %rax
leaq (%r12,%rax,8), %rdi
addq $0x10, %rdi
leaq 0xc0(%rsp), %rsi
callq 0x7c16
movq 0x130(%rsp), %rax
movsd 0x60(%rax), %xmm0
movsd %xmm0, 0x88(%rsp)
movq 0x80(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x7e85
movsd 0x88(%rsp), %xmm1
maxsd %xmm0, %xmm1
movsd 0x68fb(%rip), %xmm0     # 0x19008
divsd %xmm1, %xmm0
movapd %xmm0, %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
xorl %eax, %eax
movupd (%rbx,%rax,8), %xmm2
movapd 0xc0(%rsp,%rax,8), %xmm3
mulpd %xmm1, %xmm3
addpd %xmm2, %xmm3
movupd %xmm3, (%rbx,%rax,8)
addq $0x2, %rax
cmpq $0x6, %rax
jne 0x1271b
incl 0x8(%rsp)
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movl (%rsp), %r12d
leal 0x1(%r14), %eax
cmpl %r12d, %r14d
movl %eax, %r14d
jl 0x1259b
movq 0x40(%rsp), %rcx
leal 0x1(%rcx), %eax
cmpl %r12d, %ecx
movl %eax, %ecx
jl 0x12586
movq 0x30(%rsp), %rcx
leal 0x1(%rcx), %eax
cmpl %r12d, %ecx
movl %eax, %ecx
jl 0x12572
incl %r12d
cmpl $0x0, 0x8(%rsp)
je 0x12553
movsd 0x10(%rsp), %xmm0
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq