// File: /workspace/github_cpp_makefile_star2_O2/LandonSwartz[P]TheGreatEncryptor/./EncryptionClass.cpp
// Function: encryption_base::encrypt_data()
bool encrypt_data() {
        if (this->hash_key == 0) {
            throw file_encryption_error("no hash key has been set");
            return false;
        }
        if (data_state == 0) {
            throw file_encryption_error("there is no data to encrypt");
            return false;
        } else if (data_state == 1) {
            throw file_encryption_error("the data is already encrypted");
            return false;
        }

        // Set up the structs for the threads which will encrypt the data.
        vector<alg_prms *> encryption_alg_prms_vect;
        int indices_per_thread;
        int num_threads;
        int end_additional_increment = 0;
        // Ensure there will be at least one string per thread
        if (data->size() >= NUM_ENCRYPTION_THREADS) {
            indices_per_thread = (data->size()) / NUM_ENCRYPTION_THREADS;
            end_additional_increment = (data->size()) % NUM_ENCRYPTION_THREADS;
            num_threads = NUM_ENCRYPTION_THREADS;
        }
        // If there will not be one string per thread, simply use one thread
        else {
            num_threads = 1;
            indices_per_thread = data->size();
        }

        // Create structs for each thread
        for (int i = 0; i < num_threads; i++) {
            alg_prms * alg_prms_strc = new alg_prms();
            alg_prms_strc->data = this->data;
            alg_prms_strc->hash_key = this->hash_key;
            alg_prms_strc->start_index = (i * indices_per_thread);
            alg_prms_strc->end_index = ((i + 1) * indices_per_thread) - 1;
            encryption_alg_prms_vect.push_back(alg_prms_strc);
        }
        // Add end_additional_increment
        encryption_alg_prms_vect.back()->end_index += end_additional_increment;

        // Create the threads to encrypt the data
        vector<pthread_t> encryption_threads;
        for (auto prm_vct : encryption_alg_prms_vect) {
            pthread_t new_thread;
            pthread_create(&new_thread, NULL, encryption_algorithm, prm_vct);
            encryption_threads.push_back(new_thread);
        }

        // Now that the threads are running, join them so the function will yield
        for (auto thread : encryption_threads) {
            pthread_join(thread, NULL);
        }

        // Delete the dynamically allocated structs once all thread operation has completed
        for (auto prm_vct : encryption_alg_prms_vect) {
            delete prm_vct;
        }

        // Return true to indicate the encryption was successful.
        return true;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
cmpl $0x0, 0x10(%rdi)
je 0x2fe0
movq %rdi, %rbx
movl (%rdi), %eax
cmpl $0x1, %eax
je 0x2ffc
testl %eax, %eax
je 0x3018
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
andq $0x0, 0x10(%rsp)
movq 0x8(%rbx), %rax
movq 0x8(%rax), %r14
subq (%rax), %r14
sarq $0x5, %r14
xorl %r15d, %r15d
cmpq $0xa, %r14
jb 0x2ecc
pushq $0xa
popq %rcx
movq %r14, %rax
xorl %edx, %edx
divq %rcx
movq %rdx, 0x18(%rsp)
pushq $0xa
popq %r12
movq %rax, %r14
jmp 0x2ed9
pushq $0x1
popq %r12
movq $0x0, 0x18(%rsp)
leal -0x1(%r14), %r13d
leaq 0x20(%rsp), %rbp
subl $0x1, %r12d
jb 0x2f23
pushq $0x18
popq %rdi
callq 0x2180
andq $0x0, 0x10(%rax)
movq %rax, 0x20(%rsp)
movq 0x8(%rbx), %rcx
movq %rcx, (%rax)
movl 0x10(%rbx), %ecx
movl %ecx, 0x10(%rax)
movl %r15d, 0x8(%rax)
leal (%r13,%r15), %ecx
movl %ecx, 0xc(%rax)
movq %rsp, %rdi
movq %rbp, %rsi
callq 0x3094
addl %r14d, %r15d
jmp 0x2ee2
movq 0x8(%rsp), %r12
movq -0x8(%r12), %rax
movq 0x18(%rsp), %rcx
addl %ecx, 0xc(%rax)
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rbx
andq $0x0, 0x10(%rbx)
movaps %xmm0, (%rbx)
movq (%rsp), %r13
leaq 0x162(%rip), %r14       # 0x30b2
leaq 0x40(%rsp), %r15
cmpq %r12, %r13
je 0x2f7c
movq (%r13), %rcx
movq %r15, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x22a0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3100
addq $0x8, %r13
jmp 0x2f55
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %r14
cmpq %r14, %rbx
je 0x2f9b
movq (%rbx), %rdi
xorl %esi, %esi
callq 0x2160
addq $0x8, %rbx
jmp 0x2f86
movq (%rsp), %r14
movq 0x8(%rsp), %r15
pushq $0x18
popq %rbx
cmpq %r15, %r14
je 0x2fbd
movq (%r14), %rdi
movq %rbx, %rsi
callq 0x2190
addq $0x8, %r14
jmp 0x2fa7
leaq 0x20(%rsp), %rdi
callq 0x33ea
movq %rsp, %rdi
callq 0x3408
movb $0x1, %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %r14
leaq 0x11f5(%rip), %rsi      # 0x41e7
movq %rax, %rdi
callq 0x307e
jmp 0x3032
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %r14
leaq 0x120e(%rip), %rsi      # 0x421c
movq %rax, %rdi
callq 0x307e
jmp 0x3032
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %r14
leaq 0x11d6(%rip), %rsi      # 0x4200
movq %rax, %rdi
callq 0x307e
leaq 0x3cef(%rip), %rsi      # 0x6d28
movq 0x3f88(%rip), %rdx      # 0x6fc8
movq %r14, %rdi
callq 0x2270
jmp 0x304c
jmp 0x304c
movq %rax, %rbx
movq %r14, %rdi
callq 0x2120
jmp 0x3075
jmp 0x305b
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x33ea
jmp 0x306d
movq %rax, %rbx
movq %rsp, %rdi
callq 0x3408
movq %rbx, %rdi
callq 0x2290
nop