#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*/ FILE;

/* Variables and functions */
double CLOCKS_PER_SEC;
double clock();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, int *);
int **makeMatrix9(int, int);
int /*<<< orphan*/ matrixProdCole9(int **, int **, int **, int, int, int);
int /*<<< orphan*/ printf(char *, int, int, double);
int /*<<< orphan*/ readMatrix9(int /*<<< orphan*/ *, int **, int, int);
void exercise_3_9(char *filename) {
  FILE *fin;
  int **m1;
  int **m2;
  int **m3;
  int m, n;
  double startT, stopT;
  fin = fopen(filename, "r");
  fscanf(fin, "%d %d", &m, &n);
  m1 = makeMatrix9(m, n);
  readMatrix9(fin, m1, m, n);
  m2 = makeMatrix9(n, m);
  readMatrix9(fin, m2, n, m);
  fclose(fin);
  m3 = makeMatrix9(m, m);
  startT = clock();
  matrixProdCole9(m1, m2, m3, m, n, 10);
  stopT = clock();
  printf("%d * %d; SEQUENTIAL; %f secs\n", m, n,
         (stopT - startT) / CLOCKS_PER_SEC);
}


x86 assembly (clang, -O0):
<exercise_3_9>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe57(%rip),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1070 <fscanf@plt>
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1030 <makeMatrix9@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
call   1080 <readMatrix9@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1030 <makeMatrix9@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
call   1080 <readMatrix9@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x2c(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1030 <makeMatrix9@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    -0x30(%rbp),%r8d
mov    $0xa,%r9d
call   1090 <matrixProdCole9@plt>
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
movsd  -0x40(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
mov    0x2d87(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd9c(%rip),%rdi
call   1060 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exercise_3_9>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe70(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
lea    0xe63(%rip),%rsi
mov    %rsp,%rdx
lea    0x4(%rsp),%rcx
mov    %rax,%rdi
call   1070 <fscanf@plt>
mov    (%rsp),%edi
mov    0x4(%rsp),%esi
call   1030 <makeMatrix9@plt>
mov    %rax,%r14
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1080 <readMatrix9@plt>
mov    0x4(%rsp),%edi
mov    (%rsp),%esi
call   1030 <makeMatrix9@plt>
mov    %rax,%r15
mov    0x4(%rsp),%edx
mov    (%rsp),%ecx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1080 <readMatrix9@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    (%rsp),%edi
mov    %edi,%esi
call   1030 <makeMatrix9@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <clock@plt>
movsd  %xmm0,0x8(%rsp)
mov    (%rsp),%ecx
mov    0x4(%rsp),%r8d
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    $0xa,%r9d
call   1090 <matrixProdCole9@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
subsd  0x8(%rsp),%xmm0
mov    0x2d9e(%rip),%rax
divsd  (%rax),%xmm0
lea    0xdb3(%rip),%rdi
call   1060 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [30 x i8] c"%d * %d; SEQUENTIAL; %f secs\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define void @exercise_3_9(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32**
%5 = alloca i32**
%6 = alloca i32**
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
store i8* %0, i8** %2
%11 = load i8*, i8** %2
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %3
%13 = load i32*, i32** %3
%14 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %7, i32* %8)
%15 = load i32, i32* %7
%16 = load i32, i32* %8
%17 = call i32** @makeMatrix9(i32 %15, i32 %16)
store i32** %17, i32*** %4
%18 = load i32*, i32** %3
%19 = load i32**, i32*** %4
%20 = load i32, i32* %7
%21 = load i32, i32* %8
%22 = call i32 @readMatrix9(i32* %18, i32** %19, i32 %20, i32 %21)
%23 = load i32, i32* %8
%24 = load i32, i32* %7
%25 = call i32** @makeMatrix9(i32 %23, i32 %24)
store i32** %25, i32*** %5
%26 = load i32*, i32** %3
%27 = load i32**, i32*** %5
%28 = load i32, i32* %8
%29 = load i32, i32* %7
%30 = call i32 @readMatrix9(i32* %26, i32** %27, i32 %28, i32 %29)
%31 = load i32*, i32** %3
%32 = call i32 @fclose(i32* %31)
%33 = load i32, i32* %7
%34 = load i32, i32* %7
%35 = call i32** @makeMatrix9(i32 %33, i32 %34)
store i32** %35, i32*** %6
%36 = call double (...) @clock()
store double %36, double* %9
%37 = load i32**, i32*** %4
%38 = load i32**, i32*** %5
%39 = load i32**, i32*** %6
%40 = load i32, i32* %7
%41 = load i32, i32* %8
%42 = call i32 @matrixProdCole9(i32** %37, i32** %38, i32** %39, i32 %40, i32 %41, i32 10)
%43 = call double (...) @clock()
store double %43, double* %10
%44 = load i32, i32* %7
%45 = load i32, i32* %8
%46 = load double, double* %10
%47 = load double, double* %9
%48 = fsub double %46, %47
%49 = load double, double* @CLOCKS_PER_SEC
%50 = fdiv double %48, %49
%51 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %44, i32 %45, double %50)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [30 x i8] c"%d * %d; SEQUENTIAL; %f secs\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define void @exercise_3_9(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = call i32** @makeMatrix9(i32 %8, i32 %9)
%11 = load i32, i32* %2
%12 = load i32, i32* %3
%13 = call i32 @readMatrix9(i32* %6, i32** %10, i32 %11, i32 %12)
%14 = load i32, i32* %3
%15 = load i32, i32* %2
%16 = call i32** @makeMatrix9(i32 %14, i32 %15)
%17 = load i32, i32* %3
%18 = load i32, i32* %2
%19 = call i32 @readMatrix9(i32* %6, i32** %16, i32 %17, i32 %18)
%20 = call i32 @fclose(i32* %6)
%21 = load i32, i32* %2
%22 = call i32** @makeMatrix9(i32 %21, i32 %21)
%23 = call double (...) @clock()
%24 = load i32, i32* %2
%25 = load i32, i32* %3
%26 = call i32 @matrixProdCole9(i32** %10, i32** %16, i32** %22, i32 %24, i32 %25, i32 10)
%27 = call double (...) @clock()
%28 = load i32, i32* %2
%29 = load i32, i32* %3
%30 = fsub double %27, %23
%31 = load double, double* @CLOCKS_PER_SEC
%32 = fdiv double %30, %31
%33 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 %29, double %32)
ret void
}