// File: 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 %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rsi, -0x98(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
addq $0x30, %rdi
leaq 0x954d(%rip), %rsi      # 0x211e9
callq 0x5e70
testb $0x1, %al
jne 0x17caa
jmp 0x17e7b
leaq 0x16ff7(%rip), %rdi     # 0x2eca8
leaq 0x99dc(%rip), %rsi      # 0x21694
movq %rsi, -0xb8(%rbp)
callq 0x3270
movq %rax, %rdi
leaq 0x99e4(%rip), %rsi      # 0x216b2
callq 0x3270
movq %rax, %rdi
movq 0x162d3(%rip), %rsi     # 0x2dfb0
callq 0x32b0
movq -0xb8(%rbp), %rsi
movq %rax, %rdi
callq 0x3270
movq %rax, %rdi
leaq 0x9993(%rip), %rsi      # 0x2168e
callq 0x3270
movq -0xb8(%rbp), %rsi
movq %rax, %rdi
callq 0x3270
movq %rax, %rdi
leaq 0x9a3e(%rip), %rsi      # 0x21757
callq 0x3270
movq %rax, -0xb0(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0xb8(%rax), %esi
leaq -0x30(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0xf460
movq -0xb0(%rbp), %rdi
movq -0xa8(%rbp), %rsi
callq 0x3240
movq %rax, -0xa0(%rbp)
jmp 0x17d5e
movq -0xa0(%rbp), %rdi
leaq 0x993b(%rip), %rsi      # 0x216a7
callq 0x3270
movq %rax, -0xc0(%rbp)
jmp 0x17d7a
movq -0xc0(%rbp), %rdi
movq 0x16228(%rip), %rsi     # 0x2dfb0
callq 0x32b0
movq %rax, -0xc8(%rbp)
jmp 0x17d96
movq -0xc8(%rbp), %rdi
leaq 0x98f0(%rip), %rsi      # 0x21694
callq 0x3270
movq %rax, -0xd0(%rbp)
jmp 0x17db2
movq -0xd0(%rbp), %rdi
leaq 0x98ce(%rip), %rsi      # 0x2168e
callq 0x3270
movq %rax, -0xd8(%rbp)
jmp 0x17dce
movq -0xd8(%rbp), %rdi
leaq 0x98b8(%rip), %rsi      # 0x21694
callq 0x3270
movq %rax, -0xe0(%rbp)
jmp 0x17dea
movq -0xe0(%rbp), %rdi
leaq 0x98d1(%rip), %rsi      # 0x216c9
callq 0x3270
movq %rax, -0xe8(%rbp)
jmp 0x17e06
movq -0xe8(%rbp), %rdi
leaq 0x987f(%rip), %rsi      # 0x21693
callq 0x3270
movq %rax, -0xf0(%rbp)
jmp 0x17e22
movq -0xf0(%rbp), %rdi
leaq 0x98a7(%rip), %rsi      # 0x216d7
callq 0x3270
movq %rax, -0xf8(%rbp)
jmp 0x17e3e
movq -0xf8(%rbp), %rdi
movq 0x16164(%rip), %rsi     # 0x2dfb0
callq 0x32b0
jmp 0x17e53
leaq -0x30(%rbp), %rdi
callq 0x34e8
jmp 0x18214
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x34e8
jmp 0x1821d
movq -0x8(%rbp), %rax
movq (%rax), %rdi
addq $0x30, %rdi
leaq 0x931f(%rip), %rsi      # 0x211ac
callq 0x5e70
testb $0x1, %al
jne 0x17e9b
jmp 0x1810f
movq -0x98(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rsi
addq $0xc0, %rsi
callq 0xf2e0
movq %rax, %rsi
leaq -0x60(%rbp), %rdi
callq 0x3120
leaq 0x16de0(%rip), %rdi     # 0x2eca8
leaq 0x97c7(%rip), %rsi      # 0x21696
callq 0x3270
movq %rax, -0x100(%rbp)
jmp 0x17edd
movq -0x100(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x3240
movq %rax, -0x108(%rbp)
jmp 0x17ef6
movq -0x108(%rbp), %rdi
leaq 0x98d4(%rip), %rsi      # 0x217d8
callq 0x3270
movq %rax, -0x110(%rbp)
jmp 0x17f12
movq -0x110(%rbp), %rdi
movq 0x16090(%rip), %rsi     # 0x2dfb0
callq 0x32b0
movq %rax, -0x118(%rbp)
jmp 0x17f2e
movq -0x118(%rbp), %rdi
leaq 0x9758(%rip), %rsi      # 0x21694
callq 0x3270
movq %rax, -0x120(%rbp)
jmp 0x17f4a
movq -0x120(%rbp), %rdi
leaq 0x975a(%rip), %rsi      # 0x216b2
callq 0x3270
movq %rax, -0x128(%rbp)
jmp 0x17f66
movq -0x128(%rbp), %rdi
movq 0x1603c(%rip), %rsi     # 0x2dfb0
callq 0x32b0
movq %rax, -0x130(%rbp)
jmp 0x17f82
movq -0x130(%rbp), %rdi
leaq 0x9704(%rip), %rsi      # 0x21694
callq 0x3270
movq %rax, -0x138(%rbp)
jmp 0x17f9e
movq -0x138(%rbp), %rdi
leaq 0x96e2(%rip), %rsi      # 0x2168e
callq 0x3270
movq %rax, -0x140(%rbp)
jmp 0x17fba
movq -0x140(%rbp), %rdi
leaq 0x96cc(%rip), %rsi      # 0x21694
callq 0x3270
movq %rax, -0x148(%rbp)
jmp 0x17fd6
movq -0x148(%rbp), %rdi
leaq 0x97f6(%rip), %rsi      # 0x217da
callq 0x3270
movq %rax, -0x150(%rbp)
jmp 0x17ff2
movq -0x150(%rbp), %rdi
leaq 0x96a7(%rip), %rsi      # 0x216a7
callq 0x3270
movq %rax, -0x158(%rbp)
jmp 0x1800e
movq -0x158(%rbp), %rdi
movq 0x15f94(%rip), %rsi     # 0x2dfb0
callq 0x32b0
movq %rax, -0x160(%rbp)
jmp 0x1802a
movq -0x160(%rbp), %rdi
leaq 0x965c(%rip), %rsi      # 0x21694
callq 0x3270
movq %rax, -0x168(%rbp)
jmp 0x18046
movq -0x168(%rbp), %rdi
leaq 0x963a(%rip), %rsi      # 0x2168e
callq 0x3270
movq %rax, -0x170(%rbp)
jmp 0x18062
movq -0x170(%rbp), %rdi
leaq 0x9624(%rip), %rsi      # 0x21694
callq 0x3270
movq %rax, -0x178(%rbp)
jmp 0x1807e
movq -0x178(%rbp), %rdi
leaq 0x963d(%rip), %rsi      # 0x216c9
callq 0x3270
movq %rax, -0x180(%rbp)
jmp 0x1809a
movq -0x180(%rbp), %rdi
leaq 0x95eb(%rip), %rsi      # 0x21693
callq 0x3270
movq %rax, -0x188(%rbp)
jmp 0x180b6
movq -0x188(%rbp), %rdi
leaq 0x9613(%rip), %rsi      # 0x216d7
callq 0x3270
movq %rax, -0x190(%rbp)
jmp 0x180d2
movq -0x190(%rbp), %rdi
movq 0x15ed0(%rip), %rsi     # 0x2dfb0
callq 0x32b0
jmp 0x180e7
leaq -0x60(%rbp), %rdi
callq 0x34e8
jmp 0x18212
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x34e8
jmp 0x1821d
movq -0x8(%rbp), %rax
movq (%rax), %rdi
addq $0x30, %rdi
leaq 0x90b9(%rip), %rsi      # 0x211da
callq 0x5e70
testb $0x1, %al
jne 0x1812f
jmp 0x18210
movq -0x98(%rbp), %rsi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x1a0(%rbp)
leaq -0x90(%rbp), %rdi
movq %rdi, -0x198(%rbp)
callq 0x1c040
movq -0x1a0(%rbp), %rdi
movq -0x198(%rbp), %rsi
callq 0x18230
jmp 0x1816c
leaq -0x90(%rbp), %rdi
callq 0xee40
leaq 0x16b29(%rip), %rdi     # 0x2eca8
leaq 0x9517(%rip), %rsi      # 0x2169d
callq 0x3270
movq %rax, %rdi
movq 0x15e1b(%rip), %rsi     # 0x2dfb0
callq 0x32b0
movq %rax, %rdi
leaq 0x950d(%rip), %rsi      # 0x216b1
callq 0x3270
movq %rax, %rdi
movq 0x15dfd(%rip), %rsi     # 0x2dfb0
callq 0x32b0
movq %rax, %rdi
leaq 0x9501(%rip), %rsi      # 0x216c3
callq 0x3270
movq %rax, %rdi
movq 0x15ddf(%rip), %rsi     # 0x2dfb0
callq 0x32b0
movq %rax, %rdi
leaq 0x94f6(%rip), %rsi      # 0x216d6
callq 0x3270
movq %rax, %rdi
movq 0x15dc1(%rip), %rsi     # 0x2dfb0
callq 0x32b0
jmp 0x18210
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xee40
jmp 0x1821d
jmp 0x18212
jmp 0x18214
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x3470
nopw %cs:(%rax,%rax)