// File: /workspace/github_cpp_makefile_star2_O1/JameyWoo[P]csmile/assembly.cpp
// Function: genAssign(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>>>>>, bool)
void genAssign(TreeNode* assign, map<string, string> var2stack, bool need) {
    // debug("assign " + assign->child[0]->name);
    string left_loc = var2stack[assign->child[0]->name];
    if (assign->child[1]->nodekind == "Const") {
        assout << "\tmovl\t$"
               << to_string(assign->child[1]->val)
               << ", " << left_loc << endl;
    } else if (assign->child[1]->nodekind == "Id") {
        // debug("assign->child[1]->name: " + assign->child[1]->name);
        string right_loc = var2stack[assign->child[1]->name];
        // 先将该值赋值给某个寄存器, 然后再将寄存器赋值给左值
        assout << "\tmovl\t" << right_loc << ", %edx" << endl
               << "\tmovl\t%edx, " << left_loc << endl;
    } else if (assign->child[1]->nodekind == "Assign") {
        genAssign(assign->child[1], var2stack, true);
        assout << "\tmovl\t%edx, " << left_loc << endl;
    } else if (assign->child[1]->nodekind == "PMOp" || assign->child[1]->nodekind == "MDOp") {
        // debug("assign->child[1]->nodekind: " + assign->child[1]->nodekind);
        // 计算(加减乘除)
        // debug("assign->child[1]->nodekind: " + assign->child[1]->nodekind);
        genCalc(assign->child[1], var2stack);
        assout << "\tmovl\t%edx, " << left_loc << endl;
    } else if (assign->child[1]->nodekind == "Input") {
        genInput(assign->child[1], left_loc);  // 第二个参数是赋值的地址
    } else if (assign->child[1]->nodekind == "Call") {
        // call 有一种是在赋值中的, 有一种是普通的没有被赋值的调用
        genCall(assign->child[1], var2stack);
        // 返回值
        assout << "\tmovl\t%eax, " << left_loc << endl;
    }
    if (need) {
        assout << "\tmovl\t" << left_loc << ", %edx" << endl;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
movl $0xc0, %esi
addq (%rdi), %rsi
movq %r14, %rdi
callq 0xac76
leaq 0x18(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0x3c5c
movq 0x8(%r15), %rdi
addq $0x30, %rdi
leaq 0x5190(%rip), %rsi      # 0x15265
callq 0x2090
testl %eax, %eax
je 0x101f0
movq 0x8(%r15), %rdi
addq $0x30, %rdi
leaq 0x512f(%rip), %rsi      # 0x15220
callq 0x2090
testl %eax, %eax
je 0x1027a
movq 0x8(%r15), %rdi
addq $0x30, %rdi
leaq 0x519d(%rip), %rsi      # 0x152aa
callq 0x2090
movq 0x8(%r15), %r12
testl %eax, %eax
je 0x103f2
addq $0x30, %r12
leaq 0x5147(%rip), %rsi      # 0x15270
movq %r12, %rdi
callq 0x2090
testl %eax, %eax
je 0x1037a
movq 0x8(%r15), %rdi
addq $0x30, %rdi
leaq 0x5123(%rip), %rsi      # 0x1526b
callq 0x2090
testl %eax, %eax
je 0x1037a
movq 0x8(%r15), %rdi
addq $0x30, %rdi
leaq 0x5111(%rip), %rsi      # 0x15275
callq 0x2090
testl %eax, %eax
je 0x105d6
movq 0x8(%r15), %rdi
addq $0x30, %rdi
leaq 0x50d6(%rip), %rsi      # 0x15256
callq 0x2090
testl %eax, %eax
jne 0x1053d
movq 0x8(%r15), %r15
leaq 0x68(%rsp), %rdi
movq %r14, %rsi
callq 0x13e9a
leaq 0x68(%rsp), %rsi
movq %r15, %rdi
callq 0xf503
leaq 0x68(%rsp), %rdi
callq 0xabe4
leaq 0xba24(%rip), %rdi      # 0x1bbe0
leaq 0x5661(%rip), %rsi      # 0x15824
movl $0xc, %edx
callq 0x2220
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0xba02(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %rdi
callq 0x20e0
jmp 0x1053d
leaq 0xb9e9(%rip), %rdi      # 0x1bbe0
leaq 0x55b8(%rip), %rsi      # 0x157b6
movl $0x7, %edx
callq 0x2220
movq 0x8(%r15), %rax
movl 0xb8(%rax), %r14d
movl %r14d, %ebp
negl %ebp
cmovsl %r14d, %ebp
movl $0x1, %r15d
cmpl $0xa, %ebp
jb 0x1048a
movl $0x4, %r15d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %ebp, %ecx
cmpl $0x63, %ecx
jbe 0x10481
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x10487
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x1048a
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r15d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x10238
addl $-0x3, %r15d
jmp 0x1048a
movl $0xc0, %esi
addq 0x8(%r15), %rsi
movq %r14, %rdi
callq 0xac76
leaq 0x38(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0x3c5c
leaq 0xb931(%rip), %rdi      # 0x1bbe0
leaq 0x5477(%rip), %rsi      # 0x1572d
movl $0x6, %edx
callq 0x2220
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0xb90f(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %r14
leaq 0x558f(%rip), %rsi      # 0x1586f
movl $0x6, %edx
movq %rax, %rdi
callq 0x2220
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq %rax, %r14
leaq 0x54f9(%rip), %rsi      # 0x15817
movl $0xc, %edx
movq %rax, %rdi
callq 0x2220
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %r14, %rdi
callq 0x2220
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
jne 0x10530
jmp 0x1053d
movq 0x8(%r15), %r15
leaq 0x98(%rsp), %rdi
movq %r14, %rsi
callq 0x13e9a
leaq 0x98(%rsp), %rsi
movq %r15, %rdi
callq 0x11f1f
leaq 0x98(%rsp), %rdi
callq 0xabe4
leaq 0xb82e(%rip), %rdi      # 0x1bbe0
leaq 0x545e(%rip), %rsi      # 0x15817
movl $0xc, %edx
callq 0x2220
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0xb80c(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
jmp 0x10469
leaq 0xc8(%rsp), %rdi
movq %r14, %rsi
callq 0x13e9a
leaq 0xc8(%rsp), %rsi
movq %r12, %rdi
movl $0x1, %edx
callq 0x10080
leaq 0xc8(%rsp), %rdi
callq 0xabe4
leaq 0xb7b5(%rip), %rdi      # 0x1bbe0
leaq 0x53e5(%rip), %rsi      # 0x15817
movl $0xc, %edx
callq 0x2220
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0xb793(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
jmp 0x1053d
addl $-0x2, %r15d
jmp 0x1048a
decl %r15d
shrl $0x1f, %r14d
leal (%r15,%r14), %esi
leaq 0x38(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x28(%rsp), %rdi
movl $0x2d, %edx
callq 0x2230
addq 0x28(%rsp), %r14
movq %r14, %rdi
movl %r15d, %esi
movl %ebp, %edx
callq 0xb06f
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0xb712(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %r14
leaq 0x5351(%rip), %rsi      # 0x1582e
movl $0x2, %edx
movq %rax, %rdi
callq 0x2220
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %r14, %rdi
callq 0x2220
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0x1053d
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21c0
testb %bl, %bl
je 0x105ad
leaq 0xb698(%rip), %rdi      # 0x1bbe0
leaq 0x51de(%rip), %rsi      # 0x1572d
movl $0x6, %edx
callq 0x2220
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0xb676(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %rbx
leaq 0x52f6(%rip), %rsi      # 0x1586f
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 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x105c4
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21c0
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x58(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0x3c5c
leaq 0x48(%rsp), %rsi
callq 0xfd09
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x1053d
movq 0x58(%rsp), %rsi
jmp 0x10535
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x1064e
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x10687
movq 0x58(%rsp), %rsi
jmp 0x1067a
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
jmp 0x1064e
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0xabe4
jmp 0x10687
jmp 0x10684
jmp 0x10684
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
jne 0x10675
jmp 0x10687
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x10687
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0x10687
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x1069e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x2310