// File: /workspace/github_c_makefile_star2_O1/mjosaarinen[P]brutus/crypto_aead/scream12v3/ref/scream_cipher.c
// Function: LS_encrypt
void LS_encrypt(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];
  }
    
  /* Initial key + tweak addition */
  for (j=0; j<8; j++) data[j] ^= k[j] ^ t[j];
    
  /* ---------------- Step Function ---------------- */
  for (i=0; i<nSteps; i++) {
        
    /* ---------------- First Round ---------------- */
    /* SBox layer (bitsliced) */
    SBOX(data);
    /* First round constant */
    data[0] ^= ((2199*(2*i)) % 65536);
    /* LBox layer (tables) */
    for (j=0; j<8; j++)
      data[j] = LBox2[data[j]>>8] ^ LBox1[data[j]&0xff];
        
    /* ---------------- Second Round -------------- */
    /* SBox layer (bitsliced) */
    SBOX(data);
    /* Round constant */ 
    data[0] ^= ((2199*(2*i+1)) % 65536);
    /* LBox layer (tables) */
    for (j=0; j<8; j++)
      data[j] = LBox2[data[j]>>8] ^ LBox1[data[j]&0xff];
        
    /* Tweak schedule */
    for (j=0; j<4; j++) {
      t[j]   ^= t[j+4];
      t[j+4] ^= t[j];
    }
    /* ----------- Key + Tweak Addition ---------- */
    for (j=0; j<8; j++) data[j] ^= k[j] ^ t[j];
  }

  /* ----------- Restore initial tweak --------- */
  for (i=nSteps%3; i<3; i++) {
    for (j=0; j<4; j++) {
      t[j]   ^= t[j+4];
      t[j+4] ^= 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
vmovdqu (%rdi), %xmm3
vpbroadcastw 0x1e6d(%rip), %xmm2 # 0x3000
vpternlogd $0xb8, %xmm3, %xmm2, %xmm3
vmovdqu (%rsi), %xmm1
vpternlogd $0xb8, %xmm1, %xmm2, %xmm1
vmovdqu (%rdx), %xmm0
vpternlogd $0xb8, %xmm0, %xmm2, %xmm0
vpternlogq $0x96, %xmm0, %xmm1, %xmm3
xorl %eax, %eax
leaq 0x1e50(%rip), %rdx      # 0x3010
vpbroadcastd 0x2647(%rip), %ymm2 # 0x3810
leaq 0x2040(%rip), %rsi      # 0x3210
vpextrw $0x1, %xmm3, %r10d
vpextrw $0x2, %xmm3, %edi
movl %edi, %r14d
andl %r10d, %r14d
vmovd %xmm3, %r11d
xorl %r11d, %r14d
vpextrw $0x3, %xmm3, %r8d
movl %r8d, %r15d
xorl %r10d, %r15d
movl %r8d, %ebp
andl %r14d, %ebp
xorl %edi, %r14d
vpextrw $0x5, %xmm3, %r9d
vpextrw $0x6, %xmm3, %ebx
xorl %r14d, %r9d
xorl %ebp, %ebx
movl %r15d, %r12d
andl %r14d, %r12d
vpextrw $0x7, %xmm3, %ebp
xorl %r12d, %ebp
xorl %r8d, %r14d
xorl %edi, %r15d
andl %r14d, %r15d
vpextrw $0x4, %xmm3, %r14d
xorl %r15d, %r14d
movl %r14d, %r15d
andl %r9d, %r15d
xorl %ebx, %r15d
xorl %r15d, %r11d
movl %ebx, %r12d
orl %r9d, %r12d
xorl %ebp, %r12d
xorl %r12d, %edi
andl %ebp, %r15d
xorl %r14d, %r10d
xorl %r15d, %r10d
andl %r14d, %r12d
xorl %r9d, %r8d
xorl %r12d, %r8d
movl %r10d, %r12d
andl %edi, %r12d
xorl %r11d, %r12d
andnl %r8d, %r12d, %r15d
notl %r12d
xorl %eax, %r11d
vmovd %r11d, %xmm3
vpinsrw $0x1, %r10d, %xmm3, %xmm3
xorl %r8d, %r10d
xorl %edi, %r12d
xorl %r12d, %r9d
xorl %ebx, %r15d
movl %r12d, %r11d
andl %r10d, %r11d
xorl %ebp, %r11d
xorl %r8d, %r12d
xorl %edi, %r10d
andl %r12d, %r10d
xorl %r14d, %r10d
vpinsrw $0x2, %edi, %xmm3, %xmm3
vpinsrw $0x3, %r8d, %xmm3, %xmm3
vpinsrw $0x4, %r10d, %xmm3, %xmm3
vpinsrw $0x5, %r9d, %xmm3, %xmm3
vpinsrw $0x6, %r15d, %xmm3, %xmm3
vpinsrw $0x7, %r11d, %xmm3, %xmm3
vpmovzxwd %xmm3, %ymm3    # ymm3 = xmm3[0],zero,xmm3[1],zero,xmm3[2],zero,xmm3[3],zero,xmm3[4],zero,xmm3[5],zero,xmm3[6],zero,xmm3[7],zero
vpsrld $0x8, %ymm3, %ymm4
vextracti128 $0x1, %ymm4, %xmm5
vpmovzxdq %xmm5, %ymm5    # ymm5 = xmm5[0],zero,xmm5[1],zero,xmm5[2],zero,xmm5[3],zero
vpmovzxdq %xmm4, %ymm4    # ymm4 = xmm4[0],zero,xmm4[1],zero,xmm4[2],zero,xmm4[3],zero
vmovd %xmm4, %edi
vpextrd $0x2, %xmm4, %r8d
vextracti128 $0x1, %ymm4, %xmm4
vpextrd $0x2, %xmm4, %r9d
vmovd %xmm4, %r10d
vmovd %xmm5, %r11d
vpextrd $0x2, %xmm5, %ebx
vextracti128 $0x1, %ymm5, %xmm4
vmovd %xmm4, %r14d
vpextrd $0x2, %xmm4, %r15d
movzwl (%rdx,%rdi,2), %edi
vmovd %edi, %xmm4
vpinsrw $0x1, (%rdx,%r8,2), %xmm4, %xmm4
vpinsrw $0x2, (%rdx,%r10,2), %xmm4, %xmm4
vpinsrw $0x3, (%rdx,%r9,2), %xmm4, %xmm4
vpinsrw $0x4, (%rdx,%r11,2), %xmm4, %xmm4
vpinsrw $0x5, (%rdx,%rbx,2), %xmm4, %xmm4
vpinsrw $0x6, (%rdx,%r14,2), %xmm4, %xmm4
vpinsrw $0x7, (%rdx,%r15,2), %xmm4, %xmm4
vpand %ymm2, %ymm3, %ymm3
vextracti128 $0x1, %ymm3, %xmm5
vpmovzxdq %xmm5, %ymm5    # ymm5 = xmm5[0],zero,xmm5[1],zero,xmm5[2],zero,xmm5[3],zero
vpmovzxdq %xmm3, %ymm3    # ymm3 = xmm3[0],zero,xmm3[1],zero,xmm3[2],zero,xmm3[3],zero
vmovd %xmm3, %edi
vpextrd $0x2, %xmm3, %r8d
vextracti128 $0x1, %ymm3, %xmm3
vmovd %xmm3, %r9d
vpextrd $0x2, %xmm3, %r10d
vmovd %xmm5, %r11d
vpextrd $0x2, %xmm5, %ebx
vextracti128 $0x1, %ymm5, %xmm3
vpextrd $0x2, %xmm3, %r14d
movzwl (%rsi,%rdi,2), %edi
vmovd %edi, %xmm5
vpinsrw $0x1, (%rsi,%r8,2), %xmm5, %xmm5
vpinsrw $0x2, (%rsi,%r9,2), %xmm5, %xmm5
vpinsrw $0x3, (%rsi,%r10,2), %xmm5, %xmm5
vpinsrw $0x4, (%rsi,%r11,2), %xmm5, %xmm5
vpinsrw $0x5, (%rsi,%rbx,2), %xmm5, %xmm5
vmovd %xmm3, %edi
vpinsrw $0x6, (%rsi,%rdi,2), %xmm5, %xmm3
vpinsrw $0x7, (%rsi,%r14,2), %xmm3, %xmm3
vpxor %xmm4, %xmm3, %xmm3
vpextrw $0x1, %xmm3, %r9d
vpextrw $0x2, %xmm3, %r10d
movl %r10d, %edi
andl %r9d, %edi
vmovd %xmm3, %r14d
xorl %r14d, %edi
vpextrw $0x3, %xmm3, %r11d
movl %r11d, %r8d
xorl %r9d, %r8d
movl %r11d, %ebp
andl %edi, %ebp
xorl %r10d, %edi
vpextrw $0x5, %xmm3, %ebx
xorl %edi, %ebx
vpextrw $0x6, %xmm3, %r15d
xorl %ebp, %r15d
movl %r8d, %r12d
andl %edi, %r12d
vpextrw $0x7, %xmm3, %ebp
xorl %r12d, %ebp
xorl %r11d, %edi
xorl %r10d, %r8d
andl %edi, %r8d
vpextrw $0x4, %xmm3, %r12d
xorl %r8d, %r12d
movl %r12d, %edi
andl %ebx, %edi
xorl %r15d, %edi
xorl %edi, %r14d
movl %r15d, %r8d
orl %ebx, %r8d
xorl %ebp, %r8d
xorl %r8d, %r10d
andl %ebp, %edi
xorl %r12d, %edi
xorl %edi, %r9d
andl %r12d, %r8d
xorl %ebx, %r11d
xorl %r8d, %r11d
movl %r9d, %r8d
leal 0x897(%rax), %r13d
xorl %r14d, %r13d
vmovd %r13d, %xmm3
vpinsrw $0x1, %r9d, %xmm3, %xmm3
andl %r10d, %r9d
xorl %r14d, %r9d
andnl %r11d, %r9d, %r14d
notl %r9d
xorl %r11d, %r8d
movl %r8d, %r13d
xorl %r10d, %r13d
vpinsrw $0x2, %r10d, %xmm3, %xmm3
xorl %r9d, %r10d
xorl %r15d, %r14d
movl %r10d, %r15d
xorl %r11d, %r15d
andl %r15d, %r13d
xorl %r12d, %r13d
vpinsrw $0x3, %r11d, %xmm3, %xmm3
vpinsrw $0x4, %r13d, %xmm3, %xmm3
xorl %r10d, %ebx
vpinsrw $0x5, %ebx, %xmm3, %xmm3
movl %r10d, %r11d
andl %r8d, %r11d
xorl %ebp, %r11d
vpinsrw $0x6, %r14d, %xmm3, %xmm3
vpinsrw $0x7, %r11d, %xmm3, %xmm3
vpmovzxwd %xmm3, %ymm3    # ymm3 = xmm3[0],zero,xmm3[1],zero,xmm3[2],zero,xmm3[3],zero,xmm3[4],zero,xmm3[5],zero,xmm3[6],zero,xmm3[7],zero
vpsrld $0x8, %ymm3, %ymm4
vextracti128 $0x1, %ymm4, %xmm5
vpmovzxdq %xmm4, %ymm4    # ymm4 = xmm4[0],zero,xmm4[1],zero,xmm4[2],zero,xmm4[3],zero
vmovd %xmm4, %r11d
movzwl (%rdx,%r11,2), %r11d
vmovd %r11d, %xmm6
vpextrd $0x2, %xmm4, %r11d
vextracti128 $0x1, %ymm4, %xmm4
vpinsrw $0x1, (%rdx,%r11,2), %xmm6, %xmm6
vmovd %xmm4, %r11d
vpinsrw $0x2, (%rdx,%r11,2), %xmm6, %xmm6
vpextrd $0x2, %xmm4, %r11d
vpinsrw $0x3, (%rdx,%r11,2), %xmm6, %xmm4
vpmovzxdq %xmm5, %ymm5    # ymm5 = xmm5[0],zero,xmm5[1],zero,xmm5[2],zero,xmm5[3],zero
vmovd %xmm5, %r11d
vpinsrw $0x4, (%rdx,%r11,2), %xmm4, %xmm4
vpextrd $0x2, %xmm5, %r11d
vextracti128 $0x1, %ymm5, %xmm5
vpinsrw $0x5, (%rdx,%r11,2), %xmm4, %xmm4
vmovd %xmm5, %r11d
vpinsrw $0x6, (%rdx,%r11,2), %xmm4, %xmm4
vpextrd $0x2, %xmm5, %r11d
vpinsrw $0x7, (%rdx,%r11,2), %xmm4, %xmm4
vpand %ymm2, %ymm3, %ymm3
vpmovzxdq %xmm3, %ymm5    # ymm5 = xmm3[0],zero,xmm3[1],zero,xmm3[2],zero,xmm3[3],zero
vmovd %xmm5, %r11d
movzwl (%rsi,%r11,2), %r11d
vmovd %r11d, %xmm6
vpextrd $0x2, %xmm5, %r11d
vextracti128 $0x1, %ymm5, %xmm5
vpinsrw $0x1, (%rsi,%r11,2), %xmm6, %xmm6
vmovd %xmm5, %r11d
vpinsrw $0x2, (%rsi,%r11,2), %xmm6, %xmm6
vpextrd $0x2, %xmm5, %r11d
vextracti128 $0x1, %ymm3, %xmm3
vpinsrw $0x3, (%rsi,%r11,2), %xmm6, %xmm5
vpmovzxdq %xmm3, %ymm3    # ymm3 = xmm3[0],zero,xmm3[1],zero,xmm3[2],zero,xmm3[3],zero
vmovd %xmm3, %r11d
vpinsrw $0x4, (%rsi,%r11,2), %xmm5, %xmm5
vpextrd $0x2, %xmm3, %r11d
vextracti128 $0x1, %ymm3, %xmm3
vpinsrw $0x5, (%rsi,%r11,2), %xmm5, %xmm5
vmovd %xmm3, %r11d
vpinsrw $0x6, (%rsi,%r11,2), %xmm5, %xmm5
vpextrd $0x2, %xmm3, %r11d
vpinsrw $0x7, (%rsi,%r11,2), %xmm5, %xmm3
vpxor %xmm4, %xmm3, %xmm3
vpshufd $0xee, %xmm0, %xmm4     # xmm4 = xmm0[2,3,2,3]
vpxor %xmm4, %xmm0, %xmm4
vpunpcklqdq %xmm0, %xmm4, %xmm0 # xmm0 = xmm4[0],xmm0[0]
vpternlogq $0x96, %xmm0, %xmm1, %xmm3
addl $0x112e, %eax           # imm = 0x112E
cmpl $0xce28, %eax           # imm = 0xCE28
jne 0x11d0
movq 0x39f7(%rip), %rax      # 0x4ff0
movw %r9w, (%rax)
movq 0x39dc(%rip), %rax      # 0x4fe0
movw %r8w, (%rax)
movq 0x39b1(%rip), %rax      # 0x4fc0
movw %r10w, (%rax)
movq 0x39de(%rip), %rax      # 0x4ff8
movw %di, (%rax)
movl $0x3, %eax
vpshufd $0xee, %xmm0, %xmm1     # xmm1 = xmm0[2,3,2,3]
vpxor %xmm1, %xmm0, %xmm1
vpunpcklqdq %xmm0, %xmm1, %xmm0 # xmm0 = xmm1[0],xmm0[0]
decl %eax
jne 0x1622
vpsrlw $0x8, %xmm3, %xmm0
vpunpckhwd %xmm0, %xmm3, %xmm1 # xmm1 = xmm3[4],xmm0[4],xmm3[5],xmm0[5],xmm3[6],xmm0[6],xmm3[7],xmm0[7]
vpunpcklwd %xmm0, %xmm3, %xmm0 # xmm0 = xmm3[0],xmm0[0],xmm3[1],xmm0[1],xmm3[2],xmm0[2],xmm3[3],xmm0[3]
vinserti128 $0x1, %xmm1, %ymm0, %ymm0
vpmovwb %ymm0, (%rcx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq