// File: /workspace/github_cpp_makefile_star2_O1/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 %rbx
leaq 0xc(%rdi), %r8
movslq 0x4(%rdi), %r9
movl %r9d, %r10d
cmpq $0x7, %r9
jge 0x5eba
testl %r9d, %r9d
jle 0x5e0d
leal (,%r10,4), %eax
xorl %ecx, %ecx
movb (%rsi,%rcx), %dl
movb %dl, (%r8,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x5dfe
movslq (%rdi), %rax
movslq 0x8(%rdi), %rcx
incq %rcx
imulq %rax, %rcx
cmpl %ecx, %r10d
jge 0x5fce
movq 0x4(%rdi,%r9,8), %r14
leaq (%r8,%r9,8), %rsi
subq %r9, %rcx
xorl %edi, %edi
leaq 0x16a97(%rip), %r11     # 0x1c8d0
leaq 0xe8a0(%rip), %rbx      # 0x146e0
leal (%r10,%rdi), %eax
cltd
idivl %r9d
testl %edx, %edx
jne 0x5ea5
movq %r14, %rax
shlq $0x18, %rax
movq %r14, %rdx
shrq $0x8, %rdx
orq %rdx, %rax
shrq $0x18, %rax
movzbl (%rax,%r11), %eax
movl %r14d, %r15d
shrl $0x18, %r15d
movzbl (%r15,%r11), %ebp
shll $0x10, %eax
shll $0x8, %ebp
orl %eax, %ebp
shrl $0x10, %r14d
movzbl %r14b, %eax
movzbl (%rax,%r11), %eax
orl %ebp, %eax
shll $0x8, %eax
movzbl %dl, %edx
movzbl (%rdx,%r11), %r14d
orq %rax, %r14
leal (%r10,%rdi), %eax
cltd
idivl %r10d
cltq
xorq (%rbx,%rax,8), %r14
xorq (%r8,%rdi,8), %r14
movq %r14, (%rsi,%rdi,8)
incq %rdi
cmpq %rdi, %rcx
jne 0x5e40
jmp 0x5fce
leal (,%r10,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 0x5ecf
movslq (%rdi), %rax
movslq 0x8(%rdi), %rsi
incq %rsi
imulq %rax, %rsi
cmpl %esi, %r9d
jge 0x5fce
movq 0x4(%rdi,%r9,8), %r14
leaq 0x169cf(%rip), %rdi     # 0x1c8d0
movl $0xff, %r11d
leaq 0xe7d2(%rip), %rbx      # 0x146e0
movq %r9, %rcx
movl %ecx, %eax
xorl %edx, %edx
divl %r9d
cmpl $0x4, %edx
je 0x5f7b
testl %edx, %edx
jne 0x5fb7
movq %r14, %rax
shlq $0x18, %rax
movq %r14, %rdx
shrq $0x8, %rdx
orq %rdx, %rax
shrq $0x18, %rax
movzbl (%rax,%rdi), %eax
movl %r14d, %r15d
shrl $0x18, %r15d
movzbl (%r15,%rdi), %ebp
shll $0x10, %eax
shll $0x8, %ebp
orl %eax, %ebp
shrl $0x10, %r14d
movzbl %r14b, %eax
movzbl (%rax,%rdi), %eax
orl %ebp, %eax
shll $0x8, %eax
movzbl %dl, %edx
movzbl (%rdx,%rdi), %r14d
orq %rax, %r14
movl %ecx, %eax
xorl %edx, %edx
divl %r10d
xorq (%rbx,%rax,8), %r14
jmp 0x5fb7
movl %r14d, %eax
movl %r14d, %edx
movzbl %r14b, %r15d
shrq $0x18, %r14
movzbl (%r14,%rdi), %ebp
shrl $0x10, %eax
andl %r11d, %eax
movzbl (%rax,%rdi), %eax
shll $0x10, %ebp
shll $0x8, %eax
orl %ebp, %eax
shrl $0x8, %edx
andl %r11d, %edx
movzbl (%rdx,%rdi), %edx
orl %eax, %edx
shll $0x8, %edx
movzbl (%r15,%rdi), %r14d
orq %rdx, %r14
xorq (%r8), %r14
movq %r14, (%r8,%r9,8)
incq %rcx
addq $0x8, %r8
cmpq %rcx, %rsi
jne 0x5f11
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop