// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/aes256otrsv3/ref/t-aes_enc_only.c
// Function: Encryption
int Encryption(int skeylen, unsigned char *plain, unsigned char *cipher)
{
	int				i, j;
	int				Nr;
	unsigned int	tmp_in[4];
	unsigned int	tmp_out[4];
	
	/* Set Nk, Nr from skeylen*/
	switch(skeylen)
	{
		case 128:
			Nr = 10;
			break;
		case 192:
			Nr = 12;
			break;
		case 256:
			Nr = 14;
			break;
		default:
			/* key-length error */
			return INVALID_PARAMETER;
	}
	
	/* round-key index initilization */
	i = 0;

	/* AddRoundKey */
	tmp_in[0] = ((plain[ 0] << 24) | (plain[ 1] << 16) | (plain[ 2] << 8) | plain[ 3]) ^ ekey[i++];
	tmp_in[1] = ((plain[ 4] << 24) | (plain[ 5] << 16) | (plain[ 6] << 8) | plain[ 7]) ^ ekey[i++];
	tmp_in[2] = ((plain[ 8] << 24) | (plain[ 9] << 16) | (plain[10] << 8) | plain[11]) ^ ekey[i++];
	tmp_in[3] = ((plain[12] << 24) | (plain[13] << 16) | (plain[14] << 8) | plain[15]) ^ ekey[i++];
	
	for(j=1; j<=(Nr-1); j++)
	{
		/* SubBytes + ShiftRows + MixColumns */
		tmp_out[0] = T0[tmp_in[0] >> 24] ^ T1[(tmp_in[1] >> 16) & 0xff] ^ T2[(tmp_in[2] >> 8) & 0xff] ^ T3[tmp_in[3] & 0xff];
		tmp_out[1] = T0[tmp_in[1] >> 24] ^ T1[(tmp_in[2] >> 16) & 0xff] ^ T2[(tmp_in[3] >> 8) & 0xff] ^ T3[tmp_in[0] & 0xff];
		tmp_out[2] = T0[tmp_in[2] >> 24] ^ T1[(tmp_in[3] >> 16) & 0xff] ^ T2[(tmp_in[0] >> 8) & 0xff] ^ T3[tmp_in[1] & 0xff];
		tmp_out[3] = T0[tmp_in[3] >> 24] ^ T1[(tmp_in[0] >> 16) & 0xff] ^ T2[(tmp_in[1] >> 8) & 0xff] ^ T3[tmp_in[2] & 0xff];

		/* AddRoundKey */
		tmp_in[0] = tmp_out[0] ^ ekey[i++];
		tmp_in[1] = tmp_out[1] ^ ekey[i++];
		tmp_in[2] = tmp_out[2] ^ ekey[i++];
		tmp_in[3] = tmp_out[3] ^ ekey[i++];
	}

	/* SubBytes + ShiftRows + AddRoundKey */
	cipher[ 0] = S[ tmp_in[0] >> 24        ] ^  (ekey[i  ] >> 24)        ;
	cipher[ 1] = S[(tmp_in[1] >> 16) & 0xff] ^ ((ekey[i  ] >> 16) & 0xff);
	cipher[ 2] = S[(tmp_in[2] >>  8) & 0xff] ^ ((ekey[i  ] >>  8) & 0xff);
	cipher[ 3] = S[ tmp_in[3]        & 0xff] ^ ( ekey[i++]        & 0xff);
	cipher[ 4] = S[ tmp_in[1] >> 24        ] ^  (ekey[i  ] >> 24)        ;
	cipher[ 5] = S[(tmp_in[2] >> 16) & 0xff] ^ ((ekey[i  ] >> 16) & 0xff);
	cipher[ 6] = S[(tmp_in[3] >>  8) & 0xff] ^ ((ekey[i  ] >>  8) & 0xff);
	cipher[ 7] = S[ tmp_in[0]        & 0xff] ^ ( ekey[i++]        & 0xff);
	cipher[ 8] = S[ tmp_in[2] >> 24        ] ^  (ekey[i  ] >> 24)        ;
	cipher[ 9] = S[(tmp_in[3] >> 16) & 0xff] ^ ((ekey[i  ] >> 16) & 0xff);
	cipher[10] = S[(tmp_in[0] >>  8) & 0xff] ^ ((ekey[i  ] >>  8) & 0xff);
	cipher[11] = S[ tmp_in[1]        & 0xff] ^ ( ekey[i++]        & 0xff);
	cipher[12] = S[ tmp_in[3] >> 24        ] ^  (ekey[i  ] >> 24)        ;
	cipher[13] = S[(tmp_in[0] >> 16) & 0xff] ^ ((ekey[i  ] >> 16) & 0xff);
	cipher[14] = S[(tmp_in[1] >>  8) & 0xff] ^ ((ekey[i  ] >>  8) & 0xff);
	cipher[15] = S[ tmp_in[2]        & 0xff] ^ ( ekey[i  ]        & 0xff);

	return SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
cmpl $0x80, %edi
je 0x1f92
cmpl $0x100, %edi            # imm = 0x100
je 0x1f86
cmpl $0xc0, %edi
jne 0x2257
movq %rdx, -0x18(%rsp)
movl $0xb, %edx
jmp 0x1f9c
movq %rdx, -0x18(%rsp)
movl $0xd, %edx
jmp 0x1f9c
movq %rdx, -0x18(%rsp)
movl $0x9, %edx
movbel (%rsi), %edi
xorl 0x429a(%rip), %edi      # 0x6240
movbel 0x4(%rsi), %ecx
xorl 0x4293(%rip), %ecx      # 0x6244
movbel 0x8(%rsi), %ebx
xorl 0x428c(%rip), %ebx      # 0x6248
movbel 0xc(%rsi), %r8d
xorl 0x4283(%rip), %r8d      # 0x624c
leal (,%rdx,4), %eax
movq %rax, -0x10(%rsp)
shll $0x4, %edx
xorl %r11d, %r11d
movl $0xff, %r15d
movq %rdx, -0x8(%rsp)
movl $0x3fc, %r14d           # imm = 0x3FC
movq 0x2fe5(%rip), %r12      # 0x4fd8
movq 0x2fce(%rip), %rbp      # 0x4fc8
movq 0x2f87(%rip), %r13      # 0x4f88
movq 0x2f90(%rip), %rsi      # 0x4f98
cmpl %r11d, %edx
je 0x20f2
movl %edi, %edx
shrl $0x18, %edx
movl %ecx, %r9d
shrl $0xe, %r9d
andl %r14d, %r9d
movl (%r12,%r9), %r9d
xorl (%rbp,%rdx,4), %r9d
movl %ebx, %edx
shrl $0x8, %edx
andl %r15d, %edx
xorl (%r13,%rdx,4), %r9d
movl %r8d, %edx
andl %r15d, %edx
xorl (%rsi,%rdx,4), %r9d
movl %ecx, %edx
shrl $0x18, %edx
movl %ebx, %r10d
shrl $0xe, %r10d
andl %r14d, %r10d
movl (%r12,%r10), %r10d
xorl (%rbp,%rdx,4), %r10d
movl %r8d, %edx
shrl $0x8, %edx
andl %r15d, %edx
xorl (%r13,%rdx,4), %r10d
movl %edi, %edx
andl %r15d, %edx
xorl (%rsi,%rdx,4), %r10d
movl %ebx, %eax
shrl $0x18, %eax
movl %r8d, %edx
shrl $0xe, %edx
andl %r14d, %edx
movl (%r12,%rdx), %edx
xorl (%rbp,%rax,4), %edx
movl %edi, %eax
shrl $0x8, %eax
andl %r15d, %eax
xorl (%r13,%rax,4), %edx
movl %ecx, %eax
andl %r15d, %eax
xorl (%rsi,%rax,4), %edx
shrl $0x18, %r8d
shrl $0xe, %edi
andl %r14d, %edi
movl (%r12,%rdi), %eax
xorl (%rbp,%r8,4), %eax
shrl $0x8, %ecx
andl %r15d, %ecx
xorl (%r13,%rcx,4), %eax
andl %r15d, %ebx
xorl (%rsi,%rbx,4), %eax
leaq 0x417b(%rip), %rcx      # 0x6240
xorl 0x10(%r11,%rcx), %r9d
xorl 0x14(%r11,%rcx), %r10d
xorl 0x18(%r11,%rcx), %edx
xorl 0x1c(%r11,%rcx), %eax
addq $0x10, %r11
movl %eax, %r8d
movl %edx, %ebx
movq -0x8(%rsp), %rdx
movl %r10d, %ecx
movl %r9d, %edi
jmp 0x2008
movq -0x10(%rsp), %r9
leal (,%r9,4), %eax
movl %edi, %esi
shrl $0x18, %esi
movq 0x2ee5(%rip), %r10      # 0x4ff0
leaq 0x412e(%rip), %r15      # 0x6240
movl 0x10(%rax,%r15), %edx
movl %edx, %eax
shrl $0x18, %eax
xorb (%r10,%rsi), %al
movq -0x18(%rsp), %r14
movb %al, (%r14)
movl %ecx, %eax
shrl $0x10, %eax
movl $0xff, %r11d
andl %r11d, %eax
movl %edx, %esi
shrl $0x10, %esi
xorb (%r10,%rax), %sil
movb %sil, 0x1(%r14)
movl %ebx, %eax
shrl $0x8, %eax
andl %r11d, %eax
movl %edx, %esi
shrl $0x8, %esi
xorb (%r10,%rax), %sil
movb %sil, 0x2(%r14)
movl %r8d, %eax
andl %r11d, %eax
xorb (%r10,%rax), %dl
movb %dl, 0x3(%r14)
movl %ecx, %eax
shrl $0x18, %eax
leal 0x10(,%r9,4), %r9d
movl 0x4(%r15,%r9), %edx
movl %edx, %esi
shrl $0x18, %esi
xorb (%r10,%rax), %sil
movb %sil, 0x4(%r14)
movl %ebx, %eax
shrl $0x10, %eax
andl %r11d, %eax
movl %edx, %esi
shrl $0x10, %esi
xorb (%r10,%rax), %sil
movb %sil, 0x5(%r14)
movl %r8d, %eax
shrl $0x8, %eax
andl %r11d, %eax
movl %edx, %esi
shrl $0x8, %esi
xorb (%r10,%rax), %sil
movb %sil, 0x6(%r14)
movl %edi, %eax
andl %r11d, %eax
xorb (%r10,%rax), %dl
movb %dl, 0x7(%r14)
movl %ebx, %eax
shrl $0x18, %eax
movl 0x8(%r15,%r9), %edx
movl %edx, %esi
shrl $0x18, %esi
xorb (%r10,%rax), %sil
movb %sil, 0x8(%r14)
movl %r8d, %eax
shrl $0x10, %eax
andl %r11d, %eax
movl %edx, %esi
shrl $0x10, %esi
xorb (%r10,%rax), %sil
movb %sil, 0x9(%r14)
movl %edi, %eax
shrl $0x8, %eax
andl %r11d, %eax
movl %edx, %esi
shrl $0x8, %esi
xorb (%r10,%rax), %sil
movb %sil, 0xa(%r14)
movl %ecx, %eax
andl %r11d, %eax
xorb (%r10,%rax), %dl
movb %dl, 0xb(%r14)
shrl $0x18, %r8d
movl 0xc(%r15,%r9), %edx
movl %edx, %eax
shrl $0x18, %eax
xorb (%r10,%r8), %al
movb %al, 0xc(%r14)
shrl $0x10, %edi
andl %r11d, %edi
movl %edx, %eax
shrl $0x10, %eax
xorb (%r10,%rdi), %al
movb %al, 0xd(%r14)
shrl $0x8, %ecx
andl %r11d, %ecx
movl %edx, %eax
shrl $0x8, %eax
xorb (%r10,%rcx), %al
movb %al, 0xe(%r14)
andl %r11d, %ebx
xorb (%r10,%rbx), %dl
movb %dl, 0xf(%r14)
xorl %eax, %eax
jmp 0x225c
movl $0x1, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop