// File: /workspace/github_cpp_makefile_star2_O2/JameyWoo[P]csmile/assembly.cpp
// Function: genIfElse(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 genIfElse(TreeNode* ifelse, map<string, string> var2stack) {
    // debug("ifelse->child[0]: " + ifelse->child[0]->nodekind);
    // debug("ifelse->child[0]: " + ifelse->child[1]->nodekind);
    // debug("ifelse->child[0]: " + ifelse->child[2]->nodekind);
    // ifelse->child[0] 是条件判断
    // ifelse->child[1] 是 if 的条件成立之后的的stmt
    // ifelse->child[2] 是 else 之后的stmt
    if (ifelse->child[0]->op == "==") {
        // debug(" == ");
        TreeNode* left = ifelse->child[0]->child[0];
        solveCompare(left, "%eax", var2stack);
        // 左边的结果放到 %eax, 右边的结果放到 %edx
        TreeNode* right = ifelse->child[0]->child[1];
        solveCompare(right, "%edx", var2stack);
        assout << "\tcmpl\t%edx, %eax" << endl;

        string L1 = ".L" + to_string(getId());
        string L2 = ".L" + to_string(getId());
        assout << "\tjne\t" << L1 << endl;
        genStmt(ifelse->child[1], var2stack);
        assout << "\tjmp\t" << L2 << endl;
        assout << L1 << ":" << endl;
        // debug("else: " + ifelse->child[2]->nodekind);
        genStmt(ifelse->child[2], var2stack);
        assout << L2 << ":" << endl;
    }
    // TODO: 其他的比较
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x160, %rsp            # imm = 0x160
movq %rsi, %rbx
movq %rdi, %r14
movl $0x98, %edi
addq (%r14), %rdi
leaq 0x4238(%rip), %rsi      # 0xf7a7
callq 0x368e
testb %al, %al
je 0xb7ce
movq (%r14), %rax
movq (%rax), %r15
leaq 0x41b5(%rip), %rsi      # 0xf73e
leaq 0x80(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x2efc
leaq 0x130(%rsp), %rdi
movq %rbx, %rsi
callq 0xd3ce
leaq 0x80(%rsp), %rsi
leaq 0x130(%rsp), %rdx
movq %r15, %rdi
callq 0xc10b
leaq 0x130(%rsp), %rdi
callq 0x7b9c
leaq 0x80(%rsp), %rdi
callq 0x2358
movq (%r14), %rax
movq 0x8(%rax), %r15
leaq 0x426f(%rip), %rsi      # 0xf85a
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x2efc
leaq 0x100(%rsp), %rdi
movq %rbx, %rsi
callq 0xd3ce
leaq 0x60(%rsp), %rsi
leaq 0x100(%rsp), %rdx
movq %r15, %rdi
callq 0xc10b
leaq 0x100(%rsp), %rdi
callq 0x7b9c
leaq 0x60(%rsp), %rdi
callq 0x2358
leaq 0xb5a3(%rip), %rdi      # 0x16be0
leaq 0x4166(%rip), %rsi      # 0xf7aa
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
movl 0xb7f1(%rip), %esi      # 0x16e48
leal 0x1(%rsi), %eax
movl %eax, 0xb7e8(%rip)      # 0x16e48
movq %rsp, %r15
movq %r15, %rdi
callq 0x7cbf
leaq 0x4149(%rip), %rsi      # 0xf7bb
leaq 0x20(%rsp), %rdi
movq %r15, %rdx
callq 0x7c9b
movq %rsp, %rdi
callq 0x2358
movl 0xb7bb(%rip), %esi      # 0x16e48
leal 0x1(%rsi), %eax
movl %eax, 0xb7b2(%rip)      # 0x16e48
leaq 0x40(%rsp), %rdi
callq 0x7cbf
leaq 0x4114(%rip), %rsi      # 0xf7bb
movq %rsp, %rdi
leaq 0x40(%rsp), %rdx
callq 0x7c9b
leaq 0x40(%rsp), %rdi
callq 0x2358
leaq 0xb51b(%rip), %rdi      # 0x16be0
leaq 0x40f2(%rip), %rsi      # 0xf7be
callq 0x21b0
leaq 0x20(%rsp), %rsi
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x20f0
movq 0x8(%r14), %r15
leaq 0xd0(%rsp), %rdi
movq %rbx, %rsi
callq 0xd3ce
leaq 0xd0(%rsp), %rsi
movq %r15, %rdi
callq 0xb021
leaq 0xd0(%rsp), %rdi
callq 0x7b9c
leaq 0xb4c2(%rip), %rdi      # 0x16be0
leaq 0x409f(%rip), %rsi      # 0xf7c4
callq 0x21b0
movq %rsp, %rsi
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x20f0
leaq 0xb49c(%rip), %rdi      # 0x16be0
leaq 0x20(%rsp), %rsi
callq 0x21a0
leaq 0x41c3(%rip), %rsi      # 0xf918
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
movq 0x10(%r14), %r14
leaq 0xa0(%rsp), %rdi
movq %rbx, %rsi
callq 0xd3ce
leaq 0xa0(%rsp), %rsi
movq %r14, %rdi
callq 0xb021
leaq 0xa0(%rsp), %rdi
callq 0x7b9c
leaq 0xb443(%rip), %rdi      # 0x16be0
movq %rsp, %rsi
callq 0x21a0
leaq 0x416c(%rip), %rsi      # 0xf918
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
movq %rsp, %rdi
callq 0x2358
leaq 0x20(%rsp), %rdi
callq 0x2358
addq $0x160, %rsp            # imm = 0x160
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
jmp 0xb7f3
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x7b9c
jmp 0xb856
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
jmp 0xb859
movq %rax, %rbx
jmp 0xb85e
movq %rax, %rbx
movq %rsp, %rdi
jmp 0xb863
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x7b9c
jmp 0xb826
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
jmp 0xb863
jmp 0xb84e
movq %rax, %rbx
leaq 0x130(%rsp), %rdi
callq 0x7b9c
jmp 0xb844
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
jmp 0xb863
movq %rax, %rbx
jmp 0xb868
movq %rax, %rbx
movq %rsp, %rdi
callq 0x2358
leaq 0x20(%rsp), %rdi
callq 0x2358
movq %rbx, %rdi
callq 0x2300