// File: /workspace/github_c_makefile_star2_O2/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 %rbx
subq $0x88, %rsp
movq %rdi, %rbx
cmpl $0x2, %esi
je 0x9377
cmpl $0x1, %esi
jne 0x9647
movq 0x28(%rbx), %rax
movq (%rax), %rcx
cmpl $0x1, 0x24(%rcx)
jne 0x9647
movq 0x8(%rax), %rbx
movl 0x24(%rbx), %r14d
leaq 0xf541(%rip), %rsi      # 0x1888c
leaq -0xa0(%rbp), %rdi
leaq -0x40(%rbp), %rdx
callq 0x70d8
movq %rbx, %rdi
movl %r14d, %esi
callq 0x9699
leaq -0xa0(%rbp), %rdi
callq 0x23c8
jmp 0x9647
movq 0x15c52(%rip), %rdi     # 0x1efd0
callq 0x2120
movq 0x28(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %rax
movq (%rax), %rdi
leaq 0xf950(%rip), %rsi      # 0x18ce9
callq 0x1563d
testb %al, %al
je 0x93b5
movq 0x15c27(%rip), %rdi     # 0x1efd0
leaq 0xf93e(%rip), %rsi      # 0x18cee
callq 0x21a0
movq 0x28(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %rax
movq (%rax), %rsi
movq 0x15c05(%rip), %rdi     # 0x1efd0
callq 0x2190
leaq 0xf91a(%rip), %rsi      # 0x18cf1
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x2120
movq 0x28(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %rax
movq (%rax), %rdi
leaq 0xf8ec(%rip), %rsi      # 0x18ce9
callq 0x156b3
testb %al, %al
je 0x95a8
movq 0x15bbf(%rip), %rdi     # 0x1efd0
leaq 0xf8db(%rip), %rsi      # 0x18cf3
callq 0x21a0
movq %rax, %r14
leaq 0xf465(%rip), %rsi      # 0x1888c
leaq -0x40(%rbp), %rdi
leaq -0x1a(%rbp), %rdx
callq 0x70d8
leaq 0x15e7d(%rip), %rdi     # 0x1f2b8
leaq -0x40(%rbp), %rsi
callq 0x718c
movq (%rax), %r15
leaq 0xf86a(%rip), %rsi      # 0x18cb8
leaq -0x60(%rbp), %rdi
leaq -0x19(%rbp), %rdx
callq 0x70d8
leaq -0x60(%rbp), %rsi
movq %r15, %rdi
callq 0x15500
movl (%rax), %esi
movq %r14, %rdi
callq 0x2320
movq %rax, %rdi
callq 0x2120
leaq -0x60(%rbp), %rdi
callq 0x23c8
leaq -0x40(%rbp), %rdi
callq 0x23c8
movq 0x15b3e(%rip), %r14     # 0x1efd0
leaq 0xf86a(%rip), %rsi      # 0x18d03
movq %r14, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x2120
leaq 0xf843(%rip), %rsi      # 0x18cf3
movq %r14, %rdi
callq 0x21a0
movq %rax, %r14
movq 0x28(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %rax
movq (%rax), %rsi
leaq 0x15de7(%rip), %rdi     # 0x1f2b8
callq 0x155d4
movq (%rax), %r15
leaq 0xf7d7(%rip), %rsi      # 0x18cb7
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rdx
callq 0x70d8
leaq -0x40(%rbp), %rsi
movq %r15, %rdi
callq 0x15500
movl (%rax), %esi
shll $0x2, %esi
movq %r14, %rdi
callq 0x2320
movq %rax, %rdi
callq 0x2120
leaq -0x40(%rbp), %rdi
callq 0x23c8
movq 0x15ab2(%rip), %r14     # 0x1efd0
leaq 0xf7ec(%rip), %rsi      # 0x18d11
movq %r14, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x2120
leaq 0xf7e6(%rip), %rsi      # 0x18d22
movq %r14, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x2120
leaq 0x15cad(%rip), %r15     # 0x1f200
cmpl $0x1, (%r15)
je 0x95a8
movq 0x15a70(%rip), %r14     # 0x1efd0
leaq 0xf7c9(%rip), %rsi      # 0x18d30
movq %r14, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x2120
leaq 0xf94f(%rip), %rsi      # 0x18ecd
movq %r14, %rdi
callq 0x21a0
movl (%r15), %esi
movq %rax, %rdi
callq 0x2320
leaq 0xf759(%rip), %rsi      # 0x18cf1
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x2120
movq 0x15a21(%rip), %r14     # 0x1efd0
leaq 0xf75b(%rip), %rsi      # 0x18d11
movq %r14, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x2120
leaq 0xf76a(%rip), %rsi      # 0x18d37
movq %r14, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x2120
movq 0x28(%rbx), %rax
movq 0x8(%rax), %rcx
movq 0x10(%rax), %rbx
movq 0x28(%rcx), %rax
movq (%rax), %rsi
leaq -0x80(%rbp), %r14
movq %r14, %rdi
callq 0x2280
movq %rbx, %rdi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x9790
leaq -0x80(%rbp), %rdi
callq 0x23c8
movq 0x159b7(%rip), %rbx     # 0x1efd0
leaq 0xf726(%rip), %rsi      # 0x18d46
movq %rbx, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x2120
leaq 0xf71e(%rip), %rsi      # 0x18d55
movq %rbx, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x2120
addq $0x88, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9669
jmp 0x9677
jmp 0x9677
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
jmp 0x968c
jmp 0x9669
movq %rax, %rbx
jmp 0x9691
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
jmp 0x968c
movq %rax, %rbx
jmp 0x9688
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x23c8
leaq -0x40(%rbp), %rdi
callq 0x23c8
movq %rbx, %rdi
callq 0x2340