#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 */
typedef int /*<<< orphan*/ matrix_c;
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
double **allocate_matrix(int, int);
scalar_t__ clock();
int /*<<< orphan*/ deallocate_matrix(double ***);
int /*<<< orphan*/ memset(double *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read_matrix_binaryformat(char *, double ***, int *, int *);
int /*<<< orphan*/ transpose_matrix(double ***, int *, int *);
int /*<<< orphan*/ transposed_matrix_multiplication(double **, double **,
                                                    double ***, int, int, int,
                                                    int);
int /*<<< orphan*/ write_matrix_binaryformat(char *, double **, int, int);
int main(int argc, char *argv[]) {
  if (argc != 4) {
    printf("argc = %d\n", argc);
    printf("Use: %s [infile a][infile b][outfile]\n", argv[0]);
    return -1;
  }
  clock_t begin, end;
  double time_spent;
  begin = clock();
  double **matrix_a;
  double **matrix_b;
  double **matrix_c;
  int num_rows_a;
  int num_cols_a;
  int num_rows_b;
  int num_cols_b;
  read_matrix_binaryformat(argv[1], &matrix_a, &num_rows_a, &num_cols_a);
  read_matrix_binaryformat(argv[2], &matrix_b, &num_rows_b, &num_cols_b);
  matrix_c = allocate_matrix(num_rows_a, num_cols_b);
  memset(&(matrix_c[0][0]), 0,
         sizeof(matrix_c[0][0]) * num_rows_a * num_cols_b);
  transpose_matrix(&matrix_b, &num_rows_b, &num_cols_b);
  transposed_matrix_multiplication(matrix_a, matrix_b, &matrix_c, num_rows_a,
                                   num_cols_a, num_rows_b, num_cols_b);
  write_matrix_binaryformat(argv[3], matrix_c, num_rows_a, num_rows_b);
  deallocate_matrix(&matrix_a);
  deallocate_matrix(&matrix_b);
  deallocate_matrix(&matrix_c);
  end = clock();
  time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  printf("%f seconds used in serial implementation\n", time_spent);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11e2 <main+0x52>
mov    -0x8(%rbp),%esi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f5 <main+0x165>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x44(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   1060 <read_matrix_binaryformat@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x4c(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   1060 <read_matrix_binaryformat@plt>
mov    -0x44(%rbp),%edi
mov    -0x50(%rbp),%esi
call   1080 <allocate_matrix@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%rdi
movslq -0x44(%rbp),%rax
shl    $0x3,%rax
movslq -0x50(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    -0x38(%rbp),%rdi
lea    -0x4c(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1070 <transpose_matrix@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x44(%rbp),%ecx
mov    -0x48(%rbp),%r8d
mov    -0x4c(%rbp),%r9d
mov    -0x50(%rbp),%eax
lea    -0x40(%rbp),%rdx
mov    %eax,(%rsp)
call   10a0 <transposed_matrix_multiplication@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x44(%rbp),%edx
mov    -0x4c(%rbp),%ecx
call   10b0 <write_matrix_binaryformat@plt>
lea    -0x30(%rbp),%rdi
call   1090 <deallocate_matrix@plt>
lea    -0x38(%rbp),%rdi
call   1090 <deallocate_matrix@plt>
lea    -0x40(%rbp),%rdi
call   1090 <deallocate_matrix@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d16(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xd4b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    12b0 <main+0x120>
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,0x28(%rsp)
mov    0x8(%rbx),%rdi
lea    0x20(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x14(%rsp),%rcx
call   1060 <read_matrix_binaryformat@plt>
mov    0x10(%rbx),%rdi
lea    0x30(%rsp),%r12
lea    0x10(%rsp),%r13
lea    0xc(%rsp),%r15
mov    %r12,%rsi
mov    %r13,%rdx
mov    %r15,%rcx
call   1060 <read_matrix_binaryformat@plt>
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%esi
call   1080 <allocate_matrix@plt>
mov    %rax,0x18(%rsp)
mov    (%rax),%rdi
mov    0x8(%rsp),%edx
imul   0xc(%rsp),%edx
shl    $0x3,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1070 <transpose_matrix@plt>
mov    0x20(%rsp),%rdi
mov    0x30(%rsp),%rsi
mov    0x8(%rsp),%ecx
mov    0x14(%rsp),%r8d
mov    0x10(%rsp),%r9d
mov    0xc(%rsp),%eax
mov    %eax,(%rsp)
lea    0x18(%rsp),%rbp
mov    %rbp,%rdx
call   10a0 <transposed_matrix_multiplication@plt>
mov    0x18(%rbx),%rdi
mov    0x18(%rsp),%rsi
mov    0x8(%rsp),%edx
mov    0x10(%rsp),%ecx
call   10b0 <write_matrix_binaryformat@plt>
lea    0x20(%rsp),%rdi
call   1090 <deallocate_matrix@plt>
mov    %r12,%rdi
call   1090 <deallocate_matrix@plt>
mov    %rbp,%rdi
call   1090 <deallocate_matrix@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    0x28(%rsp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d4c(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd8b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    12d7 <main+0x147>
mov    %edi,%esi
lea    0xd47(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rsi
lea    0xd41(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"argc = %d\0A\00"
@.str.1 = [39 x i8] c"Use: %s [infile a][infile b][outfile]\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.2 = [42 x i8] c"%f seconds used in serial implementation\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca double
%9 = alloca double**
%10 = alloca double**
%11 = alloca double**
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 4
br i1 %17, label %18, label %25
18: ; preds = %2
%19 = load i32, i32* %4
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %23)
store i32 -1, i32* %3
br label %77
25: ; preds = %2
%26 = call i64 (...) @clock()
store i64 %26, i64* %6
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @read_matrix_binaryformat(i8* %29, double*** %9, i32* %12, i32* %13)
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @read_matrix_binaryformat(i8* %33, double*** %10, i32* %14, i32* %15)
%35 = load i32, i32* %12
%36 = load i32, i32* %15
%37 = call double** @allocate_matrix(i32 %35, i32 %36)
store double** %37, double*** %11
%38 = load double**, double*** %11
%39 = getelementptr inbounds double*, double** %38, i64 0
%40 = load double*, double** %39
%41 = getelementptr inbounds double, double* %40, i64 0
%42 = load i32, i32* %12
%43 = sext i32 %42 to i64
%44 = mul i64 8, %43
%45 = load i32, i32* %15
%46 = sext i32 %45 to i64
%47 = mul i64 %44, %46
%48 = trunc i64 %47 to i32
%49 = call i32 @memset(double* %41, i32 0, i32 %48)
%50 = call i32 @transpose_matrix(double*** %10, i32* %14, i32* %15)
%51 = load double**, double*** %9
%52 = load double**, double*** %10
%53 = load i32, i32* %12
%54 = load i32, i32* %13
%55 = load i32, i32* %14
%56 = load i32, i32* %15
%57 = call i32 @transposed_matrix_multiplication(double** %51, double** %52, double*** %11, i32 %53, i32 %54, i32 %55, i32 %56)
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 3
%60 = load i8*, i8** %59
%61 = load double**, double*** %11
%62 = load i32, i32* %12
%63 = load i32, i32* %14
%64 = call i32 @write_matrix_binaryformat(i8* %60, double** %61, i32 %62, i32 %63)
%65 = call i32 @deallocate_matrix(double*** %9)
%66 = call i32 @deallocate_matrix(double*** %10)
%67 = call i32 @deallocate_matrix(double*** %11)
%68 = call i64 (...) @clock()
store i64 %68, i64* %7
%69 = load i64, i64* %7
%70 = load i64, i64* %6
%71 = sub nsw i64 %69, %70
%72 = sitofp i64 %71 to double
%73 = load double, double* @CLOCKS_PER_SEC
%74 = fdiv double %72, %73
store double %74, double* %8
%75 = load double, double* %8
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), double %75)
store i32 0, i32* %3
br label %77
77: ; preds = %25, %18
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@.str = [11 x i8] c"argc = %d\0A\00"
@.str.1 = [39 x i8] c"Use: %s [infile a][infile b][outfile]\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.2 = [42 x i8] c"%f seconds used in serial implementation\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca double**
%4 = alloca double**
%5 = alloca double**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = icmp eq i32 %0, 4
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %0)
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %62
15: ; preds = %2
%16 = tail call i64 (...) @clock()
%17 = bitcast double*** %3 to i8*
%18 = bitcast double*** %4 to i8*
%19 = bitcast double*** %5 to i8*
%20 = bitcast i32* %6 to i8*
%21 = bitcast i32* %7 to i8*
%22 = bitcast i32* %8 to i8*
%23 = bitcast i32* %9 to i8*
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @read_matrix_binaryformat(i8* %25, double*** %3, i32* %6, i32* %7)
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @read_matrix_binaryformat(i8* %28, double*** %4, i32* %8, i32* %9)
%30 = load i32, i32* %6
%31 = load i32, i32* %9
%32 = call double** @allocate_matrix(i32 %30, i32 %31)
store double** %32, double*** %5
%33 = load double*, double** %32
%34 = load i32, i32* %6
%35 = shl i32 %34, 3
%36 = load i32, i32* %9
%37 = mul i32 %35, %36
%38 = call i32 @memset(double* %33, i32 0, i32 %37)
%39 = call i32 @transpose_matrix(double*** %4, i32* %8, i32* %9)
%40 = load double**, double*** %3
%41 = load double**, double*** %4
%42 = load i32, i32* %6
%43 = load i32, i32* %7
%44 = load i32, i32* %8
%45 = load i32, i32* %9
%46 = call i32 @transposed_matrix_multiplication(double** %40, double** %41, double*** %5, i32 %42, i32 %43, i32 %44, i32 %45)
%47 = getelementptr inbounds i8*, i8** %1, i64 3
%48 = load i8*, i8** %47
%49 = load double**, double*** %5
%50 = load i32, i32* %6
%51 = load i32, i32* %8
%52 = call i32 @write_matrix_binaryformat(i8* %48, double** %49, i32 %50, i32 %51)
%53 = call i32 @deallocate_matrix(double*** %3)
%54 = call i32 @deallocate_matrix(double*** %4)
%55 = call i32 @deallocate_matrix(double*** %5)
%56 = call i64 (...) @clock()
%57 = sub nsw i64 %56, %16
%58 = sitofp i64 %57 to double
%59 = load double, double* @CLOCKS_PER_SEC
%60 = fdiv double %58, %59
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), double %60)
br label %62
62: ; preds = %15, %11
%63 = phi i32 [ -1, %11 ], [ 0, %15 ]
ret i32 %63
}