// File: /workspace/github_c_makefile_star2_O3/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 0xd8b0
cmpl $0x1, %esi
jne 0xddc6
movq 0x28(%r14), %rax
movq (%rax), %rcx
cmpl $0x1, 0x24(%rcx)
jne 0xddc6
movq 0x8(%rax), %rbx
movl 0x24(%rbx), %r14d
leaq -0x98(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x1401e(%rip), %rsi     # 0x2188c
leaq 0x14019(%rip), %rdx     # 0x2188e
leaq -0xa8(%rbp), %rdi
callq 0xb0aa
movq %rbx, %rdi
movl %r14d, %esi
callq 0xde5a
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
je 0xddc6
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x21e0
jmp 0xddc6
movq 0x1a719(%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 0x143f5(%rip), %rsi     # 0x21ce9
callq 0x20e0
testl %eax, %eax
je 0xd915
movq 0x1a6cc(%rip), %rdi     # 0x27fd0
leaq 0x143e3(%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 0x1a69e(%rip), %rbx     # 0x27fd0
movq %rbx, %rdi
callq 0x2230
movq %rax, %r15
leaq 0x143ad(%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 0x1435b(%rip), %rsi     # 0x21ce9
callq 0x20e0
testl %eax, %eax
jne 0xdc80
movq 0x1a62e(%rip), %rdi     # 0x27fd0
leaq 0x1434a(%rip), %rsi     # 0x21cf3
movl $0xf, %edx
callq 0x2230
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x13eca(%rip), %rsi     # 0x2188c
leaq 0x13ec5(%rip), %rdx     # 0x2188e
leaq -0x48(%rbp), %rdi
callq 0xb0aa
leaq 0x1a8d7(%rip), %rdi     # 0x282b0
leaq -0x48(%rbp), %rsi
callq 0xae5e
movq (%rax), %r15
leaq -0x58(%rbp), %r13
movq %r13, -0x10(%r13)
leaq 0x142c4(%rip), %rsi     # 0x21cb8
leaq 0x142be(%rip), %rdx     # 0x21cb9
leaq -0x68(%rbp), %rdi
callq 0xb0aa
leaq -0x68(%rbp), %rsi
movq %r15, %rdi
callq 0x1e3be
movl (%rax), %esi
movq 0x1a5b7(%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 0xda60
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x21e0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %r13
cmpq %r13, %rdi
je 0xda79
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21e0
leaq 0x14283(%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 0x14238(%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 0x1a7d2(%rip), %rdi     # 0x282b0
callq 0x1e4be
movq (%rax), %r15
leaq -0x48(%rbp), %rdi
movq %r13, (%rdi)
leaq 0x141c3(%rip), %rsi     # 0x21cb7
leaq 0x141be(%rip), %rdx     # 0x21cb9
callq 0xb0aa
leaq -0x48(%rbp), %rsi
movq %r15, %rdi
callq 0x1e3be
movl (%rax), %esi
shll $0x2, %esi
movq 0x1a4b8(%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 0xdb5f
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21e0
leaq 0x141ab(%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 0x14181(%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 0x1a61c(%rip), %r12     # 0x281f8
cmpl $0x1, (%r12)
je 0xdc80
leaq 0x14142(%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 0x142a4(%rip), %rsi     # 0x21ecd
movl $0x3, %edx
movq %r15, %rdi
callq 0x2230
movl (%r12), %esi
movq %r15, %rdi
callq 0x2330
movq %rax, %r15
leaq 0x140a5(%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 0x1408a(%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 0x14075(%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 0xb00c
movq %r14, %rdi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xdfa5
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0xdd50
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x21e0
leaq 0x13fef(%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 0x13fc3(%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 0xdde1
jmp 0xdddc
movq %rax, %rbx
jmp 0xde39
movq %rax, %rbx
jmp 0xde52
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
je 0xde52
movq -0x98(%rbp), %rsi
jmp 0xde4a
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0xde52
movq -0x78(%rbp), %rsi
jmp 0xde4a
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
jne 0xde46
jmp 0xde52
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r13, %rdi
je 0xde39
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x21e0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xde52
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21e0
movq %rbx, %rdi
callq 0x2360