#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 **allocate_array_2d(int, int);
int /*<<< orphan*/ free_2d(int **, int);
int **matrix_multi(int **, int **, int, int, int);
int /*<<< orphan*/ print_array_2d(int **, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rand_2d(int **, int, int);
int /*<<< orphan*/ scanf(char *, int *, int *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  int n, m, p;
  printf("Give dimensions: n, m, p: ");
  scanf("%d %d %d", &n, &m, &p);
  int **A = allocate_array_2d(n, m), **B = allocate_array_2d(m, p),
      **C = allocate_array_2d(n, p);
  srand(time(NULL));
  rand_2d(A, n, m);
  rand_2d(B, m, p);
  print_array_2d(A, n, m);
  print_array_2d(B, m, p);
  C = matrix_multi(A, B, n, m, p);
  print_array_2d(C, n, p);
  free_2d(A, n);
  free_2d(B, m);
  free_2d(C, n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
lea    0xe69(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1090 <scanf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <allocate_array_2d@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1050 <allocate_array_2d@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1050 <allocate_array_2d@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   10b0 <rand_2d@plt>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   10b0 <rand_2d@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   10a0 <print_array_2d@plt>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   10a0 <print_array_2d@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
call   1030 <matrix_multi@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
call   10a0 <print_array_2d@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1080 <free_2d@plt>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1080 <free_2d@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1080 <free_2d@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
lea    0xe6f(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
lea    0xc(%rsp),%rcx
call   1090 <scanf@plt>
mov    0x8(%rsp),%edi
mov    0x4(%rsp),%esi
call   1050 <allocate_array_2d@plt>
mov    %rax,%r14
mov    0x4(%rsp),%edi
mov    0xc(%rsp),%esi
call   1050 <allocate_array_2d@plt>
mov    %rax,%r15
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%esi
call   1050 <allocate_array_2d@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
mov    %r14,%rdi
call   10b0 <rand_2d@plt>
mov    0x4(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %r15,%rdi
call   10b0 <rand_2d@plt>
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
mov    %r14,%rdi
call   10a0 <print_array_2d@plt>
mov    0x4(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %r15,%rdi
call   10a0 <print_array_2d@plt>
mov    0x8(%rsp),%edx
mov    0x4(%rsp),%ecx
mov    0xc(%rsp),%r8d
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <matrix_multi@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %rax,%rdi
call   10a0 <print_array_2d@plt>
mov    0x8(%rsp),%esi
mov    %r14,%rdi
call   1080 <free_2d@plt>
mov    0x4(%rsp),%esi
mov    %r15,%rdi
call   1080 <free_2d@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1080 <free_2d@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Give dimensions: n, m, p: \00"
@.str.1 = [9 x i8] c"%d %d %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32**
%6 = alloca i32**
%7 = alloca i32**
store i32 0, i32* %1
%8 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = call i32** @allocate_array_2d(i32 %10, i32 %11)
store i32** %12, i32*** %5
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = call i32** @allocate_array_2d(i32 %13, i32 %14)
store i32** %15, i32*** %6
%16 = load i32, i32* %2
%17 = load i32, i32* %4
%18 = call i32** @allocate_array_2d(i32 %16, i32 %17)
store i32** %18, i32*** %7
%19 = call i32 @time(i32* null)
%20 = call i32 @srand(i32 %19)
%21 = load i32**, i32*** %5
%22 = load i32, i32* %2
%23 = load i32, i32* %3
%24 = call i32 @rand_2d(i32** %21, i32 %22, i32 %23)
%25 = load i32**, i32*** %6
%26 = load i32, i32* %3
%27 = load i32, i32* %4
%28 = call i32 @rand_2d(i32** %25, i32 %26, i32 %27)
%29 = load i32**, i32*** %5
%30 = load i32, i32* %2
%31 = load i32, i32* %3
%32 = call i32 @print_array_2d(i32** %29, i32 %30, i32 %31)
%33 = load i32**, i32*** %6
%34 = load i32, i32* %3
%35 = load i32, i32* %4
%36 = call i32 @print_array_2d(i32** %33, i32 %34, i32 %35)
%37 = load i32**, i32*** %5
%38 = load i32**, i32*** %6
%39 = load i32, i32* %2
%40 = load i32, i32* %3
%41 = load i32, i32* %4
%42 = call i32** @matrix_multi(i32** %37, i32** %38, i32 %39, i32 %40, i32 %41)
store i32** %42, i32*** %7
%43 = load i32**, i32*** %7
%44 = load i32, i32* %2
%45 = load i32, i32* %4
%46 = call i32 @print_array_2d(i32** %43, i32 %44, i32 %45)
%47 = load i32**, i32*** %5
%48 = load i32, i32* %2
%49 = call i32 @free_2d(i32** %47, i32 %48)
%50 = load i32**, i32*** %6
%51 = load i32, i32* %3
%52 = call i32 @free_2d(i32** %50, i32 %51)
%53 = load i32**, i32*** %7
%54 = load i32, i32* %2
%55 = call i32 @free_2d(i32** %53, i32 %54)
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Give dimensions: n, m, p: \00"
@.str.1 = [9 x i8] c"%d %d %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%9 = load i32, i32* %1
%10 = load i32, i32* %2
%11 = call i32** @allocate_array_2d(i32 %9, i32 %10)
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = call i32** @allocate_array_2d(i32 %12, i32 %13)
%15 = load i32, i32* %1
%16 = load i32, i32* %3
%17 = call i32** @allocate_array_2d(i32 %15, i32 %16)
%18 = call i32 @time(i32* null)
%19 = call i32 @srand(i32 %18)
%20 = load i32, i32* %1
%21 = load i32, i32* %2
%22 = call i32 @rand_2d(i32** %11, i32 %20, i32 %21)
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = call i32 @rand_2d(i32** %14, i32 %23, i32 %24)
%26 = load i32, i32* %1
%27 = load i32, i32* %2
%28 = call i32 @print_array_2d(i32** %11, i32 %26, i32 %27)
%29 = load i32, i32* %2
%30 = load i32, i32* %3
%31 = call i32 @print_array_2d(i32** %14, i32 %29, i32 %30)
%32 = load i32, i32* %1
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = call i32** @matrix_multi(i32** %11, i32** %14, i32 %32, i32 %33, i32 %34)
%36 = load i32, i32* %1
%37 = load i32, i32* %3
%38 = call i32 @print_array_2d(i32** %35, i32 %36, i32 %37)
%39 = load i32, i32* %1
%40 = call i32 @free_2d(i32** %11, i32 %39)
%41 = load i32, i32* %2
%42 = call i32 @free_2d(i32** %14, i32 %41)
%43 = load i32, i32* %1
%44 = call i32 @free_2d(i32** %35, i32 %43)
ret i32 0
}