// File: /workspace/github_cpp_makefile_star2_O1/ninjabear[P]dr-doom/src/thread.cpp
// Function: thread_bomb()
void thread_bomb() { 
    std::condition_variable cv;
    std::mutex m;
    std::vector<std::thread> thread_handles;

    long thread_count = 0; 

    for (;;) {
        thread_count++;
        try { 
            thread_handles.push_back(std::thread(blocked_thread, std::ref(cv), std::ref(m)));
        } catch (const std::exception& e) {
            std::cout << "After creating " << thread_count << " new threads the following error occurred: " << std::endl << std::endl;
            std::cout << e.what() << std::endl << std::endl;
            break;
        } catch (...) {
            std::cout << "After creating " << thread_count << " new threads an unexpected (non std::exception) error occurred." << std::endl << std::endl;
            break;
        }
    }

    std::cout << "The threads are currently running. Would you like to clean up the threads before exiting? [Y/n]: ";

    char cont = 0;
    std::cin.clear();
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    std::cin.get(cont);

    if (cont != 'n' && cont != 'N') {
        std::cout << "Cleaning up threads..." << std::endl;

        cv.notify_all();

        for (long i=0; i<thread_count; i++) {
            try {
                thread_handles[i].join();
            } catch (...) { }
            cv.notify_all();
        }

        std::cout << thread_count << " threads closed. " << std::endl;
    } else {
        std::cout << "Understood, ending the process leaving the operating system to clean up " << thread_count << " detached threads." << std::endl;

        for (long i=0; i<thread_count; i++) {
            try {
                thread_handles[i].detach();
            } catch (...) { }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
leaq 0x40(%rsp), %rdi
callq 0x2270
xorl %eax, %eax
leaq 0x70(%rsp), %r14
movq %rax, 0x20(%r14)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
leaq 0x20(%rsp), %r15
movq %rax, 0x10(%r15)
movaps %xmm0, (%r15)
movl $0x1, %eax
movq %rax, 0x8(%rsp)
leaq 0x47a(%rip), %r12       # 0x4232
movq %rsp, %r13
leaq 0x18(%rsp), %rbp
leaq 0x10(%rsp), %rbx
leaq 0x40(%rsp), %rax
movq %rax, 0x18(%rsp)
movq %r14, 0x10(%rsp)
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x4290
movq %r15, %rdi
movq %r13, %rsi
callq 0x43d2
cmpq $0x0, (%rsp)
jne 0x3e05
incq 0x8(%rsp)
jmp 0x3dc5
cmpq $0x0, (%rsp)
je 0x3e0a
callq 0x2060
movq %rdx, %rbx
movq %rax, %rdi
callq 0x20b0
cmpl $0x2, %ebx
jne 0x3eea
movq %rax, %r15
movq 0x41a8(%rip), %rdi      # 0x7fd0
leaq 0x1808(%rip), %rsi      # 0x5637
movl $0xf, %edx
callq 0x2210
movq 0x4190(%rip), %r14      # 0x7fd0
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0x21c0
movq %rax, %r12
leaq 0x1830(%rip), %rsi      # 0x5687
movl $0x2b, %edx
movq %rax, %rdi
callq 0x2210
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
testq %rax, %rax
je 0x3f85
movq %rax, %rbx
movq %rax, %rdi
callq 0x20c0
movq 0x40f6(%rip), %rdi      # 0x7fd0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2210
jmp 0x3f9d
movq 0x40df(%rip), %rdi      # 0x7fd0
leaq 0x173f(%rip), %rsi      # 0x5637
movl $0xf, %edx
callq 0x2210
movq 0x8(%rsp), %r12
movq 0x40c2(%rip), %rdi      # 0x7fd0
movq %r12, %rsi
callq 0x21c0
movq %rax, %r14
leaq 0x1727(%rip), %rsi      # 0x5647
movl $0x3f, %edx
movq %rax, %rdi
callq 0x2210
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
callq 0x22c0
jmp 0x3ffc
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x22d0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq 0x4015(%rip), %rdi      # 0x7fd0
callq 0x2030
movq %rax, %rdi
callq 0x2130
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
callq 0x22c0
movq 0x8(%rsp), %r12
movq 0x3fcd(%rip), %rdi      # 0x7fd0
leaq 0x16a9(%rip), %rsi      # 0x56b3
movl $0x61, %edx
callq 0x2210
movb $0x0, (%rsp)
movq 0x3fc1(%rip), %rdi      # 0x7fe0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
xorl %esi, %esi
callq 0x22d0
movq 0x3fac(%rip), %rdi      # 0x7fe0
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
movl $0xa, %edx
callq 0x2100
movq 0x3f91(%rip), %rdi      # 0x7fe0
movq %rsp, %rsi
callq 0x2260
movb (%rsp), %al
andb $-0x21, %al
cmpb $0x4e, %al
jne 0x40f5
movq 0x3f65(%rip), %rdi      # 0x7fd0
leaq 0x16cc(%rip), %rsi      # 0x573e
movl $0x48, %edx
callq 0x2210
movq 0x3f4d(%rip), %rdi      # 0x7fd0
movq %r12, %rsi
callq 0x21c0
movq %rax, %r14
leaq 0x16f2(%rip), %rsi      # 0x5787
movl $0x12, %edx
movq %rax, %rdi
callq 0x2210
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
xorl %ebx, %ebx
movq 0x20(%rsp), %rdi
addq %rbx, %rdi
callq 0x2310
addq $0x8, %rbx
decq %r12
jne 0x40cb
jmp 0x41c9
movq %rax, %rdi
callq 0x20b0
callq 0x22c0
jmp 0x40d8
movq 0x3ed4(%rip), %rbx      # 0x7fd0
leaq 0x1612(%rip), %rsi      # 0x5715
movl $0x16, %edx
movq %rbx, %rdi
callq 0x2210
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq 0x3ea2(%rip), %rdi      # 0x7fd0
callq 0x2030
movq %rax, %rdi
callq 0x2130
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x22e0
xorl %ebx, %ebx
movq %r12, %r15
movq 0x20(%rsp), %rdi
addq %rbx, %rdi
callq 0x22f0
movq %r14, %rdi
callq 0x22e0
addq $0x8, %rbx
decq %r15
jne 0x414d
jmp 0x417c
movq %rax, %rdi
callq 0x20b0
callq 0x22c0
jmp 0x415a
movq 0x3e4d(%rip), %rdi      # 0x7fd0
movq %r12, %rsi
callq 0x21c0
movq %rax, %rbx
leaq 0x1597(%rip), %rsi      # 0x572c
movl $0x11, %edx
movq %rax, %rdi
callq 0x2210
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
leaq 0x20(%rsp), %rdi
callq 0x4332
leaq 0x40(%rsp), %rdi
callq 0x2340
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4213
jmp 0x4213
jmp 0x4213
jmp 0x4213
movq %rax, %rbx
callq 0x22c0
jmp 0x4216
movq %rax, %rbx
callq 0x22c0
jmp 0x4216
movq %rax, %rdi
callq 0x4326
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x4332
leaq 0x40(%rsp), %rdi
callq 0x2340
movq %rbx, %rdi
callq 0x2320