void kernel_sgemm_nt_8x4_lib4(int kmax, float *A0, float *A1, float *B,
                              float *C0, float *C1, float *D0, float *D1,
                              int alg) {
  if (kmax <= 0)
    return;
  int k_iter = kmax / 4;
  int k_left = kmax % 4;
  __asm__ volatile("                                \n\t"
                   "                                \n\t"
                   "movq          %2, %%rax         \n\t"
                   "movq          %3, %%rcx         \n\t"
                   "movq          %4, %%rbx         \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "movaps        0(%%rax), %%xmm0  \n\t"
                   "movaps        0(%%rcx), %%xmm1  \n\t"
                   "movaps        0(%%rbx), %%xmm2  \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "xorpd     %%xmm3,  %%xmm3       \n\t"
                   "movaps    %%xmm3,  %%xmm4       \n\t"
                   "movaps    %%xmm3,  %%xmm5       \n\t"
                   "movaps    %%xmm3,  %%xmm6       \n\t"
                   "movaps    %%xmm3,  %%xmm7       \n\t"
                   "movaps    %%xmm3,  %%xmm8       \n\t"
                   "movaps    %%xmm3,  %%xmm9       \n\t"
                   "movaps    %%xmm3, %%xmm10       \n\t"
                   "movaps    %%xmm3, %%xmm11       \n\t"
                   "movaps    %%xmm3, %%xmm12       \n\t"
                   "movaps    %%xmm3, %%xmm13       \n\t"
                   "movaps    %%xmm3, %%xmm14       \n\t"
                   "movaps    %%xmm3, %%xmm15       \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "movl      %0, %%esi             \n\t"
                   "testl  %%esi, %%esi             \n\t"
                   "je     .SCONSIDKLEFT_8X4        \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   ".SLOOPKITER_8X4:                \n\t"
                   "                                \n\t"
                   "addps   %%xmm6, %%xmm10         \n\t"
                   "addps   %%xmm3, %%xmm14         \n\t"
                   "movaps  %%xmm2, %%xmm3          \n\t"
                   "pshufd   $0x39, %%xmm2, %%xmm7  \n\t"
                   "mulps   %%xmm0, %%xmm2          \n\t"
                   "mulps   %%xmm1, %%xmm3          \n\t"
                   "                                \n\t"
                   "addps   %%xmm4, %%xmm11         \n\t"
                   "addps   %%xmm5, %%xmm15         \n\t"
                   "movaps  %%xmm7, %%xmm5          \n\t"
                   "pshufd   $0x39, %%xmm7, %%xmm6  \n\t"
                   "mulps   %%xmm0, %%xmm7          \n\t"
                   "mulps   %%xmm1, %%xmm5          \n\t"
                   "                                \n\t"
                   "addps   %%xmm2, %%xmm8          \n\t"
                   "movaps       16(%%rbx), %%xmm2  \n\t"
                   "addps   %%xmm3, %%xmm12         \n\t"
                   "movaps  %%xmm6, %%xmm3          \n\t"
                   "pshufd   $0x39, %%xmm6, %%xmm4  \n\t"
                   "mulps   %%xmm0, %%xmm6          \n\t"
                   "mulps   %%xmm1, %%xmm3          \n\t"
                   "                                \n\t"
                   "addps   %%xmm7, %%xmm9          \n\t"
                   "addps   %%xmm5, %%xmm13         \n\t"
                   "movaps  %%xmm4, %%xmm5          \n\t"
                   "mulps   %%xmm0, %%xmm4          \n\t"
                   "movaps       16(%%rax), %%xmm0  \n\t"
                   "mulps   %%xmm1, %%xmm5          \n\t"
                   "movaps       16(%%rcx), %%xmm1  \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "addps   %%xmm6, %%xmm10         \n\t"
                   "addps   %%xmm3, %%xmm14         \n\t"
                   "movaps  %%xmm2, %%xmm3          \n\t"
                   "pshufd   $0x39, %%xmm2, %%xmm7  \n\t"
                   "mulps   %%xmm0, %%xmm2          \n\t"
                   "mulps   %%xmm1, %%xmm3          \n\t"
                   "                                \n\t"
                   "addps   %%xmm4, %%xmm11         \n\t"
                   "addps   %%xmm5, %%xmm15         \n\t"
                   "movaps  %%xmm7, %%xmm5          \n\t"
                   "pshufd   $0x39, %%xmm7, %%xmm6  \n\t"
                   "mulps   %%xmm0, %%xmm7          \n\t"
                   "mulps   %%xmm1, %%xmm5          \n\t"
                   "                                \n\t"
                   "addps   %%xmm2, %%xmm8          \n\t"
                   "movaps       32(%%rbx), %%xmm2  \n\t"
                   "addps   %%xmm3, %%xmm12         \n\t"
                   "movaps  %%xmm6, %%xmm3          \n\t"
                   "pshufd   $0x39, %%xmm6, %%xmm4  \n\t"
                   "mulps   %%xmm0, %%xmm6          \n\t"
                   "mulps   %%xmm1, %%xmm3          \n\t"
                   "                                \n\t"
                   "addps   %%xmm7, %%xmm9          \n\t"
                   "addps   %%xmm5, %%xmm13         \n\t"
                   "movaps  %%xmm4, %%xmm5          \n\t"
                   "mulps   %%xmm0, %%xmm4          \n\t"
                   "movaps       32(%%rax), %%xmm0  \n\t"
                   "mulps   %%xmm1, %%xmm5          \n\t"
                   "movaps       32(%%rcx), %%xmm1  \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "addps   %%xmm6, %%xmm10         \n\t"
                   "addps   %%xmm3, %%xmm14         \n\t"
                   "movaps  %%xmm2, %%xmm3          \n\t"
                   "pshufd   $0x39, %%xmm2, %%xmm7  \n\t"
                   "mulps   %%xmm0, %%xmm2          \n\t"
                   "mulps   %%xmm1, %%xmm3          \n\t"
                   "                                \n\t"
                   "addps   %%xmm4, %%xmm11         \n\t"
                   "addps   %%xmm5, %%xmm15         \n\t"
                   "movaps  %%xmm7, %%xmm5          \n\t"
                   "pshufd   $0x39, %%xmm7, %%xmm6  \n\t"
                   "mulps   %%xmm0, %%xmm7          \n\t"
                   "mulps   %%xmm1, %%xmm5          \n\t"
                   "                                \n\t"
                   "addps   %%xmm2, %%xmm8          \n\t"
                   "movaps       48(%%rbx), %%xmm2  \n\t"
                   "addps   %%xmm3, %%xmm12         \n\t"
                   "movaps  %%xmm6, %%xmm3          \n\t"
                   "pshufd   $0x39, %%xmm6, %%xmm4  \n\t"
                   "mulps   %%xmm0, %%xmm6          \n\t"
                   "mulps   %%xmm1, %%xmm3          \n\t"
                   "                                \n\t"
                   "addps   %%xmm7, %%xmm9          \n\t"
                   "addps   %%xmm5, %%xmm13         \n\t"
                   "movaps  %%xmm4, %%xmm5          \n\t"
                   "mulps   %%xmm0, %%xmm4          \n\t"
                   "movaps       48(%%rax), %%xmm0  \n\t"
                   "mulps   %%xmm1, %%xmm5          \n\t"
                   "movaps       48(%%rcx), %%xmm1  \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "addps   %%xmm6, %%xmm10         \n\t"
                   "addps   %%xmm3, %%xmm14         \n\t"
                   "movaps  %%xmm2, %%xmm3          \n\t"
                   "pshufd   $0x39, %%xmm2, %%xmm7  \n\t"
                   "mulps   %%xmm0, %%xmm2          \n\t"
                   "mulps   %%xmm1, %%xmm3          \n\t"
                   "                                \n\t"
                   "addq       $64, %%rax           \n\t"
                   "                                \n\t"
                   "addps   %%xmm4, %%xmm11         \n\t"
                   "addps   %%xmm5, %%xmm15         \n\t"
                   "movaps  %%xmm7, %%xmm5          \n\t"
                   "pshufd   $0x39, %%xmm7, %%xmm6  \n\t"
                   "mulps   %%xmm0, %%xmm7          \n\t"
                   "mulps   %%xmm1, %%xmm5          \n\t"
                   "                                \n\t"
                   "addq       $64, %%rbx           \n\t"
                   "                                \n\t"
                   "addps   %%xmm2, %%xmm8          \n\t"
                   "movaps         (%%rbx), %%xmm2  \n\t"
                   "addps   %%xmm3, %%xmm12         \n\t"
                   "movaps  %%xmm6, %%xmm3          \n\t"
                   "pshufd   $0x39, %%xmm6, %%xmm4  \n\t"
                   "mulps   %%xmm0, %%xmm6          \n\t"
                   "mulps   %%xmm1, %%xmm3          \n\t"
                   "                                \n\t"
                   "addq       $64, %%rcx           \n\t"
                   "                                \n\t"
                   "addps   %%xmm7, %%xmm9          \n\t"
                   "decl    %%esi                   \n\t"
                   "addps   %%xmm5, %%xmm13         \n\t"
                   "movaps  %%xmm4, %%xmm5          \n\t"
                   "mulps   %%xmm0, %%xmm4          \n\t"
                   "movaps         (%%rax), %%xmm0  \n\t"
                   "mulps   %%xmm1, %%xmm5          \n\t"
                   "movaps         (%%rcx), %%xmm1  \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "jne    .SLOOPKITER_8X4          \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   ".SCONSIDKLEFT_8X4:              \n\t"
                   "                                \n\t"
                   "movl      %1, %%esi             \n\t"
                   "testl  %%esi, %%esi             \n\t"
                   "je     .SPOSTACCUM_8X4          \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   ".SLOOPKLEFT_8X4:                \n\t"
                   "                                \n\t"
                   "addps   %%xmm6, %%xmm10         \n\t"
                   "addps   %%xmm3, %%xmm14         \n\t"
                   "movaps  %%xmm2, %%xmm3          \n\t"
                   "pshufd   $0x39, %%xmm2, %%xmm7  \n\t"
                   "mulps   %%xmm0, %%xmm2          \n\t"
                   "mulps   %%xmm1, %%xmm3          \n\t"
                   "                                \n\t"
                   "addps   %%xmm4, %%xmm11         \n\t"
                   "addps   %%xmm5, %%xmm15         \n\t"
                   "movaps  %%xmm7, %%xmm5          \n\t"
                   "pshufd   $0x39, %%xmm7, %%xmm6  \n\t"
                   "mulps   %%xmm0, %%xmm7          \n\t"
                   "mulps   %%xmm1, %%xmm5          \n\t"
                   "                                \n\t"
                   "addps   %%xmm2, %%xmm8          \n\t"
                   "movaps       16(%%rbx), %%xmm2  \n\t"
                   "addps   %%xmm3, %%xmm12         \n\t"
                   "movaps  %%xmm6, %%xmm3          \n\t"
                   "pshufd   $0x39, %%xmm6, %%xmm4  \n\t"
                   "mulps   %%xmm0, %%xmm6          \n\t"
                   "mulps   %%xmm1, %%xmm3          \n\t"
                   "                                \n\t"
                   "addps   %%xmm7, %%xmm9          \n\t"
                   "addps   %%xmm5, %%xmm13         \n\t"
                   "movaps  %%xmm4, %%xmm5          \n\t"
                   "mulps   %%xmm0, %%xmm4          \n\t"
                   "movaps       16(%%rax), %%xmm0  \n\t"
                   "mulps   %%xmm1, %%xmm5          \n\t"
                   "movaps       16(%%rcx), %%xmm1  \n\t"
                   "                                \n\t"
                   "addq          $16, %%rax        \n\t"
                   "addq          $16, %%rcx        \n\t"
                   "addq          $16, %%rbx        \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "decl    %%esi                   \n\t"
                   "jne    .SLOOPKLEFT_8X4          \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   ".SPOSTACCUM_8X4:                \n\t"
                   "                                \n\t"
                   "addps   %%xmm6, %%xmm10         \n\t"
                   "addps   %%xmm3, %%xmm14         \n\t"
                   "addps   %%xmm4, %%xmm11         \n\t"
                   "addps   %%xmm5, %%xmm15         \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "movaps  %%xmm9, %%xmm4          \n\t"
                   "shufps   $0xd8, %%xmm8,  %%xmm9 \n\t"
                   "shufps   $0xd8, %%xmm11, %%xmm8 \n\t"
                   "shufps   $0xd8, %%xmm10, %%xmm11\n\t"
                   "shufps   $0xd8, %%xmm4,  %%xmm10\n\t"
                   "                                \n\t"
                   "movaps  %%xmm8, %%xmm4          \n\t"
                   "shufps   $0xd8, %%xmm10, %%xmm8 \n\t"
                   "shufps   $0xd8, %%xmm4, %%xmm10 \n\t"
                   "movaps  %%xmm9, %%xmm5          \n\t"
                   "shufps   $0xd8, %%xmm11, %%xmm9 \n\t"
                   "shufps   $0xd8, %%xmm5, %%xmm11 \n\t"
                   "                                \n\t"
                   "movaps  %%xmm13, %%xmm4         \n\t"
                   "shufps   $0xd8, %%xmm12, %%xmm13\n\t"
                   "shufps   $0xd8, %%xmm15, %%xmm12\n\t"
                   "shufps   $0xd8, %%xmm14, %%xmm15\n\t"
                   "shufps   $0xd8, %%xmm4,  %%xmm14\n\t"
                   "                                \n\t"
                   "movaps  %%xmm12, %%xmm4         \n\t"
                   "shufps   $0xd8, %%xmm14, %%xmm12\n\t"
                   "shufps   $0xd8, %%xmm4, %%xmm14 \n\t"
                   "movaps  %%xmm13, %%xmm5         \n\t"
                   "shufps   $0xd8, %%xmm15, %%xmm13\n\t"
                   "shufps   $0xd8, %%xmm5, %%xmm15 \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "movq   %5, %%rax                \n\t"
                   "movq   %6, %%rbx                \n\t"
                   "movq   %8, %%r8                 \n\t"
                   "movq   %9, %%r9                 \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "movl   %7, %%ecx                \n\t"
                   "testl  %%ecx, %%ecx             \n\t"
                   "je     .S0_8X4                  \n\t"
                   "                                \n\t"
                   "cmpl	$1, %%ecx                \n\t"
                   "                                \n\t"
                   "movaps  (%%rax),   %%xmm0       \n\t"
                   "movaps  16(%%rax), %%xmm1       \n\t"
                   "movaps  32(%%rax), %%xmm2       \n\t"
                   "movaps  48(%%rax), %%xmm3       \n\t"
                   "movaps  (%%rbx),   %%xmm4       \n\t"
                   "movaps  16(%%rbx), %%xmm5       \n\t"
                   "movaps  32(%%rbx), %%xmm6       \n\t"
                   "movaps  48(%%rbx), %%xmm7       \n\t"
                   "                                \n\t"
                   "je     .S1_8X4                  \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "subps  %%xmm8,  %%xmm0           \n\t"
                   "subps  %%xmm9,  %%xmm1           \n\t"
                   "subps  %%xmm10, %%xmm2           \n\t"
                   "subps  %%xmm11, %%xmm3           \n\t"
                   "subps  %%xmm12, %%xmm4           \n\t"
                   "subps  %%xmm13, %%xmm5           \n\t"
                   "subps  %%xmm14, %%xmm6           \n\t"
                   "subps  %%xmm15, %%xmm7           \n\t"
                   "                                \n\t"
                   "movaps  %%xmm0, (%%r8)         \n\t"
                   "movaps  %%xmm1, 16(%%r8)       \n\t"
                   "movaps  %%xmm2, 32(%%r8)       \n\t"
                   "movaps  %%xmm3, 48(%%r8)       \n\t"
                   "movaps  %%xmm4, (%%r9)         \n\t"
                   "movaps  %%xmm5, 16(%%r9)       \n\t"
                   "movaps  %%xmm6, 32(%%r9)       \n\t"
                   "movaps  %%xmm7, 48(%%r9)       \n\t"
                   "                                \n\t"
                   "jmp    .SDONE_8X4               \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   ".S1_8X4:                        \n\t"
                   "                                \n\t"
                   "addps  %%xmm0, %%xmm8           \n\t"
                   "addps  %%xmm1, %%xmm9           \n\t"
                   "addps  %%xmm2, %%xmm10          \n\t"
                   "addps  %%xmm3, %%xmm11          \n\t"
                   "addps  %%xmm4, %%xmm12          \n\t"
                   "addps  %%xmm5, %%xmm13          \n\t"
                   "addps  %%xmm6, %%xmm14          \n\t"
                   "addps  %%xmm7, %%xmm15          \n\t"
                   "                                \n\t"
                   ".S0_8X4:                        \n\t"
                   "                                \n\t"
                   "movaps	%%xmm8,  (%%r8)          \n\t"
                   "movaps	%%xmm9,  16(%%r8)        \n\t"
                   "movaps	%%xmm10, 32(%%r8)        \n\t"
                   "movaps	%%xmm11, 48(%%r8)        \n\t"
                   "movaps	%%xmm12, (%%r9)          \n\t"
                   "movaps	%%xmm13, 16(%%r9)        \n\t"
                   "movaps	%%xmm14, 32(%%r9)        \n\t"
                   "movaps	%%xmm15, 48(%%r9)        \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   "                                \n\t"
                   ".SDONE_8X4:                     \n\t"
                   "                                \n\t"
                   :
                   : "m"(k_iter), "m"(k_left), "m"(A0), "m"(A1), "m"(B),
                     "m"(C0), "m"(C1), "m"(alg), "m"(D0), "m"(D1)
                   : "rax", "rbx", "rcx", "r8", "r9", "rsi", "xmm0", "xmm1",
                     "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7", "xmm8",
                     "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14",
                     "xmm15", "memory");
}


