// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/acorn128v2/opt/encrypt.c
// Function: encrypt_32bits
void encrypt_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;


	word_235 = state[5] >> 5;
	word_196 = state[4] >> 3;
	word_160 = state[3] >> 6;
	word_111 = state[2] >> 4;
	word_66  = state[1] >> 5;
	word_23  = state[0] >> 23;
    word_244 = state[5] >> 14;
	word_12  = state[0] >> 12;

    //update using those 6 LFSRs
	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];
    */

	//compute keystream
	*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]) ^ (ca & state[196]) ^ (cb & (*ks));
	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);
    *ciphertextword = plaintextword ^ *ks;
	f = (f ^ plaintextword) & 0xffffffff;
	state[6] = state[6] ^ (f << 4);

    //shift by 32 bits
    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;

    //perform encryption

    return;
}

// Assembly:
subq $0x20, %rsp
movq %rdi, 0x18(%rsp)
movl %esi, 0x14(%rsp)
movq %rdx, 0x8(%rsp)
movq %rcx, (%rsp)
movl %r8d, -0x4(%rsp)
movl %r9d, -0x8(%rsp)
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
shrq $0x5, %rax
movq %rax, -0x70(%rsp)
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
shrq $0x3, %rax
movq %rax, -0x40(%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 (%rax), %rax
shrq $0x17, %rax
movq %rax, -0x20(%rsp)
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
shrq $0xe, %rax
movq %rax, -0x18(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rax
shrq $0xc, %rax
movq %rax, -0x60(%rsp)
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rcx
xorq -0x70(%rsp), %rcx
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
andq %rax, %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
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
andq %rax, %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
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
andq %rax, %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
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
andq %rax, %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
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
andq %rax, %rcx
movq 0x18(%rsp), %rax
xorq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq 0x18(%rsp), %rax
movq (%rax), %rcx
xorq -0x20(%rsp), %rcx
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
andq %rax, %rcx
movq 0x18(%rsp), %rax
xorq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
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 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 0x14(%rsp), %ecx
movq (%rsp), %rax
xorl (%rax), %ecx
movq 0x8(%rsp), %rax
movl %ecx, (%rax)
movq -0x10(%rsp), %rax
movl 0x14(%rsp), %ecx
xorq %rcx, %rax
movabsq $0xffffffff, %rcx       # imm = 0xFFFFFFFF
andq %rcx, %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 $0x20, %rcx
movq 0x18(%rsp), %rdx
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
andq 0x8(%rdx), %rax
shlq $0x1d, %rax
orq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, (%rax)
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rcx
shrq $0x20, %rcx
movq 0x18(%rsp), %rdx
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
andq 0x10(%rdx), %rax
shlq $0xe, %rax
orq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rcx
shrq $0x20, %rcx
movq 0x18(%rsp), %rdx
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
andq 0x18(%rdx), %rax
shlq $0xf, %rax
orq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rcx
shrq $0x20, %rcx
movq 0x18(%rsp), %rdx
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
andq 0x20(%rdx), %rax
shlq $0x7, %rax
orq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rcx
shrq $0x20, %rcx
movq 0x18(%rsp), %rdx
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
andq 0x28(%rdx), %rax
shlq $0x5, %rax
orq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rcx
shrq $0x20, %rcx
movq 0x18(%rsp), %rdx
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
andq 0x30(%rdx), %rax
shlq $0x1b, %rax
orq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x28(%rax)
movq 0x18(%rsp), %rax
movq 0x30(%rax), %rcx
shrq $0x20, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x30(%rax)
addq $0x20, %rsp
retq
nop