// File: /workspace/github_cpp_makefile_star2_O1/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, -0x38(%rbp)
movq 0x8(%rcx), %rax
testq %rax, %rax
je 0x183e
movq (%rcx), %rcx
xorl %edx, %edx
movb (%rcx,%rdx), %sil
movb %sil, -0x90(%rbp,%rdx)
incq %rdx
cmpq %rdx, %rax
jne 0x182a
leaq -0x90(%rbp), %rsi
movq %r15, %rdi
callq 0x166e
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 0x185c
incq %rdx
addq $-0x10, %rcx
addq $0x10, %rax
cmpq $0x5, %rdx
jne 0x185a
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x18a5
movq (%r12), %rcx
xorl %edx, %edx
movb (%rcx,%rdx), %sil
movb %sil, -0x70(%rbp,%rdx)
incq %rdx
cmpq %rdx, %rax
jne 0x1894
movq (%rbx), %r13
movq %rbx, -0x30(%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 0x195c
leaq -0x60(%rbp), %r14
leaq -0x50(%rbp), %rdi
movq %r13, %rsi
callq 0x1d32
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 0x18ef
movq %r15, %rdi
movq %r14, %rsi
callq 0x1a2e
movq %r15, %rdi
movq %r14, %rsi
leaq -0x70(%rbp), %rdx
callq 0x16de
movslq 0x3a00(%rip), %rax      # 0x5324
movaps -0x60(%rbp), %xmm0
movups %xmm0, (%r12,%rax)
addl $0x10, %eax
movl %eax, 0x39ee(%rip)      # 0x5324
movaps -0x80(%rbp), %xmm0
movaps %xmm0, -0x70(%rbp)
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x1953
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x10f0
addq $0x18, %r13
cmpq %rbx, %r13
jne 0x18dd
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %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
movq -0x38(%rbp), %rbx
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1dc0
movl $0x1, %esi
movq %r12, %rdi
callq 0x10f0
movq %rbx, %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 0x19e8
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x10f0
movq %rbx, %rdi
callq 0x1150