#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__ random();
double pi_monte_carlo(double point_count) {
  double x, y, circle_points = 0;
  int i;
  for (i = 0; i < point_count; ++i) {
    x = (double)random() / RAND_MAX;
    y = (double)random() / RAND_MAX;
    if (x * x + y * y <= 1)
      ++circle_points;
  }
  return ((circle_points / point_count) * 4);
}


x86 assembly (clang, -O0):
<pi_monte_carlo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11cb <pi_monte_carlo+0xbb>
mov    $0x0,%al
call   1030 <random@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e95(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e79(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe6c(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     11b8 <pi_monte_carlo+0xa8>
movsd  0xe5a(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11bd <pi_monte_carlo+0xad>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112c <pi_monte_carlo+0x1c>
movsd  -0x20(%rbp),%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  0xe23(%rip),%xmm1
mulsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pi_monte_carlo>:
push   %r14
push   %rbx
sub    $0x38,%rsp
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11cb <pi_monte_carlo+0xbb>
xorpd  %xmm2,%xmm2
mov    $0x1,%ebx
mov    0x2eb3(%rip),%r14
movsd  %xmm0,0x8(%rsp)
nopl   0x0(%rax,%rax,1)
movapd %xmm2,0x20(%rsp)
xor    %eax,%eax
call   1030 <random@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r14),%xmm0
movapd %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1030 <random@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r14),%xmm0
mulsd  %xmm0,%xmm0
movapd 0x10(%rsp),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
movsd  0xe72(%rip),%xmm1
cmpnlesd %xmm1,%xmm2
movapd %xmm2,%xmm0
movapd 0x20(%rsp),%xmm3
andpd  %xmm3,%xmm0
addsd  %xmm1,%xmm3
andnpd %xmm3,%xmm2
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
orpd   %xmm0,%xmm2
movsd  0x8(%rsp),%xmm0
add    $0x1,%ebx
ucomisd %xmm1,%xmm0
movapd %xmm2,%xmm1
ja     1140 <pi_monte_carlo+0x30>
divsd  %xmm0,%xmm1
mulsd  0xe31(%rip),%xmm1
movapd %xmm1,%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define double @pi_monte_carlo(double %0) {
%2 = fcmp ogt double %0, 0.000000e+00
br i1 %2, label %3, label %22
3: ; preds = %1, %3
%4 = phi i32 [ %19, %3 ], [ 0, %1 ]
%5 = phi double [ %18, %3 ], [ 0.000000e+00, %1 ]
%6 = tail call i64 (...) @random()
%7 = sitofp i64 %6 to double
%8 = load double, double* @RAND_MAX
%9 = fdiv double %7, %8
%10 = tail call i64 (...) @random()
%11 = sitofp i64 %10 to double
%12 = load double, double* @RAND_MAX
%13 = fdiv double %11, %12
%14 = fmul double %13, %13
%15 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %14)
%16 = fcmp ugt double %15, 1.000000e+00
%17 = fadd double %5, 1.000000e+00
%18 = select i1 %16, double %5, double %17
%19 = add nuw nsw i32 %4, 1
%20 = sitofp i32 %19 to double
%21 = fcmp olt double %20, %0
br i1 %21, label %3, label %22
22: ; preds = %3, %1
%23 = phi double [ 0.000000e+00, %1 ], [ %18, %3 ]
%24 = fdiv double %23, %0
%25 = fmul double %24, 4.000000e+00
ret double %25
}