#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(int argc, char **argv) {
  double pi = 0;
  int i;
  for (i = 0; i <= 1999999999; i += 1) {
    pi += 1.0 / (i * 4.0 + 1.0);
    pi -= 1.0 / (i * 4.0 + 3.0);
  }
  pi = pi * 4.0;
  printf("pi done - %f \n", pi);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x773593ff,-0x1c(%rbp)
jg     11ba <main+0xaa>
cvtsi2sdl -0x1c(%rbp),%xmm1
movsd  0xeb1(%rip),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xead(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xea1(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  0xe7e(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe82(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xe6e(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1135 <main+0x25>
movsd  0xe3e(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xorpd  %xmm1,%xmm1
mov    $0x77359400,%eax
movsd  0xede(%rip),%xmm2
movsd  0xede(%rip),%xmm3
movsd  0xede(%rip),%xmm4
xorpd  %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
movapd %xmm1,%xmm5
mulsd  %xmm2,%xmm5
movapd %xmm5,%xmm6
addsd  %xmm3,%xmm6
movapd %xmm3,%xmm7
divsd  %xmm6,%xmm7
addsd  %xmm7,%xmm0
addsd  %xmm4,%xmm5
movapd %xmm3,%xmm6
divsd  %xmm5,%xmm6
subsd  %xmm6,%xmm0
addsd  %xmm3,%xmm1
add    $0xffffffff,%eax
jne    1140 <main+0x30>
mulsd  0xe83(%rip),%xmm0
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [15 x i8] c"pi done - %f \0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %2, %3
%4 = phi i32 [ 0, %2 ], [ %13, %3 ]
%5 = phi double [ 0.000000e+00, %2 ], [ %12, %3 ]
%6 = sitofp i32 %4 to double
%7 = tail call double @llvm.fmuladd.f64(double %6, double 4.000000e+00, double 1.000000e+00)
%8 = fdiv double 1.000000e+00, %7
%9 = fadd double %5, %8
%10 = tail call double @llvm.fmuladd.f64(double %6, double 4.000000e+00, double 3.000000e+00)
%11 = fdiv double 1.000000e+00, %10
%12 = fsub double %9, %11
%13 = add nuw nsw i32 %4, 1
%14 = icmp eq i32 %13, 2000000000
br i1 %14, label %15, label %3
15: ; preds = %3
%16 = fmul double %12, 4.000000e+00
%17 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), double %16)
ret i32 0
}