#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 cos(float);
int /*<<< orphan*/ quad(float, float, float, float, float, float, float, float,
                        float, float, float, float);
float sin(float);
float sqrt(float);
void sphere(float r, int detail) {
  for (int i = 0; i < detail; ++i) {
    float a =
        r * sin(3.14159265358979323846 * ((float)i / (float)detail - 0.5));
    float b = r * sin(3.14159265358979323846 *
                      ((float)(i + 1) / (float)detail - 0.5));
    float ra = sqrt(r * r - a * a);
    float rb = sqrt(r * r - b * b);
    for (int j = 0; j < detail; ++j) {
      float p = 2.0 * 3.14159265358979323846 * (float)j / (float)detail;
      float q = 2.0 * 3.14159265358979323846 * (float)(j + 1) / (float)detail;
      quad(ra * cos(p), a, ra * sin(p), ra * cos(q), a, ra * sin(q),
           rb * cos(q), b, rb * sin(q), rb * cos(p), b, rb * sin(p));
    }
  }
}


x86 assembly (clang, -O0):
<sphere>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    14a4 <sphere+0x364>
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
cvtsi2ssl -0xc(%rbp),%xmm0
cvtsi2ssl -0x8(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe7e(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xe6a(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movss  -0x30(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2ss %eax,%xmm0
cvtsi2ssl -0x8(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe2b(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xe17(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movss  -0x2c(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x4(%rbp),%xmm0
movss  -0x4(%rbp),%xmm2
movss  -0x10(%rbp),%xmm1
mulss  -0x10(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1060 <sqrt@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x4(%rbp),%xmm0
movss  -0x4(%rbp),%xmm2
movss  -0x14(%rbp),%xmm1
mulss  -0x14(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1060 <sqrt@plt>
movss  %xmm0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1491 <sphere+0x351>
cvtsi2ssl -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd7f(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2ssl -0x8(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
cvtsi2ss %eax,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd4f(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2ssl -0x8(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x7c(%rbp)
movss  -0x24(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movss  -0x7c(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x5c(%rbp)
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x78(%rbp)
movss  -0x24(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movss  -0x78(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x58(%rbp)
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x74(%rbp)
movss  -0x28(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movss  -0x74(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x54(%rbp)
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x50(%rbp)
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x70(%rbp)
movss  -0x28(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movss  -0x70(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x4c(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x6c(%rbp)
movss  -0x28(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movss  -0x6c(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x48(%rbp)
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x68(%rbp)
movss  -0x28(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movss  -0x68(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x40(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x64(%rbp)
movss  -0x24(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movss  -0x64(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x60(%rbp)
movss  -0x24(%rbp),%xmm0
call   1040 <sin@plt>
movss  -0x60(%rbp),%xmm8
movss  -0x5c(%rbp),%xmm1
movss  -0x58(%rbp),%xmm2
movss  -0x54(%rbp),%xmm3
movss  -0x50(%rbp),%xmm4
movss  -0x4c(%rbp),%xmm5
movss  -0x48(%rbp),%xmm6
movss  -0x44(%rbp),%xmm7
movss  -0x40(%rbp),%xmm11
movss  -0x3c(%rbp),%xmm10
movss  -0x38(%rbp),%xmm9
movaps %xmm0,%xmm12
movss  -0x34(%rbp),%xmm0
mulss  %xmm12,%xmm8
movss  %xmm11,(%rsp)
movss  %xmm10,0x8(%rsp)
movss  %xmm9,0x10(%rsp)
movss  %xmm8,0x18(%rsp)
call   1030 <quad@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1274 <sphere+0x134>
jmp    1496 <sphere+0x356>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115a <sphere+0x1a>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sphere>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
movss  %xmm0,0x38(%rsp)
test   %edi,%edi
jle    1400 <sphere+0x2c0>
mov    %edi,%ebx
xorps  %xmm0,%xmm0
cvtsi2ss %edi,%xmm0
movss  %xmm0,0x48(%rsp)
cvtss2sd %xmm0,%xmm1
xor    %r14d,%r14d
movss  0x38(%rsp),%xmm0
mulss  %xmm0,%xmm0
movss  %xmm0,0x44(%rsp)
movsd  %xmm1,0x50(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2ss %r14d,%xmm0
divss  0x48(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe56(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xe52(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1040 <sin@plt>
add    $0x1,%r14d
xorps  %xmm1,%xmm1
cvtsi2ss %r14d,%xmm1
mulss  0x38(%rsp),%xmm0
movss  %xmm0,0x4c(%rsp)
divss  0x48(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
addsd  0xe10(%rip),%xmm0
mulsd  0xe10(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
call   1040 <sin@plt>
movss  0x4c(%rsp),%xmm1
movaps %xmm0,%xmm3
mulss  %xmm1,%xmm1
movss  0x44(%rsp),%xmm0
subss  %xmm1,%xmm0
ucomiss 0xdf9(%rip),%xmm0
jb     1230 <sphere+0xf0>
xorps  %xmm2,%xmm2
sqrtss %xmm0,%xmm2
jmp    1244 <sphere+0x104>
nopw   0x0(%rax,%rax,1)
movss  %xmm3,0x3c(%rsp)
call   1060 <sqrt@plt>
movss  0x3c(%rsp),%xmm3
movaps %xmm0,%xmm2
mulss  0x38(%rsp),%xmm3
movaps %xmm3,%xmm1
mulss  %xmm3,%xmm1
movss  0x44(%rsp),%xmm0
subss  %xmm1,%xmm0
ucomiss 0xdb6(%rip),%xmm0
movss  %xmm3,0x3c(%rsp)
movss  %xmm2,0x34(%rsp)
jb     1280 <sphere+0x140>
sqrtss %xmm0,%xmm0
jmp    1285 <sphere+0x145>
cs nopw 0x0(%rax,%rax,1)
call   1060 <sqrt@plt>
movsd  0x50(%rsp),%xmm1
movsd  0xd7d(%rip),%xmm2
movss  %xmm0,0x30(%rsp)
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  %xmm2,%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x40(%rsp)
add    $0x1,%ebp
xorps  %xmm3,%xmm3
cvtsi2ss %ebp,%xmm3
cvtss2sd %xmm3,%xmm3
mulsd  %xmm2,%xmm3
divsd  %xmm1,%xmm3
xorps  %xmm1,%xmm1
cvtsd2ss %xmm3,%xmm1
movss  %xmm1,0x2c(%rsp)
call   1050 <cos@plt>
mulss  0x34(%rsp),%xmm0
movss  %xmm0,0x6c(%rsp)
movss  0x40(%rsp),%xmm0
call   1040 <sin@plt>
mulss  0x34(%rsp),%xmm0
movss  %xmm0,0x68(%rsp)
movss  0x2c(%rsp),%xmm0
call   1050 <cos@plt>
mulss  0x34(%rsp),%xmm0
movss  %xmm0,0x64(%rsp)
movss  0x2c(%rsp),%xmm0
call   1040 <sin@plt>
mulss  0x34(%rsp),%xmm0
movss  %xmm0,0x60(%rsp)
movss  0x2c(%rsp),%xmm0
call   1050 <cos@plt>
mulss  0x30(%rsp),%xmm0
movss  %xmm0,0x5c(%rsp)
movss  0x2c(%rsp),%xmm0
call   1040 <sin@plt>
mulss  0x30(%rsp),%xmm0
movss  %xmm0,0x2c(%rsp)
movss  0x40(%rsp),%xmm0
call   1050 <cos@plt>
mulss  0x30(%rsp),%xmm0
movss  %xmm0,0x58(%rsp)
movss  0x40(%rsp),%xmm0
call   1040 <sin@plt>
mulss  0x30(%rsp),%xmm0
movss  %xmm0,0x18(%rsp)
movss  0x3c(%rsp),%xmm7
movss  %xmm7,0x10(%rsp)
movss  0x58(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
movss  0x2c(%rsp),%xmm0
movss  %xmm0,(%rsp)
movss  0x6c(%rsp),%xmm0
movss  0x4c(%rsp),%xmm1
movss  0x68(%rsp),%xmm2
movss  0x64(%rsp),%xmm3
movaps %xmm1,%xmm4
movss  0x60(%rsp),%xmm5
movss  0x5c(%rsp),%xmm6
call   1030 <quad@plt>
movsd  0xc27(%rip),%xmm2
movsd  0x50(%rsp),%xmm1
cmp    %ebp,%ebx
jne    12a0 <sphere+0x160>
cmp    %ebx,%r14d
jne    1190 <sphere+0x50>
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @sphere(float %0, i32 %1) {
%3 = alloca float
%4 = alloca i32
%5 = alloca i32
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca i32
%11 = alloca float
%12 = alloca float
store float %0, float* %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %13
13: ; preds = %124, %2
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %127
17: ; preds = %13
%18 = load float, float* %3
%19 = load i32, i32* %5
%20 = sitofp i32 %19 to float
%21 = load i32, i32* %4
%22 = sitofp i32 %21 to float
%23 = fdiv float %20, %22
%24 = fpext float %23 to double
%25 = fsub double %24, 5.000000e-01
%26 = fmul double 0x400921FB54442D18, %25
%27 = fptrunc double %26 to float
%28 = call float @sin(float %27)
%29 = fmul float %18, %28
store float %29, float* %6
%30 = load float, float* %3
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
%33 = sitofp i32 %32 to float
%34 = load i32, i32* %4
%35 = sitofp i32 %34 to float
%36 = fdiv float %33, %35
%37 = fpext float %36 to double
%38 = fsub double %37, 5.000000e-01
%39 = fmul double 0x400921FB54442D18, %38
%40 = fptrunc double %39 to float
%41 = call float @sin(float %40)
%42 = fmul float %30, %41
store float %42, float* %7
%43 = load float, float* %3
%44 = load float, float* %3
%45 = load float, float* %6
%46 = load float, float* %6
%47 = fmul float %45, %46
%48 = fneg float %47
%49 = call float @llvm.fmuladd.f32(float %43, float %44, float %48)
%50 = call float @sqrt(float %49)
store float %50, float* %8
%51 = load float, float* %3
%52 = load float, float* %3
%53 = load float, float* %7
%54 = load float, float* %7
%55 = fmul float %53, %54
%56 = fneg float %55
%57 = call float @llvm.fmuladd.f32(float %51, float %52, float %56)
%58 = call float @sqrt(float %57)
store float %58, float* %9
store i32 0, i32* %10
br label %59
59: ; preds = %120, %17
%60 = load i32, i32* %10
%61 = load i32, i32* %4
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %123
63: ; preds = %59
%64 = load i32, i32* %10
%65 = sitofp i32 %64 to float
%66 = fpext float %65 to double
%67 = fmul double 0x401921FB54442D18, %66
%68 = load i32, i32* %4
%69 = sitofp i32 %68 to float
%70 = fpext float %69 to double
%71 = fdiv double %67, %70
%72 = fptrunc double %71 to float
store float %72, float* %11
%73 = load i32, i32* %10
%74 = add nsw i32 %73, 1
%75 = sitofp i32 %74 to float
%76 = fpext float %75 to double
%77 = fmul double 0x401921FB54442D18, %76
%78 = load i32, i32* %4
%79 = sitofp i32 %78 to float
%80 = fpext float %79 to double
%81 = fdiv double %77, %80
%82 = fptrunc double %81 to float
store float %82, float* %12
%83 = load float, float* %8
%84 = load float, float* %11
%85 = call float @cos(float %84)
%86 = fmul float %83, %85
%87 = load float, float* %6
%88 = load float, float* %8
%89 = load float, float* %11
%90 = call float @sin(float %89)
%91 = fmul float %88, %90
%92 = load float, float* %8
%93 = load float, float* %12
%94 = call float @cos(float %93)
%95 = fmul float %92, %94
%96 = load float, float* %6
%97 = load float, float* %8
%98 = load float, float* %12
%99 = call float @sin(float %98)
%100 = fmul float %97, %99
%101 = load float, float* %9
%102 = load float, float* %12
%103 = call float @cos(float %102)
%104 = fmul float %101, %103
%105 = load float, float* %7
%106 = load float, float* %9
%107 = load float, float* %12
%108 = call float @sin(float %107)
%109 = fmul float %106, %108
%110 = load float, float* %9
%111 = load float, float* %11
%112 = call float @cos(float %111)
%113 = fmul float %110, %112
%114 = load float, float* %7
%115 = load float, float* %9
%116 = load float, float* %11
%117 = call float @sin(float %116)
%118 = fmul float %115, %117
%119 = call i32 @quad(float %86, float %87, float %91, float %95, float %96, float %100, float %104, float %105, float %109, float %113, float %114, float %118)
br label %120
120: ; preds = %63
%121 = load i32, i32* %10
%122 = add nsw i32 %121, 1
store i32 %122, i32* %10
br label %59
123: ; preds = %59
br label %124
124: ; preds = %123
%125 = load i32, i32* %5
%126 = add nsw i32 %125, 1
store i32 %126, i32* %5
br label %13
127: ; preds = %13
ret void
}

LLVM IR (-O2):
define void @sphere(float %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = sitofp i32 %1 to float
%6 = fpext float %5 to double
br label %10
7: ; preds = %37
%8 = icmp eq i32 %20, %1
br i1 %8, label %9, label %10
9: ; preds = %7, %2
ret void
10: ; preds = %7, %4
%11 = phi i32 [ 0, %4 ], [ %20, %7 ]
%12 = sitofp i32 %11 to float
%13 = fdiv float %12, %5
%14 = fpext float %13 to double
%15 = fadd double %14, -5.000000e-01
%16 = fmul double %15, 0x400921FB54442D18
%17 = fptrunc double %16 to float
%18 = tail call float @sin(float %17)
%19 = fmul float %18, %0
%20 = add nuw nsw i32 %11, 1
%21 = sitofp i32 %20 to float
%22 = fdiv float %21, %5
%23 = fpext float %22 to double
%24 = fadd double %23, -5.000000e-01
%25 = fmul double %24, 0x400921FB54442D18
%26 = fptrunc double %25 to float
%27 = tail call float @sin(float %26)
%28 = fmul float %27, %0
%29 = fneg float %19
%30 = fmul float %19, %29
%31 = tail call float @llvm.fmuladd.f32(float %0, float %0, float %30)
%32 = tail call float @sqrt(float %31)
%33 = fneg float %28
%34 = fmul float %28, %33
%35 = tail call float @llvm.fmuladd.f32(float %0, float %0, float %34)
%36 = tail call float @sqrt(float %35)
br label %37
37: ; preds = %10, %37
%38 = phi i32 [ %44, %37 ], [ 0, %10 ]
%39 = sitofp i32 %38 to float
%40 = fpext float %39 to double
%41 = fmul double %40, 0x401921FB54442D18
%42 = fdiv double %41, %6
%43 = fptrunc double %42 to float
%44 = add nuw nsw i32 %38, 1
%45 = sitofp i32 %44 to float
%46 = fpext float %45 to double
%47 = fmul double %46, 0x401921FB54442D18
%48 = fdiv double %47, %6
%49 = fptrunc double %48 to float
%50 = tail call float @cos(float %43)
%51 = fmul float %32, %50
%52 = tail call float @sin(float %43)
%53 = fmul float %32, %52
%54 = tail call float @cos(float %49)
%55 = fmul float %32, %54
%56 = tail call float @sin(float %49)
%57 = fmul float %32, %56
%58 = tail call float @cos(float %49)
%59 = fmul float %36, %58
%60 = tail call float @sin(float %49)
%61 = fmul float %36, %60
%62 = tail call float @cos(float %43)
%63 = fmul float %36, %62
%64 = tail call float @sin(float %43)
%65 = fmul float %36, %64
%66 = tail call i32 @quad(float %51, float %19, float %53, float %55, float %19, float %57, float %59, float %28, float %61, float %63, float %28, float %65)
%67 = icmp eq i32 %44, %1
br i1 %67, label %7, label %37
}