// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq (%rdi), %rdi
addq $0x30, %rdi
leaq 0x643d(%rip), %rsi      # 0x15265
callq 0x2090
testl %eax, %eax
je 0xef98
movq (%r14), %rdi
addq $0x30, %rdi
leaq 0x63dd(%rip), %rsi      # 0x15220
callq 0x2090
testl %eax, %eax
je 0xf0b1
movq (%r14), %rdi
addq $0x30, %rdi
leaq 0x63f8(%rip), %rsi      # 0x15256
callq 0x2090
testl %eax, %eax
jne 0xf424
movq (%r14), %r14
leaq 0x28(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x13e16
movq %r14, %rdi
movq %r15, %rsi
callq 0xf473
leaq 0x28(%rsp), %rdi
callq 0xab5a
leaq 0xcd46(%rip), %rbx      # 0x1bbe0
leaq 0x6893(%rip), %rsi      # 0x15734
movl $0x13, %edx
movq %rbx, %rdi
callq 0x2220
movq 0xcd2b(%rip), %rax      # 0x1bbe0
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq %rax, %rbx
leaq 0x6865(%rip), %rsi      # 0x15748
movl $0x11, %edx
movq %rax, %rdi
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq %rax, %rbx
leaq 0x6839(%rip), %rsi      # 0x1575a
movl $0x12, %edx
movq %rax, %rdi
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq %rax, %rbx
leaq 0x680e(%rip), %rsi      # 0x1576d
movl $0xc, %edx
movq %rax, %rdi
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
jmp 0xf424
leaq 0xcc41(%rip), %rbx      # 0x1bbe0
leaq 0x6785(%rip), %r15      # 0x1572b
movl $0x1, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2220
leaq 0x678c(%rip), %rsi      # 0x15749
movl $0x10, %edx
movq %rbx, %rdi
callq 0x2220
movq 0xcc0f(%rip), %rax      # 0x1bbe0
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2220
leaq 0x6716(%rip), %rsi      # 0x15725
movl $0x4, %edx
movq %rbx, %rdi
callq 0x2220
movl $0x1, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2220
leaq 0x67bb(%rip), %rsi      # 0x157ee
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2220
movq (%r14), %rax
movl 0xb8(%rax), %r13d
movl %r13d, %ebp
negl %ebp
cmovsl %r13d, %ebp
movl $0x1, %r14d
cmpl $0xa, %ebp
jb 0xf2e8
movl $0x4, %r14d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %ebp, %ecx
cmpl $0x63, %ecx
jbe 0xf2df
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0xf2e5
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0xf2e8
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r14d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0xf06f
addl $-0x3, %r14d
jmp 0xf2e8
movl $0xc0, %esi
addq (%r14), %rsi
movq %rbx, %rdi
callq 0xabec
leaq 0x18(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0x3c10
leaq 0xcafb(%rip), %rdi      # 0x1bbe0
leaq 0x6641(%rip), %rsi      # 0x1572d
movl $0x6, %edx
callq 0x2220
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0xcad9(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %rbx
leaq 0x6759(%rip), %rsi      # 0x1586f
movl $0x6, %edx
movq %rax, %rdi
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq %rax, %rbx
leaq 0x65d7(%rip), %rsi      # 0x1572b
movl $0x1, %edx
movq %rax, %rdi
callq 0x2220
leaq 0x65e1(%rip), %rsi      # 0x15749
movl $0x10, %edx
movq %rbx, %rdi
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq %rax, %rbx
leaq 0x6585(%rip), %rsi      # 0x1572b
movl $0x1, %edx
movq %rax, %rdi
callq 0x2220
leaq 0x656b(%rip), %rsi      # 0x15725
movl $0x4, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x655d(%rip), %rsi      # 0x1572b
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x668f(%rip), %rsi      # 0x15871
movl $0x4, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x6548(%rip), %rsi      # 0x1573e
movl $0x9, %edx
movq %rbx, %rdi
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq %rax, %rbx
leaq 0x64f7(%rip), %rsi      # 0x1572b
movl $0x1, %edx
movq %rax, %rdi
callq 0x2220
leaq 0x64dd(%rip), %rsi      # 0x15725
movl $0x4, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x64cf(%rip), %rsi      # 0x1572b
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x64f0(%rip), %rsi      # 0x15760
movl $0xc, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x64a6(%rip), %rsi      # 0x1572a
movl $0x2, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x64d6(%rip), %rsi      # 0x1576e
movl $0xb, %edx
movq %rbx, %rdi
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
jne 0xf417
jmp 0xf424
addl $-0x2, %r14d
jmp 0xf2e8
decl %r14d
shrl $0x1f, %r13d
movl %r13d, %esi
addl %r14d, %esi
leaq 0x18(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movl $0x2d, %edx
callq 0x2230
movq (%r15), %rdi
addq %r13, %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0xafe5
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %rbx, %rdi
callq 0x2220
movq %rax, %rbx
leaq 0x6407(%rip), %rsi      # 0x1573e
movl $0x9, %edx
movq %rax, %rdi
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq %rax, %rbx
leaq 0x63b6(%rip), %rsi      # 0x1572b
movl $0x1, %edx
movq %rax, %rdi
callq 0x2220
leaq 0x639c(%rip), %rsi      # 0x15725
movl $0x4, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x638e(%rip), %rsi      # 0x1572b
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x63af(%rip), %rsi      # 0x15760
movl $0xc, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x6365(%rip), %rsi      # 0x1572a
movl $0x2, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x6395(%rip), %rsi      # 0x1576e
movl $0xb, %edx
movq %rbx, %rdi
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0xf424
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21c0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0xab5a
jmp 0xf46b
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
jne 0xf45e
jmp 0xf46b
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0xf46b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x2310