#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 */
scalar_t__ RAND_MAX;
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
double rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int i;
  double random_x = 0;
  double random_y = 0;
  double pi = 0;
  if (argc != 2) {
    printf("ERROR: Needs exactly 1 argument.\n");
    exit(1);
  }
  int len = atoi(argv[1]);
  srand(time(NULL));
#pragma omp parallel for
  for (int i = 0; i < len; i++) {
    double random_x = rand() / (double)RAND_MAX;
    double random_y = rand() / (double)RAND_MAX;
    pi += random_x * random_x + random_y * random_y <= 1;
  }
  pi *= 4.0 / len;
  printf("Pi is: %f\n", pi);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b0 <main+0x50>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x34(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1267 <main+0x107>
mov    $0x0,%al
call   1080 <rand@plt>
mov    0x2df7(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    $0x0,%al
call   1080 <rand@plt>
mov    0x2ddb(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xdc9(%rip),%xmm0
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%eax
cvtsi2sd %eax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11d7 <main+0x77>
cvtsi2sdl -0x34(%rbp),%xmm1
movsd  0xd8c(%rip),%xmm0
divsd  %xmm1,%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xda4(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
cmp    $0x2,%edi
jne    1245 <main+0xd5>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%r14d
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
xorpd  %xmm2,%xmm2
test   %r14d,%r14d
jle    1214 <main+0xa4>
mov    0x2e3d(%rip),%rbx
mov    %r14d,%ebp
xchg   %ax,%ax
movsd  %xmm2,0x8(%rsp)
xor    %eax,%eax
call   1090 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq (%rbx),%xmm1
divsd  %xmm1,%xmm0
movapd %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1090 <rand@plt>
movsd  0x8(%rsp),%xmm2
xorps  %xmm1,%xmm1
cvtsi2sdq (%rbx),%xmm1
divsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm0
movapd 0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xdfe(%rip),%xmm0
cmplesd %xmm0,%xmm1
andpd  %xmm0,%xmm1
addsd  %xmm1,%xmm2
add    $0xffffffff,%ebp
jne    11b0 <main+0x40>
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
movsd  0xde4(%rip),%xmm0
divsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
lea    0xddd(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdcf(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"ERROR: Needs exactly 1 argument.\0A\00"
@RAND_MAX = global i64 0
@.str.1 = [11 x i8] c"Pi is: %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
%13 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
store double 0.000000e+00, double* %9
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %10
%24 = call i32 @time(i32* null)
%25 = call i32 @srand(i32 %24)
store i32 0, i32* %11
br label %26
26: ; preds = %50, %19
%27 = load i32, i32* %11
%28 = load i32, i32* %10
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %53
30: ; preds = %26
%31 = call double (...) @rand()
%32 = load i64, i64* @RAND_MAX
%33 = sitofp i64 %32 to double
%34 = fdiv double %31, %33
store double %34, double* %12
%35 = call double (...) @rand()
%36 = load i64, i64* @RAND_MAX
%37 = sitofp i64 %36 to double
%38 = fdiv double %35, %37
store double %38, double* %13
%39 = load double, double* %12
%40 = load double, double* %12
%41 = load double, double* %13
%42 = load double, double* %13
%43 = fmul double %41, %42
%44 = call double @llvm.fmuladd.f64(double %39, double %40, double %43)
%45 = fcmp ole double %44, 1.000000e+00
%46 = zext i1 %45 to i32
%47 = sitofp i32 %46 to double
%48 = load double, double* %9
%49 = fadd double %48, %47
store double %49, double* %9
br label %50
50: ; preds = %30
%51 = load i32, i32* %11
%52 = add nsw i32 %51, 1
store i32 %52, i32* %11
br label %26
53: ; preds = %26
%54 = load i32, i32* %10
%55 = sitofp i32 %54 to double
%56 = fdiv double 4.000000e+00, %55
%57 = load double, double* %9
%58 = fmul double %57, %56
store double %58, double* %9
%59 = load double, double* %9
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %59)
ret i32 0
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
@.str.1 = [11 x i8] c"Pi is: %f\0A\00"
@str = [33 x i8] c"ERROR: Needs exactly 1 argument.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = tail call i32 @time(i32* null)
%12 = tail call i32 @srand(i32 %11)
%13 = icmp sgt i32 %10, 0
br i1 %13, label %20, label %14
14: ; preds = %20, %7
%15 = phi double [ 0.000000e+00, %7 ], [ %35, %20 ]
%16 = sitofp i32 %10 to double
%17 = fdiv double 4.000000e+00, %16
%18 = fmul double %17, %15
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %18)
ret i32 0
20: ; preds = %7, %20
%21 = phi double [ %35, %20 ], [ 0.000000e+00, %7 ]
%22 = phi i32 [ %36, %20 ], [ 0, %7 ]
%23 = tail call double (...) @rand()
%24 = load i64, i64* @RAND_MAX
%25 = sitofp i64 %24 to double
%26 = fdiv double %23, %25
%27 = tail call double (...) @rand()
%28 = load i64, i64* @RAND_MAX
%29 = sitofp i64 %28 to double
%30 = fdiv double %27, %29
%31 = fmul double %30, %30
%32 = tail call double @llvm.fmuladd.f64(double %26, double %26, double %31)
%33 = fcmp ole double %32, 1.000000e+00
%34 = uitofp i1 %33 to double
%35 = fadd double %21, %34
%36 = add nuw nsw i32 %22, 1
%37 = icmp eq i32 %36, %10
br i1 %37, label %14, label %20
}