void aesni_setkey_enc_256(unsigned char *rk, const unsigned char *key) {
  asm("movdqu (%1), %%xmm0           \n\t"
      "movdqu %%xmm0, (%0)           \n\t"
      "add $16, %0                   \n\t"
      "movdqu 16(%1), %%xmm1         \n\t"
      "movdqu %%xmm1, (%0)           \n\t"
      "jmp 2f                        \n\t"
      "1:                                \n\t"
      "pshufd $0xff, %%xmm2, %%xmm2      \n\t"
      "pxor %%xmm0, %%xmm2               \n\t"
      "pslldq $4, %%xmm0                 \n\t"
      "pxor %%xmm0, %%xmm2               \n\t"
      "pslldq $4, %%xmm0                 \n\t"
      "pxor %%xmm0, %%xmm2               \n\t"
      "pslldq $4, %%xmm0                 \n\t"
      "pxor %%xmm2, %%xmm0               \n\t"
      "add $16, %0                       \n\t"
      "movdqu %%xmm0, (%0)               \n\t"
      ".byte 0x66,0x0F,0x3A,0xDF,"
      "0xD0"
      ",0x00        \n\t"
      "pshufd $0xaa, %%xmm2, %%xmm2      \n\t"
      "pxor %%xmm1, %%xmm2               \n\t"
      "pslldq $4, %%xmm1                 \n\t"
      "pxor %%xmm1, %%xmm2               \n\t"
      "pslldq $4, %%xmm1                 \n\t"
      "pxor %%xmm1, %%xmm2               \n\t"
      "pslldq $4, %%xmm1                 \n\t"
      "pxor %%xmm2, %%xmm1               \n\t"
      "add $16, %0                       \n\t"
      "movdqu %%xmm1, (%0)               \n\t"
      "ret                               \n\t"
      "2:                                \n\t"
      ".byte 0x66,0x0F,0x3A,0xDF,"
      "0xD1"
      ",0x01        \n\tcall 1b \n\t"
      ".byte 0x66,0x0F,0x3A,0xDF,"
      "0xD1"
      ",0x02        \n\tcall 1b \n\t"
      ".byte 0x66,0x0F,0x3A,0xDF,"
      "0xD1"
      ",0x04        \n\tcall 1b \n\t"
      ".byte 0x66,0x0F,0x3A,0xDF,"
      "0xD1"
      ",0x08        \n\tcall 1b \n\t"
      ".byte 0x66,0x0F,0x3A,0xDF,"
      "0xD1"
      ",0x10        \n\tcall 1b \n\t"
      ".byte 0x66,0x0F,0x3A,0xDF,"
      "0xD1"
      ",0x20        \n\tcall 1b \n\t"
      ".byte 0x66,0x0F,0x3A,0xDF,"
      "0xD1"
      ",0x40        \n\tcall 1b \n\t"
      :
      : "r"(rk), "r"(key)
      : "memory", "cc", "0");
}


x86 assembly (clang, -O0):
<aesni_setkey_enc_256>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rdx
movdqu (%rdx),%xmm0
movdqu %xmm0,(%rcx)
add    $0x10,%rcx
movdqu 0x10(%rdx),%xmm1
movdqu %xmm1,(%rcx)
jmp    118d <aesni_setkey_enc_256+0x8d>
pshufd $0xff,%xmm2,%xmm2
pxor   %xmm0,%xmm2
pslldq $0x4,%xmm0
pxor   %xmm0,%xmm2
pslldq $0x4,%xmm0
pxor   %xmm0,%xmm2
pslldq $0x4,%xmm0
pxor   %xmm2,%xmm0
add    $0x10,%rcx
movdqu %xmm0,(%rcx)
aeskeygenassist $0x0,%xmm0,%xmm2
pshufd $0xaa,%xmm2,%xmm2
pxor   %xmm1,%xmm2
pslldq $0x4,%xmm1
pxor   %xmm1,%xmm2
pslldq $0x4,%xmm1
pxor   %xmm1,%xmm2
pslldq $0x4,%xmm1
pxor   %xmm2,%xmm1
add    $0x10,%rcx
movdqu %xmm1,(%rcx)
ret
aeskeygenassist $0x1,%xmm1,%xmm2
call   112e <aesni_setkey_enc_256+0x2e>
aeskeygenassist $0x2,%xmm1,%xmm2
call   112e <aesni_setkey_enc_256+0x2e>
aeskeygenassist $0x4,%xmm1,%xmm2
call   112e <aesni_setkey_enc_256+0x2e>
aeskeygenassist $0x8,%xmm1,%xmm2
call   112e <aesni_setkey_enc_256+0x2e>
aeskeygenassist $0x10,%xmm1,%xmm2
call   112e <aesni_setkey_enc_256+0x2e>
aeskeygenassist $0x20,%xmm1,%xmm2
call   112e <aesni_setkey_enc_256+0x2e>
aeskeygenassist $0x40,%xmm1,%xmm2
call   112e <aesni_setkey_enc_256+0x2e>
pop    %rbp
ret

