// File: /workspace/github_c_makefile_star2_O1/mohuangrui[P]ArtraCFD/computational_geometry.c
// Function: ComputeIntersection
Real ComputeIntersection(const Real p[restrict], const int fid,
        const Polyhedron *poly, Real pi[restrict], Real N[restrict])
{
    const Real zero = 0.0;
    const Real one = 1.0;
    RealVec v0 = {zero}; /* vertices */
    RealVec v1 = {zero};
    RealVec v2 = {zero};
    RealVec e01 = {zero}; /* edges */
    RealVec e02 = {zero};
    RealVec para = {zero}; /* parametric coordinates */
    const IntVec v = {poly->f[fid][0], poly->f[fid][1], poly->f[fid][2]}; /* vertex index in vertex list */
    int e = 0; /* edge index in edge list */
    BuildTriangle(fid, poly, v0, v1, v2, e01, e02);
    const Real distSquare = PointTriangleDistance(p, v0, e01, e02, para);
    if (zero == para[1]) {
        if (zero == para[2]) {
            /* vertex 0 */
            for (int s = 0; s < DIMS; ++s) {
                pi[s] = v0[s];
                N[s] = poly->Nv[v[0]][s];
            }
        } else {
            if (one == para[2]) {
                /* vertex 2 */
                for (int s = 0; s < DIMS; ++s) {
                    pi[s] = v2[s];
                    N[s] = poly->Nv[v[2]][s];
                }
            } else {
                /* edge e02 */
                e = FindEdge(v[0], v[2], poly->edgeN, poly->e);
                for (int s = 0; s < DIMS; ++s) {
                    pi[s] = v0[s] + para[2] * e02[s];
                    N[s] = poly->Ne[e][s];
                }
            }
        }
    } else {
        if (one == para[1]) {
            /* vertex 1 */
            for (int s = 0; s < DIMS; ++s) {
                pi[s] = v1[s];
                N[s] = poly->Nv[v[1]][s];
            }
        } else {
            if (zero == para[2]) {
                /* edge e01 */
                e = FindEdge(v[0], v[1], poly->edgeN, poly->e);
                for (int s = 0; s < DIMS; ++s) {
                    pi[s] = v0[s] + para[1] * e01[s];
                    N[s] = poly->Ne[e][s];
                }
            } else {
                if (zero == para[0]) {
                    /* edge e12 */
                    e = FindEdge(v[1], v[2], poly->edgeN, poly->e);
                    for (int s = 0; s < DIMS; ++s) {
                        pi[s] = v0[s] + para[1] * e01[s] + para[2] * e02[s];
                        N[s] = poly->Ne[e][s];
                    }
                } else {
                    /* complete in the triangle */
                    for (int s = 0; s < DIMS; ++s) {
                        pi[s] = v0[s] + para[1] * e01[s] + para[2] * e02[s];
                        N[s] = poly->Nf[fid][s];
                    }
                }
            }
        }
    }
    return distSquare;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %r8, 0x30(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdi, 0x10(%rsp)
xorpd %xmm0, %xmm0
leaq 0x40(%rsp), %rbx
movapd %xmm0, (%rbx)
xorl %eax, %eax
movq %rax, 0x10(%rbx)
leaq 0xe0(%rsp), %r12
movq %rax, 0x10(%r12)
movapd %xmm0, (%r12)
leaq 0xc0(%rsp), %r8
movq %rax, 0x10(%r8)
movapd %xmm0, (%r8)
leaq 0xa0(%rsp), %r15
movq %rax, 0x10(%r15)
movapd %xmm0, (%r15)
leaq 0x80(%rsp), %r14
movq %rax, 0x10(%r14)
movapd %xmm0, (%r14)
leaq 0x60(%rsp), %rbp
movq %rax, 0x10(%rbp)
movapd %xmm0, (%rbp)
movq 0x200(%rdx), %rax
movslq %esi, %rdi
leaq (%rdi,%rdi,2), %r13
movl (%rax,%r13,4), %ecx
movl %ecx, 0x8(%rsp)
movl 0x4(%rax,%r13,4), %ecx
movl %ecx, 0x38(%rsp)
movl 0x8(%rax,%r13,4), %eax
movl %eax, 0x1c(%rsp)
movq %r14, (%rsp)
movq %rdx, 0x28(%rsp)
movq %rdx, %rsi
movq %rbx, %rdx
movq %r12, %rcx
movq %r15, %r9
callq 0xaea8
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r14, %rcx
movq %rbp, %r8
callq 0xb0ec
movapd %xmm0, %xmm2
movsd 0x8(%rbp), %xmm3
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm3
jne 0xb718
jp 0xb718
movsd 0x70(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jne 0xb787
jp 0xb787
movl 0x8(%rsp), %esi
leaq 0x40(%rsp), %r12
jmp 0xb730
movl 0x38(%rsp), %esi
ucomisd 0xe8e4(%rip), %xmm3     # 0x1a008
jne 0xb7b8
jp 0xb7b8
movq 0x30(%rsp), %r14
movq 0x28(%rsp), %r15
movq 0x20(%rsp), %rbx
movq 0x228(%r15), %rax
movslq %esi, %rcx
movq 0x10(%r12), %rdx
movq %rdx, 0x10(%rbx)
movups (%r12), %xmm0
movups %xmm0, (%rbx)
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq %rdx, 0x10(%r14)
movupd (%rax,%rcx,8), %xmm0
movupd %xmm0, (%r14)
movapd %xmm2, %xmm0
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
ucomisd 0xe879(%rip), %xmm1     # 0x1a008
movq 0x30(%rsp), %r14
movq 0x28(%rsp), %r15
movq 0x20(%rsp), %rbx
jne 0xb851
jp 0xb851
movl 0x1c(%rsp), %esi
leaq 0xc0(%rsp), %r12
jmp 0xb73f
movsd 0x70(%rsp), %xmm4
ucomisd %xmm0, %xmm4
movq 0x30(%rsp), %r14
movq 0x28(%rsp), %r15
movq 0x20(%rsp), %rbx
jne 0xb8c9
jp 0xb8c9
movl 0x4(%r15), %edx
movq 0x210(%r15), %rcx
movl 0x8(%rsp), %edi
movsd %xmm2, 0x10(%rsp)
movsd %xmm3, 0x8(%rsp)
callq 0xb9c6
movsd 0x8(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
movq 0x218(%r15), %rcx
cltq
leaq (%rax,%rax,2), %rax
movupd (%rcx,%rax,8), %xmm0
movupd %xmm0, (%r14)
movq 0x10(%rcx,%rax,8), %rax
movq %rax, 0x10(%r14)
xorl %eax, %eax
movsd 0xa0(%rsp,%rax,8), %xmm0
mulsd %xmm1, %xmm0
addsd 0x40(%rsp,%rax,8), %xmm0
movsd %xmm0, (%rbx,%rax,8)
incq %rax
cmpq $0x3, %rax
jne 0xb82b
jmp 0xb771
movl 0x4(%r15), %edx
movq 0x210(%r15), %rcx
movl 0x8(%rsp), %edi
movl 0x1c(%rsp), %esi
movsd %xmm2, 0x10(%rsp)
movsd %xmm1, 0x8(%rsp)
callq 0xb9c6
movsd 0x8(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
movq 0x218(%r15), %rcx
cltq
leaq (%rax,%rax,2), %rax
movupd (%rcx,%rax,8), %xmm0
movupd %xmm0, (%r14)
movq 0x10(%rcx,%rax,8), %rax
movq %rax, 0x10(%r14)
xorl %eax, %eax
movsd 0x80(%rsp,%rax,8), %xmm0
mulsd %xmm1, %xmm0
addsd 0x40(%rsp,%rax,8), %xmm0
movsd %xmm0, (%rbx,%rax,8)
incq %rax
cmpq $0x3, %rax
jne 0xb8a3
jmp 0xb771
movsd 0x60(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jne 0xb972
jp 0xb972
movl 0x4(%r15), %edx
movq 0x210(%r15), %rcx
movl %esi, %edi
movl 0x1c(%rsp), %esi
movsd %xmm2, 0x10(%rsp)
movsd %xmm3, 0x8(%rsp)
movsd %xmm4, 0x38(%rsp)
callq 0xb9c6
movsd 0x38(%rsp), %xmm4
movsd 0x8(%rsp), %xmm3
movsd 0x10(%rsp), %xmm2
movq 0x218(%r15), %rcx
cltq
leaq (%rax,%rax,2), %rax
movupd (%rcx,%rax,8), %xmm0
movupd %xmm0, (%r14)
movq 0x10(%rcx,%rax,8), %rax
movq %rax, 0x10(%r14)
xorl %eax, %eax
movsd 0xa0(%rsp,%rax,8), %xmm0
mulsd %xmm3, %xmm0
addsd 0x40(%rsp,%rax,8), %xmm0
movsd 0x80(%rsp,%rax,8), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rbx,%rax,8)
incq %rax
cmpq $0x3, %rax
jne 0xb93b
jmp 0xb771
movq 0x208(%r15), %rax
movq 0x10(%rax,%r13,8), %rcx
movq %rcx, 0x10(%r14)
movupd (%rax,%r13,8), %xmm0
movupd %xmm0, (%r14)
xorl %eax, %eax
movsd 0xa0(%rsp,%rax,8), %xmm0
mulsd %xmm3, %xmm0
addsd 0x40(%rsp,%rax,8), %xmm0
movsd 0x80(%rsp,%rax,8), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rbx,%rax,8)
incq %rax
cmpq $0x3, %rax
jne 0xb98f
jmp 0xb771