#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 */
double glmDotProduct3d(double const *, double const *);
double glmRayPlaneIntersectiond(const double rayOrigin[3],
                                const double rayDirection[3],
                                const double planeOrigin[3],
                                const double planeNormal[3],
                                double intersection[3]) {
  double numer, denom, d;
  d = glmDotProduct3d(planeNormal, planeOrigin);
  numer = -glmDotProduct3d(planeNormal, rayOrigin) + d;
  denom = glmDotProduct3d(planeNormal, rayDirection);
  if (denom == 0)
    return -1;
  d = numer / denom;
  if (d < 0)
    return -1;
  if (intersection) {
    intersection[0] = rayOrigin[0] + d * rayDirection[0];
    intersection[1] = rayOrigin[1] + d * rayDirection[1];
    intersection[2] = rayOrigin[2] + d * rayDirection[2];
  }
  return d;
}


x86 assembly (clang, -O0):
<glmRayPlaneIntersectiond>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <glmDotProduct3d@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <glmDotProduct3d@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <glmDotProduct3d@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a8 <glmRayPlaneIntersectiond+0x98>
jp     11a8 <glmRayPlaneIntersectiond+0x98>
movsd  0xe62(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1261 <glmRayPlaneIntersectiond+0x151>
movsd  -0x38(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    11d7 <glmRayPlaneIntersectiond+0xc7>
movsd  0xe33(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1261 <glmRayPlaneIntersectiond+0x151>
cmpq   $0x0,-0x30(%rbp)
je     1257 <glmRayPlaneIntersectiond+0x147>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
movsd  -0x48(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
movsd  -0x48(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm1
movsd  -0x48(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glmRayPlaneIntersectiond>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r14
mov    %rcx,%rbx
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rcx,%rdi
mov    %rdx,%rsi
call   1030 <glmDotProduct3d@plt>
movsd  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <glmDotProduct3d@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <glmDotProduct3d@plt>
movapd %xmm0,%xmm1
movsd  0xea0(%rip),%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jne    116c <glmRayPlaneIntersectiond+0x5c>
jnp    11d1 <glmRayPlaneIntersectiond+0xc1>
movsd  0x10(%rsp),%xmm3
subsd  0x8(%rsp),%xmm3
divsd  %xmm1,%xmm3
ucomisd %xmm3,%xmm2
ja     11d1 <glmRayPlaneIntersectiond+0xc1>
movapd %xmm3,%xmm1
test   %r14,%r14
je     11cd <glmRayPlaneIntersectiond+0xbd>
movsd  (%r12),%xmm0
mulsd  %xmm1,%xmm0
addsd  (%r15),%xmm0
movsd  %xmm0,(%r14)
movsd  0x8(%r12),%xmm0
mulsd  %xmm1,%xmm0
addsd  0x8(%r15),%xmm0
movsd  %xmm0,0x8(%r14)
movsd  0x10(%r12),%xmm0
mulsd  %xmm1,%xmm0
addsd  0x10(%r15),%xmm0
movsd  %xmm0,0x10(%r14)
movapd %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @glmRayPlaneIntersectiond(double* %0, double* %1, double* %2, double* %3, double* %4) {
%6 = alloca double
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca double*
%12 = alloca double
%13 = alloca double
%14 = alloca double
store double* %0, double** %7
store double* %1, double** %8
store double* %2, double** %9
store double* %3, double** %10
store double* %4, double** %11
%15 = load double*, double** %10
%16 = load double*, double** %9
%17 = call double @glmDotProduct3d(double* %15, double* %16)
store double %17, double* %14
%18 = load double*, double** %10
%19 = load double*, double** %7
%20 = call double @glmDotProduct3d(double* %18, double* %19)
%21 = fneg double %20
%22 = load double, double* %14
%23 = fadd double %21, %22
store double %23, double* %12
%24 = load double*, double** %10
%25 = load double*, double** %8
%26 = call double @glmDotProduct3d(double* %24, double* %25)
store double %26, double* %13
%27 = load double, double* %13
%28 = fcmp oeq double %27, 0.000000e+00
br i1 %28, label %29, label %30
29: ; preds = %5
store double -1.000000e+00, double* %6
br label %73
30: ; preds = %5
%31 = load double, double* %12
%32 = load double, double* %13
%33 = fdiv double %31, %32
store double %33, double* %14
%34 = load double, double* %14
%35 = fcmp olt double %34, 0.000000e+00
br i1 %35, label %36, label %37
36: ; preds = %30
store double -1.000000e+00, double* %6
br label %73
37: ; preds = %30
%38 = load double*, double** %11
%39 = icmp ne double* %38, null
br i1 %39, label %40, label %71
40: ; preds = %37
%41 = load double*, double** %7
%42 = getelementptr inbounds double, double* %41, i64 0
%43 = load double, double* %42
%44 = load double, double* %14
%45 = load double*, double** %8
%46 = getelementptr inbounds double, double* %45, i64 0
%47 = load double, double* %46
%48 = call double @llvm.fmuladd.f64(double %44, double %47, double %43)
%49 = load double*, double** %11
%50 = getelementptr inbounds double, double* %49, i64 0
store double %48, double* %50
%51 = load double*, double** %7
%52 = getelementptr inbounds double, double* %51, i64 1
%53 = load double, double* %52
%54 = load double, double* %14
%55 = load double*, double** %8
%56 = getelementptr inbounds double, double* %55, i64 1
%57 = load double, double* %56
%58 = call double @llvm.fmuladd.f64(double %54, double %57, double %53)
%59 = load double*, double** %11
%60 = getelementptr inbounds double, double* %59, i64 1
store double %58, double* %60
%61 = load double*, double** %7
%62 = getelementptr inbounds double, double* %61, i64 2
%63 = load double, double* %62
%64 = load double, double* %14
%65 = load double*, double** %8
%66 = getelementptr inbounds double, double* %65, i64 2
%67 = load double, double* %66
%68 = call double @llvm.fmuladd.f64(double %64, double %67, double %63)
%69 = load double*, double** %11
%70 = getelementptr inbounds double, double* %69, i64 2
store double %68, double* %70
br label %71
71: ; preds = %40, %37
%72 = load double, double* %14
store double %72, double* %6
br label %73
73: ; preds = %71, %36, %29
%74 = load double, double* %6
ret double %74
}

LLVM IR (-O2):
define double @glmRayPlaneIntersectiond(double* %0, double* %1, double* %2, double* %3, double* writeonly %4) {
%6 = tail call double @glmDotProduct3d(double* %3, double* %2)
%7 = tail call double @glmDotProduct3d(double* %3, double* %0)
%8 = tail call double @glmDotProduct3d(double* %3, double* %1)
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %32, label %10
10: ; preds = %5
%11 = fsub double %6, %7
%12 = fdiv double %11, %8
%13 = fcmp olt double %12, 0.000000e+00
br i1 %13, label %32, label %14
14: ; preds = %10
%15 = icmp eq double* %4, null
br i1 %15, label %32, label %16
16: ; preds = %14
%17 = load double, double* %0
%18 = load double, double* %1
%19 = tail call double @llvm.fmuladd.f64(double %12, double %18, double %17)
store double %19, double* %4
%20 = getelementptr inbounds double, double* %0, i64 1
%21 = load double, double* %20
%22 = getelementptr inbounds double, double* %1, i64 1
%23 = load double, double* %22
%24 = tail call double @llvm.fmuladd.f64(double %12, double %23, double %21)
%25 = getelementptr inbounds double, double* %4, i64 1
store double %24, double* %25
%26 = getelementptr inbounds double, double* %0, i64 2
%27 = load double, double* %26
%28 = getelementptr inbounds double, double* %1, i64 2
%29 = load double, double* %28
%30 = tail call double @llvm.fmuladd.f64(double %12, double %29, double %27)
%31 = getelementptr inbounds double, double* %4, i64 2
store double %30, double* %31
br label %32
32: ; preds = %14, %16, %10, %5
%33 = phi double [ -1.000000e+00, %5 ], [ -1.000000e+00, %10 ], [ %12, %16 ], [ %12, %14 ]
ret double %33
}