// File: JameyWoo[P]csmile/assembly.cpp
// Function: genLocVarDecl(TreeNode*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
int genLocVarDecl(TreeNode* vars, string func_name) {
    if (vars == NULL) return 0;
    // debug(vars->child[0]->name);

    // ! 需要统计有多少个局部变量, 以分配初始的栈空间
    stack<string> var_stack;
    map<string, string> var2stack;
    int var_cnt   = 0;
    TreeNode* var = vars;
    while (var != NULL) {
        var_cnt += 1;
        // debug("var " + var->child[1]->name);
        var_stack.push(var->child[1]->name);
        var = var->sibling;
    }
    // debug("\tvar cnt: " + to_string(var_cnt));

    // * 给局部变量分配栈空间
    int bias = -4;
    while (not var_stack.empty()) {
        var2stack[var_stack.top()] = to_string(bias) + "(%ebp)";
        var_stack.pop();
        bias -= 4;
    }

    fun2var[func_name] = var2stack;
    return var_cnt;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rsi, -0x100(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x17a3d
movl $0x0, -0x4(%rbp)
jmp 0x17c4a
leaq -0x68(%rbp), %rdi
callq 0x1bf60
leaq -0x98(%rbp), %rdi
callq 0xee20
movl $0x0, -0x9c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xa8(%rbp)
cmpq $0x0, -0xa8(%rbp)
je 0x17ac7
movl -0x9c(%rbp), %eax
incl %eax
movl %eax, -0x9c(%rbp)
movq -0xa8(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0xc0, %rsi
leaq -0x68(%rbp), %rdi
callq 0x1bf90
jmp 0x17a9c
movq -0xa8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xa8(%rbp)
jmp 0x17a67
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x17c33
movl $0xfffffffc, -0xb8(%rbp) # imm = 0xFFFFFFFC
leaq -0x68(%rbp), %rdi
callq 0x1bfc0
movb %al, -0x101(%rbp)
jmp 0x17ae2
movb -0x101(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x17af3
jmp 0x17be2
movl -0xb8(%rbp), %esi
leaq -0xf8(%rbp), %rdi
callq 0xf460
jmp 0x17b07
leaq 0x9b79(%rip), %rdx      # 0x21687
leaq -0xd8(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0xf3c0
jmp 0x17b23
leaq -0x68(%rbp), %rdi
callq 0x1bfe0
movq %rax, -0x110(%rbp)
jmp 0x17b35
movq -0x110(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0xf2e0
movq %rax, -0x118(%rbp)
jmp 0x17b51
movq -0x118(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
movq %rsi, -0x120(%rbp)
callq 0x3350
movq -0x120(%rbp), %rdi
callq 0x34e8
leaq -0xf8(%rbp), %rdi
callq 0x34e8
leaq -0x68(%rbp), %rdi
callq 0x1c000
jmp 0x17b8e
movl -0xb8(%rbp), %eax
subl $0x4, %eax
movl %eax, -0xb8(%rbp)
jmp 0x17ad1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x17bd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x34e8
leaq -0xf8(%rbp), %rdi
callq 0x34e8
jmp 0x17c33
movq -0x100(%rbp), %rsi
leaq 0x172e8(%rip), %rdi     # 0x2eed8
callq 0x1be50
movq %rax, -0x128(%rbp)
jmp 0x17bfe
movq -0x128(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x1bf30
jmp 0x17c13
movl -0x9c(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0x98(%rbp), %rdi
callq 0xee40
leaq -0x68(%rbp), %rdi
callq 0x1c020
jmp 0x17c4a
leaq -0x98(%rbp), %rdi
callq 0xee40
leaq -0x68(%rbp), %rdi
callq 0x1c020
jmp 0x17c56
movl -0x4(%rbp), %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq -0xb0(%rbp), %rdi
callq 0x3470
nopw %cs:(%rax,%rax)