// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1d0, %rsp            # imm = 0x1D0
movl %edi, %ebp
movslq %edi, %r14
imulq $0xa8, %r14, %rax
leaq 0xac73c(%rip), %r12     # 0xb4098
leaq (%r12,%rax), %rbx
addq $0x8, %rbx
leaq 0x128(%rsp), %rdi
movq %rbx, %rsi
callq 0xa562
leaq 0xf0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x110(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
movl %r14d, %edi
callq 0x603d
cmpl $0x78, %eax
jne 0x7b4b
movl 0x14(%rbx), %edi
callq 0x7601
movl %eax, %r15d
movl 0x8(%rbx), %r14d
leaq 0xa5f15(%rip), %rdi     # 0xad8d8
leaq 0x6bb6(%rip), %rsi      # 0xe580
callq 0x5f92
testb %al, %al
je 0x7b02
pushq $0x4
popq %rsi
movl %r14d, %edi
callq 0x6525
movslq 0x8(%rbx), %rax
imulq $0xa8, %rax, %rax
leaq (%r12,%rax), %rsi
addq $0x88, %rsi
leaq 0x60(%rsp), %rdi
callq 0x2250
leaq 0x60(%rsp), %rdi
pushq $0x4
popq %rsi
movl %r15d, %edx
callq 0x7d63
leaq 0x60(%rsp), %rdi
callq 0x2388
movslq 0x8(%rbx), %rax
imulq $0xa8, %rax, %rax
leaq (%r12,%rax), %rsi
addq $0x88, %rsi
leaq 0xa5e9f(%rip), %rdi     # 0xad8d8
callq 0x2110
movslq 0x130(%rsp), %rax
imulq $0xa8, %rax, %rax
leaq (%r12,%rax), %rsi
addq $0x8, %rsi
leaq 0x80(%rsp), %rdi
callq 0xa5ba
movslq 0xa6b17(%rip), %rdi     # 0xae580
shlq $0x5, %rdi
leaq 0xa5e8c(%rip), %r14     # 0xad900
addq %r14, %rdi
leaq 0x6b43(%rip), %rsi      # 0xe5c1
callq 0x2350
leaq 0x100(%rsp), %rsi
movslq 0xa6aee(%rip), %rdi     # 0xae580
shlq $0x5, %rdi
addq %r14, %rdi
callq 0x2370
movslq 0xa6adb(%rip), %rdi     # 0xae580
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x78e3(%rip), %rsi      # 0xf396
callq 0x2350
movl 0xc(%rbx), %edi
callq 0x7ded
movslq 0xa6ab9(%rip), %rdi     # 0xae580
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x7a87(%rip), %rsi      # 0xf55c
callq 0x2350
movslq 0xa6a9f(%rip), %rax     # 0xae580
leal 0x1(%rax), %ecx
movl %ecx, 0xa6a96(%rip)     # 0xae580
shlq $0x5, %rax
addq %rax, %r14
leaq 0x6b8c(%rip), %rsi      # 0xe684
movq %r14, %rdi
callq 0x2350
jmp 0x7b4b
movq 0xc4c7(%rip), %rdi      # 0x13fd0
leaq 0x6c49(%rip), %rsi      # 0xe759
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
leaq 0xa5db4(%rip), %rsi     # 0xad8d8
leaq 0x40(%rsp), %rdi
callq 0x2250
pushq $0x4
popq %rsi
leaq 0x40(%rsp), %rdx
pushq $0x1
popq %rcx
movl %r14d, %edi
callq 0x6618
leaq 0x40(%rsp), %rdi
callq 0x2388
movl %ebp, %edi
callq 0x603d
cmpl $0x8c, %eax
jne 0x7ce5
movl 0x8(%rbx), %ebp
movslq 0x12c(%rsp), %rax
imulq $0xa8, %rax, %rax
leaq (%r12,%rax), %rsi
addq $0x8, %rsi
leaq 0x80(%rsp), %rdi
callq 0xa5ba
leaq 0xa5d4d(%rip), %rdi     # 0xad8d8
leaq 0x69ee(%rip), %rsi      # 0xe580
callq 0x5f92
testb %al, %al
je 0x7ca3
pushq $0x5
popq %rsi
movl %ebp, %edi
callq 0x6525
movslq 0x8(%rbx), %rax
imulq $0xa8, %rax, %rax
leaq (%r12,%rax), %rsi
addq $0x88, %rsi
leaq 0x20(%rsp), %rdi
callq 0x2250
leaq 0x20(%rsp), %rdi
pushq $0x5
popq %rsi
xorl %edx, %edx
callq 0x7d63
leaq 0x20(%rsp), %rdi
callq 0x2388
movslq 0x8(%rbx), %rax
imulq $0xa8, %rax, %rax
leaq (%r12,%rax), %rsi
addq $0x88, %rsi
leaq 0xa5cd9(%rip), %rdi     # 0xad8d8
callq 0x2110
movslq 0xa6975(%rip), %rdi     # 0xae580
shlq $0x5, %rdi
leaq 0xa5cea(%rip), %r14     # 0xad900
addq %r14, %rdi
leaq 0x6b5d(%rip), %rsi      # 0xe77d
callq 0x2350
movslq 0xa6954(%rip), %rdi     # 0xae580
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0xa5c9e(%rip), %rsi     # 0xad8d8
callq 0x2370
movslq 0xa693a(%rip), %rdi     # 0xae580
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x7742(%rip), %rsi      # 0xf396
callq 0x2350
movl 0xc(%rbx), %edi
callq 0x7ded
movslq 0xa6918(%rip), %rdi     # 0xae580
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x78e6(%rip), %rsi      # 0xf55c
callq 0x2350
movslq 0xa68fe(%rip), %rax     # 0xae580
leal 0x1(%rax), %ecx
movl %ecx, 0xa68f5(%rip)     # 0xae580
shlq $0x5, %rax
addq %rax, %r14
leaq 0x69eb(%rip), %rsi      # 0xe684
movq %r14, %rdi
callq 0x2350
jmp 0x7ce5
movq 0xc326(%rip), %rdi      # 0x13fd0
leaq 0x6ad2(%rip), %rsi      # 0xe783
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
leaq 0xa5c13(%rip), %rsi     # 0xad8d8
movq %rsp, %rdi
callq 0x2250
pushq $0x5
popq %rsi
movq %rsp, %rdx
pushq $0x1
popq %rcx
movl %ebp, %edi
callq 0x6618
movq %rsp, %rdi
callq 0x2388
leaq 0x80(%rsp), %rdi
callq 0xa600
leaq 0x128(%rsp), %rdi
callq 0xa600
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %rsp, %rdi
jmp 0x7d33
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
jmp 0x7d33
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
jmp 0x7d33
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x2388
jmp 0x7d41
jmp 0x7d3e
jmp 0x7d3e
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0xa600
leaq 0x128(%rsp), %rdi
callq 0xa600
movq %rbx, %rdi
callq 0x2330