#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*/ debug_matrix(int *, int);
void *malloc(int);
int /*<<< orphan*/ square_matrix_multiply(int *, int *, int, int *);
int main(int argc, char *argv[]) {
  int i, j;
  int a[4][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}};
  int b[4][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}};
  int n;
  int **c;
  c = malloc(sizeof(int *) * 4);
  for (i = 0; i < 4; i++)
    c[i] = malloc(sizeof(int) * 4);
  square_matrix_multiply((int *)a, (int *)b, 4, (int *)c);
  debug_matrix((int *)c, 4);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe9c(%rip),%rsi
mov    $0x40,%edx
call   1040 <memcpy@plt>
lea    -0xa0(%rbp),%rdi
lea    0xec4(%rip),%rsi
mov    $0x40,%edx
call   1040 <memcpy@plt>
mov    $0x20,%edi
call   1050 <malloc@plt>
mov    %rax,-0xb0(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    11d2 <main+0x92>
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0xb0(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119e <main+0x5e>
lea    -0x60(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
mov    -0xb0(%rbp),%rcx
mov    $0x4,%edx
call   1030 <square_matrix_multiply@plt>
mov    -0xb0(%rbp),%rdi
mov    $0x4,%esi
call   1060 <debug_matrix@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
movaps 0xef1(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xed5(%rip),%xmm1
movaps %xmm1,0x60(%rsp)
movaps 0xeb9(%rip),%xmm2
movaps %xmm2,0x50(%rsp)
movaps 0xe9d(%rip),%xmm3
movaps %xmm3,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm1,0x20(%rsp)
movaps %xmm2,0x10(%rsp)
movaps %xmm3,(%rsp)
mov    $0x20,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,0x8(%rbx)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,0x10(%rbx)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,0x18(%rbx)
lea    0x40(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1030 <square_matrix_multiply@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1050 <debug_matrix@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.a = [4 x [4 x i32]] [[4 x i32] [i32 1, i32 2, i32 3, i32 4], [4 x i32] [i32 5, i32 6, i32 7, i32 8], [4 x i32] [i32 9, i32 10, i32 11, i32 12], [4 x i32] [i32 13, i32 14, i32 15, i32 16]]
@__const.main.b = [4 x [4 x i32]] [[4 x i32] [i32 1, i32 2, i32 3, i32 4], [4 x i32] [i32 5, i32 6, i32 7, i32 8], [4 x i32] [i32 9, i32 10, i32 11, i32 12], [4 x i32] [i32 13, i32 14, i32 15, i32 16]]
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4 x [4 x i32]]
%9 = alloca [4 x [4 x i32]]
%10 = alloca i32
%11 = alloca i32**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [4 x [4 x i32]]* %8 to i8*
%13 = bitcast [4 x [4 x i32]]* %9 to i8*
%14 = call i8* @malloc(i32 32)
%15 = bitcast i8* %14 to i32**
store i32** %15, i32*** %11
store i32 0, i32* %6
br label %16
16: ; preds = %26, %2
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 4
br i1 %18, label %19, label %29
19: ; preds = %16
%20 = call i8* @malloc(i32 16)
%21 = bitcast i8* %20 to i32*
%22 = load i32**, i32*** %11
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32*, i32** %22, i64 %24
store i32* %21, i32** %25
br label %26
26: ; preds = %19
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
br label %16
29: ; preds = %16
%30 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %8, i64 0, i64 0
%31 = bitcast [4 x i32]* %30 to i32*
%32 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %9, i64 0, i64 0
%33 = bitcast [4 x i32]* %32 to i32*
%34 = load i32**, i32*** %11
%35 = bitcast i32** %34 to i32*
%36 = call i32 @square_matrix_multiply(i32* %31, i32* %33, i32 4, i32* %35)
%37 = load i32**, i32*** %11
%38 = bitcast i32** %37 to i32*
%39 = call i32 @debug_matrix(i32* %38, i32 4)
ret i32 0
}

LLVM IR (-O2):
@__const.main.b = [4 x [4 x i32]] [[4 x i32] [i32 1, i32 2, i32 3, i32 4], [4 x i32] [i32 5, i32 6, i32 7, i32 8], [4 x i32] [i32 9, i32 10, i32 11, i32 12], [4 x i32] [i32 13, i32 14, i32 15, i32 16]]
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4 x [4 x i32]]
%4 = alloca [4 x [4 x i32]]
%5 = bitcast [4 x [4 x i32]]* %3 to i8*
%6 = bitcast [4 x [4 x i32]]* %4 to i8*
%7 = tail call dereferenceable_or_null(32) i8* @malloc(i32 32)
%8 = bitcast i8* %7 to i32**
%9 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%10 = bitcast i8* %7 to i8**
store i8* %9, i8** %10
%11 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%12 = getelementptr inbounds i32*, i32** %8, i64 1
%13 = bitcast i32** %12 to i8**
store i8* %11, i8** %13
%14 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%15 = getelementptr inbounds i32*, i32** %8, i64 2
%16 = bitcast i32** %15 to i8**
store i8* %14, i8** %16
%17 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%18 = getelementptr inbounds i32*, i32** %8, i64 3
%19 = bitcast i32** %18 to i8**
store i8* %17, i8** %19
%20 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 0, i64 0
%21 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %4, i64 0, i64 0, i64 0
%22 = bitcast i8* %7 to i32*
%23 = call i32 @square_matrix_multiply(i32* %20, i32* %21, i32 4, i32* %22)
%24 = call i32 @debug_matrix(i32* %22, i32 4)
ret i32 0
}