// File: /workspace/github_c_makefile_star2_O2/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 0x58bc
movq %rdi, %rbx
movq 0x8(%rdi), %rax
cmpq $0x0, 0x10(%rax)
je 0x58c5
callq 0x22cc
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
pushq $0x1
popq %rdx
cmpq %rax, %rcx
jae 0x58cd
movq %rdx, %rax
shlq %cl, %rax
movq 0x8(%r14), %rdx
shrq $0x6, %rcx
orq %rax, (%rdx,%rcx,8)
jmp 0x58d8
pushq $-0x1
popq %r12
jmp 0x5a4a
xorl %r12d, %r12d
jmp 0x5a4a
movq %r14, %rdi
movq %rcx, %rsi
callq 0x23b9
movq %rbx, %rdi
movq %r15, %rsi
callq 0x57f1
movq %rax, %r15
movq 0x10(%r15), %rsi
testq %rsi, %rsi
je 0x597d
movq (%r15), %rax
movq -0x8(%rax,%rsi,8), %r13
decq %rsi
movq %r15, %rdi
callq 0x2a66
addq $0x10, %r13
movq (%r13), %r13
testq %r13, %r13
je 0x58e6
movq 0x8(%r13), %r12
cmpl $0x27, 0x8(%r12)
jne 0x590a
movq (%r12), %rcx
movl 0x4(%r14), %eax
cmpq %rax, %rcx
jae 0x5941
movq 0x8(%r14), %rdx
movq %rcx, %rsi
shrq $0x6, %rsi
movq (%rdx,%rsi,8), %rdx
btq %rcx, %rdx
jb 0x590a
cmpq %rax, %rcx
jae 0x595a
pushq $0x1
popq %rax
shlq %cl, %rax
movq 0x8(%r14), %rdx
shrq $0x6, %rcx
orq %rax, (%rdx,%rcx,8)
jmp 0x5965
movq %r14, %rdi
movq %rcx, %rsi
callq 0x23b9
movq %rbx, %rdi
movq %r12, %rsi
callq 0x57f1
movq %r15, %rdi
movq %rax, %rsi
callq 0x2c1b
jmp 0x590a
movq 0x8(%rbx), %rax
movl 0x10(%rax), %r13d
xorl %r12d, %r12d
decq %r13
movq %r13, %rcx
movq %rcx, %r13
testl %r13d, %r13d
js 0x5a3a
cmpl %r13d, 0x4(%r14)
jbe 0x59be
movq 0x8(%r14), %rcx
movl %r13d, %edx
shrl $0x3, %edx
andl $0xffffff8, %edx        # imm = 0xFFFFFF8
movq (%rcx,%rdx), %rdx
leaq -0x1(%r13), %rcx
btq %r13, %rdx
jb 0x598e
movq (%rax), %rax
movl %r13d, %r12d
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movq (%rax,%r12,8), %rax
movq 0x10(%rax), %rdx
testq %rdx, %rdx
je 0x59e3
xorl %edi, %edi
leaq 0x4d36(%rip), %rsi      # 0xa717
jmp 0x5a02
cmpl $0x0, 0x38(%rax)
leaq 0x4d8a(%rip), %rdx      # 0xa778
leaq 0x4d7a(%rip), %rax      # 0xa76f
cmoveq %rax, %rdx
xorl %edi, %edi
leaq 0x4d38(%rip), %rsi      # 0xa73a
xorl %eax, %eax
callq 0x3d00
movq 0x8(%rbx), %rdi
movq %r12, %rsi
callq 0x2a66
movq 0x8(%rbx), %rax
movq 0x10(%rax), %rcx
cmpq %rcx, %r12
jae 0x5a31
movq (%rax), %rdx
movq (%rdx,%r12,8), %rdx
decq (%rdx)
incq %r12
jmp 0x5a1d
pushq $-0x1
popq %r12
jmp 0x5988
movq %r14, %rdi
callq 0x2311
movq %r15, %rdi
callq 0x2986
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq