#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 /*<<< orphan*/ printf(char *, ...);
unsigned long long strtoull(char *, char *, int);
int main(int argc, char **argv) {
  if (argc < 2) {
    printf("Usage: %s <iterations>\n", argv[0]);
    return -1;
  }
  unsigned long long i;
  unsigned long long iter = strtoull(argv[1], argv[2], 10);
  printf("Doing %llu iterations.\n", iter);
  long double sum = 0.0;
  for (i = 0; i < iter; i++) {
    sum = sum + 2.0L / ((4 * i + 1) * (4 * i + 3));
  }
  printf("The calculated value of pi is: %.20Lf\n", 4.0L * sum);
  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   $0x2,-0x8(%rbp)
jge    1161 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1224 <main+0x104>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x10(%rax),%rsi
mov    $0xa,%edx
call   1040 <strtoull@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xea2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
fldz
fstpt  -0x30(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11ff <main+0xdf>
fldt   -0x30(%rbp)
mov    -0x18(%rbp),%rcx
lea    0x1(,%rcx,4),%rax
lea    0x3(,%rcx,4),%rcx
imul   %rcx,%rax
mov    %rax,-0x38(%rbp)
test   %rax,%rax
sets   %al
movzbl %al,%eax
mov    %eax,%ecx
fildll -0x38(%rbp)
lea    0xe2c(%rip),%rax
flds   (%rax,%rcx,4)
faddp  %st,%st(1)
flds   0xe1d(%rip)
fdivp  %st,%st(1)
faddp  %st,%st(1)
fstpt  -0x30(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    119a <main+0x7a>
fldt   -0x30(%rbp)
flds   0xdf8(%rip)
fmulp  %st,%st(1)
mov    %rsp,%rax
fstpt  (%rax)
lea    0xe2a(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
cmp    $0x1,%edi
jg     1146 <main+0x26>
mov    (%rsi),%rsi
lea    0xedb(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%ebp
jmp    1254 <main+0x134>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rsi
mov    $0xa,%edx
call   1040 <strtoull@plt>
mov    %rax,%rbx
lea    0xec6(%rip),%rdi
xor    %ebp,%ebp
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
fldz
test   %rbx,%rbx
je     1243 <main+0x123>
fstp   %st(0)
fldz
cmp    $0x1,%rbx
jne    1189 <main+0x69>
xor    %eax,%eax
fldz
jmp    1204 <main+0xe4>
fstp   %st(0)
mov    %rbx,%rcx
and    $0xfffffffffffffffe,%rcx
fldz
xor    %eax,%eax
lea    0xe63(%rip),%rdx
flds   0xe65(%rip)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x1(%rax),%rsi
lea    0x3(%rax),%rdi
imul   %rdi,%rsi
mov    %rsi,0x20(%rsp)
xor    %edi,%edi
test   %rsi,%rsi
sets   %dil
fildll 0x20(%rsp)
fadds  (%rdx,%rdi,4)
fdivr  %st(1),%st
faddp  %st,%st(2)
lea    0x5(%rax),%rsi
lea    0x7(%rax),%rdi
imul   %rdi,%rsi
mov    %rsi,0x18(%rsp)
xor    %edi,%edi
test   %rsi,%rsi
sets   %dil
fildll 0x18(%rsp)
fadds  (%rdx,%rdi,4)
fdivr  %st(1),%st
faddp  %st,%st(2)
add    $0x8,%rax
add    $0xfffffffffffffffe,%rcx
jne    11b0 <main+0x90>
fstp   %st(0)
test   $0x1,%bl
je     123d <main+0x11d>
mov    %rax,%rcx
or     $0x1,%rcx
or     $0x3,%rax
imul   %rcx,%rax
mov    %rax,0x10(%rsp)
xor    %ecx,%ecx
test   %rax,%rax
sets   %cl
fildll 0x10(%rsp)
lea    0xdce(%rip),%rax
fadds  (%rax,%rcx,4)
fdivrs 0xdcd(%rip)
faddp  %st,%st(1)
fmuls  0xdc9(%rip)
fstpt  (%rsp)
lea    0xdf3(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Usage: %s <iterations>\0A\00"
@.str.1 = [24 x i8] c"Doing %llu iterations.\0A\00"
@.str.2 = [39 x i8] c"The calculated value of pi is: %.20Lf\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 x86_fp80
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 -1, i32* %3
br label %49
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i64 @strtoull(i8* %19, i8* %22, i32 10)
store i64 %23, i64* %7
%24 = load i64, i64* %7
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 %24)
store x86_fp80 0xK00000000000000000000, x86_fp80* %8
store i64 0, i64* %6
br label %26
26: ; preds = %42, %16
%27 = load i64, i64* %6
%28 = load i64, i64* %7
%29 = icmp ult i64 %27, %28
br i1 %29, label %30, label %45
30: ; preds = %26
%31 = load x86_fp80, x86_fp80* %8
%32 = load i64, i64* %6
%33 = mul i64 4, %32
%34 = add i64 %33, 1
%35 = load i64, i64* %6
%36 = mul i64 4, %35
%37 = add i64 %36, 3
%38 = mul i64 %34, %37
%39 = uitofp i64 %38 to x86_fp80
%40 = fdiv x86_fp80 0xK40008000000000000000, %39
%41 = fadd x86_fp80 %31, %40
store x86_fp80 %41, x86_fp80* %8
br label %42
42: ; preds = %30
%43 = load i64, i64* %6
%44 = add i64 %43, 1
store i64 %44, i64* %6
br label %26
45: ; preds = %26
%46 = load x86_fp80, x86_fp80* %8
%47 = fmul x86_fp80 0xK40018000000000000000, %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), x86_fp80 %47)
store i32 0, i32* %3
br label %49
49: ; preds = %45, %11
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [24 x i8] c"Usage: %s <iterations>\0A\00"
@.str.1 = [24 x i8] c"Doing %llu iterations.\0A\00"
@.str.2 = [39 x i8] c"The calculated value of pi is: %.20Lf\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %61
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i64 @strtoull(i8* %9, i8* %11, i32 10)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 %12)
%14 = icmp eq i64 %12, 0
br i1 %14, label %58, label %15
15: ; preds = %7
%16 = and i64 %12, 1
%17 = icmp eq i64 %12, 1
br i1 %17, label %43, label %18
18: ; preds = %15
%19 = and i64 %12, -2
br label %20
20: ; preds = %20, %18
%21 = phi x86_fp80 [ 0xK00000000000000000000, %18 ], [ %37, %20 ]
%22 = phi i64 [ 0, %18 ], [ %38, %20 ]
%23 = phi i64 [ 0, %18 ], [ %39, %20 ]
%24 = shl i64 %22, 2
%25 = or i64 %24, 1
%26 = or i64 %24, 3
%27 = mul i64 %25, %26
%28 = uitofp i64 %27 to x86_fp80
%29 = fdiv x86_fp80 0xK40008000000000000000, %28
%30 = fadd x86_fp80 %21, %29
%31 = shl i64 %22, 2
%32 = or i64 %31, 5
%33 = or i64 %31, 7
%34 = mul i64 %32, %33
%35 = uitofp i64 %34 to x86_fp80
%36 = fdiv x86_fp80 0xK40008000000000000000, %35
%37 = fadd x86_fp80 %30, %36
%38 = add nuw i64 %22, 2
%39 = add i64 %23, 2
%40 = icmp eq i64 %39, %19
br i1 %40, label %41, label %20
41: ; preds = %20
%42 = shl i64 %38, 2
br label %43
43: ; preds = %41, %15
%44 = phi x86_fp80 [ undef, %15 ], [ %37, %41 ]
%45 = phi x86_fp80 [ 0xK00000000000000000000, %15 ], [ %37, %41 ]
%46 = phi i64 [ 0, %15 ], [ %42, %41 ]
%47 = icmp eq i64 %16, 0
br i1 %47, label %55, label %48
48: ; preds = %43
%49 = or i64 %46, 1
%50 = or i64 %46, 3
%51 = mul i64 %49, %50
%52 = uitofp i64 %51 to x86_fp80
%53 = fdiv x86_fp80 0xK40008000000000000000, %52
%54 = fadd x86_fp80 %45, %53
br label %55
55: ; preds = %43, %48
%56 = phi x86_fp80 [ %44, %43 ], [ %54, %48 ]
%57 = fmul x86_fp80 %56, 0xK40018000000000000000
br label %58
58: ; preds = %55, %7
%59 = phi x86_fp80 [ 0xK00000000000000000000, %7 ], [ %57, %55 ]
%60 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), x86_fp80 %59)
br label %61
61: ; preds = %58, %4
%62 = phi i32 [ -1, %4 ], [ 0, %58 ]
ret i32 %62
}