// File: /workspace/github_cpp_makefile_star2_O1/zhengwangsun[P]pas2c/semantics.cpp
// Function: isDefined(int)
int isDefined(int position)
{
    if(currentTable == "main"||currentTable == tree.node[position].value)//若当前符号表为主表,或者要查询的id是子表名字，则查询主表
    {
        for(vector<Tuple>::iterator it = mainTable.begin(); it != mainTable.end();it++)//遍历查重
        {
            if(it->name == tree.node[position].value)
            {
                int i = 0, flag = 0;
                for(vector<int>::iterator it1 = it->useRow.begin(); it1 != it->useRow.end();it1++)
                {
                    if (it1[i] == tree.node[position].row)
                    {
                        flag = 1;
                        break;
                    }
                    i++;
                }
                if(flag == 0)
                    it->useRow.push_back(tree.node[position].row);
                return 1;
            }
        }
        return 0;
    }
    else//若当前符号表是子表且符号不是子表名字
    {
        //先遍历子表序列
        for(vector<subTableItem>::iterator it = subTable.begin(); it != subTable.end();it++)
        {
            if(it->name == currentTable)//找到当前子表
            {
                for(vector<Tuple>::iterator it0 = it->item.begin(); it0 != it->item.end();it0++)//遍历子表中的item
                {
                    if(it0->name == tree.node[position].value)
                    {
                        int i = 0, flag = 0;
                        for(vector<int>::iterator it1 = it0->useRow.begin(); it1 != it0->useRow.end();it1++)
                        {
                            if (it1[i] == tree.node[position].row)
                            {
                                flag = 1;
                                break;
                            }
                            i++;
                        }
                        
                        if (flag == 0)
                            it0->useRow.push_back(tree.node[position].row);
                        return 2;
                    }
                }
                
                for(vector<Tuple>::iterator it1 = it->argument.begin(); it1 != it->argument.end();it1++)//遍历子表中的argument
                {
                    if(it1->name == tree.node[position].value)
                        return 2;
                }
                //还没找到，再遍历主表
                for(vector<Tuple>::iterator it = mainTable.begin(); it != mainTable.end();it++)//遍历查重
                {
                    if(it->name == tree.node[position].value)
                    {
                        int i = 0, flag = 0;
                        for(vector<int>::iterator it1 = it->useRow.begin(); it1 != it->useRow.end();it1++)
                        {
                            if (it1[i] == tree.node[position].row)
                            {
                                flag = 1;
                                break;
                            }
                            i++;
                        }
                        if(flag == 0)
                            it->useRow.push_back(tree.node[position].row);
                        return 1;
                    }
                }
                
            }
        }
        return 0;
    }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edi, %ebp
leaq 0xaadda(%rip), %rdi     # 0xb3908
leaq 0xb9eb(%rip), %rsi      # 0x14520
callq 0x2090
testl %eax, %eax
je 0x8df6
movslq %ebp, %rax
imulq $0xa8, %rax, %rax
leaq 0xb1575(%rip), %rcx     # 0xba0c8
addq %rcx, %rax
addq $0x8, %rax
movq 0xaadaf(%rip), %rdx     # 0xb3910
movq %rax, (%rsp)
cmpq 0x88(%rax), %rdx
jne 0x8b96
testq %rdx, %rdx
je 0x8df6
movq (%rsp), %rax
movq 0x80(%rax), %rsi
movq 0xaad7f(%rip), %rdi     # 0xb3908
callq 0x2240
testl %eax, %eax
je 0x8df6
movq 0xaad3b(%rip), %r12     # 0xb38d8
cmpq 0xaad3c(%rip), %r12     # 0xb38e0
je 0x8def
movq (%rsp), %rax
addq $0xa4, %rax
movq %rax, 0x8(%rsp)
movq 0x38(%r12), %rdx
cmpq 0xaad4b(%rip), %rdx     # 0xb3910
jne 0x8dde
testq %rdx, %rdx
je 0x8be9
movq 0xaad31(%rip), %rsi     # 0xb3908
movq 0x30(%r12), %rdi
callq 0x2240
testl %eax, %eax
jne 0x8dde
movq (%r12), %r14
movq 0x8(%r12), %rbp
cmpq %rbp, %r14
sete %bl
je 0x8ca2
movq (%rsp), %rax
movq 0x88(%rax), %r13
addq $0x30, %r14
movq -0x28(%r14), %rdx
cmpq %r13, %rdx
jne 0x8c33
testq %rdx, %rdx
je 0x8c48
movq (%rsp), %rax
movq 0x80(%rax), %rsi
movq -0x30(%r14), %rdi
callq 0x2240
testl %eax, %eax
je 0x8c48
leaq 0x50(%r14), %rax
addq $0x20, %r14
cmpq %rbp, %r14
sete %bl
movq %rax, %r14
jne 0x8c0d
jmp 0x8ca2
movq (%r14), %rax
movq 0x8(%r14), %rsi
cmpq %rsi, %rax
je 0x8c76
movq (%rsp), %rcx
movl 0xa4(%rcx), %ecx
xorl %edx, %edx
cmpl %ecx, (%rax,%rdx,2)
je 0x8c9c
leaq (%rax,%rdx), %rdi
addq $0x4, %rdi
addq $0x4, %rdx
cmpq %rsi, %rdi
jne 0x8c60
cmpq 0x10(%r14), %rsi
je 0x8c8f
movq 0x8(%rsp), %rax
movl (%rax), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%r14)
jmp 0x8c9c
movq %r14, %rdi
movq 0x8(%rsp), %rdx
callq 0xf9e2
movl $0x2, %r15d
testb $0x1, %bl
je 0x8ed7
movq 0x18(%r12), %r14
movq 0x20(%r12), %r13
cmpq %r13, %r14
sete %bl
je 0x8d09
movl %r15d, 0x14(%rsp)
movq (%rsp), %rax
movq 0x88(%rax), %r15
movq 0x8(%r14), %rdx
cmpq %r15, %rdx
jne 0x8cf7
movl $0x2, %ebp
testq %rdx, %rdx
je 0x8d0c
movq (%rsp), %rax
movq 0x80(%rax), %rsi
movq (%r14), %rdi
callq 0x2240
testl %eax, %eax
je 0x8d0c
addq $0x50, %r14
cmpq %r13, %r14
sete %bl
jne 0x8ccd
movl 0x14(%rsp), %ebp
jmp 0x8d0c
movl %r15d, %ebp
testb $0x1, %bl
je 0x8ec6
movq 0xaaba4(%rip), %r14     # 0xb38c0
movq 0xaaba5(%rip), %r13     # 0xb38c8
cmpq %r13, %r14
sete %bl
je 0x8dd2
movq (%rsp), %rax
movq 0x88(%rax), %r15
addq $0x30, %r14
movq -0x28(%r14), %rdx
cmpq %r15, %rdx
jne 0x8d64
testq %rdx, %rdx
je 0x8d79
movq (%rsp), %rax
movq 0x80(%rax), %rsi
movq -0x30(%r14), %rdi
callq 0x2240
testl %eax, %eax
je 0x8d79
leaq 0x50(%r14), %rax
addq $0x20, %r14
cmpq %r13, %r14
sete %bl
movq %rax, %r14
jne 0x8d3e
jmp 0x8dd2
movq (%r14), %rax
movq 0x8(%r14), %rsi
cmpq %rsi, %rax
je 0x8da7
movq (%rsp), %rcx
movl 0xa4(%rcx), %ecx
xorl %edx, %edx
cmpl %ecx, (%rax,%rdx,2)
je 0x8dcd
leaq (%rax,%rdx), %rdi
addq $0x4, %rdi
addq $0x4, %rdx
cmpq %rsi, %rdi
jne 0x8d91
cmpq 0x10(%r14), %rsi
je 0x8dc0
movq 0x8(%rsp), %rax
movl (%rax), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%r14)
jmp 0x8dcd
movq %r14, %rdi
movq 0x8(%rsp), %rdx
callq 0xf9e2
movl $0x1, %ebp
movl %ebp, %r15d
testb $0x1, %bl
je 0x8ec6
addq $0x60, %r12
cmpq 0xaaaf7(%rip), %r12     # 0xb38e0
jne 0x8bb9
xorl %ebp, %ebp
jmp 0x8ec6
movq 0xaaac3(%rip), %rbx     # 0xb38c0
movq 0xaaac4(%rip), %r12     # 0xb38c8
cmpq %r12, %rbx
setne %r15b
je 0x8ebf
movslq %ebp, %rax
imulq $0xa8, %rax, %rax
leaq 0xb12a6(%rip), %rcx     # 0xba0c8
leaq (%rcx,%rax), %r14
addq $0x8, %r14
movq 0x88(%r14), %r13
addq $0x30, %rbx
movq -0x28(%rbx), %rdx
cmpq %r13, %rdx
jne 0x8e57
testq %rdx, %rdx
je 0x8e6d
movq 0x80(%r14), %rsi
movq -0x30(%rbx), %rdi
callq 0x2240
testl %eax, %eax
je 0x8e6d
leaq 0x50(%rbx), %rax
addq $0x20, %rbx
cmpq %r12, %rbx
setne %r15b
movq %rax, %rbx
jne 0x8e35
jmp 0x8ebf
movq (%rbx), %rax
movq 0x8(%rbx), %rsi
cmpq %rsi, %rax
je 0x8e98
movl 0xa4(%r14), %ecx
xorl %edx, %edx
cmpl %ecx, (%rax,%rdx,2)
je 0x8ebf
leaq (%rax,%rdx), %rdi
addq $0x4, %rdi
addq $0x4, %rdx
cmpq %rsi, %rdi
jne 0x8e82
addq $0xa4, %r14
cmpq 0x10(%rbx), %rsi
je 0x8eb4
movl (%r14), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x8ebf
movq %rbx, %rdi
movq %r14, %rdx
callq 0xf9e2
movzbl %r15b, %ebp
andl $0x1, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r15d, %ebp
jmp 0x8ec6