// File: /workspace/github_c_makefile_star2_O1/mjosaarinen[P]brutus/crypto_aead/scream12v2/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] ^= ((27*(2*i)) % 256);
    /* 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] ^= ((27*(2*i+1)) % 256);
    /* 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
vmovd %xmm3, %r9d
movl %r10d, %r8d
andl %r9d, %r8d
vpextrw $0x2, %xmm3, %edi
xorl %r8d, %edi
xorl %edi, %r10d
vpextrw $0x4, %xmm3, %r8d
movl %r8d, %r11d
andl %r9d, %r11d
vpextrw $0x3, %xmm3, %ebx
xorl %r11d, %ebx
xorl %ebx, %edi
movl %ebx, %r15d
andl %r10d, %r15d
xorl %r9d, %r15d
xorl %r10d, %r8d
movl %edi, %r9d
andl %r8d, %r9d
xorl %r10d, %r9d
vpextrw $0x5, %xmm3, %ebp
vpextrw $0x6, %xmm3, %r14d
vpextrw $0x7, %xmm3, %r12d
xorl %r15d, %r9d
andnl %ebp, %r12d, %r10d
andnl %r14d, %ebp, %r11d
movl %ebp, %r13d
xorl %r15d, %r13d
andnl %r12d, %r14d, %ebp
xorl %r9d, %r14d
xorl %r15d, %ebp
xorl %edi, %r11d
movl %r14d, %r15d
andl %r13d, %r15d
xorl %r12d, %edi
xorl %r15d, %edi
xorl %edi, %r14d
andnl %r13d, %r8d, %r15d
notl %r8d
xorl %ebx, %r15d
andnl %r14d, %r15d, %ebx
notl %r15d
xorl %r15d, %edi
xorl %r13d, %ebx
xorl %r14d, %r8d
movl %r8d, %r12d
andl %edi, %r12d
xorl %r14d, %r12d
xorl %ebx, %r12d
movl %eax, %r14d
andl $0xfe, %r14d
xorl %ebx, %r14d
vmovd %r14d, %xmm3
vpinsrw $0x1, %r12d, %xmm3, %xmm3
vpinsrw $0x2, %edi, %xmm3, %xmm3
vpinsrw $0x3, %r15d, %xmm3, %xmm3
vpinsrw $0x4, %r8d, %xmm3, %xmm3
vpinsrw $0x5, %ebp, %xmm3, %xmm3
xorl %r9d, %r10d
vpinsrw $0x6, %r10d, %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
vpextrd $0x2, %xmm4, %edi
vmovd %xmm4, %r8d
vextracti128 $0x1, %ymm4, %xmm4
vmovd %xmm4, %r9d
vpextrd $0x2, %xmm4, %r10d
vmovd %xmm5, %r11d
vpextrd $0x2, %xmm5, %ebx
vextracti128 $0x1, %ymm5, %xmm4
vmovd %xmm4, %r14d
vpextrd $0x2, %xmm4, %r15d
movzwl (%rdx,%r8,2), %r8d
vmovd %r8d, %xmm4
vpinsrw $0x1, (%rdx,%rdi,2), %xmm4, %xmm4
vpinsrw $0x2, (%rdx,%r9,2), %xmm4, %xmm4
vpinsrw $0x3, (%rdx,%r10,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
vmovd %xmm3, %r14d
vpextrd $0x2, %xmm3, %r15d
movzwl (%rsi,%rdi,2), %edi
vmovd %edi, %xmm3
vpinsrw $0x1, (%rsi,%r8,2), %xmm3, %xmm3
vpinsrw $0x2, (%rsi,%r9,2), %xmm3, %xmm3
vpinsrw $0x3, (%rsi,%r10,2), %xmm3, %xmm3
vpinsrw $0x4, (%rsi,%r11,2), %xmm3, %xmm3
vpinsrw $0x5, (%rsi,%rbx,2), %xmm3, %xmm3
vpinsrw $0x6, (%rsi,%r14,2), %xmm3, %xmm3
vpinsrw $0x7, (%rsi,%r15,2), %xmm3, %xmm3
vpxor %xmm4, %xmm3, %xmm3
vpextrw $0x1, %xmm3, %r9d
vmovd %xmm3, %r10d
movl %r9d, %r8d
andl %r10d, %r8d
vpextrw $0x2, %xmm3, %edi
xorl %r8d, %edi
xorl %edi, %r9d
vpextrw $0x4, %xmm3, %r8d
movl %r8d, %ebx
andl %r10d, %ebx
vpextrw $0x3, %xmm3, %r11d
xorl %ebx, %r11d
xorl %r11d, %edi
movl %r11d, %r14d
andl %r9d, %r14d
xorl %r10d, %r14d
xorl %r9d, %r8d
movl %edi, %r15d
andl %r8d, %r15d
xorl %r9d, %r15d
vpextrw $0x5, %xmm3, %ebx
vpextrw $0x6, %xmm3, %ebp
vpextrw $0x7, %xmm3, %r12d
xorl %r14d, %r15d
andnl %ebx, %r12d, %r9d
andnl %ebp, %ebx, %r10d
movl %ebx, %r13d
xorl %r14d, %r13d
andnl %r12d, %ebp, %ebx
xorl %r15d, %ebp
xorl %r14d, %ebx
xorl %r15d, %r9d
xorl %edi, %r10d
movl %ebp, %r14d
andl %r13d, %r14d
xorl %r12d, %edi
xorl %r14d, %edi
xorl %edi, %ebp
andnl %r13d, %r8d, %r14d
notl %r8d
xorl %r11d, %r14d
andnl %ebp, %r14d, %r11d
notl %r14d
xorl %r14d, %edi
xorl %r13d, %r11d
xorl %ebp, %r8d
movl %r8d, %r15d
andl %edi, %r15d
xorl %ebp, %r15d
xorl %r11d, %r15d
leal 0x1b(%rax), %ebp
movzbl %bpl, %ebp
xorl %r11d, %ebp
vmovd %ebp, %xmm3
vpinsrw $0x1, %r15d, %xmm3, %xmm3
vpinsrw $0x2, %edi, %xmm3, %xmm3
vpinsrw $0x3, %r14d, %xmm3, %xmm3
vpinsrw $0x4, %r8d, %xmm3, %xmm3
vpinsrw $0x5, %ebx, %xmm3, %xmm3
vpinsrw $0x6, %r9d, %xmm3, %xmm3
vpinsrw $0x7, %r10d, %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
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 $0x36, %eax
cmpl $0x288, %eax            # imm = 0x288
jne 0x11d0
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 0x15e5
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