#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ rand();
int /*<<< orphan*/ scanf(char *, unsigned int *);
int /*<<< orphan*/ srand(unsigned int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int i;
  int num;
  int n;
  double x, y;
  double pi;
  unsigned int seed;
  if (argc == 1) {
    fprintf(stderr, "Input argument.\n");
    return -1;
  }
  if (argc > 2) {
    fprintf(stderr, "One input argument.\n");
    return -1;
  }
  num = atoi(argv[1]);
  printf("seed = ");
  scanf("%d", &seed);
  srand(seed);
  n = 0.0;
  for (i = 0; i <= num; i++) {
    x = ((double)rand()) / ((double)RAND_MAX + 1.0);
    y = ((double)rand()) / ((double)RAND_MAX + 1.0);
    if ((x * x + y * y) < 1.0) {
      n++;
    }
  }
  pi = (double)n / (double)num * 4.0;
  printf("%f\n", pi);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11a1 <main+0x41>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f9 <main+0x199>
cmpl   $0x2,-0x8(%rbp)
jle    11cc <main+0x6c>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f9 <main+0x199>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe4d(%rip),%rdi
lea    -0x3c(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x3c(%rbp),%edi
call   1040 <srand@plt>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     12c0 <main+0x160>
mov    $0x0,%al
call   1080 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2db9(%rip),%rax
cvtsi2sdq (%rax),%xmm1
movsd  0xdcc(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1080 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2d8c(%rip),%rax
cvtsi2sdq (%rax),%xmm1
movsd  0xd9f(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xd6e(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    12ad <main+0x14d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12b2 <main+0x152>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1210 <main+0xb0>
cvtsi2sdl -0x1c(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xd2a(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    0xd56(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x1,%edi
jne    1181 <main+0x21>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
jmp    1196 <main+0x36>
cmp    $0x3,%edi
jl     11a5 <main+0x45>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1297 <main+0x137>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%r14d
lea    0xe7e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe78(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%edi
call   1040 <srand@plt>
test   %r14d,%r14d
js     126f <main+0x10f>
lea    0x1(%r14),%ebp
mov    0x2dfb(%rip),%r15
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   1080 <rand@plt>
xorps  %xmm2,%xmm2
cvtsi2sd %rax,%xmm2
xorps  %xmm0,%xmm0
cvtsi2sdq (%r15),%xmm0
movsd  0xdf1(%rip),%xmm1
addsd  %xmm1,%xmm0
divsd  %xmm0,%xmm2
movsd  %xmm2,0x10(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sdq (%r15),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
movsd  0xdc4(%rip),%xmm2
addsd  %xmm2,%xmm0
divsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
xor    %eax,%eax
ucomisd %xmm0,%xmm2
seta   %al
add    %eax,%ebx
add    $0xffffffff,%ebp
jne    11f0 <main+0x90>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
jmp    1273 <main+0x113>
xorpd  %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
divsd  %xmm1,%xmm0
mulsd  0xd81(%rip),%xmm0
lea    0xdb3(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"Input argument.\0A\00"
@.str.1 = [21 x i8] c"One input argument.\0A\00"
@.str.2 = [8 x i8] c"seed = \00"
@.str.3 = [3 x i8] c"%d\00"
@RAND_MAX = global i64 0
@.str.4 = [4 x i8] c"%f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %73
18: ; preds = %2
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 2
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %73
24: ; preds = %18
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %12)
%31 = load i32, i32* %12
%32 = call i32 @srand(i32 %31)
store i32 0, i32* %8
store i32 0, i32* %6
br label %33
33: ; preds = %61, %24
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = icmp sle i32 %34, %35
br i1 %36, label %37, label %64
37: ; preds = %33
%38 = call i64 (...) @rand()
%39 = sitofp i64 %38 to double
%40 = load i64, i64* @RAND_MAX
%41 = sitofp i64 %40 to double
%42 = fadd double %41, 1.000000e+00
%43 = fdiv double %39, %42
store double %43, double* %9
%44 = call i64 (...) @rand()
%45 = sitofp i64 %44 to double
%46 = load i64, i64* @RAND_MAX
%47 = sitofp i64 %46 to double
%48 = fadd double %47, 1.000000e+00
%49 = fdiv double %45, %48
store double %49, double* %10
%50 = load double, double* %9
%51 = load double, double* %9
%52 = load double, double* %10
%53 = load double, double* %10
%54 = fmul double %52, %53
%55 = call double @llvm.fmuladd.f64(double %50, double %51, double %54)
%56 = fcmp olt double %55, 1.000000e+00
br i1 %56, label %57, label %60
57: ; preds = %37
%58 = load i32, i32* %8
%59 = add nsw i32 %58, 1
store i32 %59, i32* %8
br label %60
60: ; preds = %57, %37
br label %61
61: ; preds = %60
%62 = load i32, i32* %6
%63 = add nsw i32 %62, 1
store i32 %63, i32* %6
br label %33
64: ; preds = %33
%65 = load i32, i32* %8
%66 = sitofp i32 %65 to double
%67 = load i32, i32* %7
%68 = sitofp i32 %67 to double
%69 = fdiv double %66, %68
%70 = fmul double %69, 4.000000e+00
store double %70, double* %11
%71 = load double, double* %11
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double %71)
store i32 0, i32* %3
br label %73
73: ; preds = %64, %21, %15
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"Input argument.\0A\00"
@.str.1 = [21 x i8] c"One input argument.\0A\00"
@.str.2 = [8 x i8] c"seed = \00"
@.str.3 = [3 x i8] c"%d\00"
@RAND_MAX = global i64 0
@.str.4 = [4 x i8] c"%f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %53
9: ; preds = %2
%10 = icmp sgt i32 %0, 2
br i1 %10, label %11, label %14
11: ; preds = %9
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %53
14: ; preds = %9
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%20 = load i32, i32* %3
%21 = call i32 @srand(i32 %20)
%22 = icmp slt i32 %17, 0
br i1 %22, label %47, label %23
23: ; preds = %14, %23
%24 = phi i32 [ %43, %23 ], [ 0, %14 ]
%25 = phi i32 [ %42, %23 ], [ 0, %14 ]
%26 = call i64 (...) @rand()
%27 = sitofp i64 %26 to double
%28 = load i64, i64* @RAND_MAX
%29 = sitofp i64 %28 to double
%30 = fadd double %29, 1.000000e+00
%31 = fdiv double %27, %30
%32 = call i64 (...) @rand()
%33 = sitofp i64 %32 to double
%34 = load i64, i64* @RAND_MAX
%35 = sitofp i64 %34 to double
%36 = fadd double %35, 1.000000e+00
%37 = fdiv double %33, %36
%38 = fmul double %37, %37
%39 = call double @llvm.fmuladd.f64(double %31, double %31, double %38)
%40 = fcmp olt double %39, 1.000000e+00
%41 = zext i1 %40 to i32
%42 = add nuw nsw i32 %25, %41
%43 = add nuw i32 %24, 1
%44 = icmp eq i32 %24, %17
br i1 %44, label %45, label %23
45: ; preds = %23
%46 = sitofp i32 %42 to double
br label %47
47: ; preds = %45, %14
%48 = phi double [ 0.000000e+00, %14 ], [ %46, %45 ]
%49 = sitofp i32 %17 to double
%50 = fdiv double %48, %49
%51 = fmul double %50, 4.000000e+00
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double %51)
br label %53
53: ; preds = %47, %11, %6
%54 = phi i32 [ -1, %6 ], [ -1, %11 ], [ 0, %47 ]
ret i32 %54
}