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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeb3(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xea6(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe93(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11c5 <main+0xa5>
movsd  -0x18(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe82(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
xor    %eax,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115f <main+0x3f>
movsd  0xe43(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
cvttsd2si -0x18(%rbp),%esi
lea    0xe3d(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe39(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
movsd  0xed0(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1040 <fabs@plt>
test   %eax,%eax
jle    11b9 <main+0x99>
mov    $0xffffffff,%ebp
mov    $0x1,%ecx
xor    %ebx,%ebx
xorpd  %xmm1,%xmm1
movsd  0xea9(%rip),%xmm2
nopw   0x0(%rax,%rax,1)
mov    %ecx,%r14d
addsd  0x8(%rsp),%xmm1
movsd  %xmm1,0x18(%rsp)
addsd  0xe91(%rip),%xmm2
movsd  %xmm2,0x10(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
divsd  %xmm2,%xmm0
add    $0x1,%ebx
movsd  %xmm0,0x8(%rsp)
call   1040 <fabs@plt>
movsd  0x10(%rsp),%xmm2
movsd  0x18(%rsp),%xmm1
mov    %ebp,%ecx
mov    %r14d,%ebp
test   %eax,%eax
jg     1160 <main+0x40>
mulsd  0xe5d(%rip),%xmm1
cvttsd2si %xmm1,%esi
jmp    11bd <main+0x9d>
xor    %ebx,%ebx
xor    %esi,%esi
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
lea    0xe53(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"pi=%10.8f\0A\00"
@.str.1 = [10 x i8] c"count=%d\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 %20
3: ; preds = %0, %3
%4 = phi double [ %13, %3 ], [ 1.000000e+00, %0 ]
%5 = phi double [ %11, %3 ], [ 1.000000e+00, %0 ]
%6 = phi double [ %10, %3 ], [ 0.000000e+00, %0 ]
%7 = phi i32 [ %14, %3 ], [ 0, %0 ]
%8 = phi i32 [ %9, %3 ], [ 1, %0 ]
%9 = phi i32 [ %8, %3 ], [ -1, %0 ]
%10 = fadd double %6, %4
%11 = fadd double %5, 2.000000e+00
%12 = sitofp i32 %9 to double
%13 = fdiv double %12, %11
%14 = add nuw nsw i32 %7, 1
%15 = tail call i32 @fabs(double %13)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %3, label %17
17: ; preds = %3
%18 = fmul double %10, 4.000000e+00
%19 = fptosi double %18 to i32
br label %20
20: ; preds = %17, %0
%21 = phi i32 [ 0, %0 ], [ %14, %17 ]
%22 = phi i32 [ 0, %0 ], [ %19, %17 ]
%23 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %21)
ret i32 0
}