// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
movq %r8, %r12
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movq 0x8(%rcx), %rax
testq %rax, %rax
je 0x185d
movq (%rcx), %rcx
xorl %edx, %edx
movb (%rcx,%rdx), %sil
movb %sil, -0x90(%rbp,%rdx)
incq %rdx
cmpq %rdx, %rax
jne 0x1849
leaq -0x90(%rbp), %rsi
movq %r15, %rdi
callq 0x168e
leaq 0x10(%r15), %rax
leaq 0xb0(%r15), %rcx
xorl %edx, %edx
xorl %esi, %esi
movl (%rax,%rsi,4), %edi
movl (%rcx,%rsi,4), %r8d
movl %r8d, (%rax,%rsi,4)
movl %edi, (%rcx,%rsi,4)
incq %rsi
cmpq $0x4, %rsi
jne 0x187b
incq %rdx
addq $-0x10, %rcx
addq $0x10, %rax
cmpq $0x5, %rdx
jne 0x1879
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x18c4
movq (%r12), %rcx
xorl %edx, %edx
movb (%rcx,%rdx), %sil
movb %sil, -0x70(%rbp,%rdx)
incq %rdx
cmpq %rdx, %rax
jne 0x18b3
movq (%rbx), %r13
movq %rbx, -0x38(%rbp)
movq 0x8(%rbx), %rbx
movq %rbx, %rax
subq %r13, %rax
shrq $0x3, %rax
movabsq $-0x5555555555555550, %rdi # imm = 0xAAAAAAAAAAAAAAB0
imulq %rax, %rdi
callq 0x1030
movq %rax, %r12
cmpq %r13, %rbx
je 0x1990
movq %r14, -0x30(%rbp)
leaq -0x60(%rbp), %r14
leaq -0x50(%rbp), %rdi
movq %r13, %rsi
callq 0x1d50
movq -0x50(%rbp), %rax
xorl %ecx, %ecx
movb (%rax,%rcx), %dl
movb %dl, -0x80(%rbp,%rcx)
movb %dl, -0x60(%rbp,%rcx)
incq %rcx
cmpq $0x10, %rcx
jne 0x1912
movq %r15, %rdi
movq %r14, %rsi
callq 0x1a5a
movq %r15, %rdi
movq %r14, %rsi
leaq -0x70(%rbp), %rdx
callq 0x16fe
movslq 0x39dd(%rip), %rax      # 0x5324
movaps -0x60(%rbp), %xmm0
movups %xmm0, (%r12,%rax)
addl $0x10, %eax
movl %eax, 0x39cb(%rip)      # 0x5324
movaps -0x80(%rbp), %xmm0
movaps %xmm0, -0x70(%rbp)
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x1976
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x10f0
addq $0x18, %r13
cmpq %rbx, %r13
jne 0x1900
movq -0x38(%rbp), %rax
movq (%rax), %rbx
movq 0x8(%rax), %rax
movq -0x30(%rbp), %r14
jmp 0x1993
movq %rbx, %rax
subq %rbx, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rcx
movl %ecx, %eax
shll $0x4, %eax
cltq
movzbl -0x1(%r12,%rax), %esi
subq %rsi, %rax
movb $0x0, (%r12,%rax)
shlq $0x4, %rcx
movq %r12, %rdx
addq %rcx, %rdx
subq %rsi, %rdx
leaq 0x10(%r14), %rax
movq %rax, (%r14)
movq %r14, %rdi
movq %r12, %rsi
callq 0x1dde
movl $0x1, %esi
movq %r12, %rdi
callq 0x10f0
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x1a13
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x10f0
movq %rbx, %rdi
callq 0x1150
nop