// File: /workspace/github_c_makefile_star2_O3/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 0xaa9d
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r14, %rcx
movq %rbp, %r8
callq 0xac9e
movapd %xmm0, %xmm2
movsd 0x8(%rbp), %xmm3
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm3
jne 0xb2c8
jp 0xb2c8
movsd 0x70(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jne 0xb337
jp 0xb337
movl 0x8(%rsp), %esi
leaq 0x40(%rsp), %r12
jmp 0xb2e0
movl 0x38(%rsp), %esi
ucomisd 0xdd34(%rip), %xmm3     # 0x19008
jne 0xb368
jp 0xb368
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 0xdcc9(%rip), %xmm1     # 0x19008
movq 0x30(%rsp), %r14
movq 0x28(%rsp), %r15
movq 0x20(%rsp), %rbx
jne 0xb401
jp 0xb401
movl 0x1c(%rsp), %esi
leaq 0xc0(%rsp), %r12
jmp 0xb2ef
movsd 0x70(%rsp), %xmm4
ucomisd %xmm0, %xmm4
movq 0x30(%rsp), %r14
movq 0x28(%rsp), %r15
movq 0x20(%rsp), %rbx
jne 0xb479
jp 0xb479
movl 0x4(%r15), %edx
movq 0x210(%r15), %rcx
movl 0x8(%rsp), %edi
movsd %xmm2, 0x10(%rsp)
movsd %xmm3, 0x8(%rsp)
callq 0xb576
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 0xb3db
jmp 0xb321
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 0xb576
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 0xb453
jmp 0xb321
movsd 0x60(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jne 0xb522
jp 0xb522
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 0xb576
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 0xb4eb
jmp 0xb321
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 0xb53f
jmp 0xb321