#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;
int atoi(char *);
scalar_t__ calloc(int, int);
scalar_t__ clock();
int /*<<< orphan*/ multiply_blocked(double *, double *, double *, int, int);
int /*<<< orphan*/ multiply_naive(double *, double *, double *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ readMatrix(char *, double *, int);
scalar_t__ strcmp(char *, char *);
int main(int arc, char **argv) {
  char *method = argv[1];
  int n = atoi(argv[2]);
  char *filenameA = argv[3];
  char *filenameB = argv[4];
  int block_size = n;
  if (strcmp(method, "blocked") == 0) {
    block_size = atoi(argv[5]);
  }
  printf("method=%s\nN=%d\nB=%d\nmatrix A: %s\nmatrix B: %s\n", method, n,
         block_size, filenameA, filenameB);
  double *a = (double *)calloc(sizeof(double), n * n);
  double *b = (double *)calloc(sizeof(double), n * n);
  readMatrix(filenameA, a, n);
  readMatrix(filenameB, b, n);
  double *c = (double *)calloc(sizeof(double), n * n);
  clock_t begin, end;
  double time_spent;
  begin = clock();
  if (strcmp(method, "blocked") == 0) {
    multiply_blocked(a, b, c, n, block_size);
  } else {
    multiply_naive(a, b, c, n);
  }
  end = clock();
  time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  printf("time: %lf\n", time_spent);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe25(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    11fa <main+0x7a>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%esi
imul   -0x1c(%rbp),%esi
mov    $0x8,%edi
call   1060 <calloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x1c(%rbp),%esi
imul   -0x1c(%rbp),%esi
mov    $0x8,%edi
call   1060 <calloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <readMatrix@plt>
mov    -0x30(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <readMatrix@plt>
mov    -0x1c(%rbp),%esi
imul   -0x1c(%rbp),%esi
mov    $0x8,%edi
call   1060 <calloc@plt>
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd71(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12bb <main+0x13b>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x50(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x34(%rbp),%r8d
call   10a0 <multiply_blocked@plt>
jmp    12cf <main+0x14f>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x50(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1090 <multiply_naive@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
sub    -0x58(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2cfa(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
lea    0xd34(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x8(%rsi),%rbp
mov    0x10(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r12d
mov    0x18(%rbx),%r14
mov    0x20(%rbx),%r15
lea    0xe53(%rip),%rsi
mov    %rbp,%rdi
call   1070 <strcmp@plt>
mov    %r12d,%ecx
test   %rax,%rax
jne    11c8 <main+0x48>
mov    0x28(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
lea    0xe39(%rip),%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
mov    %ecx,0x4(%rsp)
mov    %r14,%r8
mov    %r15,%r9
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12d,%ebx
imul   %r12d,%ebx
mov    $0x8,%edi
mov    %ebx,%esi
call   1060 <calloc@plt>
mov    %rax,%r13
mov    $0x8,%edi
mov    %ebx,%esi
call   1060 <calloc@plt>
mov    %r14,%rdi
mov    %rax,%r14
mov    %r13,%rsi
mov    %r12d,%edx
call   1030 <readMatrix@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1030 <readMatrix@plt>
mov    $0x8,%edi
mov    %ebx,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r15
lea    0xdb9(%rip),%rsi
mov    %rbp,%rdi
call   1070 <strcmp@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r12d,%ecx
test   %rax,%rax
je     1267 <main+0xe7>
call   1090 <multiply_naive@plt>
jmp    1271 <main+0xf1>
mov    0x4(%rsp),%r8d
call   10a0 <multiply_blocked@plt>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r15,%rax
cvtsi2sd %rax,%xmm0
mov    0x2d61(%rip),%rax
divsd  (%rax),%xmm0
lea    0xda5(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"blocked\00"
@.str.1 = [47 x i8] c"method=%s\0AN=%d\0AB=%d\0Amatrix A: %s\0Amatrix B: %s\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.2 = [11 x i8] c"time: %lf\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
%14 = alloca i64
%15 = alloca i64
%16 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %7
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 3
%26 = load i8*, i8** %25
store i8* %26, i8** %8
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 4
%29 = load i8*, i8** %28
store i8* %29, i8** %9
%30 = load i32, i32* %7
store i32 %30, i32* %10
%31 = load i8*, i8** %6
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %2
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 5
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
store i32 %38, i32* %10
br label %39
39: ; preds = %34, %2
%40 = load i8*, i8** %6
%41 = load i32, i32* %7
%42 = load i32, i32* %10
%43 = load i8*, i8** %8
%44 = load i8*, i8** %9
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i8* %40, i32 %41, i32 %42, i8* %43, i8* %44)
%46 = load i32, i32* %7
%47 = load i32, i32* %7
%48 = mul nsw i32 %46, %47
%49 = call i64 @calloc(i32 8, i32 %48)
%50 = inttoptr i64 %49 to double*
store double* %50, double** %11
%51 = load i32, i32* %7
%52 = load i32, i32* %7
%53 = mul nsw i32 %51, %52
%54 = call i64 @calloc(i32 8, i32 %53)
%55 = inttoptr i64 %54 to double*
store double* %55, double** %12
%56 = load i8*, i8** %8
%57 = load double*, double** %11
%58 = load i32, i32* %7
%59 = call i32 @readMatrix(i8* %56, double* %57, i32 %58)
%60 = load i8*, i8** %9
%61 = load double*, double** %12
%62 = load i32, i32* %7
%63 = call i32 @readMatrix(i8* %60, double* %61, i32 %62)
%64 = load i32, i32* %7
%65 = load i32, i32* %7
%66 = mul nsw i32 %64, %65
%67 = call i64 @calloc(i32 8, i32 %66)
%68 = inttoptr i64 %67 to double*
store double* %68, double** %13
%69 = call i64 (...) @clock()
store i64 %69, i64* %14
%70 = load i8*, i8** %6
%71 = call i64 @strcmp(i8* %70, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%72 = icmp eq i64 %71, 0
br i1 %72, label %73, label %80
73: ; preds = %39
%74 = load double*, double** %11
%75 = load double*, double** %12
%76 = load double*, double** %13
%77 = load i32, i32* %7
%78 = load i32, i32* %10
%79 = call i32 @multiply_blocked(double* %74, double* %75, double* %76, i32 %77, i32 %78)
br label %86
80: ; preds = %39
%81 = load double*, double** %11
%82 = load double*, double** %12
%83 = load double*, double** %13
%84 = load i32, i32* %7
%85 = call i32 @multiply_naive(double* %81, double* %82, double* %83, i32 %84)
br label %86
86: ; preds = %80, %73
%87 = call i64 (...) @clock()
store i64 %87, i64* %15
%88 = load i64, i64* %15
%89 = load i64, i64* %14
%90 = sub nsw i64 %88, %89
%91 = sitofp i64 %90 to double
%92 = load double, double* @CLOCKS_PER_SEC
%93 = fdiv double %91, %92
store double %93, double* %16
%94 = load double, double* %16
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %94)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"blocked\00"
@.str.1 = [47 x i8] c"method=%s\0AN=%d\0AB=%d\0Amatrix A: %s\0Amatrix B: %s\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.2 = [11 x i8] c"time: %lf\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = getelementptr inbounds i8*, i8** %1, i64 2
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = getelementptr inbounds i8*, i8** %1, i64 3
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8*, i8** %1, i64 4
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 5
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
br label %18
18: ; preds = %14, %2
%19 = phi i32 [ %17, %14 ], [ %7, %2 ]
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i8* %4, i32 %7, i32 %19, i8* %9, i8* %11)
%21 = mul nsw i32 %7, %7
%22 = tail call i64 @calloc(i32 8, i32 %21)
%23 = inttoptr i64 %22 to double*
%24 = tail call i64 @calloc(i32 8, i32 %21)
%25 = inttoptr i64 %24 to double*
%26 = tail call i32 @readMatrix(i8* %9, double* %23, i32 %7)
%27 = tail call i32 @readMatrix(i8* %11, double* %25, i32 %7)
%28 = tail call i64 @calloc(i32 8, i32 %21)
%29 = inttoptr i64 %28 to double*
%30 = tail call i64 (...) @clock()
%31 = tail call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %18
%34 = tail call i32 @multiply_blocked(double* %23, double* %25, double* %29, i32 %7, i32 %19)
br label %37
35: ; preds = %18
%36 = tail call i32 @multiply_naive(double* %23, double* %25, double* %29, i32 %7)
br label %37
37: ; preds = %35, %33
%38 = tail call i64 (...) @clock()
%39 = sub nsw i64 %38, %30
%40 = sitofp i64 %39 to double
%41 = load double, double* @CLOCKS_PER_SEC
%42 = fdiv double %40, %41
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %42)
ret i32 0
}