#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*/ free_matrix(double *);
int /*<<< orphan*/ multiply(int const, int const, int const, double *, double *,
                            double *);
double *new_matrix(int const, int const);
int /*<<< orphan*/ print_matrix(int const, int const, double *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  double *matrix1;
  double *matrix2;
  double *result;
  const int SIZE1 = 3;
  const int SIZE2 = 2;
  const int SIZE3 = 3;
  int i, j;
  matrix1 = new_matrix(SIZE1, SIZE2);
  matrix2 = new_matrix(SIZE2, SIZE3);
  result = new_matrix(SIZE1, SIZE3);
  for (i = 0; i < SIZE1; i++) {
    for (j = 0; j < SIZE2; j++) {
      matrix1[i * SIZE2 + j] = i;
    }
  }
  for (i = 0; i < SIZE2; i++) {
    for (j = 0; j < SIZE3; j++) {
      matrix2[i * SIZE3 + j] = j;
    }
  }
  printf("Matrix1:\n");
  print_matrix(SIZE1, SIZE2, matrix1);
  printf("Matrix2:\n");
  print_matrix(SIZE2, SIZE3, matrix2);
  multiply(SIZE1, SIZE2, SIZE3, matrix1, matrix2, result);
  printf("Matrix3:\n");
  print_matrix(SIZE1, SIZE3, result);
  free_matrix(matrix1);
  free_matrix(matrix2);
  free_matrix(result);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x3,-0x2c(%rbp)
movl   $0x2,-0x30(%rbp)
movl   $0x3,-0x34(%rbp)
mov    $0x3,%edi
mov    $0x2,%esi
call   1060 <new_matrix@plt>
mov    %rax,-0x18(%rbp)
mov    $0x2,%edi
mov    $0x3,%esi
call   1060 <new_matrix@plt>
mov    %rax,-0x20(%rbp)
mov    $0x3,%esi
mov    %esi,%edi
call   1060 <new_matrix@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x3,-0x38(%rbp)
jge    120e <main+0xbe>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x2,-0x3c(%rbp)
jge    11fb <main+0xab>
cvtsi2sdl -0x38(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%ecx
shl    $0x1,%ecx
add    -0x3c(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11c9 <main+0x79>
jmp    1200 <main+0xb0>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11b8 <main+0x68>
movl   $0x0,-0x38(%rbp)
cmpl   $0x2,-0x38(%rbp)
jge    1269 <main+0x119>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x3,-0x3c(%rbp)
jge    1256 <main+0x106>
cvtsi2sdl -0x3c(%rbp),%xmm0
mov    -0x20(%rbp),%rax
imul   $0x3,-0x38(%rbp),%ecx
add    -0x3c(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1226 <main+0xd6>
jmp    125b <main+0x10b>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1215 <main+0xc5>
lea    0xd90(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdx
mov    $0x3,%edi
mov    $0x2,%esi
call   1070 <print_matrix@plt>
lea    0xd7b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdx
mov    $0x2,%edi
mov    $0x3,%esi
call   1070 <print_matrix@plt>
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    $0x3,%edx
mov    $0x2,%esi
mov    %edx,%edi
call   1030 <multiply@plt>
lea    0xd49(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdx
mov    $0x3,%esi
mov    %esi,%edi
call   1070 <print_matrix@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free_matrix@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free_matrix@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free_matrix@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x3,%edi
mov    $0x2,%esi
call   1060 <new_matrix@plt>
mov    %rax,%r14
mov    $0x2,%edi
mov    $0x3,%esi
call   1060 <new_matrix@plt>
mov    %rax,%rbx
mov    $0x3,%edi
mov    $0x3,%esi
call   1060 <new_matrix@plt>
mov    %rax,%r15
xorps  %xmm0,%xmm0
movups %xmm0,(%r14)
movaps 0xe67(%rip),%xmm1
movups %xmm1,0x10(%r14)
movaps 0xe6b(%rip),%xmm1
movups %xmm1,0x20(%r14)
movhps 0xe7f(%rip),%xmm0
movups %xmm0,(%rbx)
movsd  0xe7c(%rip),%xmm0
movups %xmm0,0x10(%rbx)
movaps 0xe59(%rip),%xmm0
movups %xmm0,0x20(%rbx)
lea    0xe6e(%rip),%rdi
call   1040 <puts@plt>
mov    $0x3,%edi
mov    $0x2,%esi
mov    %r14,%rdx
call   1070 <print_matrix@plt>
lea    0xe59(%rip),%rdi
call   1040 <puts@plt>
mov    $0x2,%edi
mov    $0x3,%esi
mov    %rbx,%rdx
call   1070 <print_matrix@plt>
mov    $0x3,%edi
mov    $0x2,%esi
mov    $0x3,%edx
mov    %r14,%rcx
mov    %rbx,%r8
mov    %r15,%r9
call   1030 <multiply@plt>
lea    0xe27(%rip),%rdi
call   1040 <puts@plt>
mov    $0x3,%edi
mov    $0x3,%esi
mov    %r15,%rdx
call   1070 <print_matrix@plt>
mov    %r14,%rdi
call   1050 <free_matrix@plt>
mov    %rbx,%rdi
call   1050 <free_matrix@plt>
mov    %r15,%rdi
call   1050 <free_matrix@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"Matrix1:\0A\00"
@.str.1 = [10 x i8] c"Matrix2:\0A\00"
@.str.2 = [10 x i8] c"Matrix3:\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 3, i32* %9
store i32 2, i32* %10
store i32 3, i32* %11
%14 = call double* @new_matrix(i32 3, i32 2)
store double* %14, double** %6
%15 = call double* @new_matrix(i32 2, i32 3)
store double* %15, double** %7
%16 = call double* @new_matrix(i32 3, i32 3)
store double* %16, double** %8
store i32 0, i32* %12
br label %17
17: ; preds = %38, %2
%18 = load i32, i32* %12
%19 = icmp slt i32 %18, 3
br i1 %19, label %20, label %41
20: ; preds = %17
store i32 0, i32* %13
br label %21
21: ; preds = %34, %20
%22 = load i32, i32* %13
%23 = icmp slt i32 %22, 2
br i1 %23, label %24, label %37
24: ; preds = %21
%25 = load i32, i32* %12
%26 = sitofp i32 %25 to double
%27 = load double*, double** %6
%28 = load i32, i32* %12
%29 = mul nsw i32 %28, 2
%30 = load i32, i32* %13
%31 = add nsw i32 %29, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %27, i64 %32
store double %26, double* %33
br label %34
34: ; preds = %24
%35 = load i32, i32* %13
%36 = add nsw i32 %35, 1
store i32 %36, i32* %13
br label %21
37: ; preds = %21
br label %38
38: ; preds = %37
%39 = load i32, i32* %12
%40 = add nsw i32 %39, 1
store i32 %40, i32* %12
br label %17
41: ; preds = %17
store i32 0, i32* %12
br label %42
42: ; preds = %63, %41
%43 = load i32, i32* %12
%44 = icmp slt i32 %43, 2
br i1 %44, label %45, label %66
45: ; preds = %42
store i32 0, i32* %13
br label %46
46: ; preds = %59, %45
%47 = load i32, i32* %13
%48 = icmp slt i32 %47, 3
br i1 %48, label %49, label %62
49: ; preds = %46
%50 = load i32, i32* %13
%51 = sitofp i32 %50 to double
%52 = load double*, double** %7
%53 = load i32, i32* %12
%54 = mul nsw i32 %53, 3
%55 = load i32, i32* %13
%56 = add nsw i32 %54, %55
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %52, i64 %57
store double %51, double* %58
br label %59
59: ; preds = %49
%60 = load i32, i32* %13
%61 = add nsw i32 %60, 1
store i32 %61, i32* %13
br label %46
62: ; preds = %46
br label %63
63: ; preds = %62
%64 = load i32, i32* %12
%65 = add nsw i32 %64, 1
store i32 %65, i32* %12
br label %42
66: ; preds = %42
%67 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%68 = load double*, double** %6
%69 = call i32 @print_matrix(i32 3, i32 2, double* %68)
%70 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%71 = load double*, double** %7
%72 = call i32 @print_matrix(i32 2, i32 3, double* %71)
%73 = load double*, double** %6
%74 = load double*, double** %7
%75 = load double*, double** %8
%76 = call i32 @multiply(i32 3, i32 2, i32 3, double* %73, double* %74, double* %75)
%77 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%78 = load double*, double** %8
%79 = call i32 @print_matrix(i32 3, i32 3, double* %78)
%80 = load double*, double** %6
%81 = call i32 @free_matrix(double* %80)
%82 = load double*, double** %7
%83 = call i32 @free_matrix(double* %82)
%84 = load double*, double** %8
%85 = call i32 @free_matrix(double* %84)
ret i32 0
}

LLVM IR (-O2):
@str = [9 x i8] c"Matrix1:\00"
@str.3 = [9 x i8] c"Matrix2:\00"
@str.4 = [9 x i8] c"Matrix3:\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call double* @new_matrix(i32 3, i32 2)
%4 = tail call double* @new_matrix(i32 2, i32 3)
%5 = tail call double* @new_matrix(i32 3, i32 3)
%6 = getelementptr inbounds double, double* %3, i64 2
%7 = bitcast double* %3 to i8*
%8 = bitcast double* %6 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %8
%9 = getelementptr inbounds double, double* %3, i64 4
%10 = bitcast double* %9 to <2 x double>*
store <2 x double> <double 2.000000e+00, double 2.000000e+00>, <2 x double>* %10
%11 = bitcast double* %4 to <2 x double>*
store <2 x double> <double 0.000000e+00, double 1.000000e+00>, <2 x double>* %11
%12 = getelementptr inbounds double, double* %4, i64 2
%13 = bitcast double* %12 to <2 x double>*
store <2 x double> <double 2.000000e+00, double 0.000000e+00>, <2 x double>* %13
%14 = getelementptr inbounds double, double* %4, i64 4
%15 = bitcast double* %14 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 2.000000e+00>, <2 x double>* %15
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @print_matrix(i32 3, i32 2, double* %3)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.3, i64 0, i64 0))
%19 = tail call i32 @print_matrix(i32 2, i32 3, double* %4)
%20 = tail call i32 @multiply(i32 3, i32 2, i32 3, double* %3, double* %4, double* %5)
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.4, i64 0, i64 0))
%22 = tail call i32 @print_matrix(i32 3, i32 3, double* %5)
%23 = tail call i32 @free_matrix(double* %3)
%24 = tail call i32 @free_matrix(double* %4)
%25 = tail call i32 @free_matrix(double* %5)
ret i32 0
}