// File: /workspace/github_cpp_makefile_star2_O1/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 0xaea85(%rip), %r12     # 0xba0c8
leaq (%r12,%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 0x768e
leaq 0xe8(%rsp), %rdi
leaq 0xf8(%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, 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), %r15
movq %r15, -0x10(%r15)
movq %rcx, -0x8(%r15)
movb %cl, (%r15)
movslq 0x6c(%rsp), %rcx
imulq $0xa8, %rcx, %r8
leaq (%r12,%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 (%r12,%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)
movl (%rbx), %eax
testl %eax, %eax
jle 0xbb6b
movslq 0x4(%rbx), %rcx
imulq $0xa8, %rcx, %rcx
cmpl $0x65, 0x5c(%r12,%rcx)
jne 0xb851
movl 0x4(%rbx), %r14d
movl %r14d, %edi
callq 0x8edc
movl %eax, %ebp
cmpl $-0x1, %eax
je 0xbb8f
movslq %r14d, %rax
imulq $0xa8, %rax, %rax
leaq 0x18(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x88(%r12,%rax), %rsi
movq 0x90(%r12,%rax), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0x768e
movslq 0xa8deb(%rip), %rax     # 0xb45b0
shlq $0x5, %rax
leaq 0xa8160(%rip), %rdi     # 0xb3930
addq %rax, %rdi
movq 0x190(%rsp), %rsi
movq 0x198(%rsp), %rdx
callq 0x20a0
movl 0x8(%rbx), %ebx
leaq 0x38(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0x768e
leaq 0x28(%rsp), %rdx
movl %ebx, %edi
movl %ebp, %esi
callq 0xbda3
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0xb831
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0xbb8f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xbb8f
testl %eax, %eax
jle 0xbb6b
movslq 0x4(%rbx), %rcx
imulq $0xa8, %rcx, %rcx
cmpl $0x12, 0x5c(%r12,%rcx)
jne 0xb879
movl 0x4(%rbx), %edi
callq 0x952c
jmp 0xbb8f
testl %eax, %eax
jle 0xbb6b
movslq 0x4(%rbx), %rcx
imulq $0xa8, %rcx, %rcx
cmpl $0x7c, 0x5c(%r12,%rcx)
jne 0xb9be
movslq 0xa8d11(%rip), %rdi     # 0xb45b0
shlq $0x5, %rdi
leaq 0xa8086(%rip), %r14     # 0xb3930
addq %r14, %rdi
leaq 0x8f49(%rip), %rsi      # 0x147fd
callq 0x23d0
movl 0x8(%rbx), %edi
movl $0x1, %esi
callq 0xc280
cmpl $0x3, %eax
jne 0xbc25
movslq 0xa8cda(%rip), %rdi     # 0xb45b0
leal 0x1(%rdi), %eax
movl %eax, 0xa8cd1(%rip)     # 0xb45b0
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x8d36(%rip), %rsi      # 0x14623
callq 0x23d0
movslq 0xa8cb7(%rip), %rdi     # 0xb45b0
leal 0x1(%rdi), %eax
movl %eax, 0xa8cae(%rip)     # 0xb45b0
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x8d68(%rip), %rsi      # 0x14678
callq 0x23d0
movl 0x10(%rbx), %edi
callq 0xb621
movslq 0xa8c8c(%rip), %rax     # 0xb45b0
leal 0x2(%rax), %ecx
shlq $0x5, %rax
movl %ecx, 0xa8c7f(%rip)     # 0xb45b0
leaq (%rax,%r14), %rdi
addq $0x20, %rdi
leaq 0x8cf1(%rip), %rsi      # 0x14631
callq 0x23d0
movslq 0xa8c64(%rip), %rdi     # 0xb45b0
leal 0x1(%rdi), %eax
movl %eax, 0xa8c5b(%rip)     # 0xb45b0
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x8e9e(%rip), %rsi      # 0x14801
callq 0x23d0
movslq 0xa8c41(%rip), %rdi     # 0xb45b0
leal 0x1(%rdi), %eax
movl %eax, 0xa8c38(%rip)     # 0xb45b0
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x8cf2(%rip), %rsi      # 0x14678
callq 0x23d0
movl 0x18(%rbx), %edi
callq 0xb621
movslq 0xa8c16(%rip), %rax     # 0xb45b0
leal 0x1(%rax), %ecx
movl %ecx, 0xa8c0d(%rip)     # 0xb45b0
shlq $0x5, %rax
addq %rax, %r14
leaq 0x8c80(%rip), %rsi      # 0x14631
movq %r14, %rdi
callq 0x23d0
jmp 0xbb8f
testl %eax, %eax
jle 0xbb6b
movslq 0x4(%rbx), %rcx
imulq $0xa8, %rcx, %rcx
cmpl $0x7f, 0x5c(%r12,%rcx)
jne 0xba8d
movslq 0xa8bcc(%rip), %rdi     # 0xb45b0
shlq $0x5, %rdi
leaq 0xa7f41(%rip), %r14     # 0xb3930
addq %r14, %rdi
leaq 0x8e37(%rip), %rsi      # 0x14830
callq 0x23d0
movl 0x8(%rbx), %edi
movl $0x1, %esi
callq 0xc280
cmpl $0x3, %eax
jne 0xbac2
movslq 0xa8b95(%rip), %rdi     # 0xb45b0
leal 0x1(%rdi), %eax
movl %eax, 0xa8b8c(%rip)     # 0xb45b0
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x8bf1(%rip), %rsi      # 0x14623
callq 0x23d0
movslq 0xa8b72(%rip), %rdi     # 0xb45b0
leal 0x1(%rdi), %eax
movl %eax, 0xa8b69(%rip)     # 0xb45b0
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x8c23(%rip), %rsi      # 0x14678
callq 0x23d0
movl 0x10(%rbx), %edi
callq 0xb621
movslq 0xa8b47(%rip), %rax     # 0xb45b0
leal 0x1(%rax), %ecx
movl %ecx, 0xa8b3e(%rip)     # 0xb45b0
shlq $0x5, %rax
addq %rax, %r14
leaq 0x8bb1(%rip), %rsi      # 0x14631
movq %r14, %rdi
callq 0x23d0
jmp 0xbb8f
testl %eax, %eax
jle 0xbb6b
movslq 0x4(%rbx), %rcx
imulq $0xa8, %rcx, %rcx
cmpl $0x81, 0x5c(%r12,%rcx)
jne 0xbb0d
movl 0xc(%rbx), %esi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl $0x3, %edx
callq 0x7ae5
jmp 0xbb8f
movq 0xe507(%rip), %rbx      # 0x19fd0
leaq 0x8d3a(%rip), %rsi      # 0x1480a
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 0xe4d5(%rip), %rdi      # 0x19fd0
callq 0x2030
movq %rax, %rdi
callq 0x2150
jmp 0xbb8f
testl %eax, %eax
jle 0xbb6b
movslq 0x4(%rbx), %rax
imulq $0xa8, %rax, %rax
cmpl $0x82, 0x5c(%r12,%rax)
jne 0xbb6b
movl 0xc(%rbx), %ebx
leaq 0x58(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x8a27(%rip), %rsi      # 0x14561
leaq 0x8a21(%rip), %rdx      # 0x14562
leaq 0x48(%rsp), %rdi
callq 0x771e
movl %ebx, %edi
movl $0x2, %esi
callq 0xc3f7
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0xbb8f
movq 0x58(%rsp), %rsi
jmp 0xb844
movq 0xe45e(%rip), %rdi      # 0x19fd0
leaq 0x8c2b(%rip), %rsi      # 0x147a4
movl $0x10, %edx
callq 0x2280
movq 0xe446(%rip), %rdi      # 0x19fd0
callq 0x20f0
movq 0x190(%rsp), %rdi
cmpq %r15, %rdi
je 0xbbac
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x170(%rsp), %rdi
cmpq %r13, %rdi
je 0xbbc9
movq 0x180(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
cmpq %rax, %rdi
je 0xbbee
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0xbc13
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
movq 0xe3a4(%rip), %rdi      # 0x19fd0
leaq 0x8bd4(%rip), %rsi      # 0x14807
movl $0x28, %edx
callq 0x2280
movq 0xe38c(%rip), %rdi      # 0x19fd0
callq 0x20f0
movl $0x1, %edi
callq 0x2290
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0xbcd4
movq 0x58(%rsp), %rsi
jmp 0xbc9d
jmp 0xbcd1
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0xbc8e
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xbc8e
jmp 0xbcd1
jmp 0xbcd1
jmp 0xbcd1
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0xbcd4
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xbcd4
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0xbceb
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0xbceb
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0xf7a8
leaq 0x68(%rsp), %rdi
callq 0xf7a8
movq %rbx, %rdi
callq 0x23a0