// File: /workspace/github_cpp_makefile_star2_O3/rellla[P]E3DC-Rscp/AES.cpp
// Function: AES::KeyExpansion(unsigned char const*)
void AES::KeyExpansion(const unsigned char * key)
	{
	int i;
	unsigned long temp, * Wb = reinterpret_cast<unsigned long*>(W); // todo not portable - Endian problems
	if (Nk <= 6)
		{
		// todo - memcpy
		for (i = 0; i < 4*Nk; i++)
			W[i] = key[i];
		for (i = Nk; i < Nb*(Nr+1); i++)
			{
			temp = Wb[i-1];
			if ((i%Nk) == 0)
				temp = SubByte(RotByte(temp)) ^ Rcon[i/Nk];
			Wb[i] = Wb[i - Nk]^temp;
			}
		}
	else
		{
		// todo - memcpy
		for (i = 0; i < 4*Nk; i++)
			W[i] = key[i];
		for (i = Nk; i < Nb*(Nr+1); i++)
			{
			temp = Wb[i-1];
			if ((i%Nk) == 0)
				temp = SubByte(RotByte(temp)) ^ Rcon[i/Nk];
			else if ((i%Nk) == 4)
				temp = SubByte(temp);
			Wb[i] = Wb[i - Nk]^temp;
			}
		}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
leaq 0xc(%rdi), %r8
movslq 0x4(%rdi), %r10
movl %r10d, %r9d
cmpq $0x7, %r10
jge 0x5c4a
testl %r10d, %r10d
jle 0x5ba6
movq %r9, %rax
shlq $0x2, %rax
xorl %ecx, %ecx
movb (%rsi,%rcx), %dl
movb %dl, (%r8,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x5b97
movslq (%rdi), %rax
movslq 0x8(%rdi), %rcx
incq %rcx
imulq %rax, %rcx
cmpl %ecx, %r10d
jge 0x5d60
movq 0x4(%rdi,%r10,8), %rbx
leaq (%r8,%r10,8), %rsi
subq %r10, %rcx
xorl %edi, %edi
leaq 0x15cfe(%rip), %r10     # 0x1b8d0
leaq 0xdb07(%rip), %r11      # 0x136e0
leal (%r9,%rdi), %eax
cltd
idivl %r9d
testl %edx, %edx
jne 0x5c35
movq %rbx, %rdx
shlq $0x18, %rdx
movq %rbx, %r14
shrq $0x8, %r14
orq %r14, %rdx
shrq $0x18, %rdx
movzbl (%rdx,%r10), %edx
movl %ebx, %r15d
shrl $0x18, %r15d
movzbl (%r15,%r10), %ebp
shll $0x10, %edx
shll $0x8, %ebp
orl %edx, %ebp
shrl $0x10, %ebx
movzbl %bl, %edx
movzbl (%rdx,%r10), %edx
orl %ebp, %edx
shll $0x8, %edx
movzbl %r14b, %ebx
movzbl (%rbx,%r10), %ebx
orq %rdx, %rbx
cltq
xorq (%r11,%rax,8), %rbx
xorq (%r8,%rdi,8), %rbx
movq %rbx, (%rsi,%rdi,8)
incq %rdi
cmpq %rdi, %rcx
jne 0x5bd9
jmp 0x5d60
leal (,%r9,4), %ecx
cmpl $0x2, %ecx
movl $0x1, %eax
cmovgel %ecx, %eax
xorl %ecx, %ecx
movb (%rsi,%rcx), %dl
movb %dl, 0xc(%rdi,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x5c5f
movslq (%rdi), %rax
movslq 0x8(%rdi), %r11
incq %r11
imulq %rax, %r11
cmpl %r11d, %r9d
jge 0x5d60
movq 0x4(%rdi,%r9,8), %r15
leaq 0x15c3f(%rip), %rdi     # 0x1b8d0
movl $0xff, %ebx
leaq 0xda43(%rip), %r14      # 0x136e0
movq %r9, %rcx
movl %ecx, %eax
xorl %edx, %edx
divl %r10d
movl %edx, %esi
movl %ecx, %eax
xorl %edx, %edx
divl %r9d
cmpl $0x4, %esi
je 0x5d0f
testl %esi, %esi
jne 0x5d49
movq %r15, %rdx
shlq $0x18, %rdx
movq %r15, %rsi
shrq $0x8, %rsi
orq %rsi, %rdx
shrq $0x18, %rdx
movzbl (%rdx,%rdi), %edx
movl %r15d, %r12d
shrl $0x18, %r12d
movzbl (%r12,%rdi), %ebp
shll $0x10, %edx
shll $0x8, %ebp
orl %edx, %ebp
shrl $0x10, %r15d
movzbl %r15b, %edx
movzbl (%rdx,%rdi), %edx
orl %ebp, %edx
shll $0x8, %edx
movzbl %sil, %esi
movzbl (%rsi,%rdi), %r15d
orq %rdx, %r15
movl %eax, %eax
xorq (%r14,%rax,8), %r15
jmp 0x5d49
movl %r15d, %eax
movl %r15d, %edx
movzbl %r15b, %esi
shrq $0x18, %r15
movzbl (%r15,%rdi), %ebp
shrl $0x10, %eax
andl %ebx, %eax
movzbl (%rax,%rdi), %eax
shll $0x10, %ebp
shll $0x8, %eax
orl %ebp, %eax
shrl $0x8, %edx
andl %ebx, %edx
movzbl (%rdx,%rdi), %edx
orl %eax, %edx
shll $0x8, %edx
movzbl (%rsi,%rdi), %r15d
orq %rdx, %r15
xorq (%r8), %r15
movq %r15, (%r8,%r9,8)
incq %rcx
addq $0x8, %r8
cmpq %rcx, %r11
jne 0x5ca0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop