// File: /workspace/github_cpp_makefile_star2_O2/rellla[P]E3DC-Rscp/AES.cpp
// Function: AES::StartDecryption(unsigned char const*)
void AES::StartDecryption(const unsigned char * key)
	{
	memset(iv, 0xff, sizeof(iv));
	KeyExpansion(key);

	unsigned char a0,a1,a2,a3,b0,b1,b2,b3, * W_ptr = W;

	for (int col = Nb; col < (Nr)*Nb; col++) // do all but first and last round
		{
		a0 = W_ptr[4*col+0];
		a1 = W_ptr[4*col+1];
		a2 = W_ptr[4*col+2];
		a3 = W_ptr[4*col+3];

		b0 = GF2_8_mult(0x0E,a0)^GF2_8_mult(0x0B,a1)^
		     GF2_8_mult(0x0D,a2)^GF2_8_mult(0x09,a3);
		b1 = GF2_8_mult(0x09,a0)^GF2_8_mult(0x0E,a1)^
		     GF2_8_mult(0x0B,a2)^GF2_8_mult(0x0D,a3);
		b2 = GF2_8_mult(0x0D,a0)^GF2_8_mult(0x09,a1)^
		     GF2_8_mult(0x0E,a2)^GF2_8_mult(0x0B,a3);
		b3 = GF2_8_mult(0x0B,a0)^GF2_8_mult(0x0D,a1)^
		     GF2_8_mult(0x09,a2)^GF2_8_mult(0x0E,a3);

		W_ptr[4*col+0] = b0;
		W_ptr[4*col+1] = b1;
		W_ptr[4*col+2] = b2;
		W_ptr[4*col+3] = b3;
		}

	// we reverse the rounds to make decryption faster
	unsigned long * WL = reinterpret_cast<unsigned long*>(W);
	for (int pos = 0; pos < Nr/2; pos++)
		for (int col = 0; col < Nb; col++)
			swap(WL[col+pos*Nb],WL[col+(Nr-pos)*Nb]);
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r14
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x1fc(%rdi)
movdqu %xmm0, 0x1ec(%rdi)
callq 0x52b8
leaq 0xc(%r14), %rbx
movl (%r14), %eax
movslq %eax, %rdx
movq %r14, 0x18(%rsp)
movslq 0x8(%r14), %rcx
movslq %eax, %rsi
movq %rsi, %rax
imulq %rcx, %rax
cmpq %rax, %rdx
jge 0x9dcc
movzbl 0xc(%r14,%rdx,4), %esi
movl %esi, 0x8(%rsp)
movzbl 0xd(%r14,%rdx,4), %r13d
movl %r13d, 0xc(%rsp)
movzbl 0xe(%r14,%rdx,4), %r12d
movl %r12d, 0x14(%rsp)
movzbl 0xf(%r14,%rdx,4), %r15d
movl %r15d, 0x10(%rsp)
pushq $0xe
popq %rdi
movq %rdx, 0x20(%rsp)
callq 0x9e36
movl %eax, %ebp
pushq $0xb
popq %rdi
movl %r13d, %esi
callq 0x9e36
movl %eax, %r13d
xorb %bpl, %r13b
pushq $0xd
popq %rdi
movl %r12d, %esi
callq 0x9e36
movl %eax, %ebp
pushq $0x9
popq %r12
movl %r12d, %edi
movl %r15d, %esi
callq 0x9e36
xorb %bpl, %al
xorb %r13b, %al
movb %al, 0x7(%rsp)
movl %r12d, %edi
movl 0x8(%rsp), %esi
callq 0x9e36
movl %eax, %ebp
pushq $0xe
popq %rdi
movl 0xc(%rsp), %r12d
movl %r12d, %esi
callq 0x9e36
movl %eax, %r14d
xorb %bpl, %r14b
pushq $0xb
popq %rdi
movl 0x14(%rsp), %r15d
movl %r15d, %esi
callq 0x9e36
movb %al, 0x6(%rsp)
pushq $0xd
popq %rdi
movl 0x10(%rsp), %ebp
movl %ebp, %esi
callq 0x9e36
movl %eax, %r13d
xorb 0x6(%rsp), %r13b
xorb %r14b, %r13b
pushq $0xd
popq %rdi
movl 0x8(%rsp), %esi
callq 0x9e36
movb %al, 0x6(%rsp)
pushq $0x9
popq %rdi
movl %r12d, %esi
callq 0x9e36
movl %eax, %r14d
xorb 0x6(%rsp), %r14b
pushq $0xe
popq %rdi
movl %r15d, %esi
callq 0x9e36
movl %eax, %r15d
pushq $0xb
popq %r12
movl %r12d, %edi
movl %ebp, %esi
callq 0x9e36
movl %eax, %ebp
xorb %r15b, %bpl
xorb %r14b, %bpl
movl %r12d, %edi
movl 0x8(%rsp), %esi
callq 0x9e36
movl %eax, %r14d
pushq $0xd
popq %rdi
movl 0xc(%rsp), %esi
callq 0x9e36
movl %eax, %r15d
xorb %r14b, %r15b
pushq $0x9
popq %rdi
movl 0x14(%rsp), %esi
callq 0x9e36
movl %eax, %r14d
pushq $0xe
popq %rdi
movl 0x10(%rsp), %esi
callq 0x9e36
movq 0x20(%rsp), %rdx
xorb %r14b, %al
movq 0x18(%rsp), %r14
xorb %r15b, %al
movb 0x7(%rsp), %cl
movb %cl, 0xc(%r14,%rdx,4)
movb %r13b, 0xd(%r14,%rdx,4)
movb %bpl, 0xe(%r14,%rdx,4)
movb %al, 0xf(%r14,%rdx,4)
incq %rdx
movl (%r14), %eax
jmp 0x9c3d
pushq $0x2
popq %rdi
movl %ecx, %eax
cltd
idivl %edi
xorl %edx, %edx
testl %esi, %esi
movl $0x0, %edi
cmovgl %esi, %edi
testl %eax, %eax
cmovlel %edx, %eax
shlq $0x3, %rsi
imulq %rsi, %rcx
addq %r14, %rcx
addq $0xc, %rcx
movq %rsi, %r8
negq %r8
cmpq %rax, %rdx
je 0x9e27
xorl %r9d, %r9d
cmpq %r9, %rdi
je 0x9e1c
movq (%rbx,%r9,8), %r10
movq (%rcx,%r9,8), %r11
movq %r11, (%rbx,%r9,8)
movq %r10, (%rcx,%r9,8)
incq %r9
jmp 0x9e02
incq %rdx
addq %r8, %rcx
addq %rsi, %rbx
jmp 0x9dfa
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq