// File: /workspace/github_c_makefile_star2_O1/mjosaarinen[P]brutus/crypto_aead/scream12v2/ref/scream_cipher.c
// Function: LS_decrypt
void LS_decrypt(const crypto_uint8 input[16], const crypto_uint8 key[16], const crypto_uint8 tweak[16],
		crypto_uint8 output[16]) {
  crypto_uint16 data[8];
  crypto_uint16 k[8];
  crypto_uint16 t[8];
  int i,j;

  for (i=0; i<8; i++) {
    data[i] = ((crypto_uint16)input[2*i+1]<<8) + input[2*i];
    k[i] = ((crypto_uint16)  key[2*i+1]<<8) +   key[2*i];
    t[i] = ((crypto_uint16)tweak[2*i+1]<<8) + tweak[2*i];
  }

  /* ---------------- Step Function ---------------- */
  for (i=nSteps-1; i>=0; i--) {
    /* ----------- Key + Tweak Addition ---------- */
    for (j=0; j<8; j++) data[j] ^= k[j];
    switch(i%3) {
    case     0:
      for (j=0; j<4; j++) data[j] ^= t[j] ^ t[j+4];
      for (j=4; j<8; j++) data[j] ^= t[j-4];
      break;
    case     1:
      for (j=0; j<4; j++) data[j] ^= t[j+4];
      for (j=4; j<8; j++) data[j] ^= t[j] ^ t[j-4];
      break;
    case     2:
      for (j=0; j<8; j++) data[j] ^= t[j] ;
      break;
    }

    /* ---------------- Second Round -------------- */
    /* LBox layer (tables) */
    for (j=0; j<8; j++)
      data[j] = LBoxInv2[data[j]>>8] ^ LBoxInv1[data[j]&0xff];
    /* Round constant */
    data[0] ^= ((27*(2*i+1)) % 256);
    /* SBox layer (bitsliced) */
    SBOX_Inv(data);
        
    /* ---------------- First Round ---------------- */
    /* LBox layer (tables) */
    for (j=0; j<8; j++)
      data[j] = LBoxInv2[data[j]>>8] ^ LBoxInv1[data[j]&0xff];
    /* First round constant */
    data[0] ^= ((27*(2*i)) % 256);
    /* SBox layer (bitsliced) */
    SBOX_Inv(data);
  }

  /* Final key + tweak addition */
  for (j=0; j<8; j++) data[j] ^= k[j] ^ t[j];
    
  for (i=0; i<8; i++) {
    output[2*i]   = data[i];
    output[2*i+1] = data[i]>>8;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rcx, -0x8(%rsp)
vmovdqu (%rdi), %xmm5
vpbroadcastw 0x19c9(%rip), %xmm2 # 0x3002
vpternlogd $0xb8, %xmm5, %xmm2, %xmm5
vmovdqu (%rsi), %xmm0
vpternlogd $0xb8, %xmm0, %xmm2, %xmm0
vmovdqu (%rdx), %xmm1
vpternlogd $0xb8, %xmm1, %xmm2, %xmm1
vpshufd $0xee, %xmm1, %xmm2     # xmm2 = xmm1[2,3,2,3]
vpxor %xmm1, %xmm2, %xmm3
movl $0xb, %eax
movl $0x288, %r9d            # imm = 0x288
leaq 0x1d9f(%rip), %rsi      # 0x3410
vpbroadcastd 0x2196(%rip), %ymm4 # 0x3810
leaq 0x1f8f(%rip), %rdi      # 0x3610
movl %eax, %r8d
movl $0xaaaaaaab, %ecx       # imm = 0xAAAAAAAB
imulq %rcx, %r8
shrq $0x21, %r8
leal (%r8,%r8,2), %r10d
vpxor %xmm0, %xmm5, %xmm5
movl %eax, %r8d
subl %r10d, %r8d
je 0x16bd
cmpl $0x1, %r8d
jne 0x16cd
vpxor %xmm2, %xmm5, %xmm6
vpshufd $0xee, %xmm5, %xmm5     # xmm5 = xmm5[2,3,2,3]
vpternlogq $0x96, %xmm2, %xmm1, %xmm5
vpunpcklqdq %xmm5, %xmm6, %xmm5 # xmm5 = xmm6[0],xmm5[0]
jmp 0x16d1
vpunpcklqdq %xmm1, %xmm5, %xmm6 # xmm6 = xmm5[0],xmm1[0]
vpblendd $0xc, %xmm5, %xmm3, %xmm5 # xmm5 = xmm3[0,1],xmm5[2,3]
vpxor %xmm6, %xmm5, %xmm5
jmp 0x16d1
vpxor %xmm1, %xmm5, %xmm5
vpmovzxwd %xmm5, %ymm5    # ymm5 = xmm5[0],zero,xmm5[1],zero,xmm5[2],zero,xmm5[3],zero,xmm5[4],zero,xmm5[5],zero,xmm5[6],zero,xmm5[7],zero
vpsrld $0x8, %ymm5, %ymm6
vextracti128 $0x1, %ymm6, %xmm7
vpmovzxdq %xmm7, %ymm7    # ymm7 = xmm7[0],zero,xmm7[1],zero,xmm7[2],zero,xmm7[3],zero
vpmovzxdq %xmm6, %ymm6    # ymm6 = xmm6[0],zero,xmm6[1],zero,xmm6[2],zero,xmm6[3],zero
vmovd %xmm6, %r8d
vpextrd $0x2, %xmm6, %r10d
vextracti128 $0x1, %ymm6, %xmm6
vpextrd $0x2, %xmm6, %r11d
vmovd %xmm6, %ebx
vmovd %xmm7, %r14d
vpextrd $0x2, %xmm7, %r15d
vextracti128 $0x1, %ymm7, %xmm6
vmovd %xmm6, %r12d
vpextrd $0x2, %xmm6, %r13d
movzwl (%rsi,%r8,2), %r8d
vmovd %r8d, %xmm6
vpinsrw $0x1, (%rsi,%r10,2), %xmm6, %xmm6
vpinsrw $0x2, (%rsi,%rbx,2), %xmm6, %xmm6
vpinsrw $0x3, (%rsi,%r11,2), %xmm6, %xmm6
vpinsrw $0x4, (%rsi,%r14,2), %xmm6, %xmm6
vpinsrw $0x5, (%rsi,%r15,2), %xmm6, %xmm6
vpinsrw $0x6, (%rsi,%r12,2), %xmm6, %xmm6
vpinsrw $0x7, (%rsi,%r13,2), %xmm6, %xmm6
vpand %ymm4, %ymm5, %ymm5
vextracti128 $0x1, %ymm5, %xmm7
vpmovzxdq %xmm7, %ymm7    # ymm7 = xmm7[0],zero,xmm7[1],zero,xmm7[2],zero,xmm7[3],zero
vpmovzxdq %xmm5, %ymm5    # ymm5 = xmm5[0],zero,xmm5[1],zero,xmm5[2],zero,xmm5[3],zero
vmovd %xmm5, %r8d
vpextrd $0x2, %xmm5, %r10d
vextracti128 $0x1, %ymm5, %xmm5
vmovd %xmm5, %r11d
vpextrd $0x2, %xmm5, %ebx
vmovd %xmm7, %r14d
vpextrd $0x2, %xmm7, %r15d
vextracti128 $0x1, %ymm7, %xmm5
vpextrd $0x2, %xmm5, %r12d
movzwl (%rdi,%r8,2), %r8d
vmovd %r8d, %xmm7
vpinsrw $0x1, (%rdi,%r10,2), %xmm7, %xmm7
vpinsrw $0x2, (%rdi,%r11,2), %xmm7, %xmm7
vpinsrw $0x3, (%rdi,%rbx,2), %xmm7, %xmm7
vpinsrw $0x4, (%rdi,%r14,2), %xmm7, %xmm7
vpinsrw $0x5, (%rdi,%r15,2), %xmm7, %xmm7
vmovd %xmm5, %r8d
vpinsrw $0x6, (%rdi,%r8,2), %xmm7, %xmm5
vpinsrw $0x7, (%rdi,%r12,2), %xmm5, %xmm5
vpxor %xmm6, %xmm5, %xmm5
vmovd %xmm5, %r10d
leal -0x36(%r9), %r8d
addl $-0x1b, %r9d
movzbl %r9b, %r11d
vpextrw $0x1, %xmm5, %ebx
xorl %r10d, %r11d
vpextrw $0x2, %xmm5, %r9d
vpextrw $0x4, %xmm5, %r10d
movl %r10d, %ebp
andl %r9d, %ebp
xorl %r11d, %ebx
xorl %ebp, %ebx
xorl %ebx, %r10d
vpextrw $0x3, %xmm5, %ebp
movl %ebp, %r14d
andl %ebx, %r14d
xorl %r11d, %r14d
xorl %ebp, %r9d
movl %r14d, %r11d
andl %r10d, %r11d
xorl %ebp, %r11d
vpextrw $0x5, %xmm5, %r12d
xorl %r9d, %ebx
movl %r12d, %r13d
xorl %r14d, %r13d
andl %ebx, %r14d
vpextrw $0x6, %xmm5, %edx
xorl %edx, %ebx
vpextrw $0x7, %xmm5, %ecx
xorl %ecx, %r9d
xorl %r14d, %r9d
andnl %r9d, %ebx, %r15d
movl %r15d, %ebp
xorl %r13d, %ebp
andnl %r13d, %r9d, %r14d
xorl %r14d, %edx
xorl %ebx, %r14d
andnl %ebx, %r13d, %ebx
xorl %ebx, %r9d
xorl %r12d, %r15d
xorl %ecx, %ebx
andnl %ebx, %r10d, %ecx
notl %r10d
xorl %edx, %ecx
xorl %ecx, %r15d
xorl %r15d, %r10d
movl %r15d, %edx
andl %r11d, %edx
notl %r11d
xorl %ecx, %edx
xorl %r11d, %ebx
movl %edx, %ecx
andl %r10d, %ecx
xorl %r11d, %ecx
xorl %ebx, %r15d
vmovd %edx, %xmm5
andl %r15d, %edx
xorl %ebx, %edx
vpinsrw $0x1, %r15d, %xmm5, %xmm5
vpinsrw $0x2, %edx, %xmm5, %xmm5
vpinsrw $0x3, %ecx, %xmm5, %xmm5
vpinsrw $0x4, %r10d, %xmm5, %xmm5
vpinsrw $0x5, %ebp, %xmm5, %xmm5
vpinsrw $0x6, %r14d, %xmm5, %xmm5
vpinsrw $0x7, %r9d, %xmm5, %xmm5
vpmovzxwd %xmm5, %ymm5    # ymm5 = xmm5[0],zero,xmm5[1],zero,xmm5[2],zero,xmm5[3],zero,xmm5[4],zero,xmm5[5],zero,xmm5[6],zero,xmm5[7],zero
vpsrld $0x8, %ymm5, %ymm6
vextracti128 $0x1, %ymm6, %xmm7
vpmovzxdq %xmm7, %ymm7    # ymm7 = xmm7[0],zero,xmm7[1],zero,xmm7[2],zero,xmm7[3],zero
vpmovzxdq %xmm6, %ymm6    # ymm6 = xmm6[0],zero,xmm6[1],zero,xmm6[2],zero,xmm6[3],zero
vmovd %xmm6, %ecx
vpextrd $0x2, %xmm6, %edx
vextracti128 $0x1, %ymm6, %xmm6
vpextrd $0x2, %xmm6, %r9d
vmovd %xmm6, %r10d
vmovd %xmm7, %r11d
vpextrd $0x2, %xmm7, %ebx
vextracti128 $0x1, %ymm7, %xmm6
vmovd %xmm6, %r14d
vpextrd $0x2, %xmm6, %r15d
movzwl (%rsi,%rcx,2), %ecx
vmovd %ecx, %xmm6
vpinsrw $0x1, (%rsi,%rdx,2), %xmm6, %xmm6
vpinsrw $0x2, (%rsi,%r10,2), %xmm6, %xmm6
vpinsrw $0x3, (%rsi,%r9,2), %xmm6, %xmm6
vpinsrw $0x4, (%rsi,%r11,2), %xmm6, %xmm6
vpinsrw $0x5, (%rsi,%rbx,2), %xmm6, %xmm6
vpinsrw $0x6, (%rsi,%r14,2), %xmm6, %xmm6
vpinsrw $0x7, (%rsi,%r15,2), %xmm6, %xmm6
vpand %ymm4, %ymm5, %ymm5
vextracti128 $0x1, %ymm5, %xmm7
vpmovzxdq %xmm7, %ymm7    # ymm7 = xmm7[0],zero,xmm7[1],zero,xmm7[2],zero,xmm7[3],zero
vpmovzxdq %xmm5, %ymm5    # ymm5 = xmm5[0],zero,xmm5[1],zero,xmm5[2],zero,xmm5[3],zero
vmovd %xmm5, %ecx
vpextrd $0x2, %xmm5, %edx
vextracti128 $0x1, %ymm5, %xmm5
vmovd %xmm5, %r9d
vpextrd $0x2, %xmm5, %r10d
vmovd %xmm7, %r11d
vpextrd $0x2, %xmm7, %ebx
vextracti128 $0x1, %ymm7, %xmm5
vpextrd $0x2, %xmm5, %r14d
movzwl (%rdi,%rcx,2), %ecx
vmovd %ecx, %xmm7
vpinsrw $0x1, (%rdi,%rdx,2), %xmm7, %xmm7
vpinsrw $0x2, (%rdi,%r9,2), %xmm7, %xmm7
vpinsrw $0x3, (%rdi,%r10,2), %xmm7, %xmm7
vpinsrw $0x4, (%rdi,%r11,2), %xmm7, %xmm7
vpinsrw $0x5, (%rdi,%rbx,2), %xmm7, %xmm7
vmovd %xmm5, %ecx
vpinsrw $0x6, (%rdi,%rcx,2), %xmm7, %xmm5
vpinsrw $0x7, (%rdi,%r14,2), %xmm5, %xmm5
vpxor %xmm6, %xmm5, %xmm5
vmovd %xmm5, %ecx
movl %r8d, %edx
andl $0xfe, %edx
vpextrw $0x1, %xmm5, %ebx
vpextrw $0x2, %xmm5, %r9d
xorl %ecx, %edx
vpextrw $0x4, %xmm5, %r10d
movl %r10d, %ecx
andl %r9d, %ecx
xorl %edx, %ebx
xorl %ecx, %ebx
xorl %ebx, %r10d
vpextrw $0x3, %xmm5, %ecx
movl %ecx, %ebp
andl %ebx, %ebp
xorl %edx, %ebp
xorl %ecx, %r9d
movl %ebp, %r11d
andl %r10d, %r11d
xorl %ecx, %r11d
xorl %r9d, %ebx
vpextrw $0x5, %xmm5, %ecx
movl %ecx, %edx
xorl %ebp, %edx
andl %ebx, %ebp
vpextrw $0x6, %xmm5, %r12d
xorl %r12d, %ebx
vpextrw $0x7, %xmm5, %r13d
xorl %r13d, %r9d
xorl %ebp, %r9d
andnl %r9d, %ebx, %r15d
movl %r15d, %ebp
xorl %edx, %ebp
andnl %edx, %r9d, %r14d
xorl %r14d, %r12d
xorl %ebx, %r14d
andnl %ebx, %edx, %ebx
xorl %ebx, %r9d
xorl %ecx, %r15d
xorl %r13d, %ebx
andnl %ebx, %r10d, %ecx
notl %r10d
xorl %r12d, %ecx
xorl %ecx, %r15d
xorl %r15d, %r10d
movl %r15d, %edx
andl %r11d, %edx
notl %r11d
xorl %ecx, %edx
xorl %r11d, %ebx
movl %edx, %ecx
andl %r10d, %ecx
xorl %r11d, %ecx
xorl %ebx, %r15d
vmovd %edx, %xmm5
andl %r15d, %edx
xorl %ebx, %edx
vpinsrw $0x1, %r15d, %xmm5, %xmm5
vpinsrw $0x2, %edx, %xmm5, %xmm5
vpinsrw $0x3, %ecx, %xmm5, %xmm5
vpinsrw $0x4, %r10d, %xmm5, %xmm5
vpinsrw $0x5, %ebp, %xmm5, %xmm5
vpinsrw $0x6, %r14d, %xmm5, %xmm5
vpinsrw $0x7, %r9d, %xmm5, %xmm5
decl %eax
movl %r8d, %r9d
testl %r8d, %r8d
jne 0x1681
vpternlogq $0x96, %xmm0, %xmm1, %xmm5
vpsrlw $0x8, %xmm5, %xmm0
vpunpckhwd %xmm0, %xmm5, %xmm1 # xmm1 = xmm5[4],xmm0[4],xmm5[5],xmm0[5],xmm5[6],xmm0[6],xmm5[7],xmm0[7]
vpunpcklwd %xmm0, %xmm5, %xmm0 # xmm0 = xmm5[0],xmm0[0],xmm5[1],xmm0[1],xmm5[2],xmm0[2],xmm5[3],xmm0[3]
vinserti128 $0x1, %xmm1, %ymm0, %ymm0
movq -0x8(%rsp), %rax
vpmovwb %ymm0, (%rax)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq
nopl (%rax)