// File: /workspace/github_c_makefile_star2_O2/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
xorl %eax, %eax
cmpq $0x10, %rax
je 0x14d3
movzwl (%rdi,%rax), %r8d
movw %r8w, -0x38(%rsp,%rax)
movzwl (%rsi,%rax), %r8d
movw %r8w, -0x18(%rsp,%rax)
movzwl (%rdx,%rax), %r8d
movw %r8w, -0x28(%rsp,%rax)
addq $0x2, %rax
jmp 0x14a6
movl $0xb, %esi
leaq 0xf21(%rip), %r8        # 0x2400
leaq 0x111a(%rip), %r9       # 0x2600
xorl %eax, %eax
testl %esi, %esi
jns 0x14fe
jmp 0x17b2
movzwl -0x18(%rsp,%rax,2), %edx
xorw %dx, -0x38(%rsp,%rax,2)
incq %rax
cmpq $0x8, %rax
jne 0x14f1
movl %esi, %eax
xorl %edx, %edx
movl $0x3, %edi
divl %edi
xorl %eax, %eax
testl %edx, %edx
je 0x1545
cmpl $0x1, %edx
jne 0x156f
cmpq $0x4, %rax
je 0x1780
movzwl -0x20(%rsp,%rax,2), %edx
xorw %dx, -0x38(%rsp,%rax,2)
incq %rax
jmp 0x151a
movzwl -0x20(%rsp,%rax,2), %edx
xorw -0x28(%rsp,%rax,2), %dx
xorw %dx, -0x38(%rsp,%rax,2)
incq %rax
cmpq $0x4, %rax
jne 0x1533
xorl %eax, %eax
cmpq $0x4, %rax
je 0x1575
movzwl -0x28(%rsp,%rax,2), %edx
xorw %dx, -0x30(%rsp,%rax,2)
incq %rax
jmp 0x154d
movzwl -0x28(%rsp,%rax,2), %edx
xorw %dx, -0x38(%rsp,%rax,2)
incq %rax
cmpq $0x8, %rax
jne 0x1562
xorl %eax, %eax
cmpq $0x8, %rax
je 0x159e
movzwl -0x38(%rsp,%rax,2), %edx
movzbl %dl, %r10d
shrl $0x8, %edx
movzwl (%r9,%r10,2), %r10d
xorw (%r8,%rdx,2), %r10w
movw %r10w, -0x38(%rsp,%rax,2)
incq %rax
jmp 0x1577
imull $0x36, %esi, %eax
movl %eax, %edx
addl $0x1b, %edx
movzbl %dl, %r10d
xorw -0x38(%rsp), %r10w
movl -0x34(%rsp), %ebx
movl -0x30(%rsp), %edx
movl %edx, %ebp
andl %ebx, %ebp
xorw -0x36(%rsp), %bp
xorl %r10d, %ebp
xorl %ebp, %edx
movzwl -0x32(%rsp), %r14d
movl %r14d, %r11d
andl %ebp, %r11d
xorl %r10d, %r11d
xorl %r14d, %ebx
movl %r11d, %r10d
andl %edx, %r10d
xorl %r14d, %r10d
xorl %ebx, %ebp
movzwl -0x2e(%rsp), %r15d
movl %r15d, %r12d
xorl %r11d, %r12d
andl %ebp, %r11d
movl -0x2c(%rsp), %r14d
xorl %r14d, %ebp
movzwl -0x2a(%rsp), %r13d
xorl %r13d, %ebx
xorl %r11d, %ebx
andnl %ebx, %ebp, %edi
movl %edi, %r11d
xorl %r12d, %r11d
movw %r11w, -0x2e(%rsp)
andnl %r12d, %ebx, %r11d
xorl %r11d, %r14d
xorl %ebp, %r11d
movw %r11w, -0x2c(%rsp)
andnl %ebp, %r12d, %ebp
xorl %ebp, %ebx
movw %bx, -0x2a(%rsp)
xorl %r15d, %edi
xorl %r13d, %ebp
andnl %ebp, %edx, %r11d
notl %edx
xorl %r11d, %r14d
xorl %r14d, %edi
xorl %edi, %edx
movw %dx, -0x30(%rsp)
movl %edi, %r11d
andl %r10d, %r11d
notl %r10d
xorl %r14d, %r11d
movw %r11w, -0x38(%rsp)
xorl %r10d, %ebp
andl %r11d, %edx
xorl %r10d, %edx
movw %dx, -0x32(%rsp)
xorl %ebp, %edi
movw %di, -0x36(%rsp)
andl %r11d, %edi
xorl %ebp, %edi
movw %di, -0x34(%rsp)
xorl %edx, %edx
cmpq $0x8, %rdx
je 0x16a8
movzwl -0x38(%rsp,%rdx,2), %edi
movzbl %dil, %r10d
shrl $0x8, %edi
movzwl (%r9,%r10,2), %r10d
xorw (%r8,%rdi,2), %r10w
movw %r10w, -0x38(%rsp,%rdx,2)
incq %rdx
jmp 0x1681
andl $0xfe, %eax
xorw -0x38(%rsp), %ax
movl -0x34(%rsp), %r11d
movl -0x30(%rsp), %edx
movl %edx, %ebx
andl %r11d, %ebx
xorw -0x36(%rsp), %bx
xorl %eax, %ebx
xorl %ebx, %edx
movzwl -0x32(%rsp), %edi
movl %edi, %r10d
andl %ebx, %r10d
xorl %eax, %r10d
xorl %edi, %r11d
movl %r10d, %eax
andl %edx, %eax
xorl %edi, %eax
xorl %r11d, %ebx
movzwl -0x2e(%rsp), %r14d
movl %r14d, %r15d
xorl %r10d, %r15d
andl %ebx, %r10d
movl -0x2c(%rsp), %ebp
xorl %ebp, %ebx
movzwl -0x2a(%rsp), %r12d
xorl %r12d, %r11d
xorl %r10d, %r11d
andnl %r11d, %ebx, %r10d
movl %r10d, %edi
xorl %r15d, %edi
movw %di, -0x2e(%rsp)
andnl %r15d, %r11d, %edi
xorl %edi, %ebp
xorl %ebx, %edi
movw %di, -0x2c(%rsp)
andnl %ebx, %r15d, %ebx
xorl %ebx, %r11d
movw %r11w, -0x2a(%rsp)
xorl %r14d, %r10d
xorl %r12d, %ebx
andnl %ebx, %edx, %edi
notl %edx
xorl %edi, %ebp
xorl %ebp, %r10d
xorl %r10d, %edx
movw %dx, -0x30(%rsp)
movl %r10d, %edi
andl %eax, %edi
notl %eax
xorl %ebp, %edi
movw %di, -0x38(%rsp)
xorl %eax, %ebx
andl %edi, %edx
xorl %eax, %edx
movw %dx, -0x32(%rsp)
xorl %ebx, %r10d
movw %r10w, -0x36(%rsp)
andl %edi, %r10d
xorl %ebx, %r10d
movw %r10w, -0x34(%rsp)
decl %esi
jmp 0x14e6
xorl %eax, %eax
cmpq $0x4, %rax
je 0x1575
movzwl -0x28(%rsp,%rax,2), %edx
xorw -0x20(%rsp,%rax,2), %dx
xorw %dx, -0x30(%rsp,%rax,2)
incq %rax
jmp 0x1782
movzwl -0x28(%rsp,%rax,2), %edx
xorw -0x18(%rsp,%rax,2), %dx
xorw %dx, -0x38(%rsp,%rax,2)
incq %rax
cmpq $0x8, %rax
jne 0x17a0
xorl %eax, %eax
cmpq $0x8, %rax
je 0x17ce
movzwl -0x38(%rsp,%rax,2), %edx
movw %dx, (%rcx,%rax,2)
incq %rax
jmp 0x17ba
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)