// File: kiven-li[P]xbytes/xbytes.cpp
// Function: xbytes::xbytes::find_lr_state()
void xbytes::find_lr_state()
{
	//set first state
	make_first_state();

	//set follow state and goto
	while(true)
	{
		int change_count = 0;

		for(int i = 0; i < states.size(); ++i)
		{
			lr_state* ls = states[i];
			if(ls->is_completed) continue;
			for(int j = 0; j < ls->terms.size(); ++j)
			{
				term* t = ls->terms[j];
				if(t->dot >= t->r->rights.size()) continue;

				symbol* s = t->r->rights[t->dot];
				if(s->name == ACCEPT_TERMINAL) continue;

				lr_state ns = lr_goto(*ls, s);
				change_count += add_lr_state(ns);
				change_count += add_lr_goto(*ls, s, ns.state);		
			}
			if(!change_count) ls->is_completed = true;
		}

		if(!change_count) break;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rsi
movq %rsi, -0x128(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x85c0
leaq -0x78(%rbp), %rdi
callq 0xc5f0
movl $0x0, -0x7c(%rbp)
movl $0x0, -0x80(%rbp)
movq -0x128(%rbp), %rdi
movslq -0x80(%rbp), %rax
movq %rax, -0x130(%rbp)
addq $0x38, %rdi
callq 0xc550
movq %rax, %rcx
movq -0x130(%rbp), %rax
cmpq %rcx, %rax
jae 0x696d
movq -0x128(%rbp), %rdi
addq $0x38, %rdi
movslq -0x80(%rbp), %rsi
callq 0xc570
movq (%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
testb $0x1, 0x68(%rax)
je 0x67a8
jmp 0x695f
movl $0x0, -0x8c(%rbp)
movslq -0x8c(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x88(%rbp), %rdi
addq $0x8, %rdi
callq 0xc590
movq %rax, %rcx
movq -0x138(%rbp), %rax
cmpq %rcx, %rax
jae 0x694c
movq -0x88(%rbp), %rdi
addq $0x8, %rdi
movslq -0x8c(%rbp), %rsi
callq 0xc5b0
movq (%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movslq 0x8(%rax), %rax
movq %rax, -0x140(%rbp)
movq -0x98(%rbp), %rax
movq (%rax), %rdi
addq $0x30, %rdi
callq 0xc4d0
movq %rax, %rcx
movq -0x140(%rbp), %rax
cmpq %rcx, %rax
jb 0x683d
jmp 0x6918
movq -0x98(%rbp), %rax
movq (%rax), %rdi
addq $0x30, %rdi
movq -0x98(%rbp), %rax
movslq 0x8(%rax), %rsi
callq 0xc4f0
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rdi
addq $0x8, %rdi
leaq 0x12912(%rip), %rsi     # 0x19189
callq 0xc700
testb $0x1, %al
jne 0x6882
jmp 0x6887
jmp 0x6918
movq -0x128(%rbp), %rsi
movq -0x88(%rbp), %rdx
movq -0xa0(%rbp), %rcx
leaq -0x110(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x86b0
movq -0x128(%rbp), %rdi
movq -0x150(%rbp), %rsi
callq 0x8890
movl %eax, -0x144(%rbp)
jmp 0x68ca
movq -0x128(%rbp), %rdi
movl -0x144(%rbp), %ecx
movl -0x7c(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x7c(%rbp)
movq -0x88(%rbp), %rsi
movq -0xa0(%rbp), %rdx
movl -0x110(%rbp), %ecx
callq 0x89f0
movl %eax, -0x154(%rbp)
jmp 0x6900
movl -0x154(%rbp), %eax
addl -0x7c(%rbp), %eax
movl %eax, -0x7c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0xc5f0
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x67b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x118(%rbp)
movl %eax, -0x11c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0xc5f0
jmp 0x6983
cmpl $0x0, -0x7c(%rbp)
jne 0x695d
movq -0x88(%rbp), %rax
movb $0x1, 0x68(%rax)
jmp 0x695f
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x674a
cmpl $0x0, -0x7c(%rbp)
jne 0x6975
jmp 0x697a
jmp 0x673c
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x118(%rbp), %rdi
callq 0x34e0
nop