#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 */
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
int EXIT_SUCCESS;
double RAND_MAX;
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, double);
scalar_t__ rand();
int /*<<< orphan*/ srand(unsigned int);
int main(int argc, char *argv[]) {
  unsigned long long int i, num_points, count;
  double x, y, pi;
  clock_t t_start, t_end;
  num_points = 300000000;
  count = 0;
  t_start = clock();
  srand((unsigned)t_start);
  for (i = 0; i < num_points; i++) {
    x = (double)rand() / RAND_MAX;
    y = (double)rand() / RAND_MAX;
    if (x * x + y * y <= 1)
      count++;
  }
  pi = 4.0 * count / num_points;
  t_end = clock();
  printf("Value of pi = %g\n", pi);
  printf("Expended wall clock time = %.5f\n",
         (double)(t_end - t_start) / CLOCKS_PER_SEC);
  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)
movq   $0x11e1a300,-0x20(%rbp)
11
movq   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %eax,%edi
call   1050 <srand@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    121a <main+0xda>
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e3b(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e1f(%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  0xe3a(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     1204 <main+0xc4>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1209 <main+0xc9>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1184 <main+0x44>
movq   -0x28(%rbp),%xmm0
movaps 0xdda(%rip),%xmm3
punpckldq %xmm3,%xmm0
movapd 0xdde(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdd7(%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   1030 <clock@plt>
mov    %rax,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
lea    0xdab(%rip),%rdi
call   1040 <printf@plt>
mov    -0x50(%rbp),%rax
sub    -0x48(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d4a(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd99(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d1b(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r14
mov    %r14d,%edi
call   1050 <srand@plt>
mov    $0x11e1a300,%r12d
mov    0x2e76(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r15),%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r15),%xmm0
mulsd  %xmm0,%xmm0
movsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe4a(%rip),%xmm0
ucomisd %xmm1,%xmm0
sbb    $0xffffffffffffffff,%rbx
add    $0xffffffffffffffff,%r12
jne    1170 <main+0x30>
movq   %rbx,%xmm0
punpckldq 0xe4f(%rip),%xmm0
subpd  0xe57(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
mulsd  0xe1b(%rip),%xmm1
divsd  0xe1b(%rip),%xmm1
movapd %xmm1,(%rsp)
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
lea    0xe35(%rip),%rdi
movaps (%rsp),%xmm0
call   1040 <printf@plt>
sub    %r14,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
mov    0x2dc2(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe21(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
add    $0x18,%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"
@CLOCKS_PER_SEC = global double 0.000000e+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 i64
%13 = alloca i64
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
%14 = call i64 (...) @clock()
store i64 %14, i64* %12
%15 = load i64, i64* %12
%16 = trunc i64 %15 to i32
%17 = call i32 @srand(i32 %16)
store i64 0, i64* %6
br label %18
18: ; preds = %42, %2
%19 = load i64, i64* %6
%20 = load i64, i64* %7
%21 = icmp ult i64 %19, %20
br i1 %21, label %22, label %45
22: ; preds = %18
%23 = call i64 (...) @rand()
%24 = sitofp i64 %23 to double
%25 = load double, double* @RAND_MAX
%26 = fdiv double %24, %25
store double %26, double* %9
%27 = call i64 (...) @rand()
%28 = sitofp i64 %27 to double
%29 = load double, double* @RAND_MAX
%30 = fdiv double %28, %29
store double %30, double* %10
%31 = load double, double* %9
%32 = load double, double* %9
%33 = load double, double* %10
%34 = load double, double* %10
%35 = fmul double %33, %34
%36 = call double @llvm.fmuladd.f64(double %31, double %32, double %35)
%37 = fcmp ole double %36, 1.000000e+00
br i1 %37, label %38, label %41
38: ; preds = %22
%39 = load i64, i64* %8
%40 = add i64 %39, 1
store i64 %40, i64* %8
br label %41
41: ; preds = %38, %22
br label %42
42: ; preds = %41
%43 = load i64, i64* %6
%44 = add i64 %43, 1
store i64 %44, i64* %6
br label %18
45: ; preds = %18
%46 = load i64, i64* %8
%47 = uitofp i64 %46 to double
%48 = fmul double 4.000000e+00, %47
%49 = load i64, i64* %7
%50 = uitofp i64 %49 to double
%51 = fdiv double %48, %50
store double %51, double* %11
%52 = call i64 (...) @clock()
store i64 %52, i64* %13
%53 = load double, double* %11
%54 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double %53)
%55 = load i64, i64* %13
%56 = load i64, i64* %12
%57 = sub nsw i64 %55, %56
%58 = sitofp i64 %57 to double
%59 = load double, double* @CLOCKS_PER_SEC
%60 = fdiv double %58, %59
%61 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), double %60)
%62 = load i32, i32* @EXIT_SUCCESS
ret i32 %62
}

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"
@CLOCKS_PER_SEC = global double 0.000000e+00
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @clock()
%4 = trunc i64 %3 to i32
%5 = tail call i32 @srand(i32 %4)
br label %6
6: ; preds = %2, %6
%7 = phi i64 [ 0, %2 ], [ %22, %6 ]
%8 = phi i64 [ 0, %2 ], [ %21, %6 ]
%9 = tail call i64 (...) @rand()
%10 = sitofp i64 %9 to double
%11 = load double, double* @RAND_MAX
%12 = fdiv double %10, %11
%13 = tail call i64 (...) @rand()
%14 = sitofp i64 %13 to double
%15 = load double, double* @RAND_MAX
%16 = fdiv double %14, %15
%17 = fmul double %16, %16
%18 = tail call double @llvm.fmuladd.f64(double %12, double %12, double %17)
%19 = fcmp ole double %18, 1.000000e+00
%20 = zext i1 %19 to i64
%21 = add i64 %8, %20
%22 = add nuw nsw i64 %7, 1
%23 = icmp eq i64 %22, 300000000
br i1 %23, label %24, label %6
24: ; preds = %6
%25 = uitofp i64 %21 to double
%26 = fmul double %25, 4.000000e+00
%27 = fdiv double %26, 3.000000e+08
%28 = tail call i64 (...) @clock()
%29 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double %27)
%30 = sub nsw i64 %28, %3
%31 = sitofp i64 %30 to double
%32 = load double, double* @CLOCKS_PER_SEC
%33 = fdiv double %31, %32
%34 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), double %33)
%35 = load i32, i32* @EXIT_SUCCESS
ret i32 %35
}