#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 */
double M_PI;
long atol(char *);
int /*<<< orphan*/ exit(int);
double fabs(double);
scalar_t__ pi_mc(int /*<<< orphan*/, long);
int /*<<< orphan*/ printf(char *, double, ...);
int /*<<< orphan*/ usage(char *);
double wctime();
int main(int argc, char **argv) {
  if (argc <= 1) {
    usage(argv[0]);
    exit(1);
  }
  long n = atol(argv[1]);
  double t1 = wctime();
  double pi = 4.0 * (double)pi_mc(0, n) / 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    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     1196 <main+0x36>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <usage@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atol@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1080 <wctime@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
xor    %edi,%edi
call   1030 <pi_mc@plt>
cvtsi2sd %rax,%xmm1
movsd  0xe45(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1080 <wctime@plt>
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdq -0x18(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    0x2dec(%rip),%rax
movsd  (%rax),%xmm2
subsd  -0x28(%rbp),%xmm2
movaps 0xdf4(%rip),%xmm3
pand   %xmm3,%xmm2
mov    0x2dd1(%rip),%rax
divsd  (%rax),%xmm2
lea    0xdf6(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
movsd  -0x30(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
lea    0xe03(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
cmp    $0x1,%edi
jle    121c <main+0xbc>
mov    0x8(%rsi),%rdi
call   1060 <atol@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1080 <wctime@plt>
movsd  %xmm0,0x18(%rsp)
xor    %edi,%edi
mov    %rbx,%rsi
call   1030 <pi_mc@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mulsd  0xe5f(%rip),%xmm0
cvtsi2sd %rbx,%xmm1
movsd  %xmm1,0x8(%rsp)
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1080 <wctime@plt>
movsd  %xmm0,0x10(%rsp)
mov    0x2e1f(%rip),%rax
movsd  (%rax),%xmm0
movapd %xmm0,%xmm2
movsd  (%rsp),%xmm1
subsd  %xmm1,%xmm2
andpd  0xe2e(%rip),%xmm2
divsd  %xmm0,%xmm2
lea    0xe33(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x3,%al
call   1040 <printf@plt>
movsd  0x10(%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
lea    0xe38(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
mov    (%rsi),%rdi
call   1050 <usage@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.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 double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp sle i32 %10, 1
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @usage(i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @atol(i8* %21)
store i64 %22, i64* %6
%23 = call double (...) @wctime()
store double %23, double* %7
%24 = load i64, i64* %6
%25 = call i64 @pi_mc(i32 0, i64 %24)
%26 = sitofp i64 %25 to double
%27 = fmul double 4.000000e+00, %26
%28 = load i64, i64* %6
%29 = sitofp i64 %28 to double
%30 = fdiv double %27, %29
store double %30, double* %8
%31 = call double (...) @wctime()
store double %31, double* %9
%32 = load i64, i64* %6
%33 = sitofp i64 %32 to double
%34 = load double, double* %8
%35 = load double, double* @M_PI
%36 = load double, double* %8
%37 = fsub double %35, %36
%38 = call double @llvm.fabs.f64(double %37)
%39 = load double, double* @M_PI
%40 = fdiv double %38, %39
%41 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), double %33, double %34, double %40)
%42 = load double, double* %9
%43 = load double, double* %7
%44 = fsub double %42, %43
%45 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %44)
ret i32 0
}

LLVM IR (-O2):
@.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 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @usage(i8* %5)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @atol(i8* %10)
%12 = tail call double (...) @wctime()
%13 = tail call i64 @pi_mc(i32 0, i64 %11)
%14 = sitofp i64 %13 to double
%15 = fmul double %14, 4.000000e+00
%16 = sitofp i64 %11 to double
%17 = fdiv double %15, %16
%18 = tail call double (...) @wctime()
%19 = load double, double* @M_PI
%20 = fsub double %19, %17
%21 = tail call double @llvm.fabs.f64(double %20)
%22 = fdiv double %21, %19
%23 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), double %16, double %17, double %22)
%24 = fsub double %18, %12
%25 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %24)
ret i32 0
}