double dboard(int darts) {
  double x_coord, y_coord, pi, r;
  int score, n;
  unsigned int cconst;
  cconst = 9;
  score = 0;
  for (n = 1; n <= darts; n++) {
    r = (double)random() / cconst;
    x_coord = (2.0 * r) - 1.0;
    r = (double)random() / cconst;
    y_coord = (2.0 * r) - 1.0;
    if ((((x_coord) * (x_coord)) + ((y_coord) * (y_coord))) <= 1.0)
      score++;
  }
  pi = 4.0 * (double)score / (double)darts;
  return (pi);
}


x86 assembly (clang, -O0):
<dboard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x9,-0x34(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11f8 <dboard+0xe8>
xor    %eax,%eax
mov    %al,-0x35(%rbp)
call   1030 <random@plt>
mov    %eax,%ecx
mov    -0x35(%rbp),%al
cvtsi2sd %ecx,%xmm0
mov    -0x34(%rbp),%ecx
cvtsi2sd %rcx,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe9f(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
call   1030 <random@plt>
cvtsi2sd %eax,%xmm0
mov    -0x34(%rbp),%eax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe6b(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe36(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     11e5 <dboard+0xd5>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ea <dboard+0xda>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1130 <dboard+0x20>
cvtsi2sdl -0x2c(%rbp),%xmm1
movsd  0xdfb(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dboard>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
test   %edi,%edi
jle    11b9 <dboard+0xa9>
mov    %r14d,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <random@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  0xeba(%rip),%xmm0
divsd  %xmm0,%xmm1
addsd  %xmm1,%xmm1
movsd  0xeb2(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1030 <random@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xe8a(%rip),%xmm0
addsd  %xmm0,%xmm0
addsd  0xe86(%rip),%xmm0
mulsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe74(%rip),%xmm0
ucomisd %xmm1,%xmm0
sbb    $0xffffffff,%ebp
add    $0xffffffff,%ebx
jne    1130 <dboard+0x20>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0xe61(%rip),%xmm0
jmp    11bd <dboard+0xad>
xorpd  %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
divsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @dboard(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %2
store i32 9, i32* %9
store i32 0, i32* %7
store i32 1, i32* %8
br label %10
10: ; preds = %40, %1
%11 = load i32, i32* %8
%12 = load i32, i32* %2
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %43
14: ; preds = %10
%15 = call i32 (...) @random()
%16 = sitofp i32 %15 to double
%17 = load i32, i32* %9
%18 = uitofp i32 %17 to double
%19 = fdiv double %16, %18
store double %19, double* %6
%20 = load double, double* %6
%21 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %20, double -1.000000e+00)
store double %21, double* %3
%22 = call i32 (...) @random()
%23 = sitofp i32 %22 to double
%24 = load i32, i32* %9
%25 = uitofp i32 %24 to double
%26 = fdiv double %23, %25
store double %26, double* %6
%27 = load double, double* %6
%28 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %27, double -1.000000e+00)
store double %28, double* %4
%29 = load double, double* %3
%30 = load double, double* %3
%31 = load double, double* %4
%32 = load double, double* %4
%33 = fmul double %31, %32
%34 = call double @llvm.fmuladd.f64(double %29, double %30, double %33)
%35 = fcmp ole double %34, 1.000000e+00
br i1 %35, label %36, label %39
36: ; preds = %14
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %39
39: ; preds = %36, %14
br label %40
40: ; preds = %39
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %10
43: ; preds = %10
%44 = load i32, i32* %7
%45 = sitofp i32 %44 to double
%46 = fmul double 4.000000e+00, %45
%47 = load i32, i32* %2
%48 = sitofp i32 %47 to double
%49 = fdiv double %46, %48
store double %49, double* %5
%50 = load double, double* %5
ret double %50
}

LLVM IR (-O2):
define double @dboard(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %24, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %18, %3 ], [ 0, %1 ]
%5 = phi i32 [ %19, %3 ], [ 1, %1 ]
%6 = tail call i32 (...) @random()
%7 = sitofp i32 %6 to double
%8 = fdiv double %7, 9.000000e+00
%9 = tail call double @llvm.fmuladd.f64(double %8, double 2.000000e+00, double -1.000000e+00)
%10 = tail call i32 (...) @random()
%11 = sitofp i32 %10 to double
%12 = fdiv double %11, 9.000000e+00
%13 = tail call double @llvm.fmuladd.f64(double %12, double 2.000000e+00, double -1.000000e+00)
%14 = fmul double %13, %13
%15 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %14)
%16 = fcmp ole double %15, 1.000000e+00
%17 = zext i1 %16 to i32
%18 = add nuw nsw i32 %4, %17
%19 = add nuw i32 %5, 1
%20 = icmp eq i32 %5, %0
br i1 %20, label %21, label %3
21: ; preds = %3
%22 = sitofp i32 %18 to double
%23 = fmul double %22, 4.000000e+00
br label %24
24: ; preds = %21, %1
%25 = phi double [ 0.000000e+00, %1 ], [ %23, %21 ]
%26 = sitofp i32 %0 to double
%27 = fdiv double %25, %26
ret double %27
}