#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*/ MatrixMult(double *, int, int, double *, int, double *);
int /*<<< orphan*/ printf(char *, ...);
void test_MatrixMult() {
  double a[4][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
  double b[3][2] = {1, 2, 4, 5, 7, 8};
  double c[4][2];
  MatrixMult((double *)a, 4, 3, (double *)b, 2, (double *)c);
  int i, j;
  for (i = 0; i < 4; i++) {
    for (j = 0; j < 2; j++) {
      printf("%lf  ", c[i][j]);
    }
    printf("\n");
  }
  return;
}


x86 assembly (clang, -O0):
<test_MatrixMult>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
lea    -0x60(%rbp),%rdi
lea    0xeda(%rip),%rsi
mov    $0x60,%edx
call   1050 <memcpy@plt>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
movsd  0xead(%rip),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  0xe95(%rip),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  0xe7d(%rip),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  0xe68(%rip),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  0xe53(%rip),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xe3e(%rip),%xmm0
movsd  %xmm0,-0x68(%rbp)
lea    -0x60(%rbp),%rdi
lea    -0x90(%rbp),%rcx
lea    -0xd0(%rbp),%r9
mov    $0x4,%esi
mov    $0x3,%edx
mov    $0x2,%r8d
call   1060 <MatrixMult@plt>
movl   $0x0,-0xd4(%rbp)
cmpl   $0x4,-0xd4(%rbp)
jge    1281 <test_MatrixMult+0x141>
movl   $0x0,-0xd8(%rbp)
cmpl   $0x2,-0xd8(%rbp)
jge    125f <test_MatrixMult+0x11f>
movslq -0xd4(%rbp),%rcx
lea    -0xd0(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0xd8(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe4c(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0xd8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd8(%rbp)
jmp    120f <test_MatrixMult+0xcf>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xd4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd4(%rbp)
jmp    11f8 <test_MatrixMult+0xb8>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_MatrixMult>:
push   %rbx
sub    $0xd0,%rsp
movaps 0xf41(%rip),%xmm0
movaps %xmm0,0xc0(%rsp)
movaps 0xf22(%rip),%xmm0
movaps %xmm0,0xb0(%rsp)
movaps 0xf03(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xee4(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xec5(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xea6(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe6a(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe6e(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe72(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
lea    0x70(%rsp),%rdi
lea    0x40(%rsp),%rcx
mov    %rsp,%r9
mov    $0x4,%esi
mov    $0x3,%edx
mov    $0x2,%r8d
call   1050 <MatrixMult@plt>
movsd  (%rsp),%xmm0
lea    0xeaf(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsd  0x10(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x18(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsd  0x20(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x28(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsd  0x30(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x38(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0xd0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_MatrixMult.a = [4 x [3 x double]] [[3 x double] [double 1.000000e+00, double 2.000000e+00, double 3.000000e+00], [3 x double] [double 4.000000e+00, double 5.000000e+00, double 6.000000e+00], [3 x double] [double 7.000000e+00, double 8.000000e+00, double 9.000000e+00], [3 x double] [double 1.000000e+01, double 1.100000e+01, double 1.200000e+01]]
@.str = [6 x i8] c"%lf \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @test_MatrixMult() {
%1 = alloca [4 x [3 x double]]
%2 = alloca [3 x [2 x double]]
%3 = alloca [4 x [2 x double]]
%4 = alloca i32
%5 = alloca i32
%6 = bitcast [4 x [3 x double]]* %1 to i8*
%7 = bitcast [3 x [2 x double]]* %2 to i8*
%8 = bitcast i8* %7 to [3 x [2 x double]]*
%9 = getelementptr inbounds [3 x [2 x double]], [3 x [2 x double]]* %8, i32 0, i32 0
%10 = getelementptr inbounds [2 x double], [2 x double]* %9, i32 0, i32 0
store double 1.000000e+00, double* %10
%11 = getelementptr inbounds [2 x double], [2 x double]* %9, i32 0, i32 1
store double 2.000000e+00, double* %11
%12 = getelementptr inbounds [3 x [2 x double]], [3 x [2 x double]]* %8, i32 0, i32 1
%13 = getelementptr inbounds [2 x double], [2 x double]* %12, i32 0, i32 0
store double 4.000000e+00, double* %13
%14 = getelementptr inbounds [2 x double], [2 x double]* %12, i32 0, i32 1
store double 5.000000e+00, double* %14
%15 = getelementptr inbounds [3 x [2 x double]], [3 x [2 x double]]* %8, i32 0, i32 2
%16 = getelementptr inbounds [2 x double], [2 x double]* %15, i32 0, i32 0
store double 7.000000e+00, double* %16
%17 = getelementptr inbounds [2 x double], [2 x double]* %15, i32 0, i32 1
store double 8.000000e+00, double* %17
%18 = getelementptr inbounds [4 x [3 x double]], [4 x [3 x double]]* %1, i64 0, i64 0
%19 = bitcast [3 x double]* %18 to double*
%20 = getelementptr inbounds [3 x [2 x double]], [3 x [2 x double]]* %2, i64 0, i64 0
%21 = bitcast [2 x double]* %20 to double*
%22 = getelementptr inbounds [4 x [2 x double]], [4 x [2 x double]]* %3, i64 0, i64 0
%23 = bitcast [2 x double]* %22 to double*
%24 = call i32 @MatrixMult(double* %19, i32 4, i32 3, double* %21, i32 2, double* %23)
store i32 0, i32* %4
br label %25
25: ; preds = %46, %0
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 4
br i1 %27, label %28, label %49
28: ; preds = %25
store i32 0, i32* %5
br label %29
29: ; preds = %41, %28
%30 = load i32, i32* %5
%31 = icmp slt i32 %30, 2
br i1 %31, label %32, label %44
32: ; preds = %29
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [4 x [2 x double]], [4 x [2 x double]]* %3, i64 0, i64 %34
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [2 x double], [2 x double]* %35, i64 0, i64 %37
%39 = load double, double* %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %39)
br label %41
41: ; preds = %32
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %29
44: ; preds = %29
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %46
46: ; preds = %44
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 1
store i32 %48, i32* %4
br label %25
49: ; preds = %25
ret void
}

LLVM IR (-O2):
@__const.test_MatrixMult.a = [4 x [3 x double]] [[3 x double] [double 1.000000e+00, double 2.000000e+00, double 3.000000e+00], [3 x double] [double 4.000000e+00, double 5.000000e+00, double 6.000000e+00], [3 x double] [double 7.000000e+00, double 8.000000e+00, double 9.000000e+00], [3 x double] [double 1.000000e+01, double 1.100000e+01, double 1.200000e+01]]
@.str = [6 x i8] c"%lf \00"
define void @test_MatrixMult() {
%1 = alloca [4 x [3 x double]]
%2 = alloca [3 x [2 x double]]
%3 = alloca [4 x [2 x double]]
%4 = bitcast [4 x [3 x double]]* %1 to i8*
%5 = bitcast [3 x [2 x double]]* %2 to i8*
%6 = getelementptr inbounds [3 x [2 x double]], [3 x [2 x double]]* %2, i64 0, i64 0, i64 0
%7 = bitcast [3 x [2 x double]]* %2 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 2.000000e+00>, <2 x double>* %7
%8 = getelementptr inbounds [3 x [2 x double]], [3 x [2 x double]]* %2, i64 0, i64 1, i64 0
%9 = bitcast double* %8 to <2 x double>*
store <2 x double> <double 4.000000e+00, double 5.000000e+00>, <2 x double>* %9
%10 = getelementptr inbounds [3 x [2 x double]], [3 x [2 x double]]* %2, i64 0, i64 2, i64 0
%11 = bitcast double* %10 to <2 x double>*
store <2 x double> <double 7.000000e+00, double 8.000000e+00>, <2 x double>* %11
%12 = bitcast [4 x [2 x double]]* %3 to i8*
%13 = getelementptr inbounds [4 x [3 x double]], [4 x [3 x double]]* %1, i64 0, i64 0, i64 0
%14 = getelementptr inbounds [4 x [2 x double]], [4 x [2 x double]]* %3, i64 0, i64 0, i64 0
%15 = call i32 @MatrixMult(double* %13, i32 4, i32 3, double* %6, i32 2, double* %14)
%16 = load double, double* %14
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %16)
%18 = getelementptr inbounds [4 x [2 x double]], [4 x [2 x double]]* %3, i64 0, i64 0, i64 1
%19 = load double, double* %18
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %19)
%21 = call i32 @putchar(i32 10)
%22 = getelementptr inbounds [4 x [2 x double]], [4 x [2 x double]]* %3, i64 0, i64 1, i64 0
%23 = load double, double* %22
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %23)
%25 = getelementptr inbounds [4 x [2 x double]], [4 x [2 x double]]* %3, i64 0, i64 1, i64 1
%26 = load double, double* %25
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %26)
%28 = call i32 @putchar(i32 10)
%29 = getelementptr inbounds [4 x [2 x double]], [4 x [2 x double]]* %3, i64 0, i64 2, i64 0
%30 = load double, double* %29
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %30)
%32 = getelementptr inbounds [4 x [2 x double]], [4 x [2 x double]]* %3, i64 0, i64 2, i64 1
%33 = load double, double* %32
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %33)
%35 = call i32 @putchar(i32 10)
%36 = getelementptr inbounds [4 x [2 x double]], [4 x [2 x double]]* %3, i64 0, i64 3, i64 0
%37 = load double, double* %36
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %37)
%39 = getelementptr inbounds [4 x [2 x double]], [4 x [2 x double]]* %3, i64 0, i64 3, i64 1
%40 = load double, double* %39
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %40)
%42 = call i32 @putchar(i32 10)
ret void
}