#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 glmComputeVectorLength2f(float *);
float glmDotProduct2f(float *, float const *);
int /*<<< orphan*/ glmMakeVector2f(float *, float const *, float const *);
float sqrt(float);
float glmRayCircleIntersectionf(const float rO[2], const float rV[2],
                                const float sO[2], float sR,
                                float intersection[2]) {
  float c, v, d;
  float q[2];
  glmMakeVector2f(q, rO, sO);
  c = glmComputeVectorLength2f(q);
  if (c < sR)
    return 0;
  v = glmDotProduct2f(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];
  }
  return d;
}


x86 assembly (clang, -O0):
<glmRayCircleIntersectionf>:
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    -0x44(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <glmMakeVector2f@plt>
lea    -0x44(%rbp),%rdi
call   1030 <glmComputeVectorLength2f@plt>
movss  %xmm0,-0x34(%rbp)
movss  -0x34(%rbp),%xmm1
movss  -0x24(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    119c <glmRayCircleIntersectionf+0x5c>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    12a1 <glmRayCircleIntersectionf+0x161>
lea    -0x44(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <glmDotProduct2f@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 <glmRayCircleIntersectionf+0xda>
movss  0xdf0(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    12a1 <glmRayCircleIntersectionf+0x161>
movss  -0x38(%rbp),%xmm0
movss  %xmm0,-0x48(%rbp)
movss  -0x3c(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x48(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0x3c(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1297 <glmRayCircleIntersectionf+0x157>
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)
movss  -0x3c(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glmRayCircleIntersectionf>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
movss  %xmm0,0x8(%rsp)
mov    %rsi,%r15
mov    %rdi,%r12
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <glmMakeVector2f@plt>
mov    %rbx,%rdi
call   1030 <glmComputeVectorLength2f@plt>
movss  0x8(%rsp),%xmm2
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm2
ja     1222 <glmRayCircleIntersectionf+0xe2>
lea    0x10(%rsp),%rdi
mov    %r15,%rsi
movss  %xmm0,0xc(%rsp)
call   1060 <glmDotProduct2f@plt>
movss  0x8(%rsp),%xmm2
movaps %xmm0,%xmm1
mulss  %xmm0,%xmm0
movss  0xc(%rsp),%xmm3
mulss  %xmm3,%xmm3
subss  %xmm0,%xmm3
mulss  %xmm2,%xmm2
subss  %xmm3,%xmm2
xorps  %xmm0,%xmm0
ucomiss %xmm2,%xmm0
jbe    11cc <glmRayCircleIntersectionf+0x8c>
movss  0xe36(%rip),%xmm1
jmp    1222 <glmRayCircleIntersectionf+0xe2>
ucomiss %xmm0,%xmm2
jb     11da <glmRayCircleIntersectionf+0x9a>
xorps  %xmm0,%xmm0
sqrtss %xmm2,%xmm0
jmp    11ee <glmRayCircleIntersectionf+0xae>
movaps %xmm2,%xmm0
movss  %xmm1,0x8(%rsp)
call   1050 <sqrt@plt>
movss  0x8(%rsp),%xmm1
subss  %xmm0,%xmm1
test   %r14,%r14
je     1222 <glmRayCircleIntersectionf+0xe2>
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)
movaps %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define float @glmRayCircleIntersectionf(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 [2 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 [2 x float], [2 x float]* %15, i64 0, i64 0
%17 = load float*, float** %7
%18 = load float*, float** %9
%19 = call i32 @glmMakeVector2f(float* %16, float* %17, float* %18)
%20 = getelementptr inbounds [2 x float], [2 x float]* %15, i64 0, i64 0
%21 = call float @glmComputeVectorLength2f(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 %74
26: ; preds = %5
%27 = getelementptr inbounds [2 x float], [2 x float]* %15, i64 0, i64 0
%28 = load float*, float** %8
%29 = call float @glmDotProduct2f(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 %74
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 %72
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
br label %72
72: ; preds = %51, %44
%73 = load float, float* %14
store float %73, float* %6
br label %74
74: ; preds = %72, %43, %25
%75 = load float, float* %6
ret float %75
}

LLVM IR (-O2):
define float @glmRayCircleIntersectionf(float* %0, float* %1, float* %2, float %3, float* writeonly %4) {
%6 = alloca [2 x float]
%7 = bitcast [2 x float]* %6 to i8*
%8 = getelementptr inbounds [2 x float], [2 x float]* %6, i64 0, i64 0
%9 = call i32 @glmMakeVector2f(float* %8, float* %0, float* %2)
%10 = call float @glmComputeVectorLength2f(float* %8)
%11 = fcmp olt float %10, %3
br i1 %11, label %34, label %12
12: ; preds = %5
%13 = call float @glmDotProduct2f(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 %34, 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 %34, 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
br label %34
34: ; preds = %20, %24, %12, %5
%35 = phi float [ 0.000000e+00, %5 ], [ -1.000000e+00, %12 ], [ %22, %24 ], [ %22, %20 ]
ret float %35
}