// File: 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
movq %rsp, %rbp
subq $0x220, %rsp            # imm = 0x220
movq %rdx, -0x1d0(%rbp)
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movslq -0x8(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb551a(%rip), %rax     # 0xc6138
leaq 0x8(%rax,%rcx), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x14920
leaq -0x168(%rbp), %rdi
callq 0x149d0
movl -0x8(%rbp), %edi
callq 0xca50
movl %eax, -0x1c4(%rbp)
jmp 0x10c4b
movl -0x1c4(%rbp), %eax
cmpl $0x18, %eax
jne 0x10fc8
movq -0x1d0(%rbp), %rdi
leaq 0xaed10(%rip), %rsi     # 0xbf978
callq 0xc840
testb $0x1, %al
jne 0x10c73
jmp 0x10ccc
movslq -0x8(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb54b3(%rip), %rax     # 0xc6138
movl 0xc(%rax,%rcx), %edi
callq 0x113f0
jmp 0x10c90
movslq 0xaf989(%rip), %rax     # 0xc0620
shlq $0x5, %rax
leaq 0xaecfe(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xdb25(%rip), %rsi      # 0x1e7d1
callq 0x3380
jmp 0x10cb3
jmp 0x10d0e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x170(%rbp)
movl %eax, -0x174(%rbp)
jmp 0x110fe
movslq -0x8(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb545a(%rip), %rax     # 0xc6138
movl 0xc(%rax,%rcx), %edi
callq 0x113f0
jmp 0x10ce9
movslq 0xaf930(%rip), %rax     # 0xc0620
shlq $0x5, %rax
leaq 0xaeca5(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xd54e(%rip), %rsi      # 0x1e253
callq 0x3490
jmp 0x10d0c
jmp 0x10d0e
movslq -0x8(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb5418(%rip), %rax     # 0xc6138
movl 0x14(%rax,%rcx), %edi
movl $0x1, %esi
callq 0x11130
movl %eax, -0x1d4(%rbp)
jmp 0x10d36
movl -0x1d4(%rbp), %eax
movl %eax, -0x178(%rbp)
movslq 0xaf8d7(%rip), %rax     # 0xc0620
movl %eax, %ecx
incl %ecx
movl %ecx, 0xaf8cd(%rip)     # 0xc0620
shlq $0x5, %rax
leaq 0xaec42(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xdca6(%rip), %rsi      # 0x1ea0e
callq 0x3490
jmp 0x10d6f
cmpl $0x4, -0xc(%rbp)
jne 0x10eb5
movl $0x0, -0x17c(%rbp)
leaq 0xaebbe(%rip), %rdi     # 0xbf948
callq 0x14b00
movq %rax, -0x188(%rbp)
leaq 0xaebab(%rip), %rdi     # 0xbf948
callq 0x14b70
movq %rax, -0x190(%rbp)
leaq -0x188(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x14b30
testb $0x1, %al
jne 0x10dc2
jmp 0x10e1a
leaq -0x188(%rbp), %rdi
callq 0x14ba0
movq -0x1d0(%rbp), %rsi
movq %rax, %rdi
addq $0x30, %rdi
callq 0xc840
testb $0x1, %al
jne 0x10de7
jmp 0x10dfe
leaq -0x188(%rbp), %rdi
callq 0x14ba0
movl 0x58(%rax), %eax
movl %eax, -0x17c(%rbp)
jmp 0x10e1a
jmp 0x10e00
leaq -0x188(%rbp), %rdi
xorl %esi, %esi
callq 0x14bc0
movq %rax, -0x198(%rbp)
jmp 0x10d96
movl -0x17c(%rbp), %eax
cmpl -0x178(%rbp), %eax
jge 0x10e9d
movslq -0x8(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb52fe(%rip), %rax     # 0xc6138
movl 0xac(%rax,%rcx), %eax
movl %eax, 0xaf7dd(%rip)     # 0xc0624
movq 0x1517a(%rip), %rdi     # 0x25fc8
leaq 0xd984(%rip), %rsi      # 0x1e7d9
callq 0x3280
movq %rax, -0x1e0(%rbp)
jmp 0x10e63
movq -0x1e0(%rbp), %rdi
movl 0xaf7b4(%rip), %esi     # 0xc0624
callq 0x3440
movq %rax, -0x1e8(%rbp)
jmp 0x10e7e
movq -0x1e8(%rbp), %rdi
movq 0x15124(%rip), %rsi     # 0x25fb0
callq 0x32b0
jmp 0x10e93
movl $0x1, %edi
callq 0x3340
movl -0x178(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x19c(%rbp)
jmp 0x110da
cmpl $0x5, -0xc(%rbp)
jne 0x10f30
movslq -0x8(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb526b(%rip), %rax     # 0xc6138
movl 0xac(%rax,%rcx), %eax
movl %eax, 0xaf74a(%rip)     # 0xc0624
movq 0x150e7(%rip), %rdi     # 0x25fc8
leaq 0xd926(%rip), %rsi      # 0x1e80e
callq 0x3280
movq %rax, -0x1f0(%rbp)
jmp 0x10ef6
movq -0x1f0(%rbp), %rdi
movl 0xaf721(%rip), %esi     # 0xc0624
callq 0x3440
movq %rax, -0x1f8(%rbp)
jmp 0x10f11
movq -0x1f8(%rbp), %rdi
movq 0x15091(%rip), %rsi     # 0x25fb0
callq 0x32b0
jmp 0x10f26
movl $0x1, %edi
callq 0x3340
movl -0xc(%rbp), %eax
cmpl -0x178(%rbp), %eax
jge 0x10fb0
movslq -0x8(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb51eb(%rip), %rax     # 0xc6138
movl 0xac(%rax,%rcx), %eax
movl %eax, 0xaf6ca(%rip)     # 0xc0624
movq 0x15067(%rip), %rdi     # 0x25fc8
leaq 0xd8dc(%rip), %rsi      # 0x1e844
callq 0x3280
movq %rax, -0x200(%rbp)
jmp 0x10f76
movq -0x200(%rbp), %rdi
movl 0xaf6a1(%rip), %esi     # 0xc0624
callq 0x3440
movq %rax, -0x208(%rbp)
jmp 0x10f91
movq -0x208(%rbp), %rdi
movq 0x15011(%rip), %rsi     # 0x25fb0
callq 0x32b0
jmp 0x10fa6
movl $0x1, %edi
callq 0x3340
movl -0x178(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x19c(%rbp)
jmp 0x110da
movl -0x8(%rbp), %edi
callq 0xca50
movl %eax, -0x20c(%rbp)
jmp 0x10fd8
movl -0x20c(%rbp), %eax
cmpl $0x1a, %eax
jne 0x11098
movq -0x1d0(%rbp), %rsi
movslq -0x8(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb5138(%rip), %rax     # 0xc6138
movl 0xc(%rax,%rcx), %eax
movl %eax, -0x210(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x30e0
jmp 0x11018
movl -0x210(%rbp), %edi
leaq -0x1c0(%rbp), %rsi
callq 0x115b0
jmp 0x1102c
leaq -0x1c0(%rbp), %rdi
callq 0x34c8
movslq 0xaf5e1(%rip), %rax     # 0xc0620
movl %eax, %ecx
incl %ecx
movl %ecx, 0xaf5d7(%rip)     # 0xc0620
shlq $0x5, %rax
leaq 0xae94c(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xd9b0(%rip), %rsi      # 0x1ea0e
callq 0x3490
jmp 0x11065
movl $0x0, -0x4(%rbp)
movl $0x1, -0x19c(%rbp)
jmp 0x110da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x170(%rbp)
movl %eax, -0x174(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x34c8
jmp 0x110fe
movq 0x14f29(%rip), %rdi     # 0x25fc8
leaq 0xd7cf(%rip), %rsi      # 0x1e875
callq 0x3280
movq %rax, -0x218(%rbp)
jmp 0x110b4
movq -0x218(%rbp), %rdi
movq 0x14eee(%rip), %rsi     # 0x25fb0
callq 0x32b0
jmp 0x110c9
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x19c(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x14a90
leaq -0xc0(%rbp), %rdi
callq 0x14a90
movl -0x4(%rbp), %eax
addq $0x220, %rsp            # imm = 0x220
popq %rbp
retq
leaq -0x168(%rbp), %rdi
callq 0x14a90
leaq -0xc0(%rbp), %rdi
callq 0x14a90
movq -0x170(%rbp), %rdi
callq 0x3450
nopw %cs:(%rax,%rax)