int count_in_circle(n)
int n;
{
  int i, in;
  double x, y;
  for (i = in = 0; i < n; i++) {
    x = 2 * sprng() - 1.0;
    y = 2 * sprng() - 1.0;
    if (x * x + y * y < 1.0)
      in++;
  }
  return in;
}


x86 assembly (clang, -O0):
<count_in_circle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11bd <count_in_circle+0xad>
mov    $0x0,%al
call   1030 <sprng@plt>
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  0xeb5(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <sprng@plt>
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe96(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe69(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11aa <count_in_circle+0x9a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11af <count_in_circle+0x9f>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1129 <count_in_circle+0x19>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_in_circle>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
jle    1184 <count_in_circle+0x74>
mov    %edi,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <sprng@plt>
add    %eax,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  0xec8(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1030 <sprng@plt>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0xea7(%rip),%xmm0
mulsd  %xmm0,%xmm0
movsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
xor    %eax,%eax
movsd  0xe94(%rip),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
add    %eax,%ebp
add    $0xffffffff,%ebx
jne    1120 <count_in_circle+0x10>
jmp    1186 <count_in_circle+0x76>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @count_in_circle(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca double
store i32 %0, i32* %2
store i32 0, i32* %4
store i32 0, i32* %3
br label %7
7: ; preds = %31, %1
%8 = load i32, i32* %3
%9 = load i32, i32* %2
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %34
11: ; preds = %7
%12 = call i32 (...) @sprng()
%13 = mul nsw i32 2, %12
%14 = sitofp i32 %13 to double
%15 = fsub double %14, 1.000000e+00
store double %15, double* %5
%16 = call i32 (...) @sprng()
%17 = mul nsw i32 2, %16
%18 = sitofp i32 %17 to double
%19 = fsub double %18, 1.000000e+00
store double %19, double* %6
%20 = load double, double* %5
%21 = load double, double* %5
%22 = load double, double* %6
%23 = load double, double* %6
%24 = fmul double %22, %23
%25 = call double @llvm.fmuladd.f64(double %20, double %21, double %24)
%26 = fcmp olt double %25, 1.000000e+00
br i1 %26, label %27, label %30
27: ; preds = %11
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %30
30: ; preds = %27, %11
br label %31
31: ; preds = %30
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %7
34: ; preds = %7
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
define i32 @count_in_circle(i32 %0) {
%2 = icmp sgt i32 %0, 0
br i1 %2, label %3, label %21
3: ; preds = %1, %3
%4 = phi i32 [ %19, %3 ], [ 0, %1 ]
%5 = phi i32 [ %18, %3 ], [ 0, %1 ]
%6 = tail call i32 (...) @sprng()
%7 = shl nsw i32 %6, 1
%8 = sitofp i32 %7 to double
%9 = fadd double %8, -1.000000e+00
%10 = tail call i32 (...) @sprng()
%11 = shl nsw i32 %10, 1
%12 = sitofp i32 %11 to double
%13 = fadd double %12, -1.000000e+00
%14 = fmul double %13, %13
%15 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %14)
%16 = fcmp olt double %15, 1.000000e+00
%17 = zext i1 %16 to i32
%18 = add nuw nsw i32 %5, %17
%19 = add nuw nsw i32 %4, 1
%20 = icmp eq i32 %19, %0
br i1 %20, label %21, label %3
21: ; preds = %3, %1
%22 = phi i32 [ 0, %1 ], [ %18, %3 ]
ret i32 %22
}