// File: /workspace/github_cpp_makefile_star2_O2/SimpleButNotNaive[P]AES/decryptor.cpp
// Function: aes_decryptor::decryption(std::vector<std::vector<unsigned char, std::allocator<unsigned char>>, std::allocator<std::vector<unsigned char, std::allocator<unsigned char>>>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
string aes_decryptor::decryption(vector<vector<uint8>> cipher, string key,
                               string init_vector) {
    uint8 key_array[16];
    for (int i = 0; i < key.size(); i++) {
        key_array[i] = key[i];
    }
    generate_roundkey(key_array);
    reverse_round_key();

    uint8 pre_y[16];
    for(int i = 0;i < init_vector.size();i++){
        pre_y[i] = init_vector[i];
    }

    uint8 post_y[16];
    uint8 current_y[16];
    uint8* p_text_array = new uint8[16*cipher.size()];
    for(auto group: cipher){
        for(int i = 0;i < 16;i++){
            post_y[i] = group[i];
            current_y[i] = group[i];
        }
        decrypt_one_group(current_y);

        xor_group(current_y, pre_y);
        splice(p_text_array, current_y);

        for(int i = 0;i < 16;i++){
            pre_y[i] = post_y[i];
        }
    }

    int truncate_size = truncate(p_text_array, cipher.size() * 16);

    string ret(p_text_array, p_text_array + cipher.size() * 16 - truncate_size);

    delete p_text_array;

    return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r8, %rbx
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, -0x40(%rbp)
movq 0x8(%rcx), %rax
xorl %edx, %edx
cmpq %rdx, %rax
jbe 0x1786
movq (%rcx), %rsi
movb (%rsi,%rdx), %sil
movb %sil, -0x80(%rbp,%rdx)
incq %rdx
jmp 0x1770
leaq -0x80(%rbp), %rsi
movq %r15, %rdi
callq 0x1582
movq %r15, %rdi
callq 0x18e4
movq 0x8(%rbx), %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
jbe 0x17b4
movq (%rbx), %rdx
movb (%rdx,%rcx), %dl
movb %dl, -0x50(%rbp,%rcx)
incq %rcx
jmp 0x17a0
movq (%r14), %r13
movq %r14, -0x38(%rbp)
movq 0x8(%r14), %r12
movq %r12, %rax
subq %r13, %rax
pushq $0x18
popq %rcx
cqto
idivq %rcx
shlq $0x4, %rax
movq %rax, %rdi
callq 0x1030
movq %rax, -0x30(%rbp)
leaq -0x98(%rbp), %rbx
leaq -0x60(%rbp), %r14
cmpq %r12, %r13
je 0x1860
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1b3c
movq -0x98(%rbp), %rax
xorl %ecx, %ecx
cmpq $0x10, %rcx
je 0x1817
movb (%rax,%rcx), %dl
movb %dl, -0x70(%rbp,%rcx)
movb %dl, -0x60(%rbp,%rcx)
incq %rcx
jmp 0x1801
movq %r15, %rdi
movq %r14, %rsi
callq 0x1926
movq %r15, %rdi
movq %r14, %rsi
leaq -0x50(%rbp), %rdx
callq 0x160e
movq -0x30(%rbp), %rsi
movq %r14, %rdx
callq 0x19be
xorl %eax, %eax
cmpq $0x10, %rax
je 0x1852
movb -0x70(%rbp,%rax), %cl
movb %cl, -0x50(%rbp,%rax)
incq %rax
jmp 0x183f
movq %rbx, %rdi
callq 0x1b9e
addq $0x18, %r13
jmp 0x17e8
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
movl %eax, %ecx
shll $0x4, %ecx
movslq %ecx, %rcx
movq -0x30(%rbp), %r14
movzbl -0x1(%r14,%rcx), %esi
subq %rsi, %rcx
movb $0x0, (%r14,%rcx)
shlq $0x4, %rax
movq %r14, %rdx
addq %rax, %rdx
subq %rsi, %rdx
movq -0x40(%rbp), %rbx
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1c30
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x10e0
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x1b9e
movq %rbx, %rdi
callq 0x1150