// File: /workspace/github_cpp_makefile_star2_O2/zhengwangsun[P]pas2c/semantics.cpp
// Function: factor(int)
int factor(int k)
{
	TreeNode tNode= tree.node[k];
	TreeNode childNode;
	childNode=tree.node[tNode.child[0]];
    int flag1;
    if(lookahead(k) == 101)//101是id
    {
        int id_position = tree.node[k].child[0];//将id节点在树中的下标值赋给id_position
        int idType = -1;
        
        idType = checkIdType(id_position);
                
        if (idType == -1)
        {
            cout<<"id is not defined where factor"<<endl;
            return -1;
        }
        else
        {
            code[currentLine].append(childNode.value);
            flag1 = factor1(tree.node[k].child[1], tree.node[id_position].value);
            
            if (flag1 == 10 && idType == 4)//factor'是( expr_list )，id是函数
            {
                return checkFunReturnType(id_position);
            }
            else if (flag1 == 10 && idType == 5)//id是过程，没返回值
            {
                return 0;//会不会return -1
            }
            else if (flag1 == 11 && idType == 1)//factor'是[expression]，id是int
            {
                return 1;//相当于整型数组
            }
            else if (flag1 == 11 && idType == 2)//factor'是[expression]，id是real
            {
                return 2;//相当于实数型数组
            }
            else if (flag1 == 11 && idType == 3)//factor'是[expression]，id是real
            {
                return 3;//相当于布尔型数组
            }
            else if (flag1 == 0 && idType != -1)
                return idType;
            else if (idType == 0 && flag1 != 0)//应该没有这种情况
                return flag1;
            else
            {
                cout<<"type not match where factor"<<endl;
                return -1;
            }
        }
    }
    else if (lookahead(k) == 119)//119是num
    {
    	code[currentLine].append(childNode.value);
        return tree.node[tree.node[k].child[0]].numType + 1;//1是int，2是real
    }
    else if (lookahead(k) == 102)//102是(
    {
    	code[currentLine].append("(");
        int temp = expression(tree.node[k].child[1],1);
        code[currentLine].append(")");
        return temp;
    }
    else if (lookahead(k) == 134)//134是not
    {
    	code[currentLine].append("!");
        return factor(tree.node[k].child[1]);
    }
    else if (lookahead(k) == 135)//135是true
    {
    	code[currentLine].append("true ");
        return 3;
    }
    else if (lookahead(k) == 136)//136false
    {
    	code[currentLine].append("false ");
        return 3;
    }
    else
    {
        cout<<"factor error!"<<endl;
        return -1;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x170, %rsp            # imm = 0x170
movl %edi, %ebp
movslq %edi, %rax
imulq $0xa8, %rax, %rax
leaq 0xaa87f(%rip), %r12     # 0xb4098
leaq (%r12,%rax), %rbx
addq $0x8, %rbx
leaq 0xc8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa562
leaq 0x90(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0xb0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
movslq 0x4(%r14), %rax
imulq $0xa8, %rax, %rax
leaq (%r12,%rax), %rsi
addq $0x8, %rsi
leaq 0x20(%rsp), %rdi
callq 0xa5ba
movl %ebp, %edi
callq 0x603d
cmpl $0x88, %eax
je 0x9a2a
cmpl $0x66, %eax
je 0x99dd
leaq 0xa0(%rsp), %r15
cmpl $0x77, %eax
je 0x994a
cmpl $0x86, %eax
je 0x998d
cmpl $0x87, %eax
je 0x9981
cmpl $0x65, %eax
jne 0x99bd
movl 0x4(%rbx), %r14d
movl %r14d, %edi
callq 0x6cc0
movl %eax, %ebp
cmpl $-0x1, %eax
je 0x9a4f
movslq 0xa4c9e(%rip), %rax     # 0xae580
shlq $0x5, %rax
leaq 0xa4013(%rip), %rdi     # 0xad900
addq %rax, %rdi
movq %r15, %rsi
callq 0x2370
movslq %r14d, %rax
movl 0x8(%rbx), %ebx
imulq $0xa8, %rax, %rax
leaq (%r12,%rax), %rsi
addq $0x88, %rsi
movq %rsp, %rdi
callq 0x2250
movq %rsp, %rsi
movl %ebx, %edi
callq 0x9c17
movl %eax, %r15d
movq %rsp, %rdi
callq 0x2388
movl %r15d, %eax
xorl $0xa, %eax
movl %ebp, %ecx
xorl $0x4, %ecx
orl %eax, %ecx
jne 0x9a96
movl %r14d, %edi
callq 0x9f64
jmp 0x99b6
movslq 0xa4c2f(%rip), %rax     # 0xae580
shlq $0x5, %rax
leaq 0xa3fa4(%rip), %rdi     # 0xad900
addq %rax, %rdi
movq %r15, %rsi
callq 0x2370
movslq 0x4(%rbx), %rax
imulq $0xa8, %rax, %rax
movl 0xa8(%r12,%rax), %ebx
incl %ebx
jmp 0x9a6d
leaq 0x5233(%rip), %rsi      # 0xebbb
jmp 0x9a31
movslq 0xa4bec(%rip), %rax     # 0xae580
shlq $0x5, %rax
leaq 0xa3f61(%rip), %rdi     # 0xad900
addq %rax, %rdi
leaq 0x52a6(%rip), %rsi      # 0xec4f
callq 0x2350
movl 0x8(%rbx), %edi
callq 0x97f7
movl %eax, %ebx
jmp 0x9a6d
movq 0xa60c(%rip), %rdi      # 0x13fd0
leaq 0x51fd(%rip), %rsi      # 0xebc8
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
jmp 0x9a6a
movslq 0xa4b9c(%rip), %rdi     # 0xae580
shlq $0x5, %rdi
leaq 0xa3f11(%rip), %r14     # 0xad900
addq %r14, %rdi
leaq 0x599d(%rip), %rsi      # 0xf396
callq 0x2350
movl 0x8(%rbx), %edi
pushq $0x1
popq %rsi
callq 0x8946
movl %eax, %ebx
movslq 0xa4b6e(%rip), %rax     # 0xae580
shlq $0x5, %rax
addq %rax, %r14
leaq 0x5b3c(%rip), %rsi      # 0xf55c
movq %r14, %rdi
callq 0x2350
jmp 0x9a6d
leaq 0x5190(%rip), %rsi      # 0xebc1
movslq 0xa4b48(%rip), %rax     # 0xae580
shlq $0x5, %rax
leaq 0xa3ebd(%rip), %rdi     # 0xad900
addq %rax, %rdi
callq 0x2350
pushq $0x3
jmp 0x9a6c
leaq 0x512a(%rip), %rsi      # 0xeb80
movq 0xa573(%rip), %rdi      # 0x13fd0
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
pushq $-0x1
popq %rbx
leaq 0x20(%rsp), %rdi
callq 0xa600
leaq 0xc8(%rsp), %rdi
callq 0xa600
movl %ebx, %eax
addq $0x170, %rsp            # imm = 0x170
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, %ecx
xorl $0x5, %ecx
xorl %ebx, %ebx
orl %eax, %ecx
je 0x9a6d
movl %r15d, %eax
xorl $0xb, %eax
movl %ebp, %ecx
xorl $0x1, %ecx
orl %eax, %ecx
jne 0x9ab4
pushq $0x1
jmp 0x9a6c
movl %ebp, %ecx
xorl $0x2, %ecx
orl %eax, %ecx
jne 0x9ac1
pushq $0x2
jmp 0x9a6c
movl %ebp, %ecx
xorl $0x3, %ecx
orl %eax, %ecx
je 0x9a4b
testl %r15d, %r15d
je 0x9adf
testl %ebp, %ebp
je 0x9ae3
leaq 0x50c5(%rip), %rsi      # 0xeb9f
jmp 0x9a56
movl %ebp, %ebx
jmp 0x9a6d
movl %r15d, %ebx
jmp 0x9a6d
movq %rax, %rbx
movq %rsp, %rdi
callq 0x2388
jmp 0x9afe
jmp 0x9afb
jmp 0x9afb
jmp 0x9afb
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xa600
leaq 0xc8(%rsp), %rdi
callq 0xa600
movq %rbx, %rdi
callq 0x2330