#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 */
float glmComputeVectorLength3f(float *);
float glmDotProduct3f(float *, float const *);
int /*<<< orphan*/ glmMakeVector3f(float *, float const *, float const *);
float sqrt(float);
float glmRaySphereIntersectionf(const float rO[3], const float rV[3],
                                const float sO[3], float sR,
                                float intersection[3]) {
  float c, v, d;
  float q[3];
  glmMakeVector3f(q, rO, sO);
  c = glmComputeVectorLength3f(q);
  if (c < sR)
    return 0;
  v = glmDotProduct3f(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):
<glmRaySphereIntersectionf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movss  %xmm0,-0x24(%rbp)
mov    %rcx,-0x30(%rbp)
lea    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <glmMakeVector3f@plt>
lea    -0x48(%rbp),%rdi
call   1030 <glmComputeVectorLength3f@plt>
movss  %xmm0,-0x34(%rbp)
movss  -0x34(%rbp),%xmm1
movss  -0x24(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    119c <glmRaySphereIntersectionf+0x5c>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    12c9 <glmRaySphereIntersectionf+0x189>
lea    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <glmDotProduct3f@plt>
movss  %xmm0,-0x38(%rbp)
movss  -0x24(%rbp),%xmm0
movss  -0x24(%rbp),%xmm2
movss  -0x34(%rbp),%xmm1
movss  -0x34(%rbp),%xmm4
movss  -0x38(%rbp),%xmm3
mulss  -0x38(%rbp),%xmm3
movd   %xmm3,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm3
mulss  %xmm4,%xmm1
addss  %xmm3,%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x3c(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x3c(%rbp),%xmm0
jbe    121a <glmRaySphereIntersectionf+0xda>
movss  0xdf0(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    12c9 <glmRaySphereIntersectionf+0x189>
movss  -0x38(%rbp),%xmm0
movss  %xmm0,-0x4c(%rbp)
movss  -0x3c(%rbp),%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x4c(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0x3c(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12bf <glmRaySphereIntersectionf+0x17f>
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm1
movss  -0x3c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  (%rax),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm1
movss  -0x3c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  0x4(%rax),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movss  %xmm0,0x4(%rax)
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm1
movss  -0x3c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  0x8(%rax),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movss  %xmm0,0x8(%rax)
movss  -0x3c(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glmRaySphereIntersectionf>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
movss  %xmm0,0x4(%rsp)
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <glmMakeVector3f@plt>
mov    %rbx,%rdi
call   1030 <glmComputeVectorLength3f@plt>
movss  0x4(%rsp),%xmm2
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm2
ja     1239 <glmRaySphereIntersectionf+0xf9>
lea    0xc(%rsp),%rdi
mov    %r15,%rsi
movss  %xmm0,0x8(%rsp)
call   1050 <glmDotProduct3f@plt>
movss  0x4(%rsp),%xmm2
movaps %xmm0,%xmm1
mulss  %xmm0,%xmm0
movss  0x8(%rsp),%xmm3
mulss  %xmm3,%xmm3
subss  %xmm0,%xmm3
mulss  %xmm2,%xmm2
subss  %xmm3,%xmm2
xorps  %xmm0,%xmm0
ucomiss %xmm2,%xmm0
jbe    11cc <glmRaySphereIntersectionf+0x8c>
movss  0xe36(%rip),%xmm1
jmp    1239 <glmRaySphereIntersectionf+0xf9>
ucomiss %xmm0,%xmm2
jb     11da <glmRaySphereIntersectionf+0x9a>
xorps  %xmm0,%xmm0
sqrtss %xmm2,%xmm0
jmp    11ee <glmRaySphereIntersectionf+0xae>
movaps %xmm2,%xmm0
movss  %xmm1,0x4(%rsp)
call   1060 <sqrt@plt>
movss  0x4(%rsp),%xmm1
subss  %xmm0,%xmm1
test   %r14,%r14
je     1239 <glmRaySphereIntersectionf+0xf9>
movss  (%r15),%xmm0
mulss  %xmm1,%xmm0
addss  (%r12),%xmm0
movss  %xmm0,(%r14)
movss  0x4(%r15),%xmm0
mulss  %xmm1,%xmm0
addss  0x4(%r12),%xmm0
movss  %xmm0,0x4(%r14)
movss  0x8(%r15),%xmm0
mulss  %xmm1,%xmm0
addss  0x8(%r12),%xmm0
movss  %xmm0,0x8(%r14)
movaps %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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