// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/acorn128v2/opt/encrypt.c
// Function: decrypt_8bits
void decrypt_8bits(unsigned long long *state, unsigned int *plaintextword, unsigned int ciphertextword, unsigned int *ks, unsigned int ca, unsigned int cb)
{
    unsigned long long f;
    unsigned long long word_244, word_23, word_160, word_111, word_66, word_196, word_0, word_107, word_230;
    unsigned long long word_12,word_154,word_235,word_61,word_193;

    //f  = state[0] ^ (state[107] ^ 1) ^ maj(state[244], state[23], state[160]) ^ ch(state[230], state[111], state[66]) ^ (ca & state[196]) ^ (cb & (*ks));

    word_12  = state[0] >> 12;
    word_235 = state[5] >> 5;
    word_244 = state[5] >> 14;
    word_23  = state[0] >> 23;
    word_160 = state[3] >> 6;
    word_111 = state[2] >> 4;
    word_66  = state[1] >> 5;
    word_196 = state[4] >> 3;

	state[6] ^= (state[5] ^ word_235) & 0xff;
	state[5] ^= (state[4] ^ word_196) & 0xff;
	state[4] ^= (state[3] ^ word_160) & 0xff;
	state[3] ^= (state[2] ^ word_111) & 0xff;
	state[2] ^= (state[1] ^ word_66)  & 0xff;
	state[1] ^= (state[0] ^ word_23)  & 0xff;

    word_0   = state[0];
    word_107 = state[2];
    word_230 = state[5];
    word_154 = state[3];
    word_61  = state[1];
    word_193 = state[4];

	*ks = word_12 ^ state[3] ^ maj(word_235, state[1], state[4]);
    *ks &= 0xff;
    //f  = state[0] ^ (state[107] ^ 1) ^ maj(state[244], state[23], state[160]) ^ ch(state[230], state[111], state[66]) ^ state[196];
	f = state[0] ^ (state[2] ^ 0xffffffff) ^ maj(word_244, word_23, word_160) ^ ch32(state[5], word_111, word_66) ^ (word_196 & ca) ^ (cb & *ks);
    *plaintextword = ciphertextword ^ *ks;
    f  = (f ^ *plaintextword) & 0xff;
    state[6] =  state[6] ^ (f << 4);

    state[0] = (state[0] >> 8) | ((state[1] & 0xff) << (29+24));   //32-(64-61) = 29
    state[1] = (state[1] >> 8) | ((state[2] & 0xff) << (14+24));   //32-(64-46) = 14
    state[2] = (state[2] >> 8) | ((state[3] & 0xff) << (15+24));   //32-(64-47) = 15
    state[3] = (state[3] >> 8) | ((state[4] & 0xff) << (7+24));    //32-(64-39) = 7
    state[4] = (state[4] >> 8) | ((state[5] & 0xff) << (5+24));    //32-(64-37) = 5
    state[5] = (state[5] >> 8) | ((state[6] & 0xff) << (27+24));    //32-(64-59) = 27
    state[6] =  state[6] >> 8;

    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
vmovdqu (%rdi), %ymm0
movq (%rdi), %rax
movq 0x20(%rdi), %r10
movq %rax, %r11
shrq $0xc, %r11
vpsrlvq 0xa3b(%rip), %ymm0, %ymm2 # 0x2000
vpxor %ymm0, %ymm2, %ymm5
vmovq %xmm2, %r14
vextracti128 $0x1, %ymm2, %xmm4
vpextrq $0x1, %xmm4, %r15
movl %r15d, %ebx
xorl %r14d, %ebx
vmovdqu 0x20(%rdi), %xmm1
andl %r14d, %r15d
movq 0x28(%rdi), %r14
movq %r10, %r12
shrq $0x3, %r12
xorl %r12d, %r10d
andl %r12d, %r8d
xorl %r15d, %r8d
valignq $0x1, %ymm0, %ymm1, %ymm3 # ymm3 = ymm0[1,2,3],ymm1[0]
vpternlogq $0x78, 0xaf2(%rip){1to4}, %ymm5, %ymm3 # 0x2100
vextracti128 $0x1, %ymm3, %xmm5
vpextrq $0x1, %xmm5, %r12
vmovq %xmm3, %r15
movl %r12d, %r13d
xorl %r15d, %r13d
andl %r15d, %r12d
movq %r14, %r15
shrq $0x5, %r15
andl %r15d, %r13d
xorl %r14d, %r15d
xorl %r12d, %r11d
movl $0xff, %ebp
andl %ebp, %r15d
xorq 0x30(%rdi), %r15
xorl %r13d, %r11d
vmovq %xmm5, %r12
xorl %r11d, %r12d
movl %r12d, %r11d
andl %ebp, %r11d
movl %r11d, (%rcx)
andl %ebp, %r10d
xorq %r14, %r10
shrq $0xe, %r14
andl %ebx, %r14d
vmovq %xmm4, %rcx
xorl %r8d, %r14d
vpextrq $0x1, %xmm2, %r8
andl %r10d, %ecx
andnl %r8d, %r10d, %r8d
orl %ecx, %r8d
xorl %r14d, %r8d
andl %r9d, %r12d
xorl %r8d, %r12d
xorl %edx, %r11d
movl %r11d, (%rsi)
xorl %r12d, %r11d
vpextrq $0x1, %xmm3, %rcx
xorl %ecx, %eax
xorl %r11d, %eax
andl %ebp, %eax
shll $0x4, %eax
xorq %r15, %rax
vmovq %r10, %xmm2
vpsrlq $0x8, %ymm0, %ymm0
vpsllvq 0x9ca(%rip), %ymm3, %ymm3 # 0x2080
vpternlogq $0xec, 0x9df(%rip), %ymm0, %ymm3 # 0x20a0
vmovdqu %ymm3, (%rdi)
xorq $0xff0, %rax            # imm = 0xFF0
vpsrlq $0x8, %xmm1, %xmm0
vmovq %rax, %xmm1
vpunpcklqdq %xmm1, %xmm2, %xmm1 # xmm1 = xmm2[0],xmm1[0]
vpsllvq 0x9fe(%rip), %xmm1, %xmm1 # 0x20e0
vpternlogq $0xec, 0xa03(%rip), %xmm0, %xmm1 # 0x20f0
vmovdqu %xmm1, 0x20(%rdi)
shrq $0x8, %rax
movq %rax, 0x30(%rdi)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq