// File: /workspace/github_c_makefile_star2_O1/mjosaarinen[P]brutus/crypto_aead/aes256otrsv3/ref/t-aes_enc_only.c
// Function: KeySchedule
int KeySchedule(int skeylen, int mode, const unsigned char *skey)
{
	int				i;
	int				Nk, Nr;
	unsigned int	tmp;

	/* Set Nk, Nr from skeylen*/
	switch(skeylen)
	{
		case 128:
			Nk = 4;
			Nr = 10;
			break;
		case 192:
			Nk = 6;
			Nr = 12;
			break;
		case 256:
			Nk = 8;
			Nr = 14;
			break;
		default:
			/* key-length error */
			return INVALID_PARAMETER;
	}
	
	/* enc/dec mode error */
	if((mode != ENC) && (mode != DEC))
	{
		return INVALID_PARAMETER;
	}

	/* round-key generation for enc mode */
	for(i=0; i<Nk; i++)
	{
		ekey[i] = (skey[4*i] << 24) | (skey[4*i+1] << 16) | (skey[4*i+2] << 8) | skey[4*i+3];
	}

	for(i=Nk; i<4*(Nr+1); i++)
	{
		if((i % Nk) == 0)
		{
			tmp  = S[(ekey[i-1] >> 16) & 0xff] << 24;
			tmp |= S[(ekey[i-1] >>  8) & 0xff] << 16;
			tmp |= S[ ekey[i-1]        & 0xff] <<  8;
			tmp |= S[ ekey[i-1] >> 24        ];
			ekey[i] = ekey[i-Nk] ^ tmp ^ RC[i/Nk-1];
		}
		else if((Nk == 8) && ((i % Nk) == 4))
		{
			tmp  = S[ ekey[i-1] >> 24        ] << 24;
			tmp |= S[(ekey[i-1] >> 16) & 0xff] << 16;
			tmp |= S[(ekey[i-1] >>  8) & 0xff] <<  8;
			tmp |= S[ ekey[i-1]        & 0xff];
			ekey[i] = ekey[i-Nk] ^ tmp;
		}
		else
		{
			ekey[i] = ekey[i-Nk] ^ ekey[i-1];
		}
	}

	/* round-key generation for dec mode */
	if(mode == DEC)
	{ return INVALID_PARAMETER;
	}

	return SUCCESS;
}

// Assembly:
movl $0x1, %eax
cmpl $0x80, %edi
je 0x213a
cmpl $0x100, %edi            # imm = 0x100
je 0x212a
cmpl $0xc0, %edi
jne 0x227c
movl $0x34, %edi
movl $0x6, %r8d
jmp 0x2145
movl $0x3c, %edi
movl $0x8, %r8d
movb $0x1, %r9b
jmp 0x2148
movl $0x2c, %edi
movl $0x4, %r8d
xorl %r9d, %r9d
cmpl $0x1, %esi
ja 0x227c
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %r8d, %ecx
leal (,%r8,4), %eax
xorl %r11d, %r11d
leaq 0x40d0(%rip), %r10      # 0x6240
movl (%rdx,%r11), %ebx
movbel %ebx, (%r11,%r10)
addq $0x4, %r11
cmpq %r11, %rax
jne 0x2170
movl $0xff, %r11d
movq 0x2e60(%rip), %rbx      # 0x4ff0
movq 0x2e39(%rip), %r14      # 0x4fd0
xorb $0x1, %r9b
movq %r10, %r15
movl %ecx, %eax
xorl %edx, %edx
divl %r8d
testl %edx, %edx
je 0x21fe
cmpl $0x4, %edx
setne %al
orb %r9b, %al
jne 0x224e
movl -0x4(%r10,%rcx,4), %eax
movl %eax, %edx
movl %eax, %r12d
movzbl %al, %r13d
shrl $0x18, %eax
movzbl (%rbx,%rax), %eax
shll $0x18, %eax
shrl $0x10, %edx
andl %r11d, %edx
movzbl (%rbx,%rdx), %edx
shll $0x10, %edx
orl %eax, %edx
shrl $0x8, %r12d
andl %r11d, %r12d
movzbl (%rbx,%r12), %eax
shll $0x8, %eax
orl %edx, %eax
movzbl (%rbx,%r13), %ebp
orl %eax, %ebp
xorl -0x20(%r10,%rcx,4), %ebp
jmp 0x2256
movl -0x4(%r10,%rcx,4), %eax
movl %eax, %edx
shrl $0x10, %edx
andl %r11d, %edx
movzbl (%rbx,%rdx), %edx
shll $0x18, %edx
movl %eax, %r12d
shrl $0x8, %r12d
andl %r11d, %r12d
movzbl (%rbx,%r12), %ebp
shll $0x10, %ebp
orl %edx, %ebp
movzbl %al, %edx
movzbl (%rbx,%rdx), %edx
shll $0x8, %edx
orl %ebp, %edx
shrl $0x18, %eax
movzbl (%rbx,%rax), %ebp
orl %edx, %ebp
xorl (%r15), %ebp
movl %ecx, %eax
xorl %edx, %edx
divl %r8d
cltq
xorl -0x4(%r14,%rax,4), %ebp
jmp 0x2256
movl -0x4(%r10,%rcx,4), %ebp
xorl (%r15), %ebp
movl %ebp, (%r10,%rcx,4)
incq %rcx
addq $0x4, %r15
cmpq %rcx, %rdi
jne 0x219e
xorl %eax, %eax
cmpl $0x1, %esi
sete %al
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq