// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movslq %edi, %rax
imulq $0xa8, %rax, %rax
leaq 0xab513(%rip), %r12     # 0xb90c8
leaq (%r12,%rax), %rbx
addq $0x8, %rbx
leaq 0x28(%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 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x60(%rbx), %rsi
movq 0x68(%rbx), %rdx
addq %rsi, %rdx
callq 0x7666
leaq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x80(%rbx), %rsi
movq 0x88(%rbx), %rdx
addq %rsi, %rdx
callq 0x7666
movq 0xa0(%rbx), %rax
movq %rax, 0xc8(%rsp)
leaq 0x130(%rsp), %rax
leaq 0x140(%rsp), %r15
movq %r15, -0x10(%r15)
xorl %ecx, %ecx
movq %rcx, -0x8(%r15)
movb %cl, (%r15)
leaq 0x160(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq %rcx, -0x8(%rbp)
movb %cl, (%rbp)
movslq 0x2c(%rsp), %rcx
imulq $0xa8, %rcx, %r8
leaq (%r12,%r8), %r14
addq $0x8, %r14
leaq 0xd0(%rsp), %rdx
movl $0xb, %ecx
movq %rdx, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movb 0x58(%r14), %cl
movb %cl, 0x58(%rdx)
leaq (%r12,%r8), %rsi
addq $0x68, %rsi
movq %rax, %rdi
callq 0x2110
leaq 0x150(%rsp), %rdi
leaq 0x80(%r14), %rsi
callq 0x2110
movq 0xa0(%r14), %rax
movq %rax, 0x170(%rsp)
cmpl $0x0, (%rbx)
jle 0xdd6b
movslq 0x4(%rbx), %r14
imulq $0xa8, %r14, %r13
movl 0x5c(%r12,%r13), %eax
cmpl $0x85, %eax
jg 0xdd42
cmpl $0x65, %eax
je 0xdd99
cmpl $0x66, %eax
je 0xde7a
cmpl $0x77, %eax
jne 0xdd6b
movslq 0xa58ab(%rip), %rax     # 0xb35b0
shlq $0x5, %rax
leaq 0xa4c20(%rip), %rdi     # 0xb2930
addq %rax, %rdi
movq 0x150(%rsp), %rsi
movq 0x158(%rsp), %rdx
callq 0x20a0
movslq 0x4(%rbx), %rax
imulq $0xa8, %rax, %rax
movl 0xa8(%r12,%rax), %ebx
incl %ebx
jmp 0xdeef
cmpl $0x86, %eax
je 0xde4d
cmpl $0x87, %eax
je 0xdec9
cmpl $0x88, %eax
jne 0xdd6b
leaq 0x5e2b(%rip), %rsi      # 0x13b91
jmp 0xded0
movq 0xb25e(%rip), %rdi      # 0x18fd0
leaq 0x5e1f(%rip), %rsi      # 0x13b98
movl $0xd, %edx
callq 0x2280
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0xb241(%rip), %rdi      # 0x18fd0
callq 0x20f0
jmp 0xdeef
movl %r14d, %edi
callq 0x8ea2
movl %eax, 0x4(%rsp)
cmpl $-0x1, 0x4(%rsp)
je 0xdf87
movslq 0xa57f9(%rip), %rax     # 0xb35b0
shlq $0x5, %rax
leaq 0xa4b6e(%rip), %rdi     # 0xb2930
addq %rax, %rdi
movq 0x150(%rsp), %rsi
movq 0x158(%rsp), %rdx
callq 0x20a0
movl 0x8(%rbx), %ebx
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x88(%r12,%r13), %rsi
movq 0x90(%r12,%r13), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0x7666
leaq 0x8(%rsp), %rsi
movl %ebx, %edi
callq 0xe30b
movl %eax, %r12d
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xde2e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2230
cmpl $0x4, 0x4(%rsp)
jne 0xdfd7
cmpl $0xa, %r12d
jne 0xdfd7
movl %r14d, %edi
callq 0xe8e7
jmp 0xde76
movslq 0xa575c(%rip), %rax     # 0xb35b0
shlq $0x5, %rax
leaq 0xa4ad1(%rip), %rdi     # 0xb2930
addq %rax, %rdi
leaq 0x5db6(%rip), %rsi      # 0x13c1f
callq 0x23d0
movl 0x8(%rbx), %edi
callq 0xdb93
movl %eax, %ebx
jmp 0xdeef
movslq 0xa572f(%rip), %rdi     # 0xb35b0
shlq $0x5, %rdi
leaq 0xa4aa4(%rip), %r14     # 0xb2930
addq %r14, %rdi
leaq 0x64bd(%rip), %rsi      # 0x14353
callq 0x23d0
movl 0x8(%rbx), %edi
movl $0x1, %esi
callq 0xc02d
movl %eax, %ebx
movslq 0xa56ff(%rip), %rax     # 0xb35b0
shlq $0x5, %rax
addq %rax, %r14
leaq 0x665a(%rip), %rsi      # 0x14519
movq %r14, %rdi
callq 0x23d0
jmp 0xdeef
leaq 0x5cbb(%rip), %rsi      # 0x13b8b
movslq 0xa56d9(%rip), %rax     # 0xb35b0
shlq $0x5, %rax
leaq 0xa4a4e(%rip), %rdi     # 0xb2930
addq %rax, %rdi
movl $0x3, %ebx
callq 0x23d0
movq 0x150(%rsp), %rdi
cmpq %rbp, %rdi
je 0xdf0c
movq 0x160(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x130(%rsp), %rdi
cmpq %r15, %rdi
je 0xdf29
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0xdf4e
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xdf73
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x2230
movl %ebx, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb042(%rip), %rbx      # 0x18fd0
leaq 0x5bbb(%rip), %rsi      # 0x13b50
movl $0x1e, %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 0xb010(%rip), %rdi      # 0x18fd0
callq 0x2030
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x2150
jmp 0xdeef
cmpl $0x5, 0x4(%rsp)
jne 0xdfea
xorl %ebx, %ebx
cmpl $0xa, %r12d
je 0xdeef
cmpl $0x1, 0x4(%rsp)
jne 0xe000
movl $0x1, %ebx
cmpl $0xb, %r12d
je 0xdeef
cmpl $0x2, 0x4(%rsp)
jne 0xe016
movl $0x2, %ebx
cmpl $0xb, %r12d
je 0xdeef
cmpl $0x3, 0x4(%rsp)
jne 0xe02c
movl $0x3, %ebx
cmpl $0xb, %r12d
je 0xdeef
testl %r12d, %r12d
je 0xe066
cmpl $0x0, 0x4(%rsp)
je 0xe06f
movq 0xaf91(%rip), %rdi      # 0x18fd0
leaq 0x5b29(%rip), %rsi      # 0x13b6f
movl $0x1b, %edx
callq 0x2280
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0xaf74(%rip), %rdi      # 0x18fd0
callq 0x20f0
jmp 0xdeef
movl 0x4(%rsp), %ebx
jmp 0xdeef
movl %r12d, %ebx
jmp 0xdeef
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xe0cb
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xe0cb
jmp 0xe0c8
jmp 0xe0c8
movq %rax, %rbx
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xe0e2
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xe0e2
jmp 0xe0c8
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0xf396
leaq 0x28(%rsp), %rdi
callq 0xf396
movq %rbx, %rdi
callq 0x23a0