#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 scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int **mult_square_matrix(int **, int **, int);
int /*<<< orphan*/ printf(char *, ...);
int **read_square_matrix(char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ unalloc_square_matrix(int **, int);
int /*<<< orphan*/ write_square_matrix(int **, int, char *);
int main(int argc, char *argv[]) {
  if (argc != 4) {
    printf("Usage: %s <matrix1.txt> <matrix2.txt> <outfile.txt>\n", argv[0]);
    exit(0);
  }
  int n, n2;
  clock_t begin, end;
  begin = clock();
  int **m1 = read_square_matrix(argv[1], &n);
  int **m2 = read_square_matrix(argv[2], &n2);
  if (n != n2) {
    fprintf(stderr, "Error: the matrices must have the same	order!\n");
    exit(1);
  }
  int **m3 = mult_square_matrix(m1, m2, n);
  write_square_matrix(m3, n, argv[3]);
  end = clock();
  printf("Execution time: %lf s\n", ((double)(end - begin)) / CLOCKS_PER_SEC);
  unalloc_square_matrix(m1, n);
  unalloc_square_matrix(m2, n);
  unalloc_square_matrix(m3, n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11bc <main+0x3c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x14(%rbp),%rsi
call   10a0 <read_square_matrix@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   10a0 <read_square_matrix@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     121c <main+0x9c>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <mult_square_matrix@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
call   1040 <write_square_matrix@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
sub    -0x20(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d85(%rip),%rax
divsd  (%rax),%xmm0
lea    0xdf6(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <unalloc_square_matrix@plt>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <unalloc_square_matrix@plt>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <unalloc_square_matrix@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    124d <main+0xcd>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r15
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
call   10a0 <read_square_matrix@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xc(%rsp),%rsi
call   10a0 <read_square_matrix@plt>
mov    0x8(%rsp),%edx
cmp    0xc(%rsp),%edx
jne    1265 <main+0xe5>
mov    %rax,%r12
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <mult_square_matrix@plt>
mov    %rax,%r13
mov    0x8(%rsp),%esi
mov    0x18(%rbx),%rdx
mov    %rax,%rdi
call   1040 <write_square_matrix@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r15,%rax
cvtsi2sd %rax,%xmm0
mov    0x2de1(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe52(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    0x8(%rsp),%esi
mov    %r14,%rdi
call   1070 <unalloc_square_matrix@plt>
mov    0x8(%rsp),%esi
mov    %r12,%rdi
call   1070 <unalloc_square_matrix@plt>
mov    0x8(%rsp),%esi
mov    %r13,%rdi
call   1070 <unalloc_square_matrix@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    (%rbx),%rsi
lea    0xda9(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    0xdc0(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [53 x i8] c"Usage: %s <matrix1.txt> <matrix2.txt> <outfile.txt>\0A\00"
@stderr = global i32 0
@.str.1 = [47 x i8] c"Error: the matrices must have the same\09order!\0A\00"
@.str.2 = [23 x i8] c"Execution time: %lf s\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%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 = load i32, i32* %4
%14 = icmp ne i32 %13, 4
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %2
%22 = call i64 (...) @clock()
store i64 %22, i64* %8
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32** @read_square_matrix(i8* %25, i32* %6)
store i32** %26, i32*** %10
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32** @read_square_matrix(i8* %29, i32* %7)
store i32** %30, i32*** %11
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = icmp ne i32 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %21
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %21
%39 = load i32**, i32*** %10
%40 = load i32**, i32*** %11
%41 = load i32, i32* %6
%42 = call i32** @mult_square_matrix(i32** %39, i32** %40, i32 %41)
store i32** %42, i32*** %12
%43 = load i32**, i32*** %12
%44 = load i32, i32* %6
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 3
%47 = load i8*, i8** %46
%48 = call i32 @write_square_matrix(i32** %43, i32 %44, i8* %47)
%49 = call i64 (...) @clock()
store i64 %49, i64* %9
%50 = load i64, i64* %9
%51 = load i64, i64* %8
%52 = sub nsw i64 %50, %51
%53 = sitofp i64 %52 to double
%54 = load double, double* @CLOCKS_PER_SEC
%55 = fdiv double %53, %54
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), double %55)
%57 = load i32**, i32*** %10
%58 = load i32, i32* %6
%59 = call i32 @unalloc_square_matrix(i32** %57, i32 %58)
%60 = load i32**, i32*** %11
%61 = load i32, i32* %6
%62 = call i32 @unalloc_square_matrix(i32** %60, i32 %61)
%63 = load i32**, i32*** %12
%64 = load i32, i32* %6
%65 = call i32 @unalloc_square_matrix(i32** %63, i32 %64)
ret i32 0
}

LLVM IR (-O2):
@.str = [53 x i8] c"Usage: %s <matrix1.txt> <matrix2.txt> <outfile.txt>\0A\00"
@stderr = global i32 0
@.str.1 = [47 x i8] c"Error: the matrices must have the same\09order!\0A\00"
@.str.2 = [23 x i8] c"Execution time: %lf s\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = icmp eq i32 %0, 4
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %2
%11 = bitcast i32* %3 to i8*
%12 = bitcast i32* %4 to i8*
%13 = tail call i64 (...) @clock()
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = call i32** @read_square_matrix(i8* %15, i32* %3)
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = call i32** @read_square_matrix(i8* %18, i32* %4)
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = icmp eq i32 %20, %21
br i1 %22, label %27, label %23
23: ; preds = %10
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %10
%28 = call i32** @mult_square_matrix(i32** %16, i32** %19, i32 %20)
%29 = load i32, i32* %3
%30 = getelementptr inbounds i8*, i8** %1, i64 3
%31 = load i8*, i8** %30
%32 = call i32 @write_square_matrix(i32** %28, i32 %29, i8* %31)
%33 = call i64 (...) @clock()
%34 = sub nsw i64 %33, %13
%35 = sitofp i64 %34 to double
%36 = load double, double* @CLOCKS_PER_SEC
%37 = fdiv double %35, %36
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), double %37)
%39 = load i32, i32* %3
%40 = call i32 @unalloc_square_matrix(i32** %16, i32 %39)
%41 = load i32, i32* %3
%42 = call i32 @unalloc_square_matrix(i32** %19, i32 %41)
%43 = load i32, i32* %3
%44 = call i32 @unalloc_square_matrix(i32** %28, i32 %43)
ret i32 0
}