#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 */
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(double *, double *, int);
int /*<<< orphan*/ memset(double *, int /*<<< orphan*/, int);
double *calculatePageRank(double *vector, double **matrix, int n, double d,
                          int numIteration) {
  double *prevVector = (double *)malloc(sizeof(double) * n);
  for (int z = 0; z < numIteration; z++) {
    memcpy(prevVector, vector, sizeof(double) * n);
    memset(vector, 0, sizeof(double) * n);
    for (int i = 0; i < n; i++) {
      for (int l = 0; l < n; l++) {
        vector[i] += matrix[l][i] * prevVector[l];
      }
      vector[i] *= d;
      vector[i] += (1.0 - d) * 1.0 / (double)n;
    }
  }
  free(prevVector);
  return vector;
}


x86 assembly (clang, -O0):
<calculatePageRank>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1289 <calculatePageRank+0x149>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1276 <calculatePageRank+0x136>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    121d <calculatePageRank+0xdd>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x8(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11c7 <calculatePageRank+0x87>
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x38(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movsd  0xdc4(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  0xdb7(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x38(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11b4 <calculatePageRank+0x74>
jmp    127b <calculatePageRank+0x13b>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1175 <calculatePageRank+0x35>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculatePageRank>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,%r14d
movsd  %xmm0,0x10(%rsp)
mov    %edx,%r15d
mov    %rsi,%r13
mov    %rdi,%rbx
lea    0x0(,%r15,8),%edi
mov    %edi,0x8(%rsp)
call   1060 <malloc@plt>
movsd  0x10(%rsp),%xmm2
mov    %rax,%rbp
mov    %r14d,0xc(%rsp)
test   %r14d,%r14d
jle    129f <calculatePageRank+0x15f>
movsd  0xe70(%rip),%xmm3
subsd  %xmm2,%xmm3
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
divsd  %xmm0,%xmm3
mov    %r15d,%r12d
mov    %r12d,%r14d
and    $0xfffffffe,%r14d
xor    %eax,%eax
movsd  %xmm3,0x18(%rsp)
jmp    11d2 <calculatePageRank+0x92>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x20(%rsp),%rax
add    $0x1,%eax
cmp    0xc(%rsp),%eax
je     129f <calculatePageRank+0x15f>
mov    %rax,0x20(%rsp)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    0x8(%rsp),%edx
call   1050 <memcpy@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    0x8(%rsp),%edx
call   1040 <memset@plt>
movsd  0x18(%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
test   %r15d,%r15d
jle    11c0 <calculatePageRank+0x80>
xor    %eax,%eax
jmp    1226 <calculatePageRank+0xe6>
nopl   0x0(%rax)
mulsd  %xmm2,%xmm0
addsd  %xmm3,%xmm0
movsd  %xmm0,(%rbx,%rax,8)
add    $0x1,%rax
cmp    %r12,%rax
je     11c0 <calculatePageRank+0x80>
movsd  (%rbx,%rax,8),%xmm0
xor    %ecx,%ecx
cmp    $0x1,%r15d
je     127b <calculatePageRank+0x13b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%r13,%rcx,8),%rdx
movsd  (%rdx,%rax,8),%xmm1
mulsd  0x0(%rbp,%rcx,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rax,8)
mov    0x8(%r13,%rcx,8),%rdx
movsd  (%rdx,%rax,8),%xmm0
mulsd  0x8(%rbp,%rcx,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx,%rax,8)
add    $0x2,%rcx
cmp    %rcx,%r14
jne    1240 <calculatePageRank+0x100>
test   $0x1,%r12b
je     1210 <calculatePageRank+0xd0>
mov    0x0(%r13,%rcx,8),%rdx
movsd  (%rdx,%rax,8),%xmm1
mulsd  0x0(%rbp,%rcx,8),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx,%rax,8)
jmp    1210 <calculatePageRank+0xd0>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double* @calculatePageRank(double* %0, double** %1, i32 %2, double %3, i32 %4) {
%6 = alloca double*
%7 = alloca double**
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
%11 = alloca double*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store double* %0, double** %6
store double** %1, double*** %7
store i32 %2, i32* %8
store double %3, double* %9
store i32 %4, i32* %10
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = mul i64 8, %16
%18 = trunc i64 %17 to i32
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to double*
store double* %20, double** %11
store i32 0, i32* %12
br label %21
21: ; preds = %96, %5
%22 = load i32, i32* %12
%23 = load i32, i32* %10
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %99
25: ; preds = %21
%26 = load double*, double** %11
%27 = load double*, double** %6
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = mul i64 8, %29
%31 = trunc i64 %30 to i32
%32 = call i32 @memcpy(double* %26, double* %27, i32 %31)
%33 = load double*, double** %6
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = mul i64 8, %35
%37 = trunc i64 %36 to i32
%38 = call i32 @memset(double* %33, i32 0, i32 %37)
store i32 0, i32* %13
br label %39
39: ; preds = %92, %25
%40 = load i32, i32* %13
%41 = load i32, i32* %8
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %95
43: ; preds = %39
store i32 0, i32* %14
br label %44
44: ; preds = %69, %43
%45 = load i32, i32* %14
%46 = load i32, i32* %8
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %72
48: ; preds = %44
%49 = load double**, double*** %7
%50 = load i32, i32* %14
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double*, double** %49, i64 %51
%53 = load double*, double** %52
%54 = load i32, i32* %13
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
%57 = load double, double* %56
%58 = load double*, double** %11
%59 = load i32, i32* %14
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
%62 = load double, double* %61
%63 = load double*, double** %6
%64 = load i32, i32* %13
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
%67 = load double, double* %66
%68 = call double @llvm.fmuladd.f64(double %57, double %62, double %67)
store double %68, double* %66
br label %69
69: ; preds = %48
%70 = load i32, i32* %14
%71 = add nsw i32 %70, 1
store i32 %71, i32* %14
br label %44
72: ; preds = %44
%73 = load double, double* %9
%74 = load double*, double** %6
%75 = load i32, i32* %13
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %74, i64 %76
%78 = load double, double* %77
%79 = fmul double %78, %73
store double %79, double* %77
%80 = load double, double* %9
%81 = fsub double 1.000000e+00, %80
%82 = fmul double %81, 1.000000e+00
%83 = load i32, i32* %8
%84 = sitofp i32 %83 to double
%85 = fdiv double %82, %84
%86 = load double*, double** %6
%87 = load i32, i32* %13
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds double, double* %86, i64 %88
%90 = load double, double* %89
%91 = fadd double %90, %85
store double %91, double* %89
br label %92
92: ; preds = %72
%93 = load i32, i32* %13
%94 = add nsw i32 %93, 1
store i32 %94, i32* %13
br label %39
95: ; preds = %39
br label %96
96: ; preds = %95
%97 = load i32, i32* %12
%98 = add nsw i32 %97, 1
store i32 %98, i32* %12
br label %21
99: ; preds = %21
%100 = load double*, double** %11
%101 = call i32 @free(double* %100)
%102 = load double*, double** %6
ret double* %102
}

LLVM IR (-O2):
define double* @calculatePageRank(double* returned %0, double** nocapture %1, i32 %2, double %3, i32 %4) {
%6 = shl i32 %2, 3
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to double*
%9 = icmp sgt i32 %4, 0
br i1 %9, label %10, label %20
10: ; preds = %5
%11 = icmp sgt i32 %2, 0
%12 = fsub double 1.000000e+00, %3
%13 = sitofp i32 %2 to double
%14 = fdiv double %12, %13
%15 = zext i32 %2 to i64
%16 = and i64 %15, 1
%17 = icmp eq i32 %2, 1
%18 = and i64 %15, 4294967294
%19 = icmp eq i64 %16, 0
br label %22
20: ; preds = %30, %5
%21 = tail call i32 @free(double* %8)
ret double* %0
22: ; preds = %10, %30
%23 = phi i32 [ 0, %10 ], [ %31, %30 ]
%24 = tail call i32 @memcpy(double* %8, double* %0, i32 %6)
%25 = tail call i32 @memset(double* %0, i32 0, i32 %6)
br i1 %11, label %26, label %30
26: ; preds = %22, %45
%27 = phi i64 [ %50, %45 ], [ 0, %22 ]
%28 = getelementptr inbounds double, double* %0, i64 %27
%29 = load double, double* %28
br i1 %17, label %33, label %52
30: ; preds = %45, %22
%31 = add nuw nsw i32 %23, 1
%32 = icmp eq i32 %31, %4
br i1 %32, label %20, label %22
33: ; preds = %52, %26
%34 = phi double [ undef, %26 ], [ %70, %52 ]
%35 = phi double [ %29, %26 ], [ %70, %52 ]
%36 = phi i64 [ 0, %26 ], [ %71, %52 ]
br i1 %19, label %45, label %37
37: ; preds = %33
%38 = getelementptr inbounds double*, double** %1, i64 %36
%39 = load double*, double** %38
%40 = getelementptr inbounds double, double* %39, i64 %27
%41 = load double, double* %40
%42 = getelementptr inbounds double, double* %8, i64 %36
%43 = load double, double* %42
%44 = tail call double @llvm.fmuladd.f64(double %41, double %43, double %35)
store double %44, double* %28
br label %45
45: ; preds = %33, %37
%46 = phi double [ %34, %33 ], [ %44, %37 ]
%47 = getelementptr inbounds double, double* %0, i64 %27
%48 = fmul double %46, %3
%49 = fadd double %14, %48
store double %49, double* %47
%50 = add nuw nsw i64 %27, 1
%51 = icmp eq i64 %50, %15
br i1 %51, label %30, label %26
52: ; preds = %26, %52
%53 = phi double [ %70, %52 ], [ %29, %26 ]
%54 = phi i64 [ %71, %52 ], [ 0, %26 ]
%55 = phi i64 [ %72, %52 ], [ 0, %26 ]
%56 = getelementptr inbounds double*, double** %1, i64 %54
%57 = load double*, double** %56
%58 = getelementptr inbounds double, double* %57, i64 %27
%59 = load double, double* %58
%60 = getelementptr inbounds double, double* %8, i64 %54
%61 = load double, double* %60
%62 = tail call double @llvm.fmuladd.f64(double %59, double %61, double %53)
store double %62, double* %28
%63 = or i64 %54, 1
%64 = getelementptr inbounds double*, double** %1, i64 %63
%65 = load double*, double** %64
%66 = getelementptr inbounds double, double* %65, i64 %27
%67 = load double, double* %66
%68 = getelementptr inbounds double, double* %8, i64 %63
%69 = load double, double* %68
%70 = tail call double @llvm.fmuladd.f64(double %67, double %69, double %62)
store double %70, double* %28
%71 = add nuw nsw i64 %54, 2
%72 = add i64 %55, 2
%73 = icmp eq i64 %72, %18
br i1 %73, label %33, label %52
}