#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*/ ave_dmatrix(double **, long, long, double *);
double **dmatrix(int, long, int, long);
int /*<<< orphan*/ free_dmatrix(double **, int, long, int, long);
int /*<<< orphan*/ multi_matrix(double **, long, long, double **, long, long,
                                double **);
int /*<<< orphan*/ transpose_matrix(double **, long, long, double **);
void cov_matrix(double **a, double **b, long nr, long nc, double **cmtx) {
  double ave_a[4], ave_b[4];
  double **ta, **ta_x_b;
  long i, j;
  ave_dmatrix(a, nr, nc, ave_a);
  ave_dmatrix(b, nr, nc, ave_b);
  ta = dmatrix(1, nc, 1, nr);
  ta_x_b = dmatrix(1, nc, 1, nc);
  transpose_matrix(a, nr, nc, ta);
  multi_matrix(ta, nc, nr, b, nr, nc, ta_x_b);
  for (i = 1; i <= nc; i++)
    for (j = 1; j <= nc; j++)
      cmtx[i][j] = (ta_x_b[i][j] - ave_a[i] * ave_b[j] * nr) / (nr - 1);
  free_dmatrix(ta, 1, nc, 1, nr);
  free_dmatrix(ta_x_b, 1, nc, 1, nc);
}


x86 assembly (clang, -O0):
<cov_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   1070 <ave_dmatrix@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x70(%rbp),%rcx
call   1070 <ave_dmatrix@plt>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%edi
call   1040 <dmatrix@plt>
mov    %rax,-0x78(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%edi
call   1040 <dmatrix@plt>
mov    %rax,-0x80(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x78(%rbp),%rcx
call   1050 <transpose_matrix@plt>
mov    -0x78(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x20(%rbp),%r9
mov    -0x80(%rbp),%rax
mov    %rax,(%rsp)
call   1030 <multi_matrix@plt>
movq   $0x1,-0x88(%rbp)
mov    -0x88(%rbp),%rax
cmp    -0x20(%rbp),%rax
jg     12f4 <cov_matrix+0x1a4>
movq   $0x1,-0x90(%rbp)
mov    -0x90(%rbp),%rax
cmp    -0x20(%rbp),%rax
jg     12d8 <cov_matrix+0x188>
mov    -0x80(%rbp),%rax
mov    -0x88(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x90(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x88(%rbp),%rax
movsd  -0x50(%rbp,%rax,8),%xmm0
mov    -0x90(%rbp),%rax
mulsd  -0x70(%rbp,%rax,8),%xmm0
cvtsi2sdq -0x18(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
mov    -0x88(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x90(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x90(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x90(%rbp)
jmp    122a <cov_matrix+0xda>
jmp    12dd <cov_matrix+0x18d>
mov    -0x88(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x88(%rbp)
jmp    120e <cov_matrix+0xbe>
mov    -0x78(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%r8
mov    $0x1,%ecx
mov    %ecx,%esi
call   1060 <free_dmatrix@plt>
mov    -0x80(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x20(%rbp),%r8
mov    $0x1,%ecx
mov    %ecx,%esi
call   1060 <free_dmatrix@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cov_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %r8,%r13
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rsi,0x10(%rsp)
mov    %rdi,%r12
lea    0x60(%rsp),%rcx
mov    %rdx,%rsi
mov    %r14,%rdx
call   1070 <ave_dmatrix@plt>
lea    0x40(%rsp),%rcx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1070 <ave_dmatrix@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <dmatrix@plt>
mov    %rax,%rbp
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <dmatrix@plt>
mov    %rax,%r15
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %rbp,%rcx
call   1050 <transpose_matrix@plt>
mov    %r15,(%rsp)
mov    %rbp,0x20(%rsp)
mov    %rbp,%rdi
mov    %r15,%rbp
mov    %r14,%rsi
mov    %rbx,%rdx
mov    0x10(%rsp),%rcx
mov    %rbx,0x18(%rsp)
mov    %rbx,%r8
mov    %r14,%r9
call   1030 <multi_matrix@plt>
test   %r14,%r14
jle    13a0 <cov_matrix+0x250>
mov    0x18(%rsp),%rax
cvtsi2sd %rax,%xmm0
add    $0xffffffffffffffff,%rax
cvtsi2sd %rax,%xmm1
lea    0x1(%r14),%rax
lea    (%rsp,%r14,8),%rcx
add    $0x48,%rcx
mov    %rcx,0x30(%rsp)
mov    %r14,%rsi
and    $0xfffffffffffffffe,%rsi
mov    %r14,%rcx
or     $0x1,%rcx
mov    %rcx,0x28(%rsp)
movapd %xmm0,%xmm2
unpcklpd %xmm0,%xmm2
movapd %xmm1,%xmm3
unpcklpd %xmm1,%xmm3
mov    $0x1,%ecx
xor    %r15d,%r15d
movapd 0xd9d(%rip),%xmm4
mov    %rbp,0x38(%rsp)
jmp    1284 <cov_matrix+0x134>
nopw   0x0(%rax,%rax,1)
lea    0x1(%rcx),%rdx
add    $0x1,%r15
cmp    %r14,%rcx
mov    %rdx,%rcx
je     13a0 <cov_matrix+0x250>
mov    0x0(%rbp,%rcx,8),%rdi
mov    0x0(%r13,%rcx,8),%rdx
mov    $0x1,%ebx
cmp    $0x2,%r14
jb     1370 <cov_matrix+0x220>
lea    (%rsp,%r15,8),%r9
add    $0x70,%r9
lea    0x60(%rsp,%rcx,8),%r8
lea    0x8(%rdx),%rbx
lea    (%rdx,%rax,8),%r10
lea    0x8(%rdi),%r11
lea    (%rdi,%rax,8),%rbp
cmp    %rbp,%rbx
setb   0x10(%rsp)
cmp    %r10,%r11
mov    %r14,%rbp
mov    %r13,%r14
setb   %r13b
cmp    %r9,%rbx
setb   %r12b
cmp    %r10,%r8
setb   %r9b
cmp    0x30(%rsp),%rbx
setb   %r11b
lea    0x48(%rsp),%rbx
cmp    %r10,%rbx
setb   %r8b
mov    $0x1,%ebx
test   %r13b,0x10(%rsp)
mov    %r14,%r13
mov    %rbp,%r14
mov    0x38(%rsp),%rbp
jne    1370 <cov_matrix+0x220>
mov    $0x1,%ebx
and    %r9b,%r12b
jne    1370 <cov_matrix+0x220>
mov    $0x1,%ebx
and    %r8b,%r11b
jne    1370 <cov_matrix+0x220>
movsd  0x60(%rsp,%rcx,8),%xmm5
unpcklpd %xmm5,%xmm5
xorpd  %xmm4,%xmm5
xor    %ebx,%ebx
nopl   (%rax)
movupd 0x8(%rdi,%rbx,8),%xmm6
movupd 0x48(%rsp,%rbx,8),%xmm7
mulpd  %xmm5,%xmm7
mulpd  %xmm2,%xmm7
addpd  %xmm6,%xmm7
divpd  %xmm3,%xmm7
movupd %xmm7,0x8(%rdx,%rbx,8)
add    $0x2,%rbx
cmp    %rbx,%rsi
jne    1330 <cov_matrix+0x1e0>
mov    0x28(%rsp),%rbx
cmp    %r14,%rsi
je     1270 <cov_matrix+0x120>
nopl   0x0(%rax)
movsd  (%rdi,%rbx,8),%xmm5
movsd  0x40(%rsp,%rbx,8),%xmm6
mulsd  0x60(%rsp,%rcx,8),%xmm6
mulsd  %xmm0,%xmm6
subsd  %xmm6,%xmm5
divsd  %xmm1,%xmm5
movsd  %xmm5,(%rdx,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rax
jne    1370 <cov_matrix+0x220>
jmp    1270 <cov_matrix+0x120>
mov    0x20(%rsp),%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    $0x1,%ecx
mov    0x18(%rsp),%r8
call   1060 <free_dmatrix@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    $0x1,%ecx
mov    %r14,%r8
call   1060 <free_dmatrix@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @cov_matrix(double** %0, double** %1, i64 %2, i64 %3, double** nocapture %4) {
%6 = alloca [4 x double]
%7 = alloca [4 x double]
%8 = bitcast [4 x double]* %6 to i8*
%9 = bitcast [4 x double]* %7 to i8*
%10 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 0
%11 = call i32 @ave_dmatrix(double** %0, i64 %2, i64 %3, double* %10)
%12 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 0
%13 = call i32 @ave_dmatrix(double** %1, i64 %2, i64 %3, double* %12)
%14 = call double** @dmatrix(i32 1, i64 %3, i32 1, i64 %2)
%15 = call double** @dmatrix(i32 1, i64 %3, i32 1, i64 %3)
%16 = call i32 @transpose_matrix(double** %0, i64 %2, i64 %3, double** %14)
%17 = call i32 @multi_matrix(double** %14, i64 %3, i64 %2, double** %1, i64 %2, i64 %3, double** %15)
%18 = icmp slt i64 %3, 1
br i1 %18, label %103, label %19
19: ; preds = %5
%20 = sitofp i64 %2 to double
%21 = add nsw i64 %2, -1
%22 = sitofp i64 %21 to double
%23 = add i64 %3, 1
%24 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 1
%25 = getelementptr [4 x double], [4 x double]* %7, i64 0, i64 %23
%26 = icmp ult i64 %3, 2
%27 = and i64 %3, -2
%28 = or i64 %3, 1
%29 = insertelement <2 x double> poison, double %20, i64 0
%30 = shufflevector <2 x double> %29, <2 x double> poison, <2 x i32> zeroinitializer
%31 = insertelement <2 x double> poison, double %22, i64 0
%32 = shufflevector <2 x double> %31, <2 x double> poison, <2 x i32> zeroinitializer
%33 = icmp eq i64 %27, %3
br label %34
34: ; preds = %99, %19
%35 = phi i64 [ %102, %99 ], [ 0, %19 ]
%36 = phi i64 [ %100, %99 ], [ 1, %19 ]
%37 = getelementptr inbounds double*, double** %15, i64 %36
%38 = load double*, double** %37
%39 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 %36
%40 = getelementptr inbounds double*, double** %4, i64 %36
%41 = load double*, double** %40
br i1 %26, label %83, label %42
42: ; preds = %34
%43 = add i64 %35, 2
%44 = getelementptr [4 x double], [4 x double]* %6, i64 0, i64 %43
%45 = getelementptr [4 x double], [4 x double]* %6, i64 0, i64 %36
%46 = getelementptr double, double* %41, i64 1
%47 = getelementptr double, double* %41, i64 %23
%48 = getelementptr double, double* %38, i64 1
%49 = getelementptr double, double* %38, i64 %23
%50 = icmp ult double* %46, %49
%51 = icmp ult double* %48, %47
%52 = and i1 %50, %51
%53 = icmp ult double* %46, %44
%54 = icmp ult double* %45, %47
%55 = and i1 %53, %54
%56 = or i1 %52, %55
%57 = icmp ult double* %46, %25
%58 = icmp ult double* %24, %47
%59 = and i1 %57, %58
%60 = or i1 %56, %59
br i1 %60, label %83, label %61
61: ; preds = %42
%62 = load double, double* %39
%63 = insertelement <2 x double> poison, double %62, i64 0
%64 = shufflevector <2 x double> %63, <2 x double> poison, <2 x i32> zeroinitializer
%65 = fneg <2 x double> %64
br label %66
66: ; preds = %66, %61
%67 = phi i64 [ 0, %61 ], [ %80, %66 ]
%68 = or i64 %67, 1
%69 = getelementptr inbounds double, double* %38, i64 %68
%70 = bitcast double* %69 to <2 x double>*
%71 = load <2 x double>, <2 x double>* %70
%72 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 %68
%73 = bitcast double* %72 to <2 x double>*
%74 = load <2 x double>, <2 x double>* %73
%75 = fmul <2 x double> %74, %65
%76 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %75, <2 x double> %30, <2 x double> %71)
%77 = fdiv <2 x double> %76, %32
%78 = getelementptr inbounds double, double* %41, i64 %68
%79 = bitcast double* %78 to <2 x double>*
store <2 x double> %77, <2 x double>* %79
%80 = add nuw i64 %67, 2
%81 = icmp eq i64 %80, %27
br i1 %81, label %82, label %66
82: ; preds = %66
br i1 %33, label %99, label %83
83: ; preds = %42, %34, %82
%84 = phi i64 [ 1, %42 ], [ 1, %34 ], [ %28, %82 ]
br label %85
85: ; preds = %83, %85
%86 = phi i64 [ %97, %85 ], [ %84, %83 ]
%87 = getelementptr inbounds double, double* %38, i64 %86
%88 = load double, double* %87
%89 = load double, double* %39
%90 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 %86
%91 = load double, double* %90
%92 = fneg double %89
%93 = fmul double %91, %92
%94 = call double @llvm.fmuladd.f64(double %93, double %20, double %88)
%95 = fdiv double %94, %22
%96 = getelementptr inbounds double, double* %41, i64 %86
store double %95, double* %96
%97 = add nuw i64 %86, 1
%98 = icmp eq i64 %86, %3
br i1 %98, label %99, label %85
99: ; preds = %85, %82
%100 = add nuw i64 %36, 1
%101 = icmp eq i64 %36, %3
%102 = add i64 %35, 1
br i1 %101, label %103, label %34
103: ; preds = %99, %5
%104 = call i32 @free_dmatrix(double** %14, i32 1, i64 %3, i32 1, i64 %2)
%105 = call i32 @free_dmatrix(double** %15, i32 1, i64 %3, i32 1, i64 %3)
ret void
}