// File: /workspace/github_c_makefile_star2_O1/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 0x22c0
cmpl $0x100, %edi            # imm = 0x100
je 0x22b4
movl $0x1, %eax
cmpl $0xc0, %edi
jne 0x257a
movq %rdx, -0x18(%rsp)
movl $0xb, %eax
jmp 0x22ca
movq %rdx, -0x18(%rsp)
movl $0xd, %eax
jmp 0x22ca
movq %rdx, -0x18(%rsp)
movl $0x9, %eax
movbel (%rsi), %edi
xorl 0x3f6c(%rip), %edi      # 0x6240
movbel 0x4(%rsi), %ecx
xorl 0x3f65(%rip), %ecx      # 0x6244
movbel 0x8(%rsi), %r8d
xorl 0x3f5c(%rip), %r8d      # 0x6248
movbel 0xc(%rsi), %esi
xorl 0x3f55(%rip), %esi      # 0x624c
movq %rax, %rdx
leal (,%rax,4), %eax
movq %rax, -0x10(%rsp)
shll $0x4, %edx
movq %rdx, -0x8(%rsp)
xorl %r11d, %r11d
movq 0x2cb0(%rip), %rbx      # 0x4fc8
movl $0x3fc, %ebp            # imm = 0x3FC
movq 0x2cb4(%rip), %r14      # 0x4fd8
movl $0xff, %r15d
movq 0x2c57(%rip), %r12      # 0x4f88
movq 0x2c60(%rip), %r13      # 0x4f98
movl %edi, %edx
shrl $0x18, %edx
movl %ecx, %r9d
shrl $0xe, %r9d
andl %ebp, %r9d
movl (%r14,%r9), %r9d
xorl (%rbx,%rdx,4), %r9d
movl %r8d, %edx
shrl $0x8, %edx
andl %r15d, %edx
xorl (%r12,%rdx,4), %r9d
movl %esi, %edx
andl %r15d, %edx
xorl (%r13,%rdx,4), %r9d
movl %ecx, %edx
shrl $0x18, %edx
movl %r8d, %r10d
shrl $0xe, %r10d
andl %ebp, %r10d
movl (%r14,%r10), %r10d
xorl (%rbx,%rdx,4), %r10d
movl %esi, %edx
shrl $0x8, %edx
andl %r15d, %edx
xorl (%r12,%rdx,4), %r10d
movl %edi, %edx
andl %r15d, %edx
xorl (%r13,%rdx,4), %r10d
movl %r8d, %eax
shrl $0x18, %eax
movl %esi, %edx
shrl $0xe, %edx
andl %ebp, %edx
movl (%r14,%rdx), %edx
xorl (%rbx,%rax,4), %edx
movl %edi, %eax
shrl $0x8, %eax
andl %r15d, %eax
xorl (%r12,%rax,4), %edx
movl %ecx, %eax
andl %r15d, %eax
xorl (%r13,%rax,4), %edx
shrl $0x18, %esi
shrl $0xe, %edi
andl %ebp, %edi
movl (%r14,%rdi), %eax
xorl (%rbx,%rsi,4), %eax
shrl $0x8, %ecx
andl %r15d, %ecx
xorl (%r12,%rcx,4), %eax
andl %r15d, %r8d
xorl (%r13,%r8,4), %eax
movl %r9d, %edi
leaq 0x3e58(%rip), %r9       # 0x6240
xorl 0x10(%r11,%r9), %edi
movl %r10d, %ecx
xorl 0x14(%r11,%r9), %ecx
movl %edx, %r8d
xorl 0x18(%r11,%r9), %r8d
movl %eax, %esi
xorl 0x1c(%r11,%r9), %esi
addq $0x10, %r11
cmpl %r11d, -0x8(%rsp)
jne 0x2338
movq -0x10(%rsp), %rbx
leal (,%rbx,4), %eax
movl %edi, %r9d
shrl $0x18, %r9d
movq 0x2bc3(%rip), %r10      # 0x4ff0
leaq 0x3e0c(%rip), %r15      # 0x6240
movl 0x10(%rax,%r15), %edx
movl %edx, %eax
shrl $0x18, %eax
xorb (%r10,%r9), %al
movq -0x18(%rsp), %r14
movb %al, (%r14)
movl %ecx, %eax
shrl $0x10, %eax
movl $0xff, %r11d
andl %r11d, %eax
movl %edx, %r9d
shrl $0x10, %r9d
xorb (%r10,%rax), %r9b
movb %r9b, 0x1(%r14)
movl %r8d, %eax
shrl $0x8, %eax
andl %r11d, %eax
movl %edx, %r9d
shrl $0x8, %r9d
xorb (%r10,%rax), %r9b
movb %r9b, 0x2(%r14)
movl %esi, %eax
andl %r11d, %eax
xorb (%r10,%rax), %dl
movb %dl, 0x3(%r14)
movl %ecx, %eax
shrl $0x18, %eax
leal 0x10(,%rbx,4), %r9d
movl 0x4(%r15,%r9), %edx
movl %edx, %ebx
shrl $0x18, %ebx
xorb (%r10,%rax), %bl
movb %bl, 0x4(%r14)
movl %r8d, %eax
shrl $0x10, %eax
andl %r11d, %eax
movl %edx, %ebx
shrl $0x10, %ebx
xorb (%r10,%rax), %bl
movb %bl, 0x5(%r14)
movl %esi, %eax
shrl $0x8, %eax
andl %r11d, %eax
movl %edx, %ebx
shrl $0x8, %ebx
xorb (%r10,%rax), %bl
movb %bl, 0x6(%r14)
movl %edi, %eax
andl %r11d, %eax
xorb (%r10,%rax), %dl
movb %dl, 0x7(%r14)
movl %r8d, %eax
shrl $0x18, %eax
movl 0x8(%r15,%r9), %edx
movl %edx, %ebx
shrl $0x18, %ebx
xorb (%r10,%rax), %bl
movb %bl, 0x8(%r14)
movl %esi, %eax
shrl $0x10, %eax
andl %r11d, %eax
movl %edx, %ebx
shrl $0x10, %ebx
xorb (%r10,%rax), %bl
movb %bl, 0x9(%r14)
movl %edi, %eax
shrl $0x8, %eax
andl %r11d, %eax
movl %edx, %ebx
shrl $0x8, %ebx
xorb (%r10,%rax), %bl
movb %bl, 0xa(%r14)
movl %ecx, %eax
andl %r11d, %eax
xorb (%r10,%rax), %dl
movb %dl, 0xb(%r14)
shrl $0x18, %esi
movl 0xc(%r15,%r9), %edx
movl %edx, %eax
shrl $0x18, %eax
xorb (%r10,%rsi), %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, %r8d
xorb (%r10,%r8), %dl
movb %dl, 0xf(%r14)
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)