// File: /workspace/github_c_makefile_star2_O1/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 0xa0b(%rip), %ymm0, %ymm2 # 0x2000
vpxor %ymm0, %ymm2, %ymm4
vmovdqu 0x20(%rdi), %xmm1
valignq $0x1, %ymm0, %ymm1, %ymm3 # ymm3 = ymm0[1,2,3],ymm1[0]
vpternlogq $0x78, 0xaf0(%rip){1to4}, %ymm4, %ymm3 # 0x2100
vmovq %xmm2, %r14
vextracti128 $0x1, %ymm3, %xmm4
vpextrq $0x1, %xmm4, %r12
vmovq %xmm4, %rbx
vextracti128 $0x1, %ymm2, %xmm4
vpextrq $0x1, %xmm4, %r13
movl %r13d, %r15d
xorl %r14d, %r15d
andl %r14d, %r13d
movq %r10, %r14
shrq $0x3, %r14
xorl %r14d, %r10d
andl %r14d, %r8d
xorl %r13d, %r8d
vmovq %xmm3, %r14
movl %r12d, %ebp
xorl %r14d, %ebp
andl %r14d, %r12d
movq 0x28(%rdi), %r13
xorl %r12d, %r11d
movq %r13, %r14
shrq $0x5, %r14
andl %r14d, %ebp
xorl %r13d, %r14d
xorl %ebp, %r11d
movl $0xff, %ebp
andl %ebp, %r14d
xorq 0x30(%rdi), %r14
movq %r14, 0x30(%rdi)
andl %ebp, %r10d
xorq %r13, %r10
movq %r10, 0x28(%rdi)
vmovdqu %ymm3, 0x8(%rdi)
xorl %r11d, %ebx
movl %ebx, %r11d
andl %ebp, %r11d
movl %r11d, (%rcx)
shrq $0xe, %r13
andl %r15d, %r13d
vmovq %xmm4, %rcx
xorl %r8d, %r13d
vpextrq $0x1, %xmm2, %r8
andl %r10d, %ecx
andnl %r8d, %r10d, %r8d
orl %ecx, %r8d
xorl %r13d, %r8d
andl %r9d, %ebx
xorl %r8d, %ebx
xorl %edx, %r11d
movl %r11d, (%rsi)
xorl %ebx, %r11d
vpextrq $0x1, %xmm3, %rcx
xorl %ecx, %eax
xorl %r11d, %eax
andl %ebp, %eax
shll $0x4, %eax
xorq %r14, %rax
vmovq %r10, %xmm2
vpsrlq $0x8, %ymm0, %ymm0
vpsllvq 0x98d(%rip), %ymm3, %ymm3 # 0x2080
vpternlogq $0xec, 0x9a2(%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 0x9c1(%rip), %xmm1, %xmm1 # 0x20e0
vpternlogq $0xec, 0x9c6(%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