// File: /workspace/github_c_makefile_star2_O1/MaoKo[P]FGFX/fgfp/src/cfg_production.c
// Function: unreachable_production
int
unreachable_production(cfg_t const* cfg) {
	if (!cfg)
		{ return (ERROR); }
	if (EMPTY_VECTOR(cfg->non_terminal))
		{ return (DONE); }

	bitset_t* nter_seen = new_bitset();
	vector_t* stack_prod = NULL;

	symbol_t* crt_symbol = AT_VECTOR(cfg->non_terminal, cfg->goal);
	ADD_BITSET(nter_seen, GET_INDEX(crt_symbol));

	stack_prod = stack_production_lhs(cfg, crt_symbol);
	while (!EMPTY_VECTOR(stack_prod)) {
		production_t* crt_prod = (production_t*)BACK_VECTOR(stack_prod);
		POP_BACK_VECTOR(stack_prod);

		list_rhs_t* list = crt_prod->rhs_element;
		while (list) {
			crt_symbol = list->symbol_rhs;
			if (IS_NON_TERMINAL(crt_symbol) && !IS_PRESENT(nter_seen,
												GET_INDEX(crt_symbol))) {
				ADD_BITSET(nter_seen, GET_INDEX(crt_symbol));
				move_vector(stack_prod, stack_production_lhs(cfg, crt_symbol));
			}
			list = list->next;
		}
	}
	
	int unreach = DONE;
	for (int i = SIZE_VECTOR(cfg->non_terminal) - 1; i >= 0; --i) {
		if (!IS_PRESENT(nter_seen, (size_t)i)) {
            symbol_t* crt_symbol = (symbol_t*)AT_VECTOR(cfg->non_terminal, i);
			unreach = ERROR;
            if (crt_symbol->name) {
			    warnf(0, "The nonterminal %s is unreachable.",
                                                        crt_symbol->name);
            }
            else {
                warnf(0, "A nonterminal created by a %s element is unreachable",
                        ((crt_symbol->spec_kind == OPT) ? "optional" : "list"));
            }
			erase_vector(cfg->non_terminal, i);
			shift_index(cfg, i);
		}
	} 

	del_bitset(nter_seen);
	del_vector(stack_prod);

	return (unreach);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x5dff
movq %rdi, %rbx
movq 0x8(%rdi), %rax
cmpq $0x0, 0x10(%rax)
je 0x5e0a
callq 0x243c
movq %rax, %r14
movq 0x8(%rbx), %rax
movq 0x28(%rbx), %rcx
movq (%rax), %rax
movq (%rax,%rcx,8), %r15
movq (%r15), %rcx
movl 0x4(%r14), %eax
cmpq %rax, %rcx
jae 0x5e12
movl $0x1, %eax
shlq %cl, %rax
movq 0x8(%r14), %rdx
shrq $0x6, %rcx
orq %rax, (%rdx,%rcx,8)
jmp 0x5e1d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x5fb9
xorl %r13d, %r13d
jmp 0x5fb9
movq %r14, %rdi
movq %rcx, %rsi
callq 0x2568
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5d35
movq %rax, %r15
movq 0x10(%rax), %rsi
testq %rsi, %rsi
je 0x5ee2
movq (%r15), %rax
movq -0x8(%rax,%rsi,8), %r12
decq %rsi
movq %r15, %rdi
callq 0x2c7d
movq 0x10(%r12), %r13
testq %r13, %r13
je 0x5ed9
movq 0x8(%r13), %r12
cmpl $0x27, 0x8(%r12)
jne 0x5ed0
testq %r14, %r14
je 0x5e8c
movq (%r12), %rax
movl 0x4(%r14), %ecx
cmpq %rcx, %rax
jae 0x5e8c
movq 0x8(%r14), %rcx
movq %rax, %rdx
shrq $0x6, %rdx
movq (%rcx,%rdx,8), %rcx
btq %rax, %rcx
jb 0x5ed0
movq (%r12), %rcx
movl 0x4(%r14), %eax
cmpq %rax, %rcx
jae 0x5eaf
movl $0x1, %eax
shlq %cl, %rax
movq 0x8(%r14), %rdx
shrq $0x6, %rcx
orq %rax, (%rdx,%rcx,8)
jmp 0x5eba
movq %r14, %rdi
movq %rcx, %rsi
callq 0x2568
movq %rbx, %rdi
movq %r12, %rsi
callq 0x5d35
movq %r15, %rdi
movq %rax, %rsi
callq 0x2e4a
movq (%r13), %r13
jmp 0x5e50
movq 0x10(%r15), %rsi
jmp 0x5e2f
movq 0x8(%rbx), %rax
movl 0x10(%rax), %eax
decl %eax
js 0x5fa6
movl %eax, %r12d
xorl %r13d, %r13d
testq %r14, %r14
je 0x5f1a
movl 0x4(%r14), %eax
cmpq %rax, %r12
jae 0x5f1a
movq 0x8(%r14), %rax
movq %r12, %rcx
shrq $0x6, %rcx
movq (%rax,%rcx,8), %rax
btq %r12, %rax
jb 0x5f93
movq 0x8(%rbx), %rax
movq (%rax), %rax
movq (%rax,%r12,8), %rax
movq 0x10(%rax), %rdx
testq %rdx, %rdx
je 0x5f39
xorl %edi, %edi
leaq 0x480c(%rip), %rsi      # 0xa743
jmp 0x5f58
cmpl $0x0, 0x38(%rax)
leaq 0x4860(%rip), %rdx      # 0xa7a4
leaq 0x4850(%rip), %rax      # 0xa79b
cmoveq %rax, %rdx
xorl %edi, %edi
leaq 0x480e(%rip), %rsi      # 0xa766
xorl %eax, %eax
callq 0x22b9
movq 0x8(%rbx), %rdi
movq %r12, %rsi
callq 0x2c7d
movq 0x8(%rbx), %rcx
movq 0x10(%rcx), %rax
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpq %r12, %rax
jbe 0x5f93
movq (%rcx), %rcx
movq %r12, %rdx
movq (%rcx,%rdx,8), %rsi
decq (%rsi)
incq %rdx
cmpq %rdx, %rax
jne 0x5f84
leaq -0x1(%r12), %rax
testq %r12, %r12
movq %rax, %r12
jg 0x5ef7
jmp 0x5fa9
xorl %r13d, %r13d
movq %r14, %rdi
callq 0x248a
movq %r15, %rdi
callq 0x2b9e
movl %r13d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq