// File: /workspace/github_c_makefile_star2_O1/mjosaarinen[P]brutus/crypto_aead/aes128poetv1aes4/ni/aes-ni.c
// Function: AESNI_Key_Expansion
void AESNI_Key_Expansion(const unsigned char *userkey, AES_KEY enc_key)
{
    __m128i temp1, temp2;
    __m128i *Key_Schedule = (__m128i*)enc_key;

    temp1 = _mm_loadu_si128((__m128i*)userkey);
    _mm_storeu_si128(&Key_Schedule[0], temp1);
    temp2= _mm_aeskeygenassist_si128 (temp1 ,0x1);
    temp1 = AES_128_ASSIST(temp1, temp2);
    _mm_storeu_si128(&Key_Schedule[1], temp1);
    temp2 = _mm_aeskeygenassist_si128 (temp1,0x2);
    temp1 = AES_128_ASSIST(temp1, temp2);
    _mm_storeu_si128(&Key_Schedule[2], temp1);
    temp2 = _mm_aeskeygenassist_si128 (temp1,0x4);
    temp1 = AES_128_ASSIST(temp1, temp2);
    _mm_storeu_si128(&Key_Schedule[3], temp1);
    temp2 = _mm_aeskeygenassist_si128 (temp1,0x8);
    temp1 = AES_128_ASSIST(temp1, temp2);
    _mm_storeu_si128(&Key_Schedule[4], temp1);
    temp2 = _mm_aeskeygenassist_si128 (temp1,0x10);
    temp1 = AES_128_ASSIST(temp1, temp2);
    _mm_storeu_si128(&Key_Schedule[5], temp1);
    temp2 = _mm_aeskeygenassist_si128 (temp1,0x20);
    temp1 = AES_128_ASSIST(temp1, temp2);
    _mm_storeu_si128(&Key_Schedule[6], temp1);
    temp2 = _mm_aeskeygenassist_si128 (temp1,0x40);
    temp1 = AES_128_ASSIST(temp1, temp2);
    _mm_storeu_si128(&Key_Schedule[7], temp1);
    temp2 = _mm_aeskeygenassist_si128 (temp1,0x80);
    temp1 = AES_128_ASSIST(temp1, temp2);
    _mm_storeu_si128(&Key_Schedule[8], temp1);
    temp2 = _mm_aeskeygenassist_si128 (temp1,0x1b);
    temp1 = AES_128_ASSIST(temp1, temp2);
    _mm_storeu_si128(&Key_Schedule[9], temp1);
    temp2 = _mm_aeskeygenassist_si128 (temp1,0x36);
    temp1 = AES_128_ASSIST(temp1, temp2);
    _mm_storeu_si128(&Key_Schedule[10], temp1);
}

