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


x86 assembly (clang, -O0):
<aesni_setkey_enc_128>:
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)
jmp    114e <aesni_setkey_enc_128+0x4e>
pshufd $0xff,%xmm1,%xmm1
pxor   %xmm0,%xmm1
pslldq $0x4,%xmm0
pxor   %xmm0,%xmm1
pslldq $0x4,%xmm0
pxor   %xmm0,%xmm1
pslldq $0x4,%xmm0
pxor   %xmm1,%xmm0
add    $0x10,%rcx
movdqu %xmm0,(%rcx)
ret
aeskeygenassist $0x1,%xmm0,%xmm1
call   1121 <aesni_setkey_enc_128+0x21>
aeskeygenassist $0x2,%xmm0,%xmm1
call   1121 <aesni_setkey_enc_128+0x21>
aeskeygenassist $0x4,%xmm0,%xmm1
call   1121 <aesni_setkey_enc_128+0x21>
aeskeygenassist $0x8,%xmm0,%xmm1
call   1121 <aesni_setkey_enc_128+0x21>
aeskeygenassist $0x10,%xmm0,%xmm1
call   1121 <aesni_setkey_enc_128+0x21>
aeskeygenassist $0x20,%xmm0,%xmm1
call   1121 <aesni_setkey_enc_128+0x21>
aeskeygenassist $0x40,%xmm0,%xmm1
call   1121 <aesni_setkey_enc_128+0x21>
aeskeygenassist $0x80,%xmm0,%xmm1
call   1121 <aesni_setkey_enc_128+0x21>
aeskeygenassist $0x1b,%xmm0,%xmm1
call   1121 <aesni_setkey_enc_128+0x21>
aeskeygenassist $0x36,%xmm0,%xmm1
call   1121 <aesni_setkey_enc_128+0x21>
pop    %rbp
ret

x86 assembly (clang, -O2):
<aesni_setkey_enc_128>:
movdqu (%rsi),%xmm0
movdqu %xmm0,(%rdi)
jmp    1137 <aesni_setkey_enc_128+0x37>
pshufd $0xff,%xmm1,%xmm1
pxor   %xmm0,%xmm1
pslldq $0x4,%xmm0
pxor   %xmm0,%xmm1
pslldq $0x4,%xmm0
pxor   %xmm0,%xmm1
pslldq $0x4,%xmm0
pxor   %xmm1,%xmm0
add    $0x10,%rdi
movdqu %xmm0,(%rdi)
ret
aeskeygenassist $0x1,%xmm0,%xmm1
call   110a <aesni_setkey_enc_128+0xa>
aeskeygenassist $0x2,%xmm0,%xmm1
call   110a <aesni_setkey_enc_128+0xa>
aeskeygenassist $0x4,%xmm0,%xmm1
call   110a <aesni_setkey_enc_128+0xa>
aeskeygenassist $0x8,%xmm0,%xmm1
call   110a <aesni_setkey_enc_128+0xa>
aeskeygenassist $0x10,%xmm0,%xmm1
call   110a <aesni_setkey_enc_128+0xa>
aeskeygenassist $0x20,%xmm0,%xmm1
call   110a <aesni_setkey_enc_128+0xa>
aeskeygenassist $0x40,%xmm0,%xmm1
call   110a <aesni_setkey_enc_128+0xa>
aeskeygenassist $0x80,%xmm0,%xmm1
call   110a <aesni_setkey_enc_128+0xa>
aeskeygenassist $0x1b,%xmm0,%xmm1
call   110a <aesni_setkey_enc_128+0xa>
aeskeygenassist $0x36,%xmm0,%xmm1
call   110a <aesni_setkey_enc_128+0xa>
ret

LLVM IR (-O0):
define void @aesni_setkey_enc_128(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_128(i8* %0, i8* %1) {
tail call void asm sideeffect "movdqu ($1), %xmm0 \0A\09movdqu %xmm0, ($0) \0A\09jmp 2f \0A\091: \0A\09pshufd $$0xff, %xmm1, %xmm1 \0A\09pxor %xmm0, %xmm1 \0A\09pslldq $$4, %xmm0 \0A\09pxor %xmm0, %xmm1 \0A\09pslldq $$4, %xmm0 \0A\09pxor %xmm0, %xmm1 \0A\09pslldq $$4, %xmm0 \0A\09pxor %xmm1, %xmm0 \0A\09add $$16, $0 \0A\09movdqu %xmm0, ($0) \0A\09ret \0A\092: \0A\09.byte 0x66,0x0F,0x3A,0xDF,0xC8,0x01 \0A\09call 1b \0A\09.byte 0x66,0x0F,0x3A,0xDF,0xC8,0x02 \0A\09call 1b \0A\09.byte 0x66,0x0F,0x3A,0xDF,0xC8,0x04 \0A\09call 1b \0A\09.byte 0x66,0x0F,0x3A,0xDF,0xC8,0x08 \0A\09call 1b \0A\09.byte 0x66,0x0F,0x3A,0xDF,0xC8,0x10 \0A\09call 1b \0A\09.byte 0x66,0x0F,0x3A,0xDF,0xC8,0x20 \0A\09call 1b \0A\09.byte 0x66,0x0F,0x3A,0xDF,0xC8,0x40 \0A\09call 1b \0A\09.byte 0x66,0x0F,0x3A,0xDF,0xC8,0x80 \0A\09call 1b \0A\09.byte 0x66,0x0F,0x3A,0xDF,0xC8,0x1B \0A\09call 1b \0A\09.byte 0x66,0x0F,0x3A,0xDF,0xC8,0x36 \0A\09call 1b \0A\09", "r,r,~{memory},~{cc},~{ax},~{dirflag},~{fpsr},~{flags}"(i8* %0, i8* %1)
ret void
}