#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 generate();
double pi(long count) {
  long inside = 0;
  long outside = 0;
  double x, y;
  for (long i = 0; i < count; i++) {
    x = generate();
    y = generate();
    if (x * x + y * y <= 1)
      inside++;
    else
      outside++;
  }
  return (4.0 * inside) / (inside + outside);
}


x86 assembly (clang, -O0):
<pi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    11bb <pi+0xab>
mov    $0x0,%al
call   1030 <generate@plt>
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1030 <generate@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe8a(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     1199 <pi+0x89>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11a5 <pi+0x95>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11aa <pi+0x9a>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1134 <pi+0x24>
cvtsi2sdq -0x10(%rbp),%xmm1
movsd  0xe37(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pi>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
jle    1176 <pi+0x66>
mov    %rdi,%rbx
xor    %r15d,%r15d
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <generate@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <generate@plt>
mulsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xea2(%rip),%xmm0
ucomisd %xmm1,%xmm0
adc    $0x0,%r14
ucomisd %xmm1,%xmm0
sbb    $0xffffffffffffffff,%r15
add    $0xffffffffffffffff,%rbx
jne    1130 <pi+0x20>
jmp    117c <pi+0x6c>
xor    %r14d,%r14d
xor    %r15d,%r15d
xorps  %xmm0,%xmm0
cvtsi2sd %r15,%xmm0
mulsd  0xe7c(%rip),%xmm0
add    %r15,%r14
xorps  %xmm1,%xmm1
cvtsi2sd %r14,%xmm1
divsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define double @pi(i64 %0) {
%2 = icmp sgt i64 %0, 0
br i1 %2, label %11, label %3
3: ; preds = %11, %1
%4 = phi i64 [ 0, %1 ], [ %21, %11 ]
%5 = phi i64 [ 0, %1 ], [ %24, %11 ]
%6 = sitofp i64 %5 to double
%7 = fmul double %6, 4.000000e+00
%8 = add nuw nsw i64 %5, %4
%9 = sitofp i64 %8 to double
%10 = fdiv double %7, %9
ret double %10
11: ; preds = %1, %11
%12 = phi i64 [ %25, %11 ], [ 0, %1 ]
%13 = phi i64 [ %24, %11 ], [ 0, %1 ]
%14 = phi i64 [ %21, %11 ], [ 0, %1 ]
%15 = tail call double (...) @generate()
%16 = tail call double (...) @generate()
%17 = fmul double %16, %16
%18 = tail call double @llvm.fmuladd.f64(double %15, double %15, double %17)
%19 = fcmp ugt double %18, 1.000000e+00
%20 = zext i1 %19 to i64
%21 = add nuw nsw i64 %14, %20
%22 = xor i1 %19, true
%23 = zext i1 %22 to i64
%24 = add nuw nsw i64 %13, %23
%25 = add nuw nsw i64 %12, 1
%26 = icmp eq i64 %25, %0
br i1 %26, label %3, label %11
}