#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 omp_get_num_procs();
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  int i, num_steps;
  double x, sum, step, pi;
  double t_start, t_end;
  num_steps = 500000000;
  x = 0;
  sum = 0.0;
  step = 1.0 / (double)num_steps;
  t_start = omp_get_wtime();
#pragma omp parallel for reduction(+:sum) default(none) private(i,x) firstprivate(step, num_steps)
  for (i = 0; i < num_steps; i++) {
    x = (i + 0.5) * step;
    sum = sum + 4.0 / (1.0 + x * x);
  }
  pi = step * sum;
  t_end = omp_get_wtime();
  printf("Value of pi = %g\n", pi);
  printf("Expended wall clock time = %.20f\n", t_end - t_start);
  printf("num proc = %d\n", omp_get_num_procs());
  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)
movl   $0x1dcd6500,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm1
movsd  0xe96(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11ef <main+0xbf>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xe71(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm2
movsd  0xe38(%rip),%xmm1
addsd  %xmm1,%xmm2
movsd  0xe34(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1186 <main+0x56>
movsd  -0x30(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x48(%rbp)
cvttsd2si -0x38(%rbp),%esi
lea    0xe02(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x48(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
cvttsd2si %xmm0,%esi
lea    0xdfa(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <omp_get_num_procs@plt>
mov    %eax,%esi
lea    0xe07(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
mov    $0x1,%eax
movsd  0xeae(%rip),%xmm1
movsd  0xeae(%rip),%xmm2
movsd  0xeae(%rip),%xmm3
movsd  0xeae(%rip),%xmm5
movsd  0xead(%rip),%xmm8
xorpd  %xmm4,%xmm4
nopw   0x0(%rax,%rax,1)
movapd %xmm0,%xmm6
addsd  %xmm1,%xmm6
mulsd  %xmm2,%xmm6
mulsd  %xmm6,%xmm6
addsd  %xmm3,%xmm6
movapd %xmm5,%xmm7
divsd  %xmm6,%xmm7
addsd  %xmm4,%xmm7
xorps  %xmm6,%xmm6
cvtsi2sd %eax,%xmm6
addsd  %xmm1,%xmm6
mulsd  %xmm2,%xmm6
mulsd  %xmm6,%xmm6
addsd  %xmm3,%xmm6
movapd %xmm5,%xmm4
divsd  %xmm6,%xmm4
addsd  %xmm7,%xmm4
addsd  %xmm8,%xmm0
add    $0x2,%eax
cmp    $0x1dcd6501,%eax
jne    1180 <main+0x50>
mulsd  0xe2e(%rip),%xmm4
movsd  %xmm4,(%rsp)
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
cvttsd2si (%rsp),%esi
lea    0xe30(%rip),%rdi
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%esi
lea    0xe26(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <omp_get_num_procs@plt>
lea    0xe35(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Value of pi = %g\0A\00"
@.str.1 = [34 x i8] c"Expended wall clock time = %.20f\0A\00"
@.str.2 = [15 x i8] c"num proc = %d\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 i32
%7 = alloca i32
%8 = alloca double
%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 i32 500000000, i32* %7
store double 0.000000e+00, double* %8
store double 0.000000e+00, double* %9
%14 = load i32, i32* %7
%15 = sitofp i32 %14 to double
%16 = fdiv double 1.000000e+00, %15
store double %16, double* %10
%17 = call double (...) @omp_get_wtime()
store double %17, double* %12
store i32 0, i32* %6
br label %18
18: ; preds = %34, %2
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %37
22: ; preds = %18
%23 = load i32, i32* %6
%24 = sitofp i32 %23 to double
%25 = fadd double %24, 5.000000e-01
%26 = load double, double* %10
%27 = fmul double %25, %26
store double %27, double* %8
%28 = load double, double* %9
%29 = load double, double* %8
%30 = load double, double* %8
%31 = call double @llvm.fmuladd.f64(double %29, double %30, double 1.000000e+00)
%32 = fdiv double 4.000000e+00, %31
%33 = fadd double %28, %32
store double %33, double* %9
br label %34
34: ; preds = %22
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %18
37: ; preds = %18
%38 = load double, double* %10
%39 = load double, double* %9
%40 = fmul double %38, %39
store double %40, double* %11
%41 = call double (...) @omp_get_wtime()
store double %41, double* %13
%42 = load double, double* %11
%43 = fptosi double %42 to i32
%44 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %43)
%45 = load double, double* %13
%46 = load double, double* %12
%47 = fsub double %45, %46
%48 = fptosi double %47 to i32
%49 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%50 = call i32 (...) @omp_get_num_procs()
%51 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %50)
%52 = load i32, i32* @EXIT_SUCCESS
ret i32 %52
}

LLVM IR (-O2):
@.str = [18 x i8] c"Value of pi = %g\0A\00"
@.str.1 = [34 x i8] c"Expended wall clock time = %.20f\0A\00"
@.str.2 = [15 x i8] c"num proc = %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call double (...) @omp_get_wtime()
br label %4
4: ; preds = %4, %2
%5 = phi i32 [ 0, %2 ], [ %20, %4 ]
%6 = phi double [ 0.000000e+00, %2 ], [ %19, %4 ]
%7 = sitofp i32 %5 to double
%8 = fadd double %7, 5.000000e-01
%9 = fmul double %8, 2.000000e-09
%10 = tail call double @llvm.fmuladd.f64(double %9, double %9, double 1.000000e+00)
%11 = fdiv double 4.000000e+00, %10
%12 = fadd double %6, %11
%13 = or i32 %5, 1
%14 = sitofp i32 %13 to double
%15 = fadd double %14, 5.000000e-01
%16 = fmul double %15, 2.000000e-09
%17 = tail call double @llvm.fmuladd.f64(double %16, double %16, double 1.000000e+00)
%18 = fdiv double 4.000000e+00, %17
%19 = fadd double %12, %18
%20 = add nuw nsw i32 %5, 2
%21 = icmp eq i32 %20, 500000000
br i1 %21, label %22, label %4
22: ; preds = %4
%23 = fmul double %19, 2.000000e-09
%24 = tail call double (...) @omp_get_wtime()
%25 = fptosi double %23 to i32
%26 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = fsub double %24, %3
%28 = fptosi double %27 to i32
%29 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = tail call i32 (...) @omp_get_num_procs()
%31 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = load i32, i32* @EXIT_SUCCESS
ret i32 %32
}