#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 */
double *alloc_matrix(int);
scalar_t__ compare_matrix(double *, double *, int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ matrix_mul_basic(double *, double *, double *, int);
int /*<<< orphan*/ matrix_mul_blocked(double *, double *, double *, int, int);
int /*<<< orphan*/ matrix_mul_transposed(double *, double *, double *, int);
int /*<<< orphan*/ printf(char *, char *);
double *random_matrix(int);
void test_matrix(int n) {
  double *a = random_matrix(n);
  double *b = random_matrix(n);
  double *x = alloc_matrix(n);
  double *y = alloc_matrix(n);
  matrix_mul_basic(x, a, b, n);
  matrix_mul_transposed(y, a, b, n);
  printf("matrix_mul_transposed: %s\n",
         compare_matrix(x, y, n) ? "pass" : "fail");
  matrix_mul_blocked(y, a, b, n, 16);
  printf("matrix_mul_blocked: %s\n", compare_matrix(x, y, n) ? "pass" : "fail");
  free(a);
  free(b);
  free(x);
  free(y);
}


x86 assembly (clang, -O0):
<test_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1070 <random_matrix@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1070 <random_matrix@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <alloc_matrix@plt>
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <alloc_matrix@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x4(%rbp),%ecx
call   1090 <matrix_mul_basic@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x4(%rbp),%ecx
call   10a0 <matrix_mul_transposed@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x4(%rbp),%edx
call   1060 <compare_matrix@plt>
mov    %rax,%rcx
lea    0xe23(%rip),%rsi
lea    0xe17(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xded(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x4(%rbp),%ecx
mov    $0x10,%r8d
call   1080 <matrix_mul_blocked@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x4(%rbp),%edx
call   1060 <compare_matrix@plt>
mov    %rax,%rcx
lea    0xdd4(%rip),%rsi
lea    0xdc8(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xdc3(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebp
call   1070 <random_matrix@plt>
mov    %rax,%r14
mov    %ebp,%edi
call   1070 <random_matrix@plt>
mov    %rax,%r15
mov    %ebp,%edi
call   1040 <alloc_matrix@plt>
mov    %rax,%r12
mov    %ebp,%edi
call   1040 <alloc_matrix@plt>
mov    %rax,%r13
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %ebp,%ecx
call   1090 <matrix_mul_basic@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %ebp,%ecx
call   10a0 <matrix_mul_transposed@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1060 <compare_matrix@plt>
test   %rax,%rax
lea    0xe36(%rip),%rax
lea    0xe2a(%rip),%rbx
mov    %rbx,%rsi
cmove  %rax,%rsi
lea    0xe01(%rip),%rdi
call   1050 <printf@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %ebp,%ecx
mov    $0x10,%r8d
call   1080 <matrix_mul_blocked@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1060 <compare_matrix@plt>
test   %rax,%rax
lea    0xdef(%rip),%rax
cmove  %rax,%rbx
lea    0xde9(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"matrix_mul_transposed: %s\0A\00"
@.str.1 = [5 x i8] c"pass\00"
@.str.2 = [5 x i8] c"fail\00"
@.str.3 = [24 x i8] c"matrix_mul_blocked: %s\0A\00"
define void @test_matrix(i32 %0) {
%2 = alloca i32
%3 = alloca double*
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = call double* @random_matrix(i32 %7)
store double* %8, double** %3
%9 = load i32, i32* %2
%10 = call double* @random_matrix(i32 %9)
store double* %10, double** %4
%11 = load i32, i32* %2
%12 = call double* @alloc_matrix(i32 %11)
store double* %12, double** %5
%13 = load i32, i32* %2
%14 = call double* @alloc_matrix(i32 %13)
store double* %14, double** %6
%15 = load double*, double** %5
%16 = load double*, double** %3
%17 = load double*, double** %4
%18 = load i32, i32* %2
%19 = call i32 @matrix_mul_basic(double* %15, double* %16, double* %17, i32 %18)
%20 = load double*, double** %6
%21 = load double*, double** %3
%22 = load double*, double** %4
%23 = load i32, i32* %2
%24 = call i32 @matrix_mul_transposed(double* %20, double* %21, double* %22, i32 %23)
%25 = load double*, double** %5
%26 = load double*, double** %6
%27 = load i32, i32* %2
%28 = call i64 @compare_matrix(double* %25, double* %26, i32 %27)
%29 = icmp ne i64 %28, 0
%30 = zext i1 %29 to i64
%31 = select i1 %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%32 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %31)
%33 = load double*, double** %6
%34 = load double*, double** %3
%35 = load double*, double** %4
%36 = load i32, i32* %2
%37 = call i32 @matrix_mul_blocked(double* %33, double* %34, double* %35, i32 %36, i32 16)
%38 = load double*, double** %5
%39 = load double*, double** %6
%40 = load i32, i32* %2
%41 = call i64 @compare_matrix(double* %38, double* %39, i32 %40)
%42 = icmp ne i64 %41, 0
%43 = zext i1 %42 to i64
%44 = select i1 %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%45 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %44)
%46 = load double*, double** %3
%47 = call i32 @free(double* %46)
%48 = load double*, double** %4
%49 = call i32 @free(double* %48)
%50 = load double*, double** %5
%51 = call i32 @free(double* %50)
%52 = load double*, double** %6
%53 = call i32 @free(double* %52)
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"matrix_mul_transposed: %s\0A\00"
@.str.1 = [5 x i8] c"pass\00"
@.str.2 = [5 x i8] c"fail\00"
@.str.3 = [24 x i8] c"matrix_mul_blocked: %s\0A\00"
define void @test_matrix(i32 %0) {
%2 = tail call double* @random_matrix(i32 %0)
%3 = tail call double* @random_matrix(i32 %0)
%4 = tail call double* @alloc_matrix(i32 %0)
%5 = tail call double* @alloc_matrix(i32 %0)
%6 = tail call i32 @matrix_mul_basic(double* %4, double* %2, double* %3, i32 %0)
%7 = tail call i32 @matrix_mul_transposed(double* %5, double* %2, double* %3, i32 %0)
%8 = tail call i64 @compare_matrix(double* %4, double* %5, i32 %0)
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @matrix_mul_blocked(double* %5, double* %2, double* %3, i32 %0, i32 16)
%13 = tail call i64 @compare_matrix(double* %4, double* %5, i32 %0)
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = tail call i32 @free(double* %2)
%18 = tail call i32 @free(double* %3)
%19 = tail call i32 @free(double* %4)
%20 = tail call i32 @free(double* %5)
ret void
}