#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;
double RAND_MAX;
unsigned int omp_get_thread_num();
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, double);
scalar_t__ rand_r(unsigned int *);
int main(int argc, char *argv[]) {
  unsigned long long int i, num_points, count;
  double x, y, pi;
  double t_start, t_end;
  unsigned int seed;
  num_points = 300000000;
  count = 0;
  t_start = omp_get_wtime();
#pragma omp parallel default(none) private(x, y, seed) shared(count, num_points)
  {
    seed = omp_get_thread_num();
#pragma omp for reduction(+ : count)
    for (i = 0; i < num_points; i++) {
      x = (double)rand_r(&seed) / RAND_MAX;
      y = (double)rand_r(&seed) / RAND_MAX;
      if (x * x + y * y <= 1) {
        count++;
      }
    }
  }
  pi = 4.0 * count / num_points;
  t_end = omp_get_wtime();
  printf("Value of pi = %g\n", pi);
  printf("Expended wall clock time = %.5f\n", t_end - t_start);
  return EXIT_SUCCESS;
}


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   $0x11e1a300,-0x20(%rbp)
11
movq   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x48(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x54(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    121e <main+0xde>
lea    -0x54(%rbp),%rdi
call   1050 <rand_r@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e41(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
lea    -0x54(%rbp),%rdi
call   1050 <rand_r@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e23(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe36(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     1208 <main+0xc8>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    120d <main+0xcd>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1184 <main+0x44>
movq   -0x28(%rbp),%xmm0
movaps 0xdd6(%rip),%xmm3
punpckldq %xmm3,%xmm0
movapd 0xdda(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdd3(%rip),%xmm1
mulsd  %xmm1,%xmm0
movq   -0x20(%rbp),%xmm1
punpckldq %xmm3,%xmm1
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
lea    0xda6(%rip),%rdi
call   1060 <printf@plt>
movsd  -0x50(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
lea    0xda2(%rip),%rdi
call   1060 <printf@plt>
mov    0x2d2c(%rip),%rax
mov    (%rax),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,0x30(%rsp)
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,0xc(%rsp)
mov    $0x11e1a300,%ebx
lea    0xc(%rsp),%r14
mov    0x2e71(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <rand_r@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r12),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %r14,%rdi
call   1050 <rand_r@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r12),%xmm0
mulsd  %xmm0,%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe34(%rip),%xmm0
ucomisd %xmm1,%xmm0
sbb    $0xffffffffffffffff,%r15
add    $0xffffffffffffffff,%rbx
jne    1180 <main+0x40>
movq   %r15,%xmm0
punpckldq 0xe39(%rip),%xmm0
subpd  0xe41(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
mulsd  0xe05(%rip),%xmm1
divsd  0xe05(%rip),%xmm1
movapd %xmm1,0x10(%rsp)
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,0x28(%rsp)
lea    0xe1b(%rip),%rdi
movaps 0x10(%rsp),%xmm0
call   1060 <printf@plt>
movsd  0x28(%rsp),%xmm0
subsd  0x30(%rsp),%xmm0
lea    0xe10(%rip),%rdi
call   1060 <printf@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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