#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__ malloc(int);
double **matrixMatrixMultiplication(double **matrix0, double **matrix1, int n0,
                                    int n1, int n2) {
  int i, j, k;
  double **result;
  result = (double **)malloc(n0 * sizeof(double *));
  for (i = 0; i < n0; i++)
    result[i] = (double *)malloc(n2 * sizeof(double));
  for (i = 0; i < n0; i++) {
    for (j = 0; j < n2; j++) {
      result[i][j] = 0;
      for (k = 0; k < n1; k++)
        result[i][j] += matrix0[i][k] * matrix1[k][j];
    }
  }
  return (result);
}


x86 assembly (clang, -O0):
<matrixMatrixMultiplication>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117c <matrixMatrixMultiplication+0x6c>
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1144 <matrixMatrixMultiplication+0x34>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    124d <matrixMatrixMultiplication+0x13d>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    123a <matrixMatrixMultiplication+0x12a>
mov    -0x30(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x24(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1227 <matrixMatrixMultiplication+0x117>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x30(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11c1 <matrixMatrixMultiplication+0xb1>
jmp    122c <matrixMatrixMultiplication+0x11c>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1196 <matrixMatrixMultiplication+0x86>
jmp    123f <matrixMatrixMultiplication+0x12f>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1183 <matrixMatrixMultiplication+0x73>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrixMatrixMultiplication>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r12d
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x0(,%rbp,8),%edi
call   1030 <malloc@plt>
test   %ebp,%ebp
jle    124d <matrixMatrixMultiplication+0x13d>
mov    %r12,0x10(%rsp)
lea    0x0(,%r12,8),%r13d
mov    %rbp,0x8(%rsp)
mov    %ebp,%ecx
mov    %rcx,(%rsp)
mov    %rax,%rbp
xor    %r12d,%r12d
xchg   %ax,%ax
mov    %r13d,%edi
call   1030 <malloc@plt>
mov    %rax,0x0(%rbp,%r12,8)
add    $0x1,%r12
cmp    %r12,(%rsp)
jne    1160 <matrixMatrixMultiplication+0x50>
cmpl   $0x0,0x8(%rsp)
mov    0x10(%rsp),%r11
mov    %rbp,%rax
mov    (%rsp),%r13
jle    124d <matrixMatrixMultiplication+0x13d>
mov    %r11d,%r9d
mov    %r14d,%r8d
mov    %r8d,%r12d
and    $0xfffffffe,%r12d
xor    %r10d,%r10d
jmp    11ad <matrixMatrixMultiplication+0x9d>
add    $0x1,%r10
cmp    %r13,%r10
je     124d <matrixMatrixMultiplication+0x13d>
test   %r11d,%r11d
jle    11a0 <matrixMatrixMultiplication+0x90>
mov    (%rax,%r10,8),%rdi
xor    %ecx,%ecx
jmp    11c9 <matrixMatrixMultiplication+0xb9>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rcx
cmp    %r9,%rcx
je     11a0 <matrixMatrixMultiplication+0x90>
movq   $0x0,(%rdi,%rcx,8)
test   %r14d,%r14d
jle    11c0 <matrixMatrixMultiplication+0xb0>
mov    (%r15,%r10,8),%rdx
xorpd  %xmm0,%xmm0
xor    %esi,%esi
cmp    $0x1,%r14d
je     122b <matrixMatrixMultiplication+0x11b>
cs nopw 0x0(%rax,%rax,1)
movsd  (%rdx,%rsi,8),%xmm1
mov    (%rbx,%rsi,8),%rbp
mulsd  0x0(%rbp,%rcx,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rdi,%rcx,8)
movsd  0x8(%rdx,%rsi,8),%xmm0
mov    0x8(%rbx,%rsi,8),%rbp
mulsd  0x0(%rbp,%rcx,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rdi,%rcx,8)
add    $0x2,%rsi
cmp    %rsi,%r12
jne    11f0 <matrixMatrixMultiplication+0xe0>
test   $0x1,%r8b
je     11c0 <matrixMatrixMultiplication+0xb0>
movsd  (%rdx,%rsi,8),%xmm1
mov    (%rbx,%rsi,8),%rdx
mulsd  (%rdx,%rcx,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rdi,%rcx,8)
jmp    11c0 <matrixMatrixMultiplication+0xb0>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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