// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movl %edi, %ebp
movslq %edi, %rax
imulq $0xa8, %rax, %rax
leaq 0xabea1(%rip), %r15     # 0xb4098
leaq (%r15,%rax), %rbx
addq $0x8, %rbx
leaq 0x110(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa562
leaq 0xd8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0xf8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
movslq 0x4(%r14), %rax
imulq $0xa8, %rax, %rax
leaq (%r15,%rax), %rsi
addq $0x8, %rsi
leaq 0x68(%rsp), %rdi
callq 0xa5ba
movl %ebp, %edi
callq 0x603d
leaq 0x659f(%rip), %rsi      # 0xe804
leal -0x7c(%rax), %ecx
cmpl $0x6, %ecx
ja 0x83a5
leaq 0x62d0(%rip), %rax      # 0xe548
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movslq 0xa62f8(%rip), %rdi     # 0xae580
shlq $0x5, %rdi
leaq 0xa566d(%rip), %r14     # 0xad900
addq %r14, %rdi
leaq 0x65c0(%rip), %rsi      # 0xe85d
callq 0x2350
movl 0x8(%rbx), %edi
pushq $0x1
popq %rsi
callq 0x8946
cmpl $0x3, %eax
jne 0x8577
movslq 0xa62c3(%rip), %rdi     # 0xae580
leal 0x1(%rdi), %eax
movl %eax, 0xa62ba(%rip)     # 0xae580
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x63af(%rip), %rsi      # 0xe683
callq 0x2350
movslq 0xa62a0(%rip), %rdi     # 0xae580
leal 0x1(%rdi), %eax
movl %eax, 0xa6297(%rip)     # 0xae580
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x63e1(%rip), %rsi      # 0xe6d8
callq 0x2350
movl 0x10(%rbx), %edi
callq 0x81d7
movslq 0xa6275(%rip), %rax     # 0xae580
leal 0x2(%rax), %ecx
shlq $0x5, %rax
movl %ecx, 0xa6268(%rip)     # 0xae580
leaq (%rax,%r14), %rdi
addq $0x20, %rdi
leaq 0x636a(%rip), %rsi      # 0xe691
callq 0x2350
movslq 0xa624d(%rip), %rdi     # 0xae580
leal 0x1(%rdi), %eax
movl %eax, 0xa6244(%rip)     # 0xae580
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x6517(%rip), %rsi      # 0xe861
callq 0x2350
movslq 0xa622a(%rip), %rdi     # 0xae580
leal 0x1(%rdi), %eax
movl %eax, 0xa6221(%rip)     # 0xae580
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x636b(%rip), %rsi      # 0xe6d8
callq 0x2350
movl 0x18(%rbx), %edi
callq 0x81d7
movslq 0xa61ff(%rip), %rax     # 0xae580
leal 0x1(%rax), %ecx
movl %ecx, 0xa61f6(%rip)     # 0xae580
shlq $0x5, %rax
addq %rax, %r14
leaq 0x62f9(%rip), %rsi      # 0xe691
movq %r14, %rdi
callq 0x2350
jmp 0x8552
cmpl $0x12, %eax
je 0x852d
cmpl $0x65, %eax
jne 0x853e
movl 0x4(%rbx), %r14d
movl %r14d, %edi
callq 0x6cc0
movl %eax, %ebp
cmpl $-0x1, %eax
je 0x8552
movslq %r14d, %rax
imulq $0xa8, %rax, %rax
leaq (%r15,%rax), %rsi
addq $0x88, %rsi
leaq 0x8(%rsp), %rdi
callq 0x2250
leaq 0xe8(%rsp), %rsi
movslq 0xa6184(%rip), %rax     # 0xae580
shlq $0x5, %rax
leaq 0xa54f9(%rip), %rdi     # 0xad900
addq %rax, %rdi
callq 0x2370
movl 0x8(%rbx), %ebx
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2250
leaq 0x28(%rsp), %rdx
movl %ebx, %edi
movl %ebp, %esi
callq 0x864f
leaq 0x28(%rsp), %rdi
callq 0x2388
leaq 0x8(%rsp), %rdi
jmp 0x8468
movl 0xc(%rbx), %ebx
leaq 0x6177(%rip), %rsi      # 0xe5c1
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x4268
pushq $0x2
popq %rsi
movl %ebx, %edi
callq 0x8a61
leaq 0x48(%rsp), %rdi
callq 0x2388
jmp 0x8552
movslq 0xa6107(%rip), %rdi     # 0xae580
shlq $0x5, %rdi
leaq 0xa547c(%rip), %r14     # 0xad900
addq %r14, %rdi
leaq 0x6402(%rip), %rsi      # 0xe890
callq 0x2350
movl 0x8(%rbx), %edi
pushq $0x1
popq %rsi
callq 0x8946
cmpl $0x3, %eax
jne 0x8537
movslq 0xa60d2(%rip), %rdi     # 0xae580
leal 0x1(%rdi), %eax
movl %eax, 0xa60c9(%rip)     # 0xae580
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x61be(%rip), %rsi      # 0xe683
callq 0x2350
movslq 0xa60af(%rip), %rdi     # 0xae580
leal 0x1(%rdi), %eax
movl %eax, 0xa60a6(%rip)     # 0xae580
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x61f0(%rip), %rsi      # 0xe6d8
callq 0x2350
movl 0x10(%rbx), %edi
callq 0x81d7
movslq 0xa6084(%rip), %rax     # 0xae580
leal 0x1(%rax), %ecx
movl %ecx, 0xa607b(%rip)     # 0xae580
shlq $0x5, %rax
addq %rax, %r14
leaq 0x617e(%rip), %rsi      # 0xe691
movq %r14, %rdi
callq 0x2350
jmp 0x8552
movl 0xc(%rbx), %esi
pushq $-0x1
popq %rdi
pushq $0x3
popq %rdx
callq 0x61ef
jmp 0x8552
movl 0x4(%rbx), %edi
callq 0x7030
jmp 0x8552
leaq 0x632c(%rip), %rsi      # 0xe86a
movq 0xba8b(%rip), %rdi      # 0x13fd0
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
leaq 0x68(%rsp), %rdi
callq 0xa600
leaq 0x110(%rsp), %rdi
callq 0xa600
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0xba52(%rip), %rdi      # 0x13fd0
leaq 0x62e2(%rip), %rsi      # 0xe867
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
pushq $0x1
popq %rdi
callq 0x2220
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x2388
jmp 0x85bc
jmp 0x85ca
jmp 0x85ca
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0x85c1
jmp 0x85ca
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x2388
jmp 0x85cd
jmp 0x85ca
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0xa600
leaq 0x110(%rsp), %rdi
callq 0xa600
movq %rbx, %rdi
callq 0x2330