#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 distance_sq(double *, double *);
int in_spheres_all(int n, double *probe, double probe_radius, double *spheres,
                   double *sphere_radii, int *hits) {
  int i, counter;
  double tmp;
  counter = 0;
  for (i = n - 1; i >= 0; i--) {
    tmp = (*sphere_radii + probe_radius);
    tmp = distance_sq(spheres, probe) - tmp * tmp;
    if (tmp < -1e-10) {
      counter += 1;
      *hits = n - i - 1;
      hits++;
    }
    spheres += 3;
    sphere_radii++;
  }
  return counter;
}


x86 assembly (clang, -O0):
<in_spheres_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jl     11f7 <in_spheres_all+0xe7>
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <distance_sq@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe5e(%rip),%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    11d1 <in_spheres_all+0xc1>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x4(%rbp),%ecx
sub    -0x34(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0x18,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    1140 <in_spheres_all+0x30>
mov    -0x38(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<in_spheres_all>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x8(%rsp)
movsd  %xmm0,(%rsp)
test   %edi,%edi
jle    11aa <in_spheres_all+0x9a>
mov    %r8,%r15
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %edi,%ebp
add    $0x1,%ebp
xor    %r14d,%r14d
xor    %r13d,%r13d
jmp    1160 <in_spheres_all+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x18,%rbx
add    $0xffffffff,%ebp
add    $0x1,%r14
cmp    $0x1,%ebp
jbe    11ad <in_spheres_all+0x9d>
mov    0x8(%rsp),%rax
movsd  (%rax,%r14,8),%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <distance_sq@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
movsd  0xe69(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1150 <in_spheres_all+0x40>
add    $0x1,%r13d
mov    %r14d,(%r15)
add    $0x4,%r15
jmp    1150 <in_spheres_all+0x40>
xor    %r13d,%r13d
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @in_spheres_all(i32 %0, double* %1, double %2, double* %3, double* %4, i32* %5) {
%7 = alloca i32
%8 = alloca double*
%9 = alloca double
%10 = alloca double*
%11 = alloca double*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
store i32 %0, i32* %7
store double* %1, double** %8
store double %2, double* %9
store double* %3, double** %10
store double* %4, double** %11
store i32* %5, i32** %12
store i32 0, i32* %14
%16 = load i32, i32* %7
%17 = sub nsw i32 %16, 1
store i32 %17, i32* %13
br label %18
18: ; preds = %50, %6
%19 = load i32, i32* %13
%20 = icmp sge i32 %19, 0
br i1 %20, label %21, label %53
21: ; preds = %18
%22 = load double*, double** %11
%23 = load double, double* %22
%24 = load double, double* %9
%25 = fadd double %23, %24
store double %25, double* %15
%26 = load double*, double** %10
%27 = load double*, double** %8
%28 = call double @distance_sq(double* %26, double* %27)
%29 = load double, double* %15
%30 = load double, double* %15
%31 = fneg double %29
%32 = call double @llvm.fmuladd.f64(double %31, double %30, double %28)
store double %32, double* %15
%33 = load double, double* %15
%34 = fcmp olt double %33, -1.000000e-10
br i1 %34, label %35, label %45
35: ; preds = %21
%36 = load i32, i32* %14
%37 = add nsw i32 %36, 1
store i32 %37, i32* %14
%38 = load i32, i32* %7
%39 = load i32, i32* %13
%40 = sub nsw i32 %38, %39
%41 = sub nsw i32 %40, 1
%42 = load i32*, i32** %12
store i32 %41, i32* %42
%43 = load i32*, i32** %12
%44 = getelementptr inbounds i32, i32* %43, i32 1
store i32* %44, i32** %12
br label %45
45: ; preds = %35, %21
%46 = load double*, double** %10
%47 = getelementptr inbounds double, double* %46, i64 3
store double* %47, double** %10
%48 = load double*, double** %11
%49 = getelementptr inbounds double, double* %48, i32 1
store double* %49, double** %11
br label %50
50: ; preds = %45
%51 = load i32, i32* %13
%52 = add nsw i32 %51, -1
store i32 %52, i32* %13
br label %18
53: ; preds = %18
%54 = load i32, i32* %14
ret i32 %54
}

LLVM IR (-O2):
define i32 @in_spheres_all(i32 %0, double* %1, double %2, double* %3, double* nocapture %4, i32* nocapture writeonly %5) {
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %31
8: ; preds = %6, %25
%9 = phi double* [ %28, %25 ], [ %3, %6 ]
%10 = phi i32 [ %27, %25 ], [ 0, %6 ]
%11 = phi i32 [ %14, %25 ], [ %0, %6 ]
%12 = phi i32* [ %26, %25 ], [ %5, %6 ]
%13 = phi double* [ %29, %25 ], [ %4, %6 ]
%14 = add nsw i32 %11, -1
%15 = load double, double* %13
%16 = fadd double %15, %2
%17 = tail call double @distance_sq(double* %9, double* %1)
%18 = fneg double %16
%19 = tail call double @llvm.fmuladd.f64(double %18, double %16, double %17)
%20 = fcmp olt double %19, -1.000000e-10
br i1 %20, label %21, label %25
21: ; preds = %8
%22 = add nsw i32 %10, 1
%23 = sub nuw nsw i32 %0, %11
store i32 %23, i32* %12
%24 = getelementptr inbounds i32, i32* %12, i64 1
br label %25
25: ; preds = %21, %8
%26 = phi i32* [ %24, %21 ], [ %12, %8 ]
%27 = phi i32 [ %22, %21 ], [ %10, %8 ]
%28 = getelementptr inbounds double, double* %9, i64 3
%29 = getelementptr inbounds double, double* %13, i64 1
%30 = icmp ugt i32 %11, 1
br i1 %30, label %8, label %31
31: ; preds = %25, %6
%32 = phi i32 [ 0, %6 ], [ %27, %25 ]
ret i32 %32
}