#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 */
unsigned int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ matrixMult(double *, double *, double *, unsigned int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  unsigned int i, N;
  double *A;
  double *B;
  double *C;
  if (argc == 2) {
    N = atoi(argv[1]);
  } else {
    fprintf(stderr, "Sorry, I need matrix width as command line argument\n");
    return 1;
  }
  A = (double *)malloc(N * N * sizeof(double));
  B = (double *)malloc(N * N * sizeof(double));
  C = (double *)malloc(N * N * sizeof(double));
  for (i = 0; i < N * N; i++) {
    A[i] = 2.0;
    B[i] = (double)i;
  }
  matrixMult(A, B, C, N);
  free(A);
  free(B);
  free(C);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1185 <main+0x35>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    11a6 <main+0x56>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1274 <main+0x124>
mov    -0x18(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
imul   -0x18(%rbp),%ecx
cmp    %ecx,%eax
jae    123e <main+0xee>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
movabs $0x4000000000000000,%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
cvtsi2sd %rax,%xmm0
mov    -0x28(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f5 <main+0xa5>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x18(%rbp),%ecx
call   1040 <matrixMult@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%edi
jne    1294 <main+0x144>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%r14d
mov    %eax,%r12d
imul   %r12d,%r12d
lea    0x0(,%r12,8),%r15d
mov    %r15d,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %r15d,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    %r15d,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
test   %r12d,%r12d
je     140d <main+0x2bd>
mov    %r12d,%r8d
cmp    $0x4,%r12d
jb     11d0 <main+0x80>
lea    0x0(,%r8,8),%rcx
add    %rbp,%rcx
cmp    %rcx,%rbx
jae    12b3 <main+0x163>
lea    (%rbx,%r8,8),%rcx
cmp    %rcx,%rbp
jae    12b3 <main+0x163>
xor    %ecx,%ecx
mov    %rcx,%rdx
not    %rdx
add    %r8,%rdx
mov    %r8,%rsi
and    $0x3,%rsi
je     120e <main+0xbe>
movabs $0x4000000000000000,%rdi
xchg   %ax,%ax
mov    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    %rdi,(%rbx,%rcx,8)
movsd  %xmm0,0x0(%rbp,%rcx,8)
add    $0x1,%rcx
add    $0xffffffffffffffff,%rsi
jne    11f0 <main+0xa0>
cmp    $0x3,%rdx
jb     140d <main+0x2bd>
movabs $0x4000000000000000,%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rdx,(%rbx,%rcx,8)
mov    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x0(%rbp,%rcx,8)
mov    %rdx,0x8(%rbx,%rcx,8)
lea    0x1(%rcx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x8(%rbp,%rcx,8)
mov    %rdx,0x10(%rbx,%rcx,8)
lea    0x2(%rcx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x10(%rbp,%rcx,8)
lea    0x3(%rcx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    %rdx,0x18(%rbx,%rcx,8)
movsd  %xmm0,0x18(%rbp,%rcx,8)
add    $0x4,%rcx
cmp    %r8,%rcx
jne    1230 <main+0xe0>
jmp    140d <main+0x2bd>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    1438 <main+0x2e8>
mov    %r8d,%ecx
and    $0xfffffffc,%ecx
lea    -0x4(%rcx),%rdx
mov    %rdx,%rsi
shr    $0x2,%rsi
add    $0x1,%rsi
test   %rdx,%rdx
je     1441 <main+0x2f1>
mov    %rsi,%rdi
and    $0xfffffffffffffffe,%rdi
movdqa 0xd20(%rip),%xmm5
xor    %edx,%edx
movdqa 0xd25(%rip),%xmm8
movapd 0xd2d(%rip),%xmm2
pxor   %xmm3,%xmm3
movdqa 0xd31(%rip),%xmm4
movdqa 0xd38(%rip),%xmm9
movdqa 0xd40(%rip),%xmm6
movdqa 0xd48(%rip),%xmm7
nopl   0x0(%rax,%rax,1)
movdqa %xmm5,%xmm0
paddd  %xmm8,%xmm0
movupd %xmm2,(%rbx,%rdx,8)
movupd %xmm2,0x10(%rbx,%rdx,8)
movdqa %xmm5,%xmm1
punpckldq %xmm3,%xmm1
por    %xmm4,%xmm1
subpd  %xmm4,%xmm1
punpckldq %xmm3,%xmm0
por    %xmm4,%xmm0
subpd  %xmm4,%xmm0
movupd %xmm1,0x0(%rbp,%rdx,8)
movupd %xmm0,0x10(%rbp,%rdx,8)
movdqa %xmm5,%xmm0
paddd  %xmm9,%xmm0
movdqa %xmm5,%xmm1
paddd  %xmm6,%xmm1
movupd %xmm2,0x20(%rbx,%rdx,8)
movupd %xmm2,0x30(%rbx,%rdx,8)
punpckldq %xmm3,%xmm0
por    %xmm4,%xmm0
subpd  %xmm4,%xmm0
punpckldq %xmm3,%xmm1
por    %xmm4,%xmm1
subpd  %xmm4,%xmm1
movupd %xmm0,0x20(%rbp,%rdx,8)
movupd %xmm1,0x30(%rbp,%rdx,8)
add    $0x8,%rdx
paddd  %xmm7,%xmm5
add    $0xfffffffffffffffe,%rdi
jne    1320 <main+0x1d0>
test   $0x1,%sil
je     1404 <main+0x2b4>
movdqa 0xc53(%rip),%xmm0
paddd  %xmm5,%xmm0
movdqa 0xc57(%rip),%xmm1
movdqu %xmm1,(%rbx,%rdx,8)
movdqu %xmm1,0x10(%rbx,%rdx,8)
pxor   %xmm1,%xmm1
punpckldq %xmm1,%xmm5
movdqa 0xc4c(%rip),%xmm2
por    %xmm2,%xmm5
subpd  %xmm2,%xmm5
punpckldq %xmm1,%xmm0
por    %xmm2,%xmm0
subpd  %xmm2,%xmm0
movupd %xmm5,0x0(%rbp,%rdx,8)
movupd %xmm0,0x10(%rbp,%rdx,8)
cmp    %r8,%rcx
jne    11d2 <main+0x82>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1040 <matrixMult@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
movdqa 0xbb7(%rip),%xmm5
xor    %edx,%edx
test   $0x1,%sil
jne    13b5 <main+0x265>
jmp    1404 <main+0x2b4>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [53 x i8] c"Sorry, I need matrix width as command line argument\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 double*
%9 = alloca double*
%10 = alloca double*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %7
br label %21
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %78
21: ; preds = %13
%22 = load i32, i32* %7
%23 = load i32, i32* %7
%24 = mul i32 %22, %23
%25 = zext i32 %24 to i64
%26 = mul i64 %25, 8
%27 = trunc i64 %26 to i32
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to double*
store double* %29, double** %8
%30 = load i32, i32* %7
%31 = load i32, i32* %7
%32 = mul i32 %30, %31
%33 = zext i32 %32 to i64
%34 = mul i64 %33, 8
%35 = trunc i64 %34 to i32
%36 = call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to double*
store double* %37, double** %9
%38 = load i32, i32* %7
%39 = load i32, i32* %7
%40 = mul i32 %38, %39
%41 = zext i32 %40 to i64
%42 = mul i64 %41, 8
%43 = trunc i64 %42 to i32
%44 = call i64 @malloc(i32 %43)
%45 = inttoptr i64 %44 to double*
store double* %45, double** %10
store i32 0, i32* %6
br label %46
46: ; preds = %63, %21
%47 = load i32, i32* %6
%48 = load i32, i32* %7
%49 = load i32, i32* %7
%50 = mul i32 %48, %49
%51 = icmp ult i32 %47, %50
br i1 %51, label %52, label %66
52: ; preds = %46
%53 = load double*, double** %8
%54 = load i32, i32* %6
%55 = zext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
store double 2.000000e+00, double* %56
%57 = load i32, i32* %6
%58 = uitofp i32 %57 to double
%59 = load double*, double** %9
%60 = load i32, i32* %6
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds double, double* %59, i64 %61
store double %58, double* %62
br label %63
63: ; preds = %52
%64 = load i32, i32* %6
%65 = add i32 %64, 1
store i32 %65, i32* %6
br label %46
66: ; preds = %46
%67 = load double*, double** %8
%68 = load double*, double** %9
%69 = load double*, double** %10
%70 = load i32, i32* %7
%71 = call i32 @matrixMult(double* %67, double* %68, double* %69, i32 %70)
%72 = load double*, double** %8
%73 = call i32 @free(double* %72)
%74 = load double*, double** %9
%75 = call i32 @free(double* %74)
%76 = load double*, double** %10
%77 = call i32 @free(double* %76)
store i32 0, i32* %3
br label %78
78: ; preds = %66, %18
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [53 x i8] c"Sorry, I need matrix width as command line argument\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %108
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = mul i32 %7, %7
%9 = shl i32 %8, 3
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to double*
%12 = inttoptr i64 %10 to i8*
%13 = tail call i64 @malloc(i32 %9)
%14 = inttoptr i64 %13 to double*
%15 = inttoptr i64 %13 to i8*
%16 = tail call i64 @malloc(i32 %9)
%17 = inttoptr i64 %16 to double*
%18 = icmp eq i32 %8, 0
br i1 %18, label %134, label %19
19: ; preds = %4
%20 = zext i32 %8 to i64
%21 = icmp ult i32 %8, 4
br i1 %21, label %89, label %22
22: ; preds = %19
%23 = getelementptr double, double* %11, i64 %20
%24 = bitcast double* %23 to i8*
%25 = getelementptr double, double* %14, i64 %20
%26 = bitcast double* %25 to i8*
%27 = icmp ult i8* %12, %26
%28 = icmp ult i8* %15, %24
%29 = and i1 %27, %28
br i1 %29, label %89, label %30
30: ; preds = %22
%31 = and i64 %20, 4294967292
%32 = add nsw i64 %31, -4
%33 = lshr exact i64 %32, 2
%34 = add nuw nsw i64 %33, 1
%35 = and i64 %34, 1
%36 = icmp eq i64 %32, 0
br i1 %36, label %71, label %37
37: ; preds = %30
%38 = and i64 %34, 9223372036854775806
br label %39
39: ; preds = %39, %37
%40 = phi i64 [ 0, %37 ], [ %67, %39 ]
%41 = phi <2 x i32> [ <i32 0, i32 1>, %37 ], [ %68, %39 ]
%42 = phi i64 [ 0, %37 ], [ %69, %39 ]
%43 = add <2 x i32> %41, <i32 2, i32 2>
%44 = getelementptr inbounds double, double* %11, i64 %40
%45 = bitcast double* %44 to <2 x double>*
store <2 x double> <double 2.000000e+00, double 2.000000e+00>, <2 x double>* %45
%46 = getelementptr inbounds double, double* %44, i64 2
%47 = bitcast double* %46 to <2 x double>*
store <2 x double> <double 2.000000e+00, double 2.000000e+00>, <2 x double>* %47
%48 = uitofp <2 x i32> %41 to <2 x double>
%49 = uitofp <2 x i32> %43 to <2 x double>
%50 = getelementptr inbounds double, double* %14, i64 %40
%51 = bitcast double* %50 to <2 x double>*
store <2 x double> %48, <2 x double>* %51
%52 = getelementptr inbounds double, double* %50, i64 2
%53 = bitcast double* %52 to <2 x double>*
store <2 x double> %49, <2 x double>* %53
%54 = or i64 %40, 4
%55 = add <2 x i32> %41, <i32 4, i32 4>
%56 = add <2 x i32> %41, <i32 6, i32 6>
%57 = getelementptr inbounds double, double* %11, i64 %54
%58 = bitcast double* %57 to <2 x double>*
store <2 x double> <double 2.000000e+00, double 2.000000e+00>, <2 x double>* %58
%59 = getelementptr inbounds double, double* %57, i64 2
%60 = bitcast double* %59 to <2 x double>*
store <2 x double> <double 2.000000e+00, double 2.000000e+00>, <2 x double>* %60
%61 = uitofp <2 x i32> %55 to <2 x double>
%62 = uitofp <2 x i32> %56 to <2 x double>
%63 = getelementptr inbounds double, double* %14, i64 %54
%64 = bitcast double* %63 to <2 x double>*
store <2 x double> %61, <2 x double>* %64
%65 = getelementptr inbounds double, double* %63, i64 2
%66 = bitcast double* %65 to <2 x double>*
store <2 x double> %62, <2 x double>* %66
%67 = add nuw i64 %40, 8
%68 = add <2 x i32> %41, <i32 8, i32 8>
%69 = add i64 %42, 2
%70 = icmp eq i64 %69, %38
br i1 %70, label %71, label %39
71: ; preds = %39, %30
%72 = phi i64 [ 0, %30 ], [ %67, %39 ]
%73 = phi <2 x i32> [ <i32 0, i32 1>, %30 ], [ %68, %39 ]
%74 = icmp eq i64 %35, 0
br i1 %74, label %87, label %75
75: ; preds = %71
%76 = add <2 x i32> %73, <i32 2, i32 2>
%77 = getelementptr inbounds double, double* %11, i64 %72
%78 = bitcast double* %77 to <2 x double>*
store <2 x double> <double 2.000000e+00, double 2.000000e+00>, <2 x double>* %78
%79 = getelementptr inbounds double, double* %77, i64 2
%80 = bitcast double* %79 to <2 x double>*
store <2 x double> <double 2.000000e+00, double 2.000000e+00>, <2 x double>* %80
%81 = uitofp <2 x i32> %73 to <2 x double>
%82 = uitofp <2 x i32> %76 to <2 x double>
%83 = getelementptr inbounds double, double* %14, i64 %72
%84 = bitcast double* %83 to <2 x double>*
store <2 x double> %81, <2 x double>* %84
%85 = getelementptr inbounds double, double* %83, i64 2
%86 = bitcast double* %85 to <2 x double>*
store <2 x double> %82, <2 x double>* %86
br label %87
87: ; preds = %71, %75
%88 = icmp eq i64 %31, %20
br i1 %88, label %134, label %89
89: ; preds = %22, %19, %87
%90 = phi i64 [ 0, %22 ], [ 0, %19 ], [ %31, %87 ]
%91 = xor i64 %90, -1
%92 = add nsw i64 %91, %20
%93 = and i64 %20, 3
%94 = icmp eq i64 %93, 0
br i1 %94, label %105, label %95
95: ; preds = %89, %95
%96 = phi i64 [ %102, %95 ], [ %90, %89 ]
%97 = phi i64 [ %103, %95 ], [ 0, %89 ]
%98 = getelementptr inbounds double, double* %11, i64 %96
store double 2.000000e+00, double* %98
%99 = trunc i64 %96 to i32
%100 = uitofp i32 %99 to double
%101 = getelementptr inbounds double, double* %14, i64 %96
store double %100, double* %101
%102 = add nuw nsw i64 %96, 1
%103 = add i64 %97, 1
%104 = icmp eq i64 %103, %93
br i1 %104, label %105, label %95
105: ; preds = %95, %89
%106 = phi i64 [ %90, %89 ], [ %102, %95 ]
%107 = icmp ult i64 %92, 3
br i1 %107, label %134, label %111
108: ; preds = %2
%109 = load i32, i32* @stderr
%110 = tail call i32 @fprintf(i32 %109, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
br label %139
111: ; preds = %105, %111
%112 = phi i64 [ %132, %111 ], [ %106, %105 ]
%113 = getelementptr inbounds double, double* %11, i64 %112
store double 2.000000e+00, double* %113
%114 = trunc i64 %112 to i32
%115 = uitofp i32 %114 to double
%116 = getelementptr inbounds double, double* %14, i64 %112
store double %115, double* %116
%117 = add nuw nsw i64 %112, 1
%118 = getelementptr inbounds double, double* %11, i64 %117
store double 2.000000e+00, double* %118
%119 = trunc i64 %117 to i32
%120 = uitofp i32 %119 to double
%121 = getelementptr inbounds double, double* %14, i64 %117
store double %120, double* %121
%122 = add nuw nsw i64 %112, 2
%123 = getelementptr inbounds double, double* %11, i64 %122
store double 2.000000e+00, double* %123
%124 = trunc i64 %122 to i32
%125 = uitofp i32 %124 to double
%126 = getelementptr inbounds double, double* %14, i64 %122
store double %125, double* %126
%127 = add nuw nsw i64 %112, 3
%128 = getelementptr inbounds double, double* %11, i64 %127
store double 2.000000e+00, double* %128
%129 = trunc i64 %127 to i32
%130 = uitofp i32 %129 to double
%131 = getelementptr inbounds double, double* %14, i64 %127
store double %130, double* %131
%132 = add nuw nsw i64 %112, 4
%133 = icmp eq i64 %132, %20
br i1 %133, label %134, label %111
134: ; preds = %105, %111, %87, %4
%135 = tail call i32 @matrixMult(double* %11, double* %14, double* %17, i32 %7)
%136 = tail call i32 @free(double* %11)
%137 = tail call i32 @free(double* %14)
%138 = tail call i32 @free(double* %17)
br label %139
139: ; preds = %134, %108
%140 = phi i32 [ 0, %134 ], [ 1, %108 ]
ret i32 %140
}