// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
cmpl $0x0, 0x10(%rdi)
je 0x3616
movq %rdi, %rbx
movl (%rdi), %eax
cmpl $0x1, %eax
je 0x3634
testl %eax, %eax
je 0x3652
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movq 0x8(%rbx), %rax
movq 0x8(%rax), %r14
subq (%rax), %r14
sarq $0x5, %r14
movl $0x1, %ebp
xorl %r13d, %r13d
cmpq $0xa, %r14
jb 0x34aa
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
movq %r14, %rax
mulq %rcx
shrq $0x3, %rdx
leal (%rdx,%rdx), %eax
leal (%rax,%rax,4), %eax
subl %eax, %r14d
movl $0xa, %ebp
movl %r14d, 0xc(%rsp)
movq %rdx, %r14
jmp 0x34b2
movl $0x0, 0xc(%rsp)
leal -0x1(%r14), %r15d
leaq 0x10(%rsp), %r12
movl $0x18, %edi
callq 0x21c0
movq $0x0, 0x10(%rax)
movq %rax, 0x10(%rsp)
movq 0x8(%rbx), %rcx
movq %rcx, (%rax)
movl 0x10(%rbx), %ecx
movl %ecx, 0x10(%rax)
movl %r13d, 0x8(%rax)
leal (%r15,%r13), %ecx
movl %ecx, 0xc(%rax)
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x3501
movq %rax, (%rsi)
addq $0x8, 0x38(%rsp)
jmp 0x350e
leaq 0x30(%rsp), %rdi
movq %r12, %rdx
callq 0x3774
addl %r14d, %r13d
decl %ebp
jne 0x34bb
movq 0x38(%rsp), %r12
movq -0x8(%r12), %rax
movl 0xc(%rsp), %ecx
addl %ecx, 0xc(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x30(%rsp), %r13
cmpq %r12, %r13
je 0x35b5
leaq 0x1a4(%rip), %rbx       # 0x36ec
leaq 0x50(%rsp), %r14
leaq 0x10(%rsp), %r15
movq (%r13), %rcx
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x22e0
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x3582
movq 0x50(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x358d
movq %r15, %rdi
movq %r14, %rdx
callq 0x38b0
addq $0x8, %r13
cmpq %r12, %r13
jne 0x3552
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r14
cmpq %r14, %rbx
je 0x35b5
movq (%rbx), %rdi
xorl %esi, %esi
callq 0x21a0
addq $0x8, %rbx
jmp 0x35a0
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %r14
cmpq %r14, %rbx
je 0x35d7
movq (%rbx), %rdi
movl $0x18, %esi
callq 0x21d0
addq $0x8, %rbx
jmp 0x35bf
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x35ee
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3605
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
movb $0x1, %al
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x20f0
movq %rax, %r14
leaq 0x1bd9(%rip), %rsi      # 0x5203
movq %rax, %rdi
callq 0x36d6
jmp 0x366e
movl $0x10, %edi
callq 0x20f0
movq %rax, %r14
leaq 0x1bf0(%rip), %rsi      # 0x5238
movq %rax, %rdi
callq 0x36d6
jmp 0x366e
movl $0x10, %edi
callq 0x20f0
movq %rax, %r14
leaq 0x1bb6(%rip), %rsi      # 0x521c
movq %rax, %rdi
callq 0x36d6
leaq 0x46ab(%rip), %rsi      # 0x7d20
movq 0x494c(%rip), %rdx      # 0x7fc8
movq %r14, %rdi
callq 0x22a0
jmp 0x3688
jmp 0x3688
movq %rax, %rbx
movq %r14, %rdi
callq 0x2150
jmp 0x36cd
jmp 0x3697
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x36b6
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
jmp 0x36b6
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x36cd
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq %rbx, %rdi
callq 0x22c0
nop