x86 assembly (clang, -O0):
<kernel_sgemm_nt_8x4_lib4>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     1136 <kernel_sgemm_nt_8x4_lib4+0x36>
jmp    14f8 <.SDONE_8X4>
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x3c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%rbx
movaps (%rax),%xmm0
movaps (%rcx),%xmm1
movaps (%rbx),%xmm2
xorpd  %xmm3,%xmm3
movaps %xmm3,%xmm4
movaps %xmm3,%xmm5
movaps %xmm3,%xmm6
movaps %xmm3,%xmm7
movaps %xmm3,%xmm8
movaps %xmm3,%xmm9
movaps %xmm3,%xmm10
movaps %xmm3,%xmm11
movaps %xmm3,%xmm12
movaps %xmm3,%xmm13
movaps %xmm3,%xmm14
movaps %xmm3,%xmm15
mov    -0x3c(%rbp),%esi
test   %esi,%esi
je     132f <.SCONSIDKLEFT_8X4>

x86 assembly (clang, -O2):
<kernel_sgemm_nt_8x4_lib4>:
push   %rbx
mov    %rsi,-0x8(%rsp)
mov    %rdx,-0x10(%rsp)
mov    %rcx,-0x18(%rsp)
mov    %r8,-0x20(%rsp)
mov    %r9,-0x28(%rsp)
test   %edi,%edi
jle    14d3 <.SDONE_8X4>
mov    %edi,%eax
shr    $0x2,%eax
mov    %eax,-0x2c(%rsp)
and    $0x3,%edi
mov    %edi,-0x30(%rsp)
mov    -0x8(%rsp),%rax
mov    -0x10(%rsp),%rcx
mov    -0x18(%rsp),%rbx
movaps (%rax),%xmm0
movaps (%rcx),%xmm1
movaps (%rbx),%xmm2
xorpd  %xmm3,%xmm3
movaps %xmm3,%xmm4
movaps %xmm3,%xmm5
movaps %xmm3,%xmm6
movaps %xmm3,%xmm7
movaps %xmm3,%xmm8
movaps %xmm3,%xmm9
movaps %xmm3,%xmm10
movaps %xmm3,%xmm11
movaps %xmm3,%xmm12
movaps %xmm3,%xmm13
movaps %xmm3,%xmm14
movaps %xmm3,%xmm15
mov    -0x2c(%rsp),%esi
test   %esi,%esi
je     1313 <.SCONSIDKLEFT_8X4>

