#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*/ M_PI;
int /*<<< orphan*/ printf(char *, double, int /*<<< orphan*/);
int main() {
  int factors = 1, factor_b = 1;
  double pi = 1, member = 1;
  do {
    factors += 2;
    member *= (double)factor_b / factors;
    factor_b++;
    pi += member;
  } while (member > 1e-6);
  pi *= 2;
  printf("pi (approximate) = %10.8lf \t pi = %10.8lf\n", pi, M_PI);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movsd  0xecb(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xebe(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x8(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe7b(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     1147 <main+0x37>
movsd  0xe71(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movsd  0xee7(%rip),%xmm0
mov    $0x1,%eax
mov    $0x3,%ecx
movsd  0xedd(%rip),%xmm1
movapd %xmm0,%xmm2
nop
xorps  %xmm3,%xmm3
cvtsi2sd %eax,%xmm3
xorps  %xmm4,%xmm4
cvtsi2sd %ecx,%xmm4
divsd  %xmm4,%xmm3
mulsd  %xmm3,%xmm2
add    $0x1,%eax
addsd  %xmm2,%xmm0
add    $0x2,%ecx
ucomisd %xmm1,%xmm2
ja     1130 <main+0x20>
addsd  %xmm0,%xmm0
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [43 x i8] c"pi (approximate) = %10.8lf \09 pi = %10.8lf\0A\00"
@M_PI = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
store i32 0, i32* %1
store i32 1, i32* %2
store i32 1, i32* %3
store double 1.000000e+00, double* %4
store double 1.000000e+00, double* %5
br label %6
6: ; preds = %21, %0
%7 = load i32, i32* %2
%8 = add nsw i32 %7, 2
store i32 %8, i32* %2
%9 = load i32, i32* %3
%10 = sitofp i32 %9 to double
%11 = load i32, i32* %2
%12 = sitofp i32 %11 to double
%13 = fdiv double %10, %12
%14 = load double, double* %5
%15 = fmul double %14, %13
store double %15, double* %5
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
%18 = load double, double* %5
%19 = load double, double* %4
%20 = fadd double %19, %18
store double %20, double* %4
br label %21
21: ; preds = %6
%22 = load double, double* %5
%23 = fcmp ogt double %22, 0x3EB0C6F7A0B5ED8D
br i1 %23, label %6, label %24
24: ; preds = %21
%25 = load double, double* %4
%26 = fmul double %25, 2.000000e+00
store double %26, double* %4
%27 = load double, double* %4
%28 = load i32, i32* @M_PI
%29 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), double %27, i32 %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [43 x i8] c"pi (approximate) = %10.8lf \09 pi = %10.8lf\0A\00"
@M_PI = global i32 0
define i32 @main() {
br label %1
1: ; preds = %1, %0
%2 = phi i32 [ 1, %0 ], [ %6, %1 ]
%3 = phi i32 [ 1, %0 ], [ %11, %1 ]
%4 = phi double [ 1.000000e+00, %0 ], [ %12, %1 ]
%5 = phi double [ 1.000000e+00, %0 ], [ %10, %1 ]
%6 = add nuw nsw i32 %2, 2
%7 = sitofp i32 %3 to double
%8 = sitofp i32 %6 to double
%9 = fdiv double %7, %8
%10 = fmul double %5, %9
%11 = add nuw nsw i32 %3, 1
%12 = fadd double %4, %10
%13 = fcmp ogt double %10, 0x3EB0C6F7A0B5ED8D
br i1 %13, label %1, label %14
14: ; preds = %1
%15 = fmul double %12, 2.000000e+00
%16 = load i32, i32* @M_PI
%17 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), double %15, i32 %16)
ret i32 0
}