#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 fabs(double);
int /*<<< orphan*/ printf(char *, double);
int main(void) {
  double pi = 0.0, n = 1.0, term = 1.0;
  int sign = 1;
  while (fabs(term) >= 1e-6) {
    pi += term;
    n += 2;
    sign *= -1;
    term = sign / n;
  }
  pi = pi * 4;
  printf("pi=%.8lf\n", pi);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xec1(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeb4(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe9a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11b4 <main+0x94>
movsd  -0x20(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe89(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
imul   $0xffffffff,-0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1158 <main+0x38>
movsd  0xe54(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    0xe4e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movsd  0xed2(%rip),%xmm0
movsd  %xmm0,(%rsp)
call   1040 <fabs@plt>
xorpd  %xmm0,%xmm0
test   %eax,%eax
jle    11ac <main+0x8c>
mov    $0xffffffff,%ebx
mov    $0x1,%ecx
movsd  0xeae(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ecx,%ebp
addsd  (%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
addsd  0xe93(%rip),%xmm1
movsd  %xmm1,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
call   1040 <fabs@plt>
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm0
mov    %ebx,%ecx
mov    %ebp,%ebx
test   %eax,%eax
jg     1160 <main+0x40>
mulsd  0xe64(%rip),%xmm0
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"pi=%.8lf\0A\00"
define i32 @main() {
%1 = tail call i32 @fabs(double 1.000000e+00)
%2 = icmp sgt i32 %1, 0
br i1 %2, label %3, label %17
3: ; preds = %0, %3
%4 = phi i32 [ %5, %3 ], [ 1, %0 ]
%5 = phi i32 [ %4, %3 ], [ -1, %0 ]
%6 = phi double [ %12, %3 ], [ 1.000000e+00, %0 ]
%7 = phi double [ %10, %3 ], [ 1.000000e+00, %0 ]
%8 = phi double [ %9, %3 ], [ 0.000000e+00, %0 ]
%9 = fadd double %8, %6
%10 = fadd double %7, 2.000000e+00
%11 = sitofp i32 %5 to double
%12 = fdiv double %11, %10
%13 = tail call i32 @fabs(double %12)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %3, label %15
15: ; preds = %3
%16 = fmul double %9, 4.000000e+00
br label %17
17: ; preds = %15, %0
%18 = phi double [ 0.000000e+00, %0 ], [ %16, %15 ]
%19 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %18)
ret i32 0
}