#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 */
int atoi(char *);
double matrixMultiplication(int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int matrix_size = 100;
  if (argc > 1) {
    matrix_size = atoi(argv[1]);
    printf("Set matrix size to %d\n", matrix_size);
  } else {
    printf("Input argument is wrong, pls follow the arguments like: "
           "matrix_size block_size, \n");
  }
  int nthreads = 1;
  if (argc > 2) {
    nthreads = atoi(argv[2]);
    if (nthreads < 0) {
      printf("Set the number of threads is wrong\n");
      return -1;
    }
    printf("Set the number of threads is %d\n", nthreads);
  }
  float real_time, proc_time, mflops;
  long long flpins;
  int retval;
  printf("\n------------------------------------------------\n");
  printf("Start Matrix Multiplication\n");
  double total_t = matrixMultiplication(matrix_size, nthreads);
  printf("Total time for Matrix Mulitiplication with matrix_size: %d, "
         "-threads: %d, -no blocking taken by CPU: %f\n",
         matrix_size, nthreads, total_t);
  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)
movl   $0x64,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    117d <main+0x4d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    118b <main+0x5b>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11e1 <main+0xb1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11d0 <main+0xa0>
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <main+0xfd>
mov    -0x18(%rbp),%esi
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <matrixMultiplication@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
movsd  -0x40(%rbp),%xmm0
lea    0xedf(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jle    1198 <main+0x58>
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%r15d
lea    0xe9c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebp
cmp    $0x2,%ebx
je     11af <main+0x6f>
mov    0x10(%r14),%rdi
call   1060 <atoi@plt>
test   %eax,%eax
js     11f1 <main+0xb1>
mov    %eax,%ebp
lea    0xe8a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11af <main+0x6f>
lea    0xf02(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
mov    $0x64,%r15d
lea    0xf3c(%rip),%rdi
call   1030 <puts@plt>
lea    0xf62(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%edi
mov    %ebp,%esi
call   1040 <matrixMultiplication@plt>
lea    0xe60(%rip),%rdi
mov    %r15d,%esi
mov    %ebp,%edx
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xf48(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    11e6 <main+0xa6>

LLVM IR (-O0):
@.str = [23 x i8] c"Set matrix size to %d\0A\00"
@.str.1 = [82 x i8] c"Input argument is wrong, pls follow the arguments like: matrix_size block_size, \0A\00"
@.str.2 = [36 x i8] c"Set the number of threads is wrong\0A\00"
@.str.3 = [33 x i8] c"Set the number of threads is %d\0A\00"
@.str.4 = [51 x i8] c"\0A------------------------------------------------\0A\00"
@.str.5 = [29 x i8] c"Start Matrix Multiplication\0A\00"
@.str.6 = [105 x i8] c"Total time for Matrix Mulitiplication with matrix_size: %d, -threads: %d, -no blocking taken by CPU: %f\0A\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 float
%9 = alloca float
%10 = alloca float
%11 = alloca i64
%12 = alloca i32
%13 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 100, i32* %6
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %25
23: ; preds = %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %16
store i32 1, i32* %7
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 2
br i1 %27, label %28, label %40
28: ; preds = %25
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %28
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %50
37: ; preds = %28
%38 = load i32, i32* %7
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %37, %25
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%43 = load i32, i32* %6
%44 = load i32, i32* %7
%45 = call double @matrixMultiplication(i32 %43, i32 %44)
store double %45, double* %13
%46 = load i32, i32* %6
%47 = load i32, i32* %7
%48 = load double, double* %13
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([105 x i8], [105 x i8]* @.str.6, i64 0, i64 0), i32 %46, i32 %47, double %48)
store i32 0, i32* %3
br label %50
50: ; preds = %40, %35
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str = [23 x i8] c"Set matrix size to %d\0A\00"
@.str.3 = [33 x i8] c"Set the number of threads is %d\0A\00"
@.str.6 = [105 x i8] c"Total time for Matrix Mulitiplication with matrix_size: %d, -threads: %d, -no blocking taken by CPU: %f\0A\00"
@str = [81 x i8] c"Input argument is wrong, pls follow the arguments like: matrix_size block_size, \00"
@str.7 = [50 x i8] c"\0A------------------------------------------------\00"
@str.8 = [28 x i8] c"Start Matrix Multiplication\00"
@str.9 = [35 x i8] c"Set the number of threads is wrong\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str, i64 0, i64 0))
br label %21
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp eq i32 %0, 2
br i1 %11, label %21, label %12
12: ; preds = %6
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.9, i64 0, i64 0))
br label %28
19: ; preds = %12
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %15)
br label %21
21: ; preds = %4, %19, %6
%22 = phi i32 [ %9, %19 ], [ %9, %6 ], [ 100, %4 ]
%23 = phi i32 [ %15, %19 ], [ 1, %6 ], [ 1, %4 ]
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.7, i64 0, i64 0))
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.8, i64 0, i64 0))
%26 = tail call double @matrixMultiplication(i32 %22, i32 %23)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([105 x i8], [105 x i8]* @.str.6, i64 0, i64 0), i32 %22, i32 %23, double %26)
br label %28
28: ; preds = %21, %17
%29 = phi i32 [ -1, %17 ], [ 0, %21 ]
ret i32 %29
}