// File: /workspace/github_c_makefile_star2_O3/MaoKo[P]FGFX/fgfp/src/lr.c
// Function: check_conflict
bool
check_conflict(cfg_t const* cfg, lr1_state_t* state,
									trans_list_t** reduce_list, int kind) {

	trans_list_t* target_action = (kind == SHIFT_REDUCE)
								? state->shift_lst : state->reduces;
	bool several = false;
	if (state->accept)
		{ several = handle_accept_conflict(cfg, reduce_list); }

	while (target_action) {
		trans_list_t* reset_list = (*reduce_list);
		while (reset_list) {
			if (kind == SHIFT_REDUCE) {
				symbol_t* shift_sym = (symbol_t*)AT_VECTOR(cfg->terminal,
												reset_list->input);

				if ((_SHIFT ^ target_action->input) == reset_list->input) {
					production_t* crt_prod = (production_t*)
												AT_VECTOR(cfg->productions,
												_REDUCE ^ reset_list->state);
					symbol_t* last_sym;
					if (crt_prod->mimic_sym)
						{ last_sym = crt_prod->mimic_sym; }
					else
						{ last_sym = last_symbol_in_prod(crt_prod); }

					if (last_sym && PRECEDENCE(last_sym) != NOT_PREC
							&& PRECEDENCE(shift_sym) != NOT_PREC) {
						if (PRECEDENCE(last_sym) > PRECEDENCE(shift_sym)) {
							del_node_trans_list(&state->shift_lst,
															target_action);
						}
						else if (PRECEDENCE(last_sym) < PRECEDENCE(shift_sym))
							{ del_node_trans_list(reduce_list, reset_list); }
						else {
							if (LEFT(shift_sym)) {
								del_node_trans_list(&state->shift_lst,
															target_action);
							}
							if (RIGHT(shift_sym)) 
							{ del_node_trans_list(reduce_list, reset_list); }
						}
						return (check_conflict(cfg, state, reduce_list, kind));
					}
					else {
						// Favor of shifting
						del_node_trans_list(reduce_list, reset_list);
						several = true; break;
					}
				}
			}
			else if ((kind == REDUCE_REDUCE)
					&& (target_action->input == reset_list->input)) {
				// Favor of reducing by the rule that appear earlier

				trans_list_t const* tnode =
					(target_action->state > reset_list->state) ?
						target_action : reset_list ;

				trans_list_t** list_src =
					(target_action->state > reset_list->state) ?
						&state->reduces : reduce_list ;

				del_node_trans_list(list_src, tnode);
				return (true);
			}
			reset_list = reset_list->next;
		}
		target_action = target_action->next;
	}
	return (several);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %r13d
movq %rdx, %r8
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x10(%rsi), %rax
movq %rax, -0x40(%rbp)
leaq 0x20(%rsi), %rax
movq %rax, -0x48(%rbp)
movq %rdx, -0x30(%rbp)
xorl %eax, %eax
cmpl $0x1, %r13d
setne %al
shll $0x4, %eax
movq 0x10(%rax,%rbx), %r12
cmpb $0x1, 0x29(%rbx)
jne 0x770a
xorl %eax, %eax
movq %r8, %rsi
movq (%rsi), %rsi
testq %rsi, %rsi
je 0x770c
movq 0x10(%r15), %rcx
movq (%rcx), %rcx
movslq 0x8(%rsi), %rdx
movq (%rcx,%rdx,8), %rcx
cmpb $0x1, 0x18(%rcx)
jne 0x76dd
movq %r8, %rdi
callq 0x3b3b
movq -0x30(%rbp), %r8
movb $0x1, %al
jmp 0x76da
xorl %eax, %eax
testq %r12, %r12
je 0x787a
movq %rbx, -0x38(%rbp)
movq (%r8), %r14
testq %r14, %r14
je 0x77c8
cmpl $0x1, %r13d
jne 0x7740
movslq 0x8(%r14), %rcx
movl 0x8(%r12), %edx
xorl %ecx, %edx
cmpl $0x1000, %edx           # imm = 0x1000
jne 0x7755
jmp 0x775a
cmpl $0x2, %r13d
jne 0x7755
movl 0x8(%r12), %ecx
cmpl 0x8(%r14), %ecx
je 0x785b
movq (%r14), %r14
jmp 0x771c
movq (%r15), %rax
movq 0x10(%r15), %rdx
movq (%rdx), %rdx
movq (%rdx,%rcx,8), %rsi
movq (%rax), %rax
movslq 0xc(%r14), %rcx
xorq $0x4000, %rcx           # imm = 0x4000
movq (%rax,%rcx,8), %rdi
movq 0x28(%rdi), %rax
testq %rax, %rax
jne 0x7797
movq %rsi, %rbx
callq 0x587f
movq %rbx, %rsi
movq -0x30(%rbp), %r8
testq %rax, %rax
je 0x77b7
movq 0x20(%rax), %rax
testq %rax, %rax
je 0x77b7
movl (%rax), %ecx
cmpl $-0x1, %ecx
je 0x77b7
movq 0x20(%rsi), %rax
testq %rax, %rax
je 0x77b7
movl (%rax), %edx
cmpl $-0x1, %edx
jne 0x77da
movq %r8, %rdi
movq %r14, %rsi
callq 0x3b3b
movq -0x30(%rbp), %r8
movb $0x1, %al
movq (%r12), %r12
testq %r12, %r12
jne 0x7719
jmp 0x787a
cmpl %edx, %ecx
jle 0x77e7
movq -0x40(%rbp), %rdi
movq %r12, %rsi
jmp 0x77ef
jge 0x7807
movq %r8, %rdi
movq %r14, %rsi
callq 0x3b3b
movq -0x30(%rbp), %r8
movl $0x1, %r13d
movq -0x38(%rbp), %rbx
jmp 0x76c1
cmpb $0x1, 0x4(%rax)
movq -0x38(%rbp), %rbx
jne 0x7837
movq -0x40(%rbp), %rdi
movq %rsi, %r13
movq %r12, %rsi
callq 0x3b3b
movq -0x30(%rbp), %r8
movq 0x20(%r13), %rax
movl $0x1, %r13d
testq %rax, %rax
je 0x76c1
movl $0x1, %r13d
cmpb $0x1, 0x5(%rax)
jne 0x76c1
movq %r8, %rdi
movq %r14, %rsi
callq 0x3b3b
movq -0x30(%rbp), %r8
jmp 0x76c1
movl 0xc(%r12), %eax
cmpl 0xc(%r14), %eax
cmovgq %r12, %r14
cmovgq -0x48(%rbp), %r8
movq %r8, %rdi
movq %r14, %rsi
callq 0x3b3b
movb $0x1, %al
andb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq