void monteCarlo(unsigned long long times) {
  long long x, y;
  int in = 0;
  int a;
  for (a = 0; a < times; a++) {
    x = rand() % 1000;
    y = rand() % 1000;
    if ((x * x) + (y * y) <= 1000 * 1000)
      in++;
  }
  printf("%e\n", ((double)(in)*4) / times);
}


x86 assembly (clang, -O0):
<monteCarlo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    11b1 <monteCarlo+0x91>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
imul   -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
imul   -0x18(%rbp),%rcx
add    %rcx,%rax
cmp    $0xf4240,%rax
jg     119e <monteCarlo+0x7e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a3 <monteCarlo+0x83>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    113a <monteCarlo+0x1a>
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  0xe42(%rip),%xmm1
mulsd  %xmm1,%xmm0
movaps 0xe47(%rip),%xmm2
movq   -0x8(%rbp),%xmm1
punpckldq %xmm2,%xmm1
movapd 0xe46(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
lea    0xe3c(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<monteCarlo>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdi,%rdi
je     11b9 <monteCarlo+0x99>
mov    %r14,%rbx
xor    %r15d,%r15d
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
movslq %eax,%rbp
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
cltq
imul   %rbp,%rbp
imul   %rax,%rax
add    %rbp,%rax
cmp    $0xf4241,%rax
adc    $0x0,%r15d
add    $0xffffffffffffffff,%rbx
jne    1140 <monteCarlo+0x20>
cvtsi2sd %r15d,%xmm0
mulsd  0xe49(%rip),%xmm0
jmp    11bd <monteCarlo+0x9d>
xorpd  %xmm0,%xmm0
movq   %r14,%xmm1
punpckldq 0xe46(%rip),%xmm1
subpd  0xe4e(%rip),%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
addsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
lea    0xe47(%rip),%rdi
mov    $0x1,%al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%e\0A\00"
define void @monteCarlo(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store i64 %0, i64* %2
store i32 0, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %31, %1
%8 = load i32, i32* %6
%9 = sext i32 %8 to i64
%10 = load i64, i64* %2
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %34
12: ; preds = %7
%13 = call i32 (...) @rand()
%14 = srem i32 %13, 1000
%15 = sext i32 %14 to i64
store i64 %15, i64* %3
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 1000
%18 = sext i32 %17 to i64
store i64 %18, i64* %4
%19 = load i64, i64* %3
%20 = load i64, i64* %3
%21 = mul nsw i64 %19, %20
%22 = load i64, i64* %4
%23 = load i64, i64* %4
%24 = mul nsw i64 %22, %23
%25 = add nsw i64 %21, %24
%26 = icmp sle i64 %25, 1000000
br i1 %26, label %27, label %30
27: ; preds = %12
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %30
30: ; preds = %27, %12
br label %31
31: ; preds = %30
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %7
34: ; preds = %7
%35 = load i32, i32* %5
%36 = sitofp i32 %35 to double
%37 = fmul double %36, 4.000000e+00
%38 = load i64, i64* %2
%39 = uitofp i64 %38 to double
%40 = fdiv double %37, %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %40)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%e\0A\00"
define void @monteCarlo(i64 %0) {
%2 = icmp eq i64 %0, 0
br i1 %2, label %23, label %3
3: ; preds = %1, %3
%4 = phi i64 [ %18, %3 ], [ 0, %1 ]
%5 = phi i32 [ %17, %3 ], [ 0, %1 ]
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 1000
%8 = sext i32 %7 to i64
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 1000
%11 = sext i32 %10 to i64
%12 = mul nsw i64 %8, %8
%13 = mul nsw i64 %11, %11
%14 = add nuw nsw i64 %13, %12
%15 = icmp ult i64 %14, 1000001
%16 = zext i1 %15 to i32
%17 = add nuw nsw i32 %5, %16
%18 = add nuw i64 %4, 1
%19 = icmp eq i64 %18, %0
br i1 %19, label %20, label %3
20: ; preds = %3
%21 = sitofp i32 %17 to double
%22 = fmul double %21, 4.000000e+00
br label %23
23: ; preds = %20, %1
%24 = phi double [ 0.000000e+00, %1 ], [ %22, %20 ]
%25 = uitofp i64 %0 to double
%26 = fdiv double %24, %25
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %26)
ret void
}