// File: eniac[P]Mantis/src/compile/compile_c.cpp
// Function: extractReactionMacro(std::vector<AstNode*, std::allocator<AstNode*>>, std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void extractReactionMacro(std::vector<AstNode*> nodeArray, ostringstream& oss_preprocessor, string out_fn_base) {
    string cinclude_str = "";
    string cdefine_str = "";
	for (auto node : nodeArray) {
        if(typeContains(node, "IncludeNode")) {
            IncludeNode* includenode = dynamic_cast<IncludeNode*>(node);
            if(includenode->macrotype_==IncludeNode::C) {
                if(includenode->toString().find("include")!=string::npos) {
                    cinclude_str += includenode->toString();
                    cinclude_str += "\n";
                } else if (includenode->toString().find("define")!=string::npos) {
                    cdefine_str += includenode->toString();
                    cdefine_str += "\n";
                }
            }
        }
    }

    // Keep preprocessor other than include
    oss_preprocessor << cdefine_str;
    // Include preprocessor goes to seperate tmp file
    std::ofstream os;
    os.open(out_fn_base+"_mantis.include");
    os << cinclude_str << endl;
    os.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x390, %rsp            # imm = 0x390
movq %rdi, -0x358(%rbp)
movq %rdx, -0x350(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x348(%rbp)
callq 0xaaa70
movq -0x348(%rbp), %rdx
leaq 0x69140(%rip), %rsi     # 0x13bba3
leaq -0x38(%rbp), %rdi
callq 0xaa7d0
jmp 0xd2a6e
leaq -0x39(%rbp), %rdi
callq 0xaa5f0
leaq -0x71(%rbp), %rdi
movq %rdi, -0x360(%rbp)
callq 0xaaa70
movq -0x360(%rbp), %rdx
leaq 0x6910e(%rip), %rsi     # 0x13bba3
leaq -0x70(%rbp), %rdi
callq 0xaa7d0
jmp 0xd2aa0
leaq -0x71(%rbp), %rdi
callq 0xaa5f0
movq -0x358(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
callq 0xb2ae0
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rdi
callq 0xb2b10
movq %rax, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xb2b40
testb $0x1, %al
jne 0xd2af0
jmp 0xd2d62
leaq -0x88(%rbp), %rdi
callq 0xb2b80
movq (%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
leaq 0x67ddc(%rip), %rsi     # 0x13a8f0
callq 0x12c730
movb %al, -0x361(%rbp)
jmp 0xd2b21
movb -0x361(%rbp), %al
testb $0x1, %al
jne 0xd2b30
jmp 0xd2d4f
movq -0x98(%rbp), %rax
movq %rax, -0x370(%rbp)
cmpq $0x0, %rax
je 0xd2bb0
movq -0x370(%rbp), %rdi
leaq 0x9fa8e(%rip), %rsi     # 0x1725e0
leaq 0x9fe07(%rip), %rdx     # 0x172960
xorl %eax, %eax
movl %eax, %ecx
callq 0xaa660
movq %rax, -0x378(%rbp)
jmp 0xd2bbb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0xaa5f0
jmp 0xd2e68
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x71(%rbp), %rdi
callq 0xaa5f0
jmp 0xd2e5f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xd2e56
xorl %eax, %eax
movq %rax, -0x378(%rbp)
jmp 0xd2bbb
movq -0x378(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
cmpl $0x1, 0x48(%rax)
jne 0xd2d4d
movq -0xa0(%rbp), %rsi
movq (%rsi), %rax
movq (%rax), %rax
leaq -0xc0(%rbp), %rdi
callq *%rax
jmp 0xd2bf2
leaq -0xc0(%rbp), %rdi
leaq 0x67d0b(%rip), %rsi     # 0x13a90b
xorl %eax, %eax
movl %eax, %edx
callq 0xaab90
movq %rax, -0x380(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xaabe8
movq -0x380(%rbp), %rax
cmpq $-0x1, %rax
je 0xd2c93
movq -0xa0(%rbp), %rsi
movq (%rsi), %rax
movq (%rax), %rax
leaq -0xe0(%rbp), %rdi
callq *%rax
jmp 0xd2c41
leaq -0x38(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0xaa710
jmp 0xd2c53
leaq -0xe0(%rbp), %rdi
callq 0xaabe8
leaq 0x6716e(%rip), %rsi     # 0x139dd4
leaq -0x38(%rbp), %rdi
callq 0xaa510
jmp 0xd2c71
jmp 0xd2d4b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0xaabe8
jmp 0xd2e56
movq -0xa0(%rbp), %rsi
movq (%rsi), %rax
movq (%rax), %rax
leaq -0x100(%rbp), %rdi
callq *%rax
jmp 0xd2cab
leaq -0x100(%rbp), %rdi
leaq 0x67c43(%rip), %rsi     # 0x13a8fc
xorl %eax, %eax
movl %eax, %edx
callq 0xaab90
movq %rax, -0x388(%rbp)
leaq -0x100(%rbp), %rdi
callq 0xaabe8
movq -0x388(%rbp), %rax
cmpq $-0x1, %rax
je 0xd2d49
movq -0xa0(%rbp), %rsi
movq (%rsi), %rax
movq (%rax), %rax
leaq -0x120(%rbp), %rdi
callq *%rax
jmp 0xd2cfa
leaq -0x70(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0xaa710
jmp 0xd2d0c
leaq -0x120(%rbp), %rdi
callq 0xaabe8
leaq 0x670b5(%rip), %rsi     # 0x139dd4
leaq -0x70(%rbp), %rdi
callq 0xaa510
jmp 0xd2d2a
jmp 0xd2d49
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x120(%rbp), %rdi
callq 0xaabe8
jmp 0xd2e56
jmp 0xd2d4b
jmp 0xd2d4d
jmp 0xd2d4f
jmp 0xd2d51
leaq -0x88(%rbp), %rdi
callq 0xb2ba0
jmp 0xd2ad4
movq -0x10(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xaa4c0
jmp 0xd2d71
leaq -0x320(%rbp), %rdi
callq 0xaa9e0
jmp 0xd2d7f
movq -0x350(%rbp), %rsi
leaq 0x67b76(%rip), %rdx     # 0x13a903
leaq -0x340(%rbp), %rdi
callq 0xcb380
jmp 0xd2d9b
leaq -0x320(%rbp), %rdi
leaq -0x340(%rbp), %rsi
movl $0x10, %edx
callq 0xaa2e0
jmp 0xd2db5
leaq -0x340(%rbp), %rdi
callq 0xaabe8
leaq -0x320(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0xaa4c0
movq %rax, -0x390(%rbp)
jmp 0xd2dda
movq -0x390(%rbp), %rdi
movq 0xa1180(%rip), %rsi     # 0x173f68
callq 0xaa5b0
jmp 0xd2def
leaq -0x320(%rbp), %rdi
callq 0xaa820
jmp 0xd2dfd
leaq -0x320(%rbp), %rdi
callq 0xaa8c0
leaq -0x70(%rbp), %rdi
callq 0xaabe8
leaq -0x38(%rbp), %rdi
callq 0xaabe8
addq $0x390, %rsp            # imm = 0x390
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xd2e4a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x340(%rbp), %rdi
callq 0xaabe8
leaq -0x320(%rbp), %rdi
callq 0xaa8c0
leaq -0x70(%rbp), %rdi
callq 0xaabe8
leaq -0x38(%rbp), %rdi
callq 0xaabe8
movq -0x48(%rbp), %rdi
callq 0xaaa60
nopw %cs:(%rax,%rax)