// File: /workspace/github_cpp_makefile_star2_O2/JameyWoo[P]csmile/assembly.cpp
// Function: genWhile(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 genWhile(TreeNode* iter, map<string, string> var2stack) {
    // 循环
    string L1 = ".L" + to_string(getId());
    string L2 = ".L" + to_string(getId());

    if (iter->child[0]->op == "==") {
        // debug(" == ");
        assout << L1 << ":" << endl;
        TreeNode* left = iter->child[0]->child[0];
        solveCompare(left, "%eax", var2stack);
        // 左边的结果放到 %eax, 右边的结果放到 %edx
        TreeNode* right = iter->child[0]->child[1];
        solveCompare(right, "%edx", var2stack);
        assout << "\tcmpl\t%edx, %eax" << endl;
        assout << "\tjne\t" << L2 << endl;
        genStmt(iter->child[1], var2stack);
        assout << "\tjmp\t" << L1 << endl;

        assout << L2 << ":" << endl;
    } else if (iter->child[0]->op == "<") {
        assout << L1 << ":" << endl;
        // 左边的结果放到 %eax, 右边的结果放到 %edx
        TreeNode* left = iter->child[0]->child[0];
        TreeNode* right = iter->child[0]->child[1];
        solveCompare(left, "%eax",var2stack);
        solveCompare(right, "%edx", var2stack);
        assout << "\tcmpl\t %edx, %eax" << endl;
        assout << "\tjge\t" << L2 << endl;
        
        genStmt(iter->child[1], var2stack);
        assout << "\tjmp\t" << L1 << endl;

        assout << L2 << ":" << endl;
    } else if (iter->child[0]->op == ">") {
        assout << L1 << ":" << endl;
        // 左边的结果放到 %eax, 右边的结果放到 %edx
        TreeNode* left = iter->child[0]->child[0];
        TreeNode* right = iter->child[0]->child[1];
        solveCompare(left, "%eax",var2stack);
        solveCompare(right, "%edx", var2stack);
        assout << "\tcmpl\t %edx, %eax" << endl;
        assout << "\tjle\t" << L2 << endl;
        
        genStmt(iter->child[1], var2stack);
        assout << "\tjmp\t" << L1 << endl;

        assout << L2 << ":" << endl;
    }
    // TODO: 其他的比较
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x2d8, %rsp            # imm = 0x2D8
movq %rsi, %rbx
movq %rdi, %r14
movl 0xb46f(%rip), %esi      # 0x16e48
leal 0x1(%rsi), %eax
movl %eax, 0xb466(%rip)      # 0x16e48
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x7cbf
leaq 0x3dc5(%rip), %rsi      # 0xf7bb
leaq 0x48(%rsp), %rdi
movq %r15, %rdx
callq 0x7c9b
leaq 0x8(%rsp), %rdi
callq 0x2358
movl 0xb435(%rip), %esi      # 0x16e48
leal 0x1(%rsi), %eax
movl %eax, 0xb42c(%rip)      # 0x16e48
leaq 0x28(%rsp), %rdi
callq 0x7cbf
leaq 0x3d8e(%rip), %rsi      # 0xf7bb
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x7c9b
leaq 0x28(%rsp), %rdi
callq 0x2358
movl $0x98, %r15d
movq (%r14), %rdi
addq %r15, %rdi
leaq 0x3d4e(%rip), %rsi      # 0xf7a7
callq 0x368e
testb %al, %al
je 0xbc1a
leaq 0xb173(%rip), %rdi      # 0x16be0
leaq 0x48(%rsp), %rsi
callq 0x21a0
leaq 0x3e9a(%rip), %rsi      # 0xf918
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
movq (%r14), %rax
movq (%rax), %r15
leaq 0x3ca3(%rip), %rsi      # 0xf73e
leaq 0x108(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x2efc
leaq 0x2a8(%rsp), %rdi
movq %rbx, %rsi
callq 0xd3ce
leaq 0x108(%rsp), %rsi
leaq 0x2a8(%rsp), %rdx
movq %r15, %rdi
callq 0xc10b
leaq 0x2a8(%rsp), %rdi
callq 0x7b9c
leaq 0x108(%rsp), %rdi
callq 0x2358
movq (%r14), %rax
movq 0x8(%rax), %r15
leaq 0x3d5d(%rip), %rsi      # 0xf85a
leaq 0xe8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x2efc
leaq 0x278(%rsp), %rdi
movq %rbx, %rsi
callq 0xd3ce
leaq 0xe8(%rsp), %rsi
leaq 0x278(%rsp), %rdx
movq %r15, %rdi
callq 0xc10b
leaq 0x278(%rsp), %rdi
callq 0x7b9c
leaq 0xe8(%rsp), %rdi
callq 0x2358
leaq 0xb088(%rip), %rdi      # 0x16be0
leaq 0x3c4b(%rip), %rsi      # 0xf7aa
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
leaq 0xb06d(%rip), %rdi      # 0x16be0
leaq 0x3c44(%rip), %rsi      # 0xf7be
callq 0x21b0
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x20f0
movq 0x8(%r14), %r14
leaq 0x248(%rsp), %rdi
movq %rbx, %rsi
callq 0xd3ce
leaq 0x248(%rsp), %rsi
movq %r14, %rdi
callq 0xb021
leaq 0x248(%rsp), %rdi
callq 0x7b9c
leaq 0xb014(%rip), %rdi      # 0x16be0
leaq 0x3bf1(%rip), %rsi      # 0xf7c4
callq 0x21b0
leaq 0x48(%rsp), %rsi
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x20f0
leaq 0xafec(%rip), %rdi      # 0x16be0
leaq 0x8(%rsp), %rsi
callq 0x21a0
leaq 0x3d13(%rip), %rsi      # 0xf918
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
jmp 0xbfa4
addq (%r14), %r15
leaq 0x3bbc(%rip), %rsi      # 0xf7e0
movq %r15, %rdi
callq 0x368e
testb %al, %al
je 0xbde5
leaq 0xafa5(%rip), %rdi      # 0x16be0
leaq 0x48(%rsp), %rsi
callq 0x21a0
leaq 0x3ccc(%rip), %rsi      # 0xf918
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
movq (%r14), %rax
movq (%rax), %r12
movq 0x8(%rax), %r15
leaq 0x3ad1(%rip), %rsi      # 0xf73e
leaq 0xc8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x2efc
leaq 0x218(%rsp), %rdi
movq %rbx, %rsi
callq 0xd3ce
leaq 0xc8(%rsp), %rsi
leaq 0x218(%rsp), %rdx
movq %r12, %rdi
callq 0xc10b
leaq 0x218(%rsp), %rdi
callq 0x7b9c
leaq 0xc8(%rsp), %rdi
callq 0x2358
leaq 0x3b92(%rip), %rsi      # 0xf85a
leaq 0xa8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x2efc
leaq 0x1e8(%rsp), %rdi
movq %rbx, %rsi
callq 0xd3ce
leaq 0xa8(%rsp), %rsi
leaq 0x1e8(%rsp), %rdx
movq %r15, %rdi
callq 0xc10b
leaq 0x1e8(%rsp), %rdi
callq 0x7b9c
leaq 0xa8(%rsp), %rdi
callq 0x2358
leaq 0xaebd(%rip), %rdi      # 0x16be0
leaq 0x3ab8(%rip), %rsi      # 0xf7e2
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
leaq 0xaea2(%rip), %rdi      # 0x16be0
leaq 0x3aaf(%rip), %rsi      # 0xf7f4
callq 0x21b0
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x20f0
movq 0x8(%r14), %r14
leaq 0x1b8(%rsp), %rdi
movq %rbx, %rsi
callq 0xd3ce
leaq 0x1b8(%rsp), %rsi
movq %r14, %rdi
callq 0xb021
leaq 0x1b8(%rsp), %rdi
callq 0x7b9c
leaq 0xae49(%rip), %rdi      # 0x16be0
leaq 0x3a26(%rip), %rsi      # 0xf7c4
callq 0x21b0
leaq 0x48(%rsp), %rsi
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x20f0
leaq 0xae21(%rip), %rdi      # 0x16be0
leaq 0x8(%rsp), %rsi
callq 0x21a0
leaq 0x3b48(%rip), %rsi      # 0xf918
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
jmp 0xbfa4
movl $0x98, %edi
addq (%r14), %rdi
leaq 0x3228(%rip), %rsi      # 0xf01c
callq 0x368e
testb %al, %al
je 0xbfa4
leaq 0xadd8(%rip), %rdi      # 0x16be0
leaq 0x48(%rsp), %rsi
callq 0x21a0
leaq 0x3aff(%rip), %rsi      # 0xf918
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
movq (%r14), %rax
movq (%rax), %r12
movq 0x8(%rax), %r15
leaq 0x3904(%rip), %rsi      # 0xf73e
leaq 0x88(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x2efc
leaq 0x188(%rsp), %rdi
movq %rbx, %rsi
callq 0xd3ce
leaq 0x88(%rsp), %rsi
leaq 0x188(%rsp), %rdx
movq %r12, %rdi
callq 0xc10b
leaq 0x188(%rsp), %rdi
callq 0x7b9c
leaq 0x88(%rsp), %rdi
callq 0x2358
leaq 0x39c5(%rip), %rsi      # 0xf85a
leaq 0x68(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x2efc
leaq 0x158(%rsp), %rdi
movq %rbx, %rsi
callq 0xd3ce
leaq 0x68(%rsp), %rsi
leaq 0x158(%rsp), %rdx
movq %r15, %rdi
callq 0xc10b
leaq 0x158(%rsp), %rdi
callq 0x7b9c
leaq 0x68(%rsp), %rdi
callq 0x2358
leaq 0xacf9(%rip), %rdi      # 0x16be0
leaq 0x38f4(%rip), %rsi      # 0xf7e2
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
leaq 0xacde(%rip), %rdi      # 0x16be0
leaq 0x38f1(%rip), %rsi      # 0xf7fa
callq 0x21b0
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x20f0
movq 0x8(%r14), %r14
leaq 0x128(%rsp), %rdi
movq %rbx, %rsi
callq 0xd3ce
leaq 0x128(%rsp), %rsi
movq %r14, %rdi
callq 0xb021
leaq 0x128(%rsp), %rdi
callq 0x7b9c
leaq 0xac85(%rip), %rdi      # 0x16be0
leaq 0x3862(%rip), %rsi      # 0xf7c4
callq 0x21b0
leaq 0x48(%rsp), %rsi
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x20f0
leaq 0xac5d(%rip), %rdi      # 0x16be0
leaq 0x8(%rsp), %rsi
callq 0x21a0
leaq 0x3984(%rip), %rsi      # 0xf918
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
leaq 0x8(%rsp), %rdi
callq 0x2358
leaq 0x48(%rsp), %rdi
callq 0x2358
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
jmp 0xc07f
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
callq 0x7b9c
jmp 0xbfec
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0xc0c4
jmp 0xc0ec
movq %rax, %rbx
leaq 0x188(%rsp), %rdi
callq 0x7b9c
jmp 0xc010
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0xc0c4
jmp 0xc0ec
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
jmp 0xc07f
movq %rax, %rbx
leaq 0x1e8(%rsp), %rdi
callq 0x7b9c
jmp 0xc044
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
jmp 0xc0c4
jmp 0xc0ec
movq %rax, %rbx
leaq 0x218(%rsp), %rdi
callq 0x7b9c
jmp 0xc068
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
jmp 0xc0c4
jmp 0xc0ec
movq %rax, %rbx
leaq 0x248(%rsp), %rdi
callq 0x7b9c
jmp 0xc0ef
movq %rax, %rbx
leaq 0x278(%rsp), %rdi
callq 0x7b9c
jmp 0xc09b
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
jmp 0xc0c4
jmp 0xc0ec
movq %rax, %rbx
leaq 0x2a8(%rsp), %rdi
callq 0x7b9c
jmp 0xc0bc
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x2358
jmp 0xc0ef
jmp 0xc0ec
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0xc0f4
movq %rax, %rbx
jmp 0xc0f9
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
jmp 0xc0fe
jmp 0xc0ec
jmp 0xc0ec
jmp 0xc0ec
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x2358
leaq 0x48(%rsp), %rdi
callq 0x2358
movq %rbx, %rdi
callq 0x2300