#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 halfsphere(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 = 0.5 * 3.14159265358979323846 +
                3.14159265358979323846 * (float)j / (float)detail;
      float q = 0.5 * 3.14159265358979323846 +
                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):
<halfsphere>:
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    14bc <halfsphere+0x37c>
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    14a9 <halfsphere+0x369>
cvtsi2ssl -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd6f(%rip),%xmm1
mulsd  %xmm0,%xmm1
cvtsi2ssl -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
divsd  %xmm0,%xmm1
movsd  0xd66(%rip),%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
cvtsi2ss %eax,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd33(%rip),%xmm1
mulsd  %xmm0,%xmm1
cvtsi2ssl -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
divsd  %xmm0,%xmm1
movsd  0xd2a(%rip),%xmm0
addsd  %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 <halfsphere+0x134>
jmp    14ae <halfsphere+0x36e>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115a <halfsphere+0x1a>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<halfsphere>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
movss  %xmm0,0x38(%rsp)
test   %edi,%edi
jle    141d <halfsphere+0x2dd>
mov    %edi,%ebx
xorps  %xmm0,%xmm0
cvtsi2ss %edi,%xmm0
movss  %xmm0,0x48(%rsp)
cvtss2sd %xmm0,%xmm2
xor    %r14d,%r14d
movsd  0xe94(%rip),%xmm3
movss  0x38(%rsp),%xmm0
mulss  %xmm0,%xmm0
movss  %xmm0,0x44(%rsp)
movsd  %xmm2,0x50(%rsp)
nopw   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2ss %r14d,%xmm0
divss  0x48(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe56(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  %xmm3,%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  0xe18(%rip),%xmm0
mulsd  0xe18(%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 0xe01(%rip),%xmm0
jb     1230 <halfsphere+0xf0>
xorps  %xmm2,%xmm2
sqrtss %xmm0,%xmm2
jmp    1244 <halfsphere+0x104>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
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 <halfsphere+0x140>
sqrtss %xmm0,%xmm0
jmp    1285 <halfsphere+0x145>
cs nopw 0x0(%rax,%rax,1)
call   1060 <sqrt@plt>
movsd  0x50(%rsp),%xmm2
movsd  0xd75(%rip),%xmm3
movsd  0xd75(%rip),%xmm4
movss  %xmm0,0x30(%rsp)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  %xmm3,%xmm0
divsd  %xmm2,%xmm0
addsd  %xmm4,%xmm0
add    $0x1,%ebp
xorps  %xmm1,%xmm1
cvtsi2ss %ebp,%xmm1
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x40(%rsp)
cvtss2sd %xmm1,%xmm1
mulsd  %xmm3,%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm4,%xmm1
cvtsd2ss %xmm1,%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  0xc12(%rip),%xmm4
movsd  0xc02(%rip),%xmm3
movsd  0x50(%rsp),%xmm2
cmp    %ebp,%ebx
jne    12b0 <halfsphere+0x170>
cmp    %ebx,%r14d
jne    1190 <halfsphere+0x50>
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @halfsphere(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 = %126, %2
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %129
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 = %122, %17
%60 = load i32, i32* %10
%61 = load i32, i32* %4
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %125
63: ; preds = %59
%64 = load i32, i32* %10
%65 = sitofp i32 %64 to float
%66 = fpext float %65 to double
%67 = fmul double 0x400921FB54442D18, %66
%68 = load i32, i32* %4
%69 = sitofp i32 %68 to float
%70 = fpext float %69 to double
%71 = fdiv double %67, %70
%72 = fadd double 0x3FF921FB54442D18, %71
%73 = fptrunc double %72 to float
store float %73, float* %11
%74 = load i32, i32* %10
%75 = add nsw i32 %74, 1
%76 = sitofp i32 %75 to float
%77 = fpext float %76 to double
%78 = fmul double 0x400921FB54442D18, %77
%79 = load i32, i32* %4
%80 = sitofp i32 %79 to float
%81 = fpext float %80 to double
%82 = fdiv double %78, %81
%83 = fadd double 0x3FF921FB54442D18, %82
%84 = fptrunc double %83 to float
store float %84, float* %12
%85 = load float, float* %8
%86 = load float, float* %11
%87 = call float @cos(float %86)
%88 = fmul float %85, %87
%89 = load float, float* %6
%90 = load float, float* %8
%91 = load float, float* %11
%92 = call float @sin(float %91)
%93 = fmul float %90, %92
%94 = load float, float* %8
%95 = load float, float* %12
%96 = call float @cos(float %95)
%97 = fmul float %94, %96
%98 = load float, float* %6
%99 = load float, float* %8
%100 = load float, float* %12
%101 = call float @sin(float %100)
%102 = fmul float %99, %101
%103 = load float, float* %9
%104 = load float, float* %12
%105 = call float @cos(float %104)
%106 = fmul float %103, %105
%107 = load float, float* %7
%108 = load float, float* %9
%109 = load float, float* %12
%110 = call float @sin(float %109)
%111 = fmul float %108, %110
%112 = load float, float* %9
%113 = load float, float* %11
%114 = call float @cos(float %113)
%115 = fmul float %112, %114
%116 = load float, float* %7
%117 = load float, float* %9
%118 = load float, float* %11
%119 = call float @sin(float %118)
%120 = fmul float %117, %119
%121 = call i32 @quad(float %88, float %89, float %93, float %97, float %98, float %102, float %106, float %107, float %111, float %115, float %116, float %120)
br label %122
122: ; preds = %63
%123 = load i32, i32* %10
%124 = add nsw i32 %123, 1
store i32 %124, i32* %10
br label %59
125: ; preds = %59
br label %126
126: ; preds = %125
%127 = load i32, i32* %5
%128 = add nsw i32 %127, 1
store i32 %128, i32* %5
br label %13
129: ; preds = %13
ret void
}

LLVM IR (-O2):
define void @halfsphere(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 [ %45, %37 ], [ 0, %10 ]
%39 = sitofp i32 %38 to float
%40 = fpext float %39 to double
%41 = fmul double %40, 0x400921FB54442D18
%42 = fdiv double %41, %6
%43 = fadd double %42, 0x3FF921FB54442D18
%44 = fptrunc double %43 to float
%45 = add nuw nsw i32 %38, 1
%46 = sitofp i32 %45 to float
%47 = fpext float %46 to double
%48 = fmul double %47, 0x400921FB54442D18
%49 = fdiv double %48, %6
%50 = fadd double %49, 0x3FF921FB54442D18
%51 = fptrunc double %50 to float
%52 = tail call float @cos(float %44)
%53 = fmul float %32, %52
%54 = tail call float @sin(float %44)
%55 = fmul float %32, %54
%56 = tail call float @cos(float %51)
%57 = fmul float %32, %56
%58 = tail call float @sin(float %51)
%59 = fmul float %32, %58
%60 = tail call float @cos(float %51)
%61 = fmul float %36, %60
%62 = tail call float @sin(float %51)
%63 = fmul float %36, %62
%64 = tail call float @cos(float %44)
%65 = fmul float %36, %64
%66 = tail call float @sin(float %44)
%67 = fmul float %36, %66
%68 = tail call i32 @quad(float %53, float %19, float %55, float %57, float %19, float %59, float %61, float %28, float %63, float %65, float %28, float %67)
%69 = icmp eq i32 %45, %1
br i1 %69, label %7, label %37
}