#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 **constructMatrix(double **, int);
double **matrixAlocation(int);
int /*<<< orphan*/ matrixCalculation(double **, double **, double **, int,
                                     double *, int);
double **matrixDisallocation(int, double **);
int /*<<< orphan*/ outputPrinter(double **, int);
double pow(int, int);
int /*<<< orphan*/ scanf(char *, int *, double *);
double **stochasticMatrix(double **, double, int);
int main(int argc, char *argv[]) {
  int dim;
  int count;
  double dampfac;
  double norm = 1;
  double **ma, **mb, **resultm;
  scanf("%d %lf", &dim, &dampfac);
  ma = matrixAlocation(dim);
  mb = matrixAlocation(dim);
  resultm = matrixAlocation(dim);
  ma = constructMatrix(ma, dim);
  ma = stochasticMatrix(ma, dampfac, dim);
  for (count = 0; count <= 2000 && norm > pow(10, -12); count++)
    matrixCalculation(ma, mb, resultm, dim, &norm, count);
  outputPrinter(mb, dim);
  ma = matrixDisallocation(dim, ma);
  mb = matrixDisallocation(dim, mb);
  resultm = matrixDisallocation(dim, resultm);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  0xe62(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
lea    0xe5e(%rip),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1080 <scanf@plt>
mov    -0x14(%rbp),%edi
call   1030 <matrixAlocation@plt>
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <matrixAlocation@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <matrixAlocation@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <constructMatrix@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
movsd  -0x20(%rbp),%xmm0
mov    -0x14(%rbp),%esi
call   1040 <stochasticMatrix@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x7d0,-0x18(%rbp)
mov    %al,-0x41(%rbp)
jg     1244 <main+0xc4>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    $0xa,%edi
mov    $0xfffffff4,%esi
call   1090 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    1254 <main+0xd4>
jmp    127e <main+0xfe>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r9d
lea    -0x28(%rbp),%r8
call   10a0 <matrixCalculation@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1207 <main+0x87>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <outputPrinter@plt>
mov    -0x14(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1060 <matrixDisallocation@plt>
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   1060 <matrixDisallocation@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x40(%rbp),%rsi
call   1060 <matrixDisallocation@plt>
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
movabs $0x3ff0000000000000,%rax
mov    %rax,0x8(%rsp)
lea    0xe66(%rip),%rdi
lea    0x4(%rsp),%rsi
lea    0x18(%rsp),%rdx
call   1080 <scanf@plt>
mov    0x4(%rsp),%edi
call   1030 <matrixAlocation@plt>
mov    %rax,%rbx
mov    0x4(%rsp),%edi
call   1030 <matrixAlocation@plt>
mov    %rax,%r15
mov    0x4(%rsp),%edi
call   1030 <matrixAlocation@plt>
mov    %rax,%r14
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1070 <constructMatrix@plt>
movsd  0x18(%rsp),%xmm0
mov    0x4(%rsp),%esi
mov    %rax,%rdi
call   1040 <stochasticMatrix@plt>
mov    %rax,%rbx
mov    $0xa,%edi
mov    $0xfffffff4,%esi
call   1090 <pow@plt>
movsd  0xdf3(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    126a <main+0xea>
xor    %ebp,%ebp
lea    0x8(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    0x4(%rsp),%ecx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r12,%r8
mov    %ebp,%r9d
call   10a0 <matrixCalculation@plt>
cmp    $0x7d0,%ebp
je     126a <main+0xea>
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    $0xa,%edi
mov    $0xfffffff4,%esi
call   1090 <pow@plt>
add    $0x1,%ebp
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     1220 <main+0xa0>
mov    0x4(%rsp),%esi
mov    %r15,%rdi
call   1050 <outputPrinter@plt>
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
call   1060 <matrixDisallocation@plt>
mov    0x4(%rsp),%edi
mov    %r15,%rsi
call   1060 <matrixDisallocation@plt>
mov    0x4(%rsp),%edi
mov    %r14,%rsi
call   1060 <matrixDisallocation@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%d %lf\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 double**
%11 = alloca double**
%12 = alloca double**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 1.000000e+00, double* %9
%13 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %6, double* %8)
%14 = load i32, i32* %6
%15 = call double** @matrixAlocation(i32 %14)
store double** %15, double*** %10
%16 = load i32, i32* %6
%17 = call double** @matrixAlocation(i32 %16)
store double** %17, double*** %11
%18 = load i32, i32* %6
%19 = call double** @matrixAlocation(i32 %18)
store double** %19, double*** %12
%20 = load double**, double*** %10
%21 = load i32, i32* %6
%22 = call double** @constructMatrix(double** %20, i32 %21)
store double** %22, double*** %10
%23 = load double**, double*** %10
%24 = load double, double* %8
%25 = load i32, i32* %6
%26 = call double** @stochasticMatrix(double** %23, double %24, i32 %25)
store double** %26, double*** %10
store i32 0, i32* %7
br label %27
27: ; preds = %43, %2
%28 = load i32, i32* %7
%29 = icmp sle i32 %28, 2000
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load double, double* %9
%32 = call double @pow(i32 10, i32 -12)
%33 = fcmp ogt double %31, %32
br label %34
34: ; preds = %30, %27
%35 = phi i1 [ false, %27 ], [ %33, %30 ]
br i1 %35, label %36, label %46
36: ; preds = %34
%37 = load double**, double*** %10
%38 = load double**, double*** %11
%39 = load double**, double*** %12
%40 = load i32, i32* %6
%41 = load i32, i32* %7
%42 = call i32 @matrixCalculation(double** %37, double** %38, double** %39, i32 %40, double* %9, i32 %41)
br label %43
43: ; preds = %36
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %27
46: ; preds = %34
%47 = load double**, double*** %11
%48 = load i32, i32* %6
%49 = call i32 @outputPrinter(double** %47, i32 %48)
%50 = load i32, i32* %6
%51 = load double**, double*** %10
%52 = call double** @matrixDisallocation(i32 %50, double** %51)
store double** %52, double*** %10
%53 = load i32, i32* %6
%54 = load double**, double*** %11
%55 = call double** @matrixDisallocation(i32 %53, double** %54)
store double** %55, double*** %11
%56 = load i32, i32* %6
%57 = load double**, double*** %12
%58 = call double** @matrixDisallocation(i32 %56, double** %57)
store double** %58, double*** %12
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"%d %lf\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = bitcast i32* %3 to i8*
%7 = bitcast double* %4 to i8*
%8 = bitcast double* %5 to i8*
store double 1.000000e+00, double* %5
%9 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %3, double* %4)
%10 = load i32, i32* %3
%11 = call double** @matrixAlocation(i32 %10)
%12 = load i32, i32* %3
%13 = call double** @matrixAlocation(i32 %12)
%14 = load i32, i32* %3
%15 = call double** @matrixAlocation(i32 %14)
%16 = load i32, i32* %3
%17 = call double** @constructMatrix(double** %11, i32 %16)
%18 = load double, double* %4
%19 = load i32, i32* %3
%20 = call double** @stochasticMatrix(double** %17, double %18, i32 %19)
%21 = call double @pow(i32 10, i32 -12)
%22 = fcmp olt double %21, 1.000000e+00
br i1 %22, label %23, label %33
23: ; preds = %2, %29
%24 = phi i32 [ %27, %29 ], [ 0, %2 ]
%25 = load i32, i32* %3
%26 = call i32 @matrixCalculation(double** %20, double** %13, double** %15, i32 %25, double* %5, i32 %24)
%27 = add nuw nsw i32 %24, 1
%28 = icmp eq i32 %27, 2001
br i1 %28, label %33, label %29
29: ; preds = %23
%30 = load double, double* %5
%31 = call double @pow(i32 10, i32 -12)
%32 = fcmp ogt double %30, %31
br i1 %32, label %23, label %33
33: ; preds = %29, %23, %2
%34 = load i32, i32* %3
%35 = call i32 @outputPrinter(double** %13, i32 %34)
%36 = load i32, i32* %3
%37 = call double** @matrixDisallocation(i32 %36, double** %20)
%38 = load i32, i32* %3
%39 = call double** @matrixDisallocation(i32 %38, double** %13)
%40 = load i32, i32* %3
%41 = call double** @matrixDisallocation(i32 %40, double** %15)
ret i32 0
}