// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x20, %rsp
movq %rdi, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movl %edx, 0xc(%rsp)
movq %rcx, (%rsp)
movl %r8d, -0x4(%rsp)
movl %r9d, -0x8(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rax
shrq $0xc, %rax
movq %rax, -0x60(%rsp)
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
shrq $0x5, %rax
movq %rax, -0x70(%rsp)
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
shrq $0xe, %rax
movq %rax, -0x18(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rax
shrq $0x17, %rax
movq %rax, -0x20(%rsp)
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
shrq $0x6, %rax
movq %rax, -0x28(%rsp)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
shrq $0x4, %rax
movq %rax, -0x30(%rsp)
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
shrq $0x5, %rax
movq %rax, -0x38(%rsp)
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
shrq $0x3, %rax
movq %rax, -0x40(%rsp)
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rcx
xorq -0x70(%rsp), %rcx
andq $0xff, %rcx
movq 0x18(%rsp), %rax
xorq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rcx
xorq -0x40(%rsp), %rcx
andq $0xff, %rcx
movq 0x18(%rsp), %rax
xorq 0x28(%rax), %rcx
movq %rcx, 0x28(%rax)
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rcx
xorq -0x28(%rsp), %rcx
andq $0xff, %rcx
movq 0x18(%rsp), %rax
xorq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rcx
xorq -0x30(%rsp), %rcx
andq $0xff, %rcx
movq 0x18(%rsp), %rax
xorq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rcx
xorq -0x38(%rsp), %rcx
andq $0xff, %rcx
movq 0x18(%rsp), %rax
xorq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq 0x18(%rsp), %rax
movq (%rax), %rcx
xorq -0x20(%rsp), %rcx
andq $0xff, %rcx
movq 0x18(%rsp), %rax
xorq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rsp)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rsp)
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x58(%rsp)
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x68(%rsp)
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x78(%rsp)
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x80(%rsp)
movq -0x60(%rsp), %rax
movq 0x18(%rsp), %rcx
xorq 0x18(%rcx), %rax
movq -0x70(%rsp), %rcx
movq 0x18(%rsp), %rdx
andq 0x8(%rdx), %rcx
movq -0x70(%rsp), %rdx
movq 0x18(%rsp), %rsi
andq 0x20(%rsi), %rdx
xorq %rdx, %rcx
movq 0x18(%rsp), %rdx
movq 0x8(%rdx), %rdx
movq 0x18(%rsp), %rsi
andq 0x20(%rsi), %rdx
xorq %rdx, %rcx
xorq %rcx, %rax
movl %eax, %ecx
movq (%rsp), %rax
movl %ecx, (%rax)
movq (%rsp), %rax
movl (%rax), %ecx
andl $0xff, %ecx
movl %ecx, (%rax)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq 0x18(%rsp), %rdx
movabsq $0xffffffff, %rcx       # imm = 0xFFFFFFFF
xorq 0x10(%rdx), %rcx
xorq %rcx, %rax
movq -0x18(%rsp), %rcx
andq -0x20(%rsp), %rcx
movq -0x18(%rsp), %rdx
andq -0x28(%rsp), %rdx
xorq %rdx, %rcx
movq -0x20(%rsp), %rdx
andq -0x28(%rsp), %rdx
xorq %rdx, %rcx
xorq %rcx, %rax
movq 0x18(%rsp), %rcx
movq 0x28(%rcx), %rcx
andq -0x30(%rsp), %rcx
movq 0x18(%rsp), %rdx
movq 0x28(%rdx), %rdx
xorq $-0x1, %rdx
andq -0x38(%rsp), %rdx
xorq %rdx, %rcx
xorq %rcx, %rax
movq -0x40(%rsp), %rcx
movl -0x4(%rsp), %edx
andq %rdx, %rcx
xorq %rcx, %rax
movl -0x8(%rsp), %ecx
movq (%rsp), %rdx
andl (%rdx), %ecx
movl %ecx, %ecx
xorq %rcx, %rax
movq %rax, -0x10(%rsp)
movl 0xc(%rsp), %ecx
movq (%rsp), %rax
xorl (%rax), %ecx
movq 0x10(%rsp), %rax
movl %ecx, (%rax)
movq -0x10(%rsp), %rax
movq 0x10(%rsp), %rcx
movl (%rcx), %ecx
xorq %rcx, %rax
andq $0xff, %rax
movq %rax, -0x10(%rsp)
movq 0x18(%rsp), %rax
movq 0x30(%rax), %rcx
movq -0x10(%rsp), %rax
shlq $0x4, %rax
xorq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x30(%rax)
movq 0x18(%rsp), %rax
movq (%rax), %rcx
shrq $0x8, %rcx
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
andq $0xff, %rax
shlq $0x35, %rax
orq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, (%rax)
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rcx
shrq $0x8, %rcx
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
andq $0xff, %rax
shlq $0x26, %rax
orq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rcx
shrq $0x8, %rcx
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
andq $0xff, %rax
shlq $0x27, %rax
orq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rcx
shrq $0x8, %rcx
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
andq $0xff, %rax
shlq $0x1f, %rax
orq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rcx
shrq $0x8, %rcx
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
andq $0xff, %rax
shlq $0x1d, %rax
orq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rcx
shrq $0x8, %rcx
movq 0x18(%rsp), %rax
movq 0x30(%rax), %rax
andq $0xff, %rax
shlq $0x33, %rax
orq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x28(%rax)
movq 0x18(%rsp), %rax
movq 0x30(%rax), %rcx
shrq $0x8, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x30(%rax)
addq $0x20, %rsp
retq
nop