// File: /workspace/github_cpp_makefile_star2_O3/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 0xed8d
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 0x143b6
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 0x1452e
incl %ebx
movq 0x20(%r14), %r14
testq %r14, %r14
jne 0xeb9d
movq 0x80(%rsp), %rax
cmpq 0x60(%rsp), %rax
je 0xed53
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 0xec32
movl $0x4, %r13d
movl %r12d, %eax
cmpl $0x63, %eax
jbe 0xec29
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0xec2f
cmpl $0x2710, %eax           # imm = 0x2710
jb 0xec32
movl %eax, %ecx
imulq %rdx, %rcx
shrq $0x2d, %rcx
addl $0x4, %r13d
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0xebf9
addl $-0x3, %r13d
jmp 0xec32
addl $-0x2, %r13d
jmp 0xec32
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 0xafe5
movq %r14, %r12
movq %r14, %rdi
leaq 0x6ab1(%rip), %rsi      # 0x1571e
callq 0x2340
movq %r15, 0x28(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xec95
movq %rdx, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x38(%rsp)
jmp 0xec9c
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 0xecda
movq 0x98(%rsp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x20, %rsi
leaq 0xa8(%rsp), %rdi
callq 0xabec
movq %rax, %rdi
leaq 0x28(%rsp), %rsi
callq 0x2240
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0xed0f
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xed2b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21c0
leaq 0x50(%rsp), %rdi
callq 0x147c8
addl $-0x4, %ebp
movq 0x80(%rsp), %rax
cmpq 0x60(%rsp), %rax
movq %r12, %r14
movl $0xd1b71759, %edx       # imm = 0xD1B71759
jne 0xebde
leaq 0xd0b6(%rip), %rdi      # 0x1be10
movq 0x48(%rsp), %rsi
callq 0x137c6
leaq 0xa8(%rsp), %rsi
movq %rax, %rdi
callq 0x1395e
leaq 0xa8(%rsp), %rdi
callq 0xab5a
leaq 0x50(%rsp), %rdi
callq 0x13c6a
jmp 0xed8f
xorl %ebx, %ebx
movl %ebx, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xede4
jmp 0xede4
movq %rax, %rbx
jmp 0xedc6
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0xedc6
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xede7
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0xede7
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0xab5a
leaq 0x50(%rsp), %rdi
callq 0x13c6a
movq %rbx, %rdi
callq 0x2310