// File: /workspace/github_cpp_makefile_star2_O2/bummelbaerchen[P]e3dc/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
	uint32_t * WL = reinterpret_cast<uint32_t*>(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, %rbx
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x1fc(%rdi)
movdqu %xmm0, 0x1ec(%rdi)
callq 0x7620
movl (%rbx), %ecx
movslq %ecx, %rsi
movl 0x8(%rbx), %eax
movl %ecx, %edx
imull %eax, %edx
movslq %edx, %rdx
cmpq %rdx, %rsi
jge 0xbfd4
movq %rsi, 0x10(%rsp)
movq 0x10(%rsp), %rax
movzbl 0xc(%rbx,%rax,4), %esi
movl %esi, 0x1c(%rsp)
movq 0x10(%rsp), %rax
movzbl 0xd(%rbx,%rax,4), %r12d
movl %r12d, 0x20(%rsp)
movq 0x10(%rsp), %rax
movzbl 0xe(%rbx,%rax,4), %r15d
movq 0x10(%rsp), %rax
movzbl 0xf(%rbx,%rax,4), %r14d
movl %r14d, 0x18(%rsp)
pushq $0xe
popq %rdi
callq 0xc03a
movl %eax, %ebp
pushq $0xb
popq %rdi
movl %r12d, %esi
callq 0xc03a
movl %eax, %r13d
xorb %bpl, %r13b
pushq $0xd
popq %rdi
movl %r15d, %esi
callq 0xc03a
movl %eax, %ebp
pushq $0x9
popq %r12
movl %r12d, %edi
movl %r14d, %esi
callq 0xc03a
xorb %bpl, %al
xorb %r13b, %al
movb %al, 0xf(%rsp)
movl %r12d, %edi
movl 0x1c(%rsp), %r12d
movl %r12d, %esi
callq 0xc03a
movl %eax, %r13d
pushq $0xe
popq %rdi
movl 0x20(%rsp), %ebp
movl %ebp, %esi
callq 0xc03a
movl %eax, %r14d
xorb %r13b, %r14b
pushq $0xb
popq %rdi
movl %r15d, 0x24(%rsp)
movl %r15d, %esi
callq 0xc03a
movb %al, 0xe(%rsp)
pushq $0xd
popq %rdi
movl 0x18(%rsp), %esi
callq 0xc03a
movl %eax, %r13d
xorb 0xe(%rsp), %r13b
xorb %r14b, %r13b
pushq $0xd
popq %rdi
movl %r12d, %esi
callq 0xc03a
movl %eax, %r12d
pushq $0x9
popq %rdi
movl %ebp, %esi
callq 0xc03a
movl %eax, %r14d
xorb %r12b, %r14b
pushq $0xe
popq %rdi
movl %r15d, %esi
callq 0xc03a
movl %eax, %r15d
pushq $0xb
popq %rdi
movl 0x18(%rsp), %r12d
movl %r12d, %esi
callq 0xc03a
movl %eax, %ebp
xorb %r15b, %bpl
xorb %r14b, %bpl
pushq $0xb
popq %rdi
movl 0x1c(%rsp), %esi
callq 0xc03a
movl %eax, %r14d
pushq $0xd
popq %rdi
movl 0x20(%rsp), %esi
callq 0xc03a
movl %eax, %r15d
xorb %r14b, %r15b
pushq $0x9
popq %rdi
movl 0x24(%rsp), %esi
callq 0xc03a
movl %eax, %r14d
pushq $0xe
popq %rdi
movl %r12d, %esi
callq 0xc03a
movq 0x10(%rsp), %rsi
xorb %r14b, %al
xorb %r15b, %al
movb 0xf(%rsp), %cl
movb %cl, 0xc(%rbx,%rsi,4)
movb %r13b, 0xd(%rbx,%rsi,4)
movb %bpl, 0xe(%rbx,%rsi,4)
movb %al, 0xf(%rbx,%rsi,4)
incq %rsi
movl (%rbx), %ecx
jmp 0xbe45
xorl %esi, %esi
pushq $0x2
popq %rdi
xorl %r8d, %r8d
cltd
idivl %edi
cmpl %eax, %r8d
jge 0xc02b
xorl %eax, %eax
cmpl %ecx, %eax
jge 0xc021
movl %r8d, %edx
imull %ecx, %edx
addl %eax, %edx
movslq %edx, %rdx
movl 0x8(%rbx), %r9d
addl %esi, %r9d
imull %ecx, %r9d
movslq %r9d, %rcx
addq %rax, %rcx
movl 0xc(%rbx,%rdx,4), %r9d
movl 0xc(%rbx,%rcx,4), %r10d
movl %r10d, 0xc(%rbx,%rdx,4)
movl %r9d, 0xc(%rbx,%rcx,4)
movl (%rbx), %ecx
incq %rax
jmp 0xbfe6
incl %r8d
movl 0x8(%rbx), %eax
decl %esi
jmp 0xbfdc
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq