#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 timespec {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC_RAW;
scalar_t__ RAND_MAX;
int atoi(char *);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int get_time(struct timespec *, struct timespec *);
int /*<<< orphan*/ memset(float *, int /*<<< orphan*/, int);
scalar_t__ page_alloc(int);
int /*<<< orphan*/ page_free(float *, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ rand();
int /*<<< orphan*/ save_bin(char *, float *, int);
int /*<<< orphan*/ sgemm_kernel_x64_fma_m4n24(float *, float *, float *, int,
                                              int);
int /*<<< orphan*/ sgemm_naive(float *, float *, float *, int, int, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ thread_bind(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int i;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s m k\n", argv[0]);
    return 0;
  }
  int m = atoi(argv[1]);
  int k = atoi(argv[2]);
  long comp = 2L * m * k * 24L;
  int loop_time = (int)(2e11 / comp);
  struct timespec start, end;
  double t, gflops;
  thread_bind(0);
  float *a = (float *)page_alloc(m * k * sizeof(float));
  float *b = (float *)page_alloc(k * 24 * sizeof(float));
  float *c1 = (float *)page_alloc(m * 24 * sizeof(float));
  float *c2 = (float *)page_alloc(m * 24 * sizeof(float));
  srand(time(NULL));
  for (i = 0; i < m * k; i++) {
    a[i] = (float)rand() / (float)RAND_MAX;
  }
  for (i = 0; i < k * 24; i++) {
    b[i] = (float)rand() / (float)RAND_MAX;
  }
  for (i = 0; i < loop_time; i++) {
    sgemm_kernel_x64_fma_m4n24(a, b, c2, m, k);
  }
  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
  for (i = 0; i < loop_time; i++) {
    sgemm_kernel_x64_fma_m4n24(a, b, c2, m, k);
  }
  clock_gettime(CLOCK_MONOTONIC_RAW, &end);
  t = get_time(&start, &end) / loop_time;
  gflops = (double)comp / t * 1e-9;
  printf(
      "sgemm_kernel_x64_fma(%d, %d, %d): time = %lf us, perf = %lf GFLOPS.\n",
      m, 24, k, t * 1e6, gflops);
  memset(c1, 0, m * 24 * sizeof(float));
  memset(c2, 0, m * 24 * sizeof(float));
  sgemm_naive(a, b, c1, m, 24, k);
  sgemm_kernel_x64_fma_m4n24(a, b, c2, m, k);
  save_bin("naive.bin", c1, m * 24);
  save_bin("tuned.bin", c2, m * 24);
  printf("sgemm_naive result: naive.bin\n");
  printf("sgemm_kernel_x64_fma_m4n24 result: tuned.bin\n");
  printf("Use fp_diff(https://github.com/pigirons/fp_diff) to compare the "
         "results.\n");
  page_free(a, m * k * sizeof(float));
  page_free(b, k * 24 * sizeof(float));
  page_free(c1, m * 24 * sizeof(float));
  page_free(c2, m * 24 * sizeof(float));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1238 <main+0x48>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf1(%rip),%rsi
call   10c0 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    159f <main+0x3af>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x1,%rax
movslq -0x1c(%rbp),%rcx
imul   %rcx,%rax
imul   $0x18,%rax,%rax
mov    %rax,-0x28(%rbp)
cvtsi2sdq -0x28(%rbp),%xmm1
movsd  0xd82(%rip),%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
xor    %edi,%edi
call   1100 <thread_bind@plt>
mov    -0x18(%rbp),%eax
imul   -0x1c(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   10e0 <page_alloc@plt>
mov    %rax,-0x50(%rbp)
imul   $0x18,-0x1c(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   10e0 <page_alloc@plt>
mov    %rax,-0x58(%rbp)
imul   $0x18,-0x18(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   10e0 <page_alloc@plt>
mov    %rax,-0x60(%rbp)
imul   $0x18,-0x18(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   10e0 <page_alloc@plt>
mov    %rax,-0x68(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <time@plt>
mov    %eax,%edi
call   10a0 <srand@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jge    1347 <main+0x157>
mov    $0x0,%al
call   1110 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2cc5(%rip),%rax
cvtsi2ssq (%rax),%xmm1
divss  %xmm1,%xmm0
mov    -0x50(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12fe <main+0x10e>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
imul   $0x18,-0x1c(%rbp),%ecx
cmp    %ecx,%eax
jge    1394 <main+0x1a4>
mov    $0x0,%al
call   1110 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2c78(%rip),%rax
cvtsi2ssq (%rax),%xmm1
divss  %xmm1,%xmm0
mov    -0x58(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    134e <main+0x15e>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    13cd <main+0x1dd>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x68(%rbp),%rdx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1030 <sgemm_kernel_x64_fma_m4n24@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    139b <main+0x1ab>
mov    0x2c0c(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1050 <clock_gettime@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1418 <main+0x228>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x68(%rbp),%rdx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1030 <sgemm_kernel_x64_fma_m4n24@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    13e6 <main+0x1f6>
mov    0x2bc1(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
call   1050 <clock_gettime@plt>
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10b0 <get_time@plt>
cltd
idivl  -0x2c(%rbp)
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdq -0x28(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
movsd  0xbb9(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%ecx
movsd  0xb9a(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
lea    0xba8(%rip),%rdi
mov    $0x18,%edx
mov    $0x2,%al
call   1070 <printf@plt>
mov    -0x60(%rbp),%rdi
imul   $0x18,-0x18(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x68(%rbp),%rdi
imul   $0x18,-0x18(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x60(%rbp),%rdx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r9d
mov    $0x18,%r8d
call   1090 <sgemm_naive@plt>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x68(%rbp),%rdx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1030 <sgemm_kernel_x64_fma_m4n24@plt>
mov    -0x60(%rbp),%rsi
imul   $0x18,-0x18(%rbp),%edx
lea    0xb6e(%rip),%rdi
call   1060 <save_bin@plt>
mov    -0x68(%rbp),%rsi
imul   $0x18,-0x18(%rbp),%edx
lea    0xb64(%rip),%rdi
call   1060 <save_bin@plt>
lea    0xb62(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xb73(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xb93(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%eax
imul   -0x1c(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%esi
call   1040 <page_free@plt>
mov    -0x58(%rbp),%rdi
imul   $0x18,-0x1c(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%esi
call   1040 <page_free@plt>
mov    -0x60(%rbp),%rdi
imul   $0x18,-0x18(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%esi
call   1040 <page_free@plt>
mov    -0x68(%rbp),%rdi
imul   $0x18,-0x18(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%esi
call   1040 <page_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%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    %rsi,%rbx
cmp    $0x3,%edi
jne    13fb <main+0x1fb>
mov    0x8(%rbx),%rdi
call   1100 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
call   1100 <atoi@plt>
mov    %eax,%r14d
movslq %ebp,%rax
movslq %r14d,%rcx
imul   %rax,%rcx
shl    $0x4,%rcx
lea    (%rcx,%rcx,2),%rax
cvtsi2sd %rax,%xmm0
movsd  0xdb0(%rip),%xmm1
movsd  %xmm0,0x38(%rsp)
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %edi,%edi
call   1110 <thread_bind@plt>
mov    %r14d,%ebx
imul   %ebp,%ebx
lea    0x0(,%rbx,4),%edi
mov    %edi,0x1c(%rsp)
call   10f0 <page_alloc@plt>
mov    %rax,%r12
mov    %r14d,%eax
shl    $0x5,%eax
lea    (%rax,%rax,2),%edi
mov    %edi,0x18(%rsp)
call   10f0 <page_alloc@plt>
mov    %rax,%r13
lea    0x0(,%rbp,8),%eax
mov    %rax,0x10(%rsp)
mov    %rbp,0x28(%rsp)
mov    %ebp,%eax
shl    $0x5,%eax
lea    (%rax,%rax,2),%ebp
mov    %ebp,%edi
call   10f0 <page_alloc@plt>
mov    %rax,0x30(%rsp)
mov    %ebp,0xc(%rsp)
mov    %ebp,%edi
call   10f0 <page_alloc@plt>
mov    %rax,0x20(%rsp)
xor    %edi,%edi
call   10e0 <time@plt>
mov    %eax,%edi
call   10b0 <srand@plt>
test   %ebx,%ebx
jle    131a <main+0x11a>
mov    %ebx,%ebx
mov    0x2d04(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1120 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ssq (%r15),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,(%r12,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    12f0 <main+0xf0>
cvttsd2si (%rsp),%eax
mov    %eax,(%rsp)
test   %r14d,%r14d
jle    137b <main+0x17b>
lea    0x0(,%r14,8),%eax
lea    (%rax,%rax,2),%eax
cmp    $0x2,%eax
mov    $0x1,%ebx
cmovge %eax,%ebx
mov    0x2ca4(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1120 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ssq (%r15),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,0x0(%r13,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1350 <main+0x150>
mov    0x10(%rsp),%rax
lea    (%rax,%rax,2),%eax
mov    %eax,0x10(%rsp)
mov    (%rsp),%ebx
test   %ebx,%ebx
jle    1418 <main+0x218>
mov    0x28(%rsp),%r15
mov    0x20(%rsp),%rbp
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1030 <sgemm_kernel_x64_fma_m4n24@plt>
add    $0xffffffff,%ebx
jne    13a0 <main+0x1a0>
mov    0x2c20(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1060 <clock_gettime@plt>
cmpl   $0x0,(%rsp)
jle    1435 <main+0x235>
mov    (%rsp),%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1030 <sgemm_kernel_x64_fma_m4n24@plt>
add    $0xffffffff,%ebx
jne    13e0 <main+0x1e0>
jmp    1435 <main+0x235>
mov    0x2bce(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xc0a(%rip),%rsi
call   10d0 <fprintf@plt>
jmp    1567 <main+0x367>
mov    0x2bc1(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1060 <clock_gettime@plt>
mov    0x28(%rsp),%r15
mov    0x20(%rsp),%rbp
mov    0x2ba4(%rip),%rax
mov    (%rax),%edi
lea    0x40(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <clock_gettime@plt>
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   10c0 <get_time@plt>
cltd
idivl  (%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x38(%rsp),%xmm1
divsd  %xmm0,%xmm1
mulsd  0xb93(%rip),%xmm1
mulsd  0xb93(%rip),%xmm0
lea    0xba3(%rip),%rdi
mov    %r15d,%esi
mov    $0x18,%edx
mov    %r14d,%ecx
mov    $0x2,%al
call   1080 <printf@plt>
mov    0x30(%rsp),%rdi
xor    %esi,%esi
mov    %rbp,%rbx
mov    0xc(%rsp),%ebp
mov    %ebp,%edx
call   1090 <memset@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1090 <memset@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    0x30(%rsp),%rbp
mov    %rbp,%rdx
mov    %r15d,%ecx
mov    $0x18,%r8d
mov    %r14d,%r9d
call   10a0 <sgemm_naive@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1030 <sgemm_kernel_x64_fma_m4n24@plt>
lea    0xb8f(%rip),%rdi
mov    %rbp,%rsi
mov    %rbp,%r14
mov    0x10(%rsp),%ebp
mov    %ebp,%edx
call   1070 <save_bin@plt>
lea    0xba4(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1070 <save_bin@plt>
lea    0xb52(%rip),%rdi
call   1050 <puts@plt>
lea    0xb64(%rip),%rdi
call   1050 <puts@plt>
lea    0xb85(%rip),%rdi
call   1050 <puts@plt>
mov    %r12,%rdi
mov    0x1c(%rsp),%esi
call   1040 <page_free@plt>
mov    %r13,%rdi
mov    0x18(%rsp),%esi
call   1040 <page_free@plt>
mov    %r14,%rdi
mov    0xc(%rsp),%ebp
mov    %ebp,%esi
call   1040 <page_free@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <page_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.timespec = type { i32 }
@stderr = global i32 0
@.str = [15 x i8] c"Usage: %s m k\0A\00"
@RAND_MAX = global i64 0
@CLOCK_MONOTONIC_RAW = global i32 0
@.str.1 = [69 x i8] c"sgemm_kernel_x64_fma(%d, %d, %d): time = %lf us, perf = %lf GFLOPS.\0A\00"
@.str.2 = [10 x i8] c"naive.bin\00"
@.str.3 = [10 x i8] c"tuned.bin\00"
@.str.4 = [31 x i8] c"sgemm_naive result: naive.bin\0A\00"
@.str.5 = [46 x i8] c"sgemm_kernel_x64_fma_m4n24 result: tuned.bin\0A\00"
@.str.6 = [74 x i8] c"Use fp_diff(https://github.com/pigirons/fp_diff) to compare the results.\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 i32
%9 = alloca i64
%10 = alloca i32
%11 = alloca %struct.timespec
%12 = alloca %struct.timespec
%13 = alloca double
%14 = alloca double
%15 = alloca float*
%16 = alloca float*
%17 = alloca float*
%18 = alloca float*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 3
br i1 %20, label %21, label %27
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %25)
store i32 0, i32* %3
br label %233
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
store i32 %31, i32* %7
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
store i32 %35, i32* %8
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = mul nsw i64 2, %37
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = mul nsw i64 %38, %40
%42 = mul nsw i64 %41, 24
store i64 %42, i64* %9
%43 = load i64, i64* %9
%44 = sitofp i64 %43 to double
%45 = fdiv double 2.000000e+11, %44
%46 = fptosi double %45 to i32
store i32 %46, i32* %10
%47 = call i32 @thread_bind(i32 0)
%48 = load i32, i32* %7
%49 = load i32, i32* %8
%50 = mul nsw i32 %48, %49
%51 = sext i32 %50 to i64
%52 = mul i64 %51, 4
%53 = trunc i64 %52 to i32
%54 = call i64 @page_alloc(i32 %53)
%55 = inttoptr i64 %54 to float*
store float* %55, float** %15
%56 = load i32, i32* %8
%57 = mul nsw i32 %56, 24
%58 = sext i32 %57 to i64
%59 = mul i64 %58, 4
%60 = trunc i64 %59 to i32
%61 = call i64 @page_alloc(i32 %60)
%62 = inttoptr i64 %61 to float*
store float* %62, float** %16
%63 = load i32, i32* %7
%64 = mul nsw i32 %63, 24
%65 = sext i32 %64 to i64
%66 = mul i64 %65, 4
%67 = trunc i64 %66 to i32
%68 = call i64 @page_alloc(i32 %67)
%69 = inttoptr i64 %68 to float*
store float* %69, float** %17
%70 = load i32, i32* %7
%71 = mul nsw i32 %70, 24
%72 = sext i32 %71 to i64
%73 = mul i64 %72, 4
%74 = trunc i64 %73 to i32
%75 = call i64 @page_alloc(i32 %74)
%76 = inttoptr i64 %75 to float*
store float* %76, float** %18
%77 = call i32 @time(i32* null)
%78 = call i32 @srand(i32 %77)
store i32 0, i32* %6
br label %79
79: ; preds = %95, %27
%80 = load i32, i32* %6
%81 = load i32, i32* %7
%82 = load i32, i32* %8
%83 = mul nsw i32 %81, %82
%84 = icmp slt i32 %80, %83
br i1 %84, label %85, label %98
85: ; preds = %79
%86 = call i64 (...) @rand()
%87 = sitofp i64 %86 to float
%88 = load i64, i64* @RAND_MAX
%89 = sitofp i64 %88 to float
%90 = fdiv float %87, %89
%91 = load float*, float** %15
%92 = load i32, i32* %6
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds float, float* %91, i64 %93
store float %90, float* %94
br label %95
95: ; preds = %85
%96 = load i32, i32* %6
%97 = add nsw i32 %96, 1
store i32 %97, i32* %6
br label %79
98: ; preds = %79
store i32 0, i32* %6
br label %99
99: ; preds = %114, %98
%100 = load i32, i32* %6
%101 = load i32, i32* %8
%102 = mul nsw i32 %101, 24
%103 = icmp slt i32 %100, %102
br i1 %103, label %104, label %117
104: ; preds = %99
%105 = call i64 (...) @rand()
%106 = sitofp i64 %105 to float
%107 = load i64, i64* @RAND_MAX
%108 = sitofp i64 %107 to float
%109 = fdiv float %106, %108
%110 = load float*, float** %16
%111 = load i32, i32* %6
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds float, float* %110, i64 %112
store float %109, float* %113
br label %114
114: ; preds = %104
%115 = load i32, i32* %6
%116 = add nsw i32 %115, 1
store i32 %116, i32* %6
br label %99
117: ; preds = %99
store i32 0, i32* %6
br label %118
118: ; preds = %129, %117
%119 = load i32, i32* %6
%120 = load i32, i32* %10
%121 = icmp slt i32 %119, %120
br i1 %121, label %122, label %132
122: ; preds = %118
%123 = load float*, float** %15
%124 = load float*, float** %16
%125 = load float*, float** %18
%126 = load i32, i32* %7
%127 = load i32, i32* %8
%128 = call i32 @sgemm_kernel_x64_fma_m4n24(float* %123, float* %124, float* %125, i32 %126, i32 %127)
br label %129
129: ; preds = %122
%130 = load i32, i32* %6
%131 = add nsw i32 %130, 1
store i32 %131, i32* %6
br label %118
132: ; preds = %118
%133 = load i32, i32* @CLOCK_MONOTONIC_RAW
%134 = call i32 @clock_gettime(i32 %133, %struct.timespec* %11)
store i32 0, i32* %6
br label %135
135: ; preds = %146, %132
%136 = load i32, i32* %6
%137 = load i32, i32* %10
%138 = icmp slt i32 %136, %137
br i1 %138, label %139, label %149
139: ; preds = %135
%140 = load float*, float** %15
%141 = load float*, float** %16
%142 = load float*, float** %18
%143 = load i32, i32* %7
%144 = load i32, i32* %8
%145 = call i32 @sgemm_kernel_x64_fma_m4n24(float* %140, float* %141, float* %142, i32 %143, i32 %144)
br label %146
146: ; preds = %139
%147 = load i32, i32* %6
%148 = add nsw i32 %147, 1
store i32 %148, i32* %6
br label %135
149: ; preds = %135
%150 = load i32, i32* @CLOCK_MONOTONIC_RAW
%151 = call i32 @clock_gettime(i32 %150, %struct.timespec* %12)
%152 = call i32 @get_time(%struct.timespec* %11, %struct.timespec* %12)
%153 = load i32, i32* %10
%154 = sdiv i32 %152, %153
%155 = sitofp i32 %154 to double
store double %155, double* %13
%156 = load i64, i64* %9
%157 = sitofp i64 %156 to double
%158 = load double, double* %13
%159 = fdiv double %157, %158
%160 = fmul double %159, 1.000000e-09
store double %160, double* %14
%161 = load i32, i32* %7
%162 = load i32, i32* %8
%163 = load double, double* %13
%164 = fmul double %163, 1.000000e+06
%165 = load double, double* %14
%166 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i32 %161, i32 24, i32 %162, double %164, double %165)
%167 = load float*, float** %17
%168 = load i32, i32* %7
%169 = mul nsw i32 %168, 24
%170 = sext i32 %169 to i64
%171 = mul i64 %170, 4
%172 = trunc i64 %171 to i32
%173 = call i32 @memset(float* %167, i32 0, i32 %172)
%174 = load float*, float** %18
%175 = load i32, i32* %7
%176 = mul nsw i32 %175, 24
%177 = sext i32 %176 to i64
%178 = mul i64 %177, 4
%179 = trunc i64 %178 to i32
%180 = call i32 @memset(float* %174, i32 0, i32 %179)
%181 = load float*, float** %15
%182 = load float*, float** %16
%183 = load float*, float** %17
%184 = load i32, i32* %7
%185 = load i32, i32* %8
%186 = call i32 @sgemm_naive(float* %181, float* %182, float* %183, i32 %184, i32 24, i32 %185)
%187 = load float*, float** %15
%188 = load float*, float** %16
%189 = load float*, float** %18
%190 = load i32, i32* %7
%191 = load i32, i32* %8
%192 = call i32 @sgemm_kernel_x64_fma_m4n24(float* %187, float* %188, float* %189, i32 %190, i32 %191)
%193 = load float*, float** %17
%194 = load i32, i32* %7
%195 = mul nsw i32 %194, 24
%196 = call i32 @save_bin(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), float* %193, i32 %195)
%197 = load float*, float** %18
%198 = load i32, i32* %7
%199 = mul nsw i32 %198, 24
%200 = call i32 @save_bin(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), float* %197, i32 %199)
%201 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%202 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0))
%203 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.6, i64 0, i64 0))
%204 = load float*, float** %15
%205 = load i32, i32* %7
%206 = load i32, i32* %8
%207 = mul nsw i32 %205, %206
%208 = sext i32 %207 to i64
%209 = mul i64 %208, 4
%210 = trunc i64 %209 to i32
%211 = call i32 @page_free(float* %204, i32 %210)
%212 = load float*, float** %16
%213 = load i32, i32* %8
%214 = mul nsw i32 %213, 24
%215 = sext i32 %214 to i64
%216 = mul i64 %215, 4
%217 = trunc i64 %216 to i32
%218 = call i32 @page_free(float* %212, i32 %217)
%219 = load float*, float** %17
%220 = load i32, i32* %7
%221 = mul nsw i32 %220, 24
%222 = sext i32 %221 to i64
%223 = mul i64 %222, 4
%224 = trunc i64 %223 to i32
%225 = call i32 @page_free(float* %219, i32 %224)
%226 = load float*, float** %18
%227 = load i32, i32* %7
%228 = mul nsw i32 %227, 24
%229 = sext i32 %228 to i64
%230 = mul i64 %229, 4
%231 = trunc i64 %230 to i32
%232 = call i32 @page_free(float* %226, i32 %231)
store i32 0, i32* %3
br label %233
233: ; preds = %149, %21
%234 = load i32, i32* %3
ret i32 %234
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@stderr = global i32 0
@.str = [15 x i8] c"Usage: %s m k\0A\00"
@RAND_MAX = global i64 0
@CLOCK_MONOTONIC_RAW = global i32 0
@.str.1 = [69 x i8] c"sgemm_kernel_x64_fma(%d, %d, %d): time = %lf us, perf = %lf GFLOPS.\0A\00"
@.str.2 = [10 x i8] c"naive.bin\00"
@.str.3 = [10 x i8] c"tuned.bin\00"
@str = [30 x i8] c"sgemm_naive result: naive.bin\00"
@str.7 = [45 x i8] c"sgemm_kernel_x64_fma_m4n24 result: tuned.bin\00"
@str.8 = [73 x i8] c"Use fp_diff(https://github.com/pigirons/fp_diff) to compare the results.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = icmp eq i32 %0, 3
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %112
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = sext i32 %13 to i64
%18 = sext i32 %16 to i64
%19 = mul nsw i64 %17, 48
%20 = mul i64 %19, %18
%21 = sitofp i64 %20 to double
%22 = fdiv double 2.000000e+11, %21
%23 = fptosi double %22 to i32
%24 = bitcast %struct.timespec* %3 to i8*
%25 = bitcast %struct.timespec* %4 to i8*
%26 = tail call i32 @thread_bind(i32 0)
%27 = mul nsw i32 %16, %13
%28 = shl i32 %27, 2
%29 = tail call i64 @page_alloc(i32 %28)
%30 = inttoptr i64 %29 to float*
%31 = mul i32 %16, 24
%32 = mul i32 %16, 96
%33 = tail call i64 @page_alloc(i32 %32)
%34 = inttoptr i64 %33 to float*
%35 = mul nsw i32 %13, 24
%36 = mul i32 %13, 96
%37 = tail call i64 @page_alloc(i32 %36)
%38 = inttoptr i64 %37 to float*
%39 = tail call i64 @page_alloc(i32 %36)
%40 = inttoptr i64 %39 to float*
%41 = tail call i32 @time(i32* null)
%42 = tail call i32 @srand(i32 %41)
%43 = icmp sgt i32 %27, 0
br i1 %43, label %44, label %46
44: ; preds = %10
%45 = zext i32 %27 to i64
br label %51
46: ; preds = %51, %10
%47 = icmp sgt i32 %16, 0
br i1 %47, label %48, label %61
48: ; preds = %46
%49 = call i32 @llvm.smax.i32(i32 %31, i32 1)
%50 = zext i32 %49 to i64
br label %66
51: ; preds = %44, %51
%52 = phi i64 [ 0, %44 ], [ %59, %51 ]
%53 = tail call i64 (...) @rand()
%54 = sitofp i64 %53 to float
%55 = load i64, i64* @RAND_MAX
%56 = sitofp i64 %55 to float
%57 = fdiv float %54, %56
%58 = getelementptr inbounds float, float* %30, i64 %52
store float %57, float* %58
%59 = add nuw nsw i64 %52, 1
%60 = icmp eq i64 %59, %45
br i1 %60, label %46, label %51
61: ; preds = %66, %46
%62 = icmp sgt i32 %23, 0
br i1 %62, label %76, label %63
63: ; preds = %61
%64 = load i32, i32* @CLOCK_MONOTONIC_RAW
%65 = call i32 @clock_gettime(i32 %64, %struct.timespec* %3)
br label %89
66: ; preds = %48, %66
%67 = phi i64 [ 0, %48 ], [ %74, %66 ]
%68 = tail call i64 (...) @rand()
%69 = sitofp i64 %68 to float
%70 = load i64, i64* @RAND_MAX
%71 = sitofp i64 %70 to float
%72 = fdiv float %69, %71
%73 = getelementptr inbounds float, float* %34, i64 %67
store float %72, float* %73
%74 = add nuw nsw i64 %67, 1
%75 = icmp eq i64 %74, %50
br i1 %75, label %61, label %66
76: ; preds = %61, %76
%77 = phi i32 [ %79, %76 ], [ 0, %61 ]
%78 = tail call i32 @sgemm_kernel_x64_fma_m4n24(float* %30, float* %34, float* %40, i32 %13, i32 %16)
%79 = add nuw nsw i32 %77, 1
%80 = icmp eq i32 %79, %23
br i1 %80, label %81, label %76
81: ; preds = %76
%82 = load i32, i32* @CLOCK_MONOTONIC_RAW
%83 = call i32 @clock_gettime(i32 %82, %struct.timespec* %3)
br i1 %62, label %84, label %89
84: ; preds = %81, %84
%85 = phi i32 [ %87, %84 ], [ 0, %81 ]
%86 = call i32 @sgemm_kernel_x64_fma_m4n24(float* %30, float* %34, float* %40, i32 %13, i32 %16)
%87 = add nuw nsw i32 %85, 1
%88 = icmp eq i32 %87, %23
br i1 %88, label %89, label %84
89: ; preds = %84, %63, %81
%90 = load i32, i32* @CLOCK_MONOTONIC_RAW
%91 = call i32 @clock_gettime(i32 %90, %struct.timespec* %4)
%92 = call i32 @get_time(%struct.timespec* %3, %struct.timespec* %4)
%93 = sdiv i32 %92, %23
%94 = sitofp i32 %93 to double
%95 = fdiv double %21, %94
%96 = fmul double %95, 1.000000e-09
%97 = fmul double %94, 1.000000e+06
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 24, i32 %16, double %97, double %96)
%99 = call i32 @memset(float* %38, i32 0, i32 %36)
%100 = call i32 @memset(float* %40, i32 0, i32 %36)
%101 = call i32 @sgemm_naive(float* %30, float* %34, float* %38, i32 %13, i32 24, i32 %16)
%102 = call i32 @sgemm_kernel_x64_fma_m4n24(float* %30, float* %34, float* %40, i32 %13, i32 %16)
%103 = call i32 @save_bin(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), float* %38, i32 %35)
%104 = call i32 @save_bin(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), float* %40, i32 %35)
%105 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%106 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.7, i64 0, i64 0))
%107 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str.8, i64 0, i64 0))
%108 = call i32 @page_free(float* %30, i32 %28)
%109 = call i32 @page_free(float* %34, i32 %32)
%110 = call i32 @page_free(float* %38, i32 %36)
%111 = call i32 @page_free(float* %40, i32 %36)
br label %112
112: ; preds = %89, %6
ret i32 0
}