LLVM IR (-O0):
define void @kernel_sgemm_nt_8x4_lib4(i32 %0, float* %1, float* %2, float* %3, float* %4, float* %5, float* %6, float* %7, i32 %8) {
%10 = alloca i32
%11 = alloca float*
%12 = alloca float*
%13 = alloca float*
%14 = alloca float*
%15 = alloca float*
%16 = alloca float*
%17 = alloca float*
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i32 %0, i32* %10
store float* %1, float** %11
store float* %2, float** %12
store float* %3, float** %13
store float* %4, float** %14
store float* %5, float** %15
store float* %6, float** %16
store float* %7, float** %17
store i32 %8, i32* %18
%21 = load i32, i32* %10
%22 = icmp sle i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %9
br label %29
24: ; preds = %9
%25 = load i32, i32* %10
%26 = sdiv i32 %25, 4
store i32 %26, i32* %19
%27 = load i32, i32* %10
%28 = srem i32 %27, 4
store i32 %28, i32* %20
br label %29
29: ; preds = %24, %23
ret void
}

LLVM IR (-O2):
define void @kernel_sgemm_nt_8x4_lib4(i32 %0, float* %1, float* %2, float* %3, float* %4, float* %5, float* %6, float* %7, i32 %8) {
%10 = alloca float*
%11 = alloca float*
%12 = alloca float*
%13 = alloca float*
%14 = alloca float*
%15 = alloca float*
%16 = alloca float*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store float* %1, float** %10
store float* %2, float** %11
store float* %3, float** %12
store float* %4, float** %13
store float* %5, float** %14
store float* %6, float** %15
store float* %7, float** %16
store i32 %8, i32* %17
%20 = icmp slt i32 %0, 1
br i1 %20, label %26, label %21
21: ; preds = %9
%22 = bitcast i32* %18 to i8*
%23 = lshr i32 %0, 2
store i32 %23, i32* %18
%24 = bitcast i32* %19 to i8*
%25 = and i32 %0, 3
store i32 %25, i32* %19
br label %26
26: ; preds = %9, %21
ret void
}