#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 glmDotProduct4d(double const *, double const *);
double glmRaySpaceIntersectiond(const double rayOrigin[4],
                                const double rayDirection[4],
                                const double spaceOrigin[4],
                                const double spaceNormal[4],
                                double intersection[4]) {
  double numer, denom, d;
  d = glmDotProduct4d(spaceNormal, spaceOrigin);
  numer = -glmDotProduct4d(spaceNormal, rayOrigin) + d;
  denom = glmDotProduct4d(spaceNormal, 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];
    intersection[3] = rayOrigin[3] + d * rayDirection[3];
  }
  return d;
}


x86 assembly (clang, -O0):
<glmRaySpaceIntersectiond>:
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 <glmDotProduct4d@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <glmDotProduct4d@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 <glmDotProduct4d@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a8 <glmRaySpaceIntersectiond+0x98>
jp     11a8 <glmRaySpaceIntersectiond+0x98>
movsd  0xe62(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1289 <glmRaySpaceIntersectiond+0x179>
movsd  -0x38(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    11d7 <glmRaySpaceIntersectiond+0xc7>
movsd  0xe33(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1289 <glmRaySpaceIntersectiond+0x179>
cmpq   $0x0,-0x30(%rbp)
je     127f <glmRaySpaceIntersectiond+0x16f>
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)
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm1
movsd  -0x48(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x18(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,0x18(%rax)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glmRaySpaceIntersectiond>:
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 <glmDotProduct4d@plt>
movsd  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <glmDotProduct4d@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <glmDotProduct4d@plt>
movapd %xmm0,%xmm1
movsd  0xea0(%rip),%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jne    116c <glmRaySpaceIntersectiond+0x5c>
jnp    11e8 <glmRaySpaceIntersectiond+0xd8>
movsd  0x10(%rsp),%xmm3
subsd  0x8(%rsp),%xmm3
divsd  %xmm1,%xmm3
ucomisd %xmm3,%xmm2
ja     11e8 <glmRaySpaceIntersectiond+0xd8>
movapd %xmm3,%xmm1
test   %r14,%r14
je     11e4 <glmRaySpaceIntersectiond+0xd4>
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)
movsd  0x18(%r12),%xmm0
mulsd  %xmm1,%xmm0
addsd  0x18(%r15),%xmm0
movsd  %xmm0,0x18(%r14)
movapd %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @glmRaySpaceIntersectiond(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 @glmDotProduct4d(double* %15, double* %16)
store double %17, double* %14
%18 = load double*, double** %10
%19 = load double*, double** %7
%20 = call double @glmDotProduct4d(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 @glmDotProduct4d(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 %83
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 %83
37: ; preds = %30
%38 = load double*, double** %11
%39 = icmp ne double* %38, null
br i1 %39, label %40, label %81
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
%71 = load double*, double** %7
%72 = getelementptr inbounds double, double* %71, i64 3
%73 = load double, double* %72
%74 = load double, double* %14
%75 = load double*, double** %8
%76 = getelementptr inbounds double, double* %75, i64 3
%77 = load double, double* %76
%78 = call double @llvm.fmuladd.f64(double %74, double %77, double %73)
%79 = load double*, double** %11
%80 = getelementptr inbounds double, double* %79, i64 3
store double %78, double* %80
br label %81
81: ; preds = %40, %37
%82 = load double, double* %14
store double %82, double* %6
br label %83
83: ; preds = %81, %36, %29
%84 = load double, double* %6
ret double %84
}

LLVM IR (-O2):
define double @glmRaySpaceIntersectiond(double* %0, double* %1, double* %2, double* %3, double* writeonly %4) {
%6 = tail call double @glmDotProduct4d(double* %3, double* %2)
%7 = tail call double @glmDotProduct4d(double* %3, double* %0)
%8 = tail call double @glmDotProduct4d(double* %3, double* %1)
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %38, 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 %38, label %14
14: ; preds = %10
%15 = icmp eq double* %4, null
br i1 %15, label %38, 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
%32 = getelementptr inbounds double, double* %0, i64 3
%33 = load double, double* %32
%34 = getelementptr inbounds double, double* %1, i64 3
%35 = load double, double* %34
%36 = tail call double @llvm.fmuladd.f64(double %12, double %35, double %33)
%37 = getelementptr inbounds double, double* %4, i64 3
store double %36, double* %37
br label %38
38: ; preds = %14, %16, %10, %5
%39 = phi double [ -1.000000e+00, %5 ], [ -1.000000e+00, %10 ], [ %12, %16 ], [ %12, %14 ]
ret double %39
}