// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/aes128n8t8clocv2/ref/aes_core.c
// Function: AES_set_encrypt_key
int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
			AES_KEY *key) {

	u32 *rk;
   	int i = 0;
	u32 temp;

	if (!userKey || !key)
		return -1;
	if (bits != 128 && bits != 192 && bits != 256)
		return -2;

	rk = (u32*)key->rd_key;

	if (bits==128)
		key->rounds = 10;
	else if (bits==192)
		key->rounds = 12;
	else
		key->rounds = 14;

	rk[0] = GETU32(userKey     );
	rk[1] = GETU32(userKey +  4);
	rk[2] = GETU32(userKey +  8);
	rk[3] = GETU32(userKey + 12);
	if (bits == 128) {
		for (;;) {
			temp  = rk[3];
			rk[4] = rk[0] ^
				(Te4[(temp >> 16) & 0xff] & 0xff000000) ^
				(Te4[(temp >>  8) & 0xff] & 0x00ff0000) ^
				(Te4[(temp      ) & 0xff] & 0x0000ff00) ^
				(Te4[(temp >> 24)       ] & 0x000000ff) ^
				rcon[i];
			rk[5] = rk[1] ^ rk[4];
			rk[6] = rk[2] ^ rk[5];
			rk[7] = rk[3] ^ rk[6];
			if (++i == 10) {
				return 0;
			}
			rk += 4;
		}
	}
	rk[4] = GETU32(userKey + 16);
	rk[5] = GETU32(userKey + 20);
	if (bits == 192) {
		for (;;) {
			temp = rk[ 5];
			rk[ 6] = rk[ 0] ^
				(Te4[(temp >> 16) & 0xff] & 0xff000000) ^
				(Te4[(temp >>  8) & 0xff] & 0x00ff0000) ^
				(Te4[(temp      ) & 0xff] & 0x0000ff00) ^
				(Te4[(temp >> 24)       ] & 0x000000ff) ^
				rcon[i];
			rk[ 7] = rk[ 1] ^ rk[ 6];
			rk[ 8] = rk[ 2] ^ rk[ 7];
			rk[ 9] = rk[ 3] ^ rk[ 8];
			if (++i == 8) {
				return 0;
			}
			rk[10] = rk[ 4] ^ rk[ 9];
			rk[11] = rk[ 5] ^ rk[10];
			rk += 6;
		}
	}
	rk[6] = GETU32(userKey + 24);
	rk[7] = GETU32(userKey + 28);
	if (bits == 256) {
		for (;;) {
			temp = rk[ 7];
			rk[ 8] = rk[ 0] ^
				(Te4[(temp >> 16) & 0xff] & 0xff000000) ^
				(Te4[(temp >>  8) & 0xff] & 0x00ff0000) ^
				(Te4[(temp      ) & 0xff] & 0x0000ff00) ^
				(Te4[(temp >> 24)       ] & 0x000000ff) ^
				rcon[i];
			rk[ 9] = rk[ 1] ^ rk[ 8];
			rk[10] = rk[ 2] ^ rk[ 9];
			rk[11] = rk[ 3] ^ rk[10];
			if (++i == 7) {
				return 0;
			}
			temp = rk[11];
			rk[12] = rk[ 4] ^
				(Te4[(temp >> 24)       ] & 0xff000000) ^
				(Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^
				(Te4[(temp >>  8) & 0xff] & 0x0000ff00) ^
				(Te4[(temp      ) & 0xff] & 0x000000ff);
			rk[13] = rk[ 5] ^ rk[12];
			rk[14] = rk[ 6] ^ rk[13];
			rk[15] = rk[ 7] ^ rk[14];

			rk += 8;
        	}
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
testq %rdi, %rdi
sete %al
testq %rdx, %rdx
sete %cl
orb %al, %cl
jne 0x1221
cmpl $0x80, %esi
je 0x120d
cmpl $0x100, %esi            # imm = 0x100
je 0x120d
cmpl $0xc0, %esi
jne 0x123f
cmpl $0x80, %esi
jne 0x122b
movl $0xa, 0xf0(%rdx)
jmp 0x1253
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x131d
cmpl $0xc0, %esi
jne 0x1249
movl $0xc, 0xf0(%rdx)
jmp 0x1253
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jmp 0x131d
movl $0xe, 0xf0(%rdx)
movl (%rdi), %ecx
movbel %ecx, (%rdx)
movl 0x4(%rdi), %r8d
movbel %r8d, 0x4(%rdx)
movl 0x8(%rdi), %r9d
movbel %r9d, 0x8(%rdx)
bswapl %ecx
movl 0xc(%rdi), %r10d
movbel %r10d, 0xc(%rdx)
cmpl $0x80, %esi
jne 0x1326
xorl %eax, %eax
leaq 0x2d72(%rip), %rsi      # 0x4000
movl $0xff, %edi
leaq 0x3166(%rip), %r8       # 0x4400
xorl %r9d, %r9d
movl 0xc(%rdx,%r9,4), %r10d
movl %r10d, %r11d
shrl $0xe, %r11d
andl $0x3fc, %r11d           # imm = 0x3FC
movzbl 0x3(%r11,%rsi), %r11d
shll $0x18, %r11d
xorl %ecx, %r11d
movl %r10d, %ecx
shrl $0x8, %ecx
andl %edi, %ecx
movzbl 0x2(%rsi,%rcx,4), %ecx
shll $0x10, %ecx
movl %r10d, %ebx
andl %edi, %ebx
movzbl 0x1(%rsi,%rbx,4), %ebx
shll $0x8, %ebx
xorl %ecx, %ebx
xorl %r11d, %ebx
movl %r10d, %ecx
shrl $0x18, %ecx
movzbl (%rsi,%rcx,4), %ecx
xorl %ebx, %ecx
xorl (%r9,%r8), %ecx
movl %ecx, 0x10(%rdx,%r9,4)
movl 0x4(%rdx,%r9,4), %r11d
xorl %ecx, %r11d
movl %r11d, 0x14(%rdx,%r9,4)
xorl 0x8(%rdx,%r9,4), %r11d
movl %r11d, 0x18(%rdx,%r9,4)
xorl %r10d, %r11d
movl %r11d, 0x1c(%rdx,%r9,4)
addq $0x4, %r9
cmpq $0x28, %r9
jne 0x129d
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
bswapl %r8d
bswapl %r9d
movl 0x10(%rdi), %eax
movbel %eax, 0x10(%rdx)
bswapl %r10d
movl 0x14(%rdi), %r11d
movbel %r11d, 0x14(%rdx)
cmpl $0xc0, %esi
jne 0x13fa
bswapl %r11d
addq $0x2c, %rdx
xorl %eax, %eax
leaq 0x2ca3(%rip), %rsi      # 0x4000
movl $0xff, %edi
leaq 0x3097(%rip), %rbx      # 0x4400
xorl %r14d, %r14d
movl %r11d, %r15d
shrl $0xe, %r15d
andl $0x3fc, %r15d           # imm = 0x3FC
movzbl 0x3(%r15,%rsi), %ebp
shll $0x18, %ebp
xorl %ecx, %ebp
movl %r11d, %ecx
shrl $0x8, %ecx
andl %edi, %ecx
movzbl 0x2(%rsi,%rcx,4), %ecx
shll $0x10, %ecx
movl %r11d, %r15d
andl %edi, %r15d
movzbl 0x1(%rsi,%r15,4), %r15d
shll $0x8, %r15d
xorl %ecx, %r15d
xorl %ebp, %r15d
movl %r11d, %ecx
shrl $0x18, %ecx
movzbl (%rsi,%rcx,4), %ecx
xorl %r15d, %ecx
xorl (%r14,%rbx), %ecx
movl %ecx, -0x14(%rdx)
xorl %ecx, %r8d
movl %r8d, -0x10(%rdx)
xorl %r8d, %r9d
movl %r9d, -0xc(%rdx)
xorl %r9d, %r10d
movl %r10d, -0x8(%rdx)
cmpq $0x1c, %r14
je 0x131d
movl -0x1c(%rdx), %ebp
xorl %r10d, %ebp
movl %ebp, -0x4(%rdx)
xorl %ebp, %r11d
movl %r11d, (%rdx)
addq $0x4, %r14
addq $0x18, %rdx
jmp 0x136c
movl 0x18(%rdi), %eax
movbel %eax, 0x18(%rdx)
movl 0x1c(%rdi), %edi
movbel %edi, 0x1c(%rdx)
xorl %eax, %eax
cmpl $0x100, %esi            # imm = 0x100
jne 0x131d
bswapl %edi
xorl %eax, %eax
leaq 0x2bdd(%rip), %rsi      # 0x4000
movl $0xff, %r11d
leaq 0x2fd0(%rip), %rbx      # 0x4400
xorl %r14d, %r14d
movl %edi, %r15d
shrl $0xe, %r15d
andl $0x3fc, %r15d           # imm = 0x3FC
movzbl 0x3(%r15,%rsi), %ebp
shll $0x18, %ebp
xorl %ecx, %ebp
movl %edi, %ecx
shrl $0x8, %ecx
andl %r11d, %ecx
movzbl 0x2(%rsi,%rcx,4), %ecx
shll $0x10, %ecx
movl %edi, %r15d
andl %r11d, %r15d
movzbl 0x1(%rsi,%r15,4), %r15d
shll $0x8, %r15d
xorl %ecx, %r15d
xorl %ebp, %r15d
movl %edi, %ecx
shrl $0x18, %ecx
movzbl (%rsi,%rcx,4), %ecx
xorl %r15d, %ecx
xorl (%r14,%rbx), %ecx
movl %ecx, 0x20(%rdx,%r14,8)
xorl %ecx, %r8d
movl %r8d, 0x24(%rdx,%r14,8)
xorl %r8d, %r9d
movl %r9d, 0x28(%rdx,%r14,8)
xorl %r9d, %r10d
movl %r10d, 0x2c(%rdx,%r14,8)
cmpq $0x18, %r14
je 0x131d
movl %r10d, %r15d
shrl $0x18, %r15d
movzbl 0x3(%rsi,%r15,4), %ebp
shll $0x18, %ebp
xorl 0x10(%rdx,%r14,8), %ebp
movl %r10d, %r15d
shrl $0xe, %r15d
andl $0x3fc, %r15d           # imm = 0x3FC
movzbl 0x2(%r15,%rsi), %r15d
shll $0x10, %r15d
movl %r10d, %r12d
shrl $0x8, %r12d
andl %r11d, %r12d
movzbl 0x1(%rsi,%r12,4), %r12d
shll $0x8, %r12d
xorl %r15d, %r12d
movl %r10d, %r15d
andl %r11d, %r15d
movzbl (%rsi,%r15,4), %r15d
xorl %r12d, %r15d
xorl %ebp, %r15d
movl %r15d, 0x30(%rdx,%r14,8)
xorl 0x14(%rdx,%r14,8), %r15d
movl %r15d, 0x34(%rdx,%r14,8)
xorl 0x18(%rdx,%r14,8), %r15d
movl %r15d, 0x38(%rdx,%r14,8)
xorl %r15d, %edi
movl %edi, 0x3c(%rdx,%r14,8)
addq $0x4, %r14
jmp 0x1433