#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ LED(int, int, int, int /*<<< orphan*/, int /*<<< orphan*/,
                       int /*<<< orphan*/);
int /*<<< orphan*/ buffer_LED(int, int, int, int /*<<< orphan*/,
                              int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ pow(int, int);
double sqrt(scalar_t__);
void cube_sphere(int x, int y, int z, uint8_t r, uint8_t g, uint8_t b, int d,
                 int buffer) {
  int xx, yy, zz;
  double radius = (double)d / 2;
  for (xx = 0; xx < 8; xx++)
    for (yy = 0; yy < 8; yy++)
      for (zz = 0; zz < 8; zz++) {
        double polar = sqrt(pow(xx - x, 2) + pow(yy - y, 2) + pow(zz - z, 2));
        if (polar < radius)
          if (buffer)
            buffer_LED(xx, yy, zz, r, g, b);
          else
            LED(xx, yy, zz, r, g, b);
      }
}


x86 assembly (clang, -O0):
<cube_sphere>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    %r9d,-0x18(%rbp)
cvtsi2sdl 0x10(%rbp),%xmm0
movsd  0xe91(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    1291 <cube_sphere+0x151>
movl   $0x0,-0x20(%rbp)
cmpl   $0x8,-0x20(%rbp)
jge    127e <cube_sphere+0x13e>
movl   $0x0,-0x24(%rbp)
cmpl   $0x8,-0x24(%rbp)
jge    126b <cube_sphere+0x12b>
mov    -0x1c(%rbp),%edi
sub    -0x4(%rbp),%edi
mov    $0x2,%esi
call   1040 <pow@plt>
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%edi
sub    -0x8(%rbp),%edi
mov    $0x2,%esi
call   1040 <pow@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x24(%rbp),%edi
sub    -0xc(%rbp),%edi
mov    $0x2,%esi
call   1040 <pow@plt>
mov    -0x40(%rbp),%rdi
add    %rax,%rdi
call   1060 <sqrt@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1258 <cube_sphere+0x118>
cmpl   $0x0,0x18(%rbp)
je     123a <cube_sphere+0xfa>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x18(%rbp),%r9d
call   1030 <buffer_LED@plt>
jmp    1253 <cube_sphere+0x113>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x18(%rbp),%r9d
call   1050 <LED@plt>
jmp    1258 <cube_sphere+0x118>
jmp    125d <cube_sphere+0x11d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a1 <cube_sphere+0x61>
jmp    1270 <cube_sphere+0x130>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1190 <cube_sphere+0x50>
jmp    1283 <cube_sphere+0x143>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117f <cube_sphere+0x3f>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cube_sphere>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,0x14(%rsp)
mov    %r8d,0x10(%rsp)
mov    %ecx,0xc(%rsp)
mov    %edx,%ebp
mov    %esi,0x1c(%rsp)
mov    %edi,0x18(%rsp)
cvtsi2sdl 0x60(%rsp),%xmm0
mulsd  0xe8c(%rip),%xmm0
movsd  %xmm0,0x20(%rsp)
neg    %ebp
xor    %r13d,%r13d
jmp    11a3 <cube_sphere+0x63>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%r13d
add    $0x1,%r13d
cmp    $0x8,%r13d
je     1271 <cube_sphere+0x131>
mov    %r13d,0x8(%rsp)
sub    0x18(%rsp),%r13d
xor    %r15d,%r15d
jmp    11ca <cube_sphere+0x8a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r15d
cmp    $0x8,%r15d
je     1190 <cube_sphere+0x50>
mov    %r15d,%r14d
sub    0x1c(%rsp),%r14d
xor    %ebx,%ebx
jmp    1208 <cube_sphere+0xc8>
mov    0x8(%rsp),%edi
mov    %r15d,%esi
mov    %ebx,%edx
mov    0xc(%rsp),%ecx
mov    0x10(%rsp),%r8d
mov    0x14(%rsp),%r9d
call   1050 <LED@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebx
cmp    $0x8,%ebx
je     11c0 <cube_sphere+0x80>
mov    %r13d,%edi
mov    $0x2,%esi
call   1040 <pow@plt>
mov    %rax,%r12
mov    %r14d,%edi
mov    $0x2,%esi
call   1040 <pow@plt>
add    %rax,%r12
lea    (%rbx,%rbp,1),%edi
mov    $0x2,%esi
call   1040 <pow@plt>
add    %rax,%r12
mov    %r12,%rdi
call   1060 <sqrt@plt>
movsd  0x20(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    1200 <cube_sphere+0xc0>
cmpl   $0x0,0x68(%rsp)
je     11d6 <cube_sphere+0x96>
mov    0x8(%rsp),%edi
mov    %r15d,%esi
mov    %ebx,%edx
mov    0xc(%rsp),%ecx
mov    0x10(%rsp),%r8d
mov    0x14(%rsp),%r9d
call   1030 <buffer_LED@plt>
jmp    1200 <cube_sphere+0xc0>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @cube_sphere(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca double
%21 = alloca double
store i32 %0, i32* %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i32 %6, i32* %15
store i32 %7, i32* %16
%22 = load i32, i32* %15
%23 = sitofp i32 %22 to double
%24 = fdiv double %23, 2.000000e+00
store double %24, double* %20
store i32 0, i32* %17
br label %25
25: ; preds = %84, %8
%26 = load i32, i32* %17
%27 = icmp slt i32 %26, 8
br i1 %27, label %28, label %87
28: ; preds = %25
store i32 0, i32* %18
br label %29
29: ; preds = %80, %28
%30 = load i32, i32* %18
%31 = icmp slt i32 %30, 8
br i1 %31, label %32, label %83
32: ; preds = %29
store i32 0, i32* %19
br label %33
33: ; preds = %76, %32
%34 = load i32, i32* %19
%35 = icmp slt i32 %34, 8
br i1 %35, label %36, label %79
36: ; preds = %33
%37 = load i32, i32* %17
%38 = load i32, i32* %9
%39 = sub nsw i32 %37, %38
%40 = call i64 @pow(i32 %39, i32 2)
%41 = load i32, i32* %18
%42 = load i32, i32* %10
%43 = sub nsw i32 %41, %42
%44 = call i64 @pow(i32 %43, i32 2)
%45 = add nsw i64 %40, %44
%46 = load i32, i32* %19
%47 = load i32, i32* %11
%48 = sub nsw i32 %46, %47
%49 = call i64 @pow(i32 %48, i32 2)
%50 = add nsw i64 %45, %49
%51 = call double @sqrt(i64 %50)
store double %51, double* %21
%52 = load double, double* %21
%53 = load double, double* %20
%54 = fcmp olt double %52, %53
br i1 %54, label %55, label %75
55: ; preds = %36
%56 = load i32, i32* %16
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %66
58: ; preds = %55
%59 = load i32, i32* %17
%60 = load i32, i32* %18
%61 = load i32, i32* %19
%62 = load i32, i32* %12
%63 = load i32, i32* %13
%64 = load i32, i32* %14
%65 = call i32 @buffer_LED(i32 %59, i32 %60, i32 %61, i32 %62, i32 %63, i32 %64)
br label %74
66: ; preds = %55
%67 = load i32, i32* %17
%68 = load i32, i32* %18
%69 = load i32, i32* %19
%70 = load i32, i32* %12
%71 = load i32, i32* %13
%72 = load i32, i32* %14
%73 = call i32 @LED(i32 %67, i32 %68, i32 %69, i32 %70, i32 %71, i32 %72)
br label %74
74: ; preds = %66, %58
br label %75
75: ; preds = %74, %36
br label %76
76: ; preds = %75
%77 = load i32, i32* %19
%78 = add nsw i32 %77, 1
store i32 %78, i32* %19
br label %33
79: ; preds = %33
br label %80
80: ; preds = %79
%81 = load i32, i32* %18
%82 = add nsw i32 %81, 1
store i32 %82, i32* %18
br label %29
83: ; preds = %29
br label %84
84: ; preds = %83
%85 = load i32, i32* %17
%86 = add nsw i32 %85, 1
store i32 %86, i32* %17
br label %25
87: ; preds = %25
ret void
}

LLVM IR (-O2):
define void @cube_sphere(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = sitofp i32 %6 to double
%10 = fmul double %9, 5.000000e-01
%11 = icmp eq i32 %7, 0
br label %12
12: ; preds = %8, %39
%13 = phi i32 [ 0, %8 ], [ %40, %39 ]
%14 = sub nsw i32 %13, %0
br label %15
15: ; preds = %12, %36
%16 = phi i32 [ 0, %12 ], [ %37, %36 ]
%17 = sub nsw i32 %16, %1
br label %18
18: ; preds = %15, %33
%19 = phi i32 [ 0, %15 ], [ %34, %33 ]
%20 = tail call i64 @pow(i32 %14, i32 2)
%21 = tail call i64 @pow(i32 %17, i32 2)
%22 = add nsw i64 %21, %20
%23 = sub nsw i32 %19, %2
%24 = tail call i64 @pow(i32 %23, i32 2)
%25 = add nsw i64 %22, %24
%26 = tail call double @sqrt(i64 %25)
%27 = fcmp olt double %26, %10
br i1 %27, label %28, label %33
28: ; preds = %18
br i1 %11, label %31, label %29
29: ; preds = %28
%30 = tail call i32 @buffer_LED(i32 %13, i32 %16, i32 %19, i32 %3, i32 %4, i32 %5)
br label %33
31: ; preds = %28
%32 = tail call i32 @LED(i32 %13, i32 %16, i32 %19, i32 %3, i32 %4, i32 %5)
br label %33
33: ; preds = %29, %31, %18
%34 = add nuw nsw i32 %19, 1
%35 = icmp eq i32 %34, 8
br i1 %35, label %36, label %18
36: ; preds = %33
%37 = add nuw nsw i32 %16, 1
%38 = icmp eq i32 %37, 8
br i1 %38, label %39, label %15
39: ; preds = %36
%40 = add nuw nsw i32 %13, 1
%41 = icmp eq i32 %40, 8
br i1 %41, label %42, label %12
42: ; preds = %39
ret void
}