#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 pow(int, int);
int /*<<< orphan*/ printf(char *, int, double);
scalar_t__ rand();
double sqrt(double);
int main() {
  double x, y, r;
  int i, n;
  int red[5] = {0};
  double pi[5] = {0.0};
  for (n = 0; n <= 4; n++) {
    for (i = 0; i < pow(10, n + 1); i++) {
      x = ((double)rand() / (double)RAND_MAX);
      y = ((double)rand() / (double)RAND_MAX);
      if (sqrt(x * x + y * y) <= 1.0) {
        red[n] = red[n] + 1;
      }
    }
    pi[n] = 4.0 * (double)red[n] / (double)pow(10, n + 1);
    printf("%d   %.12e\n", (int)pow(10, n + 1), pi[n]);
  }
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x4,-0x28(%rbp)
jg     12d3 <main+0x183>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x28(%rbp),%esi
add    $0x1,%esi
mov    $0xa,%edi
call   1050 <pow@plt>
mov    %eax,%ecx
mov    -0x74(%rbp),%eax
cmp    %ecx,%eax
jge    125b <main+0x10b>
mov    $0x0,%al
call   1070 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e18(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2df7(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xddd(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     1248 <main+0xf8>
movslq -0x28(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%ecx
add    $0x1,%ecx
movslq -0x28(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,4)
jmp    124d <main+0xfd>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119a <main+0x4a>
movslq -0x28(%rbp),%rax
cvtsi2sdl -0x40(%rbp,%rax,4),%xmm1
movsd  0xd93(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
mov    -0x28(%rbp),%esi
add    $0x1,%esi
mov    $0xa,%edi
call   1050 <pow@plt>
movsd  -0x80(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movslq -0x28(%rbp),%rax
movsd  %xmm0,-0x70(%rbp,%rax,8)
mov    -0x28(%rbp),%esi
add    $0x1,%esi
mov    $0xa,%edi
call   1050 <pow@plt>
mov    %eax,%esi
movslq -0x28(%rbp),%rax
movsd  -0x70(%rbp,%rax,8),%xmm0
lea    0xd50(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1189 <main+0x39>
mov    $0xffffffff,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
xorpd  %xmm0,%xmm0
movapd %xmm0,0x10(%rsp)
movl   $0x0,0x20(%rsp)
mov    0x2e83(%rip),%r15
lea    0xeac(%rip),%r14
xor    %r12d,%r12d
jmp    11e4 <main+0xa4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sdl 0x10(%rsp,%r12,4),%xmm0
mulsd  0xe76(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0xa,%edi
mov    %ebx,%esi
call   1040 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    $0xa,%edi
mov    %ebx,%esi
call   1040 <pow@plt>
mov    %r14,%rdi
mov    %eax,%esi
movsd  0x8(%rsp),%xmm0
call   1030 <printf@plt>
mov    %rbx,%r12
cmp    $0x5,%rbx
je     12a2 <main+0x162>
lea    0x1(%r12),%rbx
mov    $0xa,%edi
mov    %ebx,%esi
call   1040 <pow@plt>
test   %eax,%eax
jle    1180 <main+0x40>
xor    %ebp,%ebp
jmp    1217 <main+0xd7>
nopl   (%rax)
add    $0x1,%ebp
mov    $0xa,%edi
mov    %ebx,%esi
call   1040 <pow@plt>
cmp    %eax,%ebp
jge    1180 <main+0x40>
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq (%r15),%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq (%r15),%xmm1
divsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
ucomisd 0xd9f(%rip),%xmm1
jb     1280 <main+0x140>
sqrtsd %xmm0,%xmm0
jmp    1285 <main+0x145>
nopl   0x0(%rax)
call   1050 <sqrt@plt>
movsd  0xd73(%rip),%xmm1
ucomisd %xmm0,%xmm1
jb     1200 <main+0xc0>
addl   $0x1,0x10(%rsp,%r12,4)
jmp    1200 <main+0xc0>
mov    $0xffffffff,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@RAND_MAX = global i64 0
@.str = [12 x i8] c"%d %.12e\0A\00"
define i32 @main() {
%1 = alloca [5 x i32]
%2 = bitcast [5 x i32]* %1 to i8*
br label %3
3: ; preds = %0, %34
%4 = phi i64 [ 0, %0 ], [ %5, %34 ]
%5 = add nuw nsw i64 %4, 1
%6 = trunc i64 %5 to i32
%7 = tail call i32 @pow(i32 10, i32 %6)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %34
9: ; preds = %3
%10 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %4
br label %11
11: ; preds = %9, %30
%12 = phi i32 [ 0, %9 ], [ %31, %30 ]
%13 = tail call i64 (...) @rand()
%14 = sitofp i64 %13 to double
%15 = load i64, i64* @RAND_MAX
%16 = sitofp i64 %15 to double
%17 = fdiv double %14, %16
%18 = tail call i64 (...) @rand()
%19 = sitofp i64 %18 to double
%20 = load i64, i64* @RAND_MAX
%21 = sitofp i64 %20 to double
%22 = fdiv double %19, %21
%23 = fmul double %22, %22
%24 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %23)
%25 = tail call double @sqrt(double %24)
%26 = fcmp ugt double %25, 1.000000e+00
br i1 %26, label %30, label %27
27: ; preds = %11
%28 = load i32, i32* %10
%29 = add nsw i32 %28, 1
store i32 %29, i32* %10
br label %30
30: ; preds = %11, %27
%31 = add nuw nsw i32 %12, 1
%32 = tail call i32 @pow(i32 10, i32 %6)
%33 = icmp slt i32 %31, %32
br i1 %33, label %11, label %34
34: ; preds = %30, %3
%35 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %4
%36 = load i32, i32* %35
%37 = sitofp i32 %36 to double
%38 = fmul double %37, 4.000000e+00
%39 = tail call i32 @pow(i32 10, i32 %6)
%40 = sitofp i32 %39 to double
%41 = fdiv double %38, %40
%42 = tail call i32 @pow(i32 10, i32 %6)
%43 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %42, double %41)
%44 = icmp eq i64 %5, 5
br i1 %44, label %45, label %3
45: ; preds = %34
ret i32 -1
}