// File: /workspace/github_cpp_makefile_star2_O1/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 0x63ad(%rip), %rsi      # 0x15265
callq 0x2090
testl %eax, %eax
je 0xf028
movq (%r14), %rdi
addq $0x30, %rdi
leaq 0x634d(%rip), %rsi      # 0x15220
callq 0x2090
testl %eax, %eax
je 0xf141
movq (%r14), %rdi
addq $0x30, %rdi
leaq 0x6368(%rip), %rsi      # 0x15256
callq 0x2090
testl %eax, %eax
jne 0xf4b4
movq (%r14), %r14
leaq 0x28(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x13e9a
movq %r14, %rdi
movq %r15, %rsi
callq 0xf503
leaq 0x28(%rsp), %rdi
callq 0xabe4
leaq 0xccb6(%rip), %rbx      # 0x1bbe0
leaq 0x6803(%rip), %rsi      # 0x15734
movl $0x13, %edx
movq %rbx, %rdi
callq 0x2220
movq 0xcc9b(%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 0x67d5(%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 0x67a9(%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 0x677e(%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 0xf4b4
leaq 0xcbb1(%rip), %rbx      # 0x1bbe0
leaq 0x66f5(%rip), %r15      # 0x1572b
movl $0x1, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2220
leaq 0x66fc(%rip), %rsi      # 0x15749
movl $0x10, %edx
movq %rbx, %rdi
callq 0x2220
movq 0xcb7f(%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 0x6686(%rip), %rsi      # 0x15725
movl $0x4, %edx
movq %rbx, %rdi
callq 0x2220
movl $0x1, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2220
leaq 0x672b(%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 0xf378
movl $0x4, %r14d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %ebp, %ecx
cmpl $0x63, %ecx
jbe 0xf36f
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0xf375
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0xf378
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r14d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0xf0ff
addl $-0x3, %r14d
jmp 0xf378
movl $0xc0, %esi
addq (%r14), %rsi
movq %rbx, %rdi
callq 0xac76
leaq 0x18(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0x3c5c
leaq 0xca6b(%rip), %rdi      # 0x1bbe0
leaq 0x65b1(%rip), %rsi      # 0x1572d
movl $0x6, %edx
callq 0x2220
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0xca49(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %rbx
leaq 0x66c9(%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 0x6547(%rip), %rsi      # 0x1572b
movl $0x1, %edx
movq %rax, %rdi
callq 0x2220
leaq 0x6551(%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 0x64f5(%rip), %rsi      # 0x1572b
movl $0x1, %edx
movq %rax, %rdi
callq 0x2220
leaq 0x64db(%rip), %rsi      # 0x15725
movl $0x4, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x64cd(%rip), %rsi      # 0x1572b
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x65ff(%rip), %rsi      # 0x15871
movl $0x4, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x64b8(%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 0x6467(%rip), %rsi      # 0x1572b
movl $0x1, %edx
movq %rax, %rdi
callq 0x2220
leaq 0x644d(%rip), %rsi      # 0x15725
movl $0x4, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x643f(%rip), %rsi      # 0x1572b
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x6460(%rip), %rsi      # 0x15760
movl $0xc, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x6416(%rip), %rsi      # 0x1572a
movl $0x2, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x6446(%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 0xf4a7
jmp 0xf4b4
addl $-0x2, %r14d
jmp 0xf378
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 0xb06f
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %rbx, %rdi
callq 0x2220
movq %rax, %rbx
leaq 0x6377(%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 0x6326(%rip), %rsi      # 0x1572b
movl $0x1, %edx
movq %rax, %rdi
callq 0x2220
leaq 0x630c(%rip), %rsi      # 0x15725
movl $0x4, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x62fe(%rip), %rsi      # 0x1572b
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x631f(%rip), %rsi      # 0x15760
movl $0xc, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x62d5(%rip), %rsi      # 0x1572a
movl $0x2, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x6305(%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 0xf4b4
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 0xabe4
jmp 0xf4fb
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
jne 0xf4ee
jmp 0xf4fb
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0xf4fb
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x2310