// File: /workspace/github_cpp_makefile_star2_O3/zhengwangsun[P]pas2c/semantics.cpp
// Function: statement(int)
void statement(int k)
{
	TreeNode tNode= tree.node[k];
	TreeNode childNode;
	childNode=tree.node[tNode.child[0]];
    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)//说明找到
        {
            string idValue=tree.node[id_position].value;

            code[currentLine].append(childNode.value);

            statement1(tree.node[k].child[1], idType, idValue);
            
        }
    }
    else if (lookahead(k) == 18)//18是compound_statement
    {
        compound_statement(tree.node[k].child[0]);
    }
    else if (lookahead(k) == 124)//124是if
    {
    	code[currentLine].append("if(");
        int ifFlag = expression(tree.node[k].child[1],1);
        
        if(ifFlag== 3)//如果表达式的值是布尔类型
        {
			code[currentLine++].append(")\n");
			code[currentLine++].append("{\n");

            statement(tree.node[k].child[3]);
            currentLine++;
			code[currentLine++].append("}\n");//}单独占一行 

			code[currentLine++].append("else\n");

			code[currentLine++].append("{\n");
			
            statement(tree.node[k].child[5]);
            code[currentLine++].append("}\n");//}单独占一行	
        }
        else
        {
            cout<<"if expresion type wrong where statement!"<<endl;
            exit(1);
        }
    }
    else if (lookahead(k) == 127)//127是while
    {
    	code[currentLine].append("while(");
        if (expression(tree.node[k].child[1],1) == 3)//如果表达式的值是布尔类型
        {
        	code[currentLine++].append(")\n");
			code[currentLine++].append("{\n");
            statement(tree.node[k].child[3]);
            code[currentLine++].append("}\n");
        }
        else
            cout<<"expresion type wrong where statement!"<<endl;
    }
    else if (lookahead(k) == 129)//117是read
    {
        identifier_list(-1, tree.node[k].child[2], 3);//statement调用是3
    }
    else if (lookahead(k) == 130)//130是write
    {
        expression_list(tree.node[k].child[2], 2, " ");
    }
    else
        cout<<"statement error!"<<endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movslq %edi, %rax
