// File: /workspace/github_cpp_makefile_star2_O1/lmclaramunt[P]AES-Crypto/Cipher.cpp
// Function: Cipher::CBC_decrypt()
void Cipher::CBC_decrypt(){   
    Sequence tag = CBC_MAC(*inputBlock, false, true);             //Generate MAC Tag from Ciphertext
    Sequence readTag = inputBlock->getSequenceVector().at(0);     //Get the MAC Tag in the Ciphertext
    if(authenticateSequences(&readTag, &tag)){                    //Compare them for authentication purposes
        Sequence prevSq(16), cipherText(16); 
        int size = inputBlock->getSequenceVector().size();
        int i = -1;
        for(Sequence sq: inputBlock->getSequenceVector()){         
            i++;
            if(i <= 1){
                prevSq.updateSequence(sq);  //Skip decryption of first and last Block of ciphertext
                continue;                   //These blocks are the IV and MAC Tag respectively
            }
            cipherText.updateSequence(sq);  //Keep track of ciphertext, we'll need it next round   
            decrypt(&sq, aesKeyExp);
            sq = sq ^ prevSq;               
            prevSq.updateSequence(cipherText);  //Update previous sequence, to ciphertext values
        }
        try{
            removePadding(&inputBlock->getSequenceVector().at(size-1));     //Last block will have padding
        }catch(const char* str){
            throw str;
        }

        //Blocks have been authenticated, decrypted, and padding removed. Ready to write plaintext
        writePlainText();
        /* Sequence cleanup as it can leave traces in memory */
        prevSq.~Sequence();
        cipherText.~Sequence();
    }else
        throw "Ciphertext has been modified, it won't be decrypted!\n";     //Authenticate-then-decrypt
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %rbx
movq 0x10(%rdi), %rsi
leaq 0x48(%rsp), %r14
movq %r14, %rdi
callq 0x6448
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x57f0
movq %rax, 0x28(%rsp)
movl %edx, 0x30(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x352e
movq 0x10(%rbx), %rdi
callq 0x3568
movq (%rax), %rcx
cmpq %rcx, 0x8(%rax)
je 0x5f71
movups (%rcx), %xmm0
leaq 0x60(%rsp), %rsi
movaps %xmm0, (%rsi)
leaq 0x28(%rsp), %rdx
callq 0x59a2
testb %al, %al
je 0x5f83
leaq 0x38(%rsp), %rdi
movl $0x10, %esi
callq 0x31dc
leaq 0x18(%rsp), %rdi
movl $0x10, %esi
callq 0x31dc
movq 0x10(%rbx), %rdi
callq 0x3568
movq 0x8(%rax), %rcx
subq (%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x10(%rbx), %rdi
callq 0x3568
movq (%rax), %rbp
movq 0x8(%rax), %r13
cmpq %r13, %rbp
je 0x5f15
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
leaq 0x38(%rsp), %r14
movq %rsp, %r12
movups (%rbp), %xmm0
movaps %xmm0, (%rsp)
movq (%rsp), %rsi
testl %r15d, %r15d
jle 0x5efa
movl 0x8(%rsp), %edx
leaq 0x18(%rsp), %rdi
callq 0x327e
movq (%rbx), %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x55e8
movq %r12, %rdi
movq %r14, %rsi
callq 0x335d
movq (%rax), %rcx
movq %rcx, (%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x8(%rsp)
movq 0x18(%rsp), %rsi
leaq 0x20(%rsp), %rax
jmp 0x5eff
leaq 0x8(%rsp), %rax
movl (%rax), %edx
movq %r14, %rdi
callq 0x327e
addq $0x10, %rbp
incl %r15d
cmpq %r13, %rbp
jne 0x5ea8
movq 0x10(%rbx), %rdi
callq 0x3568
movq 0x10(%rsp), %rcx
shlq $0x1c, %rcx
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
addq %rcx, %rsi
sarq $0x20, %rsi
movq (%rax), %rcx
movq 0x8(%rax), %rdx
subq %rcx, %rdx
sarq $0x4, %rdx
cmpq %rsi, %rdx
jbe 0x5fa8
shlq $0x4, %rsi
addq %rsi, %rcx
movq %rcx, %rsi
callq 0x5a14
movq %rbx, %rdi
callq 0x5a98
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x181c(%rip), %rdi      # 0x7794
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2330
movl $0x8, %edi
callq 0x2120
leaq 0x179f(%rip), %rcx      # 0x7733
movq %rcx, (%rax)
movq 0x5022(%rip), %rsi      # 0xafc0
movq %rax, %rdi
xorl %edx, %edx
callq 0x23d0
leaq 0x17e5(%rip), %rdi      # 0x7794
xorl %eax, %eax
callq 0x2330
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x352e
jmp 0x5ffe
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x5ffe
movq %rbx, %rdi
callq 0x20d0
movq %rax, %rbx
movl $0x8, %edi
callq 0x2120
movq %rbx, (%rax)
movq 0x4fd4(%rip), %rsi      # 0xafc0
movq %rax, %rdi
xorl %edx, %edx
callq 0x23d0
movq %rax, %rbx
callq 0x23a0
movq %rbx, %rdi
callq 0x2400