#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 glmComputeVectorLength3d(double *);
double glmDotProduct3d(double *, double const *);
int /*<<< orphan*/ glmMakeVector3d(double *, double const *, double const *);
double sqrt(double);
double glmRaySphereIntersectiond(const double rO[3], const double rV[3],
                                 const double sO[3], double sR,
                                 double intersection[3]) {
  double c, v, d;
  double q[3];
  glmMakeVector3d(q, rO, sO);
  c = glmComputeVectorLength3d(q);
  if (c < sR)
    return 0;
  v = glmDotProduct3d(q, rV);
  d = sR * sR - (c * c - v * v);
  if (d < 0)
    return -1;
  d = v - sqrt(d);
  if (intersection) {
    intersection[0] = rO[0] + d * rV[0];
    intersection[1] = rO[1] + d * rV[1];
    intersection[2] = rO[2] + d * rV[2];
  }
  return d;
}


x86 assembly (clang, -O0):
<glmRaySphereIntersectiond>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movsd  %xmm0,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <glmMakeVector3d@plt>
lea    -0x60(%rbp),%rdi
call   1030 <glmComputeVectorLength3d@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    119d <glmRaySphereIntersectiond+0x5d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12df <glmRaySphereIntersectiond+0x19f>
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <glmDotProduct3d@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm4
movsd  -0x40(%rbp),%xmm3
mulsd  -0x40(%rbp),%xmm3
movq   %xmm3,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm3
mulsd  %xmm4,%xmm1
addsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    1230 <glmRaySphereIntersectiond+0xf0>
movsd  0xdda(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12df <glmRaySphereIntersectiond+0x19f>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12d5 <glmRaySphereIntersectiond+0x195>
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    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glmRaySphereIntersectiond>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r14
movsd  %xmm0,(%rsp)
mov    %rsi,%r15
mov    %rdi,%r12
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <glmMakeVector3d@plt>
mov    %rbx,%rdi
call   1030 <glmComputeVectorLength3d@plt>
movsd  (%rsp),%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm2
ja     123b <glmRaySphereIntersectiond+0xfb>
lea    0x10(%rsp),%rdi
mov    %r15,%rsi
movsd  %xmm0,0x8(%rsp)
call   1050 <glmDotProduct3d@plt>
movsd  (%rsp),%xmm2
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm3
mulsd  %xmm3,%xmm3
subsd  %xmm0,%xmm3
mulsd  %xmm2,%xmm2
subsd  %xmm3,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
jbe    11ce <glmRaySphereIntersectiond+0x8e>
movsd  0xe34(%rip),%xmm1
jmp    123b <glmRaySphereIntersectiond+0xfb>
ucomisd %xmm0,%xmm2
jb     11dd <glmRaySphereIntersectiond+0x9d>
xorps  %xmm0,%xmm0
sqrtsd %xmm2,%xmm0
jmp    11f0 <glmRaySphereIntersectiond+0xb0>
movapd %xmm2,%xmm0
movsd  %xmm1,(%rsp)
call   1060 <sqrt@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
test   %r14,%r14
je     123b <glmRaySphereIntersectiond+0xfb>
movsd  (%r15),%xmm0
mulsd  %xmm1,%xmm0
addsd  (%r12),%xmm0
movsd  %xmm0,(%r14)
movsd  0x8(%r15),%xmm0
mulsd  %xmm1,%xmm0
addsd  0x8(%r12),%xmm0
movsd  %xmm0,0x8(%r14)
movsd  0x10(%r15),%xmm0
mulsd  %xmm1,%xmm0
addsd  0x10(%r12),%xmm0
movsd  %xmm0,0x10(%r14)
movapd %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @glmRaySphereIntersectiond(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
%15 = alloca [3 x 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
%16 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 0
%17 = load double*, double** %7
%18 = load double*, double** %9
%19 = call i32 @glmMakeVector3d(double* %16, double* %17, double* %18)
%20 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 0
%21 = call double @glmComputeVectorLength3d(double* %20)
store double %21, double* %12
%22 = load double, double* %12
%23 = load double, double* %10
%24 = fcmp olt double %22, %23
br i1 %24, label %25, label %26
25: ; preds = %5
store double 0.000000e+00, double* %6
br label %84
26: ; preds = %5
%27 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 0
%28 = load double*, double** %8
%29 = call double @glmDotProduct3d(double* %27, double* %28)
store double %29, double* %13
%30 = load double, double* %10
%31 = load double, double* %10
%32 = load double, double* %12
%33 = load double, double* %12
%34 = load double, double* %13
%35 = load double, double* %13
%36 = fmul double %34, %35
%37 = fneg double %36
%38 = call double @llvm.fmuladd.f64(double %32, double %33, double %37)
%39 = fneg double %38
%40 = call double @llvm.fmuladd.f64(double %30, double %31, double %39)
store double %40, double* %14
%41 = load double, double* %14
%42 = fcmp olt double %41, 0.000000e+00
br i1 %42, label %43, label %44
43: ; preds = %26
store double -1.000000e+00, double* %6
br label %84
44: ; preds = %26
%45 = load double, double* %13
%46 = load double, double* %14
%47 = call double @sqrt(double %46)
%48 = fsub double %45, %47
store double %48, double* %14
%49 = load double*, double** %11
%50 = icmp ne double* %49, null
br i1 %50, label %51, label %82
51: ; preds = %44
%52 = load double*, double** %7
%53 = getelementptr inbounds double, double* %52, i64 0
%54 = load double, double* %53
%55 = load double, double* %14
%56 = load double*, double** %8
%57 = getelementptr inbounds double, double* %56, i64 0
%58 = load double, double* %57
%59 = call double @llvm.fmuladd.f64(double %55, double %58, double %54)
%60 = load double*, double** %11
%61 = getelementptr inbounds double, double* %60, i64 0
store double %59, double* %61
%62 = load double*, double** %7
%63 = getelementptr inbounds double, double* %62, i64 1
%64 = load double, double* %63
%65 = load double, double* %14
%66 = load double*, double** %8
%67 = getelementptr inbounds double, double* %66, i64 1
%68 = load double, double* %67
%69 = call double @llvm.fmuladd.f64(double %65, double %68, double %64)
%70 = load double*, double** %11
%71 = getelementptr inbounds double, double* %70, i64 1
store double %69, double* %71
%72 = load double*, double** %7
%73 = getelementptr inbounds double, double* %72, i64 2
%74 = load double, double* %73
%75 = load double, double* %14
%76 = load double*, double** %8
%77 = getelementptr inbounds double, double* %76, i64 2
%78 = load double, double* %77
%79 = call double @llvm.fmuladd.f64(double %75, double %78, double %74)
%80 = load double*, double** %11
%81 = getelementptr inbounds double, double* %80, i64 2
store double %79, double* %81
br label %82
82: ; preds = %51, %44
%83 = load double, double* %14
store double %83, double* %6
br label %84
84: ; preds = %82, %43, %25
%85 = load double, double* %6
ret double %85
}

LLVM IR (-O2):
define double @glmRaySphereIntersectiond(double* %0, double* %1, double* %2, double %3, double* writeonly %4) {
%6 = alloca [3 x double]
%7 = bitcast [3 x double]* %6 to i8*
%8 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%9 = call i32 @glmMakeVector3d(double* %8, double* %0, double* %2)
%10 = call double @glmComputeVectorLength3d(double* %8)
%11 = fcmp olt double %10, %3
br i1 %11, label %40, label %12
12: ; preds = %5
%13 = call double @glmDotProduct3d(double* %8, double* %1)
%14 = fneg double %13
%15 = fmul double %13, %14
%16 = call double @llvm.fmuladd.f64(double %10, double %10, double %15)
%17 = fneg double %16
%18 = call double @llvm.fmuladd.f64(double %3, double %3, double %17)
%19 = fcmp olt double %18, 0.000000e+00
br i1 %19, label %40, label %20
20: ; preds = %12
%21 = call double @sqrt(double %18)
%22 = fsub double %13, %21
%23 = icmp eq double* %4, null
br i1 %23, label %40, label %24
24: ; preds = %20
%25 = load double, double* %0
%26 = load double, double* %1
%27 = call double @llvm.fmuladd.f64(double %22, double %26, double %25)
store double %27, double* %4
%28 = getelementptr inbounds double, double* %0, i64 1
%29 = load double, double* %28
%30 = getelementptr inbounds double, double* %1, i64 1
%31 = load double, double* %30
%32 = call double @llvm.fmuladd.f64(double %22, double %31, double %29)
%33 = getelementptr inbounds double, double* %4, i64 1
store double %32, double* %33
%34 = getelementptr inbounds double, double* %0, i64 2
%35 = load double, double* %34
%36 = getelementptr inbounds double, double* %1, i64 2
%37 = load double, double* %36
%38 = call double @llvm.fmuladd.f64(double %22, double %37, double %35)
%39 = getelementptr inbounds double, double* %4, i64 2
store double %38, double* %39
br label %40
40: ; preds = %20, %24, %12, %5
%41 = phi double [ 0.000000e+00, %5 ], [ -1.000000e+00, %12 ], [ %22, %24 ], [ %22, %20 ]
ret double %41
}