#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;
  int nthreads = 1;
  nsteps = (argc > 1) ? atoi(argv[1]) : 1000000;
  step = 1.0 / (double)nsteps;
  t = hpctimer_getwtime();
  sum = 0.0;
#pragma omp parallel shared(sum)
  {
#pragma omp master
#pragma omp for private(x)
    for (i = 1; i <= nsteps; i++) {
      x = (i - 0.5) * step;
#pragma omp critical
      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, nthreads = %d)\n", nsteps, step, nthreads);
  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)
movl   $0x1,-0x4c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1179 <main+0x49>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x50(%rbp)
jmp    1186 <main+0x56>
mov    $0xf4240,%eax
mov    %eax,-0x50(%rbp)
jmp    1186 <main+0x56>
mov    -0x50(%rbp),%eax
mov    %eax,-0x20(%rbp)
cvtsi2sdl -0x20(%rbp),%xmm1
movsd  0xe6f(%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     1226 <main+0xf6>
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  0xe42(%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  0xe09(%rip),%xmm1
addsd  %xmm1,%xmm2
movsd  0xe05(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11bd <main+0x8d>
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 0xdc4(%rip),%xmm2
pand   %xmm2,%xmm1
lea    0xdc9(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
cvtsi2sdl -0x20(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
mov    -0x4c(%rbp),%esi
lea    0xdd9(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  -0x48(%rbp),%xmm0
lea    0xdef(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    0x2d3d(%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>
xorpd  %xmm5,%xmm5
movsd  0xe81(%rip),%xmm0
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
xorpd  %xmm5,%xmm5
mov    $0x1,%ecx
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    $0x1,%esi
mov    $0x2,%al
call   1030 <printf@plt>
lea    0xdc6(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
mov    0x2cfe(%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 = [41 x i8] c"(nsteps = %d, step = %f, nthreads = %d)\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
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0x400921FB54442D18, double* %6
store i32 1, i32* %14
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
br label %23
22: ; preds = %2
br label %23
23: ; preds = %22, %17
%24 = phi i32 [ %21, %17 ], [ 1000000, %22 ]
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = sitofp i32 %25 to double
%27 = fdiv double 1.000000e+00, %26
store double %27, double* %11
%28 = call double (...) @hpctimer_getwtime()
store double %28, double* %13
store double 0.000000e+00, double* %12
store i32 1, i32* %7
br label %29
29: ; preds = %45, %23
%30 = load i32, i32* %7
%31 = load i32, i32* %8
%32 = icmp sle i32 %30, %31
br i1 %32, label %33, label %48
33: ; preds = %29
%34 = load i32, i32* %7
%35 = sitofp i32 %34 to double
%36 = fsub double %35, 5.000000e-01
%37 = load double, double* %11
%38 = fmul double %36, %37
store double %38, double* %10
%39 = load double, double* %12
%40 = load double, double* %10
%41 = load double, double* %10
%42 = call double @llvm.fmuladd.f64(double %40, double %41, double 1.000000e+00)
%43 = fdiv double 4.000000e+00, %42
%44 = fadd double %39, %43
store double %44, double* %12
br label %45
45: ; preds = %33
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %29
48: ; preds = %29
%49 = load double, double* %11
%50 = load double, double* %12
%51 = fmul double %49, %50
store double %51, double* %9
%52 = call double (...) @hpctimer_getwtime()
%53 = load double, double* %13
%54 = fsub double %52, %53
store double %54, double* %13
%55 = load double, double* %9
%56 = load double, double* %9
%57 = load double, double* %6
%58 = fsub double %56, %57
%59 = call double @llvm.fabs.f64(double %58)
%60 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), double %55, double %59)
%61 = load i32, i32* %8
%62 = sitofp i32 %61 to double
%63 = load double, double* %11
%64 = load i32, i32* %14
%65 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), double %62, double %63, i32 %64)
%66 = load double, double* %13
%67 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), double %66)
%68 = load i32, i32* @EXIT_SUCCESS
ret i32 %68
}

LLVM IR (-O2):
@.str = [43 x i8] c"PI is approximately %.16f, Error is %.16f\0A\00"
@.str.1 = [41 x i8] c"(nsteps = %d, step = %f, nthreads = %d)\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 i32 [ 1, %17 ], [ %36, %19 ]
%21 = phi double [ 0.000000e+00, %17 ], [ %35, %19 ]
%22 = phi i32 [ 0, %17 ], [ %37, %19 ]
%23 = sitofp i32 %20 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 %21, %27
%29 = add nuw i32 %20, 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 %20, 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 [ 5.000000e-01, %14 ], [ %41, %39 ]
%45 = phi double [ 0.000000e+00, %14 ], [ %35, %39 ]
%46 = icmp eq i32 %15, 0
br i1 %46, label %52, label %47
47: ; preds = %42
%48 = fmul double %11, %44
%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 %45, %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 ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), double %10, double %11, i32 1)
%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
}