// File: kiven-li[P]xbytes/xbytes.cpp
// Function: xbytes::xbytes::closure(xbytes::lr_state&)
void xbytes::closure(lr_state& s)
{
	while(true)
	{
		int change_count = 0;
		for(int i = 0; i < s.terms.size(); ++i)
		{
			term* t = s.terms[i];
			if(t->is_completed) continue;
			if(t->dot >= t->r->rights.size()) continue;
			if(t->r->rights[t->dot]->type == ST_TERMINAL) continue;

			symbol* ss = t->r->rights[t->dot];
			for(int j = 0; j < ss->rules.size(); ++j)
			{				
				term tt;
				tt.r = ss->rules[j];
				tt.dot = 0;

				if(t->forwards.size() != 0)
				{
					for(int m = 0; m < t->forwards.size(); ++m)
					{
						for(int n = 0; n < t->forwards[m]->first_set.size(); ++n)
						{
							tt.forwards.push_back(t->forwards[m]->first_set[n]);
							change_count += add_term(s, tt);
							tt.forwards.clear();
						}
					}
				}
				if(t->dot < t->r->rights.size() - 1)
				{
					for(int m = 0; m < t->r->rights[t->dot+1]->first_set.size(); ++m)
					{
						tt.forwards.push_back(t->r->rights[t->dot+1]->first_set[m]);
						change_count += add_term(s, tt);
						tt.forwards.clear();
					}
				}
			}

			if(!change_count) t->is_completed = true;
		}

		if(!change_count) break;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movslq -0x18(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
callq 0xc590
movq %rax, %rcx
movq -0x88(%rbp), %rax
cmpq %rcx, %rax
jae 0x8e20
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movslq -0x18(%rbp), %rsi
callq 0xc5b0
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
testb $0x1, 0x28(%rax)
je 0x8adb
jmp 0x8e12
movq -0x20(%rbp), %rax
movslq 0x8(%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
addq $0x30, %rdi
callq 0xc4d0
movq %rax, %rcx
movq -0x90(%rbp), %rax
cmpq %rcx, %rax
jb 0x8b0e
jmp 0x8e12
movq -0x20(%rbp), %rax
movq (%rax), %rdi
addq $0x30, %rdi
movq -0x20(%rbp), %rax
movslq 0x8(%rax), %rsi
callq 0xc4f0
movq (%rax), %rax
cmpl $0x1, 0x48(%rax)
jne 0x8b34
jmp 0x8e12
movq -0x20(%rbp), %rax
movq (%rax), %rdi
addq $0x30, %rdi
movq -0x20(%rbp), %rax
movslq 0x8(%rax), %rsi
callq 0xc4f0
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movslq -0x2c(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x28(%rbp), %rdi
addq $0x50, %rdi
callq 0xc510
movq %rax, %rcx
movq -0x98(%rbp), %rax
cmpq %rcx, %rax
jae 0x8e02
leaq -0x60(%rbp), %rdi
callq 0xc770
movq -0x28(%rbp), %rdi
addq $0x50, %rdi
movslq -0x2c(%rbp), %rsi
callq 0xc530
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x58(%rbp)
movq -0x20(%rbp), %rdi
addq $0x10, %rdi
callq 0xc4d0
cmpq $0x0, %rax
je 0x8ce1
movl $0x0, -0x64(%rbp)
movslq -0x64(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x20(%rbp), %rdi
addq $0x10, %rdi
callq 0xc4d0
movq %rax, %rcx
movq -0xa0(%rbp), %rax
cmpq %rcx, %rax
jae 0x8cdf
movl $0x0, -0x68(%rbp)
movslq -0x68(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x20(%rbp), %rdi
addq $0x10, %rdi
movslq -0x64(%rbp), %rsi
callq 0xc4f0
movq (%rax), %rdi
addq $0x70, %rdi
callq 0xc4d0
movq %rax, %rcx
movq -0xa8(%rbp), %rax
cmpq %rcx, %rax
jae 0x8ccf
leaq -0x50(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x20(%rbp), %rdi
addq $0x10, %rdi
movslq -0x64(%rbp), %rsi
callq 0xc4f0
movq (%rax), %rdi
addq $0x70, %rdi
movslq -0x68(%rbp), %rsi
callq 0xc4f0
movq -0xb0(%rbp), %rdi
movq %rax, %rsi
callq 0xc690
jmp 0x8c75
movq -0x80(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x91b0
movl %eax, -0xb4(%rbp)
jmp 0x8c8e
movl -0xb4(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
leaq -0x60(%rbp), %rdi
addq $0x10, %rdi
callq 0xca30
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x8bfd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xc5d0
jmp 0x8e36
jmp 0x8cd1
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x8bcb
jmp 0x8ce1
movq -0x20(%rbp), %rax
movslq 0x8(%rax), %rax
movq %rax, -0xc0(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
addq $0x30, %rdi
callq 0xc4d0
movq %rax, %rcx
movq -0xc0(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x8deb
movl $0x0, -0x78(%rbp)
movslq -0x78(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
addq $0x30, %rdi
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0xc4f0
movq (%rax), %rdi
addq $0x70, %rdi
callq 0xc4d0
movq %rax, %rcx
movq -0xc8(%rbp), %rax
cmpq %rcx, %rax
jae 0x8de9
leaq -0x50(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
addq $0x30, %rdi
movl 0x8(%rax), %eax
incl %eax
movslq %eax, %rsi
callq 0xc4f0
movq (%rax), %rdi
addq $0x70, %rdi
movslq -0x78(%rbp), %rsi
callq 0xc4f0
movq -0xd0(%rbp), %rdi
movq %rax, %rsi
callq 0xc690
jmp 0x8da9
movq -0x80(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x91b0
movl %eax, -0xd4(%rbp)
jmp 0x8dc2
movl -0xd4(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
leaq -0x60(%rbp), %rdi
addq $0x10, %rdi
callq 0xca30
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x8d1e
jmp 0x8deb
leaq -0x60(%rbp), %rdi
callq 0xc5d0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x8b5a
cmpl $0x0, -0x14(%rbp)
jne 0x8e10
movq -0x20(%rbp), %rax
movb $0x1, 0x28(%rax)
jmp 0x8e12
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x8a89
cmpl $0x0, -0x14(%rbp)
jne 0x8e28
jmp 0x8e2d
jmp 0x8a7b
addq $0xe0, %rsp
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x34e0
nop