#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 RAND_MAX;
int /*<<< orphan*/ printf(char *, double);
double rand();
int main() {
  double i, imax, n;
  double x, y, pi;
  n = 0.0;
  imax = 10000000.0;
  for (i = 0; i <= imax; i++) {
    x = rand() / (RAND_MAX + 1.0);
    y = rand() / (RAND_MAX + 1.0);
    if ((x * x + y * y) < 1.0) {
      n += 1.0;
    }
  }
  pi = n / imax * 4.0;
  printf("%f\n", pi);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xec1(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1202 <main+0xe2>
mov    $0x0,%al
call   1040 <rand@plt>
movsd  0xea1(%rip),%xmm1
mov    0x2e72(%rip),%rax
addsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
movsd  0xe7e(%rip),%xmm1
mov    0x2e4f(%rip),%rax
addsd  (%rax),%xmm1
divsd  %xmm1,%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  0xe46(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11e6 <main+0xc6>
movsd  0xe34(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11eb <main+0xcb>
movsd  0xe1d(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    114c <main+0x2c>
movsd  -0x20(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  0xdf4(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    0xdef(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
xorpd  %xmm1,%xmm1
mov    $0x989681,%ebx
mov    0x2eb1(%rip),%r14
nopw   0x0(%rax,%rax,1)
movapd %xmm1,0x10(%rsp)
xor    %eax,%eax
call   1040 <rand@plt>
movsd  (%r14),%xmm2
movsd  0xea6(%rip),%xmm1
addsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
movapd %xmm0,(%rsp)
xor    %eax,%eax
call   1040 <rand@plt>
movsd  (%r14),%xmm1
movsd  0xe85(%rip),%xmm3
addsd  %xmm3,%xmm1
divsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm0
movapd (%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movapd 0x10(%rsp),%xmm2
movapd %xmm2,%xmm0
addsd  %xmm3,%xmm0
cmpltsd %xmm3,%xmm1
andpd  %xmm1,%xmm0
andnpd %xmm2,%xmm1
orpd   %xmm0,%xmm1
add    $0xffffffff,%ebx
jne    1140 <main+0x20>
movapd %xmm1,%xmm0
divsd  0xe44(%rip),%xmm0
mulsd  0xe44(%rip),%xmm0
lea    0xe45(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

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

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