// File: /workspace/github_cpp_makefile_star2_O2/ninjabear[P]dr-doom/src/file_handles.cpp
// Function: many_open_file_handles()
void many_open_file_handles() {
    std::string temp_file_name = std::tmpnam(nullptr);
    std::vector<std::FILE*> file_handles;

    for (;;) {
        errno = 0; // reset this
        FILE* fp = fopen(temp_file_name.c_str(), "w");
        if (fp==NULL) {
            std::cout << "Failed to open handle to " << temp_file_name << " on iteration #" << file_handles.size() << std::endl; 
            std::cout << "Reason: " << std::strerror(errno) << " (" << errno << ")" << std::endl;
            break;
        }
        file_handles.push_back(fp);
    }

    std::cout << std::endl;
    std::cout << "Would you like to close the open file handles now? [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 << "Closing #" << file_handles.size() << " file handles" << std::endl;

        for (FILE* fh : file_handles) { 
            fclose(fh);
        }
    } else {
        std::cout << "Leaving #" << file_handles.size() << " file handles dangling on exit" << std::endl;
    }


}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x48, %rsp
xorl %edi, %edi
callq 0x2170
leaq 0x28(%rsp), %rdi
leaq 0x10(%rsp), %r14
movq %rax, %rsi
movq %r14, %rdx
callq 0x2b52
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
andq $0x0, 0x10(%r14)
callq 0x2030
movq %rax, %rbx
leaq 0x16ca(%rip), %r15      # 0x44e0
leaq 0x8(%rsp), %r12
andl $0x0, (%rbx)
movq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x2220
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x2e42
movq %r14, %rdi
movq %r12, %rsi
callq 0x3036
jmp 0x2e1b
movq 0x4187(%rip), %rdi      # 0x6fd0
leaq 0x1692(%rip), %rsi      # 0x44e2
callq 0x21e0
leaq 0x28(%rsp), %rsi
movq %rax, %rdi
callq 0x21a0
leaq 0x1693(%rip), %rsi      # 0x44fc
movq %rax, %rdi
callq 0x21e0
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x2130
movq %rax, %rdi
callq 0x20d0
movq 0x413a(%rip), %rdi      # 0x6fd0
leaq 0x166f(%rip), %rsi      # 0x450c
callq 0x21e0
movq %rax, %r14
movl (%rbx), %edi
callq 0x2080
movq %r14, %rdi
movq %rax, %rsi
callq 0x21e0
leaq 0x1657(%rip), %rsi      # 0x4515
movq %rax, %rdi
callq 0x21e0
movl (%rbx), %esi
movq %rax, %rdi
callq 0x22f0
leaq 0x1641(%rip), %rsi      # 0x4518
movq %rax, %rdi
callq 0x21e0
movq %rax, %rdi
callq 0x20d0
movq 0x40e2(%rip), %rdi      # 0x6fd0
callq 0x20d0
movq 0x40d6(%rip), %rdi      # 0x6fd0
leaq 0x1619(%rip), %rsi      # 0x451a
callq 0x21e0
movb $0x0, 0x8(%rsp)
movq 0x40ce(%rip), %rdi      # 0x6fe0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
xorl %esi, %esi
callq 0x22c0
movq 0x40b9(%rip), %rdi      # 0x6fe0
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
pushq $0xa
popq %rdx
callq 0x2100
movq 0x40a0(%rip), %rdi      # 0x6fe0
leaq 0x8(%rsp), %rsi
callq 0x2250
movb 0x8(%rsp), %al
andb $-0x21, %al
cmpb $0x4e, %al
jne 0x2fb4
movq 0x4075(%rip), %rdi      # 0x6fd0
leaq 0x160b(%rip), %rsi      # 0x456d
callq 0x21e0
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x2130
leaq 0x15f3(%rip), %rsi      # 0x4577
movq %rax, %rdi
callq 0x21e0
movq %rax, %rdi
callq 0x20d0
leaq 0x10(%rsp), %rdi
callq 0x305e
leaq 0x28(%rsp), %rdi
callq 0x2348
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x4015(%rip), %rdi      # 0x6fd0
leaq 0x1593(%rip), %rsi      # 0x4555
callq 0x21e0
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x2130
leaq 0x157b(%rip), %rsi      # 0x455f
movq %rax, %rdi
callq 0x21e0
movq %rax, %rdi
callq 0x20d0
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r14
cmpq %r14, %rbx
je 0x2f94
movq (%rbx), %rdi
callq 0x21f0
addq $0x8, %rbx
jmp 0x2ffe
jmp 0x3017
jmp 0x3017
jmp 0x3017
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x305e
leaq 0x28(%rsp), %rdi
callq 0x2348
movq %rbx, %rdi
callq 0x2310