#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 */
struct drand48_data {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ drand48_r(struct drand48_data *, double *);
double fabs(double);
int /*<<< orphan*/ free(struct drand48_data *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ srand48_r(long, struct drand48_data *);
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;
  int Nthreads = 1;
  struct drand48_data *drandData;
  drandData =
      (struct drand48_data *)malloc(Nthreads * sizeof(struct drand48_data));
  long int seed = 0;
  srand48_r(seed, drandData + 0);
  do {
    int Ninnertests = 10000;
    estPi = newPi;
    for (int n = 0; n < Ninnertests; ++n) {
      double x, y;
      ++test;
      drand48_r(drandData + 0, &x);
      drand48_r(drandData + 0, &y);
      if (x * x + y * y < 1) {
        ++Ninside;
      }
    }
    newPi = Ninside / (double)test;
    printf("newPi = %lf\n", 4. * newPi);
  } while (fabs(newPi - estPi) > tol);
  printf("\n");
  printf("estPi = %lf\n", 4. * newPi);
  free(drandData);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%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  0xe72(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x1,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1060 <srand48_r@plt>
movl   $0x2710,-0x54(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    1259 <main+0x109>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x48(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1070 <drand48_r@plt>
mov    -0x48(%rbp),%rdi
lea    -0x68(%rbp),%rsi
call   1070 <drand48_r@plt>
movsd  -0x60(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm2
movsd  -0x68(%rbp),%xmm0
mulsd  -0x68(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xde0(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1246 <main+0xf6>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    124b <main+0xfb>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    11da <main+0x8a>
cvtsi2sdq -0x20(%rbp),%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xd92(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
lea    0xdae(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movaps 0xd86(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x38(%rbp),%xmm0
ja     11c2 <main+0x72>
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  0xd49(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
lea    0xd72(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
xor    %ebx,%ebx
xor    %edi,%edi
mov    %rax,%rsi
call   1070 <srand48_r@plt>
xorpd  %xmm0,%xmm0
lea    0x20(%rsp),%r14
lea    0x18(%rsp),%r15
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x10(%rsp)
mov    $0x2710,%r12d
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r14,%rsi
call   1080 <drand48_r@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1080 <drand48_r@plt>
movsd  0x20(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xor    %eax,%eax
movsd  0xe18(%rip),%xmm1
ucomisd %xmm0,%xmm1
seta   %al
add    %rax,%rbx
add    $0xffffffff,%r12d
jne    11b0 <main+0x50>
add    $0x2710,%rbp
xorps  %xmm1,%xmm1
cvtsi2sd %rbx,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rbp,%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
mulsd  0xde3(%rip),%xmm0
lea    0xe04(%rip),%rdi
movsd  %xmm0,(%rsp)
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm1
movapd %xmm1,%xmm0
subsd  0x10(%rsp),%xmm0
andpd  0xdd0(%rip),%xmm0
ucomisd 0xdb8(%rip),%xmm0
movapd %xmm1,%xmm0
ja     11a0 <main+0x40>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xdca(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.drand48_data = type { i32 }
@.str = [13 x i8] c"newPi = %lf\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [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 %struct.drand48_data*
%13 = alloca i64
%14 = alloca i32
%15 = alloca i32
%16 = alloca double
%17 = 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
store i32 1, i32* %11
%18 = load i32, i32* %11
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 4
%21 = trunc i64 %20 to i32
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to %struct.drand48_data*
store %struct.drand48_data* %23, %struct.drand48_data** %12
store i64 0, i64* %13
%24 = load i64, i64* %13
%25 = load %struct.drand48_data*, %struct.drand48_data** %12
%26 = getelementptr inbounds %struct.drand48_data, %struct.drand48_data* %25, i64 0
%27 = call i32 @srand48_r(i64 %24, %struct.drand48_data* %26)
br label %28
28: ; preds = %66, %2
store i32 10000, i32* %14
%29 = load double, double* %8
store double %29, double* %9
store i32 0, i32* %15
br label %30
30: ; preds = %54, %28
%31 = load i32, i32* %15
%32 = load i32, i32* %14
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %57
34: ; preds = %30
%35 = load i64, i64* %6
%36 = add nsw i64 %35, 1
store i64 %36, i64* %6
%37 = load %struct.drand48_data*, %struct.drand48_data** %12
%38 = getelementptr inbounds %struct.drand48_data, %struct.drand48_data* %37, i64 0
%39 = call i32 @drand48_r(%struct.drand48_data* %38, double* %16)
%40 = load %struct.drand48_data*, %struct.drand48_data** %12
%41 = getelementptr inbounds %struct.drand48_data, %struct.drand48_data* %40, i64 0
%42 = call i32 @drand48_r(%struct.drand48_data* %41, double* %17)
%43 = load double, double* %16
%44 = load double, double* %16
%45 = load double, double* %17
%46 = load double, double* %17
%47 = fmul double %45, %46
%48 = call double @llvm.fmuladd.f64(double %43, double %44, double %47)
%49 = fcmp olt double %48, 1.000000e+00
br i1 %49, label %50, label %53
50: ; preds = %34
%51 = load i64, i64* %7
%52 = add nsw i64 %51, 1
store i64 %52, i64* %7
br label %53
53: ; preds = %50, %34
br label %54
54: ; preds = %53
%55 = load i32, i32* %15
%56 = add nsw i32 %55, 1
store i32 %56, i32* %15
br label %30
57: ; preds = %30
%58 = load i64, i64* %7
%59 = sitofp i64 %58 to double
%60 = load i64, i64* %6
%61 = sitofp i64 %60 to double
%62 = fdiv double %59, %61
store double %62, double* %8
%63 = load double, double* %8
%64 = fmul double 4.000000e+00, %63
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %64)
br label %66
66: ; preds = %57
%67 = load double, double* %8
%68 = load double, double* %9
%69 = fsub double %67, %68
%70 = call double @llvm.fabs.f64(double %69)
%71 = load double, double* %10
%72 = fcmp ogt double %70, %71
br i1 %72, label %28, label %73
73: ; preds = %66
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%75 = load double, double* %8
%76 = fmul double 4.000000e+00, %75
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), double %76)
%78 = load %struct.drand48_data*, %struct.drand48_data** %12
%79 = call i32 @free(%struct.drand48_data* %78)
ret i32 0
}

LLVM IR (-O2):
%struct.drand48_data = type { i32 }
@.str = [13 x i8] c"newPi = %lf\0A\00"
@.str.2 = [13 x i8] c"estPi = %lf\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca double
%4 = alloca double
%5 = tail call i64 @malloc(i32 4)
%6 = inttoptr i64 %5 to %struct.drand48_data*
%7 = tail call i32 @srand48_r(i64 0, %struct.drand48_data* %6)
%8 = bitcast double* %3 to i8*
%9 = bitcast double* %4 to i8*
br label %10
10: ; preds = %15, %2
%11 = phi i32 [ %25, %15 ], [ 10000, %2 ]
%12 = phi double [ %19, %15 ], [ 0.000000e+00, %2 ]
%13 = phi i64 [ %38, %15 ], [ 0, %2 ]
%14 = phi i64 [ %16, %15 ], [ 0, %2 ]
br label %26
15: ; preds = %26
%16 = add i64 %14, 10000
%17 = sitofp i64 %38 to double
%18 = sitofp i64 %16 to double
%19 = fdiv double %17, %18
%20 = fmul double %19, 4.000000e+00
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %20)
%22 = fsub double %19, %12
%23 = call double @llvm.fabs.f64(double %22)
%24 = fcmp ogt double %23, 1.000000e-08
%25 = add i32 %11, 10000
br i1 %24, label %10, label %41
26: ; preds = %10, %26
%27 = phi i64 [ %14, %10 ], [ %29, %26 ]
%28 = phi i64 [ %13, %10 ], [ %38, %26 ]
%29 = add i64 %27, 1
%30 = call i32 @drand48_r(%struct.drand48_data* %6, double* %3)
%31 = call i32 @drand48_r(%struct.drand48_data* %6, double* %4)
%32 = load double, double* %3
%33 = load double, double* %4
%34 = fmul double %33, %33
%35 = call double @llvm.fmuladd.f64(double %32, double %32, double %34)
%36 = fcmp olt double %35, 1.000000e+00
%37 = zext i1 %36 to i64
%38 = add nsw i64 %28, %37
%39 = trunc i64 %29 to i32
%40 = icmp eq i32 %11, %39
br i1 %40, label %15, label %26
41: ; preds = %15
%42 = call i32 @putchar(i32 10)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), double %20)
%44 = call i32 @free(%struct.drand48_data* %6)
ret i32 0
}