// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
testq %rdi, %rdi
je 0xee1d
movq %rdi, %r14
movq %rsi, 0x48(%rsp)
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %r15
movaps %xmm0, 0x40(%r15)
movaps %xmm0, 0x30(%r15)
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, (%r15)
xorl %ebx, %ebx
movq %r15, %rdi
xorl %esi, %esi
callq 0x14438
leaq 0xb0(%rsp), %rax
movl $0x0, (%rax)
movq %rbx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rbx, 0x20(%rax)
movl $0xc0, %r12d
movq 0x8(%r14), %rsi
addq %r12, %rsi
movq %r15, %rdi
callq 0x145b0
incl %ebx
movq 0x20(%r14), %r14
testq %r14, %r14
jne 0xec2d
movq 0x80(%rsp), %rax
cmpq 0x60(%rsp), %rax
je 0xede3
movl $0xfffffffc, %ebp       # imm = 0xFFFFFFFC
leaq 0x38(%rsp), %r15
leaq 0x8(%rsp), %r14
movl $0xd1b71759, %edx       # imm = 0xD1B71759
movl %ebp, %r12d
negl %r12d
movl $0x1, %r13d
cmpl $0xa, %r12d
jb 0xecc2
movl $0x4, %r13d
movl %r12d, %eax
cmpl $0x63, %eax
jbe 0xecb9
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0xecbf
cmpl $0x2710, %eax           # imm = 0x2710
jb 0xecc2
movl %eax, %ecx
imulq %rdx, %rcx
shrq $0x2d, %rcx
addl $0x4, %r13d
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0xec89
addl $-0x3, %r13d
jmp 0xecc2
addl $-0x2, %r13d
jmp 0xecc2
decl %r13d
leal 0x1(%r13), %esi
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %r14, %rdi
movl $0x2d, %edx
callq 0x2230
movq 0x8(%rsp), %rdi
incq %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0xb06f
movq %r14, %r12
movq %r14, %rdi
leaq 0x6a21(%rip), %rsi      # 0x1571e
callq 0x2340
movq %r15, 0x28(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xed25
movq %rdx, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x38(%rsp)
jmp 0xed2c
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rdx, 0x30(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x80(%rsp), %rsi
cmpq 0x88(%rsp), %rsi
jne 0xed6a
movq 0x98(%rsp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x20, %rsi
leaq 0xa8(%rsp), %rdi
callq 0xac76
movq %rax, %rdi
leaq 0x28(%rsp), %rsi
callq 0x2240
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0xed9f
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xedbb
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21c0
leaq 0x50(%rsp), %rdi
callq 0x1484a
addl $-0x4, %ebp
movq 0x80(%rsp), %rax
cmpq 0x60(%rsp), %rax
movq %r12, %r14
movl $0xd1b71759, %edx       # imm = 0xD1B71759
jne 0xec6e
leaq 0xd026(%rip), %rdi      # 0x1be10
movq 0x48(%rsp), %rsi
callq 0x13856
leaq 0xa8(%rsp), %rsi
movq %rax, %rdi
callq 0x139ee
leaq 0xa8(%rsp), %rdi
callq 0xabe4
leaq 0x50(%rsp), %rdi
callq 0x13cfc
jmp 0xee1f
xorl %ebx, %ebx
movl %ebx, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xee74
jmp 0xee74
movq %rax, %rbx
jmp 0xee56
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0xee56
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xee77
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0xee77
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0xabe4
leaq 0x50(%rsp), %rdi
callq 0x13cfc
movq %rbx, %rdi
callq 0x2310