#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 *, int);
double rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int main() {
  srand(time(0));
  int numberInside = 0;
  int totalPoints = 0;
  scanf("%d", &totalPoints);
  for (int i = 0; i < totalPoints; ++i) {
    double x = rand() / (double)RAND_MAX;
    double y = rand() / (double)RAND_MAX;
    if (x * x + y * y < 1.0) {
      ++numberInside;
    }
  }
  printf("Pi = %f\n", 4 * (double)numberInside / (double)totalPoints);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe8e(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1220 <main+0xd0>
mov    $0x0,%al
call   1070 <rand@plt>
mov    0x2e3c(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
mov    0x2e20(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe0e(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    120d <main+0xbd>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1212 <main+0xc2>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1192 <main+0x42>
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  0xdd3(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%esi
lea    0xdce(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,0x4(%rsp)
lea    0xe9b(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
jle    120d <main+0xbd>
mov    0x2e56(%rip),%r14
xor    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq (%r14),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq (%r14),%xmm1
divsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
xor    %eax,%eax
movsd  0xe18(%rip),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
add    %eax,%ebp
add    $0x1,%ebx
mov    0x4(%rsp),%eax
cmp    %eax,%ebx
jl     11a0 <main+0x50>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0xdfd(%rip),%xmm0
jmp    1211 <main+0xc1>
xorpd  %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%esi
lea    0xdec(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@RAND_MAX = global i64 0
@.str.1 = [9 x i8] c"Pi = %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32 @time(i32 0)
%3 = tail call i32 @srand(i32 %2)
%4 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp sgt i32 %6, 0
br i1 %7, label %18, label %11
8: ; preds = %18
%9 = sitofp i32 %33 to double
%10 = fmul double %9, 4.000000e+00
br label %11
11: ; preds = %8, %0
%12 = phi double [ 0.000000e+00, %0 ], [ %10, %8 ]
%13 = phi i32 [ %6, %0 ], [ %35, %8 ]
%14 = sitofp i32 %13 to double
%15 = fdiv double %12, %14
%16 = fptosi double %15 to i32
%17 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %16)
ret i32 0
18: ; preds = %0, %18
%19 = phi i32 [ %33, %18 ], [ 0, %0 ]
%20 = phi i32 [ %34, %18 ], [ 0, %0 ]
%21 = call double (...) @rand()
%22 = load i64, i64* @RAND_MAX
%23 = sitofp i64 %22 to double
%24 = fdiv double %21, %23
%25 = call double (...) @rand()
%26 = load i64, i64* @RAND_MAX
%27 = sitofp i64 %26 to double
%28 = fdiv double %25, %27
%29 = fmul double %28, %28
%30 = call double @llvm.fmuladd.f64(double %24, double %24, double %29)
%31 = fcmp olt double %30, 1.000000e+00
%32 = zext i1 %31 to i32
%33 = add nuw nsw i32 %19, %32
%34 = add nuw nsw i32 %20, 1
%35 = load i32, i32* %1
%36 = icmp slt i32 %34, %35
br i1 %36, label %18, label %8
}