main(argc, argv) int argc;
char *argv[];
{
  int in, n, in_old, n_old;
  double pi, error, stderror, p = 3.141592653589793238462643 / 4.0;
  char filename[80];
  initialize(&n, &in_old, &n_old, filename);
  in = count_in_circle(n);
  in += in_old;
  n += n_old;
  pi = (4.0 * in) / n;
  error = fabs(pi - 3.141592653589793238462643);
  stderror = 4 * sqrt(p * (1.0 - p) / n);
  printf("pi is estimated as %18.16f from %12d samples.\n", pi, n);
  printf("\tError = %10.8g, standard error = %10.8g\n", error, stderror);
  save_state(filename, in, n);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  0xeae(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
lea    -0x90(%rbp),%rcx
lea    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1050 <initialize@plt>
mov    -0x18(%rbp),%edi
mov    $0x0,%al
call   1040 <count_in_circle@plt>
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xe4b(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe3c(%rip),%xmm1
subsd  %xmm1,%xmm0
movaps 0xe41(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xe13(%rip),%xmm1
subsd  -0x40(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xde9(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%esi
lea    0xe01(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
lea    0xe18(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    $0x0,%al
call   1060 <save_state@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
lea    0xc(%rsp),%rdi
lea    0x1c(%rsp),%rsi
lea    0x18(%rsp),%rdx
lea    0x30(%rsp),%rcx
xor    %eax,%eax
call   1050 <initialize@plt>
mov    0xc(%rsp),%edi
xor    %eax,%eax
call   1040 <count_in_circle@plt>
mov    %eax,%ebx
add    0x1c(%rsp),%ebx
mov    0xc(%rsp),%eax
add    0x18(%rsp),%eax
mov    %eax,0xc(%rsp)
cvtsi2sd %ebx,%xmm2
mulsd  0xe64(%rip),%xmm2
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm2
movsd  0xe5c(%rip),%xmm0
addsd  %xmm2,%xmm0
andpd  0xe68(%rip),%xmm0
movapd %xmm0,0x20(%rsp)
movsd  0xe4a(%rip),%xmm0
divsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11da <main+0x8a>
sqrtsd %xmm0,%xmm0
jmp    11eb <main+0x9b>
movsd  %xmm2,0x10(%rsp)
call   1070 <sqrt@plt>
movsd  0x10(%rsp),%xmm2
mulsd  0xe0d(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    0xc(%rsp),%esi
lea    0xe2c(%rip),%rdi
movapd %xmm2,%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xe49(%rip),%rdi
movaps 0x20(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    $0x2,%al
call   1030 <printf@plt>
mov    0xc(%rsp),%edx
lea    0x30(%rsp),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <save_state@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [47 x i8] c"pi is estimated as %18.16f from %12d samples.\0A\00"
@.str.1 = [42 x i8] c"\09Error = %10.8g, standard error = %10.8g\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca [80 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
store double 0x3FE921FB54442D18, double* %12
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%15 = call i32 (i32*, i32*, i32*, i8*, ...) bitcast (i32 (...)* @initialize to i32 (i32*, i32*, i32*, i8*, ...)*)(i32* %6, i32* %7, i32* %8, i8* %14)
%16 = load i32, i32* %6
%17 = call i32 (i32, ...) bitcast (i32 (...)* @count_in_circle to i32 (i32, ...)*)(i32 %16)
store i32 %17, i32* %5
%18 = load i32, i32* %7
%19 = load i32, i32* %5
%20 = add nsw i32 %19, %18
store i32 %20, i32* %5
%21 = load i32, i32* %8
%22 = load i32, i32* %6
%23 = add nsw i32 %22, %21
store i32 %23, i32* %6
%24 = load i32, i32* %5
%25 = sitofp i32 %24 to double
%26 = fmul double 4.000000e+00, %25
%27 = load i32, i32* %6
%28 = sitofp i32 %27 to double
%29 = fdiv double %26, %28
store double %29, double* %9
%30 = load double, double* %9
%31 = fsub double %30, 0x400921FB54442D18
%32 = call double @llvm.fabs.f64(double %31)
store double %32, double* %10
%33 = load double, double* %12
%34 = load double, double* %12
%35 = fsub double 1.000000e+00, %34
%36 = fmul double %33, %35
%37 = load i32, i32* %6
%38 = sitofp i32 %37 to double
%39 = fdiv double %36, %38
%40 = call double @sqrt(double %39)
%41 = fmul double 4.000000e+00, %40
store double %41, double* %11
%42 = load double, double* %9
%43 = load i32, i32* %6
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), double %42, i32 %43)
%45 = load double, double* %10
%46 = load double, double* %11
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), double %45, double %46)
%48 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%49 = load i32, i32* %5
%50 = load i32, i32* %6
%51 = call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @save_state to i32 (i8*, i32, i32, ...)*)(i8* %48, i32 %49, i32 %50)
ret i32 0
}

LLVM IR (-O2):
@.str = [47 x i8] c"pi is estimated as %18.16f from %12d samples.\0A\00"
@.str.1 = [42 x i8] c"\09Error = %10.8g, standard error = %10.8g\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [80 x i8]
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%11 = call i32 (i32*, i32*, i32*, i8*, ...) bitcast (i32 (...)* @initialize to i32 (i32*, i32*, i32*, i8*, ...)*)(i32* %3, i32* %4, i32* %5, i8* %10)
%12 = load i32, i32* %3
%13 = call i32 (i32, ...) bitcast (i32 (...)* @count_in_circle to i32 (i32, ...)*)(i32 %12)
%14 = load i32, i32* %4
%15 = add nsw i32 %14, %13
%16 = load i32, i32* %5
%17 = load i32, i32* %3
%18 = add nsw i32 %17, %16
store i32 %18, i32* %3
%19 = sitofp i32 %15 to double
%20 = fmul double %19, 4.000000e+00
%21 = sitofp i32 %18 to double
%22 = fdiv double %20, %21
%23 = fadd double %22, 0xC00921FB54442D18
%24 = call double @llvm.fabs.f64(double %23)
%25 = fdiv double 0x3FC592FA2A179CE8, %21
%26 = call double @sqrt(double %25)
%27 = fmul double %26, 4.000000e+00
%28 = load i32, i32* %3
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), double %22, i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), double %24, double %27)
%31 = load i32, i32* %3
%32 = call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @save_state to i32 (i8*, i32, i32, ...)*)(i8* %10, i32 %15, i32 %31)
ret i32 0
}