// File: /workspace/github_cpp_makefile_star2_O3/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 0x5182(%rip), %rsi      # 0x157be
callq 0x2090
testl %eax, %eax
jne 0x10ba8
movq (%r14), %rax
movq (%rax), %r15
leaq 0x98(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x50f3(%rip), %rsi      # 0x15755
leaq 0x50f0(%rip), %rdx      # 0x15759
leaq 0x88(%rsp), %rdi
callq 0x312c
leaq 0x138(%rsp), %rdi
movq %r12, %rsi
callq 0x13e16
leaq 0x88(%rsp), %rsi
leaq 0x138(%rsp), %rdx
movq %r15, %rdi
callq 0x11c4f
leaq 0x138(%rsp), %rdi
callq 0xab5a
movq 0x88(%rsp), %rdi
cmpq %rbx, %rdi
je 0x106c8
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x21c0
movq (%r14), %rax
movq 0x8(%rax), %r15
leaq 0x78(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x5192(%rip), %rsi      # 0x15871
leaq 0x518f(%rip), %rdx      # 0x15875
leaq 0x68(%rsp), %rdi
callq 0x312c
leaq 0x108(%rsp), %rdi
movq %r12, %rsi
callq 0x13e16
leaq 0x68(%rsp), %rsi
leaq 0x108(%rsp), %rdx
movq %r15, %rdi
callq 0x11c4f
leaq 0x108(%rsp), %rdi
callq 0xab5a
movq 0x68(%rsp), %rdi
cmpq %rbx, %rdi
je 0x10739
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x21c0
leaq 0xb4a0(%rip), %r15      # 0x1bbe0
leaq 0x507a(%rip), %rsi      # 0x157c1
movl $0x10, %edx
movq %r15, %rdi
callq 0x2220
movq 0xb485(%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 0xb6c2(%rip), %r13d     # 0x1be48
leal 0x1(%r13), %eax
movl %eax, 0xb6b8(%rip)      # 0x1be48
movl %r13d, %ebp
negl %ebp
cmovsl %r13d, %ebp
movl $0x1, %r15d
cmpl $0xa, %ebp
jb 0x107ed
movl $0x4, %r15d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %ebp, %ecx
cmpl $0x63, %ecx
jbe 0x107e4
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x107ea
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x107ed
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r15d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x107b1
addl $-0x3, %r15d
jmp 0x107ed
addl $-0x2, %r15d
jmp 0x107ed
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 0xafe5
leaq 0x4fa5(%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 0x10866
movq %rdx, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0x1086c
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 0x1089f
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21c0
movl 0xb5a2(%rip), %r15d     # 0x1be48
leal 0x1(%r15), %eax
movl %eax, 0xb598(%rip)      # 0x1be48
movl %r15d, %ebp
negl %ebp
cmovsl %r15d, %ebp
movl $0x1, %r12d
cmpl $0xa, %ebp
jb 0x1090d
movl $0x4, %r12d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %ebp, %ecx
cmpl $0x63, %ecx
jbe 0x10904
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x1090a
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x1090d
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r12d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x108d1
addl $-0x3, %r12d
jmp 0x1090d
addl $-0x2, %r12d
jmp 0x1090d
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 0xafe5
leaq 0x4e88(%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 0x10987
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0x1098f
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 0x109be
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21c0
leaq 0xb21b(%rip), %rdi      # 0x1bbe0
leaq 0x4e09(%rip), %rsi      # 0x157d5
movl $0x5, %edx
callq 0x2220
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
leaq 0xb1f9(%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 0x13e16
leaq 0xd8(%rsp), %rsi
movq %r15, %rdi
callq 0xfdff
leaq 0xd8(%rsp), %rdi
callq 0xab5a
leaq 0xb192(%rip), %rdi      # 0x1bbe0
leaq 0x4d86(%rip), %rsi      # 0x157db
movl $0x5, %edx
callq 0x2220
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
leaq 0xb171(%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 0xb131(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %r15
leaq 0x4e71(%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 0x13e16
leaq 0xa8(%rsp), %rsi
movq %r14, %rdi
callq 0xfdff
leaq 0xa8(%rsp), %rdi
callq 0xab5a
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
leaq 0xb0ad(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %rbx
leaq 0x4ded(%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 0x10b8c
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x10ba8
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 0x10bd2
movq %rax, %r14
leaq 0xd8(%rsp), %rdi
callq 0xab5a
jmp 0x10c73
movq %rax, %r14
movq 0x48(%rsp), %rdi
cmpq %rbx, %rdi
je 0x10c8e
movq 0x58(%rsp), %rsi
jmp 0x10c86
movq %rax, %r14
jmp 0x10c8e
movq %rax, %r14
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x10caa
movq 0x10(%rsp), %rsi
jmp 0x10ca2
movq %rax, %r14
leaq 0x108(%rsp), %rdi
callq 0xab5a
jmp 0x10c33
movq %rax, %r14
movq 0x68(%rsp), %rdi
cmpq %rbx, %rdi
je 0x10caa
movq 0x78(%rsp), %rsi
jmp 0x10ca2
movq %rax, %r14
leaq 0x138(%rsp), %rdi
callq 0xab5a
jmp 0x10c59
movq %rax, %r14
movq 0x88(%rsp), %rdi
cmpq %rbx, %rdi
je 0x10caa
movq 0x98(%rsp), %rsi
jmp 0x10ca2
movq %rax, %r14
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x10c8e
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x10caa
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21c0
movq %r14, %rdi
callq 0x2310