#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
double RAND_MAX;
int atoi(char *);
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ rand();
int main(int argc, char *argv[]) {
  int i, n, hits = 0;
  if (argc != 2)
    errx(EXIT_FAILURE, "expected number of trials");
  n = atoi(argv[1]);
  for (i = 0; i < n; i++) {
    double x = ((double)rand()) / RAND_MAX;
    double y = ((double)rand()) / RAND_MAX;
    hits += x * x + y * y <= 1.0 ? 1 : 0;
  }
  printf("%f\n", 4 * ((double)hits) / n);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     117c <main+0x3c>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
call   1030 <errx@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    121d <main+0xdd>
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e36(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e1a(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe0d(%rip),%xmm0
xor    %eax,%eax
mov    $0x1,%ecx
ucomisd %xmm1,%xmm0
cmovae %ecx,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1193 <main+0x53>
cvtsi2sdl -0x1c(%rbp),%xmm1
movsd  0xdd6(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%esi
lea    0xde8(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
je     1164 <main+0x24>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
lea    0xeb1(%rip),%rsi
call   1030 <errx@plt>
mov    0x8(%rbx),%rdi
call   1050 <atoi@plt>
mov    %eax,%r14d
test   %eax,%eax
jle    11e3 <main+0xa3>
mov    0x2e6d(%rip),%r15
mov    %r14d,%ebx
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r15),%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r15),%xmm0
mulsd  %xmm0,%xmm0
movsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe3a(%rip),%xmm0
ucomisd %xmm1,%xmm0
sbb    $0xffffffff,%ebp
add    $0xffffffff,%ebx
jne    1180 <main+0x40>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0xe27(%rip),%xmm0
jmp    11e7 <main+0xa7>
xorpd  %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%esi
lea    0xe2c(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [26 x i8] c"expected number of trials\00"
@RAND_MAX = global double 0.000000e+00
@.str.1 = [4 x i8] c"%f\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @errx(i32 %14, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %13, %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %7
store i32 0, i32* %6
br label %21
21: ; preds = %45, %16
%22 = load i32, i32* %6
%23 = load i32, i32* %7
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %48
25: ; preds = %21
%26 = call i64 (...) @rand()
%27 = sitofp i64 %26 to double
%28 = load double, double* @RAND_MAX
%29 = fdiv double %27, %28
store double %29, double* %9
%30 = call i64 (...) @rand()
%31 = sitofp i64 %30 to double
%32 = load double, double* @RAND_MAX
%33 = fdiv double %31, %32
store double %33, double* %10
%34 = load double, double* %9
%35 = load double, double* %9
%36 = load double, double* %10
%37 = load double, double* %10
%38 = fmul double %36, %37
%39 = call double @llvm.fmuladd.f64(double %34, double %35, double %38)
%40 = fcmp ole double %39, 1.000000e+00
%41 = zext i1 %40 to i64
%42 = select i1 %40, i32 1, i32 0
%43 = load i32, i32* %8
%44 = add nsw i32 %43, %42
store i32 %44, i32* %8
br label %45
45: ; preds = %25
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %21
48: ; preds = %21
%49 = load i32, i32* %8
%50 = sitofp i32 %49 to double
%51 = fmul double 4.000000e+00, %50
%52 = load i32, i32* %7
%53 = sitofp i32 %52 to double
%54 = fdiv double %51, %53
%55 = fptosi double %54 to i32
%56 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %55)
%57 = load i32, i32* @EXIT_SUCCESS
ret i32 %57
}

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