#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 EXIT_SUCCESS;
int atoi(char *);
double fabs(double);
double hpctimer_getwtime();
int /*<<< orphan*/ printf(char *, double, ...);
int main(int argc, char **argv) {
  double PI25DT = 3.141592653589793238462643;
  int i, nsteps;
  double pi, x, step, sum;
  double t;
  nsteps = (argc > 1) ? atoi(argv[1]) : 1000000;
  step = 1.0 / (double)nsteps;
  t = hpctimer_getwtime();
  sum = 0.0;
  for (i = 1; i <= nsteps; i++) {
    x = (i - 0.5) * step;
    sum = sum + 4.0 / (1.0 + x * x);
  }
  pi = step * sum;
  t = hpctimer_getwtime() - t;
  printf("PI is approximately %.16f, Error is %.16f\n", pi, fabs(pi - PI25DT));
  printf("(nsteps = %d, step = %f)\n", nsteps, step);
  printf("Elapsed time = %.6f sec.\n", t);
  return EXIT_SUCCESS;
}


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)
movsd  0xeb2(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1172 <main+0x42>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x4c(%rbp)
jmp    117f <main+0x4f>
mov    $0xf4240,%eax
mov    %eax,-0x4c(%rbp)
jmp    117f <main+0x4f>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x20(%rbp)
cvtsi2sdl -0x20(%rbp),%xmm1
movsd  0xe76(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1040 <hpctimer_getwtime@plt>
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     121f <main+0xef>
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  0xe49(%rip),%xmm1
subsd  %xmm1,%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm2
movsd  0xe10(%rip),%xmm1
addsd  %xmm1,%xmm2
movsd  0xe0c(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b6 <main+0x86>
movsd  -0x38(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1040 <hpctimer_getwtime@plt>
subsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movaps 0xdcb(%rip),%xmm2
pand   %xmm2,%xmm1
lea    0xdd0(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
cvtsi2sdl -0x20(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
lea    0xde3(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  -0x48(%rbp),%xmm0
lea    0xdea(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    $0xf4240,%ebx
cmp    $0x2,%edi
jl     114a <main+0x1a>
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    %eax,%ebx
cvtsi2sd %ebx,%xmm0
movsd  0xeaa(%rip),%xmm1
movsd  %xmm0,0x18(%rsp)
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1040 <hpctimer_getwtime@plt>
movsd  %xmm0,0x8(%rsp)
test   %ebx,%ebx
jle    119a <main+0x6a>
cmp    $0x1,%ebx
jne    11a8 <main+0x78>
movsd  0xe85(%rip),%xmm0
xorpd  %xmm5,%xmm5
movsd  (%rsp),%xmm4
test   $0x1,%bl
jne    1244 <main+0x114>
jmp    1264 <main+0x134>
xorpd  %xmm5,%xmm5
movsd  (%rsp),%xmm4
jmp    1264 <main+0x134>
mov    %ebx,%eax
and    $0xfffffffe,%eax
mov    $0x1,%ecx
xorpd  %xmm5,%xmm5
movsd  0xe52(%rip),%xmm0
movsd  0xe52(%rip),%xmm1
movsd  (%rsp),%xmm4
movsd  0xe2d(%rip),%xmm6
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xorps  %xmm2,%xmm2
cvtsi2sd %ecx,%xmm2
addsd  %xmm0,%xmm2
mulsd  %xmm4,%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm6,%xmm2
movapd %xmm1,%xmm3
divsd  %xmm2,%xmm3
addsd  %xmm5,%xmm3
lea    0x1(%rcx),%edx
xorps  %xmm2,%xmm2
cvtsi2sd %edx,%xmm2
addsd  %xmm0,%xmm2
mulsd  %xmm4,%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm6,%xmm2
movapd %xmm1,%xmm5
divsd  %xmm2,%xmm5
addsd  %xmm3,%xmm5
add    $0x2,%ecx
cmp    %eax,%edx
jne    11e0 <main+0xb0>
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
addsd  0xdd1(%rip),%xmm0
test   $0x1,%bl
je     1264 <main+0x134>
mulsd  %xmm4,%xmm0
mulsd  %xmm0,%xmm0
addsd  0xdac(%rip),%xmm0
movsd  0xdbc(%rip),%xmm1
divsd  %xmm0,%xmm1
addsd  %xmm1,%xmm5
mulsd  %xmm4,%xmm5
movsd  %xmm5,0x10(%rsp)
xor    %eax,%eax
call   1040 <hpctimer_getwtime@plt>
subsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xd97(%rip),%xmm1
movsd  0x10(%rsp),%xmm0
addsd  %xmm0,%xmm1
andpd  0xd95(%rip),%xmm1
lea    0xd9e(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
lea    0xdbb(%rip),%rdi
movsd  0x18(%rsp),%xmm0
movsd  (%rsp),%xmm1
mov    $0x2,%al
call   1030 <printf@plt>
lea    0xdbc(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
mov    0x2d03(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [43 x i8] c"PI is approximately %.16f, Error is %.16f\0A\00"
@.str.1 = [26 x i8] c"(nsteps = %d, step = %f)\0A\00"
@.str.2 = [26 x i8] c"Elapsed time = %.6f sec.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0x400921FB54442D18, double* %6
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
br label %22
21: ; preds = %2
br label %22
22: ; preds = %21, %16
%23 = phi i32 [ %20, %16 ], [ 1000000, %21 ]
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = sitofp i32 %24 to double
%26 = fdiv double 1.000000e+00, %25
store double %26, double* %11
%27 = call double (...) @hpctimer_getwtime()
store double %27, double* %13
store double 0.000000e+00, double* %12
store i32 1, i32* %7
br label %28
28: ; preds = %44, %22
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = icmp sle i32 %29, %30
br i1 %31, label %32, label %47
32: ; preds = %28
%33 = load i32, i32* %7
%34 = sitofp i32 %33 to double
%35 = fsub double %34, 5.000000e-01
%36 = load double, double* %11
%37 = fmul double %35, %36
store double %37, double* %10
%38 = load double, double* %12
%39 = load double, double* %10
%40 = load double, double* %10
%41 = call double @llvm.fmuladd.f64(double %39, double %40, double 1.000000e+00)
%42 = fdiv double 4.000000e+00, %41
%43 = fadd double %38, %42
store double %43, double* %12
br label %44
44: ; preds = %32
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %28
47: ; preds = %28
%48 = load double, double* %11
%49 = load double, double* %12
%50 = fmul double %48, %49
store double %50, double* %9
%51 = call double (...) @hpctimer_getwtime()
%52 = load double, double* %13
%53 = fsub double %51, %52
store double %53, double* %13
%54 = load double, double* %9
%55 = load double, double* %9
%56 = load double, double* %6
%57 = fsub double %55, %56
%58 = call double @llvm.fabs.f64(double %57)
%59 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), double %54, double %58)
%60 = load i32, i32* %8
%61 = sitofp i32 %60 to double
%62 = load double, double* %11
%63 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), double %61, double %62)
%64 = load double, double* %13
%65 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), double %64)
%66 = load i32, i32* @EXIT_SUCCESS
ret i32 %66
}

LLVM IR (-O2):
@.str = [43 x i8] c"PI is approximately %.16f, Error is %.16f\0A\00"
@.str.1 = [26 x i8] c"(nsteps = %d, step = %f)\0A\00"
@.str.2 = [26 x i8] c"Elapsed time = %.6f sec.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
br label %8
8: ; preds = %2, %4
%9 = phi i32 [ %7, %4 ], [ 1000000, %2 ]
%10 = sitofp i32 %9 to double
%11 = fdiv double 1.000000e+00, %10
%12 = tail call double (...) @hpctimer_getwtime()
%13 = icmp slt i32 %9, 1
br i1 %13, label %52, label %14
14: ; preds = %8
%15 = and i32 %9, 1
%16 = icmp eq i32 %9, 1
br i1 %16, label %42, label %17
17: ; preds = %14
%18 = and i32 %9, -2
br label %19
19: ; preds = %19, %17
%20 = phi double [ 0.000000e+00, %17 ], [ %35, %19 ]
%21 = phi i32 [ 1, %17 ], [ %36, %19 ]
%22 = phi i32 [ 0, %17 ], [ %37, %19 ]
%23 = sitofp i32 %21 to double
%24 = fadd double %23, -5.000000e-01
%25 = fmul double %11, %24
%26 = tail call double @llvm.fmuladd.f64(double %25, double %25, double 1.000000e+00)
%27 = fdiv double 4.000000e+00, %26
%28 = fadd double %20, %27
%29 = add nuw i32 %21, 1
%30 = sitofp i32 %29 to double
%31 = fadd double %30, -5.000000e-01
%32 = fmul double %11, %31
%33 = tail call double @llvm.fmuladd.f64(double %32, double %32, double 1.000000e+00)
%34 = fdiv double 4.000000e+00, %33
%35 = fadd double %28, %34
%36 = add nuw i32 %21, 2
%37 = add i32 %22, 2
%38 = icmp eq i32 %37, %18
br i1 %38, label %39, label %19
39: ; preds = %19
%40 = sitofp i32 %36 to double
%41 = fadd double %40, -5.000000e-01
br label %42
42: ; preds = %39, %14
%43 = phi double [ undef, %14 ], [ %35, %39 ]
%44 = phi double [ 0.000000e+00, %14 ], [ %35, %39 ]
%45 = phi double [ 5.000000e-01, %14 ], [ %41, %39 ]
%46 = icmp eq i32 %15, 0
br i1 %46, label %52, label %47
47: ; preds = %42
%48 = fmul double %11, %45
%49 = tail call double @llvm.fmuladd.f64(double %48, double %48, double 1.000000e+00)
%50 = fdiv double 4.000000e+00, %49
%51 = fadd double %44, %50
br label %52
52: ; preds = %47, %42, %8
%53 = phi double [ 0.000000e+00, %8 ], [ %43, %42 ], [ %51, %47 ]
%54 = fmul double %11, %53
%55 = tail call double (...) @hpctimer_getwtime()
%56 = fsub double %55, %12
%57 = fadd double %54, 0xC00921FB54442D18
%58 = tail call double @llvm.fabs.f64(double %57)
%59 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), double %54, double %58)
%60 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), double %10, double %11)
%61 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), double %56)
%62 = load i32, i32* @EXIT_SUCCESS
ret i32 %62
}