#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);
int main() {
  int sign = 1, k = 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;
    k++;
  }
  pi = pi * 4;
  printf("pi=%10.8f\nloopth is %12d\n", pi, k);
  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)
movsd  -0x18(%rbp),%xmm0
mov    -0xc(%rbp),%esi
lea    0xe3a(%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    11b5 <main+0x95>
mov    $0xffffffff,%ebp
mov    $0x1,%ecx
xor    %ebx,%ebx
xorpd  %xmm0,%xmm0
movsd  0xea9(%rip),%xmm1
nopw   0x0(%rax,%rax,1)
mov    %ecx,%r14d
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
addsd  0xe91(%rip),%xmm1
movsd  %xmm1,0x10(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
divsd  %xmm1,%xmm0
add    $0x1,%ebx
movsd  %xmm0,0x8(%rsp)
call   1040 <fabs@plt>
movsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm0
mov    %ebp,%ecx
mov    %r14d,%ebp
test   %eax,%eax
jg     1160 <main+0x40>
mulsd  0xe5d(%rip),%xmm0
jmp    11bb <main+0x9b>
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
lea    0xe56(%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 = [26 x i8] c"pi=%10.8f\0Aloopth is %12d\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 = load i32, i32* %3
%31 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double %29, i32 %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"pi=%10.8f\0Aloopth is %12d\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 %19
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
br label %19
19: ; preds = %17, %0
%20 = phi i32 [ 0, %0 ], [ %14, %17 ]
%21 = phi double [ 0.000000e+00, %0 ], [ %18, %17 ]
%22 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double %21, i32 %20)
ret i32 0
}