#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 */
struct timeval {
  unsigned long long tv_sec;
  scalar_t__ tv_usec;
};

/* Variables and functions */
scalar_t__ aligned_alloc(int, int);
int /*<<< orphan*/ fillbuf(float *, int);
int /*<<< orphan*/ free(float *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ matmul(float *, int, int, float *, int, int, float *);
int /*<<< orphan*/ matmul8x8(float *, int, float *, int, float *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  float *m1 = (float *)aligned_alloc(64, sizeof(float) * 512 * 512);
  float *m2 = (float *)aligned_alloc(64, sizeof(float) * 512 * 512);
  float *mo = (float *)aligned_alloc(64, sizeof(float) * 512 * 512);
  srand(time(NULL));
  fillbuf(m1, 512 * 512);
  fillbuf(m2, 512 * 512);
  fillbuf(mo, 512 * 512);
  printf("init done\n");
  struct timeval s_time, e_time;
  gettimeofday(&s_time, NULL);
  for (int y = 0; y < 512; y += 8) {
    for (int x = 0; x < 512; x += 8) {
      matmul8x8(m1 + y * 512, 512, m2 + x, 512, mo + y * 512 + x);
    }
  }
  gettimeofday(&e_time, NULL);
  printf("exec %lld us\n", (e_time.tv_sec - s_time.tv_sec) * 1000000ULL +
                               (e_time.tv_usec - s_time.tv_usec));
  matmul(m1, 512, 512, m2, 512, 512, mo);
  free(m1);
  free(m2);
  free(mo);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x40,%edi
mov    $0x100000,%esi
call   10b0 <aligned_alloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x40,%edi
mov    $0x100000,%esi
call   10b0 <aligned_alloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x40,%edi
mov    $0x100000,%esi
call   10b0 <aligned_alloc@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    -0x10(%rbp),%rdi
mov    $0x40000,%esi
call   1070 <fillbuf@plt>
mov    -0x18(%rbp),%rdi
mov    $0x40000,%esi
call   1070 <fillbuf@plt>
mov    -0x20(%rbp),%rdi
mov    $0x40000,%esi
call   1070 <fillbuf@plt>
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0x44(%rbp)
cmpl   $0x200,-0x44(%rbp)
jge    12c2 <main+0x132>
movl   $0x0,-0x48(%rbp)
cmpl   $0x200,-0x48(%rbp)
jge    12af <main+0x11f>
mov    -0x10(%rbp),%rdi
mov    -0x44(%rbp),%eax
shl    $0x9,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rdx
movslq -0x48(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
mov    -0x20(%rbp),%r8
mov    -0x44(%rbp),%eax
shl    $0x9,%eax
cltq
shl    $0x2,%rax
add    %rax,%r8
movslq -0x48(%rbp),%rax
shl    $0x2,%rax
add    %rax,%r8
mov    $0x200,%ecx
mov    %ecx,%esi
call   10a0 <matmul8x8@plt>
mov    -0x48(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x48(%rbp)
jmp    1248 <main+0xb8>
jmp    12b4 <main+0x124>
mov    -0x44(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x44(%rbp)
jmp    1234 <main+0xa4>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x40(%rbp),%rax
sub    -0x30(%rbp),%rax
imul   $0xf4240,%rax,%rsi
mov    -0x38(%rbp),%rax
sub    -0x28(%rbp),%rax
add    %rax,%rsi
lea    0xd1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    $0x200,%r9d
mov    %r9d,%esi
mov    %r9d,%edx
mov    %r9d,%r8d
mov    %rax,(%rsp)
call   1090 <matmul@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    $0x40,%edi
mov    $0x100000,%esi
call   10c0 <aligned_alloc@plt>
mov    %rax,%rbx
mov    $0x40,%edi
mov    $0x100000,%esi
call   10c0 <aligned_alloc@plt>
mov    %rax,%rbp
mov    $0x40,%edi
mov    $0x100000,%esi
call   10c0 <aligned_alloc@plt>
mov    %rax,%r14
xor    %r15d,%r15d
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    %rbx,0x18(%rsp)
mov    %rbx,%rdi
mov    $0x40000,%esi
call   1080 <fillbuf@plt>
mov    %rbp,0x10(%rsp)
mov    %rbp,%rdi
mov    $0x40000,%esi
call   1080 <fillbuf@plt>
mov    %r14,%rdi
mov    $0x40000,%esi
call   1080 <fillbuf@plt>
lea    0xde1(%rip),%rdi
call   1040 <puts@plt>
lea    0x38(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    %r14,0x20(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%r13
shl    $0xb,%r13
add    0x18(%rsp),%r13
mov    $0xfffffffffffffff8,%r12
mov    0x10(%rsp),%rbx
mov    %r14,%rbp
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
mov    $0x200,%ecx
mov    %rbp,%r8
call   10b0 <matmul8x8@plt>
add    $0x8,%r12
add    $0x20,%rbp
add    $0x20,%rbx
cmp    $0x1f8,%r12
jb     1270 <main+0xd0>
lea    0x8(%r15),%rax
add    $0x4000,%r14
cmp    $0x1f8,%r15
mov    %rax,%r15
jb     1250 <main+0xb0>
lea    0x28(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    0x28(%rsp),%rax
mov    0x30(%rsp),%rsi
sub    0x38(%rsp),%rax
imul   $0xf4240,%rax,%rax
sub    0x40(%rsp),%rsi
add    %rax,%rsi
lea    0xd1b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%rsp),%r14
mov    %r14,(%rsp)
mov    0x18(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x200,%esi
mov    $0x200,%edx
mov    0x10(%rsp),%rbp
mov    %rbp,%rcx
mov    $0x200,%r8d
mov    $0x200,%r9d
call   10a0 <matmul@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [11 x i8] c"init done\0A\00"
@.str.1 = [14 x i8] c"exec %lld us\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float*
%3 = alloca float*
%4 = alloca float*
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i64 @aligned_alloc(i32 64, i32 1048576)
%10 = inttoptr i64 %9 to float*
store float* %10, float** %2
%11 = call i64 @aligned_alloc(i32 64, i32 1048576)
%12 = inttoptr i64 %11 to float*
store float* %12, float** %3
%13 = call i64 @aligned_alloc(i32 64, i32 1048576)
%14 = inttoptr i64 %13 to float*
store float* %14, float** %4
%15 = call i32 @time(i32* null)
%16 = call i32 @srand(i32 %15)
%17 = load float*, float** %2
%18 = call i32 @fillbuf(float* %17, i32 262144)
%19 = load float*, float** %3
%20 = call i32 @fillbuf(float* %19, i32 262144)
%21 = load float*, float** %4
%22 = call i32 @fillbuf(float* %21, i32 262144)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
store i32 0, i32* %7
br label %25
25: ; preds = %55, %0
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 512
br i1 %27, label %28, label %58
28: ; preds = %25
store i32 0, i32* %8
br label %29
29: ; preds = %51, %28
%30 = load i32, i32* %8
%31 = icmp slt i32 %30, 512
br i1 %31, label %32, label %54
32: ; preds = %29
%33 = load float*, float** %2
%34 = load i32, i32* %7
%35 = mul nsw i32 %34, 512
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds float, float* %33, i64 %36
%38 = load float*, float** %3
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds float, float* %38, i64 %40
%42 = load float*, float** %4
%43 = load i32, i32* %7
%44 = mul nsw i32 %43, 512
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds float, float* %42, i64 %45
%47 = load i32, i32* %8
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds float, float* %46, i64 %48
%50 = call i32 @matmul8x8(float* %37, i32 512, float* %41, i32 512, float* %49)
br label %51
51: ; preds = %32
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 8
store i32 %53, i32* %8
br label %29
54: ; preds = %29
br label %55
55: ; preds = %54
%56 = load i32, i32* %7
%57 = add nsw i32 %56, 8
store i32 %57, i32* %7
br label %25
58: ; preds = %25
%59 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%60 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%61 = load i64, i64* %60
%62 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%63 = load i64, i64* %62
%64 = sub i64 %61, %63
%65 = mul i64 %64, 1000000
%66 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%67 = load i64, i64* %66
%68 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%69 = load i64, i64* %68
%70 = sub nsw i64 %67, %69
%71 = add i64 %65, %70
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %71)
%73 = load float*, float** %2
%74 = load float*, float** %3
%75 = load float*, float** %4
%76 = call i32 @matmul(float* %73, i32 512, i32 512, float* %74, i32 512, i32 512, float* %75)
%77 = load float*, float** %2
%78 = call i32 @free(float* %77)
%79 = load float*, float** %3
%80 = call i32 @free(float* %79)
%81 = load float*, float** %4
%82 = call i32 @free(float* %81)
%83 = load i32, i32* %1
ret i32 %83
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str.1 = [14 x i8] c"exec %lld us\0A\00"
@str = [10 x i8] c"init done\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = tail call i64 @aligned_alloc(i32 64, i32 1048576)
%4 = inttoptr i64 %3 to float*
%5 = tail call i64 @aligned_alloc(i32 64, i32 1048576)
%6 = inttoptr i64 %5 to float*
%7 = tail call i64 @aligned_alloc(i32 64, i32 1048576)
%8 = inttoptr i64 %7 to float*
%9 = tail call i32 @time(i32* null)
%10 = tail call i32 @srand(i32 %9)
%11 = tail call i32 @fillbuf(float* %4, i32 262144)
%12 = tail call i32 @fillbuf(float* %6, i32 262144)
%13 = tail call i32 @fillbuf(float* %8, i32 262144)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%15 = bitcast %struct.timeval* %1 to i8*
%16 = bitcast %struct.timeval* %2 to i8*
%17 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
br label %18
18: ; preds = %0, %42
%19 = phi i64 [ 0, %0 ], [ %43, %42 ]
%20 = shl nuw nsw i64 %19, 9
%21 = getelementptr inbounds float, float* %4, i64 %20
%22 = getelementptr inbounds float, float* %8, i64 %20
br label %45
23: ; preds = %42
%24 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%26 = load i64, i64* %25
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%28 = load i64, i64* %27
%29 = sub i64 %26, %28
%30 = mul i64 %29, 1000000
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%32 = load i64, i64* %31
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%34 = load i64, i64* %33
%35 = sub i64 %32, %34
%36 = add i64 %35, %30
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %36)
%38 = tail call i32 @matmul(float* %4, i32 512, i32 512, float* %6, i32 512, i32 512, float* %8)
%39 = tail call i32 @free(float* %4)
%40 = tail call i32 @free(float* %6)
%41 = tail call i32 @free(float* %8)
ret i32 0
42: ; preds = %45
%43 = add nuw nsw i64 %19, 8
%44 = icmp ult i64 %19, 504
br i1 %44, label %18, label %23
45: ; preds = %18, %45
%46 = phi i64 [ 0, %18 ], [ %50, %45 ]
%47 = getelementptr inbounds float, float* %6, i64 %46
%48 = getelementptr inbounds float, float* %22, i64 %46
%49 = tail call i32 @matmul8x8(float* %21, i32 512, float* %47, i32 512, float* %48)
%50 = add nuw nsw i64 %46, 8
%51 = icmp ult i64 %46, 504
br i1 %51, label %45, label %42
}