// File: /workspace/github_c_makefile_star2_O2/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 $0xe8, %rsp
movq %r8, %rbx
movq %rcx, %r14
movq %rdi, 0x10(%rsp)
xorpd %xmm0, %xmm0
leaq 0x30(%rsp), %r9
andq $0x0, 0x10(%r9)
leaq 0xd0(%rsp), %rcx
andq $0x0, 0x10(%rcx)
movapd %xmm0, (%r9)
movapd %xmm0, (%rcx)
leaq 0xb0(%rsp), %r8
movapd %xmm0, (%r8)
andq $0x0, 0x10(%r8)
leaq 0x90(%rsp), %rbp
movapd %xmm0, (%rbp)
andq $0x0, 0x10(%rbp)
leaq 0x70(%rsp), %r13
andq $0x0, 0x10(%r13)
leaq 0x50(%rsp), %r15
andq $0x0, 0x10(%r15)
movapd %xmm0, (%r13)
movapd %xmm0, (%r15)
movq 0x200(%rdx), %rax
movslq %esi, %r12
imulq $0xc, %r12, %rsi
movslq (%rax,%rsi), %rdi
movq %rdi, 0x8(%rsp)
movslq 0x4(%rax,%rsi), %rdi
movq %rdi, 0x28(%rsp)
movslq 0x8(%rax,%rsi), %rax
movq %rax, 0x20(%rsp)
movq %r13, (%rsp)
movl %r12d, %edi
movq %rdx, 0x18(%rsp)
movq %rdx, %rsi
movq %r9, %rdx
movq %rbp, %r9
callq 0xa25b
movq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq %r15, %r8
callq 0xa42c
movapd %xmm0, %xmm2
movsd 0x8(%r15), %xmm3
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm3
jne 0xaa8e
jp 0xaa8e
movsd 0x60(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jne 0xaae1
jp 0xaae1
imulq $0x18, 0x8(%rsp), %rax
movq 0x18(%rsp), %rcx
addq 0x228(%rcx), %rax
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0xad24
movsd 0x30(%rsp,%rcx,8), %xmm0
movsd %xmm0, (%r14,%rcx,8)
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rbx,%rcx,8)
incq %rcx
jmp 0xaa69
movq 0x28(%rsp), %rsi
ucomisd 0xd56d(%rip), %xmm3     # 0x18008
jne 0xab31
jp 0xab31
imulq $0x18, %rsi, %rax
movq 0x18(%rsp), %rcx
addq 0x228(%rcx), %rax
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0xad24
movsd 0xd0(%rsp,%rcx,8), %xmm0
movsd %xmm0, (%r14,%rcx,8)
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rbx,%rcx,8)
incq %rcx
jmp 0xaab9
ucomisd 0xd51f(%rip), %xmm1     # 0x18008
jne 0xabba
jp 0xabba
imulq $0x18, 0x20(%rsp), %rax
movq 0x18(%rsp), %rcx
addq 0x228(%rcx), %rax
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0xad24
movsd 0xb0(%rsp,%rcx,8), %xmm0
movsd %xmm0, (%r14,%rcx,8)
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rbx,%rcx,8)
incq %rcx
jmp 0xab09
movsd 0x60(%rsp), %xmm4
ucomisd %xmm0, %xmm4
jne 0xac2f
jp 0xac2f
movq 0x18(%rsp), %r15
movl 0x4(%r15), %edx
movq 0x210(%r15), %rcx
movq 0x8(%rsp), %rdi
movsd %xmm2, 0x10(%rsp)
movsd %xmm3, 0x8(%rsp)
callq 0xad3a
movsd 0x8(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
cltq
imulq $0x18, %rax, %rax
addq 0x218(%r15), %rax
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0xad24
movsd 0x90(%rsp,%rcx,8), %xmm0
mulsd %xmm1, %xmm0
addsd 0x30(%rsp,%rcx,8), %xmm0
movsd %xmm0, (%r14,%rcx,8)
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rbx,%rcx,8)
incq %rcx
jmp 0xab88
movq 0x18(%rsp), %r15
movl 0x4(%r15), %edx
movq 0x210(%r15), %rcx
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
movsd %xmm2, 0x10(%rsp)
movsd %xmm1, 0x8(%rsp)
callq 0xad3a
movsd 0x8(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
cltq
imulq $0x18, %rax, %rax
addq 0x218(%r15), %rax
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0xad24
movsd 0x70(%rsp,%rcx,8), %xmm0
mulsd %xmm1, %xmm0
addsd 0x30(%rsp,%rcx,8), %xmm0
movsd %xmm0, (%r14,%rcx,8)
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rbx,%rcx,8)
incq %rcx
jmp 0xac00
movsd 0x50(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jne 0xacd5
jp 0xacd5
movq 0x18(%rsp), %r15
movl 0x4(%r15), %edx
movq 0x210(%r15), %rcx
movl %esi, %edi
movq 0x20(%rsp), %rsi
movsd %xmm2, 0x10(%rsp)
movsd %xmm3, 0x8(%rsp)
movsd %xmm4, 0x28(%rsp)
callq 0xad3a
movsd 0x28(%rsp), %xmm4
movsd 0x8(%rsp), %xmm3
movsd 0x10(%rsp), %xmm2
cltq
imulq $0x18, %rax, %rax
addq 0x218(%r15), %rax
xorl %ecx, %ecx
cmpq $0x18, %rcx
je 0xad24
movsd 0x90(%rsp,%rcx), %xmm0
mulsd %xmm3, %xmm0
addsd 0x30(%rsp,%rcx), %xmm0
movsd 0x70(%rsp,%rcx), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%r14,%rcx)
movsd (%rax,%rcx), %xmm0
movsd %xmm0, (%rbx,%rcx)
addq $0x8, %rcx
jmp 0xac94
imulq $0x18, %r12, %rax
movq 0x18(%rsp), %rcx
addq 0x208(%rcx), %rax
xorl %ecx, %ecx
cmpq $0x18, %rcx
je 0xad24
movsd 0x90(%rsp,%rcx), %xmm0
mulsd %xmm3, %xmm0
addsd 0x30(%rsp,%rcx), %xmm0
movsd 0x70(%rsp,%rcx), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%r14,%rcx)
movsd (%rax,%rcx), %xmm0
movsd %xmm0, (%rbx,%rcx)
addq $0x8, %rcx
jmp 0xace7
movapd %xmm2, %xmm0
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq