#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 randomReal(int, int);
int /*<<< orphan*/ randomize();
double MonteCarloPI(void) {
  double x, y;
  int loop = 0;
  randomize();
  x = randomReal(-1, 1);
  y = randomReal(-1, 1);
  for (int i = 0; i < 10000; i++) {
    x = randomReal(-1, 1);
    y = randomReal(-1, 1);
    if (x * x + y * y < 1) {
      loop++;
    }
  }
  return ((double)loop / (double)10000) * 4;
}


x86 assembly (clang, -O0):
<MonteCarloPI>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1040 <randomize@plt>
mov    $0xffffffff,%edi
mov    $0x1,%esi
call   1030 <randomReal@plt>
movsd  %xmm0,-0x8(%rbp)
mov    $0xffffffff,%edi
mov    $0x1,%esi
call   1030 <randomReal@plt>
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x2710,-0x18(%rbp)
jge    11e4 <MonteCarloPI+0xc4>
mov    $0xffffffff,%edi
mov    $0x1,%esi
call   1030 <randomReal@plt>
movsd  %xmm0,-0x8(%rbp)
mov    $0xffffffff,%edi
mov    $0x1,%esi
call   1030 <randomReal@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe52(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d1 <MonteCarloPI+0xb1>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d6 <MonteCarloPI+0xb6>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1165 <MonteCarloPI+0x45>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xe17(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe03(%rip),%xmm1
mulsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MonteCarloPI>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <randomize@plt>
mov    $0xffffffff,%edi
mov    $0x1,%esi
call   1030 <randomReal@plt>
mov    $0xffffffff,%edi
mov    $0x1,%esi
call   1030 <randomReal@plt>
mov    $0x2710,%ebp
nop
mov    $0xffffffff,%edi
mov    $0x1,%esi
call   1030 <randomReal@plt>
movsd  %xmm0,(%rsp)
mov    $0xffffffff,%edi
mov    $0x1,%esi
call   1030 <randomReal@plt>
mulsd  %xmm0,%xmm0
movsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
xor    %eax,%eax
movsd  0xe72(%rip),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
add    %eax,%ebx
add    $0xffffffff,%ebp
jne    1150 <MonteCarloPI+0x30>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
divsd  0xe5d(%rip),%xmm0
mulsd  0xe5d(%rip),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @MonteCarloPI() {
%1 = alloca double
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %3
%5 = call i32 (...) @randomize()
%6 = call double @randomReal(i32 -1, i32 1)
store double %6, double* %1
%7 = call double @randomReal(i32 -1, i32 1)
store double %7, double* %2
store i32 0, i32* %4
br label %8
8: ; preds = %25, %0
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 10000
br i1 %10, label %11, label %28
11: ; preds = %8
%12 = call double @randomReal(i32 -1, i32 1)
store double %12, double* %1
%13 = call double @randomReal(i32 -1, i32 1)
store double %13, double* %2
%14 = load double, double* %1
%15 = load double, double* %1
%16 = load double, double* %2
%17 = load double, double* %2
%18 = fmul double %16, %17
%19 = call double @llvm.fmuladd.f64(double %14, double %15, double %18)
%20 = fcmp olt double %19, 1.000000e+00
br i1 %20, label %21, label %24
21: ; preds = %11
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %24
24: ; preds = %21, %11
br label %25
25: ; preds = %24
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %8
28: ; preds = %8
%29 = load i32, i32* %3
%30 = sitofp i32 %29 to double
%31 = fdiv double %30, 1.000000e+04
%32 = fmul double %31, 4.000000e+00
ret double %32
}

LLVM IR (-O2):
define double @MonteCarloPI() {
%1 = tail call i32 (...) @randomize()
%2 = tail call double @randomReal(i32 -1, i32 1)
%3 = tail call double @randomReal(i32 -1, i32 1)
br label %8
4: ; preds = %8
%5 = sitofp i32 %17 to double
%6 = fdiv double %5, 1.000000e+04
%7 = fmul double %6, 4.000000e+00
ret double %7
8: ; preds = %0, %8
%9 = phi i32 [ 0, %0 ], [ %18, %8 ]
%10 = phi i32 [ 0, %0 ], [ %17, %8 ]
%11 = tail call double @randomReal(i32 -1, i32 1)
%12 = tail call double @randomReal(i32 -1, i32 1)
%13 = fmul double %12, %12
%14 = tail call double @llvm.fmuladd.f64(double %11, double %11, double %13)
%15 = fcmp olt double %14, 1.000000e+00
%16 = zext i1 %15 to i32
%17 = add nuw nsw i32 %10, %16
%18 = add nuw nsw i32 %9, 1
%19 = icmp eq i32 %18, 10000
br i1 %19, label %4, label %8
}