#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 sqrt(double);
double circle_pi(int rectangles) {
  int i;
  double width = 0.0, area = 0.0, piFourths = 0.0;
  if (rectangles > 0) {
    width = 1.0 / rectangles;
  }
  for (i = 1; i <= rectangles; i++) {
    double midpoint, height;
    midpoint = (width * i) - (width / 2);
    height = sqrt(1.0 * 1.0 - midpoint * midpoint);
    area += width * height;
  }
  if (1.0 > 0) {
    piFourths = area / (1.0 * 1.0);
  }
  return piFourths * 4;
}


x86 assembly (clang, -O0):
<circle_pi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1153 <circle_pi+0x43>
cvtsi2sdl -0x4(%rbp),%xmm1
movsd  0xeb6(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     120a <circle_pi+0xfa>
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
movsd  0xe93(%rip),%xmm3
divsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe2e(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115a <circle_pi+0x4a>
movsd  -0x18(%rbp),%xmm0
movsd  0xde9(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xde0(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<circle_pi>:
test   %edi,%edi
jle    115f <circle_pi+0x4f>
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edi,%r14d
cvtsi2sd %edi,%xmm0
movsd  0xed3(%rip),%xmm1
movapd %xmm1,%xmm2
divsd  %xmm0,%xmm2
movsd  0xecb(%rip),%xmm4
mulsd  %xmm2,%xmm4
cmp    $0x1,%edi
movsd  %xmm2,0x10(%rsp)
jne    1163 <circle_pi+0x53>
xorpd  %xmm3,%xmm3
test   $0x1,%r14b
jne    1282 <circle_pi+0x172>
jmp    12c9 <circle_pi+0x1b9>
xorps  %xmm0,%xmm0
ret
mov    %r14d,%r15d
and    $0xfffffffe,%r15d
xorpd  %xmm5,%xmm5
mov    $0x1,%eax
movsd  0xe85(%rip),%xmm6
xorpd  %xmm3,%xmm3
movsd  %xmm4,0x18(%rsp)
jmp    11df <circle_pi+0xcf>
nopw   0x0(%rax,%rax,1)
movsd  %xmm3,0x20(%rsp)
call   1030 <sqrt@plt>
movsd  0x20(%rsp),%xmm3
movsd  0xe57(%rip),%xmm6
xorpd  %xmm5,%xmm5
movsd  0x18(%rsp),%xmm4
movsd  0x10(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
mulsd  %xmm2,%xmm3
addsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
movapd %xmm0,%xmm3
addsd  %xmm1,%xmm3
lea    0x1(%rbp),%eax
cmp    %r15d,%ebp
je     1272 <circle_pi+0x162>
mov    %eax,%ebx
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm4,%xmm1
mulsd  %xmm1,%xmm1
movapd %xmm6,%xmm0
subsd  %xmm1,%xmm0
ucomisd %xmm5,%xmm0
movsd  %xmm3,0x8(%rsp)
jb     1220 <circle_pi+0x110>
xorps  %xmm3,%xmm3
sqrtsd %xmm0,%xmm3
jmp    1241 <circle_pi+0x131>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1030 <sqrt@plt>
movsd  0xdd3(%rip),%xmm6
xorpd  %xmm5,%xmm5
movsd  0x18(%rsp),%xmm4
movsd  0x10(%rsp),%xmm2
movapd %xmm0,%xmm3
lea    0x1(%rbx),%ebp
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm4,%xmm1
mulsd  %xmm1,%xmm1
movapd %xmm6,%xmm0
subsd  %xmm1,%xmm0
ucomisd %xmm5,%xmm0
jb     1190 <circle_pi+0x80>
sqrtsd %xmm0,%xmm0
jmp    11b9 <circle_pi+0xa9>
add    $0x2,%ebx
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
test   $0x1,%r14b
je     12c9 <circle_pi+0x1b9>
mulsd  %xmm2,%xmm1
addsd  %xmm4,%xmm1
mulsd  %xmm1,%xmm1
movsd  0xd6a(%rip),%xmm0
subsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     12aa <circle_pi+0x19a>
sqrtsd %xmm0,%xmm0
jmp    12c1 <circle_pi+0x1b1>
movsd  %xmm3,0x8(%rsp)
call   1030 <sqrt@plt>
movsd  0x8(%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
mulsd  %xmm0,%xmm2
addsd  %xmm2,%xmm3
mulsd  0xd3f(%rip),%xmm3
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
movapd %xmm3,%xmm0
ret

LLVM IR (-O0):
define double @circle_pi(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store i32 %0, i32* %2
store double 0.000000e+00, double* %4
store double 0.000000e+00, double* %5
store double 0.000000e+00, double* %6
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load i32, i32* %2
%13 = sitofp i32 %12 to double
%14 = fdiv double 1.000000e+00, %13
store double %14, double* %4
br label %15
15: ; preds = %11, %1
store i32 1, i32* %3
br label %16
16: ; preds = %37, %15
%17 = load i32, i32* %3
%18 = load i32, i32* %2
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %40
20: ; preds = %16
%21 = load double, double* %4
%22 = load i32, i32* %3
%23 = sitofp i32 %22 to double
%24 = load double, double* %4
%25 = fdiv double %24, 2.000000e+00
%26 = fneg double %25
%27 = call double @llvm.fmuladd.f64(double %21, double %23, double %26)
store double %27, double* %7
%28 = load double, double* %7
%29 = load double, double* %7
%30 = fneg double %28
%31 = call double @llvm.fmuladd.f64(double %30, double %29, double 1.000000e+00)
%32 = call double @sqrt(double %31)
store double %32, double* %8
%33 = load double, double* %4
%34 = load double, double* %8
%35 = load double, double* %5
%36 = call double @llvm.fmuladd.f64(double %33, double %34, double %35)
store double %36, double* %5
br label %37
37: ; preds = %20
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %16
40: ; preds = %16
%41 = load double, double* %5
%42 = fdiv double %41, 1.000000e+00
store double %42, double* %6
%43 = load double, double* %6
%44 = fmul double %43, 4.000000e+00
ret double %44
}

LLVM IR (-O2):
define double @circle_pi(i32 %0) {
%2 = icmp sgt i32 %0, 0
br i1 %2, label %3, label %47
3: ; preds = %1
%4 = sitofp i32 %0 to double
%5 = fdiv double 1.000000e+00, %4
%6 = fmul double %5, -5.000000e-01
%7 = and i32 %0, 1
%8 = icmp eq i32 %0, 1
br i1 %8, label %33, label %9
9: ; preds = %3
%10 = and i32 %0, -2
br label %11
11: ; preds = %11, %9
%12 = phi i32 [ 1, %9 ], [ %28, %11 ]
%13 = phi double [ 0.000000e+00, %9 ], [ %27, %11 ]
%14 = phi i32 [ 0, %9 ], [ %29, %11 ]
%15 = sitofp i32 %12 to double
%16 = tail call double @llvm.fmuladd.f64(double %5, double %15, double %6)
%17 = fneg double %16
%18 = tail call double @llvm.fmuladd.f64(double %17, double %16, double 1.000000e+00)
%19 = tail call double @sqrt(double %18)
%20 = tail call double @llvm.fmuladd.f64(double %5, double %19, double %13)
%21 = add nuw i32 %12, 1
%22 = sitofp i32 %21 to double
%23 = tail call double @llvm.fmuladd.f64(double %5, double %22, double %6)
%24 = fneg double %23
%25 = tail call double @llvm.fmuladd.f64(double %24, double %23, double 1.000000e+00)
%26 = tail call double @sqrt(double %25)
%27 = tail call double @llvm.fmuladd.f64(double %5, double %26, double %20)
%28 = add nuw i32 %12, 2
%29 = add i32 %14, 2
%30 = icmp eq i32 %29, %10
br i1 %30, label %31, label %11
31: ; preds = %11
%32 = sitofp i32 %28 to double
br label %33
33: ; preds = %31, %3
%34 = phi double [ undef, %3 ], [ %27, %31 ]
%35 = phi double [ 1.000000e+00, %3 ], [ %32, %31 ]
%36 = phi double [ 0.000000e+00, %3 ], [ %27, %31 ]
%37 = icmp eq i32 %7, 0
br i1 %37, label %44, label %38
38: ; preds = %33
%39 = tail call double @llvm.fmuladd.f64(double %5, double %35, double %6)
%40 = fneg double %39
%41 = tail call double @llvm.fmuladd.f64(double %40, double %39, double 1.000000e+00)
%42 = tail call double @sqrt(double %41)
%43 = tail call double @llvm.fmuladd.f64(double %5, double %42, double %36)
br label %44
44: ; preds = %33, %38
%45 = phi double [ %34, %33 ], [ %43, %38 ]
%46 = fmul double %45, 4.000000e+00
br label %47
47: ; preds = %1, %44
%48 = phi double [ %46, %44 ], [ 0.000000e+00, %1 ]
ret double %48
}