#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 sqrt(double);
int sphere_intersect(double *l0, double *l1, double x, double y, double z,
                     double kx, double ky, double kz, double r) {
  double B, C, D, A;
  A = kx * kx + ky * ky + kz * kz;
  B = (x * kx + y * ky + z * kz);
  C = x * x + y * y + z * z - r * r;
  D = B * B - A * C;
  if (D < 0 || A == 0)
    return 0;
  D = sqrt(D);
  if (B >= 0) {
    *l0 = (-B - D) / A;
    *l1 = C / (*l0 * A);
  } else {
    *l0 = C / (-B + D);
    *l1 = C / (*l0 * A);
  }
  *l0 *= sqrt(A);
  *l1 *= sqrt(A);
  return 1;
}


x86 assembly (clang, -O0):
<sphere_intersect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
movsd  %xmm2,-0x30(%rbp)
movsd  %xmm3,-0x38(%rbp)
movsd  %xmm4,-0x40(%rbp)
movsd  %xmm5,-0x48(%rbp)
movsd  %xmm6,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x70(%rbp),%xmm1
mulsd  -0x60(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x68(%rbp),%xmm0
ja     1263 <sphere_intersect+0x153>
movsd  -0x70(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    126f <sphere_intersect+0x15f>
jp     126f <sphere_intersect+0x15f>
movl   $0x0,-0x4(%rbp)
jmp    1364 <sphere_intersect+0x254>
movsd  -0x68(%rbp),%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x58(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     12e1 <sphere_intersect+0x1d1>
movsd  -0x58(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
subsd  -0x68(%rbp),%xmm0
divsd  -0x70(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x60(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mulsd  -0x70(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1331 <sphere_intersect+0x221>
movsd  -0x60(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
addsd  -0x68(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x60(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mulsd  -0x70(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x70(%rbp),%xmm0
call   1030 <sqrt@plt>
mov    -0x10(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x70(%rbp),%xmm0
call   1030 <sqrt@plt>
mov    -0x18(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sphere_intersect>:
movapd %xmm1,%xmm8
mulsd  %xmm4,%xmm8
mulsd  %xmm4,%xmm4
movapd %xmm0,%xmm7
mulsd  %xmm3,%xmm7
mulsd  %xmm3,%xmm3
addsd  %xmm4,%xmm3
movapd %xmm2,%xmm4
mulsd  %xmm5,%xmm4
mulsd  %xmm5,%xmm5
addsd  %xmm3,%xmm5
addsd  %xmm8,%xmm7
addsd  %xmm4,%xmm7
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
mulsd  %xmm6,%xmm6
subsd  %xmm6,%xmm2
movapd %xmm2,%xmm1
mulsd  %xmm5,%xmm1
movapd %xmm7,%xmm0
mulsd  %xmm7,%xmm0
subsd  %xmm1,%xmm0
xor    %eax,%eax
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     1277 <sphere_intersect+0x167>
ucomisd %xmm1,%xmm5
jne    1193 <sphere_intersect+0x83>
jnp    1277 <sphere_intersect+0x167>
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
movsd  %xmm5,0x8(%rsp)
jb     11cc <sphere_intersect+0xbc>
sqrtsd %xmm0,%xmm0
ucomisd %xmm1,%xmm7
jb     11f7 <sphere_intersect+0xe7>
xorpd  0xe3e(%rip),%xmm7
subsd  %xmm0,%xmm7
divsd  %xmm5,%xmm7
jmp    1203 <sphere_intersect+0xf3>
movsd  %xmm2,(%rsp)
movapd %xmm7,0x10(%rsp)
call   1030 <sqrt@plt>
xorpd  %xmm1,%xmm1
movapd 0x10(%rsp),%xmm7
movsd  (%rsp),%xmm2
movsd  0x8(%rsp),%xmm5
ucomisd %xmm1,%xmm7
jae    11ba <sphere_intersect+0xaa>
subsd  %xmm7,%xmm0
movapd %xmm2,%xmm7
divsd  %xmm0,%xmm7
movsd  %xmm7,(%rbx)
mulsd  %xmm5,%xmm7
divsd  %xmm7,%xmm2
movsd  %xmm2,(%r14)
xorps  %xmm1,%xmm1
sqrtsd %xmm5,%xmm1
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm5
movapd %xmm1,%xmm0
jae    1246 <sphere_intersect+0x136>
movapd %xmm5,%xmm0
movsd  %xmm1,(%rsp)
call   1030 <sqrt@plt>
xorpd  %xmm2,%xmm2
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm5
mulsd  (%rbx),%xmm0
movsd  %xmm0,(%rbx)
ucomisd %xmm2,%xmm5
jae    1261 <sphere_intersect+0x151>
movapd %xmm5,%xmm0
call   1030 <sqrt@plt>
movapd %xmm0,%xmm1
mulsd  (%r14),%xmm1
movsd  %xmm1,(%r14)
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @sphere_intersect(double* %0, double* %1, double %2, double %3, double %4, double %5, double %6, double %7, double %8) {
%10 = alloca i32
%11 = alloca double*
%12 = alloca double*
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
store double* %0, double** %11
store double* %1, double** %12
store double %2, double* %13
store double %3, double* %14
store double %4, double* %15
store double %5, double* %16
store double %6, double* %17
store double %7, double* %18
store double %8, double* %19
%24 = load double, double* %16
%25 = load double, double* %16
%26 = load double, double* %17
%27 = load double, double* %17
%28 = fmul double %26, %27
%29 = call double @llvm.fmuladd.f64(double %24, double %25, double %28)
%30 = load double, double* %18
%31 = load double, double* %18
%32 = call double @llvm.fmuladd.f64(double %30, double %31, double %29)
store double %32, double* %23
%33 = load double, double* %13
%34 = load double, double* %16
%35 = load double, double* %14
%36 = load double, double* %17
%37 = fmul double %35, %36
%38 = call double @llvm.fmuladd.f64(double %33, double %34, double %37)
%39 = load double, double* %15
%40 = load double, double* %18
%41 = call double @llvm.fmuladd.f64(double %39, double %40, double %38)
store double %41, double* %20
%42 = load double, double* %13
%43 = load double, double* %13
%44 = load double, double* %14
%45 = load double, double* %14
%46 = fmul double %44, %45
%47 = call double @llvm.fmuladd.f64(double %42, double %43, double %46)
%48 = load double, double* %15
%49 = load double, double* %15
%50 = call double @llvm.fmuladd.f64(double %48, double %49, double %47)
%51 = load double, double* %19
%52 = load double, double* %19
%53 = fneg double %51
%54 = call double @llvm.fmuladd.f64(double %53, double %52, double %50)
store double %54, double* %21
%55 = load double, double* %20
%56 = load double, double* %20
%57 = load double, double* %23
%58 = load double, double* %21
%59 = fmul double %57, %58
%60 = fneg double %59
%61 = call double @llvm.fmuladd.f64(double %55, double %56, double %60)
store double %61, double* %22
%62 = load double, double* %22
%63 = fcmp olt double %62, 0.000000e+00
br i1 %63, label %67, label %64
64: ; preds = %9
%65 = load double, double* %23
%66 = fcmp oeq double %65, 0.000000e+00
br i1 %66, label %67, label %68
67: ; preds = %64, %9
store i32 0, i32* %10
br label %114
68: ; preds = %64
%69 = load double, double* %22
%70 = call double @sqrt(double %69)
store double %70, double* %22
%71 = load double, double* %20
%72 = fcmp oge double %71, 0.000000e+00
br i1 %72, label %73, label %88
73: ; preds = %68
%74 = load double, double* %20
%75 = fneg double %74
%76 = load double, double* %22
%77 = fsub double %75, %76
%78 = load double, double* %23
%79 = fdiv double %77, %78
%80 = load double*, double** %11
store double %79, double* %80
%81 = load double, double* %21
%82 = load double*, double** %11
%83 = load double, double* %82
%84 = load double, double* %23
%85 = fmul double %83, %84
%86 = fdiv double %81, %85
%87 = load double*, double** %12
store double %86, double* %87
br label %103
88: ; preds = %68
%89 = load double, double* %21
%90 = load double, double* %20
%91 = fneg double %90
%92 = load double, double* %22
%93 = fadd double %91, %92
%94 = fdiv double %89, %93
%95 = load double*, double** %11
store double %94, double* %95
%96 = load double, double* %21
%97 = load double*, double** %11
%98 = load double, double* %97
%99 = load double, double* %23
%100 = fmul double %98, %99
%101 = fdiv double %96, %100
%102 = load double*, double** %12
store double %101, double* %102
br label %103
103: ; preds = %88, %73
%104 = load double, double* %23
%105 = call double @sqrt(double %104)
%106 = load double*, double** %11
%107 = load double, double* %106
%108 = fmul double %107, %105
store double %108, double* %106
%109 = load double, double* %23
%110 = call double @sqrt(double %109)
%111 = load double*, double** %12
%112 = load double, double* %111
%113 = fmul double %112, %110
store double %113, double* %111
store i32 1, i32* %10
br label %114
114: ; preds = %103, %67
%115 = load i32, i32* %10
ret i32 %115
}

LLVM IR (-O2):
define i32 @sphere_intersect(double* nocapture %0, double* nocapture %1, double %2, double %3, double %4, double %5, double %6, double %7, double %8) {
%10 = fmul double %6, %6
%11 = tail call double @llvm.fmuladd.f64(double %5, double %5, double %10)
%12 = tail call double @llvm.fmuladd.f64(double %7, double %7, double %11)
%13 = fmul double %3, %6
%14 = tail call double @llvm.fmuladd.f64(double %2, double %5, double %13)
%15 = tail call double @llvm.fmuladd.f64(double %4, double %7, double %14)
%16 = fmul double %3, %3
%17 = tail call double @llvm.fmuladd.f64(double %2, double %2, double %16)
%18 = tail call double @llvm.fmuladd.f64(double %4, double %4, double %17)
%19 = fneg double %8
%20 = tail call double @llvm.fmuladd.f64(double %19, double %8, double %18)
%21 = fneg double %12
%22 = fmul double %20, %21
%23 = tail call double @llvm.fmuladd.f64(double %15, double %15, double %22)
%24 = fcmp olt double %23, 0.000000e+00
%25 = fcmp oeq double %12, 0.000000e+00
%26 = select i1 %24, i1 true, i1 %25
br i1 %26, label %47, label %27
27: ; preds = %9
%28 = tail call double @sqrt(double %23)
%29 = fcmp ult double %15, 0.000000e+00
br i1 %29, label %34, label %30
30: ; preds = %27
%31 = fneg double %15
%32 = fsub double %31, %28
%33 = fdiv double %32, %12
br label %37
34: ; preds = %27
%35 = fsub double %28, %15
%36 = fdiv double %20, %35
br label %37
37: ; preds = %34, %30
%38 = phi double [ %36, %34 ], [ %33, %30 ]
store double %38, double* %0
%39 = fmul double %12, %38
%40 = fdiv double %20, %39
store double %40, double* %1
%41 = tail call double @sqrt(double %12)
%42 = load double, double* %0
%43 = fmul double %41, %42
store double %43, double* %0
%44 = tail call double @sqrt(double %12)
%45 = load double, double* %1
%46 = fmul double %44, %45
store double %46, double* %1
br label %47
47: ; preds = %9, %37
%48 = phi i32 [ 1, %37 ], [ 0, %9 ]
ret i32 %48
}