// Assembly:
vmovdqu (%rdi), %xmm0
vaeskeygenassist $0x1, %xmm0, %xmm1
vmovdqu %xmm0, (%rsi)
vpshufd $0xff, %xmm1, %xmm1     # xmm1 = xmm1[3,3,3,3]
vpslldq $0x4, %xmm0, %xmm2      # xmm2 = zero,zero,zero,zero,xmm0[0,1,2,3,4,5,6,7,8,9,10,11]
vpslldq $0x8, %xmm0, %xmm3      # xmm3 = zero,zero,zero,zero,zero,zero,zero,zero,xmm0[0,1,2,3,4,5,6,7]
vpslldq $0xc, %xmm0, %xmm4      # xmm4 = zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,xmm0[0,1,2,3]
vpternlogq $0x96, %xmm3, %xmm2, %xmm4
vpternlogq $0x96, %xmm1, %xmm0, %xmm4
vmovdqu %xmm4, 0x10(%rsi)
vaeskeygenassist $0x2, %xmm4, %xmm0
vpshufd $0xff, %xmm0, %xmm0     # xmm0 = xmm0[3,3,3,3]
vpslldq $0x4, %xmm4, %xmm1      # xmm1 = zero,zero,zero,zero,xmm4[0,1,2,3,4,5,6,7,8,9,10,11]
vpslldq $0x8, %xmm4, %xmm2      # xmm2 = zero,zero,zero,zero,zero,zero,zero,zero,xmm4[0,1,2,3,4,5,6,7]
vpslldq $0xc, %xmm4, %xmm3      # xmm3 = zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,xmm4[0,1,2,3]
vpternlogq $0x96, %xmm2, %xmm1, %xmm3
vpternlogq $0x96, %xmm0, %xmm4, %xmm3
vaeskeygenassist $0x4, %xmm3, %xmm0
vpshufd $0xff, %xmm0, %xmm0     # xmm0 = xmm0[3,3,3,3]
vpslldq $0x4, %xmm3, %xmm1      # xmm1 = zero,zero,zero,zero,xmm3[0,1,2,3,4,5,6,7,8,9,10,11]
vpslldq $0x8, %xmm3, %xmm2      # xmm2 = zero,zero,zero,zero,zero,zero,zero,zero,xmm3[0,1,2,3,4,5,6,7]
vpslldq $0xc, %xmm3, %xmm4      # xmm4 = zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,xmm3[0,1,2,3]
vpternlogq $0x96, %xmm2, %xmm1, %xmm4
vpternlogq $0x96, %xmm0, %xmm3, %xmm4
vaeskeygenassist $0x8, %xmm4, %xmm0
vmovdqu %xmm3, 0x20(%rsi)
vmovdqu %xmm4, 0x30(%rsi)
vpshufd $0xff, %xmm0, %xmm0     # xmm0 = xmm0[3,3,3,3]
vpslldq $0x4, %xmm4, %xmm1      # xmm1 = zero,zero,zero,zero,xmm4[0,1,2,3,4,5,6,7,8,9,10,11]
vpslldq $0x8, %xmm4, %xmm2      # xmm2 = zero,zero,zero,zero,zero,zero,zero,zero,xmm4[0,1,2,3,4,5,6,7]
vpslldq $0xc, %xmm4, %xmm3      # xmm3 = zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,xmm4[0,1,2,3]
vpternlogq $0x96, %xmm2, %xmm1, %xmm3
vpternlogq $0x96, %xmm0, %xmm4, %xmm3
vmovdqu %xmm3, 0x40(%rsi)
vaeskeygenassist $0x10, %xmm3, %xmm0
vpshufd $0xff, %xmm0, %xmm0     # xmm0 = xmm0[3,3,3,3]
vpslldq $0x4, %xmm3, %xmm1      # xmm1 = zero,zero,zero,zero,xmm3[0,1,2,3,4,5,6,7,8,9,10,11]
vpslldq $0x8, %xmm3, %xmm2      # xmm2 = zero,zero,zero,zero,zero,zero,zero,zero,xmm3[0,1,2,3,4,5,6,7]
vpslldq $0xc, %xmm3, %xmm4      # xmm4 = zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,xmm3[0,1,2,3]
vpternlogq $0x96, %xmm2, %xmm1, %xmm4
vpternlogq $0x96, %xmm0, %xmm3, %xmm4
vaeskeygenassist $0x20, %xmm4, %xmm0
vpshufd $0xff, %xmm0, %xmm0     # xmm0 = xmm0[3,3,3,3]
vpslldq $0x4, %xmm4, %xmm1      # xmm1 = zero,zero,zero,zero,xmm4[0,1,2,3,4,5,6,7,8,9,10,11]
vpslldq $0x8, %xmm4, %xmm2      # xmm2 = zero,zero,zero,zero,zero,zero,zero,zero,xmm4[0,1,2,3,4,5,6,7]
vpslldq $0xc, %xmm4, %xmm3      # xmm3 = zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,xmm4[0,1,2,3]
vpternlogq $0x96, %xmm2, %xmm1, %xmm3
vpternlogq $0x96, %xmm0, %xmm4, %xmm3
vaeskeygenassist $0x40, %xmm3, %xmm0
vmovdqu %xmm4, 0x50(%rsi)
vmovdqu %xmm3, 0x60(%rsi)
vpshufd $0xff, %xmm0, %xmm0     # xmm0 = xmm0[3,3,3,3]
vpslldq $0x4, %xmm3, %xmm1      # xmm1 = zero,zero,zero,zero,xmm3[0,1,2,3,4,5,6,7,8,9,10,11]
vpslldq $0x8, %xmm3, %xmm2      # xmm2 = zero,zero,zero,zero,zero,zero,zero,zero,xmm3[0,1,2,3,4,5,6,7]
vpslldq $0xc, %xmm3, %xmm4      # xmm4 = zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,xmm3[0,1,2,3]
vpternlogq $0x96, %xmm2, %xmm1, %xmm4
vpternlogq $0x96, %xmm0, %xmm3, %xmm4
vmovdqu %xmm4, 0x70(%rsi)
vaeskeygenassist $0x80, %xmm4, %xmm0
vpshufd $0xff, %xmm0, %xmm0     # xmm0 = xmm0[3,3,3,3]
vpslldq $0x4, %xmm4, %xmm1      # xmm1 = zero,zero,zero,zero,xmm4[0,1,2,3,4,5,6,7,8,9,10,11]
vpslldq $0x8, %xmm4, %xmm2      # xmm2 = zero,zero,zero,zero,zero,zero,zero,zero,xmm4[0,1,2,3,4,5,6,7]
vpslldq $0xc, %xmm4, %xmm3      # xmm3 = zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,xmm4[0,1,2,3]
vpternlogq $0x96, %xmm2, %xmm1, %xmm3
vpternlogq $0x96, %xmm0, %xmm4, %xmm3
vaeskeygenassist $0x1b, %xmm3, %xmm0
vpshufd $0xff, %xmm0, %xmm0     # xmm0 = xmm0[3,3,3,3]
vpslldq $0x4, %xmm3, %xmm1      # xmm1 = zero,zero,zero,zero,xmm3[0,1,2,3,4,5,6,7,8,9,10,11]
vpslldq $0x8, %xmm3, %xmm2      # xmm2 = zero,zero,zero,zero,zero,zero,zero,zero,xmm3[0,1,2,3,4,5,6,7]
vpslldq $0xc, %xmm3, %xmm4      # xmm4 = zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,xmm3[0,1,2,3]
vpternlogq $0x96, %xmm2, %xmm1, %xmm4
vpternlogq $0x96, %xmm0, %xmm3, %xmm4
vaeskeygenassist $0x36, %xmm4, %xmm0
vmovdqu %xmm3, 0x80(%rsi)
vmovdqu %xmm4, 0x90(%rsi)
vpshufd $0xff, %xmm0, %xmm0     # xmm0 = xmm0[3,3,3,3]
vpslldq $0x4, %xmm4, %xmm1      # xmm1 = zero,zero,zero,zero,xmm4[0,1,2,3,4,5,6,7,8,9,10,11]
vpslldq $0x8, %xmm4, %xmm2      # xmm2 = zero,zero,zero,zero,zero,zero,zero,zero,xmm4[0,1,2,3,4,5,6,7]
vpslldq $0xc, %xmm4, %xmm3      # xmm3 = zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,xmm4[0,1,2,3]
vpternlogq $0x96, %xmm2, %xmm1, %xmm3
vpternlogq $0x96, %xmm0, %xmm4, %xmm3
vmovdqu %xmm3, 0xa0(%rsi)
retq