#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 int /*<<< orphan*/ n;
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ M_PI;
scalar_t__ RAND_MAX;
scalar_t__ clock();
int /*<<< orphan*/ fabs(scalar_t__);
int /*<<< orphan*/ printf(char *, unsigned long, scalar_t__, double,
                          int /*<<< orphan*/, double);
scalar_t__ rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int main(void) {
  double pi;
  unsigned long i, j, k;
  unsigned long n[] = {100,     1000,     10000,     100000,
                       1000000, 10000000, 100000000, 1000000000};
  double x = 0.0;
  double y = 0.0;
  srand(time(0));
  clock_t begin, end;
  double time_spent;
  for (j = 0; j < sizeof(n) / sizeof(n[0]); ++j) {
    i = 0;
    begin = clock();
    for (k = 0; k < n[j]; ++k) {
      x = ((double)rand() + 1) / (double)RAND_MAX;
      y = ((double)rand() + 1) / (double)RAND_MAX;
      if ((x * x + y * y) <= 1.0) {
        ++i;
      }
    }
    pi = i / ((double)n[j]) * 4;
    end = clock();
    time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
    printf("Iterationen %10ld Werte: Pi: %f, berechneter Wert: %f, Differenz: "
           "%e, Laufzeit: %2.8f\n",
           n[j], M_PI, pi, fabs(M_PI - pi), time_spent);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xea3(%rip),%rsi
mov    $0x40,%edx
call   1070 <memcpy@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x80(%rbp)
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movq   $0x0,-0x20(%rbp)
cmpq   $0x8,-0x20(%rbp)
jae    13b6 <main+0x246>
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x88(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
cmp    -0x70(%rbp,%rcx,8),%rax
jae    12a3 <main+0x133>
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2sd %rax,%xmm0
movsd  0xdfb(%rip),%xmm1
addsd  %xmm1,%xmm0
mov    0x2dc0(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2sd %rax,%xmm0
movsd  0xdce(%rip),%xmm1
addsd  %xmm1,%xmm0
mov    0x2d93(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x78(%rbp),%xmm1
movsd  -0x78(%rbp),%xmm2
movsd  -0x80(%rbp),%xmm0
mulsd  -0x80(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xd91(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     128d <main+0x11d>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1292 <main+0x122>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11e6 <main+0x76>
movq   -0x18(%rbp),%xmm0
movaps 0xd61(%rip),%xmm3
punpckldq %xmm3,%xmm0
movapd 0xd65(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movq   -0x70(%rbp,%rax,8),%xmm1
punpckldq %xmm3,%xmm1
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  0xd0d(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rax
sub    -0x88(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2cbc(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
mov    -0x20(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rax
mov    %rax,-0xb0(%rbp)
mov    0x2ca1(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0xa8(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
mov    0x2c83(%rip),%rax
cvtsi2sdq (%rax),%xmm0
subsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%rdi
call   1060 <fabs@plt>
mov    -0xb0(%rbp),%rsi
mov    -0xa8(%rbp),%rdx
movsd  -0xa0(%rbp),%xmm0
ff
mov    %eax,%ecx
movsd  -0x98(%rbp),%xmm1
ff
lea    0xcd0(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11bd <main+0x4d>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    0x2e55(%rip),%rbp
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r15
lea    0xe8f(%rip),%rax
mov    (%rax,%r13,8),%r12
cmp    $0x2,%r12
mov    $0x1,%ebx
cmovae %r12,%rbx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1080 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
movsd  0xe29(%rip),%xmm0
addsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq 0x0(%rbp),%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0xdfc(%rip),%xmm2
addsd  %xmm2,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq 0x0(%rbp),%xmm1
divsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm0
movsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
ucomisd %xmm1,%xmm2
sbb    $0xffffffffffffffff,%r14
add    $0xffffffffffffffff,%rbx
jne    11c0 <main+0x60>
movq   %r14,%xmm0
movdqa 0xdcf(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xdd3(%rip),%xmm2
subpd  %xmm2,%xmm0
movapd %xmm0,%xmm3
unpckhpd %xmm0,%xmm3
addsd  %xmm0,%xmm3
movq   %r12,%xmm0
punpckldq %xmm1,%xmm0
subpd  %xmm2,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
divsd  %xmm1,%xmm3
mulsd  0xd86(%rip),%xmm3
movapd %xmm3,(%rsp)
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r15,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2d40(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    0x2d37(%rip),%rax
mov    (%rax),%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
subsd  (%rsp),%xmm0
cvttsd2si %xmm0,%rdi
call   1060 <fabs@plt>
lea    0xd9e(%rip),%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
movapd (%rsp),%xmm0
mov    %eax,%ecx
movsd  0x10(%rsp),%xmm1
call   1040 <printf@plt>
add    $0x1,%r13
cmp    $0x8,%r13
jne    1190 <main+0x30>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.n = [8 x i64] [i64 100, i64 1000, i64 10000, i64 100000, i64 1000000, i64 10000000, i64 100000000, i64 1000000000]
@RAND_MAX = global i64 0
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [87 x i8] c"Iterationen %10ld Werte: Pi: %f, berechneter Wert: %f, Differenz: %e, Laufzeit: %2.8f\0A\00"
@M_PI = global i64 0
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca [8 x i64]
%7 = alloca double
%8 = alloca double
%9 = alloca i64
%10 = alloca i64
%11 = alloca double
store i32 0, i32* %1
%12 = bitcast [8 x i64]* %6 to i8*
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
%13 = call i32 @time(i32 0)
%14 = call i32 @srand(i32 %13)
store i64 0, i64* %4
br label %15
15: ; preds = %82, %0
%16 = load i64, i64* %4
%17 = icmp ult i64 %16, 8
br i1 %17, label %18, label %85
18: ; preds = %15
store i64 0, i64* %3
%19 = call i64 (...) @clock()
store i64 %19, i64* %9
store i64 0, i64* %5
br label %20
20: ; preds = %50, %18
%21 = load i64, i64* %5
%22 = load i64, i64* %4
%23 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 %22
%24 = load i64, i64* %23
%25 = icmp ult i64 %21, %24
br i1 %25, label %26, label %53
26: ; preds = %20
%27 = call i64 (...) @rand()
%28 = sitofp i64 %27 to double
%29 = fadd double %28, 1.000000e+00
%30 = load i64, i64* @RAND_MAX
%31 = sitofp i64 %30 to double
%32 = fdiv double %29, %31
store double %32, double* %7
%33 = call i64 (...) @rand()
%34 = sitofp i64 %33 to double
%35 = fadd double %34, 1.000000e+00
%36 = load i64, i64* @RAND_MAX
%37 = sitofp i64 %36 to double
%38 = fdiv double %35, %37
store double %38, double* %8
%39 = load double, double* %7
%40 = load double, double* %7
%41 = load double, double* %8
%42 = load double, double* %8
%43 = fmul double %41, %42
%44 = call double @llvm.fmuladd.f64(double %39, double %40, double %43)
%45 = fcmp ole double %44, 1.000000e+00
br i1 %45, label %46, label %49
46: ; preds = %26
%47 = load i64, i64* %3
%48 = add i64 %47, 1
store i64 %48, i64* %3
br label %49
49: ; preds = %46, %26
br label %50
50: ; preds = %49
%51 = load i64, i64* %5
%52 = add i64 %51, 1
store i64 %52, i64* %5
br label %20
53: ; preds = %20
%54 = load i64, i64* %3
%55 = uitofp i64 %54 to double
%56 = load i64, i64* %4
%57 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 %56
%58 = load i64, i64* %57
%59 = uitofp i64 %58 to double
%60 = fdiv double %55, %59
%61 = fmul double %60, 4.000000e+00
store double %61, double* %2
%62 = call i64 (...) @clock()
store i64 %62, i64* %10
%63 = load i64, i64* %10
%64 = load i64, i64* %9
%65 = sub nsw i64 %63, %64
%66 = sitofp i64 %65 to double
%67 = load double, double* @CLOCKS_PER_SEC
%68 = fdiv double %66, %67
store double %68, double* %11
%69 = load i64, i64* %4
%70 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 %69
%71 = load i64, i64* %70
%72 = load i64, i64* @M_PI
%73 = load double, double* %2
%74 = load i64, i64* @M_PI
%75 = sitofp i64 %74 to double
%76 = load double, double* %2
%77 = fsub double %75, %76
%78 = fptosi double %77 to i64
%79 = call i32 @fabs(i64 %78)
%80 = load double, double* %11
%81 = call i32 @printf(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0), i64 %71, i64 %72, double %73, i32 %79, double %80)
br label %82
82: ; preds = %53
%83 = load i64, i64* %4
%84 = add i64 %83, 1
store i64 %84, i64* %4
br label %15
85: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@__const.main.n = [8 x i64] [i64 100, i64 1000, i64 10000, i64 100000, i64 1000000, i64 10000000, i64 100000000, i64 1000000000]
@RAND_MAX = global i64 0
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [87 x i8] c"Iterationen %10ld Werte: Pi: %f, berechneter Wert: %f, Differenz: %e, Laufzeit: %2.8f\0A\00"
@M_PI = global i64 0
define i32 @main() {
%1 = tail call i32 @time(i32 0)
%2 = tail call i32 @srand(i32 %1)
br label %3
3: ; preds = %31, %0
%4 = phi i64 [ 0, %0 ], [ %47, %31 ]
%5 = tail call i64 (...) @clock()
%6 = getelementptr inbounds [8 x i64], [8 x i64]* @__const.main.n, i64 0, i64 %4
%7 = load i64, i64* %6
%8 = call i64 @llvm.umax.i64(i64 %7, i64 1)
br label %9
9: ; preds = %3, %9
%10 = phi i64 [ %28, %9 ], [ 0, %3 ]
%11 = phi i64 [ %29, %9 ], [ 0, %3 ]
%12 = tail call i64 (...) @rand()
%13 = sitofp i64 %12 to double
%14 = fadd double %13, 1.000000e+00
%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 = fadd double %19, 1.000000e+00
%21 = load i64, i64* @RAND_MAX
%22 = sitofp i64 %21 to double
%23 = fdiv double %20, %22
%24 = fmul double %23, %23
%25 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %24)
%26 = fcmp ole double %25, 1.000000e+00
%27 = zext i1 %26 to i64
%28 = add i64 %10, %27
%29 = add nuw i64 %11, 1
%30 = icmp eq i64 %29, %8
br i1 %30, label %31, label %9
31: ; preds = %9
%32 = uitofp i64 %28 to double
%33 = uitofp i64 %7 to double
%34 = fdiv double %32, %33
%35 = fmul double %34, 4.000000e+00
%36 = tail call i64 (...) @clock()
%37 = sub nsw i64 %36, %5
%38 = sitofp i64 %37 to double
%39 = load double, double* @CLOCKS_PER_SEC
%40 = fdiv double %38, %39
%41 = load i64, i64* @M_PI
%42 = sitofp i64 %41 to double
%43 = fsub double %42, %35
%44 = fptosi double %43 to i64
%45 = tail call i32 @fabs(i64 %44)
%46 = tail call i32 @printf(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0), i64 %7, i64 %41, double %35, i32 %45, double %40)
%47 = add nuw nsw i64 %4, 1
%48 = icmp eq i64 %47, 8
br i1 %48, label %49, label %3
49: ; preds = %31
ret i32 0
}