// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movslq %edi, %rax
imulq $0xa8, %rax, %rax
leaq 0xaebf8(%rip), %r14     # 0xb90c8
leaq (%r14,%rax), %rbx
addq $0x8, %rbx
leaq 0x88(%rsp), %rax
movl $0xb, %ecx
movq %rax, %rdi
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
movb 0x58(%rbx), %cl
movb %cl, 0x58(%rax)
leaq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x60(%rbx), %rsi
movq 0x68(%rbx), %rdx
addq %rsi, %rdx
callq 0x7666
leaq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x80(%rbx), %rsi
movq 0x88(%rbx), %rdx
addq %rsi, %rdx
callq 0x7666
movq 0xa0(%rbx), %rax
movq %rax, 0x128(%rsp)
leaq 0x1a0(%rsp), %r13
movq %r13, -0x10(%r13)
xorl %eax, %eax
movq %rax, -0x8(%r13)
movb %al, (%r13)
leaq 0x1c0(%rsp), %r15
movq %r15, -0x10(%r15)
movq %rax, -0x8(%r15)
movb %al, (%r15)
cmpl $0x0, (%rbx)
jle 0xaa7e
movslq 0x4(%rbx), %rax
imulq $0xa8, %rax, %rax
cmpl $0x78, 0x5c(%r14,%rax)
jne 0xa802
movl 0x14(%rbx), %edi
callq 0x9e24
movl %eax, %r12d
movl 0x8(%rbx), %ebp
leaq 0xa8359(%rip), %rdi     # 0xb2908
leaq 0x8f9a(%rip), %rsi      # 0x13550
callq 0x2090
testl %eax, %eax
je 0xa665
movq 0xea06(%rip), %r12      # 0x18fd0
leaq 0x9158(%rip), %rsi      # 0x13729
movl $0x23, %edx
movq %r12, %rdi
callq 0x2280
movq (%r12), %rax
addq -0x18(%rax), %r12
movq %r12, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq 0xe9d3(%rip), %rdi      # 0x18fd0
callq 0x2030
movq %rax, %rdi
callq 0x2150
leaq 0x58(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0xa82ed(%rip), %rsi     # 0xb2908
movq 0xa82ee(%rip), %rdx     # 0xb2910
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0x7666
leaq 0x48(%rsp), %rdx
movl %ebp, %edi
movl $0x4, %esi
movl $0x1, %ecx
callq 0x8274
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0xa802
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xa802
movl %ebp, %edi
movl $0x4, %esi
callq 0x8132
movslq 0x8(%rbx), %rax
imulq $0xa8, %rax, %rax
leaq 0x78(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq 0x88(%r14,%rax), %rsi
movq 0x90(%r14,%rax), %rdx
addq %rsi, %rdx
leaq 0x68(%rsp), %rdi
callq 0x7666
leaq 0x68(%rsp), %rdi
movl $0x4, %esi
movl %r12d, %edx
callq 0xabbf
movq 0x68(%rsp), %rdi
cmpq %rbp, %rdi
je 0xa6cb
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x2230
movslq 0x8(%rbx), %rax
imulq $0xa8, %rax, %rax
leaq (%r14,%rax), %rsi
addq $0x88, %rsi
leaq 0xa8220(%rip), %rdi     # 0xb2908
callq 0x2110
movslq 0x90(%rsp), %rax
imulq $0xa8, %rax, %rdx
leaq (%r14,%rdx), %r12
addq $0x8, %r12
leaq 0x130(%rsp), %rax
movl $0xb, %ecx
movq %rax, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movb 0x58(%r12), %cl
movb %cl, 0x58(%rax)
leaq (%r14,%rdx), %rsi
addq $0x68, %rsi
leaq 0x190(%rsp), %rdi
callq 0x2110
leaq 0x80(%r12), %rsi
leaq 0x1b0(%rsp), %rdi
callq 0x2110
movq 0xa0(%r12), %rax
movq %rax, 0x1d0(%rsp)
movslq 0xa8e4d(%rip), %rdi     # 0xb35b0
shlq $0x5, %rdi
leaq 0xa81c2(%rip), %r12     # 0xb2930
addq %r12, %rdi
leaq 0x8e19(%rip), %rsi      # 0x13591
callq 0x23d0
movslq 0xa8e2c(%rip), %rdi     # 0xb35b0
shlq $0x5, %rdi
addq %r12, %rdi
movq 0x1b0(%rsp), %rsi
movq 0x1b8(%rsp), %rdx
callq 0x20a0
movslq 0xa8e09(%rip), %rdi     # 0xb35b0
shlq $0x5, %rdi
addq %r12, %rdi
leaq 0x9b9e(%rip), %rsi      # 0x14353
callq 0x23d0
movl 0xc(%rbx), %edi
callq 0xac75
movslq 0xa8de7(%rip), %rdi     # 0xb35b0
shlq $0x5, %rdi
addq %r12, %rdi
leaq 0x9d42(%rip), %rsi      # 0x14519
callq 0x23d0
movslq 0xa8dcd(%rip), %rax     # 0xb35b0
leal 0x1(%rax), %ecx
movl %ecx, 0xa8dc4(%rip)     # 0xb35b0
shlq $0x5, %rax
addq %rax, %r12
leaq 0x8e5a(%rip), %rsi      # 0x13654
movq %r12, %rdi
callq 0x23d0
cmpl $0x0, (%rbx)
jle 0xaa7e
movslq 0x4(%rbx), %rax
imulq $0xa8, %rax, %rax
cmpl $0x8c, 0x5c(%r14,%rax)
jne 0xaa7e
movl 0x8(%rbx), %ebp
movslq 0x8c(%rsp), %rax
imulq $0xa8, %rax, %rdx
leaq (%r14,%rdx), %r12
addq $0x8, %r12
leaq 0x130(%rsp), %rax
movl $0xb, %ecx
movq %rax, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movb 0x58(%r12), %cl
movb %cl, 0x58(%rax)
leaq (%r14,%rdx), %rsi
addq $0x68, %rsi
leaq 0x190(%rsp), %rdi
callq 0x2110
leaq 0x80(%r12), %rsi
leaq 0x1b0(%rsp), %rdi
callq 0x2110
movq 0xa0(%r12), %rax
movq %rax, 0x1d0(%rsp)
leaq 0xa806a(%rip), %rdi     # 0xb2908
leaq 0x8cab(%rip), %rsi      # 0x13550
callq 0x2090
testl %eax, %eax
je 0xa952
movq 0xe717(%rip), %rbx      # 0x18fd0
leaq 0x8e93(%rip), %rsi      # 0x13753
movl $0x24, %edx
movq %rbx, %rdi
callq 0x2280
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq 0xe6e5(%rip), %rdi      # 0x18fd0
callq 0x2030
movq %rax, %rdi
callq 0x2150
leaq 0x18(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0xa8000(%rip), %rsi     # 0xb2908
movq 0xa8001(%rip), %rdx     # 0xb2910
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0x7666
leaq 0x8(%rsp), %rdx
movl %ebp, %edi
movl $0x5, %esi
movl $0x1, %ecx
callq 0x8274
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0xaa7e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xaa7e
movl %ebp, %edi
movl $0x5, %esi
callq 0x8132
movslq 0x8(%rbx), %rax
imulq $0xa8, %rax, %rax
leaq 0x38(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x88(%r14,%rax), %rsi
movq 0x90(%r14,%rax), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0x7666
leaq 0x28(%rsp), %rdi
movl $0x5, %esi
xorl %edx, %edx
callq 0xabbf
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0xa9b8
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2230
movslq 0x8(%rbx), %rax
imulq $0xa8, %rax, %rax
leaq (%r14,%rax), %rsi
addq $0x88, %rsi
leaq 0xa7f33(%rip), %rdi     # 0xb2908
callq 0x2110
movslq 0xa8bcf(%rip), %rdi     # 0xb35b0
shlq $0x5, %rdi
leaq 0xa7f44(%rip), %r14     # 0xb2930
addq %r14, %rdi
leaq 0x8d57(%rip), %rsi      # 0x1374d
callq 0x23d0
movslq 0xa8bae(%rip), %rdi     # 0xb35b0
shlq $0x5, %rdi
addq %r14, %rdi
movq 0xa7ef8(%rip), %rsi     # 0xb2908
movq 0xa7ef9(%rip), %rdx     # 0xb2910
callq 0x20a0
movslq 0xa8b8d(%rip), %rdi     # 0xb35b0
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x9922(%rip), %rsi      # 0x14353
callq 0x23d0
movl 0xc(%rbx), %edi
callq 0xac75
movslq 0xa8b6b(%rip), %rdi     # 0xb35b0
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x9ac6(%rip), %rsi      # 0x14519
callq 0x23d0
movslq 0xa8b51(%rip), %rax     # 0xb35b0
leal 0x1(%rax), %ecx
movl %ecx, 0xa8b48(%rip)     # 0xb35b0
shlq $0x5, %rax
addq %rax, %r14
leaq 0x8bde(%rip), %rsi      # 0x13654
movq %r14, %rdi
callq 0x23d0
movq 0x1b0(%rsp), %rdi
cmpq %r15, %rdi
je 0xaa9b
movq 0x1c0(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x190(%rsp), %rdi
cmpq %r13, %rdi
je 0xaab8
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
cmpq %rax, %rdi
je 0xaadd
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
cmpq %rax, %rdi
je 0xab02
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x2230
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0xab9d
movq 0x38(%rsp), %rsi
jmp 0xab62
movq %rax, %rbx
movq 0x68(%rsp), %rdi
cmpq %rbp, %rdi
je 0xab9d
movq 0x78(%rsp), %rsi
jmp 0xab62
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0xab9d
movq 0x18(%rsp), %rsi
jmp 0xab62
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0xab9d
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xab9d
jmp 0xab9a
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
cmpq %rax, %rdi
je 0xabb7
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xabb7
jmp 0xab9a
movq %rax, %rbx
leaq 0x130(%rsp), %rdi
callq 0xf396
leaq 0x88(%rsp), %rdi
callq 0xf396
movq %rbx, %rdi
callq 0x23a0