#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 pow(int, int);
int /*<<< orphan*/ printf(char *, double);
int main() {
  int i = 0;
  double arctan1 = 0;
  double d;
  while (i < 10000) {
    arctan1 += pow(-1, i) / (i * 2 + 1);
    if (i % 100 == 0) {
      printf("pi = %f\n", arctan1 * 4);
    }
    i++;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
cmpl   $0x2710,-0x8(%rbp)
jge    11ad <main+0x8d>
mov    -0x8(%rbp),%esi
mov    $0xffffffff,%edi
call   1040 <pow@plt>
mov    -0x8(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    119f <main+0x7f>
movsd  0xe72(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    113e <main+0x1e>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
mov    $0x1,%ebp
lea    0xeca(%rip),%r14
jmp    114e <main+0x2e>
add    $0x1,%ebx
add    $0x2,%ebp
cmp    $0x4e21,%ebp
je     11b1 <main+0x91>
movsd  %xmm0,0x8(%rsp)
movzwl %bx,%r15d
mov    %r15d,%eax
shr    $0x2,%eax
imul   $0x147b,%eax,%eax
shr    $0x11,%eax
imul   $0xffffff9c,%eax,%r12d
mov    $0xffffffff,%edi
mov    %ebx,%esi
call   1040 <pow@plt>
cltd
idiv   %ebp
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x8(%rsp),%xmm0
add    %r12w,%r15w
jne    1140 <main+0x20>
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0xe5f(%rip),%xmm0
mov    %r14,%rdi
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
jmp    1140 <main+0x20>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [9 x i8] c"pi = %f\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %16
%2 = phi i32 [ 0, %0 ], [ %17, %16 ]
%3 = phi double [ 0.000000e+00, %0 ], [ %9, %16 ]
%4 = tail call i32 @pow(i32 -1, i32 %2)
%5 = shl nuw nsw i32 %2, 1
%6 = or i32 %5, 1
%7 = sdiv i32 %4, %6
%8 = sitofp i32 %7 to double
%9 = fadd double %3, %8
%10 = trunc i32 %2 to i16
%11 = urem i16 %10, 100
%12 = icmp eq i16 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = fmul double %9, 4.000000e+00
%15 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %14)
br label %16
16: ; preds = %13, %1
%17 = add nuw nsw i32 %2, 1
%18 = icmp eq i32 %17, 10000
br i1 %18, label %19, label %1
19: ; preds = %16
ret i32 0
}