// File: lmclaramunt[P]AES-Crypto/Cipher.cpp
// Function: Cipher::decrypt(Sequence*, unsigned char**)
void Cipher::decrypt(Sequence* input, unsigned char** key){
    State state(input);
    addRoudKey(Nr, key, state.getStateArray());

    for (int i=Nr-1; i > 0; i--) {
        unsigned char** s2 = new unsigned char*[4];
        invShiftRows(state.getStateArray());
        invSubBytes(state.getStateArray());
        addRoudKey(i, key, state.getStateArray());
        invMixColumns(state.getStateArray(), s2);
        state.setStateArray(s2);
    }

    invShiftRows(state.getStateArray());
    invSubBytes(state.getStateArray());
    addRoudKey(0, key, state.getStateArray());
    input->updateSequence(state.toSequence());

    /* State cleanup as it can leave traces in memory */
    state.~State();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x20(%rbp), %rdi
movq %rdi, -0x78(%rbp)
callq 0x7280
movq -0x80(%rbp), %rax
movq -0x78(%rbp), %rdi
movl 0x1c(%rax), %eax
movl %eax, -0x6c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
callq 0x73b0
movq %rax, -0x60(%rbp)
jmp 0x9a61
movq -0x80(%rbp), %rdi
movq -0x60(%rbp), %rcx
movq -0x68(%rbp), %rdx
movl -0x6c(%rbp), %esi
callq 0x94e0
movq -0x80(%rbp), %rax
movl 0x1c(%rax), %eax
subl $0x1, %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0x9b92
movl $0x20, %edi
callq 0x3030
movq %rax, -0x88(%rbp)
jmp 0x9a9f
movq -0x88(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x73b0
movq %rax, -0x90(%rbp)
jmp 0x9abc
movq -0x90(%rbp), %rsi
movq -0x80(%rbp), %rdi
callq 0x97f0
leaq -0x20(%rbp), %rdi
callq 0x73b0
movq %rax, -0x98(%rbp)
jmp 0x9ade
movq -0x98(%rbp), %rsi
movq -0x80(%rbp), %rdi
callq 0x9860
movl -0x30(%rbp), %eax
movl %eax, -0xac(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x73b0
movq %rax, -0xa0(%rbp)
jmp 0x9b14
movq -0xa0(%rbp), %rcx
movq -0xa8(%rbp), %rdx
movl -0xac(%rbp), %esi
movq -0x80(%rbp), %rdi
callq 0x94e0
leaq -0x20(%rbp), %rdi
callq 0x73b0
movq %rax, -0xb8(%rbp)
jmp 0x9b43
movq -0xb8(%rbp), %rsi
movq -0x80(%rbp), %rdi
movq -0x38(%rbp), %rdx
callq 0x9910
jmp 0x9b59
movq -0x38(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x7470
jmp 0x9b68
jmp 0x9b6a
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x9a82
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x7350
jmp 0x9c81
leaq -0x20(%rbp), %rdi
callq 0x73b0
movq %rax, -0xc0(%rbp)
jmp 0x9ba4
movq -0xc0(%rbp), %rsi
movq -0x80(%rbp), %rdi
callq 0x97f0
leaq -0x20(%rbp), %rdi
callq 0x73b0
movq %rax, -0xc8(%rbp)
jmp 0x9bc6
movq -0xc8(%rbp), %rsi
movq -0x80(%rbp), %rdi
callq 0x9860
movq -0x18(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x73b0
movq %rax, -0xd0(%rbp)
jmp 0x9bf3
movq -0xd0(%rbp), %rcx
movq -0xd8(%rbp), %rdx
movq -0x80(%rbp), %rdi
xorl %esi, %esi
callq 0x94e0
movq -0x10(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x73d0
movl %edx, -0xe4(%rbp)
movq %rax, -0xe0(%rbp)
jmp 0x9c2f
movq -0xf0(%rbp), %rdi
movl -0xe4(%rbp), %eax
movq -0xe0(%rbp), %rcx
movq %rcx, -0x58(%rbp)
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rsi
movl -0x40(%rbp), %edx
callq 0x4b70
jmp 0x9c66
leaq -0x20(%rbp), %rdi
callq 0x7350
leaq -0x20(%rbp), %rdi
callq 0x7350
addq $0xf0, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x34d0
nopw (%rax,%rax)