#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 drand48();
double fabs(double);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char **argv) {
  long long int test = 0;
  long long int Ninside = 0;
  double newPi = 0, estPi = 0;
  double tol = 1e-8;
  do {
    int n, Ninnertests = 10000;
    estPi = newPi;
    for (n = 0; n < Ninnertests; ++n) {
      ++test;
      double x = drand48();
      double y = drand48();
      if (x * x + y * y < 1) {
        ++Ninside;
      }
    }
    newPi = Ninside / (double)test;
    printf("newPi = %lf\n", newPi);
  } while (fabs(newPi - estPi) > tol);
  printf("estPi = %lf\n", 4. * newPi);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xea2(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x2710,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    11f8 <main+0xd8>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <drand48@plt>
movsd  %xmm0,-0x48(%rbp)
mov    $0x0,%al
call   1040 <drand48@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm0
mulsd  -0x50(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe41(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11e5 <main+0xc5>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11ea <main+0xca>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    117b <main+0x5b>
cvtsi2sdq -0x20(%rbp),%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
cvttsd2si -0x28(%rbp),%esi
lea    0xe17(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movaps 0xdf1(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x38(%rbp),%xmm0
ja     1163 <main+0x43>
movsd  0xdc2(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
cvttsd2si %xmm0,%esi
lea    0xde7(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
xorpd  %xmm0,%xmm0
lea    0xefb(%rip),%r14
xor    %ebx,%ebx
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x10(%rsp)
mov    $0x2710,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <drand48@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <drand48@plt>
mulsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
xor    %eax,%eax
movsd  0xe80(%rip),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
add    %rax,%rbx
add    $0xffffffff,%ebp
jne    1150 <main+0x30>
add    $0x2710,%r15
xorps  %xmm1,%xmm1
cvtsi2sd %rbx,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %r15,%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
cvttsd2si %xmm1,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm1
movapd %xmm1,%xmm0
subsd  0x10(%rsp),%xmm0
andpd  0xe4c(%rip),%xmm0
ucomisd 0xe2c(%rip),%xmm0
movapd %xmm1,%xmm0
ja     1140 <main+0x20>
mulsd  0xe22(%rip),%xmm1
cvttsd2si %xmm1,%esi
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"newPi = %lf\0A\00"
@.str.1 = [13 x i8] c"estPi = %lf\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %19, %2
%4 = phi double [ 0.000000e+00, %2 ], [ %23, %19 ]
%5 = phi i64 [ 0, %2 ], [ %16, %19 ]
%6 = phi i64 [ 0, %2 ], [ %20, %19 ]
br label %7
7: ; preds = %3, %7
%8 = phi i64 [ %5, %3 ], [ %16, %7 ]
%9 = phi i32 [ 0, %3 ], [ %17, %7 ]
%10 = tail call double (...) @drand48()
%11 = tail call double (...) @drand48()
%12 = fmul double %11, %11
%13 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %12)
%14 = fcmp olt double %13, 1.000000e+00
%15 = zext i1 %14 to i64
%16 = add nsw i64 %8, %15
%17 = add nuw nsw i32 %9, 1
%18 = icmp eq i32 %17, 10000
br i1 %18, label %19, label %7
19: ; preds = %7
%20 = add i64 %6, 10000
%21 = sitofp i64 %16 to double
%22 = sitofp i64 %20 to double
%23 = fdiv double %21, %22
%24 = fptosi double %23 to i32
%25 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = fsub double %23, %4
%27 = tail call double @llvm.fabs.f64(double %26)
%28 = fcmp ogt double %27, 1.000000e-08
br i1 %28, label %3, label %29
29: ; preds = %19
%30 = fmul double %23, 4.000000e+00
%31 = fptosi double %30 to i32
%32 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %31)
ret i32 0
}