#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 *);
int /*<<< orphan*/ exit(int);
double fabs(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, double, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  double t, k = 3.0, l = -1.0;
  int i, s;
  if (argc < 2) {
    fprintf(stderr, "%s <number of iterations>\n", argv[0]);
    exit(1);
  }
  t = 1.0;
  for (i = 0, s = atoi(argv[1]); i < s; i++) {
    t += l / k;
    k += 2.0;
    l *= -1.0;
  }
  t *= 4;
  printf("My value of Pi: %.16f, math.h's value of Pi: %.16f\n", t, M_PI);
  printf("Absolute difference: %.16f\n", fabs(M_PI - t));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  0xeaa(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe95(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a0 <main+0x60>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xeaf(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movsd  0xe68(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    1216 <main+0xd6>
movsd  -0x28(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe34(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe02(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c4 <main+0x84>
movsd  0xdfa(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    0x2db4(%rip),%rax
movsd  (%rax),%xmm1
lea    0xe1c(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    0x2d9b(%rip),%rax
movsd  (%rax),%xmm0
subsd  -0x18(%rbp),%xmm0
movaps 0xdd3(%rip),%xmm1
pand   %xmm1,%xmm0
lea    0xe27(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jle    1238 <main+0xf8>
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
test   %eax,%eax
jle    1172 <main+0x32>
cmp    $0x1,%eax
jne    117c <main+0x3c>
movsd  0xea0(%rip),%xmm5
movsd  0xea0(%rip),%xmm0
jmp    11d5 <main+0x95>
movsd  0xe86(%rip),%xmm0
jmp    11f1 <main+0xb1>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
movsd  0xe7f(%rip),%xmm5
movsd  0xe7f(%rip),%xmm1
movsd  0xe7f(%rip),%xmm2
movsd  0xe7f(%rip),%xmm3
movapd %xmm1,%xmm0
cs nopw 0x0(%rax,%rax,1)
nop
movapd %xmm2,%xmm4
divsd  %xmm5,%xmm4
addsd  %xmm0,%xmm4
addsd  %xmm3,%xmm5
movapd %xmm1,%xmm0
divsd  %xmm5,%xmm0
addsd  %xmm4,%xmm0
addsd  %xmm3,%xmm5
add    $0xfffffffe,%ecx
jne    11b0 <main+0x70>
test   $0x1,%al
je     11e9 <main+0xa9>
movsd  0xe37(%rip),%xmm1
divsd  %xmm5,%xmm1
addsd  %xmm1,%xmm0
mulsd  0xe0f(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    0x2dea(%rip),%rbx
movsd  (%rbx),%xmm1
lea    0xe52(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  (%rbx),%xmm0
subsd  0x8(%rsp),%xmm0
andpd  0xe0e(%rip),%xmm0
lea    0xe66(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xdf5(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"%s <number of iterations>\0A\00"
@.str.1 = [52 x i8] c"My value of Pi: %.16f, math.h's value of Pi: %.16f\0A\00"
@M_PI = global double 0.000000e+00
@.str.2 = [28 x i8] c"Absolute difference: %.16f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 3.000000e+00, double* %7
store double -1.000000e+00, double* %8
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
store double 1.000000e+00, double* %6
store i32 0, i32* %9
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %10
br label %25
25: ; preds = %39, %20
%26 = load i32, i32* %9
%27 = load i32, i32* %10
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %42
29: ; preds = %25
%30 = load double, double* %8
%31 = load double, double* %7
%32 = fdiv double %30, %31
%33 = load double, double* %6
%34 = fadd double %33, %32
store double %34, double* %6
%35 = load double, double* %7
%36 = fadd double %35, 2.000000e+00
store double %36, double* %7
%37 = load double, double* %8
%38 = fmul double %37, -1.000000e+00
store double %38, double* %8
br label %39
39: ; preds = %29
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %25
42: ; preds = %25
%43 = load double, double* %6
%44 = fmul double %43, 4.000000e+00
store double %44, double* %6
%45 = load double, double* %6
%46 = load double, double* @M_PI
%47 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), double %45, double %46)
%48 = load double, double* @M_PI
%49 = load double, double* %6
%50 = fsub double %48, %49
%51 = call double @llvm.fabs.f64(double %50)
%52 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), double %51)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"%s <number of iterations>\0A\00"
@.str.1 = [52 x i8] c"My value of Pi: %.16f, math.h's value of Pi: %.16f\0A\00"
@M_PI = global double 0.000000e+00
@.str.2 = [28 x i8] c"Absolute difference: %.16f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %42
14: ; preds = %9
%15 = and i32 %12, 1
%16 = icmp eq i32 %12, 1
br i1 %16, label %31, label %17
17: ; preds = %14
%18 = and i32 %12, -2
br label %19
19: ; preds = %19, %17
%20 = phi double [ 1.000000e+00, %17 ], [ %27, %19 ]
%21 = phi double [ 3.000000e+00, %17 ], [ %28, %19 ]
%22 = phi i32 [ 0, %17 ], [ %29, %19 ]
%23 = fdiv double -1.000000e+00, %21
%24 = fadd double %23, %20
%25 = fadd double %21, 2.000000e+00
%26 = fdiv double 1.000000e+00, %25
%27 = fadd double %26, %24
%28 = fadd double %25, 2.000000e+00
%29 = add i32 %22, 2
%30 = icmp eq i32 %29, %18
br i1 %30, label %31, label %19
31: ; preds = %19, %14
%32 = phi double [ undef, %14 ], [ %27, %19 ]
%33 = phi double [ 1.000000e+00, %14 ], [ %27, %19 ]
%34 = phi double [ 3.000000e+00, %14 ], [ %28, %19 ]
%35 = icmp eq i32 %15, 0
br i1 %35, label %39, label %36
36: ; preds = %31
%37 = fdiv double -1.000000e+00, %34
%38 = fadd double %37, %33
br label %39
39: ; preds = %31, %36
%40 = phi double [ %32, %31 ], [ %38, %36 ]
%41 = fmul double %40, 4.000000e+00
br label %42
42: ; preds = %39, %9
%43 = phi double [ 4.000000e+00, %9 ], [ %41, %39 ]
%44 = load double, double* @M_PI
%45 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), double %43, double %44)
%46 = load double, double* @M_PI
%47 = fsub double %46, %43
%48 = tail call double @llvm.fabs.f64(double %47)
%49 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), double %48)
ret i32 0
}