#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 */
typedef scalar_t__ uint64_t;

/* Variables and functions */
double M_PI;
scalar_t__ RAND_MAX;
long atol(char *);
int /*<<< orphan*/ exit(int);
double fabs(double);
int /*<<< orphan*/ printf(char *, long const, ...);
double rand_r(unsigned int *);
double sqrt(double);
int /*<<< orphan*/ usage(char *);
double wctime();
int main(int argc, char **argv) {
  if (argc <= 1) {
    usage(argv[0]);
    exit(1);
  }
  const long n = atol(argv[1]);
  double x, y;
  uint64_t count = 0;
  unsigned int seed = 1234321;
  long m = n;
  double t1 = wctime();
  while (m--) {
    x = rand_r(&seed) / (double)RAND_MAX;
    y = rand_r(&seed) / (double)RAND_MAX;
    if (sqrt(x * x + y * y) < 1.0)
      ++count;
  }
  double pi = 4.0 * (double)count / n;
  double t2 = wctime();
  printf("pi(%ld) = %.12lf (accuracy: %.12lf)\n", n, pi,
         fabs(M_PI - pi) / M_PI);
  printf("Time: %f\n", t2 - t1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     11a6 <main+0x36>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <usage@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atol@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x12d591,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1090 <wctime@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x40(%rbp)
cmp    $0x0,%rax
je     1276 <main+0x106>
lea    -0x34(%rbp),%rdi
call   1030 <rand_r@plt>
mov    0x2ddd(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    -0x34(%rbp),%rdi
call   1030 <rand_r@plt>
mov    0x2dbf(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xdbd(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1271 <main+0x101>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11da <main+0x6a>
cvtsi2sdq -0x30(%rbp),%xmm1
movsd  0xd8c(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    $0x0,%al
call   1090 <wctime@plt>
movsd  %xmm0,-0x58(%rbp)
mov    -0x18(%rbp),%rsi
movsd  -0x50(%rbp),%xmm0
mov    0x2d35(%rip),%rax
movsd  (%rax),%xmm1
subsd  -0x50(%rbp),%xmm1
movaps 0xd3d(%rip),%xmm2
pand   %xmm2,%xmm1
mov    0x2d1a(%rip),%rax
divsd  (%rax),%xmm1
lea    0xd47(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  -0x58(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
cvttsd2si %xmm0,%rsi
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
cmp    $0x1,%edi
jle    12de <main+0x16e>
mov    0x8(%rsi),%rdi
call   1060 <atol@plt>
mov    %rax,%r14
movl   $0x12d591,0xc(%rsp)
xor    %eax,%eax
call   1090 <wctime@plt>
movsd  %xmm0,0x18(%rsp)
test   %r14,%r14
je     1258 <main+0xe8>
xor    %ebx,%ebx
lea    0xc(%rsp),%r15
mov    0x2e22(%rip),%r12
mov    %r14,%r13
jmp    11ee <main+0x7e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
call   1070 <sqrt@plt>
xor    %eax,%eax
movsd  0xe21(%rip),%xmm1
ucomisd %xmm0,%xmm1
seta   %al
add    %rax,%rbx
test   %r13,%r13
je     1246 <main+0xd6>
add    $0xffffffffffffffff,%r13
mov    %r15,%rdi
call   1030 <rand_r@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq (%r12),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
mov    %r15,%rdi
call   1030 <rand_r@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq (%r12),%xmm1
divsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm0
movsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
ucomisd 0xdd2(%rip),%xmm1
jb     11d0 <main+0x60>
sqrtsd %xmm0,%xmm0
jmp    11d5 <main+0x65>
xorps  %xmm1,%xmm1
cvtsi2sd %rbx,%xmm1
mulsd  0xdb2(%rip),%xmm1
jmp    125c <main+0xec>
xorpd  %xmm1,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %r14,%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
xor    %eax,%eax
call   1090 <wctime@plt>
movsd  %xmm0,(%rsp)
mov    0x2d67(%rip),%rax
movsd  (%rax),%xmm2
movapd %xmm2,%xmm1
movsd  0x10(%rsp),%xmm0
subsd  %xmm0,%xmm1
andpd  0xd85(%rip),%xmm1
divsd  %xmm2,%xmm1
lea    0xd8a(%rip),%rdi
mov    %r14,%rsi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  (%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
cvttsd2si %xmm0,%rsi
lea    0xd8e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    (%rsi),%rdi
call   1050 <usage@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@RAND_MAX = global i64 0
@.str = [37 x i8] c"pi(%ld) = %.12lf (accuracy: %.12lf)\0A\00"
@M_PI = global double 0.000000e+00
@.str.1 = [10 x i8] c"Time: %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca double
%8 = alloca double
%9 = alloca i64
%10 = alloca i32
%11 = alloca i64
%12 = alloca double
%13 = alloca double
%14 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp sle i32 %15, 1
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @usage(i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i64 @atol(i8* %26)
store i64 %27, i64* %6
store i64 0, i64* %9
store i32 1234321, i32* %10
%28 = load i64, i64* %6
store i64 %28, i64* %11
%29 = call double (...) @wctime()
store double %29, double* %12
br label %30
30: ; preds = %54, %23
%31 = load i64, i64* %11
%32 = add nsw i64 %31, -1
store i64 %32, i64* %11
%33 = icmp ne i64 %31, 0
br i1 %33, label %34, label %55
34: ; preds = %30
%35 = call double @rand_r(i32* %10)
%36 = load i64, i64* @RAND_MAX
%37 = sitofp i64 %36 to double
%38 = fdiv double %35, %37
store double %38, double* %7
%39 = call double @rand_r(i32* %10)
%40 = load i64, i64* @RAND_MAX
%41 = sitofp i64 %40 to double
%42 = fdiv double %39, %41
store double %42, double* %8
%43 = load double, double* %7
%44 = load double, double* %7
%45 = load double, double* %8
%46 = load double, double* %8
%47 = fmul double %45, %46
%48 = call double @llvm.fmuladd.f64(double %43, double %44, double %47)
%49 = call double @sqrt(double %48)
%50 = fcmp olt double %49, 1.000000e+00
br i1 %50, label %51, label %54
51: ; preds = %34
%52 = load i64, i64* %9
%53 = add nsw i64 %52, 1
store i64 %53, i64* %9
br label %54
54: ; preds = %51, %34
br label %30
55: ; preds = %30
%56 = load i64, i64* %9
%57 = sitofp i64 %56 to double
%58 = fmul double 4.000000e+00, %57
%59 = load i64, i64* %6
%60 = sitofp i64 %59 to double
%61 = fdiv double %58, %60
store double %61, double* %13
%62 = call double (...) @wctime()
store double %62, double* %14
%63 = load i64, i64* %6
%64 = load double, double* %13
%65 = load double, double* @M_PI
%66 = load double, double* %13
%67 = fsub double %65, %66
%68 = call double @llvm.fabs.f64(double %67)
%69 = load double, double* @M_PI
%70 = fdiv double %68, %69
%71 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i64 %63, double %64, double %70)
%72 = load double, double* %14
%73 = load double, double* %12
%74 = fsub double %72, %73
%75 = fptosi double %74 to i64
%76 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 %75)
ret i32 0
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
@.str = [37 x i8] c"pi(%ld) = %.12lf (accuracy: %.12lf)\0A\00"
@M_PI = global double 0.000000e+00
@.str.1 = [10 x i8] c"Time: %f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 @usage(i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @atol(i8* %11)
%13 = bitcast i32* %3 to i8*
store i32 1234321, i32* %3
%14 = tail call double (...) @wctime()
%15 = icmp eq i64 %12, 0
br i1 %15, label %38, label %16
16: ; preds = %9, %16
%17 = phi i64 [ %33, %16 ], [ 0, %9 ]
%18 = phi i64 [ %19, %16 ], [ %12, %9 ]
%19 = add nsw i64 %18, -1
%20 = call double @rand_r(i32* %3)
%21 = load i64, i64* @RAND_MAX
%22 = sitofp i64 %21 to double
%23 = fdiv double %20, %22
%24 = call double @rand_r(i32* %3)
%25 = load i64, i64* @RAND_MAX
%26 = sitofp i64 %25 to double
%27 = fdiv double %24, %26
%28 = fmul double %27, %27
%29 = call double @llvm.fmuladd.f64(double %23, double %23, double %28)
%30 = call double @sqrt(double %29)
%31 = fcmp olt double %30, 1.000000e+00
%32 = zext i1 %31 to i64
%33 = add nuw nsw i64 %17, %32
%34 = icmp eq i64 %19, 0
br i1 %34, label %35, label %16
35: ; preds = %16
%36 = sitofp i64 %33 to double
%37 = fmul double %36, 4.000000e+00
br label %38
38: ; preds = %35, %9
%39 = phi double [ 0.000000e+00, %9 ], [ %37, %35 ]
%40 = sitofp i64 %12 to double
%41 = fdiv double %39, %40
%42 = call double (...) @wctime()
%43 = load double, double* @M_PI
%44 = fsub double %43, %41
%45 = call double @llvm.fabs.f64(double %44)
%46 = fdiv double %45, %43
%47 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i64 %12, double %41, double %46)
%48 = fsub double %42, %14
%49 = fptosi double %48 to i64
%50 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 %49)
ret i32 0
}