#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ glmIsPointInTriangle3d(double *, double const *,
                                          double const *, double const *);
double glmRayPlaneIntersectiond(double const *, double const *, double const *,
                                double const *, double *);
double glmRayTriangleIntersectiond(const double rayOrigin[3],
                                   const double rayVector[3],
                                   const double c1[3], const double c2[3],
                                   const double c3[3], const double normal[3],
                                   double intersection[3]) {
  double distance;
  distance =
      glmRayPlaneIntersectiond(rayOrigin, rayVector, c1, normal, intersection);
  if (distance < 0)
    return -1;
  if (!glmIsPointInTriangle3d(intersection, c1, c2, c3))
    return -1;
  return distance;
}


x86 assembly (clang, -O0):
<glmRayTriangleIntersectiond>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    0x10(%rbp),%r8
call   1030 <glmRayPlaneIntersectiond@plt>
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    1182 <glmRayTriangleIntersectiond+0x62>
movsd  0xe88(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11bc <glmRayTriangleIntersectiond+0x9c>
mov    0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1040 <glmIsPointInTriangle3d@plt>
cmp    $0x0,%eax
jne    11b2 <glmRayTriangleIntersectiond+0x92>
movsd  0xe58(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11bc <glmRayTriangleIntersectiond+0x9c>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glmRayTriangleIntersectiond>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%rbx
mov    0x30(%rsp),%r12
mov    %r9,%rcx
mov    %r12,%r8
call   1030 <glmRayPlaneIntersectiond@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     116c <glmRayTriangleIntersectiond+0x4c>
movsd  %xmm0,(%rsp)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1040 <glmIsPointInTriangle3d@plt>
test   %eax,%eax
je     116c <glmRayTriangleIntersectiond+0x4c>
movsd  (%rsp),%xmm0
jmp    1174 <glmRayTriangleIntersectiond+0x54>
movsd  0xe8c(%rip),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @glmRayTriangleIntersectiond(double* %0, double* %1, double* %2, double* %3, double* %4, double* %5, double* %6) {
%8 = alloca double
%9 = alloca double*
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
%14 = alloca double*
%15 = alloca double*
%16 = alloca double
store double* %0, double** %9
store double* %1, double** %10
store double* %2, double** %11
store double* %3, double** %12
store double* %4, double** %13
store double* %5, double** %14
store double* %6, double** %15
%17 = load double*, double** %9
%18 = load double*, double** %10
%19 = load double*, double** %11
%20 = load double*, double** %14
%21 = load double*, double** %15
%22 = call double @glmRayPlaneIntersectiond(double* %17, double* %18, double* %19, double* %20, double* %21)
store double %22, double* %16
%23 = load double, double* %16
%24 = fcmp olt double %23, 0.000000e+00
br i1 %24, label %25, label %26
25: ; preds = %7
store double -1.000000e+00, double* %8
br label %36
26: ; preds = %7
%27 = load double*, double** %15
%28 = load double*, double** %11
%29 = load double*, double** %12
%30 = load double*, double** %13
%31 = call i32 @glmIsPointInTriangle3d(double* %27, double* %28, double* %29, double* %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %26
store double -1.000000e+00, double* %8
br label %36
34: ; preds = %26
%35 = load double, double* %16
store double %35, double* %8
br label %36
36: ; preds = %34, %33, %25
%37 = load double, double* %8
ret double %37
}

LLVM IR (-O2):
define double @glmRayTriangleIntersectiond(double* %0, double* %1, double* %2, double* %3, double* %4, double* %5, double* %6) {
%8 = tail call double @glmRayPlaneIntersectiond(double* %0, double* %1, double* %2, double* %5, double* %6)
%9 = fcmp olt double %8, 0.000000e+00
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = tail call i32 @glmIsPointInTriangle3d(double* %6, double* %2, double* %3, double* %4)
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, double -1.000000e+00, double %8
br label %14
14: ; preds = %10, %7
%15 = phi double [ -1.000000e+00, %7 ], [ %13, %10 ]
ret double %15
}