// File: zhengwangsun[P]pas2c/semantics.cpp
// Function: subprogram_head(int)
void subprogram_head(int k)
{
	TreeNode tNode= tree.node[k];
	TreeNode childNode;
    if (lookahead(k) == 120)//120是function
    {
        //先获得 此函数的返回值类型，还有id的一些信息
        int returnType = standard_type(tree.node[k].child[4]);
        
        int id_position = tree.node[k].child[1];//将id节点在树中的下标值赋给id_position
        
        if(currentTable == "main")
        {
            //在主符号表中填入此函数id然后建立一个子符号表，再调用arguments
            enterMain(id_position, 4);
            mkTable(tree.node[tree.node[k].child[1]].value, 4, returnType);
            currentTable = tree.node[tree.node[k].child[1]].value;

			childNode=tree.node[tNode.child[1]];
			code[currentLine].append(" ");
			code[currentLine].append(childNode.value);
            code[currentLine].append("(");
            arguments(tree.node[k].child[2]);
            code[currentLine].append(")");
            code[currentLine++].append("\n");
        }
        else
        {
            cout<<"double embed where subprogram_head1"<<endl;
            enterSub(id_position, 4, currentTable, 1);//填入子表的agument
        }
        
    }
    if (lookahead(k) == 140)//140是procedure
    {
        int id_position = tree.node[k].child[1];//将id节点在树中的下标值赋给id_position
        childNode=tree.node[tNode.child[0]];
        if(currentTable == "main")
        {
            //在主符号表中填入此函数id然后建立一个子符号表，再调用arguments
            enterMain(id_position, 5);
            mkTable(tree.node[tree.node[k].child[1]].value, 5, 0);
            currentTable = tree.node[tree.node[k].child[1]].value;
            code[currentLine].append("void ");
            code[currentLine].append(currentTable);
            
            code[currentLine].append("(");
			
            arguments(tree.node[k].child[2]);
            
            code[currentLine].append(")");
            
            code[currentLine++].append("\n");
        }
        else
        {
            cout<<"double embed where subprogram_head2 "<<endl;
            enterSub(id_position, 5, currentTable, 1);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movl %edi, -0x4(%rbp)
movslq -0x4(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb6a48(%rip), %rax     # 0xc6138
leaq 0x8(%rax,%rcx), %rsi
leaq -0xb0(%rbp), %rdi
callq 0x14920
leaq -0x158(%rbp), %rdi
callq 0x149d0
movl -0x4(%rbp), %edi
callq 0xca50
movl %eax, -0x1fc(%rbp)
jmp 0xf71d
movl -0x1fc(%rbp), %eax
cmpl $0x78, %eax
jne 0xfa20
movslq -0x4(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb69fa(%rip), %rax     # 0xc6138
movl 0x1c(%rax,%rcx), %edi
callq 0xf1b0
movl %eax, -0x200(%rbp)
jmp 0xf74f
movl -0x200(%rbp), %eax
movl %eax, -0x168(%rbp)
movslq -0x4(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb69cb(%rip), %rax     # 0xc6138
movl 0x10(%rax,%rcx), %eax
movl %eax, -0x16c(%rbp)
leaq 0xb01fa(%rip), %rdi     # 0xbf978
leaq 0xed35(%rip), %rsi      # 0x1e4ba
callq 0xc770
movb %al, -0x201(%rbp)
jmp 0xf792
movb -0x201(%rbp), %al
testb $0x1, %al
jne 0xf7a1
jmp 0xf97d
movl -0x16c(%rbp), %edi
movl $0x4, %esi
callq 0xd230
jmp 0xf7b3
movslq -0x4(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb6973(%rip), %rax     # 0xc6138
movslq 0x10(%rax,%rcx), %rcx
imulq $0xa8, %rcx, %rcx
leaq 0x88(%rax,%rcx), %rsi
leaq -0x190(%rbp), %rdi
callq 0x30e0
jmp 0xf7e7
movl -0x168(%rbp), %edx
leaq -0x190(%rbp), %rdi
movl $0x4, %esi
callq 0xfd30
jmp 0xf800
leaq -0x190(%rbp), %rdi
callq 0x34c8
movslq -0x4(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb691a(%rip), %rax     # 0xc6138
movslq 0x10(%rax,%rcx), %rcx
imulq $0xa8, %rcx, %rcx
leaq 0x88(%rax,%rcx), %rsi
leaq 0xb013f(%rip), %rdi     # 0xbf978
callq 0x3030
jmp 0xf840
movslq -0xa8(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb68e3(%rip), %rax     # 0xc6138
leaq 0x8(%rax,%rcx), %rsi
leaq -0x158(%rbp), %rdi
callq 0x14a10
jmp 0xf868
movslq 0xb0db1(%rip), %rax     # 0xc0620
shlq $0x5, %rax
leaq 0xb0126(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xec77(%rip), %rsi      # 0x1e4fb
callq 0x3490
jmp 0xf88b
movslq 0xb0d8e(%rip), %rax     # 0xc0620
shlq $0x5, %rax
leaq 0xb0103(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq -0xd8(%rbp), %rsi
callq 0x34a0
jmp 0xf8ae
movslq 0xb0d6b(%rip), %rax     # 0xc0620
shlq $0x5, %rax
leaq 0xb00e0(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xf86c(%rip), %rsi      # 0x1f136
callq 0x3490
jmp 0xf8d1
movslq -0x4(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb6855(%rip), %rax     # 0xc6138
movl 0x14(%rax,%rcx), %edi
callq 0xfdd0
jmp 0xf8ee
movslq 0xb0d2b(%rip), %rax     # 0xc0620
shlq $0x5, %rax
leaq 0xb00a0(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xf9f2(%rip), %rsi      # 0x1f2fc
callq 0x3490
jmp 0xf911
movslq 0xb0d08(%rip), %rax     # 0xc0620
movl %eax, %ecx
incl %ecx
movl %ecx, 0xb0cfe(%rip)     # 0xc0620
shlq $0x5, %rax
leaq 0xb0073(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xec87(%rip), %rsi      # 0x1e5be
callq 0x3490
jmp 0xf93e
jmp 0xfa1e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0xfd02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x34c8
jmp 0xfd02
movq 0x16644(%rip), %rdi     # 0x25fc8
leaq 0xed08(%rip), %rsi      # 0x1e693
callq 0x3280
movq %rax, -0x210(%rbp)
jmp 0xf999
movq -0x210(%rbp), %rdi
movq 0x16609(%rip), %rsi     # 0x25fb0
callq 0x32b0
jmp 0xf9ae
movl -0x16c(%rbp), %eax
movl %eax, -0x214(%rbp)
leaq 0xaffb7(%rip), %rsi     # 0xbf978
leaq -0x1b0(%rbp), %rdi
callq 0x30e0
jmp 0xf9cf
movl -0x214(%rbp), %edi
movl $0x4, %esi
leaq -0x1b0(%rbp), %rdx
movl $0x1, %ecx
callq 0xd340
jmp 0xf9ed
leaq -0x1b0(%rbp), %rdi
callq 0x34c8
jmp 0xfa1e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x34c8
jmp 0xfd02
jmp 0xfa20
movl -0x4(%rbp), %edi
callq 0xca50
movl %eax, -0x218(%rbp)
jmp 0xfa30
movl -0x218(%rbp), %eax
cmpl $0x8c, %eax
jne 0xfce1
movslq -0x4(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb66e5(%rip), %rax     # 0xc6138
movl 0x10(%rax,%rcx), %ecx
movl %ecx, -0x1b4(%rbp)
movslq -0xac(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
leaq 0x8(%rax,%rcx), %rsi
leaq -0x158(%rbp), %rdi
callq 0x14a10
jmp 0xfa7e
leaq 0xafef3(%rip), %rdi     # 0xbf978
leaq 0xea2e(%rip), %rsi      # 0x1e4ba
callq 0xc770
movb %al, -0x219(%rbp)
jmp 0xfa99
movb -0x219(%rbp), %al
testb $0x1, %al
jne 0xfaa8
jmp 0xfc41
movl -0x1b4(%rbp), %edi
movl $0x5, %esi
callq 0xd230
jmp 0xfaba
movslq -0x4(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb666c(%rip), %rax     # 0xc6138
movslq 0x10(%rax,%rcx), %rcx
imulq $0xa8, %rcx, %rcx
leaq 0x88(%rax,%rcx), %rsi
leaq -0x1d8(%rbp), %rdi
callq 0x30e0
jmp 0xfaee
leaq -0x1d8(%rbp), %rdi
movl $0x5, %esi
xorl %edx, %edx
callq 0xfd30
jmp 0xfb03
leaq -0x1d8(%rbp), %rdi
callq 0x34c8
movslq -0x4(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb6617(%rip), %rax     # 0xc6138
movslq 0x10(%rax,%rcx), %rcx
imulq $0xa8, %rcx, %rcx
leaq 0x88(%rax,%rcx), %rsi
leaq 0xafe3c(%rip), %rdi     # 0xbf978
callq 0x3030
jmp 0xfb43
movslq 0xb0ad6(%rip), %rax     # 0xc0620
shlq $0x5, %rax
leaq 0xafe4b(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xeb58(%rip), %rsi      # 0x1e6b7
callq 0x3490
jmp 0xfb66
movslq 0xb0ab3(%rip), %rax     # 0xc0620
shlq $0x5, %rax
leaq 0xafe28(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xafdf6(%rip), %rsi     # 0xbf978
callq 0x34a0
jmp 0xfb89
movslq 0xb0a90(%rip), %rax     # 0xc0620
shlq $0x5, %rax
leaq 0xafe05(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xf591(%rip), %rsi      # 0x1f136
callq 0x3490
jmp 0xfbac
movslq -0x4(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb657a(%rip), %rax     # 0xc6138
movl 0x14(%rax,%rcx), %edi
callq 0xfdd0
jmp 0xfbc9
movslq 0xb0a50(%rip), %rax     # 0xc0620
shlq $0x5, %rax
leaq 0xafdc5(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xf717(%rip), %rsi      # 0x1f2fc
callq 0x3490
jmp 0xfbec
movslq 0xb0a2d(%rip), %rax     # 0xc0620
movl %eax, %ecx
incl %ecx
movl %ecx, 0xb0a23(%rip)     # 0xc0620
shlq $0x5, %rax
leaq 0xafd98(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xe9ac(%rip), %rsi      # 0x1e5be
callq 0x3490
jmp 0xfc19
jmp 0xfcdf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x34c8
jmp 0xfd02
movq 0x16380(%rip), %rdi     # 0x25fc8
leaq 0xea6e(%rip), %rsi      # 0x1e6bd
callq 0x3280
movq %rax, -0x228(%rbp)
jmp 0xfc5d
movq -0x228(%rbp), %rdi
movq 0x16345(%rip), %rsi     # 0x25fb0
callq 0x32b0
jmp 0xfc72
movl -0x1b4(%rbp), %eax
movl %eax, -0x22c(%rbp)
leaq 0xafcf3(%rip), %rsi     # 0xbf978
leaq -0x1f8(%rbp), %rdi
callq 0x30e0
jmp 0xfc93
movl -0x22c(%rbp), %edi
movl $0x5, %esi
leaq -0x1f8(%rbp), %rdx
movl $0x1, %ecx
callq 0xd340
jmp 0xfcb1
leaq -0x1f8(%rbp), %rdi
callq 0x34c8
jmp 0xfcdf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x34c8
jmp 0xfd02
jmp 0xfce1
leaq -0x158(%rbp), %rdi
callq 0x14a90
leaq -0xb0(%rbp), %rdi
callq 0x14a90
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
leaq -0x158(%rbp), %rdi
callq 0x14a90
leaq -0xb0(%rbp), %rdi
callq 0x14a90
movq -0x160(%rbp), %rdi
callq 0x3450
nopw %cs:(%rax,%rax)