// File: /workspace/github_c_makefile_star2_O1/mjosaarinen[P]brutus/crypto_aead/acorn128v2/opt/encrypt.c
// Function: decrypt_32bits
void decrypt_32bits(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) & 0xffffffff;
	state[5] ^= (state[4] ^ word_196) & 0xffffffff;
	state[4] ^= (state[3] ^ word_160) & 0xffffffff;
	state[3] ^= (state[2] ^ word_111) & 0xffffffff;
	state[2] ^= (state[1] ^ word_66)  & 0xffffffff;
	state[1] ^= (state[0] ^ word_23)  & 0xffffffff;

	/*
    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]);
    //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) & 0xffffffff;
    state[6] =  state[6] ^ (f << 4);

    state[0] = (state[0] >> 32) | ((state[1] & 0xffffffff) << 29);  //32-(64-61) = 29
    state[1] = (state[1] >> 32) | ((state[2] & 0xffffffff) << 14);  //32-(64-46) = 14
    state[2] = (state[2] >> 32) | ((state[3] & 0xffffffff) << 15);  //32-(64-47) = 15
    state[3] = (state[3] >> 32) | ((state[4] & 0xffffffff) << 7);   //32-(64-39) = 7
    state[4] = (state[4] >> 32) | ((state[5] & 0xffffffff) << 5);   //32-(64-37) = 5
    state[5] = (state[5] >> 32) | ((state[6] & 0xffffffff) << 27);  //32-(64-59) = 27
    state[6] =  state[6] >> 32;

    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
vmovdqu (%rdi), %ymm0
movq (%rdi), %r10
movq 0x20(%rdi), %rax
movq %r10, %r11
shrq $0xc, %r11
vpsrlvq 0xb6d(%rip), %ymm0, %ymm2 # 0x2000
vpxor %ymm0, %ymm2, %ymm1
vpxor %xmm3, %xmm3, %xmm3
vpblendd $0xaa, %ymm3, %ymm1, %ymm4 # ymm4 = ymm1[0],ymm3[1],ymm1[2],ymm3[3],ymm1[4],ymm3[5],ymm1[6],ymm3[7]
vmovq %xmm2, %r15
vextracti128 $0x1, %ymm2, %xmm3
vpextrq $0x1, %xmm3, %r14
movl %r14d, %ebx
xorl %r15d, %ebx
andl %r15d, %r14d
vmovdqu 0x20(%rdi), %xmm1
movq %rax, %r15
shrq $0x3, %r15
xorl %r15d, %eax
andl %r15d, %r8d
xorl %r14d, %r8d
valignq $0x1, %ymm0, %ymm1, %ymm5 # ymm5 = ymm0[1,2,3],ymm1[0]
vpxor %ymm5, %ymm4, %ymm4
vextracti128 $0x1, %ymm4, %xmm5
vpextrq $0x1, %xmm5, %r14
vmovq %xmm4, %r15
movl %r14d, %ebp
xorl %r15d, %ebp
andl %r15d, %r14d
movq 0x28(%rdi), %r12
xorl %r14d, %r11d
movq %r12, %r15
shrq $0x5, %r15
andl %r15d, %ebp
xorl %ebp, %r11d
vmovq %xmm5, %r14
xorl %r12d, %r15d
xorq 0x30(%rdi), %r15
xorl %r11d, %r14d
movq %r15, 0x30(%rdi)
xorq %r12, %rax
movq %rax, 0x28(%rdi)
vmovdqu %ymm4, 0x8(%rdi)
movl %r14d, (%rcx)
shrq $0xe, %r12
andl %ebx, %r12d
vpextrq $0x1, %xmm2, %rcx
xorl %r8d, %r12d
vmovq %xmm3, %r8
andl %eax, %r8d
andnl %ecx, %eax, %ecx
orl %r8d, %ecx
vpextrq $0x1, %xmm4, %r8
xorl %ecx, %r8d
xorl %r8d, %r10d
xorl %r12d, %r10d
andl %r14d, %r9d
xorl %r10d, %r9d
xorl %edx, %r14d
movl %r14d, (%rsi)
xorl %r9d, %r14d
notl %r14d
shlq $0x4, %r14
xorq %r15, %r14
vpsrlq $0x20, %ymm0, %ymm0
vpsllvq 0xa9f(%rip), %ymm4, %ymm2 # 0x2020
vpternlogq $0xec, 0xab4(%rip), %ymm0, %ymm2 # 0x2040
vmovdqu %ymm2, (%rdi)
vmovq %rax, %xmm0
vpsrlq $0x20, %xmm1, %xmm1
vmovq %r14, %xmm2
vpunpcklqdq %xmm2, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm2[0]
vpsllvq 0xb14(%rip), %xmm0, %xmm0 # 0x20c0
vpternlogq $0xec, 0xb19(%rip), %xmm1, %xmm0 # 0x20d0
vmovdqu %xmm0, 0x20(%rdi)
shrq $0x20, %r14
movq %r14, 0x30(%rdi)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
vzeroupper
retq