// File: /workspace/github_cpp_makefile_star2_O1/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 0xac274(%rip), %r15     # 0xba0c8
leaq (%r15,%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 0x768e
leaq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x80(%rbx), %rsi
movq 0x88(%rbx), %rdx
addq %rsi, %rdx
callq 0x768e
movq 0xa0(%rbx), %rax
movq %rax, 0xc8(%rsp)
leaq 0x130(%rsp), %rax
leaq 0x140(%rsp), %rdx
movq %rdx, -0x10(%rdx)
xorl %ecx, %ecx
movq %rcx, -0x8(%rdx)
movb %cl, (%rdx)
leaq 0x160(%rsp), %r13
movq %r13, -0x10(%r13)
movq %rcx, -0x8(%r13)
movb %cl, (%r13)
movslq 0x2c(%rsp), %rcx
imulq $0xa8, %rcx, %r8
leaq (%r15,%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 (%r15,%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)
movl (%rbx), %eax
testl %eax, %eax
jle 0xe2a3
movslq 0x4(%rbx), %rcx
imulq $0xa8, %rcx, %rcx
cmpl $0x65, 0x5c(%r15,%rcx)
jne 0xe044
movl 0x4(%rbx), %r14d
movl %r14d, %edi
callq 0x8edc
movl %eax, %ebp
cmpl $-0x1, %eax
je 0xe0a7
movslq 0xa660b(%rip), %rax     # 0xb45b0
shlq $0x5, %rax
leaq 0xa5980(%rip), %rdi     # 0xb3930
addq %rax, %rdi
movq 0x150(%rsp), %rsi
movq 0x158(%rsp), %rdx
callq 0x20a0
movslq %r14d, %rax
movl 0x8(%rbx), %ebx
imulq $0xa8, %rax, %rax
leaq 0x18(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x88(%r15,%rax), %rsi
movq 0x90(%r15,%rax), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0x768e
leaq 0x8(%rsp), %rsi
movl %ebx, %edi
callq 0xe611
movl %eax, %r15d
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0xe022
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2230
movl %r15d, %eax
xorl $0xa, %eax
movl %ebp, %ecx
xorl $0x4, %ecx
orl %eax, %ecx
jne 0xe168
movl %r14d, %edi
callq 0xec12
movl %eax, %ebx
jmp 0xe2cc
testl %eax, %eax
jle 0xe2a3
movslq 0x4(%rbx), %rcx
imulq $0xa8, %rcx, %rcx
cmpl $0x77, 0x5c(%r15,%rcx)
jne 0xe0f7
movslq 0xa6546(%rip), %rax     # 0xb45b0
shlq $0x5, %rax
leaq 0xa58bb(%rip), %rdi     # 0xb3930
addq %rax, %rdi
movq 0x150(%rsp), %rsi
movq 0x158(%rsp), %rdx
callq 0x20a0
movslq 0x4(%rbx), %rax
imulq $0xa8, %rax, %rax
movl 0xa8(%r15,%rax), %ebx
incl %ebx
jmp 0xe2cc
movq 0xbf22(%rip), %rbx      # 0x19fd0
leaq 0x6a6b(%rip), %rsi      # 0x14b20
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 0xbef0(%rip), %rdi      # 0x19fd0
callq 0x2030
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x2150
jmp 0xe2cc
testl %eax, %eax
jle 0xe2a3
movslq 0x4(%rbx), %rcx
imulq $0xa8, %rcx, %rcx
cmpl $0x66, 0x5c(%r15,%rcx)
jne 0xe1f2
movslq 0xa6493(%rip), %rdi     # 0xb45b0
shlq $0x5, %rdi
leaq 0xa5808(%rip), %r14     # 0xb3930
addq %r14, %rdi
leaq 0x7201(%rip), %rsi      # 0x15333
callq 0x23d0
movl 0x8(%rbx), %edi
movl $0x1, %esi
callq 0xc280
movl %eax, %ebx
movslq 0xa6463(%rip), %rax     # 0xb45b0
shlq $0x5, %rax
addq %rax, %r14
leaq 0x739e(%rip), %rsi      # 0x154f9
movq %r14, %rdi
callq 0x23d0
jmp 0xe2cc
movl %ebp, %ecx
xorl $0x5, %ecx
xorl %ebx, %ebx
orl %eax, %ecx
je 0xe2cc
movl %r15d, %eax
xorl $0xb, %eax
movl %ebp, %ecx
xorl $0x1, %ecx
movl $0x1, %ebx
orl %eax, %ecx
je 0xe2cc
movl %ebp, %ecx
xorl $0x2, %ecx
movl $0x2, %ebx
orl %eax, %ecx
je 0xe2cc
movl %ebp, %ecx
xorl $0x3, %ecx
movl $0x3, %ebx
orl %eax, %ecx
je 0xe2cc
testl %r15d, %r15d
je 0xe36c
testl %ebp, %ebp
je 0xe373
movq 0xbe05(%rip), %rdi      # 0x19fd0
leaq 0x696d(%rip), %rsi      # 0x14b3f
movl $0x1b, %edx
callq 0x2280
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0xbde8(%rip), %rdi      # 0x19fd0
callq 0x20f0
jmp 0xe2cc
testl %eax, %eax
jle 0xe2a3
movslq 0x4(%rbx), %rcx
imulq $0xa8, %rcx, %rcx
cmpl $0x86, 0x5c(%r15,%rcx)
jne 0xe23e
movslq 0xa6399(%rip), %rax     # 0xb45b0
shlq $0x5, %rax
leaq 0xa570e(%rip), %rdi     # 0xb3930
addq %rax, %rdi
leaq 0x69c3(%rip), %rsi      # 0x14bef
callq 0x23d0
movl 0x8(%rbx), %edi
callq 0xde32
jmp 0xe03d
testl %eax, %eax
jle 0xe2a3
movslq 0x4(%rbx), %rcx
imulq $0xa8, %rcx, %rcx
cmpl $0x87, 0x5c(%r15,%rcx)
jne 0xe261
leaq 0x68fc(%rip), %rsi      # 0x14b5b
jmp 0xe282
testl %eax, %eax
jle 0xe2a3
movslq 0x4(%rbx), %rax
imulq $0xa8, %rax, %rax
cmpl $0x88, 0x5c(%r15,%rax)
jne 0xe2a3
leaq 0x68df(%rip), %rsi      # 0x14b61
movslq 0xa6327(%rip), %rax     # 0xb45b0
shlq $0x5, %rax
leaq 0xa569c(%rip), %rdi     # 0xb3930
addq %rax, %rdi
movl $0x3, %ebx
callq 0x23d0
jmp 0xe2cc
movq 0xbd26(%rip), %rdi      # 0x19fd0
leaq 0x68b7(%rip), %rsi      # 0x14b68
movl $0xd, %edx
callq 0x2280
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0xbd09(%rip), %rdi      # 0x19fd0
callq 0x20f0
movq 0x150(%rsp), %rdi
cmpq %r13, %rdi
je 0xe2e9
movq 0x160(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
je 0xe30e
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0xe333
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xe358
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
movl %ebp, %ebx
jmp 0xe2cc
movl %r15d, %ebx
jmp 0xe2cc
jmp 0xe3c7
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0xe3ca
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xe3ca
movq %rax, %rbx
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xe3e1
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xe3e1
jmp 0xe3c7
jmp 0xe3c7
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0xf7a8
leaq 0x28(%rsp), %rdi
callq 0xf7a8
movq %rbx, %rdi
callq 0x23a0