// File: kiven-li[P]xbytes/xbytes.cpp
// Function: xbytes::xbytes::add_rule(xbytes::rule&)
void xbytes::add_rule(rule& r)
{
	//create new rule
	rule* rr = new rule();
	rr->index = rules.size();
	rr->left = r.left;
	rr->left_alias = r.left_alias;
	rr->rights = r.rights;
	rr->right_alias = r.right_alias;
	rr->code = r.code;
	make_string_rule(*rr);
	rules.push_back(rr);

	//attach rule with left symbol
	rr->left->rules.push_back(rr);

	//set start rule
	if(rr->left->name == "program")
	{
		start = rr;

		symbol* s = new symbol();
		s->index = symbols.size();
		s->name = ACCEPT_TERMINAL;
		s->type = ST_TERMINAL;
		s->associativity = AT_NONE;
		s->precedence = -1;
		symbols.push_back(s);
		rr->rights.push_back(s);
		rr->right_alias.push_back("");
	}
	
	//clear global rule
	r.left = NULL;
	r.left_alias.clear();
	r.rights.clear();	
	r.right_alias.clear();
	r.code.clear();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movl $0xa8, %edi
callq 0x32f0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x60(%rbp)
callq 0xc260
jmp 0x98d6
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rax
movq %rax, -0x18(%rbp)
addq $0x20, %rdi
callq 0xc510
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rsi
addq $0x10, %rsi
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
callq 0x3030
movq -0x10(%rbp), %rsi
addq $0x30, %rsi
movq -0x18(%rbp), %rdi
addq $0x30, %rdi
callq 0xca50
movq -0x10(%rbp), %rsi
addq $0x48, %rsi
movq -0x18(%rbp), %rdi
addq $0x48, %rdi
callq 0xd0d0
movq -0x10(%rbp), %rsi
addq $0x60, %rsi
movq -0x18(%rbp), %rdi
addq $0x60, %rdi
callq 0x3030
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x9c10
movq -0x68(%rbp), %rdi
addq $0x20, %rdi
leaq -0x18(%rbp), %rsi
callq 0xd320
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x50, %rdi
leaq -0x18(%rbp), %rsi
callq 0xd320
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x8, %rdi
leaq 0xfb7a(%rip), %rsi      # 0x19517
callq 0xc700
testb $0x1, %al
jne 0x99ab
jmp 0x9b16
movq -0x68(%rbp), %rax
movq -0x18(%rbp), %rcx
movq %rcx, (%rax)
movl $0xa8, %edi
callq 0x32f0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x70(%rbp)
callq 0xc1f0
jmp 0x99d1
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rax
movq %rax, -0x30(%rbp)
addq $0x8, %rdi
movq %rdi, -0x90(%rbp)
callq 0xc4d0
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rdi
addq $0x8, %rdi
leaq 0xf785(%rip), %rsi      # 0x19189
callq 0x33f0
movq -0x90(%rbp), %rdi
movq -0x30(%rbp), %rax
movl $0x1, 0x48(%rax)
movq -0x30(%rbp), %rax
movl $0x0, 0xa4(%rax)
movq -0x30(%rbp), %rax
movl $0xffffffff, 0xa0(%rax) # imm = 0xFFFFFFFF
leaq -0x30(%rbp), %rsi
movq %rsi, -0x88(%rbp)
callq 0xc690
movq -0x88(%rbp), %rsi
movq -0x18(%rbp), %rdi
addq $0x30, %rdi
callq 0xc690
movq -0x18(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x80(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0x78(%rbp)
callq 0x34f0
movq -0x78(%rbp), %rdx
leaq 0xfbc1(%rip), %rsi      # 0x19640
leaq -0x50(%rbp), %rdi
callq 0x3830
jmp 0x9a8a
movq -0x80(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0xd390
jmp 0x9a99
leaq -0x50(%rbp), %rdi
callq 0x31b0
leaq -0x51(%rbp), %rdi
callq 0x3340
jmp 0x9b16
movq -0x60(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0xa8, %esi
callq 0x3300
jmp 0x9b5f
movq -0x70(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0xa8, %esi
callq 0x3300
jmp 0x9b5f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x9b0b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x31b0
leaq -0x51(%rbp), %rdi
callq 0x3340
jmp 0x9b5f
movq -0x10(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
callq 0x33e0
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
callq 0xca30
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
callq 0xd3c0
movq -0x10(%rbp), %rdi
addq $0x60, %rdi
callq 0x33e0
addq $0x90, %rsp
popq %rbp
retq
movq -0x20(%rbp), %rdi
callq 0x34e0
nopl (%rax,%rax)