// File: /workspace/github_c_makefile_star2_O1/zyearn[P]SmallC/codegen.cpp
// Function: genExtdef(treeNode*, int)
void genExtdef(treeNode* node,int type)
{
    if(type == 1)//type == 1´¦Àí¶ÔÈ«¾Ö±äÁ¿¸³Öµ
    {   
        if(node->child[0]->type == 1)//¶Ôint int[]¸³Öµ
        {
            genExtvars(node->child[1], node->child[1]->type, "_G");
        }
        else//¶Ôstruct¸³Öµ
        {
        
        }
    }
    else if(type == 2)
    {
        // type == 2 Éú³Éº¯Êý´úÂë
        cout << endl; 
        if (node->child[1]->child[0]->data != "main") cout << "__"; 
        cout << node->child[1]->child[0]->data << ":" << endl;
        
        //mainÈ«¾Ö±äÁ¿ºÍ¾Ö²¿±äÁ¿ÈëÕ»
        if (node->child[1]->child[0]->data == "main")
        {
            cout << "add $sp, $sp, -" << (*FT["_G"])["#"] << endl;
            cout << "move $s2, $sp" << endl;
            //ÒÔÉÏÊÇ´¦ÀíÈ«¾Ö±äÁ¿£¬$s2ÓÃÀ´×÷Îª»ùÖ·¼Ä´æÆ÷
            //´Ë´¦²åÈë¾Ö²¿±äÁ¿
            cout << "add $sp, $sp, -" << (*FT[node->child[1]->child[0]->data])["##"] * 4 << endl;
            cout << "add $sp, $sp, -4" << endl;
            cout << "move $s0, $sp" << endl;
            //È»ºóÌø×ªµ½ÉèÖÃÈ«¾Ö±äÁ¿µÄµØ·½, È«¾Ö±äÁ¿µÄ¸³Öµ
            if( globalNumber != 1)  // !=ËµÃ÷´æÔÚ
            {
                cout << "j _G_1" << endl;
                //Ìø»ØÀ´
                cout << "_G_" << globalNumber << ":" << endl;
            }           
        }

        cout << "add $sp, $sp, -4" << endl; 
        cout << "sw $ra, 0($sp)" << endl; ////ÉèÖÃÐÂµÄ·µ»ØµØÖ·
//      printf("ready to genStmtblock()\n");
        genStmtblock(node->child[2], node->child[2]->type, node->child[1]->child[0]->data);
        
        /*
        if (node->child[0]->data == "main"){
            cout << "li $v0, 1" << endl;
            cout << "la $a0, 0($t0)" << endl;
            cout << "syscall" << endl;
            cout << "li $v0, 4" << endl;
            cout << "la $a0, newline" << endl;
            cout << "syscall" << endl;
        }*/

        cout << "lw $s1 -4($s0)" << endl;
        cout << "jr $s1" << endl;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %r14
cmpl $0x2, %esi
je 0xda85
cmpl $0x1, %esi
jne 0xdf9b
movq 0x28(%r14), %rax
movq (%rax), %rcx
cmpl $0x1, 0x24(%rcx)
jne 0xdf9b
movq 0x8(%rax), %rbx
movl 0x24(%rbx), %r14d
leaq -0x98(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x13e49(%rip), %rsi     # 0x2188c
leaq 0x13e44(%rip), %rdx     # 0x2188e
leaq -0xa8(%rbp), %rdi
callq 0xb264
movq %rbx, %rdi
movl %r14d, %esi
callq 0xe02f
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
je 0xdf9b
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x21e0
jmp 0xdf9b
movq 0x1a544(%rip), %rbx     # 0x27fd0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movq 0x28(%r14), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %rax
movq (%rax), %rdi
leaq 0x14220(%rip), %rsi     # 0x21ce9
callq 0x20e0
testl %eax, %eax
je 0xdaea
movq 0x1a4f7(%rip), %rdi     # 0x27fd0
leaq 0x1420e(%rip), %rsi     # 0x21cee
movl $0x2, %edx
callq 0x2230
movq 0x28(%r14), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq 0x1a4c9(%rip), %rbx     # 0x27fd0
movq %rbx, %rdi
callq 0x2230
movq %rax, %r15
leaq 0x141d8(%rip), %rsi     # 0x21cf1
movl $0x1, %edx
movq %rax, %rdi
callq 0x2230
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movq 0x28(%r14), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %rax
movq (%rax), %rdi
leaq 0x14186(%rip), %rsi     # 0x21ce9
callq 0x20e0
testl %eax, %eax
jne 0xde55
movq 0x1a459(%rip), %rdi     # 0x27fd0
leaq 0x14175(%rip), %rsi     # 0x21cf3
movl $0xf, %edx
callq 0x2230
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x13cf5(%rip), %rsi     # 0x2188c
leaq 0x13cf0(%rip), %rdx     # 0x2188e
leaq -0x48(%rbp), %rdi
callq 0xb264
leaq 0x1a702(%rip), %rdi     # 0x282b0
leaq -0x48(%rbp), %rsi
callq 0xb01a
movq (%rax), %r15
leaq -0x58(%rbp), %r13
movq %r13, -0x10(%r13)
leaq 0x140ef(%rip), %rsi     # 0x21cb8
leaq 0x140e9(%rip), %rdx     # 0x21cb9
leaq -0x68(%rbp), %rdi
callq 0xb264
leaq -0x68(%rbp), %rsi
movq %r15, %rdi
callq 0x1e6b4
movl (%rax), %esi
movq 0x1a3e2(%rip), %r15     # 0x27fd0
movq %r15, %rdi
callq 0x2330
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movq -0x68(%rbp), %rdi
cmpq %r13, %rdi
je 0xdc35
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x21e0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %r13
cmpq %r13, %rdi
je 0xdc4e
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21e0
leaq 0x140ae(%rip), %rsi     # 0x21d03
movl $0xd, %edx
movq %r15, %rdi
callq 0x2230
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
leaq 0x14063(%rip), %rsi     # 0x21cf3
movl $0xf, %edx
movq %r15, %rdi
callq 0x2230
movq 0x28(%r14), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %rax
movq (%rax), %rsi
leaq 0x1a5fd(%rip), %rdi     # 0x282b0
callq 0x1e7b4
movq (%rax), %r15
leaq -0x48(%rbp), %rdi
movq %r13, (%rdi)
leaq 0x13fee(%rip), %rsi     # 0x21cb7
leaq 0x13fe9(%rip), %rdx     # 0x21cb9
callq 0xb264
leaq -0x48(%rbp), %rsi
movq %r15, %rdi
callq 0x1e6b4
movl (%rax), %esi
shll $0x2, %esi
movq 0x1a2e3(%rip), %r15     # 0x27fd0
movq %r15, %rdi
callq 0x2330
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0xdd34
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21e0
leaq 0x13fd6(%rip), %rsi     # 0x21d11
movl $0x10, %edx
movq %r15, %rdi
callq 0x2230
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
leaq 0x13fac(%rip), %rsi     # 0x21d22
movl $0xd, %edx
movq %r15, %rdi
callq 0x2230
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
leaq 0x1a447(%rip), %r12     # 0x281f8
cmpl $0x1, (%r12)
je 0xde55
leaq 0x13f6d(%rip), %rsi     # 0x21d30
movl $0x6, %edx
movq %r15, %rdi
callq 0x2230
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
leaq 0x140cf(%rip), %rsi     # 0x21ecd
movl $0x3, %edx
movq %r15, %rdi
callq 0x2230
movl (%r12), %esi
movq %r15, %rdi
callq 0x2330
movq %rax, %r15
leaq 0x13ed0(%rip), %rsi     # 0x21cf1
movl $0x1, %edx
movq %rax, %rdi
callq 0x2230
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
leaq 0x13eb5(%rip), %rsi     # 0x21d11
movl $0x10, %edx
movq %rbx, %rdi
callq 0x2230
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
leaq 0x13ea0(%rip), %rsi     # 0x21d37
movl $0xe, %edx
movq %rbx, %rdi
callq 0x2230
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movq 0x28(%r14), %rax
movq 0x8(%rax), %rcx
movq 0x10(%rax), %r14
movq 0x28(%rcx), %rax
movq (%rax), %rax
leaq -0x78(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0x88(%rbp), %r15
movq %r15, %rdi
callq 0xb1ca
movq %r14, %rdi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xe17a
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0xdf25
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x21e0
leaq 0x13e1a(%rip), %rsi     # 0x21d46
movl $0xe, %edx
movq %rbx, %rdi
callq 0x2230
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
leaq 0x13dee(%rip), %rsi     # 0x21d55
movl $0x6, %edx
movq %rbx, %rdi
callq 0x2230
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xdfb6
jmp 0xdfb1
movq %rax, %rbx
jmp 0xe00e
movq %rax, %rbx
jmp 0xe027
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
je 0xe027
movq -0x98(%rbp), %rsi
jmp 0xe01f
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0xe027
movq -0x78(%rbp), %rsi
jmp 0xe01f
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
jne 0xe01b
jmp 0xe027
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r13, %rdi
je 0xe00e
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x21e0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xe027
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21e0
movq %rbx, %rdi
callq 0x2360