#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 **allocateSpace(int);
double **Matrix_matrix_multiply(double **matrixa, double **matrixb, int size) {
  double sum = 0;
  double **output = allocateSpace(size);
  if (output == NULL) {
    return NULL;
  }
  int i, j, k;
  for (i = 0; i < size; i++) {
    for (j = 0; j < size; j++) {
      for (k = 0; k < size; k++) {
        sum += matrixa[i][k] * matrixb[k][j];
      }
      output[i][j] = sum;
      sum = 0;
    }
  }
  return output;
}


x86 assembly (clang, -O0):
<Matrix_matrix_multiply>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <allocateSpace@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    114f <Matrix_matrix_multiply+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    121d <Matrix_matrix_multiply+0x10d>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1215 <Matrix_matrix_multiply+0x105>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1202 <Matrix_matrix_multiply+0xf2>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11d2 <Matrix_matrix_multiply+0xc2>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    117c <Matrix_matrix_multiply+0x6c>
movsd  -0x28(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x38(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1169 <Matrix_matrix_multiply+0x59>
jmp    1207 <Matrix_matrix_multiply+0xf7>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1156 <Matrix_matrix_multiply+0x46>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Matrix_matrix_multiply>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r13
mov    %rdi,%r14
mov    %edx,%edi
call   1030 <allocateSpace@plt>
test   %rax,%rax
je     1231 <Matrix_matrix_multiply+0x121>
test   %ebp,%ebp
jle    1231 <Matrix_matrix_multiply+0x121>
mov    %ebp,%r10d
lea    -0x1(%r10),%r9
mov    %r10d,%r12d
and    $0x3,%r12d
mov    %r10d,%r15d
and    $0xfffffffc,%r15d
xor    %r8d,%r8d
jmp    116d <Matrix_matrix_multiply+0x5d>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r8
cmp    %r10,%r8
je     1231 <Matrix_matrix_multiply+0x121>
mov    (%rax,%r8,8),%r11
mov    (%r14,%r8,8),%rdx
xor    %ecx,%ecx
jmp    118f <Matrix_matrix_multiply+0x7f>
nopl   0x0(%rax)
movsd  %xmm0,(%r11,%rcx,8)
add    $0x1,%rcx
cmp    %r10,%rcx
je     1160 <Matrix_matrix_multiply+0x50>
xorpd  %xmm0,%xmm0
xor    %ebp,%ebp
cmp    $0x3,%r9
jb     11f8 <Matrix_matrix_multiply+0xe8>
nopl   0x0(%rax,%rax,1)
movsd  (%rdx,%rbp,8),%xmm1
movsd  0x8(%rdx,%rbp,8),%xmm2
mov    0x0(%r13,%rbp,8),%rsi
mov    0x8(%r13,%rbp,8),%rdi
mulsd  (%rsi,%rcx,8),%xmm1
addsd  %xmm0,%xmm1
mulsd  (%rdi,%rcx,8),%xmm2
addsd  %xmm1,%xmm2
movsd  0x10(%rdx,%rbp,8),%xmm1
mov    0x10(%r13,%rbp,8),%rsi
mulsd  (%rsi,%rcx,8),%xmm1
movsd  0x18(%rdx,%rbp,8),%xmm0
mov    0x18(%r13,%rbp,8),%rsi
mulsd  (%rsi,%rcx,8),%xmm0
addsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
add    $0x4,%rbp
cmp    %rbp,%r15
jne    11a0 <Matrix_matrix_multiply+0x90>
test   %r12,%r12
je     1180 <Matrix_matrix_multiply+0x70>
lea    0x0(,%rbp,8),%rdi
add    %r13,%rdi
lea    (%rdx,%rbp,8),%rbp
xor    %esi,%esi
xchg   %ax,%ax
movsd  0x0(%rbp,%rsi,8),%xmm1
mov    (%rdi,%rsi,8),%rbx
mulsd  (%rbx,%rcx,8),%xmm1
addsd  %xmm1,%xmm0
add    $0x1,%rsi
cmp    %rsi,%r12
jne    1210 <Matrix_matrix_multiply+0x100>
jmp    1180 <Matrix_matrix_multiply+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double** @Matrix_matrix_multiply(double** %0, double** %1, i32 %2) {
%4 = alloca double**
%5 = alloca double**
%6 = alloca double**
%7 = alloca i32
%8 = alloca double
%9 = alloca double**
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store double** %0, double*** %5
store double** %1, double*** %6
store i32 %2, i32* %7
store double 0.000000e+00, double* %8
%13 = load i32, i32* %7
%14 = call double** @allocateSpace(i32 %13)
store double** %14, double*** %9
%15 = load double**, double*** %9
%16 = icmp eq double** %15, null
br i1 %16, label %17, label %18
17: ; preds = %3
store double** null, double*** %4
br label %76
18: ; preds = %3
store i32 0, i32* %10
br label %19
19: ; preds = %71, %18
%20 = load i32, i32* %10
%21 = load i32, i32* %7
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %74
23: ; preds = %19
store i32 0, i32* %11
br label %24
24: ; preds = %67, %23
%25 = load i32, i32* %11
%26 = load i32, i32* %7
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %70
28: ; preds = %24
store i32 0, i32* %12
br label %29
29: ; preds = %54, %28
%30 = load i32, i32* %12
%31 = load i32, i32* %7
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %57
33: ; preds = %29
%34 = load double**, double*** %5
%35 = load i32, i32* %10
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double*, double** %34, i64 %36
%38 = load double*, double** %37
%39 = load i32, i32* %12
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = load double, double* %41
%43 = load double**, double*** %6
%44 = load i32, i32* %12
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double*, double** %43, i64 %45
%47 = load double*, double** %46
%48 = load i32, i32* %11
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
%51 = load double, double* %50
%52 = load double, double* %8
%53 = call double @llvm.fmuladd.f64(double %42, double %51, double %52)
store double %53, double* %8
br label %54
54: ; preds = %33
%55 = load i32, i32* %12
%56 = add nsw i32 %55, 1
store i32 %56, i32* %12
br label %29
57: ; preds = %29
%58 = load double, double* %8
%59 = load double**, double*** %9
%60 = load i32, i32* %10
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double*, double** %59, i64 %61
%63 = load double*, double** %62
%64 = load i32, i32* %11
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
store double %58, double* %66
store double 0.000000e+00, double* %8
br label %67
67: ; preds = %57
%68 = load i32, i32* %11
%69 = add nsw i32 %68, 1
store i32 %69, i32* %11
br label %24
70: ; preds = %24
br label %71
71: ; preds = %70
%72 = load i32, i32* %10
%73 = add nsw i32 %72, 1
store i32 %73, i32* %10
br label %19
74: ; preds = %19
%75 = load double**, double*** %9
store double** %75, double*** %4
br label %76
76: ; preds = %74, %17
%77 = load double**, double*** %4
ret double** %77
}

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