// File: /workspace/github_c_makefile_star2_O2/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 $0xe8, %rsp
movl %r9d, 0x1c(%rsp)
movl %r8d, 0x2c(%rsp)
movl %ecx, 0x10(%rsp)
movq %rdx, 0x70(%rsp)
movq %rsi, 0x80(%rsp)
movq 0x138(%rsp), %rax
movq 0x120(%rsp), %rcx
movsd 0x3c8(%rcx), %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0x3d8(%rcx), %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0x3e8(%rcx), %xmm0
movsd %xmm0, 0x58(%rsp)
movsd 0x30(%rcx), %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x38(%rcx), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x40(%rcx), %xmm0
movsd %xmm0, 0x40(%rsp)
movl 0x18(%rcx), %edx
movl %edx, 0x28(%rsp)
movl 0x1c(%rcx), %edx
movl %edx, 0x24(%rsp)
movl 0x20(%rcx), %edx
movl %edx, 0x20(%rsp)
xorps %xmm0, %xmm0
leaq 0xb0(%rsp), %rdx
movaps %xmm0, 0x20(%rdx)
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, (%rdx)
leaq 0x90(%rsp), %rdx
movaps %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
leaq 0x30(%rsp), %rdx
andq $0x0, (%rdx)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movslq %edi, %rax
imulq $0x28, %rax, %rax
movq %rax, 0x38(%rsp)
leaq 0x68(%rcx), %rax
movq %rax, 0x88(%rsp)
movl $0x0, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
jne 0x11902
movl 0x10(%rsp), %eax
negl %eax
movl $0x0, 0x14(%rsp)
movl %eax, 0x18(%rsp)
movl %eax, %r13d
cmpl 0x10(%rsp), %r13d
jg 0x118f9
movl 0x18(%rsp), %eax
movl %r13d, 0xc(%rsp)
cmpl 0x10(%rsp), %eax
jg 0x118f1
movl 0x18(%rsp), %r14d
cmpl 0x10(%rsp), %r14d
jg 0x118ea
movq 0x80(%rsp), %rcx
movl (%rcx), %ebx
addl %r14d, %ebx
movl 0x4(%rcx), %ebp
movl %eax, %r12d
addl %eax, %ebp
movl 0x8(%rcx), %r15d
addl %r13d, %r15d
movl %r15d, %edi
movl %ebp, %esi
movl %ebx, %edx
movq 0x88(%rsp), %rcx
callq 0x75f9
testl %eax, %eax
je 0x118df
movq 0x120(%rsp), %rax
movl 0xc(%rax), %r8d
movl 0x10(%rax), %ecx
movl %r15d, %edi
movl %ebp, %esi
movl %ebx, %edx
callq 0x75ec
cltq
imulq $0x88, %rax, %r13
movl 0x1c(%rsp), %eax
movq 0x128(%rsp), %rcx
cmpl %eax, (%rcx,%r13)
jne 0x118da
addq %rcx, %r13
movl 0x2c(%rsp), %eax
cmpl $-0x1, %eax
je 0x11803
cmpl $-0x2, %eax
jne 0x117f9
movl 0x1c(%rsp), %eax
cmpl %eax, 0xc(%r13)
jne 0x118da
cmpl $0x0, 0x4(%r13)
jns 0x11803
jmp 0x118da
cmpl %eax, 0xc(%r13)
jne 0x118da
incl 0x14(%rsp)
movl %ebx, %edi
movsd 0x68(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
movl 0x28(%rsp), %esi
callq 0x7651
movsd %xmm0, 0x90(%rsp)
movl %ebp, %edi
movsd 0x60(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movl 0x24(%rsp), %esi
callq 0x7651
movsd %xmm0, 0x98(%rsp)
movl %r15d, %edi
movsd 0x58(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
movl 0x20(%rsp), %esi
callq 0x7651
movsd %xmm0, 0xa0(%rsp)
movq 0x130(%rsp), %rax
movsd 0x40(%rax), %xmm0
movsd 0x48(%rax), %xmm1
movq 0x38(%rsp), %rax
leaq (%rax,%r13), %rdi
addq $0x10, %rdi
leaq 0xb0(%rsp), %rbx
movq %rbx, %rsi
callq 0x74af
movq 0x120(%rsp), %rax
movsd 0x60(%rax), %xmm0
movsd %xmm0, 0x78(%rsp)
movq 0x70(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x7710
movaps %xmm0, %xmm1
movq %rbx, %rdi
movsd 0x78(%rsp), %xmm0
leaq 0x30(%rsp), %rsi
movq 0x138(%rsp), %rdx
callq 0x11a41
movl 0xc(%rsp), %r13d
movl %r12d, %eax
incl %r14d
jmp 0x11751
incl %eax
jmp 0x11742
incl %r13d
jmp 0x1172e
incl 0x10(%rsp)
jmp 0x1170e
movsd 0x30(%rsp), %xmm0
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq