// File: /workspace/github_c_makefile_star2_O0/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 %edi, -0x8(%rsp)
movl %esi, -0xc(%rsp)
movq %rdx, -0x18(%rsp)
movl -0x8(%rsp), %eax
movl %eax, -0x2c(%rsp)
subl $0x80, %eax
je 0x22c8
jmp 0x22ae
movl -0x2c(%rsp), %eax
subl $0xc0, %eax
je 0x22da
jmp 0x22bb
movl -0x2c(%rsp), %eax
subl $0x100, %eax            # imm = 0x100
je 0x22ec
jmp 0x22fe
movl $0x4, -0x20(%rsp)
movl $0xa, -0x24(%rsp)
jmp 0x230b
movl $0x6, -0x20(%rsp)
movl $0xc, -0x24(%rsp)
jmp 0x230b
movl $0x8, -0x20(%rsp)
movl $0xe, -0x24(%rsp)
jmp 0x230b
movl $0x1, -0x4(%rsp)
jmp 0x267b
cmpl $0x0, -0xc(%rsp)
je 0x2326
cmpl $0x1, -0xc(%rsp)
je 0x2326
movl $0x1, -0x4(%rsp)
jmp 0x267b
movl $0x0, -0x1c(%rsp)
movl -0x1c(%rsp), %eax
cmpl -0x20(%rsp), %eax
jge 0x23bf
movq -0x18(%rsp), %rax
movl -0x1c(%rsp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %edx
shll $0x18, %edx
movq -0x18(%rsp), %rax
movl -0x1c(%rsp), %ecx
shll $0x2, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x10, %eax
orl %eax, %edx
movq -0x18(%rsp), %rax
movl -0x1c(%rsp), %ecx
shll $0x2, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
orl %eax, %edx
movq -0x18(%rsp), %rax
movl -0x1c(%rsp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
orl %eax, %edx
movslq -0x1c(%rsp), %rcx
leaq 0x4e94(%rip), %rax      # 0x7240
movl %edx, (%rax,%rcx,4)
movl -0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rsp)
jmp 0x232e
movl -0x20(%rsp), %eax
movl %eax, -0x1c(%rsp)
movl -0x1c(%rsp), %eax
movl -0x24(%rsp), %ecx
addl $0x1, %ecx
shll $0x2, %ecx
cmpl %ecx, %eax
jge 0x2662
movl -0x1c(%rsp), %eax
cltd
idivl -0x20(%rsp)
cmpl $0x0, %edx
jne 0x2506
movl -0x1c(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x4e40(%rip), %rax      # 0x7240
movl (%rax,%rcx,4), %eax
shrl $0x10, %eax
andl $0xff, %eax
movl %eax, %eax
movl %eax, %ecx
movq 0x3bda(%rip), %rax      # 0x5ff0
movzbl (%rax,%rcx), %eax
shll $0x18, %eax
movl %eax, -0x28(%rsp)
movl -0x1c(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x4e0e(%rip), %rax      # 0x7240
movl (%rax,%rcx,4), %eax
shrl $0x8, %eax
andl $0xff, %eax
movl %eax, %eax
movl %eax, %ecx
movq 0x3ba8(%rip), %rax      # 0x5ff0
movzbl (%rax,%rcx), %eax
shll $0x10, %eax
orl -0x28(%rsp), %eax
movl %eax, -0x28(%rsp)
movl -0x1c(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x4dd8(%rip), %rax      # 0x7240
movl (%rax,%rcx,4), %eax
andl $0xff, %eax
movl %eax, %eax
movl %eax, %ecx
movq 0x3b75(%rip), %rax      # 0x5ff0
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
orl -0x28(%rsp), %eax
movl %eax, -0x28(%rsp)
movl -0x1c(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x4da5(%rip), %rax      # 0x7240
movl (%rax,%rcx,4), %eax
shrl $0x18, %eax
movl %eax, %eax
movl %eax, %ecx
movq 0x3b44(%rip), %rax      # 0x5ff0
movzbl (%rax,%rcx), %eax
orl -0x28(%rsp), %eax
movl %eax, -0x28(%rsp)
movl -0x1c(%rsp), %eax
subl -0x20(%rsp), %eax
movslq %eax, %rcx
leaq 0x4d76(%rip), %rax      # 0x7240
movl (%rax,%rcx,4), %eax
xorl -0x28(%rsp), %eax
movl %eax, -0x30(%rsp)
movl -0x1c(%rsp), %eax
cltd
idivl -0x20(%rsp)
movl -0x30(%rsp), %edx
subl $0x1, %eax
movslq %eax, %rcx
movq 0x3ae1(%rip), %rax      # 0x5fd0
xorl (%rax,%rcx,4), %edx
movslq -0x1c(%rsp), %rcx
leaq 0x4d42(%rip), %rax      # 0x7240
movl %edx, (%rax,%rcx,4)
jmp 0x2650
cmpl $0x8, -0x20(%rsp)
jne 0x2616
movl -0x1c(%rsp), %eax
cltd
idivl -0x20(%rsp)
cmpl $0x4, %edx
jne 0x2616
movl -0x1c(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x4d0c(%rip), %rax      # 0x7240
movl (%rax,%rcx,4), %eax
shrl $0x18, %eax
movl %eax, %eax
movl %eax, %ecx
movq 0x3aab(%rip), %rax      # 0x5ff0
movzbl (%rax,%rcx), %eax
shll $0x18, %eax
movl %eax, -0x28(%rsp)
movl -0x1c(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x4cdf(%rip), %rax      # 0x7240
movl (%rax,%rcx,4), %eax
shrl $0x10, %eax
andl $0xff, %eax
movl %eax, %eax
movl %eax, %ecx
movq 0x3a79(%rip), %rax      # 0x5ff0
movzbl (%rax,%rcx), %eax
shll $0x10, %eax
orl -0x28(%rsp), %eax
movl %eax, -0x28(%rsp)
movl -0x1c(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x4ca9(%rip), %rax      # 0x7240
movl (%rax,%rcx,4), %eax
shrl $0x8, %eax
andl $0xff, %eax
movl %eax, %eax
movl %eax, %ecx
movq 0x3a43(%rip), %rax      # 0x5ff0
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
orl -0x28(%rsp), %eax
movl %eax, -0x28(%rsp)
movl -0x1c(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x4c73(%rip), %rax      # 0x7240
movl (%rax,%rcx,4), %eax
andl $0xff, %eax
movl %eax, %eax
movl %eax, %ecx
movq 0x3a10(%rip), %rax      # 0x5ff0
movzbl (%rax,%rcx), %eax
orl -0x28(%rsp), %eax
movl %eax, -0x28(%rsp)
movl -0x1c(%rsp), %eax
subl -0x20(%rsp), %eax
movslq %eax, %rcx
leaq 0x4c42(%rip), %rax      # 0x7240
movl (%rax,%rcx,4), %edx
xorl -0x28(%rsp), %edx
movslq -0x1c(%rsp), %rcx
leaq 0x4c2f(%rip), %rax      # 0x7240
movl %edx, (%rax,%rcx,4)
jmp 0x264e
movl -0x1c(%rsp), %eax
subl -0x20(%rsp), %eax
movslq %eax, %rcx
leaq 0x4c18(%rip), %rax      # 0x7240
movl (%rax,%rcx,4), %edx
movl -0x1c(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x4c04(%rip), %rax      # 0x7240
xorl (%rax,%rcx,4), %edx
movslq -0x1c(%rsp), %rcx
leaq 0x4bf5(%rip), %rax      # 0x7240
movl %edx, (%rax,%rcx,4)
jmp 0x2650
jmp 0x2652
movl -0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rsp)
jmp 0x23c7
cmpl $0x1, -0xc(%rsp)
jne 0x2673
movl $0x1, -0x4(%rsp)
jmp 0x267b
movl $0x0, -0x4(%rsp)
movl -0x4(%rsp), %eax
retq