// File: SimpleButNotNaive[P]AES/encryptor.cpp
// Function: aes_encryptor::encryption(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<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>>)
vector<vector<uint8>> aes_encryptor::encryption(string p_text, string key, string init_vector) {
    string total_plain_text = padding(p_text);
    vector<vector<uint8>> text_vector = split(total_plain_text);

    vector<vector<uint8>> cipher;

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

    generate_roundkey(key_array);

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

    uint8 x[16];
    for(auto group : text_vector){
        for(int i = 0;i < group.size();i++){
            x[i] = group[i];
        }
        xor_group(x, y);
        encrypt_one_group(x);

        for(int i = 0; i < 16;i++){
            y[i] = x[i];
        }
        
        vector<uint8> one_group;
        for(int i = 0;i < 16;i++){
            one_group.push_back(y[i]);
        }
        cipher.push_back(one_group);
    }
    return cipher;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movq %r8, -0x1a0(%rbp)
movq %rcx, -0x198(%rbp)
movq %rdx, -0x190(%rbp)
movq %rsi, %rax
movq -0x190(%rbp), %rsi
movq %rdi, -0x188(%rbp)
movq %rdi, %rdx
movq %rdx, -0x180(%rbp)
movq %rdi, -0x8(%rbp)
movq %rax, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x178(%rbp)
leaq -0x68(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x20a0
movq -0x178(%rbp), %rsi
movq -0x170(%rbp), %rdx
leaq -0x48(%rbp), %rdi
callq 0x4a00
jmp 0x45f3
leaq -0x68(%rbp), %rdi
callq 0x2238
leaq -0xb0(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x20a0
jmp 0x460e
movq -0x178(%rbp), %rsi
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rdx
callq 0x4ac0
jmp 0x462a
leaq -0xb0(%rbp), %rdi
callq 0x2238
movq -0x188(%rbp), %rdi
movb $0x0, -0xb1(%rbp)
callq 0x4d30
movl $0x0, -0xd4(%rbp)
movq -0x198(%rbp), %rdi
movslq -0xd4(%rbp), %rax
movq %rax, -0x1a8(%rbp)
callq 0x20d0
movq %rax, %rcx
movq -0x1a8(%rbp), %rax
cmpq %rcx, %rax
jae 0x471d
movq -0x198(%rbp), %rdi
movslq -0xd4(%rbp), %rsi
callq 0x2220
movq %rax, -0x1b0(%rbp)
jmp 0x469c
movq -0x1b0(%rbp), %rax
movb (%rax), %cl
movslq -0xd4(%rbp), %rax
movb %cl, -0xd0(%rbp,%rax)
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
jmp 0x4653
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x2238
jmp 0x49f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x49ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x2238
jmp 0x49ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x49d5
movq -0x178(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x2a50
jmp 0x4732
movl $0x0, -0xf4(%rbp)
cmpl $0x10, -0xf4(%rbp)
jge 0x4789
movq -0x1a0(%rbp), %rdi
movslq -0xf4(%rbp), %rsi
callq 0x2220
movq %rax, -0x1b8(%rbp)
jmp 0x4761
movq -0x1b8(%rbp), %rax
movb (%rax), %cl
movslq -0xf4(%rbp), %rax
movb %cl, -0xf0(%rbp,%rax)
movl -0xf4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4(%rbp)
jmp 0x473c
leaq -0x90(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rdi
callq 0x36e0
movq %rax, -0x120(%rbp)
movq -0x118(%rbp), %rdi
callq 0x3710
movq %rax, -0x128(%rbp)
leaq -0x120(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x3740
testb $0x1, %al
jne 0x47d9
jmp 0x4994
leaq -0x120(%rbp), %rdi
callq 0x3780
movq %rax, %rsi
leaq -0x140(%rbp), %rdi
callq 0x37a0
jmp 0x47f6
movl $0x0, -0x144(%rbp)
movslq -0x144(%rbp), %rax
movq %rax, -0x1c0(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x3a00
movq %rax, %rcx
movq -0x1c0(%rbp), %rax
cmpq %rcx, %rax
jae 0x485d
movslq -0x144(%rbp), %rsi
leaq -0x140(%rbp), %rdi
callq 0x3890
movb (%rax), %cl
movslq -0x144(%rbp), %rax
movb %cl, -0x110(%rbp,%rax)
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0x4800
movq -0x178(%rbp), %rdi
leaq -0x110(%rbp), %rsi
leaq -0xf0(%rbp), %rdx
callq 0x2b20
jmp 0x4879
movq -0x178(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x4bf0
jmp 0x488e
movl $0x0, -0x148(%rbp)
cmpl $0x10, -0x148(%rbp)
jge 0x48df
movslq -0x148(%rbp), %rax
movb -0x110(%rbp,%rax), %cl
movslq -0x148(%rbp), %rax
movb %cl, -0xf0(%rbp,%rax)
movl -0x148(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x148(%rbp)
jmp 0x4898
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x4986
leaq -0x160(%rbp), %rdi
callq 0x4d50
movl $0x0, -0x164(%rbp)
cmpl $0x10, -0x164(%rbp)
jge 0x4948
movslq -0x164(%rbp), %rax
leaq -0xf0(%rbp,%rax), %rsi
leaq -0x160(%rbp), %rdi
callq 0x4d70
jmp 0x491b
jmp 0x491d
movl -0x164(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x164(%rbp)
jmp 0x48f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x38b0
jmp 0x4986
movq -0x188(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x4de0
jmp 0x495d
leaq -0x160(%rbp), %rdi
callq 0x38b0
leaq -0x140(%rbp), %rdi
callq 0x38b0
leaq -0x120(%rbp), %rdi
callq 0x3910
jmp 0x47bd
leaq -0x140(%rbp), %rdi
callq 0x38b0
jmp 0x49d5
movb $0x1, -0xb1(%rbp)
testb $0x1, -0xb1(%rbp)
jne 0x49b0
movq -0x188(%rbp), %rdi
callq 0x4e50
leaq -0x90(%rbp), %rdi
callq 0x4e50
leaq -0x48(%rbp), %rdi
callq 0x2238
movq -0x180(%rbp), %rax
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
movq -0x188(%rbp), %rdi
callq 0x4e50
leaq -0x90(%rbp), %rdi
callq 0x4e50
leaq -0x48(%rbp), %rdi
callq 0x2238
movq -0x70(%rbp), %rdi
callq 0x21d0
nop