#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 */
scalar_t__ isInCircle(double, double);
double random();
double monteCarloPi(int totalNumberOfPoints) {
  int numberOfPointsInCircle = 0;
  double xCoordinate;
  double yCoordinate;
  int i;
  for (i = 0; i < totalNumberOfPoints; i++) {
    xCoordinate = random();
    yCoordinate = random();
    if (isInCircle(xCoordinate, yCoordinate)) {
      numberOfPointsInCircle++;
    }
  }
  return 4.0 * (double)numberOfPointsInCircle / (double)totalNumberOfPoints;
}


x86 assembly (clang, -O0):
<monteCarloPi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1192 <monteCarloPi+0x72>
mov    $0x0,%al
call   1030 <random@plt>
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1040 <isInCircle@plt>
cmp    $0x0,%rax
je     117f <monteCarloPi+0x5f>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1184 <monteCarloPi+0x64>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1139 <monteCarloPi+0x19>
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  0xe61(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<monteCarloPi>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
test   %edi,%edi
jle    117f <monteCarloPi+0x5f>
mov    %r14d,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <random@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <random@plt>
movaps %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
call   1040 <isInCircle@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
add    $0xffffffff,%ebx
jne    1140 <monteCarloPi+0x20>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0xe83(%rip),%xmm0
jmp    1183 <monteCarloPi+0x63>
xorpd  %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
divsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define double @monteCarloPi(i32 %0) {
%2 = icmp sgt i32 %0, 0
br i1 %2, label %3, label %17
3: ; preds = %1, %3
%4 = phi i32 [ %12, %3 ], [ 0, %1 ]
%5 = phi i32 [ %11, %3 ], [ 0, %1 ]
%6 = tail call double (...) @random()
%7 = tail call double (...) @random()
%8 = tail call i64 @isInCircle(double %6, double %7)
%9 = icmp ne i64 %8, 0
%10 = zext i1 %9 to i32
%11 = add nuw nsw i32 %5, %10
%12 = add nuw nsw i32 %4, 1
%13 = icmp eq i32 %12, %0
br i1 %13, label %14, label %3
14: ; preds = %3
%15 = sitofp i32 %11 to double
%16 = fmul double %15, 4.000000e+00
br label %17
17: ; preds = %14, %1
%18 = phi double [ 0.000000e+00, %1 ], [ %16, %14 ]
%19 = sitofp i32 %0 to double
%20 = fdiv double %18, %19
ret double %20
}