// File: /workspace/github_cpp_makefile_star2_O1/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 0xafa93(%rip), %r14     # 0xba0c8
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 0x768e
leaq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x80(%rbx), %rsi
movq 0x88(%rbx), %rdx
addq %rsi, %rdx
callq 0x768e
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 0xa967
movslq 0x4(%rbx), %rax
imulq $0xa8, %rax, %rax
cmpl $0x78, 0x5c(%r14,%rax)
jne 0xa967
movl 0x14(%rbx), %edi
callq 0x9f3c
movl %eax, %r12d
movl 0x8(%rbx), %ebp
leaq 0xa91f4(%rip), %rdi     # 0xb3908
leaq 0x9e05(%rip), %rsi      # 0x14520
callq 0x2090
testl %eax, %eax
je 0xa7ca
movq 0xf8a1(%rip), %r12      # 0x19fd0
leaq 0x9fc3(%rip), %rsi      # 0x146f9
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 0xf86e(%rip), %rdi      # 0x19fd0
callq 0x2030
movq %rax, %rdi
callq 0x2150
leaq 0x58(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0xa9188(%rip), %rsi     # 0xb3908
movq 0xa9189(%rip), %rdx     # 0xb3910
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0x768e
leaq 0x48(%rsp), %rdx
movl %ebp, %edi
movl $0x4, %esi
movl $0x1, %ecx
callq 0x8278
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0xa967
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xa967
movl %ebp, %edi
movl $0x4, %esi
callq 0x8136
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 0x768e
leaq 0x68(%rsp), %rdi
movl $0x4, %esi
movl %r12d, %edx
callq 0xad24
movq 0x68(%rsp), %rdi
cmpq %rbp, %rdi
je 0xa830
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x2230
movslq 0x8(%rbx), %rax
imulq $0xa8, %rax, %rax
leaq (%r14,%rax), %rsi
addq $0x88, %rsi
leaq 0xa90bb(%rip), %rdi     # 0xb3908
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 0xa9ce8(%rip), %rdi     # 0xb45b0
shlq $0x5, %rdi
leaq 0xa905d(%rip), %r12     # 0xb3930
addq %r12, %rdi
leaq 0x9c84(%rip), %rsi      # 0x14561
callq 0x23d0
movslq 0xa9cc7(%rip), %rdi     # 0xb45b0
shlq $0x5, %rdi
addq %r12, %rdi
movq 0x1b0(%rsp), %rsi
movq 0x1b8(%rsp), %rdx
callq 0x20a0
movslq 0xa9ca4(%rip), %rdi     # 0xb45b0
shlq $0x5, %rdi
addq %r12, %rdi
leaq 0xaa19(%rip), %rsi      # 0x15333
callq 0x23d0
movl 0xc(%rbx), %edi
callq 0xadda
movslq 0xa9c82(%rip), %rdi     # 0xb45b0
shlq $0x5, %rdi
addq %r12, %rdi
leaq 0xabbd(%rip), %rsi      # 0x154f9
callq 0x23d0
movslq 0xa9c68(%rip), %rax     # 0xb45b0
leal 0x1(%rax), %ecx
movl %ecx, 0xa9c5f(%rip)     # 0xb45b0
shlq $0x5, %rax
addq %rax, %r12
leaq 0x9cc5(%rip), %rsi      # 0x14624
movq %r12, %rdi
callq 0x23d0
cmpl $0x0, (%rbx)
jle 0xabe3
movslq 0x4(%rbx), %rax
imulq $0xa8, %rax, %rax
cmpl $0x8c, 0x5c(%r14,%rax)
jne 0xabe3
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 0xa8f05(%rip), %rdi     # 0xb3908
leaq 0x9b16(%rip), %rsi      # 0x14520
callq 0x2090
testl %eax, %eax
je 0xaab7
movq 0xf5b2(%rip), %rbx      # 0x19fd0
leaq 0x9cfe(%rip), %rsi      # 0x14723
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 0xf580(%rip), %rdi      # 0x19fd0
callq 0x2030
movq %rax, %rdi
callq 0x2150
leaq 0x18(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0xa8e9b(%rip), %rsi     # 0xb3908
movq 0xa8e9c(%rip), %rdx     # 0xb3910
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0x768e
leaq 0x8(%rsp), %rdx
movl %ebp, %edi
movl $0x5, %esi
movl $0x1, %ecx
callq 0x8278
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0xabe3
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xabe3
movl %ebp, %edi
movl $0x5, %esi
callq 0x8136
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 0x768e
leaq 0x28(%rsp), %rdi
movl $0x5, %esi
xorl %edx, %edx
callq 0xad24
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0xab1d
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2230
movslq 0x8(%rbx), %rax
imulq $0xa8, %rax, %rax
leaq (%r14,%rax), %rsi
addq $0x88, %rsi
leaq 0xa8dce(%rip), %rdi     # 0xb3908
callq 0x2110
movslq 0xa9a6a(%rip), %rdi     # 0xb45b0
shlq $0x5, %rdi
leaq 0xa8ddf(%rip), %r14     # 0xb3930
addq %r14, %rdi
leaq 0x9bc2(%rip), %rsi      # 0x1471d
callq 0x23d0
movslq 0xa9a49(%rip), %rdi     # 0xb45b0
shlq $0x5, %rdi
addq %r14, %rdi
movq 0xa8d93(%rip), %rsi     # 0xb3908
movq 0xa8d94(%rip), %rdx     # 0xb3910
callq 0x20a0
movslq 0xa9a28(%rip), %rdi     # 0xb45b0
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0xa79d(%rip), %rsi      # 0x15333
callq 0x23d0
movl 0xc(%rbx), %edi
callq 0xadda
movslq 0xa9a06(%rip), %rdi     # 0xb45b0
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0xa941(%rip), %rsi      # 0x154f9
callq 0x23d0
movslq 0xa99ec(%rip), %rax     # 0xb45b0
leal 0x1(%rax), %ecx
movl %ecx, 0xa99e3(%rip)     # 0xb45b0
shlq $0x5, %rax
addq %rax, %r14
leaq 0x9a49(%rip), %rsi      # 0x14624
movq %r14, %rdi
callq 0x23d0
movq 0x1b0(%rsp), %rdi
cmpq %r15, %rdi
je 0xac00
movq 0x1c0(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x190(%rsp), %rdi
cmpq %r13, %rdi
je 0xac1d
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
cmpq %rax, %rdi
je 0xac42
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
cmpq %rax, %rdi
je 0xac67
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 0xad02
movq 0x38(%rsp), %rsi
jmp 0xacc7
movq %rax, %rbx
movq 0x68(%rsp), %rdi
cmpq %rbp, %rdi
je 0xad02
movq 0x78(%rsp), %rsi
jmp 0xacc7
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0xad02
movq 0x18(%rsp), %rsi
jmp 0xacc7
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0xad02
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xad02
jmp 0xacff
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
cmpq %rax, %rdi
je 0xad1c
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xad1c
jmp 0xacff
movq %rax, %rbx
leaq 0x130(%rsp), %rdi
callq 0xf7a8
leaq 0x88(%rsp), %rdi
callq 0xf7a8
movq %rbx, %rdi
callq 0x23a0