// File: /workspace/github_c_makefile_star2_O0/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
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
cmpl $0x1, -0xc(%rbp)
jne 0x1541a
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
cmpl $0x1, 0x24(%rax)
jne 0x15413
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0xf8(%rbp)
movl 0x24(%rax), %eax
movl %eax, -0xec(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x3460
movq -0xe8(%rbp), %rdx
leaq 0x20591(%rip), %rsi     # 0x3593c
leaq -0x30(%rbp), %rdi
callq 0xfd00
jmp 0x153b6
movl -0xec(%rbp), %esi
movq -0xf8(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq 0x15980
jmp 0x153ce
leaq -0x30(%rbp), %rdi
callq 0x34f8
leaq -0x31(%rbp), %rdi
callq 0x32f0
jmp 0x15415
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x15405
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x34f8
leaq -0x31(%rbp), %rdi
callq 0x32f0
jmp 0x15969
jmp 0x15415
jmp 0x15960
cmpl $0x2, -0xc(%rbp)
jne 0x1595e
movq 0x28ba5(%rip), %rdi     # 0x3dfd0
movq 0x28b7e(%rip), %rsi     # 0x3dfb0
callq 0x32b0
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %rax
movq (%rax), %rdi
leaq 0x209a8(%rip), %rsi     # 0x35df9
callq 0x30b00
testb $0x1, %al
jne 0x1545c
jmp 0x1546f
movq 0x28b6d(%rip), %rdi     # 0x3dfd0
leaq 0x20994(%rip), %rsi     # 0x35dfe
callq 0x3250
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %rax
movq (%rax), %rsi
movq 0x28b47(%rip), %rdi     # 0x3dfd0
callq 0x3230
movq %rax, %rdi
leaq 0x20969(%rip), %rsi     # 0x35e01
callq 0x3250
movq %rax, %rdi
movq 0x28b09(%rip), %rsi     # 0x3dfb0
callq 0x32b0
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %rax
movq (%rax), %rdi
leaq 0x20933(%rip), %rsi     # 0x35df9
callq 0x30c10
testb $0x1, %al
jne 0x154d4
jmp 0x15849
movq 0x28af5(%rip), %rdi     # 0x3dfd0
leaq 0x20921(%rip), %rsi     # 0x35e03
callq 0x3250
movq %rax, -0x108(%rbp)
leaq -0x69(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x3460
movq -0x100(%rbp), %rdx
leaq 0x20430(%rip), %rsi     # 0x3593c
leaq -0x68(%rbp), %rdi
callq 0xfd00
jmp 0x15517
leaq 0x28e32(%rip), %rdi     # 0x3e350
leaq -0x68(%rbp), %rsi
callq 0xfe90
movq %rax, -0x110(%rbp)
jmp 0x15530
movq -0x110(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x120(%rbp)
leaq -0x91(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x3460
movq -0x118(%rbp), %rdx
leaq 0x20866(%rip), %rsi     # 0x35dc8
leaq -0x90(%rbp), %rdi
callq 0xfd00
jmp 0x15570
movq -0x120(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x30860
movq %rax, -0x128(%rbp)
jmp 0x1558c
movq -0x108(%rbp), %rdi
movq -0x128(%rbp), %rax
movl (%rax), %esi
callq 0x3430
movq %rax, -0x130(%rbp)
jmp 0x155aa
movq -0x130(%rbp), %rdi
movq 0x289f8(%rip), %rsi     # 0x3dfb0
callq 0x32b0
jmp 0x155bf
leaq -0x90(%rbp), %rdi
callq 0x34f8
leaq -0x91(%rbp), %rdi
callq 0x32f0
leaq -0x68(%rbp), %rdi
callq 0x34f8
leaq -0x69(%rbp), %rdi
callq 0x32f0
movq 0x289e0(%rip), %rdi     # 0x3dfd0
movq %rdi, -0x150(%rbp)
leaq 0x20815(%rip), %rsi     # 0x35e13
callq 0x3250
movq %rax, %rdi
movq 0x289a3(%rip), %rsi     # 0x3dfb0
callq 0x32b0
movq -0x150(%rbp), %rdi
leaq 0x207e3(%rip), %rsi     # 0x35e03
callq 0x3250
movq %rax, -0x148(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %rax
movq (%rax), %rsi
leaq 0x28d0a(%rip), %rdi     # 0x3e350
callq 0x30a20
movq (%rax), %rax
movq %rax, -0x140(%rbp)
leaq -0xb9(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x3460
movq -0x138(%rbp), %rdx
leaq 0x20751(%rip), %rsi     # 0x35dc7
leaq -0xb8(%rbp), %rdi
callq 0xfd00
jmp 0x15684
movq -0x140(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x30860
movq %rax, -0x158(%rbp)
jmp 0x156a0
movq -0x148(%rbp), %rdi
movq -0x158(%rbp), %rax
movl (%rax), %esi
shll $0x2, %esi
callq 0x3430
movq %rax, -0x160(%rbp)
jmp 0x156c1
movq -0x160(%rbp), %rdi
movq 0x288e1(%rip), %rsi     # 0x3dfb0
callq 0x32b0
jmp 0x156d6
leaq -0xb8(%rbp), %rdi
callq 0x34f8
leaq -0xb9(%rbp), %rdi
callq 0x32f0
movq 0x288db(%rip), %rdi     # 0x3dfd0
leaq 0x20725(%rip), %rsi     # 0x35e21
callq 0x3250
movq %rax, %rdi
movq 0x288a5(%rip), %rsi     # 0x3dfb0
callq 0x32b0
movq 0x288b9(%rip), %rdi     # 0x3dfd0
leaq 0x20714(%rip), %rsi     # 0x35e32
callq 0x3250
movq %rax, %rdi
movq 0x28883(%rip), %rsi     # 0x3dfb0
callq 0x32b0
leaq 0x28b5f(%rip), %rax     # 0x3e298
cmpl $0x1, (%rax)
je 0x15847
movq 0x28887(%rip), %rdi     # 0x3dfd0
leaq 0x206f0(%rip), %rsi     # 0x35e40
callq 0x3250
movq %rax, %rdi
movq 0x28851(%rip), %rsi     # 0x3dfb0
callq 0x32b0
movq 0x28865(%rip), %rdi     # 0x3dfd0
leaq 0x2086b(%rip), %rsi     # 0x35fdd
callq 0x3250
movq %rax, %rdi
leaq 0x28b17(%rip), %rax     # 0x3e298
movl (%rax), %esi
callq 0x3430
movq %rax, %rdi
leaq 0x2066f(%rip), %rsi     # 0x35e01
callq 0x3250
movq %rax, %rdi
movq 0x2880f(%rip), %rsi     # 0x3dfb0
callq 0x32b0
jmp 0x15847
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x15802
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x157f9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x157ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x34f8
leaq -0x91(%rbp), %rdi
callq 0x32f0
leaq -0x68(%rbp), %rdi
callq 0x34f8
leaq -0x69(%rbp), %rdi
callq 0x32f0
jmp 0x15969
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x15836
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x34f8
leaq -0xb9(%rbp), %rdi
callq 0x32f0
jmp 0x15969
jmp 0x15849
movq 0x28780(%rip), %rdi     # 0x3dfd0
movq %rdi, -0x188(%rbp)
leaq 0x205c3(%rip), %rsi     # 0x35e21
callq 0x3250
movq %rax, %rdi
movq 0x28743(%rip), %rsi     # 0x3dfb0
movq %rsi, -0x180(%rbp)
callq 0x32b0
movq -0x188(%rbp), %rdi
leaq 0x205c0(%rip), %rsi     # 0x35e47
callq 0x3250
movq -0x180(%rbp), %rsi
movq %rax, %rdi
callq 0x32b0
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rcx
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
movq %rcx, -0x178(%rbp)
movl 0x24(%rcx), %ecx
movl %ecx, -0x16c(%rbp)
movq 0x28(%rax), %rax
movq (%rax), %rsi
leaq -0xe0(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x3150
movq -0x178(%rbp), %rdi
movl -0x16c(%rbp), %esi
movq -0x168(%rbp), %rdx
xorl %ecx, %ecx
callq 0x15bc0
jmp 0x158f2
leaq -0xe0(%rbp), %rdi
callq 0x34f8
movq 0x286cb(%rip), %rdi     # 0x3dfd0
leaq 0x2054a(%rip), %rsi     # 0x35e56
callq 0x3250
movq %rax, %rdi
movq 0x28695(%rip), %rsi     # 0x3dfb0
callq 0x32b0
movq 0x286a9(%rip), %rdi     # 0x3dfd0
leaq 0x20537(%rip), %rsi     # 0x35e65
callq 0x3250
movq %rax, %rdi
movq 0x28673(%rip), %rsi     # 0x3dfb0
callq 0x32b0
jmp 0x1595e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x34f8
jmp 0x15969
jmp 0x15960
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x3450
nopw %cs:(%rax,%rax)