// File: /workspace/github_cpp_makefile_star2_O2/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 0x2260
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %r14
andq $0x0, 0x20(%r14)
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
leaq 0x20(%rsp), %r15
movaps %xmm0, (%r15)
andq $0x0, 0x10(%r15)
pushq $0x1
popq %rax
movq %rax, (%rsp)
leaq 0x2d4(%rip), %r12       # 0x3931
leaq 0x8(%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 0x3982
movq %r15, %rdi
movq %r13, %rsi
callq 0x3af6
movq %r13, %rdi
callq 0x2dac
incq (%rsp)
jmp 0x366c
movq %rdx, %rbx
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x2dac
jmp 0x36bd
movq %rdx, %rbx
movq %rax, %r14
movq %r14, %rdi
callq 0x20a0
cmpl $0x2, %ebx
jne 0x373a
movq %rax, %r14
movq 0x38fc(%rip), %rdi      # 0x6fd0
leaq 0xf5c(%rip), %rsi       # 0x4637
callq 0x21e0
movq %rax, %rdi
movq (%rsp), %rsi
callq 0x21d0
leaq 0xf94(%rip), %rsi       # 0x4687
movq %rax, %rdi
callq 0x21e0
movq %rax, %rdi
callq 0x20d0
movq %rax, %rdi
callq 0x20d0
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
movq 0x38b5(%rip), %rdi      # 0x6fd0
movq %rax, %rsi
callq 0x21e0
movq %rax, %rdi
callq 0x20d0
movq %rax, %rdi
callq 0x20d0
callq 0x22b0
jmp 0x377d
movq 0x388f(%rip), %rdi      # 0x6fd0
leaq 0xeef(%rip), %rsi       # 0x4637
callq 0x21e0
movq %rax, %rdi
movq (%rsp), %rsi
callq 0x21d0
leaq 0xee7(%rip), %rsi       # 0x4647
movq %rax, %rdi
callq 0x21e0
movq %rax, %rdi
callq 0x20d0
movq %rax, %rdi
callq 0x20d0
callq 0x22b0
movq 0x384c(%rip), %rdi      # 0x6fd0
leaq 0xf28(%rip), %rsi       # 0x46b3
callq 0x21e0
movb $0x0, 0x8(%rsp)
movq 0x3844(%rip), %rdi      # 0x6fe0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
xorl %esi, %esi
callq 0x22c0
movq 0x382f(%rip), %rdi      # 0x6fe0
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
pushq $0xa
popq %rdx
callq 0x2100
movq 0x3816(%rip), %rdi      # 0x6fe0
leaq 0x8(%rsp), %rsi
callq 0x2250
movb 0x8(%rsp), %al
andb $-0x21, %al
cmpb $0x4e, %al
jne 0x3843
movq 0x37eb(%rip), %rdi      # 0x6fd0
leaq 0xf52(%rip), %rsi       # 0x473e
callq 0x21e0
movq %rax, %rdi
movq (%rsp), %rsi
callq 0x21d0
leaq 0xf83(%rip), %rsi       # 0x4787
movq %rax, %rdi
callq 0x21e0
movq %rax, %rdi
callq 0x20d0
xorl %ebx, %ebx
subq $0x1, (%rsp)
jb 0x38c8
movq 0x20(%rsp), %rdi
addq %rbx, %rdi
callq 0x2300
addq $0x8, %rbx
jmp 0x3816
movq %rax, %rdi
callq 0x20a0
callq 0x22b0
jmp 0x382e
movq 0x3786(%rip), %rdi      # 0x6fd0
leaq 0xec4(%rip), %rsi       # 0x4715
callq 0x21e0
movq %rax, %rdi
callq 0x20d0
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x22d0
xorl %ebx, %ebx
movq (%rsp), %r15
subq $0x1, %r15
jb 0x38a1
movq 0x20(%rsp), %rdi
addq %rbx, %rdi
callq 0x22e0
movq %r14, %rdi
callq 0x22d0
addq $0x8, %rbx
jmp 0x3871
movq %rax, %rdi
callq 0x20a0
callq 0x22b0
jmp 0x3884
movq 0x3728(%rip), %rdi      # 0x6fd0
movq (%rsp), %rsi
callq 0x21d0
leaq 0xe74(%rip), %rsi       # 0x472c
movq %rax, %rdi
callq 0x21e0
movq %rax, %rdi
callq 0x20d0
leaq 0x20(%rsp), %rdi
callq 0x3a04
leaq 0x40(%rsp), %rdi
callq 0x2330
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3912
jmp 0x3912
jmp 0x3912
jmp 0x3912
movq %rax, %rbx
callq 0x22b0
jmp 0x3915
movq %rax, %rbx
callq 0x22b0
jmp 0x3915
movq %rax, %rdi
callq 0x3053
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x3a04
leaq 0x40(%rsp), %rdi
callq 0x2330
movq %rbx, %rdi
callq 0x2310