#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*/ print_matrix(char *, int, int, int **);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  int matrix_a[3][2] = {{9, 0}, {5, 6}, {1, 2}};
  int matrix_b[2][3] = {{2, 4, 3}, {7, 8, 9}};
  int matrix_x[3][3] = {0};
  for (int row = 0; row < 3; row++) {
    for (int col = 0; col < 3; col++) {
      int sum = 0;
      for (int ctrl = 0; ctrl < 2; ctrl++)
        sum += matrix_a[row][ctrl] * matrix_b[ctrl][col];
      matrix_x[row][col] = sum;
    }
  }
  print_matrix("Matrix A", 3, 2, matrix_a);
  print_matrix("Matrix B", 2, 3, matrix_b);
  print_matrix("Matrix X", 3, 3, matrix_x);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeb0(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xead(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeaf(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xeac(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xea9(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x24,%edx
call   1040 <memset@plt>
movl   $0x0,-0x84(%rbp)
cmpl   $0x3,-0x84(%rbp)
jge    1292 <main+0x162>
movl   $0x0,-0x88(%rbp)
cmpl   $0x3,-0x88(%rbp)
jge    1279 <main+0x149>
movl   $0x0,-0x8c(%rbp)
movl   $0x0,-0x90(%rbp)
cmpl   $0x2,-0x90(%rbp)
jge    1243 <main+0x113>
movslq -0x84(%rbp),%rcx
lea    -0x30(%rbp),%rax
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x90(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
movslq -0x90(%rbp),%rdx
lea    -0x50(%rbp),%rcx
imul   $0xc,%rdx,%rdx
add    %rdx,%rcx
movslq -0x88(%rbp),%rdx
imul   (%rcx,%rdx,4),%eax
add    -0x8c(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x90(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x90(%rbp)
jmp    11dd <main+0xad>
mov    -0x8c(%rbp),%edx
movslq -0x84(%rbp),%rcx
lea    -0x80(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movslq -0x88(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    11bc <main+0x8c>
jmp    127e <main+0x14e>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11a5 <main+0x75>
lea    -0x30(%rbp),%rcx
lea    0xd9b(%rip),%rdi
mov    $0x3,%esi
mov    $0x2,%edx
call   1050 <print_matrix@plt>
lea    -0x50(%rbp),%rcx
lea    0xd8a(%rip),%rdi
mov    $0x2,%esi
mov    $0x3,%edx
call   1050 <print_matrix@plt>
lea    -0x80(%rbp),%rcx
lea    0xd79(%rip),%rdi
mov    $0x3,%edx
mov    %edx,%esi
call   1050 <print_matrix@plt>
lea    0xd6f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x68,%rsp
mov    0xf05(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xee9(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
mov    0xf0d(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0xef1(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0xea6(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xeaa(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movl   $0x15,0x60(%rsp)
lea    0xede(%rip),%rdi
lea    0x20(%rsp),%rcx
mov    $0x3,%esi
mov    $0x2,%edx
call   1040 <print_matrix@plt>
lea    0xecc(%rip),%rdi
mov    %rsp,%rcx
mov    $0x2,%esi
mov    $0x3,%edx
call   1040 <print_matrix@plt>
lea    0xebc(%rip),%rdi
lea    0x40(%rsp),%rcx
mov    $0x3,%esi
mov    $0x3,%edx
call   1040 <print_matrix@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x68,%rsp
ret

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

LLVM IR (-O2):
@__const.main.matrix_a = [3 x [2 x i32]] [[2 x i32] [i32 9, i32 0], [2 x i32] [i32 5, i32 6], [2 x i32] [i32 1, i32 2]]
@__const.main.matrix_b = [2 x [3 x i32]] [[3 x i32] [i32 2, i32 4, i32 3], [3 x i32] [i32 7, i32 8, i32 9]]
@.str = [9 x i8] c"Matrix A\00"
@.str.1 = [9 x i8] c"Matrix B\00"
@.str.2 = [9 x i8] c"Matrix X\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x [2 x i32]]
%4 = alloca [2 x [3 x i32]]
%5 = alloca [3 x [3 x i32]]
%6 = bitcast [3 x [2 x i32]]* %3 to i8*
%7 = bitcast [2 x [3 x i32]]* %4 to i8*
%8 = bitcast [3 x [3 x i32]]* %5 to i8*
%9 = bitcast [3 x [3 x i32]]* %5 to <4 x i32>*
store <4 x i32> <i32 18, i32 36, i32 27, i32 52>, <4 x i32>* %9
%10 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %5, i64 0, i64 1, i64 1
%11 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> <i32 68, i32 69, i32 16, i32 20>, <4 x i32>* %11
%12 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %5, i64 0, i64 2, i64 2
store i32 21, i32* %12
%13 = bitcast [3 x [2 x i32]]* %3 to i32**
%14 = call i32 @print_matrix(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 3, i32 2, i32** %13)
%15 = bitcast [2 x [3 x i32]]* %4 to i32**
%16 = call i32 @print_matrix(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 3, i32** %15)
%17 = bitcast [3 x [3 x i32]]* %5 to i32**
%18 = call i32 @print_matrix(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 3, i32 3, i32** %17)
%19 = call i32 @putchar(i32 10)
ret i32 0
}