#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__ RAND_MAX;
int /*<<< orphan*/ printf(char *, double);
double rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  srand(time(NULL));
  double x, y;
  unsigned long int belongs = 0, executed = 0;
  for (executed = 0; executed < 1000000000; executed++) {
    x = rand() / (double)RAND_MAX;
    y = rand() / (double)RAND_MAX;
    if (x * x + y * y <= 1) {
      belongs++;
    }
  }
  printf("%lf\n", (4.0 * belongs) / executed);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x3b9aca00,-0x28(%rbp)
3b
jae    120d <main+0xcd>
mov    $0x0,%al
call   1060 <rand@plt>
mov    0x2e55(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    0x2e39(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%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  0xe47(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     11f7 <main+0xb7>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11fc <main+0xbc>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1177 <main+0x37>
movq   -0x20(%rbp),%xmm0
movaps 0xde7(%rip),%xmm3
punpckldq %xmm3,%xmm0
movapd 0xdeb(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xde4(%rip),%xmm1
mulsd  %xmm1,%xmm0
movq   -0x28(%rbp),%xmm1
punpckldq %xmm3,%xmm1
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
lea    0xdcd(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x3b9aca00,%r15d
mov    0x2e84(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq (%r14),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq (%r14),%xmm1
divsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe4a(%rip),%xmm0
ucomisd %xmm1,%xmm0
sbb    $0xffffffffffffffff,%rbx
add    $0xffffffffffffffff,%r15
jne    1170 <main+0x30>
movq   %rbx,%xmm1
punpckldq 0xe4f(%rip),%xmm1
subpd  0xe57(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe1b(%rip),%xmm0
divsd  0xe1b(%rip),%xmm0
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
@.str = [5 x i8] c"%lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca i64
%5 = alloca i64
store i32 0, i32* %1
%6 = call i32 @time(i32* null)
%7 = call i32 @srand(i32 %6)
store i64 0, i64* %4
store i64 0, i64* %5
store i64 0, i64* %5
br label %8
8: ; preds = %31, %0
%9 = load i64, i64* %5
%10 = icmp ult i64 %9, 1000000000
br i1 %10, label %11, label %34
11: ; preds = %8
%12 = call double (...) @rand()
%13 = load i64, i64* @RAND_MAX
%14 = sitofp i64 %13 to double
%15 = fdiv double %12, %14
store double %15, double* %2
%16 = call double (...) @rand()
%17 = load i64, i64* @RAND_MAX
%18 = sitofp i64 %17 to double
%19 = fdiv double %16, %18
store double %19, double* %3
%20 = load double, double* %2
%21 = load double, double* %2
%22 = load double, double* %3
%23 = load double, double* %3
%24 = fmul double %22, %23
%25 = call double @llvm.fmuladd.f64(double %20, double %21, double %24)
%26 = fcmp ole double %25, 1.000000e+00
br i1 %26, label %27, label %30
27: ; preds = %11
%28 = load i64, i64* %4
%29 = add i64 %28, 1
store i64 %29, i64* %4
br label %30
30: ; preds = %27, %11
br label %31
31: ; preds = %30
%32 = load i64, i64* %5
%33 = add i64 %32, 1
store i64 %33, i64* %5
br label %8
34: ; preds = %8
%35 = load i64, i64* %4
%36 = uitofp i64 %35 to double
%37 = fmul double 4.000000e+00, %36
%38 = load i64, i64* %5
%39 = uitofp i64 %38 to double
%40 = fdiv double %37, %39
%41 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %40)
ret i32 0
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
@.str = [5 x i8] c"%lf\0A\00"
define i32 @main() {
%1 = tail call i32 @time(i32* null)
%2 = tail call i32 @srand(i32 %1)
br label %3
3: ; preds = %0, %3
%4 = phi i64 [ 0, %0 ], [ %19, %3 ]
%5 = phi i64 [ 0, %0 ], [ %18, %3 ]
%6 = tail call double (...) @rand()
%7 = load i64, i64* @RAND_MAX
%8 = sitofp i64 %7 to double
%9 = fdiv double %6, %8
%10 = tail call double (...) @rand()
%11 = load i64, i64* @RAND_MAX
%12 = sitofp i64 %11 to double
%13 = fdiv double %10, %12
%14 = fmul double %13, %13
%15 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %14)
%16 = fcmp ole double %15, 1.000000e+00
%17 = zext i1 %16 to i64
%18 = add i64 %5, %17
%19 = add nuw nsw i64 %4, 1
%20 = icmp eq i64 %19, 1000000000
br i1 %20, label %21, label %3
21: ; preds = %3
%22 = uitofp i64 %18 to double
%23 = fmul double %22, 4.000000e+00
%24 = fdiv double %23, 1.000000e+09
%25 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %24)
ret i32 0
}