// File: kiven-li[P]xbytes/xbytes.cpp
// Function: xbytes::xbytes::resolve_conflict(xbytes::action&, xbytes::action&)
int xbytes::resolve_conflict(action& x, action& y)
{
	int error = 0;
	assert(x.lookahead == y.lookahead);

	if(x.type == LR_ACTION_SHIFT && y.type == LR_ACTION_SHIFT)
	{
		y.type = LR_ACTION_SSCONFLICT;
		error++;
	}

	if(x.type == LR_ACTION_SHIFT && y.type == LR_ACTION_REDUCE)
	{
		symbol* xs = x.lookahead;
		symbol* ys = y.r->precedence_symbol;

		if(ys == NULL || xs->precedence < 0 || ys->precedence < 0)
		{
			//Not enough precedence information
			y.type = LR_ACTION_SRCONFLICT;
			error++;
		}
		else if(xs->precedence > ys->precedence)
		{
			y.type = LR_ACTION_RDRESOLVED;
		}
		else if(xs->precedence < ys->precedence)
		{
			x.type = LR_ACTION_SHRESOLVED;
		}
		else if(xs->precedence == ys->precedence && xs->associativity == AT_RIGHT)//Use operator
		{
			y.type = LR_ACTION_RDRESOLVED;//associativity
		}
		else if(xs->precedence == ys->precedence && xs->associativity == AT_LEFT)//to break tie
		{
			x.type = LR_ACTION_SHRESOLVED;
		}
		else
		{
			assert(xs->precedence == ys->precedence && xs->associativity == AT_NONE);
			x.type = LR_ACTION_ERROR;
		}
	}
	else if(x.type = LR_ACTION_REDUCE && y.type == LR_ACTION_REDUCE)
	{
		symbol* xs = x.r->precedence_symbol;
		symbol* ys = y.r->precedence_symbol;

		if(xs == NULL || ys == NULL || xs->precedence < 0 || 
			ys->precedence < 0 || xs->precedence == ys->precedence)
		{
			y.type = LR_ACTION_RRCONFLICT;
			error++;
		}
		else if(xs->precedence > ys->precedence)
		{
			y.type = LR_ACTION_RDRESOLVED;
		}
		else if(xs->precedence < ys->precedence)
		{
			x.type = LR_ACTION_RDRESOLVED;
		}
	}
	else
	{
		assert(
			x.type == LR_ACTION_SHRESOLVED ||
			x.type == LR_ACTION_RDRESOLVED ||
			x.type == LR_ACTION_SSCONFLICT ||
			x.type == LR_ACTION_SRCONFLICT ||
			x.type == LR_ACTION_RRCONFLICT ||
			y.type == LR_ACTION_SHRESOLVED ||
			y.type == LR_ACTION_RDRESOLVED ||
			y.type == LR_ACTION_SSCONFLICT ||
			y.type == LR_ACTION_SRCONFLICT ||
			y.type == LR_ACTION_RRCONFLICT
			);
	}

	return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x931f
jmp 0x933e
leaq 0xfebf(%rip), %rdi      # 0x191e5
leaq 0xfe6b(%rip), %rsi      # 0x19198
movl $0x2bc, %edx            # imm = 0x2BC
leaq 0xfec7(%rip), %rcx      # 0x19200
callq 0x31d0
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x9363
movq -0x18(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x9363
movq -0x18(%rbp), %rax
movl $0x6, (%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x94ed
movq -0x18(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x94ed
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0xa0(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x93bd
movq -0x28(%rbp), %rax
cmpl $0x0, 0xa0(%rax)
jl 0x93bd
movq -0x30(%rbp), %rax
cmpl $0x0, 0xa0(%rax)
jge 0x93d5
movq -0x18(%rbp), %rax
movl $0x7, (%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x94e8
movq -0x28(%rbp), %rax
movl 0xa0(%rax), %eax
movq -0x30(%rbp), %rcx
cmpl 0xa0(%rcx), %eax
jle 0x93fa
movq -0x18(%rbp), %rax
movl $0x9, (%rax)
jmp 0x94e6
movq -0x28(%rbp), %rax
movl 0xa0(%rax), %eax
movq -0x30(%rbp), %rcx
cmpl 0xa0(%rcx), %eax
jge 0x941f
movq -0x10(%rbp), %rax
movl $0xa, (%rax)
jmp 0x94e4
movq -0x28(%rbp), %rax
movl 0xa0(%rax), %eax
movq -0x30(%rbp), %rcx
cmpl 0xa0(%rcx), %eax
jne 0x9451
movq -0x28(%rbp), %rax
cmpl $0x2, 0xa4(%rax)
jne 0x9451
movq -0x18(%rbp), %rax
movl $0x9, (%rax)
jmp 0x94e2
movq -0x28(%rbp), %rax
movl 0xa0(%rax), %eax
movq -0x30(%rbp), %rcx
cmpl 0xa0(%rcx), %eax
jne 0x9480
movq -0x28(%rbp), %rax
cmpl $0x1, 0xa4(%rax)
jne 0x9480
movq -0x10(%rbp), %rax
movl $0xa, (%rax)
jmp 0x94e0
movq -0x28(%rbp), %rax
movl 0xa0(%rax), %ecx
movq -0x30(%rbp), %rdx
xorl %eax, %eax
cmpl 0xa0(%rdx), %ecx
movb %al, -0x41(%rbp)
jne 0x94ac
movq -0x28(%rbp), %rax
cmpl $0x0, 0xa4(%rax)
sete %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x94b5
jmp 0x94b7
jmp 0x94d6
leaq 0xfd7b(%rip), %rdi      # 0x19239
leaq 0xfcd3(%rip), %rsi      # 0x19198
movl $0x2e1, %edx            # imm = 0x2E1
leaq 0xfd2f(%rip), %rcx      # 0x19200
callq 0x31d0
movq -0x10(%rbp), %rax
movl $0x5, (%rax)
jmp 0x94e2
jmp 0x94e4
jmp 0x94e6
jmp 0x94e8
jmp 0x968b
movq -0x18(%rbp), %rax
cmpl $0x3, (%rax)
sete %al
movb %al, %cl
andb $0x1, %cl
movzbl %cl, %edx
movq -0x10(%rbp), %rcx
movl %edx, (%rcx)
testb $0x1, %al
jne 0x950e
jmp 0x95d2
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq 0xa0(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0xa0(%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x9572
cmpq $0x0, -0x40(%rbp)
je 0x9572
movq -0x38(%rbp), %rax
cmpl $0x0, 0xa0(%rax)
jl 0x9572
movq -0x40(%rbp), %rax
cmpl $0x0, 0xa0(%rax)
jl 0x9572
movq -0x38(%rbp), %rax
movl 0xa0(%rax), %eax
movq -0x40(%rbp), %rcx
cmpl 0xa0(%rcx), %eax
jne 0x9587
movq -0x18(%rbp), %rax
movl $0x8, (%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x95cd
movq -0x38(%rbp), %rax
movl 0xa0(%rax), %eax
movq -0x40(%rbp), %rcx
cmpl 0xa0(%rcx), %eax
jle 0x95a9
movq -0x18(%rbp), %rax
movl $0x9, (%rax)
jmp 0x95cb
movq -0x38(%rbp), %rax
movl 0xa0(%rax), %eax
movq -0x40(%rbp), %rcx
cmpl 0xa0(%rcx), %eax
jge 0x95c9
movq -0x10(%rbp), %rax
movl $0x9, (%rax)
jmp 0x95cb
jmp 0x95cd
jmp 0x9689
movq -0x10(%rbp), %rcx
movb $0x1, %al
cmpl $0xa, (%rcx)
movb %al, -0x42(%rbp)
je 0x965d
movq -0x10(%rbp), %rcx
movb $0x1, %al
cmpl $0x9, (%rcx)
movb %al, -0x42(%rbp)
je 0x965d
movq -0x10(%rbp), %rcx
movb $0x1, %al
cmpl $0x6, (%rcx)
movb %al, -0x42(%rbp)
je 0x965d
movq -0x10(%rbp), %rcx
movb $0x1, %al
cmpl $0x7, (%rcx)
movb %al, -0x42(%rbp)
je 0x965d
movq -0x10(%rbp), %rcx
movb $0x1, %al
cmpl $0x8, (%rcx)
movb %al, -0x42(%rbp)
je 0x965d
movq -0x18(%rbp), %rcx
movb $0x1, %al
cmpl $0xa, (%rcx)
movb %al, -0x42(%rbp)
je 0x965d
movq -0x18(%rbp), %rcx
movb $0x1, %al
cmpl $0x9, (%rcx)
movb %al, -0x42(%rbp)
je 0x965d
movq -0x18(%rbp), %rcx
movb $0x1, %al
cmpl $0x6, (%rcx)
movb %al, -0x42(%rbp)
je 0x965d
movq -0x18(%rbp), %rcx
movb $0x1, %al
cmpl $0x7, (%rcx)
movb %al, -0x42(%rbp)
je 0x965d
movq -0x18(%rbp), %rax
cmpl $0x8, (%rax)
sete %al
movb %al, -0x42(%rbp)
movb -0x42(%rbp), %al
testb $0x1, %al
jne 0x9666
jmp 0x9668
jmp 0x9687
leaq 0xfc0b(%rip), %rdi      # 0x1927a
leaq 0xfb22(%rip), %rsi      # 0x19198
movl $0x306, %edx            # imm = 0x306
leaq 0xfb7e(%rip), %rcx      # 0x19200
callq 0x31d0
jmp 0x9689
jmp 0x968b
movl -0x1c(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)