x86 assembly (clang, -O2):
<aesni_setkey_enc_256>:
movdqu (%rsi),%xmm0
movdqu %xmm0,(%rdi)
add    $0x10,%rdi
movdqu 0x10(%rsi),%xmm1
movdqu %xmm1,(%rdi)
jmp    1176 <aesni_setkey_enc_256+0x76>
pshufd $0xff,%xmm2,%xmm2
pxor   %xmm0,%xmm2
pslldq $0x4,%xmm0
pxor   %xmm0,%xmm2
pslldq $0x4,%xmm0
pxor   %xmm0,%xmm2
pslldq $0x4,%xmm0
pxor   %xmm2,%xmm0
add    $0x10,%rdi
movdqu %xmm0,(%rdi)
aeskeygenassist $0x0,%xmm0,%xmm2
pshufd $0xaa,%xmm2,%xmm2
pxor   %xmm1,%xmm2
pslldq $0x4,%xmm1
pxor   %xmm1,%xmm2
pslldq $0x4,%xmm1
pxor   %xmm1,%xmm2
pslldq $0x4,%xmm1
pxor   %xmm2,%xmm1
add    $0x10,%rdi
movdqu %xmm1,(%rdi)
ret
aeskeygenassist $0x1,%xmm1,%xmm2
call   1117 <aesni_setkey_enc_256+0x17>
aeskeygenassist $0x2,%xmm1,%xmm2
call   1117 <aesni_setkey_enc_256+0x17>
aeskeygenassist $0x4,%xmm1,%xmm2
call   1117 <aesni_setkey_enc_256+0x17>
aeskeygenassist $0x8,%xmm1,%xmm2
call   1117 <aesni_setkey_enc_256+0x17>
aeskeygenassist $0x10,%xmm1,%xmm2
call   1117 <aesni_setkey_enc_256+0x17>
aeskeygenassist $0x20,%xmm1,%xmm2
call   1117 <aesni_setkey_enc_256+0x17>
aeskeygenassist $0x40,%xmm1,%xmm2
call   1117 <aesni_setkey_enc_256+0x17>
ret

LLVM IR (-O0):
define void @aesni_setkey_enc_256(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%5 = load i8*, i8** %3
%6 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
define void @aesni_setkey_enc_256(i8* %0, i8* %1) {
tail call void asm sideeffect "movdqu ($1), %xmm0 \0A\09movdqu %xmm0, ($0) \0A\09add $$16, $0 \0A\09movdqu 16($1), %xmm1 \0A\09movdqu %xmm1, ($0) \0A\09jmp 2f \0A\091: \0A\09pshufd $$0xff, %xmm2, %xmm2 \0A\09pxor %xmm0, %xmm2 \0A\09pslldq $$4, %xmm0 \0A\09pxor %xmm0, %xmm2 \0A\09pslldq $$4, %xmm0 \0A\09pxor %xmm0, %xmm2 \0A\09pslldq $$4, %xmm0 \0A\09pxor %xmm2, %xmm0 \0A\09add $$16, $0 \0A\09movdqu %xmm0, ($0) \0A\09.byte 0x66,0x0F,0x3A,0xDF,0xD0,0x00 \0A\09pshufd $$0xaa, %xmm2, %xmm2 \0A\09pxor %xmm1, %xmm2 \0A\09pslldq $$4, %xmm1 \0A\09pxor %xmm1, %xmm2 \0A\09pslldq $$4, %xmm1 \0A\09pxor %xmm1, %xmm2 \0A\09pslldq $$4, %xmm1 \0A\09pxor %xmm2, %xmm1 \0A\09add $$16, $0 \0A\09movdqu %xmm1, ($0) \0A\09ret \0A\092: \0A\09.byte 0x66,0x0F,0x3A,0xDF,0xD1,0x01 \0A\09call 1b \0A\09.byte 0x66,0x0F,0x3A,0xDF,0xD1,0x02 \0A\09call 1b \0A\09.byte 0x66,0x0F,0x3A,0xDF,0xD1,0x04 \0A\09call 1b \0A\09.byte 0x66,0x0F,0x3A,0xDF,0xD1,0x08 \0A\09call 1b \0A\09.byte 0x66,0x0F,0x3A,0xDF,0xD1,0x10 \0A\09call 1b \0A\09.byte 0x66,0x0F,0x3A,0xDF,0xD1,0x20 \0A\09call 1b \0A\09.byte 0x66,0x0F,0x3A,0xDF,0xD1,0x40 \0A\09call 1b \0A\09", "r,r,~{memory},~{cc},~{ax},~{dirflag},~{fpsr},~{flags}"(i8* %0, i8* %1)
ret void
}