#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 dboard(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ srandom(int);
int main(int argc, char *argv[]) {
  double pi;
  double avepi;
  int i, n;
  printf("Starting serial version of pi calculation using dartboard "
         "algorithm...\n");
  srandom(5);
  avepi = 0;
  for (i = 0; i < 1; i++) {
    pi = dboard(1);
    avepi = ((avepi * i) + pi) / (i + 1);
    printf("   After %3d throws, average value of pi = %10.8f\n", (1 * (i + 1)),
           avepi);
  }
#pragma CIVL __pi = avepi;
  printf("\nReal value of PI: 3.1415926535897 \n");
}


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)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x5,%edi
call   1030 <srandom@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jge    11da <main+0xaa>
mov    $0x1,%edi
call   1040 <dboard@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%esi
add    $0x1,%esi
shl    $0x0,%esi
movsd  -0x20(%rbp),%xmm0
lea    0xe83(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116d <main+0x3d>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xeeb(%rip),%rdi
call   1040 <puts@plt>
mov    $0x5,%edi
call   1030 <srandom@plt>
mov    $0x1,%edi
call   1050 <dboard@plt>
xorpd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
lea    0xe90(%rip),%rdi
mov    $0x1,%esi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xef7(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [72 x i8] c"Starting serial version of pi calculation using dartboard algorithm...\0A\00"
@.str.1 = [51 x i8] c" After %3d throws, average value of pi = %10.8f\0A\00"
@.str.2 = [37 x i8] c"\0AReal value of PI: 3.1415926535897 \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @srandom(i32 5)
store double 0.000000e+00, double* %7
store i32 0, i32* %8
br label %12
12: ; preds = %31, %2
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 1
br i1 %14, label %15, label %34
15: ; preds = %12
%16 = call double @dboard(i32 1)
store double %16, double* %6
%17 = load double, double* %7
%18 = load i32, i32* %8
%19 = sitofp i32 %18 to double
%20 = load double, double* %6
%21 = call double @llvm.fmuladd.f64(double %17, double %19, double %20)
%22 = load i32, i32* %8
%23 = add nsw i32 %22, 1
%24 = sitofp i32 %23 to double
%25 = fdiv double %21, %24
store double %25, double* %7
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
%28 = mul nsw i32 1, %27
%29 = load double, double* %7
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %28, double %29)
br label %31
31: ; preds = %15
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
br label %12
34: ; preds = %12
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str.1 = [51 x i8] c" After %3d throws, average value of pi = %10.8f\0A\00"
@str = [71 x i8] c"Starting serial version of pi calculation using dartboard algorithm...\00"
@str.3 = [36 x i8] c"\0AReal value of PI: 3.1415926535897 \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @srandom(i32 5)
%5 = tail call double @dboard(i32 1)
%6 = fadd double %5, 0.000000e+00
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 1, double %6)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0))
ret i32 0
}