#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 */
unsigned long const random();
long double pi(size_t ntimes) {
  size_t cnt = 0;
  const unsigned long M = 1 << 31;
  const unsigned long mod = M - 1, prod = M * M;
  unsigned long x, y;
  for (size_t i = 0; i < ntimes; ++i) {
    x = random() & mod;
    y = random() & mod;
    if (x * x + y * y < prod)
      ++cnt;
  }
  return 4.0 * cnt / ntimes;
}


x86 assembly (clang, -O0):
<pi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0xffffffff80000000,-0x18(%rbp)
80
movabs $0xffffffff7fffffff,%rax
ff ff ff
mov    %rax,-0x20(%rbp)
movabs $0x4000000000000000,%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    11d8 <pi+0xc8>
mov    $0x0,%al
call   1030 <random@plt>
movabs $0xffffffff7fffffff,%rcx
ff ff ff
and    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
movabs $0xffffffff7fffffff,%rcx
ff ff ff
and    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
imul   -0x30(%rbp),%rax
mov    -0x38(%rbp),%rcx
imul   -0x38(%rbp),%rcx
add    %rcx,%rax
movabs $0x4000000000000000,%rcx
cmp    %rcx,%rax
jae    11c2 <pi+0xb2>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11c7 <pi+0xb7>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1150 <pi+0x40>
movq   -0x10(%rbp),%xmm0
movaps 0xe1c(%rip),%xmm3
punpckldq %xmm3,%xmm0
movapd 0xe20(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe19(%rip),%xmm1
mulsd  %xmm1,%xmm0
movq   -0x8(%rbp),%xmm1
punpckldq %xmm3,%xmm1
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
fldl   -0x48(%rbp)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pi>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
test   %rdi,%rdi
je     119f <pi+0x8f>
movabs $0xffffffff7fffffff,%r15
ff ff ff
mov    %r14,%r13
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1030 <random@plt>
mov    %rax,%rbx
and    %r15,%rbx
xor    %eax,%eax
call   1030 <random@plt>
and    %r15,%rax
imul   %rbx,%rbx
imul   %rax,%rax
add    %rbx,%rax
shr    $0x3e,%rax
cmp    $0x1,%rax
adc    $0x0,%r12
add    $0xffffffffffffffff,%r13
jne    1140 <pi+0x30>
movq   %r12,%xmm1
punpckldq 0xe7f(%rip),%xmm1
subpd  0xe87(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe83(%rip),%xmm0
jmp    11a3 <pi+0x93>
xorpd  %xmm0,%xmm0
movq   %r14,%xmm1
punpckldq 0xe50(%rip),%xmm1
subpd  0xe58(%rip),%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
addsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
movsd  %xmm0,0x8(%rsp)
fldl   0x8(%rsp)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define x86_fp80 @pi(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i64 %0, i64* %2
store i64 0, i64* %3
store i64 -2147483648, i64* %4
store i64 -2147483649, i64* %5
store i64 4611686018427387904, i64* %6
store i64 0, i64* %9
br label %10
10: ; preds = %31, %1
%11 = load i64, i64* %9
%12 = load i64, i64* %2
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %34
14: ; preds = %10
%15 = call i64 (...) @random()
%16 = and i64 %15, -2147483649
store i64 %16, i64* %7
%17 = call i64 (...) @random()
%18 = and i64 %17, -2147483649
store i64 %18, i64* %8
%19 = load i64, i64* %7
%20 = load i64, i64* %7
%21 = mul i64 %19, %20
%22 = load i64, i64* %8
%23 = load i64, i64* %8
%24 = mul i64 %22, %23
%25 = add i64 %21, %24
%26 = icmp ult i64 %25, 4611686018427387904
br i1 %26, label %27, label %30
27: ; preds = %14
%28 = load i64, i64* %3
%29 = add i64 %28, 1
store i64 %29, i64* %3
br label %30
30: ; preds = %27, %14
br label %31
31: ; preds = %30
%32 = load i64, i64* %9
%33 = add i64 %32, 1
store i64 %33, i64* %9
br label %10
34: ; preds = %10
%35 = load i64, i64* %3
%36 = uitofp i64 %35 to double
%37 = fmul double 4.000000e+00, %36
%38 = load i64, i64* %2
%39 = uitofp i64 %38 to double
%40 = fdiv double %37, %39
%41 = fpext double %40 to x86_fp80
ret x86_fp80 %41
}

LLVM IR (-O2):
define x86_fp80 @pi(i64 %0) {
%2 = icmp eq i64 %0, 0
br i1 %2, label %6, label %11
3: ; preds = %11
%4 = uitofp i64 %23 to double
%5 = fmul double %4, 4.000000e+00
br label %6
6: ; preds = %3, %1
%7 = phi double [ 0.000000e+00, %1 ], [ %5, %3 ]
%8 = uitofp i64 %0 to double
%9 = fdiv double %7, %8
%10 = fpext double %9 to x86_fp80
ret x86_fp80 %10
11: ; preds = %1, %11
%12 = phi i64 [ %24, %11 ], [ 0, %1 ]
%13 = phi i64 [ %23, %11 ], [ 0, %1 ]
%14 = tail call i64 (...) @random()
%15 = and i64 %14, -2147483649
%16 = tail call i64 (...) @random()
%17 = and i64 %16, -2147483649
%18 = mul i64 %15, %15
%19 = mul i64 %17, %17
%20 = add i64 %19, %18
%21 = icmp ult i64 %20, 4611686018427387904
%22 = zext i1 %21 to i64
%23 = add i64 %13, %22
%24 = add nuw i64 %12, 1
%25 = icmp eq i64 %24, %0
br i1 %25, label %3, label %11
}