// File: /workspace/github_cpp_makefile_star2_O2/zhengwangsun[P]pas2c/semantics.cpp
// Function: statement1(int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
int statement1(int k, int idType, string idValue)
{
	TreeNode tNode= tree.node[k];
	TreeNode childNode;
    
    if(lookahead(k) == 24)//24是variable'
    {
    	if(idValue == currentTable)
    	{
    		variable1(tree.node[k].child[0]);
        	code[currentLine]="return "; //assignop
            
    	}
        else
		{
        	variable1(tree.node[k].child[0]);
        	code[currentLine].append("="); //assignop
        }
        
        int flag1 = expression(tree.node[k].child[2],1);
        
        code[currentLine++].append(";\n");  
        if (idType == 4)//前面的id是函数（4）
        {
            //获取函数返回值类型，不允许嵌套，所以只在主符号表里面搜索
            int funRetureType = 0;
            for (vector<subTableItem>::iterator it = subTable.begin(); it != subTable.end();it++)
            {
                if (it->name == idValue)
                {
                    funRetureType = it->returnType;
                    break;
                }
            }
            if (funRetureType < flag1) {
                errorLine = tree.node[k].row;
                cout<<"function return type wrong where statement1 in line "<<errorLine<<endl;
                exit(1);
                return -1;
            }
            else
                return flag1;
        }
        else if (idType == 5)//statement'前面的id类型是过程
        {
            errorLine = tree.node[k].row;
            cout<<"there is no return in proce where statement1 in line "<<errorLine<<endl;
            exit(1);
            return -1;
        }
        else if (idType < flag1)//id是普通变量，但类型小于expression
        {
            errorLine = tree.node[k].row;
            cout<<"id assignop type wrong where statement1 in line "<<errorLine<<endl;
            exit(1);
            return -1;
        }
            
        else
            return flag1;
    }
    else if(lookahead(k) == 26)//26是procedure_call_statement’
    {
        procedure_call_statement1(tree.node[k].child[0], idValue);
        code[currentLine++].append(";\n");
        return 0;
    }
    else
    {
        cout<<"statement' error!"<<endl;
        return -1;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rdx, %r14
movl %esi, %ebp
movslq %edi, %r15
imulq $0xa8, %r15, %rax
leaq 0xaba22(%rip), %rcx     # 0xb4098
leaq (%rcx,%rax), %rbx
addq $0x8, %rbx
leaq 0xd0(%rsp), %rdi
movq %rbx, %rsi
callq 0xa562
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0xb8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
movl %r15d, %edi
callq 0x603d
cmpl $0x1a, %eax
je 0x8711
cmpl $0x18, %eax
jne 0x8769
leaq 0xa5205(%rip), %rsi     # 0xad8d8
movq %r14, %rdi
callq 0x5f9f
movl 0x4(%rbx), %edi
testb %al, %al
je 0x878d
callq 0x8b0c
movslq 0xa5e8e(%rip), %rax     # 0xae580
shlq $0x5, %rax
leaq 0xa5203(%rip), %rdi     # 0xad900
addq %rax, %rdi
leaq 0x6190(%rip), %rsi      # 0xe897
callq 0x2360
jmp 0x87b3
movl 0x4(%rbx), %ebx
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x2250
leaq 0x8(%rsp), %rsi
movl %ebx, %edi
callq 0x8c2d
leaq 0x8(%rsp), %rdi
callq 0x2388
movslq 0xa5e42(%rip), %rax     # 0xae580
leal 0x1(%rax), %ecx
movl %ecx, 0xa5e39(%rip)     # 0xae580
shlq $0x5, %rax
leaq 0xa51ae(%rip), %rdi     # 0xad900
addq %rax, %rdi
xorl %r15d, %r15d
leaq 0x6375(%rip), %rsi      # 0xead4
callq 0x2350
jmp 0x8871
movq 0xb860(%rip), %rdi      # 0x13fd0
leaq 0x61c4(%rip), %rsi      # 0xe93b
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
pushq $-0x1
popq %r15
jmp 0x8871
callq 0x8b0c
movslq 0xa5de7(%rip), %rax     # 0xae580
shlq $0x5, %rax
leaq 0xa515c(%rip), %rdi     # 0xad900
addq %rax, %rdi
leaq 0x5b21(%rip), %rsi      # 0xe2cf
callq 0x2350
movl 0xc(%rbx), %edi
pushq $0x1
popq %rsi
callq 0x8946
movl %eax, %r15d
movslq 0xa5db8(%rip), %rax     # 0xae580
leal 0x1(%rax), %ecx
movl %ecx, 0xa5daf(%rip)     # 0xae580
shlq $0x5, %rax
leaq 0xa5124(%rip), %rdi     # 0xad900
addq %rax, %rdi
leaq 0x62ee(%rip), %rsi      # 0xead4
callq 0x2350
cmpl $0x4, %ebp
je 0x8838
cmpl $0x5, %ebp
je 0x889d
cmpl %ebp, %r15d
jle 0x8871
movl 0xa4(%rbx), %eax
movl %eax, 0xa5d7a(%rip)     # 0xae584
movq 0xb7bf(%rip), %rdi      # 0x13fd0
leaq 0x60f2(%rip), %rsi      # 0xe90a
callq 0x21d0
movl 0xa5d61(%rip), %esi     # 0xae584
movq %rax, %rdi
callq 0x2320
movq %rax, %rdi
callq 0x20f0
jmp 0x8909
movq 0xa5069(%rip), %r13     # 0xad8a8
cmpq 0xa506a(%rip), %r13     # 0xad8b0
je 0x8864
leaq 0x30(%r13), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x5f9f
testb %al, %al
jne 0x8868
addq $0x30, %r12
movq %r12, %r13
jmp 0x883f
xorl %eax, %eax
jmp 0x886c
movl 0x58(%r13), %eax
cmpl %r15d, %eax
jl 0x88d4
leaq 0x28(%rsp), %rdi
callq 0xa600
leaq 0xd0(%rsp), %rdi
callq 0xa600
movl %r15d, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0xa4(%rbx), %eax
movl %eax, 0xa5cdb(%rip)     # 0xae584
movq 0xb720(%rip), %rdi      # 0x13fd0
leaq 0x601d(%rip), %rsi      # 0xe8d4
callq 0x21d0
movl 0xa5cc2(%rip), %esi     # 0xae584
movq %rax, %rdi
callq 0x2320
movq %rax, %rdi
callq 0x20f0
jmp 0x8909
movl 0xa4(%rbx), %eax
movl %eax, 0xa5ca4(%rip)     # 0xae584
movq 0xb6e9(%rip), %rdi      # 0x13fd0
leaq 0x5fb1(%rip), %rsi      # 0xe89f
callq 0x21d0
movl 0xa5c8b(%rip), %esi     # 0xae584
movq %rax, %rdi
callq 0x2320
movq %rax, %rdi
callq 0x20f0
pushq $0x1
popq %rdi
callq 0x2220
jmp 0x8924
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x2388
jmp 0x8927
jmp 0x8924
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0xa600
leaq 0xd0(%rsp), %rdi
callq 0xa600
movq %rbx, %rdi
callq 0x2330