// File: /workspace/github_cpp_makefile_star2_O1/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rsi, %r12
movq %rdi, %r14
movl $0x98, %edi
addq (%r14), %rdi
leaq 0x50f2(%rip), %rsi      # 0x157be
callq 0x2090
testl %eax, %eax
jne 0x10c38
movq (%r14), %rax
movq (%rax), %r15
leaq 0x98(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x5063(%rip), %rsi      # 0x15755
leaq 0x5060(%rip), %rdx      # 0x15759
leaq 0x88(%rsp), %rdi
callq 0x312c
leaq 0x138(%rsp), %rdi
movq %r12, %rsi
callq 0x13e9a
leaq 0x88(%rsp), %rsi
leaq 0x138(%rsp), %rdx
movq %r15, %rdi
callq 0x11cdf
leaq 0x138(%rsp), %rdi
callq 0xabe4
movq 0x88(%rsp), %rdi
cmpq %rbx, %rdi
je 0x10758
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x21c0
movq (%r14), %rax
movq 0x8(%rax), %r15
leaq 0x78(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x5102(%rip), %rsi      # 0x15871
leaq 0x50ff(%rip), %rdx      # 0x15875
leaq 0x68(%rsp), %rdi
callq 0x312c
leaq 0x108(%rsp), %rdi
movq %r12, %rsi
callq 0x13e9a
leaq 0x68(%rsp), %rsi
leaq 0x108(%rsp), %rdx
movq %r15, %rdi
callq 0x11cdf
leaq 0x108(%rsp), %rdi
callq 0xabe4
movq 0x68(%rsp), %rdi
cmpq %rbx, %rdi
je 0x107c9
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x21c0
leaq 0xb410(%rip), %r15      # 0x1bbe0
leaq 0x4fea(%rip), %rsi      # 0x157c1
movl $0x10, %edx
movq %r15, %rdi
callq 0x2220
movq 0xb3f5(%rip), %rax      # 0x1bbe0
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movl 0xb632(%rip), %r13d     # 0x1be48
leal 0x1(%r13), %eax
movl %eax, 0xb628(%rip)      # 0x1be48
movl %r13d, %ebp
negl %ebp
cmovsl %r13d, %ebp
movl $0x1, %r15d
cmpl $0xa, %ebp
jb 0x1087d
movl $0x4, %r15d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %ebp, %ecx
cmpl $0x63, %ecx
jbe 0x10874
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x1087a
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x1087d
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r15d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x10841
addl $-0x3, %r15d
jmp 0x1087d
addl $-0x2, %r15d
jmp 0x1087d
decl %r15d
movq %r12, 0x40(%rsp)
shrl $0x1f, %r13d
movl %r13d, %esi
addl %r15d, %esi
leaq 0x10(%rsp), %rax
movq %rax, -0x10(%rax)
movq %rsp, %r12
movq %r12, %rdi
movl $0x2d, %edx
callq 0x2230
movq (%r12), %rdi
addq %r13, %rdi
movl %r15d, %esi
movl %ebp, %edx
callq 0xb06f
leaq 0x4f15(%rip), %rcx      # 0x157d2
movl $0x2, %r8d
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2200
leaq 0x30(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x108f6
movq %rdx, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0x108fc
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
leaq 0x10(%rsp), %rsi
movq 0x8(%rax), %rdx
movq %rdx, 0x28(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq (%rsp), %rdi
cmpq %rsi, %rdi
je 0x1092f
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21c0
movl 0xb512(%rip), %r15d     # 0x1be48
leal 0x1(%r15), %eax
movl %eax, 0xb508(%rip)      # 0x1be48
movl %r15d, %ebp
negl %ebp
cmovsl %r15d, %ebp
movl $0x1, %r12d
cmpl $0xa, %ebp
jb 0x1099d
movl $0x4, %r12d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %ebp, %ecx
cmpl $0x63, %ecx
jbe 0x10994
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x1099a
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x1099d
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r12d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x10961
addl $-0x3, %r12d
jmp 0x1099d
addl $-0x2, %r12d
jmp 0x1099d
decl %r12d
shrl $0x1f, %r15d
leal (%r12,%r15), %esi
leaq 0x58(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x48(%rsp), %rdi
movl $0x2d, %edx
callq 0x2230
leaq 0x48(%rsp), %r13
addq (%r13), %r15
movq %r15, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0xb06f
leaq 0x4df8(%rip), %rcx      # 0x157d2
movl $0x2, %r8d
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2200
leaq 0x10(%rsp), %r13
movq %r13, (%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
movq 0x40(%rsp), %r12
je 0x10a17
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0x10a1f
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
movq %rdx, 0x8(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x48(%rsp), %rdi
cmpq %rbx, %rdi
je 0x10a4e
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21c0
leaq 0xb18b(%rip), %rdi      # 0x1bbe0
leaq 0x4d79(%rip), %rsi      # 0x157d5
movl $0x5, %edx
callq 0x2220
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
leaq 0xb169(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq 0x8(%r14), %r15
leaq 0xd8(%rsp), %rdi
movq %r12, %rsi
callq 0x13e9a
leaq 0xd8(%rsp), %rsi
movq %r15, %rdi
callq 0xfe8f
leaq 0xd8(%rsp), %rdi
callq 0xabe4
leaq 0xb102(%rip), %rdi      # 0x1bbe0
leaq 0x4cf6(%rip), %rsi      # 0x157db
movl $0x5, %edx
callq 0x2220
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
leaq 0xb0e1(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
leaq 0xb0a1(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %r15
leaq 0x4de1(%rip), %rsi      # 0x1592f
movl $0x1, %edx
movq %rax, %rdi
callq 0x2220
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq 0x10(%r14), %r14
leaq 0xa8(%rsp), %rdi
movq %r12, %rsi
callq 0x13e9a
leaq 0xa8(%rsp), %rsi
movq %r14, %rdi
callq 0xfe8f
leaq 0xa8(%rsp), %rdi
callq 0xabe4
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
leaq 0xb01d(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %rbx
leaq 0x4d5d(%rip), %rsi      # 0x1592f
movl $0x1, %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 %r13, %rdi
je 0x10c1c
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x10c38
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21c0
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq 0xa8(%rsp), %rdi
jmp 0x10c62
movq %rax, %r14
leaq 0xd8(%rsp), %rdi
callq 0xabe4
jmp 0x10d03
movq %rax, %r14
movq 0x48(%rsp), %rdi
cmpq %rbx, %rdi
je 0x10d1e
movq 0x58(%rsp), %rsi
jmp 0x10d16
movq %rax, %r14
jmp 0x10d1e
movq %rax, %r14
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x10d3a
movq 0x10(%rsp), %rsi
jmp 0x10d32
movq %rax, %r14
leaq 0x108(%rsp), %rdi
callq 0xabe4
jmp 0x10cc3
movq %rax, %r14
movq 0x68(%rsp), %rdi
cmpq %rbx, %rdi
je 0x10d3a
movq 0x78(%rsp), %rsi
jmp 0x10d32
movq %rax, %r14
leaq 0x138(%rsp), %rdi
callq 0xabe4
jmp 0x10ce9
movq %rax, %r14
movq 0x88(%rsp), %rdi
cmpq %rbx, %rdi
je 0x10d3a
movq 0x98(%rsp), %rsi
jmp 0x10d32
movq %rax, %r14
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x10d1e
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x10d3a
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21c0
movq %r14, %rdi
callq 0x2310