#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(double *, double *);
double sqrt(double);
int cube_in_sphere(double ccenter[3], double cwidth, double scenter[3],
                   double sradius) {
  double cradius, d;
  int k;
  cradius = sqrt(3.0) * cwidth;
  d = distance(ccenter, scenter);
  if (d + cradius < sradius)
    return (2);
  else if (sradius < d - cradius)
    return (0);
  for (k = 0; k < 3; k++) {
    if (ccenter[k] + cwidth < scenter[k] - sradius)
      return (0);
    if (ccenter[k] - cwidth > scenter[k] + sradius)
      return (0);
  }
  return (1);
}


x86 assembly (clang, -O0):
<cube_in_sphere>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
movsd  0xebe(%rip),%xmm0
call   1030 <sqrt@plt>
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <distance@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
addsd  -0x30(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1188 <cube_in_sphere+0x68>
movl   $0x2,-0x4(%rbp)
jmp    1251 <cube_in_sphere+0x131>
movsd  -0x28(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ad <cube_in_sphere+0x8d>
movl   $0x0,-0x4(%rbp)
jmp    1251 <cube_in_sphere+0x131>
jmp    11b2 <cube_in_sphere+0x92>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x3,-0x3c(%rbp)
jge    124a <cube_in_sphere+0x12a>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
addsd  -0x18(%rbp),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11fd <cube_in_sphere+0xdd>
movl   $0x0,-0x4(%rbp)
jmp    1251 <cube_in_sphere+0x131>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x18(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
addsd  -0x28(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    1237 <cube_in_sphere+0x117>
movl   $0x0,-0x4(%rbp)
jmp    1251 <cube_in_sphere+0x131>
jmp    123c <cube_in_sphere+0x11c>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11b9 <cube_in_sphere+0x99>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cube_in_sphere>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movsd  %xmm1,0x10(%rsp)
mov    %rsi,%r14
mov    %rdi,%rbx
movsd  0xed5(%rip),%xmm1
movsd  %xmm0,(%rsp)
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1030 <distance@plt>
movsd  0x8(%rsp),%xmm2
movsd  0x10(%rsp),%xmm4
movapd %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    $0x2,%eax
ucomisd %xmm1,%xmm4
ja     1207 <cube_in_sphere+0xf7>
subsd  %xmm2,%xmm0
xor    %eax,%eax
ucomisd %xmm4,%xmm0
ja     1207 <cube_in_sphere+0xf7>
movsd  (%rbx),%xmm0
movapd %xmm0,%xmm2
movsd  (%rsp),%xmm5
addsd  %xmm5,%xmm2
movsd  (%r14),%xmm1
movapd %xmm1,%xmm3
subsd  %xmm4,%xmm3
ucomisd %xmm2,%xmm3
ja     1207 <cube_in_sphere+0xf7>
subsd  %xmm5,%xmm0
addsd  %xmm4,%xmm1
ucomisd %xmm1,%xmm0
ja     1207 <cube_in_sphere+0xf7>
movsd  0x8(%rbx),%xmm0
movapd %xmm0,%xmm2
addsd  %xmm5,%xmm2
movsd  0x8(%r14),%xmm1
movapd %xmm1,%xmm3
subsd  %xmm4,%xmm3
ucomisd %xmm2,%xmm3
ja     1207 <cube_in_sphere+0xf7>
subsd  %xmm5,%xmm0
addsd  %xmm4,%xmm1
ucomisd %xmm1,%xmm0
ja     1207 <cube_in_sphere+0xf7>
movsd  0x10(%rbx),%xmm0
movapd %xmm0,%xmm2
addsd  %xmm5,%xmm2
movsd  0x10(%r14),%xmm1
movapd %xmm1,%xmm3
subsd  %xmm4,%xmm3
ucomisd %xmm2,%xmm3
ja     1207 <cube_in_sphere+0xf7>
subsd  %xmm5,%xmm0
addsd  %xmm4,%xmm1
ucomisd %xmm1,%xmm0
ja     1207 <cube_in_sphere+0xf7>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @cube_in_sphere(double* %0, double %1, double* %2, double %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca double
%8 = alloca double*
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
store double* %0, double** %6
store double %1, double* %7
store double* %2, double** %8
store double %3, double* %9
%13 = call double @sqrt(double 3.000000e+00)
%14 = load double, double* %7
%15 = fmul double %13, %14
store double %15, double* %10
%16 = load double*, double** %6
%17 = load double*, double** %8
%18 = call double @distance(double* %16, double* %17)
store double %18, double* %11
%19 = load double, double* %11
%20 = load double, double* %10
%21 = fadd double %19, %20
%22 = load double, double* %9
%23 = fcmp olt double %21, %22
br i1 %23, label %24, label %25
24: ; preds = %4
store i32 2, i32* %5
br label %76
25: ; preds = %4
%26 = load double, double* %9
%27 = load double, double* %11
%28 = load double, double* %10
%29 = fsub double %27, %28
%30 = fcmp olt double %26, %29
br i1 %30, label %31, label %32
31: ; preds = %25
store i32 0, i32* %5
br label %76
32: ; preds = %25
br label %33
33: ; preds = %32
store i32 0, i32* %12
br label %34
34: ; preds = %72, %33
%35 = load i32, i32* %12
%36 = icmp slt i32 %35, 3
br i1 %36, label %37, label %75
37: ; preds = %34
%38 = load double*, double** %6
%39 = load i32, i32* %12
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = load double, double* %41
%43 = load double, double* %7
%44 = fadd double %42, %43
%45 = load double*, double** %8
%46 = load i32, i32* %12
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %45, i64 %47
%49 = load double, double* %48
%50 = load double, double* %9
%51 = fsub double %49, %50
%52 = fcmp olt double %44, %51
br i1 %52, label %53, label %54
53: ; preds = %37
store i32 0, i32* %5
br label %76
54: ; preds = %37
%55 = load double*, double** %6
%56 = load i32, i32* %12
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %55, i64 %57
%59 = load double, double* %58
%60 = load double, double* %7
%61 = fsub double %59, %60
%62 = load double*, double** %8
%63 = load i32, i32* %12
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds double, double* %62, i64 %64
%66 = load double, double* %65
%67 = load double, double* %9
%68 = fadd double %66, %67
%69 = fcmp ogt double %61, %68
br i1 %69, label %70, label %71
70: ; preds = %54
store i32 0, i32* %5
br label %76
71: ; preds = %54
br label %72
72: ; preds = %71
%73 = load i32, i32* %12
%74 = add nsw i32 %73, 1
store i32 %74, i32* %12
br label %34
75: ; preds = %34
store i32 1, i32* %5
br label %76
76: ; preds = %75, %70, %53, %31, %24
%77 = load i32, i32* %5
ret i32 %77
}

LLVM IR (-O2):
define i32 @cube_in_sphere(double* %0, double %1, double* %2, double %3) {
%5 = fmul double %1, 0x3FFBB67AE8584CAA
%6 = tail call double @distance(double* %0, double* %2)
%7 = fadd double %5, %6
%8 = fcmp olt double %7, %3
br i1 %8, label %47, label %9
9: ; preds = %4
%10 = fsub double %6, %5
%11 = fcmp ogt double %10, %3
br i1 %11, label %47, label %12
12: ; preds = %9
%13 = load double, double* %0
%14 = fadd double %13, %1
%15 = load double, double* %2
%16 = fsub double %15, %3
%17 = fcmp olt double %14, %16
br i1 %17, label %47, label %43
18: ; preds = %43
%19 = getelementptr inbounds double, double* %0, i64 1
%20 = load double, double* %19
%21 = fadd double %20, %1
%22 = getelementptr inbounds double, double* %2, i64 1
%23 = load double, double* %22
%24 = fsub double %23, %3
%25 = fcmp olt double %21, %24
br i1 %25, label %47, label %26
26: ; preds = %18
%27 = fsub double %20, %1
%28 = fadd double %23, %3
%29 = fcmp ogt double %27, %28
br i1 %29, label %47, label %30
30: ; preds = %26
%31 = getelementptr inbounds double, double* %0, i64 2
%32 = load double, double* %31
%33 = fadd double %32, %1
%34 = getelementptr inbounds double, double* %2, i64 2
%35 = load double, double* %34
%36 = fsub double %35, %3
%37 = fcmp olt double %33, %36
br i1 %37, label %47, label %38
38: ; preds = %30
%39 = fsub double %32, %1
%40 = fadd double %35, %3
%41 = fcmp ogt double %39, %40
br i1 %41, label %47, label %42
42: ; preds = %38
br label %47
43: ; preds = %12
%44 = fsub double %13, %1
%45 = fadd double %15, %3
%46 = fcmp ogt double %44, %45
br i1 %46, label %47, label %18
47: ; preds = %43, %12, %18, %26, %30, %38, %42, %9, %4
%48 = phi i32 [ 2, %4 ], [ 0, %9 ], [ 0, %12 ], [ 0, %43 ], [ 0, %18 ], [ 0, %26 ], [ 0, %30 ], [ 0, %38 ], [ 1, %42 ]
ret i32 %48
}