// File: /workspace/github_cpp_makefile_star2_O2/JameyWoo[P]csmile/assembly.cpp
// Function: genOutput(TreeNode*, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>)
void genOutput(TreeNode* output, map<string, string> var2stack) {
    // debug("in output: " + output->child[0]->nodekind);
    // debug("in output value: " + to_string(output->child[0]->val));
    if (output->child[0]->nodekind == "Const") {
        assout << "\t"
               << "movl\t$.LC0, %eax" << endl
               << "\t"
               << "movl"
               << "\t"
               << "$" << to_string(output->child[0]->val)
               << ", 4(%esp)" << endl
               << "\t"
               << "movl"
               << "\t"
               << "%eax, (%esp)"
               << "\n\t"
               << "call\tprintf" << endl;
    } else if (output->child[0]->nodekind == "Id") {
        // debug("id: " + output->child[0]->name);
        string id_loc = var2stack[output->child[0]->name];
        assout << "\tmovl\t" << id_loc << ", %edx" << endl
               << "\t"
               << "movl\t$.LC0, %eax" << endl
               << "\t"
               << "movl"
               << "\t"
               << "%edx"
               << ", 4(%esp)" << endl
               << "\t"
               << "movl"
               << "\t"
               << "%eax, (%esp)"
               << "\n\t"
               << "call\tprintf" << endl;
    } else if (output->child[0]->nodekind == "Call") {
        genCall(output->child[0], var2stack);
        // call 的结果在 %eax中
        assout << "\tmovl\t%eax, 4(%esp)" << endl
               << "\tmovl\t$.LC0, %eax" << endl
               << "\tmovl\t%eax, (%esp)" << endl
               << "\tcall\tprintf" << endl;
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x50, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rdi
addq $0x30, %rdi
leaq 0x49c6(%rip), %rsi      # 0xf265
callq 0x368e
testb %al, %al
je 0xa9ad
leaq 0xc32d(%rip), %rdi      # 0x16be0
leaq 0x4e5a(%rip), %r14      # 0xf714
movq %r14, %rsi
callq 0x21b0
leaq 0x4e69(%rip), %rsi      # 0xf732
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
movq %rax, %rdi
movq %r14, %rsi
callq 0x21b0
leaq 0x4e23(%rip), %rsi      # 0xf70e
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
movq %r14, %rsi
callq 0x21b0
leaq 0x4ed2(%rip), %rsi      # 0xf7d7
movq %rax, %rdi
callq 0x21b0
movq %rax, %r14
movq (%rbx), %rax
movl 0xb8(%rax), %esi
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x7cbf
movq %r14, %rdi
movq %rbx, %rsi
callq 0x21a0
leaq 0x4df1(%rip), %rsi      # 0xf727
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
leaq 0x4dc7(%rip), %rsi      # 0xf714
movq %rax, %rdi
callq 0x21b0
leaq 0x4db2(%rip), %rsi      # 0xf70e
movq %rax, %rdi
callq 0x21b0
leaq 0x4da9(%rip), %rsi      # 0xf714
movq %rax, %rdi
callq 0x21b0
leaq 0x4dcf(%rip), %rsi      # 0xf749
movq %rax, %rdi
callq 0x21b0
leaq 0x4d8a(%rip), %rsi      # 0xf713
movq %rax, %rdi
callq 0x21b0
leaq 0x4dbf(%rip), %rsi      # 0xf757
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
jmp 0xaaf3
movq (%rbx), %rdi
addq $0x30, %rdi
leaq 0x486d(%rip), %rsi      # 0xf228
callq 0x368e
testb %al, %al
je 0xab05
movl $0xc0, %esi
addq (%rbx), %rsi
movq %r14, %rdi
callq 0x7c16
movq %rsp, %rdi
movq %rax, %rsi
callq 0x2250
leaq 0xc1f6(%rip), %rdi      # 0x16be0
leaq 0x4d25(%rip), %rsi      # 0xf716
callq 0x21b0
movq %rsp, %rsi
movq %rax, %rdi
callq 0x21a0
leaq 0x4e50(%rip), %rsi      # 0xf858
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
leaq 0x4cf5(%rip), %rsi      # 0xf714
movq %rax, %rdi
callq 0x21b0
leaq 0x4d04(%rip), %rsi      # 0xf732
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
leaq 0x4ccf(%rip), %rsi      # 0xf714
movq %rax, %rdi
callq 0x21b0
leaq 0x4cba(%rip), %rsi      # 0xf70e
movq %rax, %rdi
callq 0x21b0
leaq 0x4cb1(%rip), %rsi      # 0xf714
movq %rax, %rdi
callq 0x21b0
leaq 0x4de8(%rip), %rsi      # 0xf85a
movq %rax, %rdi
callq 0x21b0
leaq 0x4ca6(%rip), %rsi      # 0xf727
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
leaq 0x4c7c(%rip), %rsi      # 0xf714
movq %rax, %rdi
callq 0x21b0
leaq 0x4c67(%rip), %rsi      # 0xf70e
movq %rax, %rdi
callq 0x21b0
leaq 0x4c5e(%rip), %rsi      # 0xf714
movq %rax, %rdi
callq 0x21b0
leaq 0x4c84(%rip), %rsi      # 0xf749
movq %rax, %rdi
callq 0x21b0
leaq 0x4c3f(%rip), %rsi      # 0xf713
movq %rax, %rdi
callq 0x21b0
leaq 0x4c74(%rip), %rsi      # 0xf757
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
movq %rsp, %rdi
callq 0x2358
addq $0x50, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq (%rbx), %rdi
addq $0x30, %rdi
leaq 0x4743(%rip), %rsi      # 0xf256
callq 0x368e
testb %al, %al
je 0xaafb
movq (%rbx), %rbx
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xd3ce
movq %rbx, %rdi
movq %r15, %rsi
callq 0xabcd
leaq 0x20(%rsp), %rdi
callq 0x7b9c
leaq 0xc095(%rip), %rdi      # 0x16be0
leaq 0x4bcb(%rip), %rsi      # 0xf71d
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
leaq 0x4bcb(%rip), %rsi      # 0xf731
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
leaq 0x4bc6(%rip), %rsi      # 0xf743
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
leaq 0x4bc2(%rip), %rsi      # 0xf756
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
jmp 0xaafb
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x7b9c
jmp 0xabc5
jmp 0xabba
movq %rax, %rbx
movq %rsp, %rdi
callq 0x2358
movq %rbx, %rdi
callq 0x2300