// File: fondoger[P]C0-Compiler/src/mips.cpp
// Function: buildSymbolTable()
static void buildSymbolTable()
{
    assert((*m).op == FUNC);

    tabClear(LOCAL);
    cur_func_id = (*m).b;
    cur_func_size = 4;  // reserved for $ra

    std::stack<TabEntry> entries;
    for (auto t = m + 1; (*t).op != END; t++) {
        const FourTuple &ft = *t;
        if (ft.op == PARA || ft.op == VAR || ft.op == TEMP) {
            DataType dtype = ft.a == "int" ? DT_INT : DT_CHAR;
            int data_type_size = (dtype == DT_INT) ? SIZE_INT: SIZE_CHAR;
            int array_size = 1; // array size
            if (ft.res != "") { 
                array_size = std::stoi(ft.res);
            }
            cur_func_size += data_type_size * array_size;
        }
    }

    // Important
    prev_para_addr = -4;

    int addr = cur_func_size - 4;
    for (auto t = m + 1; (*t).op != END; t++) {
        const FourTuple &ft = *t;
        if (ft.op == PARA || ft.op == VAR || ft.op == TEMP) {
            DataType dtype = ft.a == "int" ? DT_INT : DT_CHAR;
            int data_type_size = (dtype == DT_INT) ? SIZE_INT : SIZE_CHAR;
            int array_size = 1;
            bool isArray = false;
            if (ft.res != "") {
                array_size = std::stoi(ft.res);
                isArray = true;
            }
            addr -= data_type_size * array_size;
            IdentType itype = (isArray ? IT_ARRAY : IT_VARIABLE);
            TabEntry entry = { LOCAL, itype, dtype, -1, addr };
            tabInsert(ft.b, entry);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
leaq 0x207b6(%rip), %rdi     # 0x4a7d8
callq 0x22e40
cmpl $0x5, (%rax)
jne 0x2a02e
jmp 0x2a04d
leaq 0xbf4b(%rip), %rdi      # 0x35f80
leaq 0xbf54(%rip), %rsi      # 0x35f90
movl $0xc6, %edx
leaq 0xc00e(%rip), %rcx      # 0x36056
callq 0x3230
movl $0x1, %edi
callq 0x2f570
leaq 0x2077a(%rip), %rdi     # 0x4a7d8
callq 0x22e40
movq %rax, %rsi
addq $0x28, %rsi
leaq 0x20747(%rip), %rdi     # 0x4a7b8
callq 0x3040
movl $0x4, 0x207b4(%rip)     # 0x4a834
leaq -0x50(%rbp), %rdi
callq 0x2d4e0
leaq 0x20748(%rip), %rdi     # 0x4a7d8
movl $0x1, %esi
callq 0x2d510
movq %rax, -0x58(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x22e40
cmpl $0x12, (%rax)
je 0x2a1a6
leaq -0x58(%rbp), %rdi
callq 0x22e40
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpl $0x6, (%rax)
je 0x2a0dc
movq -0x60(%rbp), %rax
cmpl $0x8, (%rax)
je 0x2a0dc
movq -0x60(%rbp), %rax
cmpl $0x17, (%rax)
jne 0x2a18d
movq -0x60(%rbp), %rdi
addq $0x8, %rdi
leaq 0xb6be(%rip), %rsi      # 0x357a9
callq 0x2d280
movb %al, %dl
movl $0x2, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %ecx
movl $0x4, %eax
cmpl $0x1, %ecx
cmovel %eax, %eax
movl %eax, -0x68(%rbp)
movl $0x1, -0x6c(%rbp)
movq -0x60(%rbp), %rdi
addq $0x48, %rdi
leaq 0xbec9(%rip), %rsi      # 0x35ff5
callq 0x2d2b0
testb $0x1, %al
jne 0x2a137
jmp 0x2a17a
movq -0x60(%rbp), %rdi
addq $0x48, %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x27ae0
movl %eax, -0xd4(%rbp)
jmp 0x2a155
movl -0xd4(%rbp), %eax
movl %eax, -0x6c(%rbp)
jmp 0x2a17a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x2d550
jmp 0x2a383
movl -0x68(%rbp), %eax
imull -0x6c(%rbp), %eax
addl 0x206ad(%rip), %eax     # 0x4a834
movl %eax, 0x206a7(%rip)     # 0x4a834
jmp 0x2a18f
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
callq 0x2d2e0
movq %rax, -0x88(%rbp)
jmp 0x2a09e
movl $0xfffffffc, 0x20688(%rip) # imm = 0xFFFFFFFC
movl 0x2067e(%rip), %eax     # 0x4a834
subl $0x4, %eax
movl %eax, -0x8c(%rbp)
leaq 0x20612(%rip), %rdi     # 0x4a7d8
movl $0x1, %esi
callq 0x2d510
movq %rax, -0x98(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x22e40
cmpl $0x12, (%rax)
je 0x2a371
leaq -0x98(%rbp), %rdi
callq 0x22e40
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
cmpl $0x6, (%rax)
je 0x2a227
movq -0xa0(%rbp), %rax
cmpl $0x8, (%rax)
je 0x2a227
movq -0xa0(%rbp), %rax
cmpl $0x17, (%rax)
jne 0x2a355
movq -0xa0(%rbp), %rdi
addq $0x8, %rdi
leaq 0xb570(%rip), %rsi      # 0x357a9
callq 0x2d280
movb %al, %dl
movl $0x2, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0xa4(%rbp)
movl -0xa4(%rbp), %ecx
movl $0x4, %eax
cmpl $0x1, %ecx
cmovel %eax, %eax
movl %eax, -0xa8(%rbp)
movl $0x1, -0xac(%rbp)
movb $0x0, -0xad(%rbp)
movq -0xa0(%rbp), %rdi
addq $0x48, %rdi
leaq 0xbd65(%rip), %rsi      # 0x35ff5
callq 0x2d2b0
testb $0x1, %al
jne 0x2a29b
jmp 0x2a2cf
movq -0xa0(%rbp), %rdi
addq $0x48, %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x27ae0
movl %eax, -0xd8(%rbp)
jmp 0x2a2bc
movl -0xd8(%rbp), %eax
movl %eax, -0xac(%rbp)
movb $0x1, -0xad(%rbp)
movl -0xa8(%rbp), %ecx
movl -0xac(%rbp), %eax
imull %eax, %ecx
movl -0x8c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x8c(%rbp)
movzbl -0xad(%rbp), %ecx
andl $0x1, %ecx
movl %ecx, %eax
leal 0x1(%rax,%rax), %eax
movl %eax, -0xb4(%rbp)
movl $0x1, -0xc8(%rbp)
movl -0xb4(%rbp), %eax
movl %eax, -0xc4(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0xc0(%rbp)
movl $0xffffffff, -0xbc(%rbp) # imm = 0xFFFFFFFF
movl -0x8c(%rbp), %eax
movl %eax, -0xb8(%rbp)
movq -0xa0(%rbp), %rdi
addq $0x28, %rdi
leaq -0xc8(%rbp), %rsi
callq 0x2f430
jmp 0x2a353
jmp 0x2a355
jmp 0x2a357
leaq -0x98(%rbp), %rdi
xorl %esi, %esi
callq 0x2d2e0
movq %rax, -0xd0(%rbp)
jmp 0x2a1d7
leaq -0x50(%rbp), %rdi
callq 0x2d550
addq $0xe0, %rsp
popq %rbp
retq
movq -0x78(%rbp), %rdi
callq 0x3560
nopl (%rax)