// File: /workspace/github_c_makefile_star2_O1/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 %r14
pushq %rbx
testq %rdi, %rdi
sete %cl
testq %rdx, %rdx
sete %r8b
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
orb %cl, %r8b
jne 0x131b
cmpl $0x80, %esi
je 0x121d
cmpl $0x100, %esi            # imm = 0x100
je 0x121d
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
cmpl $0xc0, %esi
jne 0x131b
cmpl $0x80, %esi
jne 0x1231
movl $0xa, 0xf0(%rdx)
jmp 0x124f
cmpl $0xc0, %esi
jne 0x1245
movl $0xc, 0xf0(%rdx)
jmp 0x124f
movl $0xe, 0xf0(%rdx)
movl (%rdi), %eax
movbel %eax, (%rdx)
movl 0x4(%rdi), %eax
movbel %eax, 0x4(%rdx)
movl 0x8(%rdi), %eax
movbel %eax, 0x8(%rdx)
movl 0xc(%rdi), %eax
movbel %eax, 0xc(%rdx)
cmpl $0x80, %esi
jne 0x1320
xorl %eax, %eax
leaq 0x2d7e(%rip), %rcx      # 0x4000
movl $0xff, %esi
leaq 0x3172(%rip), %rdi      # 0x4400
xorl %r8d, %r8d
movl 0xc(%rdx,%r8,4), %r9d
movl %r9d, %r10d
shrl $0xe, %r10d
andl $0x3fc, %r10d           # imm = 0x3FC
movzbl 0x3(%r10,%rcx), %r10d
shll $0x18, %r10d
xorl (%rdx,%r8,4), %r10d
movl %r9d, %r11d
shrl $0x8, %r11d
andl %esi, %r11d
movzbl 0x2(%rcx,%r11,4), %r11d
shll $0x10, %r11d
movl %r9d, %ebx
andl %esi, %ebx
movzbl 0x1(%rcx,%rbx,4), %ebx
shll $0x8, %ebx
xorl %r11d, %ebx
movl %r9d, %r11d
shrl $0x18, %r11d
movzbl (%rcx,%r11,4), %r11d
xorl %ebx, %r11d
xorl %r10d, %r11d
xorl (%r8,%rdi), %r11d
movl %r11d, 0x10(%rdx,%r8,4)
xorl 0x4(%rdx,%r8,4), %r11d
movl %r11d, 0x14(%rdx,%r8,4)
xorl 0x8(%rdx,%r8,4), %r11d
movl %r11d, 0x18(%rdx,%r8,4)
xorl %r9d, %r11d
movl %r11d, 0x1c(%rdx,%r8,4)
addq $0x4, %r8
cmpq $0x28, %r8
jne 0x1291
popq %rbx
popq %r14
popq %rbp
retq
movl 0x10(%rdi), %eax
movbel %eax, 0x10(%rdx)
movl 0x14(%rdi), %eax
movbel %eax, 0x14(%rdx)
cmpl $0xc0, %esi
jne 0x13f3
addq $0x2c, %rdx
xorl %eax, %eax
leaq 0x2cb7(%rip), %rcx      # 0x4000
movl $0xff, %esi
leaq 0x30ab(%rip), %rdi      # 0x4400
xorl %r8d, %r8d
movl -0x18(%rdx), %r9d
movl %r9d, %r10d
shrl $0xe, %r10d
andl $0x3fc, %r10d           # imm = 0x3FC
movzbl 0x3(%r10,%rcx), %r11d
shll $0x18, %r11d
xorl -0x2c(%rdx), %r11d
movl %r9d, %r10d
shrl $0x8, %r10d
andl %esi, %r10d
movzbl 0x2(%rcx,%r10,4), %r10d
shll $0x10, %r10d
movl %r9d, %ebx
andl %esi, %ebx
movzbl 0x1(%rcx,%rbx,4), %ebx
shll $0x8, %ebx
xorl %r10d, %ebx
movl %r9d, %r10d
shrl $0x18, %r10d
movzbl (%rcx,%r10,4), %r10d
xorl %ebx, %r10d
xorl %r11d, %r10d
xorl (%r8,%rdi), %r10d
movl %r10d, -0x14(%rdx)
xorl -0x28(%rdx), %r10d
movl %r10d, -0x10(%rdx)
xorl -0x24(%rdx), %r10d
movl %r10d, -0xc(%rdx)
xorl -0x20(%rdx), %r10d
movl %r10d, -0x8(%rdx)
cmpq $0x1c, %r8
je 0x131b
xorl -0x1c(%rdx), %r10d
movl %r10d, -0x4(%rdx)
xorl %r9d, %r10d
movl %r10d, (%rdx)
addq $0x4, %r8
addq $0x18, %rdx
jmp 0x1358
movl 0x18(%rdi), %eax
movbel %eax, 0x18(%rdx)
movl 0x1c(%rdi), %eax
movbel %eax, 0x1c(%rdx)
xorl %eax, %eax
cmpl $0x100, %esi            # imm = 0x100
jne 0x131b
xorl %eax, %eax
leaq 0x2be6(%rip), %rcx      # 0x4000
movl $0xff, %esi
leaq 0x2fda(%rip), %rdi      # 0x4400
xorl %r8d, %r8d
movl 0x1c(%rdx,%r8,8), %r9d
movl %r9d, %r10d
shrl $0xe, %r10d
andl $0x3fc, %r10d           # imm = 0x3FC
movzbl 0x3(%r10,%rcx), %r11d
shll $0x18, %r11d
xorl (%rdx,%r8,8), %r11d
movl %r9d, %r10d
shrl $0x8, %r10d
andl %esi, %r10d
movzbl 0x2(%rcx,%r10,4), %r10d
shll $0x10, %r10d
movl %r9d, %ebx
andl %esi, %ebx
movzbl 0x1(%rcx,%rbx,4), %ebx
shll $0x8, %ebx
xorl %r10d, %ebx
movl %r9d, %r10d
shrl $0x18, %r10d
movzbl (%rcx,%r10,4), %r10d
xorl %ebx, %r10d
xorl %r11d, %r10d
xorl (%r8,%rdi), %r10d
movl %r10d, 0x20(%rdx,%r8,8)
xorl 0x4(%rdx,%r8,8), %r10d
movl %r10d, 0x24(%rdx,%r8,8)
xorl 0x8(%rdx,%r8,8), %r10d
movl %r10d, 0x28(%rdx,%r8,8)
xorl 0xc(%rdx,%r8,8), %r10d
movl %r10d, 0x2c(%rdx,%r8,8)
cmpq $0x18, %r8
je 0x131b
movl %r10d, %r11d
shrl $0x18, %r11d
movzbl 0x3(%rcx,%r11,4), %r11d
shll $0x18, %r11d
xorl 0x10(%rdx,%r8,8), %r11d
movl %r10d, %ebx
shrl $0xe, %ebx
andl $0x3fc, %ebx            # imm = 0x3FC
movzbl 0x2(%rbx,%rcx), %ebx
shll $0x10, %ebx
movl %r10d, %r14d
shrl $0x8, %r14d
andl %esi, %r14d
movzbl 0x1(%rcx,%r14,4), %ebp
shll $0x8, %ebp
xorl %ebx, %ebp
andl %esi, %r10d
movzbl (%rcx,%r10,4), %r10d
xorl %ebp, %r10d
xorl %r11d, %r10d
movl %r10d, 0x30(%rdx,%r8,8)
xorl 0x14(%rdx,%r8,8), %r10d
movl %r10d, 0x34(%rdx,%r8,8)
xorl 0x18(%rdx,%r8,8), %r10d
movl %r10d, 0x38(%rdx,%r8,8)
xorl %r9d, %r10d
movl %r10d, 0x3c(%rdx,%r8,8)
addq $0x4, %r8
jmp 0x1429