#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*/ glmIsPointInTriangle3f(float *, float const *, float const *,
                                          float const *);
float glmRayPlaneIntersectionf(float const *, float const *, float const *,
                               float const *, float *);
float glmRayTriangleIntersectionf(const float rayOrigin[3],
                                  const float rayVector[3], const float c1[3],
                                  const float c2[3], const float c3[3],
                                  const float normal[3],
                                  float intersection[3]) {
  float distance;
  distance =
      glmRayPlaneIntersectionf(rayOrigin, rayVector, c1, normal, intersection);
  if (distance < 0)
    return -1;
  if (!glmIsPointInTriangle3f(intersection, c1, c2, c3))
    return -1;
  return distance;
}


x86 assembly (clang, -O0):
<glmRayTriangleIntersectionf>:
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 <glmRayPlaneIntersectionf@plt>
movss  %xmm0,-0x3c(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x3c(%rbp),%xmm0
jbe    1181 <glmRayTriangleIntersectionf+0x61>
movss  0xe89(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11bb <glmRayTriangleIntersectionf+0x9b>
mov    0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1040 <glmIsPointInTriangle3f@plt>
cmp    $0x0,%eax
jne    11b1 <glmRayTriangleIntersectionf+0x91>
movss  0xe59(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11bb <glmRayTriangleIntersectionf+0x9b>
movss  -0x3c(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glmRayTriangleIntersectionf>:
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 <glmRayPlaneIntersectionf@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
ja     116c <glmRayTriangleIntersectionf+0x4c>
movss  %xmm0,0x4(%rsp)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1040 <glmIsPointInTriangle3f@plt>
test   %eax,%eax
je     116c <glmRayTriangleIntersectionf+0x4c>
movss  0x4(%rsp),%xmm0
jmp    1174 <glmRayTriangleIntersectionf+0x54>
movss  0xe8c(%rip),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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