#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 */
double RAND_MAX;
scalar_t__ rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
double seqMonteCarloPi(int num_iterations) {
  int i, sum = 0;
  srand(time(NULL));
  for (i = 0; i < num_iterations * 6; i++) {
    double x = (double)rand() / RAND_MAX;
    double y = (double)rand() / RAND_MAX;
    if (x * x + y * y <= 1.)
      sum++;
  }
  return (double)(4 * sum) / (num_iterations * 6);
}


x86 assembly (clang, -O0):
<seqMonteCarloPi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
imul   $0x6,-0x4(%rbp),%ecx
cmp    %ecx,%eax
jge    11ea <seqMonteCarloPi+0xba>
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e6d(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e51(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe3c(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     11d7 <seqMonteCarloPi+0xa7>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11dc <seqMonteCarloPi+0xac>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1159 <seqMonteCarloPi+0x29>
mov    -0xc(%rbp),%eax
shl    $0x2,%eax
cvtsi2sd %eax,%xmm0
imul   $0x6,-0x4(%rbp),%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seqMonteCarloPi>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
lea    (%rbx,%rbx,1),%eax
lea    (%rax,%rax,2),%r14d
test   %ebx,%ebx
jle    11ce <seqMonteCarloPi+0x9e>
cmp    $0x2,%r14d
mov    $0x1,%ebx
cmovge %r14d,%ebx
mov    0x2e82(%rip),%r15
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r15),%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1050 <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    $0xffffffff,%ebp
add    $0xffffffff,%ebx
jne    1170 <seqMonteCarloPi+0x40>
shl    $0x2,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
jmp    11d2 <seqMonteCarloPi+0xa2>
xorpd  %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
divsd  %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
define double @seqMonteCarloPi(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca double
store i32 %0, i32* %2
store i32 0, i32* %4
%7 = call i32 @time(i32* null)
%8 = call i32 @srand(i32 %7)
store i32 0, i32* %3
br label %9
9: ; preds = %34, %1
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = mul nsw i32 %11, 6
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %37
14: ; preds = %9
%15 = call i64 (...) @rand()
%16 = sitofp i64 %15 to double
%17 = load double, double* @RAND_MAX
%18 = fdiv double %16, %17
store double %18, double* %5
%19 = call i64 (...) @rand()
%20 = sitofp i64 %19 to double
%21 = load double, double* @RAND_MAX
%22 = fdiv double %20, %21
store double %22, double* %6
%23 = load double, double* %5
%24 = load double, double* %5
%25 = load double, double* %6
%26 = load double, double* %6
%27 = fmul double %25, %26
%28 = call double @llvm.fmuladd.f64(double %23, double %24, double %27)
%29 = fcmp ole double %28, 1.000000e+00
br i1 %29, label %30, label %33
30: ; preds = %14
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %33
33: ; preds = %30, %14
br label %34
34: ; preds = %33
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %9
37: ; preds = %9
%38 = load i32, i32* %4
%39 = mul nsw i32 4, %38
%40 = sitofp i32 %39 to double
%41 = load i32, i32* %2
%42 = mul nsw i32 %41, 6
%43 = sitofp i32 %42 to double
%44 = fdiv double %40, %43
ret double %44
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define double @seqMonteCarloPi(i32 %0) {
%2 = tail call i32 @time(i32* null)
%3 = tail call i32 @srand(i32 %2)
%4 = mul i32 %0, 6
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %29
6: ; preds = %1
%7 = call i32 @llvm.smax.i32(i32 %4, i32 1)
br label %8
8: ; preds = %6, %8
%9 = phi i32 [ %24, %8 ], [ 0, %6 ]
%10 = phi i32 [ %23, %8 ], [ 0, %6 ]
%11 = tail call i64 (...) @rand()
%12 = sitofp i64 %11 to double
%13 = load double, double* @RAND_MAX
%14 = fdiv double %12, %13
%15 = tail call i64 (...) @rand()
%16 = sitofp i64 %15 to double
%17 = load double, double* @RAND_MAX
%18 = fdiv double %16, %17
%19 = fmul double %18, %18
%20 = tail call double @llvm.fmuladd.f64(double %14, double %14, double %19)
%21 = fcmp ole double %20, 1.000000e+00
%22 = zext i1 %21 to i32
%23 = add nuw nsw i32 %10, %22
%24 = add nuw nsw i32 %9, 1
%25 = icmp eq i32 %24, %7
br i1 %25, label %26, label %8
26: ; preds = %8
%27 = shl i32 %23, 2
%28 = sitofp i32 %27 to double
br label %29
29: ; preds = %26, %1
%30 = phi double [ 0.000000e+00, %1 ], [ %28, %26 ]
%31 = sitofp i32 %4 to double
%32 = fdiv double %30, %31
ret double %32
}