#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 */
double *allocMat(int);
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ freeMat(double *);
int /*<<< orphan*/ genMat(int, double *);
int /*<<< orphan*/ mulMatSample(int, double *, double *, double *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ readMat(double *, char *);
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ writeMat(int, double *, char *);
int main(int argc, char **argv) {
  int matsize;
  char *filename_a, *filename_b, *filename_c;
  double *mata, *matb, *matc;
  if (argc != 5) {
    printf("Useage : \n\t$ genmat matsize filename1 filename2 filename3\n");
    printf("\tmatsize : N\n");
    printf("\tfilename1 : input matrix A\n");
    printf("\tfilename2 : input matrix B\n");
    printf("\tfilename3 : answer matrix C\n");
    exit(0);
  }
  srand((unsigned)time(NULL));
  matsize = atoi(argv[1]);
  filename_a = argv[2];
  filename_b = argv[3];
  filename_c = argv[4];
  printf("NxN : %dx%d\n", matsize, matsize);
  printf("mat A : [%s]\n", filename_a);
  printf("mat B : [%s]\n", filename_b);
  printf("mat C : [%s]\n", filename_c);
  mata = allocMat(matsize);
  matb = allocMat(matsize);
  matc = allocMat(matsize);
  genMat(matsize, mata);
  writeMat(matsize, mata, filename_a);
  genMat(matsize, matb);
  writeMat(matsize, matb, filename_b);
  readMat(mata, filename_a);
  readMat(matb, filename_b);
  mulMatSample(matsize, mata, matb, matc);
  writeMat(matsize, matc, filename_c);
  freeMat(mata);
  freeMat(matb);
  freeMat(matc);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     121d <main+0x6d>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%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    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   10b0 <allocMat@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
call   10b0 <allocMat@plt>
mov    %rax,-0x40(%rbp)
mov    -0x14(%rbp),%edi
call   10b0 <allocMat@plt>
mov    %rax,-0x48(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   10d0 <genMat@plt>
mov    -0x14(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <writeMat@plt>
mov    -0x14(%rbp),%edi
mov    -0x40(%rbp),%rsi
call   10d0 <genMat@plt>
mov    -0x14(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <writeMat@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <readMat@plt>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <readMat@plt>
mov    -0x14(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rcx
call   1080 <mulMatSample@plt>
mov    -0x14(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <writeMat@plt>
mov    -0x38(%rbp),%rdi
call   1060 <freeMat@plt>
mov    -0x40(%rbp),%rdi
call   1060 <freeMat@plt>
mov    -0x48(%rbp),%rdi
call   1060 <freeMat@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x5,%edi
jne    12ee <main+0x12e>
mov    %rsi,%rbp
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
mov    0x8(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebx
mov    0x10(%rbp),%r12
mov    0x18(%rbp),%r15
mov    0x20(%rbp),%rbp
mov    %rbp,(%rsp)
lea    0xdf9(%rip),%rdi
mov    %eax,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdf4(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdf1(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdee(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
call   10c0 <allocMat@plt>
mov    %rax,%r13
mov    %ebx,%edi
call   10c0 <allocMat@plt>
mov    %rax,%rbp
mov    %ebx,%edi
call   10c0 <allocMat@plt>
mov    %rax,%r14
mov    %ebx,%edi
mov    %r13,%rsi
call   10e0 <genMat@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    %r12,%rdx
call   1050 <writeMat@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   10e0 <genMat@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1050 <writeMat@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1030 <readMat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1030 <readMat@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
call   1090 <mulMatSample@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    (%rsp),%rdx
call   1050 <writeMat@plt>
mov    %r13,%rdi
call   1070 <freeMat@plt>
mov    %rbp,%rdi
call   1070 <freeMat@plt>
mov    %r14,%rdi
call   1070 <freeMat@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd42(%rip),%rdi
call   1040 <puts@plt>
lea    0xd70(%rip),%rdi
call   1040 <puts@plt>
lea    0xd71(%rip),%rdi
call   1040 <puts@plt>
lea    0xd81(%rip),%rdi
call   1040 <puts@plt>
lea    0xd91(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [59 x i8] c"Useage : \0A\09$ genmat matsize filename1 filename2 filename3\0A\00"
@.str.1 = [14 x i8] c"\09matsize : N\0A\00"
@.str.2 = [29 x i8] c"\09filename1 : input matrix A\0A\00"
@.str.3 = [29 x i8] c"\09filename2 : input matrix B\0A\00"
@.str.4 = [30 x i8] c"\09filename3 : answer matrix C\0A\00"
@.str.5 = [13 x i8] c"NxN : %dx%d\0A\00"
@.str.6 = [14 x i8] c"mat A : [%s]\0A\00"
@.str.7 = [14 x i8] c"mat B : [%s]\0A\00"
@.str.8 = [14 x i8] c"mat C : [%s]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
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, 5
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %2
%23 = call i64 @time(i32* null)
%24 = trunc i64 %23 to i32
%25 = call i32 @srand(i32 %24)
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %6
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
store i8* %32, i8** %7
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 3
%35 = load i8*, i8** %34
store i8* %35, i8** %8
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 4
%38 = load i8*, i8** %37
store i8* %38, i8** %9
%39 = load i32, i32* %6
%40 = load i32, i32* %6
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %39, i32 %40)
%42 = load i8*, i8** %7
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %42)
%44 = load i8*, i8** %8
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %44)
%46 = load i8*, i8** %9
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* %46)
%48 = load i32, i32* %6
%49 = call double* @allocMat(i32 %48)
store double* %49, double** %10
%50 = load i32, i32* %6
%51 = call double* @allocMat(i32 %50)
store double* %51, double** %11
%52 = load i32, i32* %6
%53 = call double* @allocMat(i32 %52)
store double* %53, double** %12
%54 = load i32, i32* %6
%55 = load double*, double** %10
%56 = call i32 @genMat(i32 %54, double* %55)
%57 = load i32, i32* %6
%58 = load double*, double** %10
%59 = load i8*, i8** %7
%60 = call i32 @writeMat(i32 %57, double* %58, i8* %59)
%61 = load i32, i32* %6
%62 = load double*, double** %11
%63 = call i32 @genMat(i32 %61, double* %62)
%64 = load i32, i32* %6
%65 = load double*, double** %11
%66 = load i8*, i8** %8
%67 = call i32 @writeMat(i32 %64, double* %65, i8* %66)
%68 = load double*, double** %10
%69 = load i8*, i8** %7
%70 = call i32 @readMat(double* %68, i8* %69)
%71 = load double*, double** %11
%72 = load i8*, i8** %8
%73 = call i32 @readMat(double* %71, i8* %72)
%74 = load i32, i32* %6
%75 = load double*, double** %10
%76 = load double*, double** %11
%77 = load double*, double** %12
%78 = call i32 @mulMatSample(i32 %74, double* %75, double* %76, double* %77)
%79 = load i32, i32* %6
%80 = load double*, double** %12
%81 = load i8*, i8** %9
%82 = call i32 @writeMat(i32 %79, double* %80, i8* %81)
%83 = load double*, double** %10
%84 = call i32 @freeMat(double* %83)
%85 = load double*, double** %11
%86 = call i32 @freeMat(double* %85)
%87 = load double*, double** %12
%88 = call i32 @freeMat(double* %87)
ret i32 0
}

LLVM IR (-O2):
@.str.5 = [13 x i8] c"NxN : %dx%d\0A\00"
@.str.6 = [14 x i8] c"mat A : [%s]\0A\00"
@.str.7 = [14 x i8] c"mat B : [%s]\0A\00"
@.str.8 = [14 x i8] c"mat C : [%s]\0A\00"
@str = [58 x i8] c"Useage : \0A\09$ genmat matsize filename1 filename2 filename3\00"
@str.9 = [13 x i8] c"\09matsize : N\00"
@str.10 = [28 x i8] c"\09filename1 : input matrix A\00"
@str.11 = [28 x i8] c"\09filename2 : input matrix B\00"
@str.12 = [29 x i8] c"\09filename3 : answer matrix C\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 5
br i1 %3, label %11, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.9, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.10, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.11, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.12, i64 0, i64 0))
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %2
%12 = tail call i64 @time(i32* null)
%13 = trunc i64 %12 to i32
%14 = tail call i32 @srand(i32 %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8*, i8** %1, i64 3
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8*, i8** %1, i64 4
%23 = load i8*, i8** %22
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %17, i32 %17)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %19)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %21)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* %23)
%28 = tail call double* @allocMat(i32 %17)
%29 = tail call double* @allocMat(i32 %17)
%30 = tail call double* @allocMat(i32 %17)
%31 = tail call i32 @genMat(i32 %17, double* %28)
%32 = tail call i32 @writeMat(i32 %17, double* %28, i8* %19)
%33 = tail call i32 @genMat(i32 %17, double* %29)
%34 = tail call i32 @writeMat(i32 %17, double* %29, i8* %21)
%35 = tail call i32 @readMat(double* %28, i8* %19)
%36 = tail call i32 @readMat(double* %29, i8* %21)
%37 = tail call i32 @mulMatSample(i32 %17, double* %28, double* %29, double* %30)
%38 = tail call i32 @writeMat(i32 %17, double* %30, i8* %23)
%39 = tail call i32 @freeMat(double* %28)
%40 = tail call i32 @freeMat(double* %29)
%41 = tail call i32 @freeMat(double* %30)
ret i32 0
}