#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__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ RAND_MAX;
int atoi(char *);
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ rand();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  srand(time(NULL));
  if (argc >= 2) {
    int iterations = atoi(argv[1]);
    int i;
    double success, pi;
    clock_t start, end;
    start = clock();
    for (i = 1; i < iterations; i++) {
      double x = 2 * ((double)rand() / (double)RAND_MAX);
      double y = 2 * ((double)rand() / (double)RAND_MAX);
      if (x * x + y * y < 4)
        success++;
    }
    pi = success / i * 4;
    printf("After %d trials, pi = %.10f\n", iterations, pi);
    end = clock();
    double elapsed = (double)(end - start) / CLOCKS_PER_SEC;
    printf("Elapsed time: approximately %.3f seconds.\n", elapsed);
  } else {
    int i;
    double success;
    printf("Simulation will run until the user presses Ctrl-C.\n");
    sleep(1);
    for (i = 1; 1; i++) {
      double x = 2 * ((double)rand() / (double)RAND_MAX);
      double y = 2 * ((double)rand() / (double)RAND_MAX);
      if (x * x + y * y < 4)
        success++;
      double pi = success / i * 4;
      if (i % 1000000 == 0)
        printf("After %d trials, pi = %.10f\n", i, pi);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
cmpl   $0x2,-0x8(%rbp)
jl     12f3 <main+0x183>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x30(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    127e <main+0x10e>
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2sd %rax,%xmm1
mov    0x2dfc(%rip),%rax
cvtsi2sdq (%rax),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe13(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2sd %rax,%xmm1
mov    0x2dcf(%rip),%rax
cvtsi2sdq (%rax),%xmm0
divsd  %xmm0,%xmm1
movsd  0xde6(%rip),%xmm0
mulsd  %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  0xdb1(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    126b <main+0xfb>
movsd  0xdaf(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1270 <main+0x100>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c5 <main+0x55>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xd6c(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
lea    0xd6c(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
sub    -0x30(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d16(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
lea    0xd4e(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    141c <main+0x2ac>
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
movl   $0x1,-0x54(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    1321 <main+0x1b1>
jmp    1417 <main+0x2a7>
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2sd %rax,%xmm1
mov    0x2cac(%rip),%rax
cvtsi2sdq (%rax),%xmm0
divsd  %xmm0,%xmm1
movsd  0xcc3(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2sd %rax,%xmm1
mov    0x2c7f(%rip),%rax
cvtsi2sdq (%rax),%xmm0
divsd  %xmm0,%xmm1
movsd  0xc96(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x68(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm2
movsd  -0x70(%rbp),%xmm0
mulsd  -0x70(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xc61(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    13bb <main+0x24b>
movsd  0xc5f(%rip),%xmm0
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
cvtsi2sdl -0x54(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xc2f(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    -0x54(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1404 <main+0x294>
mov    -0x54(%rbp),%esi
movsd  -0x78(%rbp),%xmm0
lea    0xc1b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1409 <main+0x299>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1312 <main+0x1a2>
jmp    141c <main+0x2ac>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
cmp    $0x2,%ebp
jl     1288 <main+0x108>
mov    0x8(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
cmp    $0x2,%r15d
jl     139b <main+0x21b>
mov    $0x1,%ebx
mov    0x2e0c(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   10a0 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq 0x0(%rbp),%xmm0
divsd  %xmm0,%xmm1
addsd  %xmm1,%xmm1
movapd %xmm1,0x10(%rsp)
xor    %eax,%eax
call   10a0 <rand@plt>
xorps  %xmm2,%xmm2
cvtsi2sd %rax,%xmm2
xorps  %xmm1,%xmm1
cvtsi2sdq 0x0(%rbp),%xmm1
divsd  %xmm1,%xmm2
movapd 0x10(%rsp),%xmm0
addsd  %xmm2,%xmm2
mulsd  %xmm2,%xmm2
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
movapd (%rsp),%xmm2
movapd %xmm2,%xmm1
addsd  0xdb7(%rip),%xmm1
cmpltsd 0xdb6(%rip),%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
add    $0x1,%ebx
movapd %xmm0,(%rsp)
cmp    %ebx,%r15d
jne    11e0 <main+0x60>
xorps  %xmm1,%xmm1
cvtsi2sd %r15d,%xmm1
divsd  %xmm1,%xmm0
mulsd  0xd85(%rip),%xmm0
jmp    13a3 <main+0x223>
lea    0xdd1(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    $0xffffffff,%r12d
mov    0x2d30(%rip),%r15
lea    0xd61(%rip),%r14
jmp    12cd <main+0x14d>
nopl   0x0(%rax)
add    $0x1,%ebx
add    $0xffffffff,%r12d
movapd %xmm0,0x10(%rsp)
mov    %ebx,%eax
imul   $0x431bde83,%rax,%rax
shr    $0x32,%rax
imul   $0xf4240,%eax,%ebp
xor    %eax,%eax
call   10a0 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq (%r15),%xmm0
divsd  %xmm0,%xmm1
addsd  %xmm1,%xmm1
movapd %xmm1,(%rsp)
xor    %eax,%eax
call   10a0 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq (%r15),%xmm1
divsd  %xmm1,%xmm0
addsd  %xmm0,%xmm0
mulsd  %xmm0,%xmm0
movapd (%rsp),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
movapd 0x10(%rsp),%xmm1
movapd %xmm1,%xmm0
addsd  0xcba(%rip),%xmm0
cmpltsd 0xcb9(%rip),%xmm2
andpd  %xmm2,%xmm0
andnpd %xmm1,%xmm2
orpd   %xmm0,%xmm2
movapd %xmm2,%xmm0
add    %r12d,%ebp
jne    12c0 <main+0x140>
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
movapd %xmm0,(%rsp)
movapd (%rsp),%xmm0
divsd  %xmm1,%xmm0
mulsd  0xc83(%rip),%xmm0
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1050 <printf@plt>
movapd (%rsp),%xmm0
jmp    12c0 <main+0x140>
movsd  0xc6d(%rip),%xmm0
lea    0xc6e(%rip),%rdi
mov    %r15d,%esi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2c1b(%rip),%rax
divsd  (%rax),%xmm0
lea    0xc5d(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
@.str = [29 x i8] c"After %d trials, pi = %.10f\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [43 x i8] c"Elapsed time: approximately %.3f seconds.\0A\00"
@.str.2 = [52 x i8] c"Simulation will run until the user presses Ctrl-C.\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 double
%9 = alloca double
%10 = alloca i64
%11 = alloca i64
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca i32
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%20 = call i32 @time(i32* null)
%21 = call i32 @srand(i32 %20)
%22 = load i32, i32* %4
%23 = icmp sge i32 %22, 2
br i1 %23, label %24, label %79
24: ; preds = %2
%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* %6
%29 = call i64 (...) @clock()
store i64 %29, i64* %10
store i32 1, i32* %7
br label %30
30: ; preds = %58, %24
%31 = load i32, i32* %7
%32 = load i32, i32* %6
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %61
34: ; preds = %30
%35 = call i64 (...) @rand()
%36 = sitofp i64 %35 to double
%37 = load i64, i64* @RAND_MAX
%38 = sitofp i64 %37 to double
%39 = fdiv double %36, %38
%40 = fmul double 2.000000e+00, %39
store double %40, double* %12
%41 = call i64 (...) @rand()
%42 = sitofp i64 %41 to double
%43 = load i64, i64* @RAND_MAX
%44 = sitofp i64 %43 to double
%45 = fdiv double %42, %44
%46 = fmul double 2.000000e+00, %45
store double %46, double* %13
%47 = load double, double* %12
%48 = load double, double* %12
%49 = load double, double* %13
%50 = load double, double* %13
%51 = fmul double %49, %50
%52 = call double @llvm.fmuladd.f64(double %47, double %48, double %51)
%53 = fcmp olt double %52, 4.000000e+00
br i1 %53, label %54, label %57
54: ; preds = %34
%55 = load double, double* %8
%56 = fadd double %55, 1.000000e+00
store double %56, double* %8
br label %57
57: ; preds = %54, %34
br label %58
58: ; preds = %57
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
br label %30
61: ; preds = %30
%62 = load double, double* %8
%63 = load i32, i32* %7
%64 = sitofp i32 %63 to double
%65 = fdiv double %62, %64
%66 = fmul double %65, 4.000000e+00
store double %66, double* %9
%67 = load i32, i32* %6
%68 = load double, double* %9
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %67, double %68)
%70 = call i64 (...) @clock()
store i64 %70, i64* %11
%71 = load i64, i64* %11
%72 = load i64, i64* %10
%73 = sub nsw i64 %71, %72
%74 = sitofp i64 %73 to double
%75 = load double, double* @CLOCKS_PER_SEC
%76 = fdiv double %74, %75
store double %76, double* %14
%77 = load double, double* %14
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), double %77)
br label %124
79: ; preds = %2
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
%81 = call i32 @sleep(i32 1)
store i32 1, i32* %15
br label %82
82: ; preds = %120, %79
br i1 true, label %83, label %123
83: ; preds = %82
%84 = call i64 (...) @rand()
%85 = sitofp i64 %84 to double
%86 = load i64, i64* @RAND_MAX
%87 = sitofp i64 %86 to double
%88 = fdiv double %85, %87
%89 = fmul double 2.000000e+00, %88
store double %89, double* %17
%90 = call i64 (...) @rand()
%91 = sitofp i64 %90 to double
%92 = load i64, i64* @RAND_MAX
%93 = sitofp i64 %92 to double
%94 = fdiv double %91, %93
%95 = fmul double 2.000000e+00, %94
store double %95, double* %18
%96 = load double, double* %17
%97 = load double, double* %17
%98 = load double, double* %18
%99 = load double, double* %18
%100 = fmul double %98, %99
%101 = call double @llvm.fmuladd.f64(double %96, double %97, double %100)
%102 = fcmp olt double %101, 4.000000e+00
br i1 %102, label %103, label %106
103: ; preds = %83
%104 = load double, double* %16
%105 = fadd double %104, 1.000000e+00
store double %105, double* %16
br label %106
106: ; preds = %103, %83
%107 = load double, double* %16
%108 = load i32, i32* %15
%109 = sitofp i32 %108 to double
%110 = fdiv double %107, %109
%111 = fmul double %110, 4.000000e+00
store double %111, double* %19
%112 = load i32, i32* %15
%113 = srem i32 %112, 1000000
%114 = icmp eq i32 %113, 0
br i1 %114, label %115, label %119
115: ; preds = %106
%116 = load i32, i32* %15
%117 = load double, double* %19
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %116, double %117)
br label %119
119: ; preds = %115, %106
br label %120
120: ; preds = %119
%121 = load i32, i32* %15
%122 = add nsw i32 %121, 1
store i32 %122, i32* %15
br label %82
123: ; preds = %82
br label %124
124: ; preds = %123, %61
ret i32 0
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
@.str = [29 x i8] c"After %d trials, pi = %.10f\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [43 x i8] c"Elapsed time: approximately %.3f seconds.\0A\00"
@str = [51 x i8] c"Simulation will run until the user presses Ctrl-C.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %47
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = tail call i64 (...) @clock()
%11 = icmp sgt i32 %9, 1
br i1 %11, label %12, label %38
12: ; preds = %6, %12
%13 = phi i32 [ %32, %12 ], [ 1, %6 ]
%14 = phi double [ %31, %12 ], [ undef, %6 ]
%15 = tail call i64 (...) @rand()
%16 = sitofp i64 %15 to double
%17 = load i64, i64* @RAND_MAX
%18 = sitofp i64 %17 to double
%19 = fdiv double %16, %18
%20 = fmul double %19, 2.000000e+00
%21 = tail call i64 (...) @rand()
%22 = sitofp i64 %21 to double
%23 = load i64, i64* @RAND_MAX
%24 = sitofp i64 %23 to double
%25 = fdiv double %22, %24
%26 = fmul double %25, 2.000000e+00
%27 = fmul double %26, %26
%28 = tail call double @llvm.fmuladd.f64(double %20, double %20, double %27)
%29 = fcmp olt double %28, 4.000000e+00
%30 = fadd double %14, 1.000000e+00
%31 = select i1 %29, double %30, double %14
%32 = add nuw nsw i32 %13, 1
%33 = icmp eq i32 %32, %9
br i1 %33, label %34, label %12
34: ; preds = %12
%35 = sitofp i32 %9 to double
%36 = fdiv double %31, %35
%37 = fmul double %36, 4.000000e+00
br label %38
38: ; preds = %34, %6
%39 = phi double [ %37, %34 ], [ 0x7FF8000000000000, %6 ]
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %9, double %39)
%41 = tail call i64 (...) @clock()
%42 = sub nsw i64 %41, %10
%43 = sitofp i64 %42 to double
%44 = load double, double* @CLOCKS_PER_SEC
%45 = fdiv double %43, %44
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), double %45)
ret i32 0
47: ; preds = %2
%48 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
%49 = tail call i32 @sleep(i32 1)
br label %50
50: ; preds = %77, %47
%51 = phi double [ undef, %47 ], [ %69, %77 ]
%52 = phi i32 [ 1, %47 ], [ %78, %77 ]
%53 = tail call i64 (...) @rand()
%54 = sitofp i64 %53 to double
%55 = load i64, i64* @RAND_MAX
%56 = sitofp i64 %55 to double
%57 = fdiv double %54, %56
%58 = fmul double %57, 2.000000e+00
%59 = tail call i64 (...) @rand()
%60 = sitofp i64 %59 to double
%61 = load i64, i64* @RAND_MAX
%62 = sitofp i64 %61 to double
%63 = fdiv double %60, %62
%64 = fmul double %63, 2.000000e+00
%65 = fmul double %64, %64
%66 = tail call double @llvm.fmuladd.f64(double %58, double %58, double %65)
%67 = fcmp olt double %66, 4.000000e+00
%68 = fadd double %51, 1.000000e+00
%69 = select i1 %67, double %68, double %51
%70 = urem i32 %52, 1000000
%71 = icmp eq i32 %70, 0
br i1 %71, label %72, label %77
72: ; preds = %50
%73 = sitofp i32 %52 to double
%74 = fdiv double %69, %73
%75 = fmul double %74, 4.000000e+00
%76 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %52, double %75)
br label %77
77: ; preds = %72, %50
%78 = add nuw nsw i32 %52, 1
br label %50
}