// File: /workspace/github_cpp_makefile_star2_O2/calgagi[P]cp_gen/main.cpp
// Function: output_templates(std::basic_fstream<char, std::char_traits<char>>&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&)
void output_templates(fstream& new_file, const vector<string>& templates) {
    // this assumes that gen is in the root directory of cp_gen (where lib is)
    string gen_path = pathToGen();
    gen_path += "lib/";

    set<string> already_outputted;

    for (const string& ds : templates) {
        vector<string> to_output;

        queue<string> q;
        q.push(ds);

        // perform BFS on dependency graph
        while (!q.empty()) {
            string cur_lib = q.front();
            q.pop();
            if (already_outputted.find(cur_lib) != already_outputted.end()) {
                continue;
            }
            already_outputted.insert(cur_lib);
            to_output.push_back(cur_lib);
            for (const string& dep : dep_graph[cur_lib]) {
                q.push(dep);
            }
        }
        
        // output files in reverse visited order
        for (int i = to_output.size() - 1; ~i; i--) {
            output_file(new_file, gen_path + to_output[i] + ".hpp");
            new_file << endl;
        }
    }

    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x68(%rsp), %r15
movq %r15, %rdi
callq 0x2687
leaq 0x2852(%rip), %rsi      # 0x50c1
movq %r15, %rdi
callq 0x22f0
leaq 0x40(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq %rcx, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
leaq 0x10(%rbx), %r15
leaq 0xc8(%rsp), %r12
leaq 0xa8(%rsp), %rbp
leaq 0x88(%rsp), %r14
cmpq 0x28(%rsp), %rax
je 0x2a06
movq %rax, 0x8(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movq %r12, %rdi
callq 0x30ae
movq %r12, %rdi
movq 0x8(%rsp), %rsi
callq 0x3c22
movq 0xd8(%rsp), %rsi
cmpq %rsi, 0xf8(%rsp)
je 0x297a
movq %r14, %rdi
callq 0x2270
movq %r12, %rdi
callq 0x3e98
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x3f02
leaq 0x40(%rsp), %rcx
cmpq %rcx, %rax
je 0x2934
movq %r14, %rdi
callq 0x2338
jmp 0x28f1
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x3f78
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x30ca
leaq 0x588b(%rip), %rdi      # 0x81e0
movq %r14, %rsi
callq 0x30f6
movq (%rax), %r13
movq 0x8(%rax), %rbx
cmpq %rbx, %r13
je 0x292a
movq %r12, %rdi
movq %r13, %rsi
callq 0x3c22
addq $0x20, %r13
jmp 0x2964
movq 0x18(%rsp), %r13
subq 0x10(%rsp), %r13
shrq $0x5, %r13
decl %r13d
cmpl $-0x1, %r13d
je 0x29e6
movslq %r13d, %rdx
shlq $0x5, %rdx
addq 0x10(%rsp), %rdx
movq %rbp, %rdi
leaq 0x68(%rsp), %rsi
callq 0x315c
movq %r14, %rdi
movq %rbp, %rsi
leaq 0x270f(%rip), %rdx      # 0x50c6
callq 0x300f
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x270f
movq %r14, %rdi
callq 0x2338
movq %rbp, %rdi
callq 0x2338
decl %r13d
movq %r15, %rdi
callq 0x2100
jmp 0x298b
movq %r12, %rdi
callq 0x33e8
leaq 0x10(%rsp), %rdi
callq 0x2fe8
movq 0x8(%rsp), %rax
addq $0x20, %rax
jmp 0x28be
leaq 0x38(%rsp), %rdi
callq 0x3514
leaq 0x68(%rsp), %rdi
callq 0x2338
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x2a97
movq %rax, %rbx
jmp 0x2a83
jmp 0x2a5f
jmp 0x2a66
jmp 0x2a66
jmp 0x2a5f
movq %rax, %rbx
jmp 0x2a53
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x2338
leaq 0xa8(%rsp), %rdi
jmp 0x2a71
jmp 0x2a5f
movq %rax, %rbx
jmp 0x2a76
jmp 0x2a66
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x2338
leaq 0xc8(%rsp), %rdi
callq 0x33e8
leaq 0x10(%rsp), %rdi
callq 0x2fe8
leaq 0x38(%rsp), %rdi
callq 0x3514
leaq 0x68(%rsp), %rdi
callq 0x2338
movq %rbx, %rdi
callq 0x22d0