// File: /workspace/github_cpp_makefile_star2_O3/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       # 0x4262
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 0x42c0
movq %r15, %rdi
movq %r13, %rsi
callq 0x43f2
cmpq $0x0, (%rsp)
jne 0x3e35
incq 0x8(%rsp)
jmp 0x3df5
cmpq $0x0, (%rsp)
je 0x3e3a
callq 0x2060
movq %rdx, %rbx
movq %rax, %rdi
callq 0x20b0
cmpl $0x2, %ebx
jne 0x3f1a
movq %rax, %r15
movq 0x4178(%rip), %rdi      # 0x7fd0
leaq 0x17d8(%rip), %rsi      # 0x5637
movl $0xf, %edx
callq 0x2210
movq 0x4160(%rip), %r14      # 0x7fd0
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0x21c0
movq %rax, %r12
leaq 0x1800(%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 0x3fb5
movq %rax, %rbx
movq %rax, %rdi
callq 0x20c0
movq 0x40c6(%rip), %rdi      # 0x7fd0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2210
jmp 0x3fcd
movq 0x40af(%rip), %rdi      # 0x7fd0
leaq 0x170f(%rip), %rsi      # 0x5637
movl $0xf, %edx
callq 0x2210
movq 0x8(%rsp), %r12
movq 0x4092(%rip), %rdi      # 0x7fd0
movq %r12, %rsi
callq 0x21c0
movq %rax, %r14
leaq 0x16f7(%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 0x402c
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 0x3fe5(%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 0x3f9d(%rip), %rdi      # 0x7fd0
leaq 0x1679(%rip), %rsi      # 0x56b3
movl $0x61, %edx
callq 0x2210
movb $0x0, (%rsp)
movq 0x3f91(%rip), %rdi      # 0x7fe0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
xorl %esi, %esi
callq 0x22d0
movq 0x3f7c(%rip), %rdi      # 0x7fe0
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
movl $0xa, %edx
callq 0x2100
movq 0x3f61(%rip), %rdi      # 0x7fe0
movq %rsp, %rsi
callq 0x2260
movb (%rsp), %al
andb $-0x21, %al
cmpb $0x4e, %al
jne 0x4125
movq 0x3f35(%rip), %rdi      # 0x7fd0
leaq 0x169c(%rip), %rsi      # 0x573e
movl $0x48, %edx
callq 0x2210
movq 0x3f1d(%rip), %rdi      # 0x7fd0
movq %r12, %rsi
callq 0x21c0
movq %rax, %r14
leaq 0x16c2(%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 0x40fb
jmp 0x41f9
movq %rax, %rdi
callq 0x20b0
callq 0x22c0
jmp 0x4108
movq 0x3ea4(%rip), %rbx      # 0x7fd0
leaq 0x15e2(%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 0x3e72(%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 0x417d
jmp 0x41ac
movq %rax, %rdi
callq 0x20b0
callq 0x22c0
jmp 0x418a
movq 0x3e1d(%rip), %rdi      # 0x7fd0
movq %r12, %rsi
callq 0x21c0
movq %rax, %rbx
leaq 0x1567(%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 0x4352
leaq 0x40(%rsp), %rdi
callq 0x2340
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4243
jmp 0x4243
jmp 0x4243
jmp 0x4243
movq %rax, %rbx
callq 0x22c0
jmp 0x4246
movq %rax, %rbx
callq 0x22c0
jmp 0x4246
movq %rax, %rdi
callq 0x4346
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x4352
leaq 0x40(%rsp), %rdi
callq 0x2340
movq %rbx, %rdi
callq 0x2320