#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 *malloc(int);
scalar_t__ matmul0(int *, int *, int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setRandomToMatrix(int *, int, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int strtol(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Usage: %s <matrix_size>\n", argv[0]);
    return 1;
  }
  clock_t count = 0;
  int i;
  int N = strtol(argv[1], NULL, 10);
  srand(time(NULL));
  int *A, *B, *C;
  A = malloc(N * N * sizeof(int));
  B = malloc(N * N * sizeof(int));
  C = malloc(N * N * sizeof(int));
  setRandomToMatrix(A, N, 100);
  setRandomToMatrix(B, N, 100);
  for (i = 0; i < 1000; i++) {
    count += matmul0(C, A, B, N);
  }
  printf("%d\t%lf\n", N, (double)count / 1000 / CLOCKS_PER_SEC);
  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)
cmpl   $0x2,-0x8(%rbp)
jge    11b1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bf <main+0x14f>
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    -0x20(%rbp),%eax
imul   -0x20(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
imul   -0x20(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%eax
imul   -0x20(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    $0x64,%edx
call   1040 <setRandomToMatrix@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    $0x64,%edx
call   1040 <setRandomToMatrix@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3e8,-0x1c(%rbp)
jge    128a <main+0x11a>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%ecx
call   1050 <matmul0@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1253 <main+0xe3>
mov    -0x20(%rbp),%esi
cvtsi2sdq -0x18(%rbp),%xmm0
movsd  0xd65(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    0x2d42(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd70(%rip),%rdi
mov    $0x1,%al
call   1030 <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   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     119b <main+0x2b>
mov    (%rsi),%rsi
lea    0xe7e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%eax
jmp    1254 <main+0xe4>
mov    0x8(%rsi),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,%r14d
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    %r14d,%ebx
imul   %r14d,%ebx
shl    $0x2,%ebx
mov    %ebx,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    %ebx,%edi
call   1090 <malloc@plt>
mov    %rax,%r12
mov    %ebx,%edi
call   1090 <malloc@plt>
mov    %rax,%r13
mov    %r15,%rdi
mov    %r14d,%esi
mov    $0x64,%edx
call   1040 <setRandomToMatrix@plt>
mov    %r12,%rdi
mov    %r14d,%esi
mov    $0x64,%edx
call   1040 <setRandomToMatrix@plt>
mov    $0x3e8,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r14d,%ecx
call   1050 <matmul0@plt>
add    %rax,%rbp
add    $0xffffffff,%ebx
jne    1210 <main+0xa0>
cvtsi2sd %rbp,%xmm0
divsd  0xdca(%rip),%xmm0
mov    0x2dab(%rip),%rax
divsd  (%rax),%xmm0
lea    0xdd9(%rip),%rdi
mov    %r14d,%esi
mov    $0x1,%al
call   1030 <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 = [25 x i8] c"Usage: %s <matrix_size>\0A\00"
@.str.1 = [8 x i8] c"%d\09%lf\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %75
19: ; preds = %2
store i64 0, i64* %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @strtol(i8* %22, i32* null, i32 10)
store i32 %23, i32* %8
%24 = call i32 @time(i32* null)
%25 = call i32 @srand(i32 %24)
%26 = load i32, i32* %8
%27 = load i32, i32* %8
%28 = mul nsw i32 %26, %27
%29 = sext i32 %28 to i64
%30 = mul i64 %29, 4
%31 = trunc i64 %30 to i32
%32 = call i32* @malloc(i32 %31)
store i32* %32, i32** %9
%33 = load i32, i32* %8
%34 = load i32, i32* %8
%35 = mul nsw i32 %33, %34
%36 = sext i32 %35 to i64
%37 = mul i64 %36, 4
%38 = trunc i64 %37 to i32
%39 = call i32* @malloc(i32 %38)
store i32* %39, i32** %10
%40 = load i32, i32* %8
%41 = load i32, i32* %8
%42 = mul nsw i32 %40, %41
%43 = sext i32 %42 to i64
%44 = mul i64 %43, 4
%45 = trunc i64 %44 to i32
%46 = call i32* @malloc(i32 %45)
store i32* %46, i32** %11
%47 = load i32*, i32** %9
%48 = load i32, i32* %8
%49 = call i32 @setRandomToMatrix(i32* %47, i32 %48, i32 100)
%50 = load i32*, i32** %10
%51 = load i32, i32* %8
%52 = call i32 @setRandomToMatrix(i32* %50, i32 %51, i32 100)
store i32 0, i32* %7
br label %53
53: ; preds = %64, %19
%54 = load i32, i32* %7
%55 = icmp slt i32 %54, 1000
br i1 %55, label %56, label %67
56: ; preds = %53
%57 = load i32*, i32** %11
%58 = load i32*, i32** %9
%59 = load i32*, i32** %10
%60 = load i32, i32* %8
%61 = call i64 @matmul0(i32* %57, i32* %58, i32* %59, i32 %60)
%62 = load i64, i64* %6
%63 = add nsw i64 %62, %61
store i64 %63, i64* %6
br label %64
64: ; preds = %56
%65 = load i32, i32* %7
%66 = add nsw i32 %65, 1
store i32 %66, i32* %7
br label %53
67: ; preds = %53
%68 = load i32, i32* %8
%69 = load i64, i64* %6
%70 = sitofp i64 %69 to double
%71 = fdiv double %70, 1.000000e+03
%72 = load double, double* @CLOCKS_PER_SEC
%73 = fdiv double %71, %72
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %68, double %73)
store i32 0, i32* %3
br label %75
75: ; preds = %67, %14
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@.str = [25 x i8] c"Usage: %s <matrix_size>\0A\00"
@.str.1 = [8 x i8] c"%d\09%lf\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %33
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strtol(i8* nocapture %9, i32* null, i32 10)
%11 = tail call i32 @time(i32* null)
%12 = tail call i32 @srand(i32 %11)
%13 = shl i32 %10, 2
%14 = mul i32 %13, %10
%15 = tail call i32* @malloc(i32 %14)
%16 = tail call i32* @malloc(i32 %14)
%17 = tail call i32* @malloc(i32 %14)
%18 = tail call i32 @setRandomToMatrix(i32* %15, i32 %10, i32 100)
%19 = tail call i32 @setRandomToMatrix(i32* %16, i32 %10, i32 100)
br label %20
20: ; preds = %7, %20
%21 = phi i64 [ 0, %7 ], [ %24, %20 ]
%22 = phi i32 [ 0, %7 ], [ %25, %20 ]
%23 = tail call i64 @matmul0(i32* %17, i32* %15, i32* %16, i32 %10)
%24 = add nsw i64 %23, %21
%25 = add nuw nsw i32 %22, 1
%26 = icmp eq i32 %25, 1000
br i1 %26, label %27, label %20
27: ; preds = %20
%28 = sitofp i64 %24 to double
%29 = fdiv double %28, 1.000000e+03
%30 = load double, double* @CLOCKS_PER_SEC
%31 = fdiv double %29, %30
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %10, double %31)
br label %33
33: ; preds = %27, %4
%34 = phi i32 [ 1, %4 ], [ 0, %27 ]
ret i32 %34
}