// File: /workspace/github_cpp_makefile_star2_O1/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, 0x28(%rsp)
leaq 0x70(%rsp), %r15
movq %r15, %rdi
callq 0x276d
leaq 0x265f(%rip), %rsi      # 0x50a5
movq %r15, %rdi
callq 0x2350
leaq 0xf0(%rsp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq %rax, (%rsp)
movq %rcx, 0x48(%rsp)
cmpq %rcx, %rax
je 0x2cc6
leaq 0x18(%rsp), %rbx
movq 0x28(%rsp), %rax
leaq 0x10(%rax), %r15
leaq 0x90(%rsp), %r12
leaq 0x8(%rsp), %r13
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movaps %xmm0, 0xd0(%rsp)
movaps %xmm0, 0xc0(%rsp)
movaps %xmm0, 0xb0(%rsp)
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movq %r12, %rdi
xorl %esi, %esi
callq 0x40e4
movq %r12, %rdi
movq (%rsp), %rsi
callq 0x425c
movq 0xa0(%rsp), %rax
cmpq %rax, 0xc0(%rsp)
je 0x2ba5
movq %rbx, 0x8(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x3bd6
movq %r12, %rdi
callq 0x44f6
leaq 0xe8(%rsp), %rdi
movq %r13, %rsi
callq 0x4584
leaq 0xf0(%rsp), %rcx
cmpq %rcx, %rax
je 0x2b5c
movq 0x8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x2af1
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x2af1
leaq 0xe8(%rsp), %rdi
movq %r13, %rsi
callq 0x460e
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x36b2
leaq 0x5678(%rip), %rdi      # 0x81f8
movq %r13, %rsi
callq 0x36f0
movq (%rax), %r14
movq 0x8(%rax), %rbp
cmpq %rbp, %r14
je 0x2b43
movq %r12, %rdi
movq %r14, %rsi
callq 0x425c
addq $0x20, %r14
jmp 0x2b8f
movq 0x38(%rsp), %r14
subq 0x30(%rsp), %r14
shrq $0x5, %r14
decl %r14d
cmpl $-0x1, %r14d
je 0x2c9d
movslq %r14d, %rdx
shlq $0x5, %rdx
addq 0x30(%rsp), %rdx
leaq 0x50(%rsp), %rbp
movq %rbp, %rdi
leaq 0x70(%rsp), %rsi
callq 0x376c
movq %rbp, %rdi
leaq 0x24c2(%rip), %rsi      # 0x50aa
callq 0x2350
movq %rbx, 0x8(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x2c10
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x2c16
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
movq %rdx, 0x10(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x2823
movq 0x8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x2c52
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x2c6e
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2200
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
decl %r14d
movq %rax, %rdi
callq 0x2150
jmp 0x2bb6
movq %r12, %rdi
callq 0x39c0
leaq 0x30(%rsp), %rdi
callq 0x35c8
movq (%rsp), %rax
addq $0x20, %rax
movq %rax, (%rsp)
cmpq 0x48(%rsp), %rax
jne 0x2aa2
leaq 0xe8(%rsp), %rdi
callq 0x3b5e
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2cf4
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2200
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x2d97
movq %rax, %r14
jmp 0x2d80
jmp 0x2d54
jmp 0x2d59
jmp 0x2d59
jmp 0x2d59
jmp 0x2d54
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x2d3e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x2d3e
jmp 0x2d54
movq %rax, %r14
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x2d73
movq 0x60(%rsp), %rsi
jmp 0x2d6b
movq %rax, %r14
jmp 0x2d73
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x2d73
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x90(%rsp), %rdi
callq 0x39c0
leaq 0x30(%rsp), %rdi
callq 0x35c8
leaq 0xe8(%rsp), %rdi
callq 0x3b5e
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2db8
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r14, %rdi
callq 0x2320