#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);
int /*<<< orphan*/ printf(char *);
double **matrixMultiplication(double **matrixA, int rowA, int columnA,
                              double **matrixB, int rowB, int columnB) {
  double **result;
  if (columnA != rowB) {
    printf("matrixMultiplication error - indeces of first and second matrix "
           "are not okay");
    return result;
  }
  result = (double **)malloc(rowA * sizeof(double *));
  for (int i = 0; i < rowA; i++) {
    result[i] = (double *)malloc(columnB * sizeof(double));
    for (int j = 0; j < columnB; j++) {
      result[i][j] = 0;
      for (int k = 0; k < rowB; k++) {
        result[i][j] += matrixA[i][k] * matrixB[k][j];
      }
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<matrixMultiplication>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     1163 <matrixMultiplication+0x43>
lea    0xeaf(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    126d <matrixMultiplication+0x14d>
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1265 <matrixMultiplication+0x145>
movslq -0x28(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1252 <matrixMultiplication+0x132>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x38(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    123f <matrixMultiplication+0x11f>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%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    11d9 <matrixMultiplication+0xb9>
jmp    1244 <matrixMultiplication+0x124>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11ae <matrixMultiplication+0x8e>
jmp    1257 <matrixMultiplication+0x137>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    117d <matrixMultiplication+0x5d>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrixMultiplication>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,0x8(%rsp)
cmp    %r8d,%edx
jne    125b <matrixMultiplication+0x13b>
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,0x20(%rsp)
lea    0x0(,%r14,8),%edi
call   1040 <malloc@plt>
mov    %rax,0x10(%rsp)
test   %r14d,%r14d
jle    1267 <matrixMultiplication+0x147>
mov    0x8(%rsp),%rax
lea    0x0(,%rax,8),%ecx
mov    %ecx,0x4(%rsp)
mov    %r14d,%ecx
mov    %rcx,0x18(%rsp)
mov    %eax,%r15d
mov    %ebp,%r13d
mov    %r13d,%r14d
and    $0xfffffffe,%r14d
xor    %r12d,%r12d
jmp    119f <matrixMultiplication+0x7f>
xchg   %ax,%ax
add    $0x1,%r12
cmp    0x18(%rsp),%r12
je     1267 <matrixMultiplication+0x147>
mov    0x4(%rsp),%edi
call   1040 <malloc@plt>
mov    0x10(%rsp),%rcx
mov    %rax,(%rcx,%r12,8)
cmpl   $0x0,0x8(%rsp)
mov    0x20(%rsp),%r8
jle    1190 <matrixMultiplication+0x70>
xor    %ecx,%ecx
jmp    11d9 <matrixMultiplication+0xb9>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rcx
cmp    %r15,%rcx
je     1190 <matrixMultiplication+0x70>
movq   $0x0,(%rax,%rcx,8)
test   %ebp,%ebp
jle    11d0 <matrixMultiplication+0xb0>
mov    (%r8,%r12,8),%rdx
xorpd  %xmm0,%xmm0
xor    %esi,%esi
cmp    $0x1,%ebp
je     1239 <matrixMultiplication+0x119>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%rdx,%rsi,8),%xmm1
mov    (%rbx,%rsi,8),%rdi
mulsd  (%rdi,%rcx,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rax,%rcx,8)
movsd  0x8(%rdx,%rsi,8),%xmm0
mov    0x8(%rbx,%rsi,8),%rdi
mulsd  (%rdi,%rcx,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
add    $0x2,%rsi
cmp    %rsi,%r14
jne    1200 <matrixMultiplication+0xe0>
test   $0x1,%r13b
je     11d0 <matrixMultiplication+0xb0>
movsd  (%rdx,%rsi,8),%xmm1
mov    (%rbx,%rsi,8),%rdx
mulsd  (%rdx,%rcx,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rax,%rcx,8)
jmp    11d0 <matrixMultiplication+0xb0>
lea    0xd9e(%rip),%rdi
call   1030 <printf@plt>
mov    0x10(%rsp),%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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