#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 */
int /*<<< orphan*/ printf(char *, double);
int main(void) {
  int i;
  double pi = 0;
  for (i = 0;; i++) {
    double temp = 1.0 / (i * 2 + 1);
    if (i % 2 == 0)
      pi += temp;
    else
      pi -= temp;
    if (temp < 1e-6)
      break;
  }
  printf("%.6f\n", pi);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xebd(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1174 <main+0x64>
movsd  -0x18(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1187 <main+0x77>
movsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe79(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    119f <main+0x8f>
jmp    11b2 <main+0xa2>
jmp    11a4 <main+0x94>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    112e <main+0x1e>
movsd  -0x10(%rbp),%xmm0
lea    0xe52(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xorpd  %xmm0,%xmm0
xor    %eax,%eax
mov    $0x1,%ecx
movsd  0xedc(%rip),%xmm1
movapd 0xee4(%rip),%xmm2
movsd  0xed4(%rip),%xmm3
jmp    1150 <main+0x40>
cs nopw 0x0(%rax,%rax,1)
addsd  %xmm5,%xmm0
add    $0x1,%eax
add    $0x2,%ecx
ucomisd %xmm4,%xmm3
ja     1171 <main+0x61>
xorps  %xmm5,%xmm5
cvtsi2sd %ecx,%xmm5
movapd %xmm1,%xmm4
divsd  %xmm5,%xmm4
movapd %xmm4,%xmm5
test   $0x1,%al
je     1140 <main+0x30>
movapd %xmm4,%xmm5
xorpd  %xmm2,%xmm5
jmp    1140 <main+0x30>
lea    0xea8(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%.6f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca double
store i32 0, i32* %1
store double 0.000000e+00, double* %3
store i32 0, i32* %2
br label %5
5: ; preds = %27, %0
%6 = load i32, i32* %2
%7 = mul nsw i32 %6, 2
%8 = add nsw i32 %7, 1
%9 = sitofp i32 %8 to double
%10 = fdiv double 1.000000e+00, %9
store double %10, double* %4
%11 = load i32, i32* %2
%12 = srem i32 %11, 2
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %5
%15 = load double, double* %4
%16 = load double, double* %3
%17 = fadd double %16, %15
store double %17, double* %3
br label %22
18: ; preds = %5
%19 = load double, double* %4
%20 = load double, double* %3
%21 = fsub double %20, %19
store double %21, double* %3
br label %22
22: ; preds = %18, %14
%23 = load double, double* %4
%24 = fcmp olt double %23, 0x3EB0C6F7A0B5ED8D
br i1 %24, label %25, label %26
25: ; preds = %22
br label %30
26: ; preds = %22
br label %27
27: ; preds = %26
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %5
30: ; preds = %25
%31 = load double, double* %3
%32 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%.6f\0A\00"
define i32 @main() {
br label %1
1: ; preds = %1, %0
%2 = phi i32 [ 0, %0 ], [ %14, %1 ]
%3 = phi double [ 0.000000e+00, %0 ], [ %12, %1 ]
%4 = shl nuw nsw i32 %2, 1
%5 = or i32 %4, 1
%6 = sitofp i32 %5 to double
%7 = fdiv double 1.000000e+00, %6
%8 = and i32 %2, 1
%9 = icmp eq i32 %8, 0
%10 = fneg double %7
%11 = select i1 %9, double %7, double %10
%12 = fadd double %3, %11
%13 = fcmp olt double %7, 0x3EB0C6F7A0B5ED8D
%14 = add nuw nsw i32 %2, 1
br i1 %13, label %15, label %1
15: ; preds = %1
%16 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %12)
ret i32 0
}