imulq $0xa8, %rax, %rax
leaq 0xadc3d(%rip), %r15     # 0xb90c8
leaq (%r15,%rax), %rbx
addq $0x8, %rbx
leaq 0x68(%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 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x60(%rbx), %rsi
movq 0x68(%rbx), %rdx
addq %rsi, %rdx
callq 0x7666
leaq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x80(%rbx), %rsi
movq 0x88(%rbx), %rdx
addq %rsi, %rdx
callq 0x7666
movq 0xa0(%rbx), %rax
movq %rax, 0x108(%rsp)
leaq 0x170(%rsp), %rax
leaq 0x180(%rsp), %r13
movq %r13, -0x10(%r13)
xorl %ecx, %ecx
movq %rcx, -0x8(%r13)
movb %cl, (%r13)
leaq 0x1a0(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq %rcx, -0x8(%rbp)
movb %cl, (%rbp)
movslq 0x6c(%rsp), %rcx
imulq $0xa8, %rcx, %r8
leaq (%r15,%r8), %r14
addq $0x8, %r14
leaq 0x110(%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 0x190(%rsp), %rdi
leaq 0x80(%r14), %rsi
callq 0x2110
movq 0xa0(%r14), %rax
movq %rax, 0x1b0(%rsp)
cmpl $0x0, (%rbx)
jle 0xb7d1
movslq 0x4(%rbx), %rdi
imulq $0xa8, %rdi, %r14
movl 0x5c(%r15,%r14), %eax
leal -0x7c(%rax), %ecx
cmpl $0x6, %ecx
ja 0xb6fa
leaq 0x7f4d(%rip), %rax      # 0x13518
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movslq 0xa7fd5(%rip), %rdi     # 0xb35b0
shlq $0x5, %rdi
leaq 0xa734a(%rip), %r14     # 0xb2930
addq %r14, %rdi
leaq 0x823d(%rip), %rsi      # 0x1382d
callq 0x23d0
movl 0x8(%rbx), %edi
movl $0x1, %esi
callq 0xc02d
cmpl $0x3, %eax
jne 0xb9ef
movslq 0xa7f9e(%rip), %rdi     # 0xb35b0
leal 0x1(%rdi), %eax
movl %eax, 0xa7f95(%rip)     # 0xb35b0
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x802a(%rip), %rsi      # 0x13653
callq 0x23d0
movslq 0xa7f7b(%rip), %rdi     # 0xb35b0
leal 0x1(%rdi), %eax
movl %eax, 0xa7f72(%rip)     # 0xb35b0
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x805c(%rip), %rsi      # 0x136a8
callq 0x23d0
movl 0x10(%rbx), %edi
callq 0xb469
movslq 0xa7f50(%rip), %rax     # 0xb35b0
leal 0x2(%rax), %ecx
shlq $0x5, %rax
movl %ecx, 0xa7f43(%rip)     # 0xb35b0
leaq (%rax,%r14), %rdi
addq $0x20, %rdi
leaq 0x7fe5(%rip), %rsi      # 0x13661
callq 0x23d0
movslq 0xa7f28(%rip), %rdi     # 0xb35b0
leal 0x1(%rdi), %eax
movl %eax, 0xa7f1f(%rip)     # 0xb35b0
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x8192(%rip), %rsi      # 0x13831
callq 0x23d0
movslq 0xa7f05(%rip), %rdi     # 0xb35b0
leal 0x1(%rdi), %eax
movl %eax, 0xa7efc(%rip)     # 0xb35b0
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x7fe6(%rip), %rsi      # 0x136a8
callq 0x23d0
movl 0x18(%rbx), %edi
callq 0xb469
movslq 0xa7eda(%rip), %rax     # 0xb35b0
leal 0x1(%rax), %ecx
movl %ecx, 0xa7ed1(%rip)     # 0xb35b0
shlq $0x5, %rax
addq %rax, %r14
leaq 0x7f74(%rip), %rsi      # 0x13661
movq %r14, %rdi
callq 0x23d0
jmp 0xb7f5
cmpl $0x12, %eax
je 0xb99a
cmpl $0x65, %eax
jne 0xb7d1
callq 0x8ea2
cmpl $-0x1, %eax
je 0xb7f5
movl %eax, 0x4(%rsp)
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x88(%r15,%r14), %rsi
movq 0x90(%r15,%r14), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0x7666
movslq 0xa7e65(%rip), %rax     # 0xb35b0
shlq $0x5, %rax
leaq 0xa71da(%rip), %rdi     # 0xb2930
addq %rax, %rdi
movq 0x190(%rsp), %rsi
movq 0x198(%rsp), %rdx
callq 0x20a0
movl 0x8(%rbx), %ebx
leaq 0x38(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0x7666
leaq 0x28(%rsp), %rdx
movl %ebx, %edi
movl 0x4(%rsp), %esi
callq 0xbb68
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0xb7b8
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xb7f5
movq 0x18(%rsp), %rsi
jmp 0xb8c6
movq 0xd7f8(%rip), %rdi      # 0x18fd0
leaq 0x7ff5(%rip), %rsi      # 0x137d4
movl $0x10, %edx
callq 0x2280
movq 0xd7e0(%rip), %rdi      # 0x18fd0
callq 0x20f0
movq 0x190(%rsp), %rdi
cmpq %rbp, %rdi
je 0xb812
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x170(%rsp), %rdi
cmpq %r13, %rdi
je 0xb82f
movq 0x180(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0xe8(%rsp), %rdi
cmpq %r12, %rdi
je 0xb84c
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0xb871
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x2230
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0xc(%rbx), %ebx
leaq 0x58(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x7cfb(%rip), %rsi      # 0x13591
leaq 0x7cf5(%rip), %rdx      # 0x13592
leaq 0x48(%rsp), %rdi
callq 0x76fc
movl %ebx, %edi
movl $0x2, %esi
callq 0xc19b
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0xb7f5
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xb7f5
movslq 0xa7cd6(%rip), %rdi     # 0xb35b0
shlq $0x5, %rdi
leaq 0xa704b(%rip), %r14     # 0xb2930
addq %r14, %rdi
leaq 0x7f71(%rip), %rsi      # 0x13860
callq 0x23d0
movl 0x8(%rbx), %edi
movl $0x1, %esi
callq 0xc02d
cmpl $0x3, %eax
jne 0xb9a4
movslq 0xa7c9f(%rip), %rdi     # 0xb35b0
leal 0x1(%rdi), %eax
movl %eax, 0xa7c96(%rip)     # 0xb35b0
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x7d2b(%rip), %rsi      # 0x13653
callq 0x23d0
movslq 0xa7c7c(%rip), %rdi     # 0xb35b0
leal 0x1(%rdi), %eax
movl %eax, 0xa7c73(%rip)     # 0xb35b0
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x7d5d(%rip), %rsi      # 0x136a8
callq 0x23d0
movl 0x10(%rbx), %edi
callq 0xb469
movslq 0xa7c51(%rip), %rax     # 0xb35b0
leal 0x1(%rax), %ecx
movl %ecx, 0xa7c48(%rip)     # 0xb35b0
shlq $0x5, %rax
addq %rax, %r14
leaq 0x7ceb(%rip), %rsi      # 0x13661
movq %r14, %rdi
callq 0x23d0
jmp 0xb7f5
movl 0xc(%rbx), %esi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl $0x3, %edx
callq 0x7ac6
jmp 0xb7f5
callq 0x9447
jmp 0xb7f5
movq 0xd625(%rip), %rbx      # 0x18fd0
leaq 0x7e88(%rip), %rsi      # 0x1383a
movl $0x25, %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 0xd5f3(%rip), %rdi      # 0x18fd0
callq 0x2030
movq %rax, %rdi
callq 0x2150
jmp 0xb7f5
movq 0xd5da(%rip), %rdi      # 0x18fd0
leaq 0x7e3a(%rip), %rsi      # 0x13837
movl $0x28, %edx
callq 0x2280
movq 0xd5c2(%rip), %rdi      # 0x18fd0
callq 0x20f0
movl $0x1, %edi
callq 0x2290
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0xba56
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xba56
jmp 0xbaa0
jmp 0xbaa0
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0xbaa3
movq 0x58(%rsp), %rsi
jmp 0xba6a
jmp 0xbaa0
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xbaa3
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xbaa3
jmp 0xbaa0
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0xbaba
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xbaba
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0xf396
leaq 0x68(%rsp), %rdi
callq 0xf396
movq %rbx, %rdi
callq 0x23a0