// File: /workspace/github_cpp_makefile_star2_O3/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 0xabec
leaq 0x18(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0x3c10
movq 0x8(%r15), %rdi
addq $0x30, %rdi
leaq 0x5220(%rip), %rsi      # 0x15265
callq 0x2090
testl %eax, %eax
je 0x10160
movq 0x8(%r15), %rdi
addq $0x30, %rdi
leaq 0x51bf(%rip), %rsi      # 0x15220
callq 0x2090
testl %eax, %eax
je 0x101ea
movq 0x8(%r15), %rdi
addq $0x30, %rdi
leaq 0x522d(%rip), %rsi      # 0x152aa
callq 0x2090
movq 0x8(%r15), %r12
testl %eax, %eax
je 0x10362
addq $0x30, %r12
leaq 0x51d7(%rip), %rsi      # 0x15270
movq %r12, %rdi
callq 0x2090
testl %eax, %eax
je 0x102ea
movq 0x8(%r15), %rdi
addq $0x30, %rdi
leaq 0x51b3(%rip), %rsi      # 0x1526b
callq 0x2090
testl %eax, %eax
je 0x102ea
movq 0x8(%r15), %rdi
addq $0x30, %rdi
leaq 0x51a1(%rip), %rsi      # 0x15275
callq 0x2090
testl %eax, %eax
je 0x10546
movq 0x8(%r15), %rdi
addq $0x30, %rdi
leaq 0x5166(%rip), %rsi      # 0x15256
callq 0x2090
testl %eax, %eax
jne 0x104ad
movq 0x8(%r15), %r15
leaq 0x68(%rsp), %rdi
movq %r14, %rsi
callq 0x13e16
leaq 0x68(%rsp), %rsi
movq %r15, %rdi
callq 0xf473
leaq 0x68(%rsp), %rdi
callq 0xab5a
leaq 0xbab4(%rip), %rdi      # 0x1bbe0
leaq 0x56f1(%rip), %rsi      # 0x15824
movl $0xc, %edx
callq 0x2220
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0xba92(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %rdi
callq 0x20e0
jmp 0x104ad
leaq 0xba79(%rip), %rdi      # 0x1bbe0
leaq 0x5648(%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 0x103fa
movl $0x4, %r15d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %ebp, %ecx
cmpl $0x63, %ecx
jbe 0x103f1
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x103f7
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x103fa
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r15d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x101a8
addl $-0x3, %r15d
jmp 0x103fa
movl $0xc0, %esi
addq 0x8(%r15), %rsi
movq %r14, %rdi
callq 0xabec
leaq 0x38(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0x3c10
leaq 0xb9c1(%rip), %rdi      # 0x1bbe0
leaq 0x5507(%rip), %rsi      # 0x1572d
movl $0x6, %edx
callq 0x2220
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0xb99f(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %r14
leaq 0x561f(%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 0x5589(%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 0x104a0
jmp 0x104ad
movq 0x8(%r15), %r15
leaq 0x98(%rsp), %rdi
movq %r14, %rsi
callq 0x13e16
leaq 0x98(%rsp), %rsi
movq %r15, %rdi
callq 0x11e8f
leaq 0x98(%rsp), %rdi
callq 0xab5a
leaq 0xb8be(%rip), %rdi      # 0x1bbe0
leaq 0x54ee(%rip), %rsi      # 0x15817
movl $0xc, %edx
callq 0x2220
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0xb89c(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
jmp 0x103d9
leaq 0xc8(%rsp), %rdi
movq %r14, %rsi
callq 0x13e16
leaq 0xc8(%rsp), %rsi
movq %r12, %rdi
movl $0x1, %edx
callq 0xfff0
leaq 0xc8(%rsp), %rdi
callq 0xab5a
leaq 0xb845(%rip), %rdi      # 0x1bbe0
leaq 0x5475(%rip), %rsi      # 0x15817
movl $0xc, %edx
callq 0x2220
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0xb823(%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 0x104ad
addl $-0x2, %r15d
jmp 0x103fa
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 0xafe5
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0xb7a2(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %r14
leaq 0x53e1(%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 0x104ad
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21c0
testb %bl, %bl
je 0x1051d
leaq 0xb728(%rip), %rdi      # 0x1bbe0
leaq 0x526e(%rip), %rsi      # 0x1572d
movl $0x6, %edx
callq 0x2220
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0xb706(%rip), %rdi      # 0x1bbe0
callq 0x2220
movq %rax, %rbx
leaq 0x5386(%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 0x10534
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 0x3c10
leaq 0x48(%rsp), %rsi
callq 0xfc79
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x104ad
movq 0x58(%rsp), %rsi
jmp 0x104a5
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x105be
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x105f7
movq 0x58(%rsp), %rsi
jmp 0x105ea
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
jmp 0x105be
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0xab5a
jmp 0x105f7
jmp 0x105f4
jmp 0x105f4
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
jne 0x105e5
jmp 0x105f7
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x105f7
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0x105f7
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x1060e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x2310