#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 */
long atol(char *);
int omp_get_max_threads();
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, double, double);
int main(int argc, char **argv) {
  long i, num_steps = 1000000000;
  double step, x, sum, pi, taken;
  double start, stop;
  int num_threads = omp_get_max_threads();
  if (argc > 1) {
    num_steps = atol(argv[1]);
  }
  printf("Calculating PI using:\n"
         "  %ld slices\n"
         "  %d thread(s)\n",
         num_steps, num_threads);
  start = omp_get_wtime();
  sum = 0.0;
  step = 1.0 / num_steps;
#pragma omp parallel for private(x) reduction(+ : sum)
  for (i = 0; i < num_steps; i++) {
    x = (i + 0.5) * step;
    sum += 4.0 / (1.0 + x * x);
  }
  pi = sum * step;
  stop = omp_get_wtime();
  taken = ((double)(stop - start));
  printf("Obtained value for PI: %.16g\n"
         "Time taken:            %.16g seconds\n",
         pi, taken);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x3b9aca00,-0x20(%rbp)
3b
mov    $0x0,%al
call   1050 <omp_get_max_threads@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1183 <main+0x43>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atol@plt>
mov    %rax,-0x20(%rbp)
cvtsi2sdq -0x20(%rbp),%xmm0
cvtsi2sdl -0x5c(%rbp),%xmm1
lea    0xe83(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdq -0x20(%rbp),%xmm1
movsd  0xe44(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    1238 <main+0xf8>
cvtsi2sdq -0x18(%rbp),%xmm0
movsd  0xe27(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xdf3(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xdef(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11cd <main+0x8d>
movsd  -0x38(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
subsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
lea    0xdd8(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
xor    %eax,%eax
call   1050 <omp_get_max_threads@plt>
mov    %eax,%ebp
mov    $0x3b9aca00,%r15d
cmp    $0x2,%ebx
jl     116f <main+0x2f>
mov    0x8(%r14),%rdi
call   1060 <atol@plt>
mov    %rax,%r15
cvtsi2sd %r15,%xmm0
movsd  %xmm0,0x8(%rsp)
cvtsi2sd %ebp,%xmm1
lea    0xe93(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  0xe67(%rip),%xmm1
movapd %xmm1,%xmm6
divsd  0x8(%rsp),%xmm6
test   %r15,%r15
movsd  %xmm0,0x10(%rsp)
jle    11cf <main+0x8f>
cmp    $0x1,%r15
jne    11d8 <main+0x98>
xorpd  %xmm0,%xmm0
movsd  0xe48(%rip),%xmm1
test   $0x1,%r15b
jne    126b <main+0x12b>
jmp    128b <main+0x14b>
xorpd  %xmm0,%xmm0
jmp    128b <main+0x14b>
mov    %r15,%rax
and    $0xfffffffffffffffe,%rax
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
movsd  0xe1b(%rip),%xmm2
movsd  0xe1b(%rip),%xmm3
cs nopw 0x0(%rax,%rax,1)
nop
xorps  %xmm4,%xmm4
cvtsi2sd %rcx,%xmm4
addsd  %xmm2,%xmm4
mulsd  %xmm6,%xmm4
mulsd  %xmm4,%xmm4
addsd  %xmm1,%xmm4
movapd %xmm3,%xmm5
divsd  %xmm4,%xmm5
addsd  %xmm0,%xmm5
lea    0x1(%rcx),%rdx
xorps  %xmm4,%xmm4
cvtsi2sd %rdx,%xmm4
addsd  %xmm2,%xmm4
mulsd  %xmm6,%xmm4
mulsd  %xmm4,%xmm4
addsd  %xmm1,%xmm4
movapd %xmm3,%xmm0
divsd  %xmm4,%xmm0
addsd  %xmm5,%xmm0
add    $0x2,%rcx
cmp    %rax,%rcx
jne    1200 <main+0xc0>
xorps  %xmm1,%xmm1
cvtsi2sd %rcx,%xmm1
addsd  0xda3(%rip),%xmm1
test   $0x1,%r15b
je     128b <main+0x14b>
mulsd  %xmm6,%xmm1
mulsd  %xmm1,%xmm1
addsd  0xd85(%rip),%xmm1
movsd  0xd8d(%rip),%xmm2
divsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
mulsd  %xmm0,%xmm6
movsd  %xmm6,0x8(%rsp)
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movapd %xmm0,%xmm1
subsd  0x10(%rsp),%xmm1
lea    0xd9e(%rip),%rdi
movsd  0x8(%rsp),%xmm0
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"Calculating PI using:\0A %ld slices\0A %d thread(s)\0A\00"
@.str.1 = [67 x i8] c"Obtained value for PI: %.16g\0ATime taken: %.16g seconds\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 double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 1000000000, i64* %7
%16 = call i32 (...) @omp_get_max_threads()
store i32 %16, i32* %15
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 1
br i1 %18, label %19, label %24
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @atol(i8* %22)
store i64 %23, i64* %7
br label %24
24: ; preds = %19, %2
%25 = load i64, i64* %7
%26 = sitofp i64 %25 to double
%27 = load i32, i32* %15
%28 = sitofp i32 %27 to double
%29 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), double %26, double %28)
%30 = call double (...) @omp_get_wtime()
store double %30, double* %13
store double 0.000000e+00, double* %10
%31 = load i64, i64* %7
%32 = sitofp i64 %31 to double
%33 = fdiv double 1.000000e+00, %32
store double %33, double* %8
store i64 0, i64* %6
br label %34
34: ; preds = %50, %24
%35 = load i64, i64* %6
%36 = load i64, i64* %7
%37 = icmp slt i64 %35, %36
br i1 %37, label %38, label %53
38: ; preds = %34
%39 = load i64, i64* %6
%40 = sitofp i64 %39 to double
%41 = fadd double %40, 5.000000e-01
%42 = load double, double* %8
%43 = fmul double %41, %42
store double %43, double* %9
%44 = load double, double* %9
%45 = load double, double* %9
%46 = call double @llvm.fmuladd.f64(double %44, double %45, double 1.000000e+00)
%47 = fdiv double 4.000000e+00, %46
%48 = load double, double* %10
%49 = fadd double %48, %47
store double %49, double* %10
br label %50
50: ; preds = %38
%51 = load i64, i64* %6
%52 = add nsw i64 %51, 1
store i64 %52, i64* %6
br label %34
53: ; preds = %34
%54 = load double, double* %10
%55 = load double, double* %8
%56 = fmul double %54, %55
store double %56, double* %11
%57 = call double (...) @omp_get_wtime()
store double %57, double* %14
%58 = load double, double* %14
%59 = load double, double* %13
%60 = fsub double %58, %59
store double %60, double* %12
%61 = load double, double* %11
%62 = load double, double* %12
%63 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), double %61, double %62)
ret i32 0
}

LLVM IR (-O2):
@.str = [51 x i8] c"Calculating PI using:\0A %ld slices\0A %d thread(s)\0A\00"
@.str.1 = [67 x i8] c"Obtained value for PI: %.16g\0ATime taken: %.16g seconds\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @omp_get_max_threads()
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i64 @atol(i8* %7)
br label %9
9: ; preds = %5, %2
%10 = phi i64 [ %8, %5 ], [ 1000000000, %2 ]
%11 = sitofp i64 %10 to double
%12 = sitofp i32 %3 to double
%13 = tail call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), double %11, double %12)
%14 = tail call double (...) @omp_get_wtime()
%15 = fdiv double 1.000000e+00, %11
%16 = icmp sgt i64 %10, 0
br i1 %16, label %17, label %55
17: ; preds = %9
%18 = and i64 %10, 1
%19 = icmp eq i64 %10, 1
br i1 %19, label %45, label %20
20: ; preds = %17
%21 = and i64 %10, -2
br label %22
22: ; preds = %22, %20
%23 = phi i64 [ 0, %20 ], [ %39, %22 ]
%24 = phi double [ 0.000000e+00, %20 ], [ %38, %22 ]
%25 = phi i64 [ 0, %20 ], [ %40, %22 ]
%26 = sitofp i64 %23 to double
%27 = fadd double %26, 5.000000e-01
%28 = fmul double %15, %27
%29 = tail call double @llvm.fmuladd.f64(double %28, double %28, double 1.000000e+00)
%30 = fdiv double 4.000000e+00, %29
%31 = fadd double %24, %30
%32 = or i64 %23, 1
%33 = sitofp i64 %32 to double
%34 = fadd double %33, 5.000000e-01
%35 = fmul double %15, %34
%36 = tail call double @llvm.fmuladd.f64(double %35, double %35, double 1.000000e+00)
%37 = fdiv double 4.000000e+00, %36
%38 = fadd double %31, %37
%39 = add nuw nsw i64 %23, 2
%40 = add i64 %25, 2
%41 = icmp eq i64 %40, %21
br i1 %41, label %42, label %22
42: ; preds = %22
%43 = sitofp i64 %39 to double
%44 = fadd double %43, 5.000000e-01
br label %45
45: ; preds = %42, %17
%46 = phi double [ undef, %17 ], [ %38, %42 ]
%47 = phi double [ 5.000000e-01, %17 ], [ %44, %42 ]
%48 = phi double [ 0.000000e+00, %17 ], [ %38, %42 ]
%49 = icmp eq i64 %18, 0
br i1 %49, label %55, label %50
50: ; preds = %45
%51 = fmul double %15, %47
%52 = tail call double @llvm.fmuladd.f64(double %51, double %51, double 1.000000e+00)
%53 = fdiv double 4.000000e+00, %52
%54 = fadd double %48, %53
br label %55
55: ; preds = %50, %45, %9
%56 = phi double [ 0.000000e+00, %9 ], [ %46, %45 ], [ %54, %50 ]
%57 = fmul double %15, %56
%58 = tail call double (...) @omp_get_wtime()
%59 = fsub double %58, %14
%60 = tail call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), double %57, double %59)
ret i32 0
}