// File: /workspace/github_cpp_makefile_star2_O3/JameyWoo[P]csmile/assembly.cpp
// Function: genReturn(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 genReturn(TreeNode* returnStmt, map<string, string> var2stack) {
    // debug("return: " + returnStmt->child[0]->nodekind);
    if (returnStmt->child[0]->nodekind == "Id") {
        assout << "\tmovl\t" << var2stack[returnStmt->child[0]->name] << ", %eax" << endl;
    } else if (returnStmt->child[0]->nodekind == "Const") {
        assout << "\tmovl\t$" << to_string(returnStmt->child[0]->val) << ", %eax" << endl;
    } else if (returnStmt->child[0]->nodekind == "Call") {
        // debug("return call: " + returnStmt->child[0]->nodekind);
        genCall(returnStmt->child[0], var2stack);
    }
    // TODO: 除了直接返回Id, 还有其他返回形式. 如 a + b, input() 这种
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rdi
addq $0x30, %rdi
leaq 0x454e(%rip), %rsi      # 0x15220
callq 0x2090
testl %eax, %eax
je 0x10d3e
movq (%rbx), %rdi
addq $0x30, %rdi
leaq 0x457c(%rip), %rsi      # 0x15265
callq 0x2090
testl %eax, %eax
je 0x10dc2
movq (%rbx), %rdi
addq $0x30, %rdi
leaq 0x4552(%rip), %rsi      # 0x15256
callq 0x2090
testl %eax, %eax
jne 0x10ed3
movq (%rbx), %rbx
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x13e16
movq %rbx, %rdi
movq %r15, %rsi
callq 0xf473
leaq 0x20(%rsp), %rdi
callq 0xab5a
jmp 0x10ed3
leaq 0xae9b(%rip), %r15      # 0x1bbe0
leaq 0x49e1(%rip), %rsi      # 0x1572d
movl $0x6, %edx
movq %r15, %rdi
callq 0x2220
movl $0xc0, %esi
addq (%rbx), %rsi
movq %r14, %rdi
callq 0xabec
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r15, %rdi
callq 0x2220
movq %rax, %rbx
leaq 0x49d1(%rip), %rsi      # 0x15753
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
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x2120
leaq 0xae17(%rip), %rdi      # 0x1bbe0
leaq 0x49e6(%rip), %rsi      # 0x157b6
movl $0x7, %edx
callq 0x2220
movq (%rbx), %rax
movl 0xb8(%rax), %r12d
movl %r12d, %ebx
negl %ebx
cmovsl %r12d, %ebx
movl $0x1, %ebp
cmpl $0xa, %ebx
jb 0x10e3b
movl $0x4, %ebp
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %ebx, %ecx
cmpl $0x63, %ecx
jbe 0x10e34
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x10e39
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x10e3b
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %ebp
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x10e03
addl $-0x3, %ebp
jmp 0x10e3b
addl $-0x2, %ebp
jmp 0x10e3b
decl %ebp
shrl $0x1f, %r12d
movl %r12d, %esi
addl %ebp, %esi
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
movq %rsp, %r14
movq %r14, %rdi
movl $0x2d, %edx
callq 0x2230
movq (%r14), %rdi
addq %r12, %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0xafe5
movq (%r14), %rsi
movq 0x8(%r14), %rdx
leaq 0xad66(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %rbx
leaq 0x48ca(%rip), %rsi      # 0x15753
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 (%rsp), %rdi
cmpq %r15, %rdi
je 0x10ed3
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21c0
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xab5a
jmp 0x10f08
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x10f08
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x2310