#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 */
double M_PI;
int atoi(char const *);
double iterate_approx_pi(size_t, int);
int /*<<< orphan*/ printf(char *, double);
int main(int argc, const char **argv) {
  size_t i, iterations;
  int verbose;
  unsigned base;
  char *endptr;
  double pi;
  iterations = (argc > 1) ? ((size_t)atoi(argv[1])) : 10 * 1000 * 1000;
  verbose = (argc > 2) ? atoi(argv[2]) : 0;
  pi = iterate_approx_pi(iterations, verbose);
  printf("after %lu iterations\n", (unsigned long)iterations);
  printf("pi is about: %21.18f\n", pi);
  printf("pi is known: %21.18f\n", M_PI);
  printf("      error: %21.18f\n", M_PI - pi);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1168 <main+0x38>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
cltq
mov    %rax,-0x40(%rbp)
jmp    1176 <main+0x46>
mov    $0x989680,%eax
mov    %rax,-0x40(%rbp)
jmp    1176 <main+0x46>
mov    -0x40(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    119d <main+0x6d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x44(%rbp)
jmp    11a7 <main+0x77>
xor    %eax,%eax
mov    %eax,-0x44(%rbp)
jmp    11a7 <main+0x77>
mov    -0x44(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <iterate_approx_pi@plt>
movsd  %xmm0,-0x38(%rbp)
movaps 0xe3b(%rip),%xmm1
movq   -0x20(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe3a(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
lea    0xe34(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x38(%rbp),%xmm0
lea    0xe39(%rip),%rdi
call   1040 <printf@plt>
mov    0x2ddf(%rip),%rax
movsd  (%rax),%xmm0
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dc8(%rip),%rax
movsd  (%rax),%xmm0
subsd  -0x38(%rbp),%xmm0
lea    0xe32(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
mov    $0x989680,%ebx
cmp    $0x2,%edi
jl     1166 <main+0x36>
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
movslq %eax,%rbx
cmp    $0x2,%ebp
je     1166 <main+0x36>
mov    0x10(%r15),%rdi
call   1050 <atoi@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <iterate_approx_pi@plt>
movsd  %xmm0,(%rsp)
movq   %rbx,%xmm1
punpckldq 0xe7d(%rip),%xmm1
subpd  0xe85(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
lea    0xe8c(%rip),%rdi
movsd  (%rsp),%xmm0
call   1040 <printf@plt>
mov    0x2e2d(%rip),%rbx
movsd  (%rbx),%xmm0
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
movsd  (%rbx),%xmm0
subsd  (%rsp),%xmm0
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"after %lu iterations\0A\00"
@.str.1 = [22 x i8] c"pi is about: %21.18f\0A\00"
@.str.2 = [22 x i8] c"pi is known: %21.18f\0A\00"
@M_PI = global double 0.000000e+00
@.str.3 = [22 x i8] c" error: %21.18f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
%19 = sext i32 %18 to i64
br label %21
20: ; preds = %2
br label %21
21: ; preds = %20, %14
%22 = phi i64 [ %19, %14 ], [ 10000000, %20 ]
store i64 %22, i64* %7
%23 = load i32, i32* %4
%24 = icmp sgt i32 %23, 2
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
br label %31
30: ; preds = %21
br label %31
31: ; preds = %30, %25
%32 = phi i32 [ %29, %25 ], [ 0, %30 ]
store i32 %32, i32* %8
%33 = load i64, i64* %7
%34 = load i32, i32* %8
%35 = call double @iterate_approx_pi(i64 %33, i32 %34)
store double %35, double* %11
%36 = load i64, i64* %7
%37 = uitofp i64 %36 to double
%38 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), double %37)
%39 = load double, double* %11
%40 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), double %39)
%41 = load double, double* @M_PI
%42 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), double %41)
%43 = load double, double* @M_PI
%44 = load double, double* %11
%45 = fsub double %43, %44
%46 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), double %45)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"after %lu iterations\0A\00"
@.str.1 = [22 x i8] c"pi is about: %21.18f\0A\00"
@.str.2 = [22 x i8] c"pi is known: %21.18f\0A\00"
@M_PI = global double 0.000000e+00
@.str.3 = [22 x i8] c" error: %21.18f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %14
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = sext i32 %7 to i64
%9 = icmp eq i32 %0, 2
br i1 %9, label %14, label %10
10: ; preds = %4
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
br label %14
14: ; preds = %2, %4, %10
%15 = phi i64 [ %8, %10 ], [ %8, %4 ], [ 10000000, %2 ]
%16 = phi i32 [ %13, %10 ], [ 0, %4 ], [ 0, %2 ]
%17 = tail call double @iterate_approx_pi(i64 %15, i32 %16)
%18 = uitofp i64 %15 to double
%19 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), double %18)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), double %17)
%21 = load double, double* @M_PI
%22 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), double %21)
%23 = load double, double* @M_PI
%24 = fsub double %23, %17
%25 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), double %24)
ret i32 0
}