// File: /workspace/github_c_makefile_star2_O3/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 0x5c69
movq %rdi, %rbx
movq 0x8(%rdi), %rax
cmpq $0x0, 0x10(%rax)
je 0x5c74
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 0x5c7c
movl $0x1, %eax
shlq %cl, %rax
movq 0x8(%r14), %rdx
shrq $0x6, %rcx
orq %rax, (%rdx,%rcx,8)
jmp 0x5c87
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x5e0b
xorl %r13d, %r13d
jmp 0x5e0b
movq %r14, %rdi
movq %rcx, %rsi
callq 0x2570
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5b9f
movq %rax, %r15
movq 0x10(%rax), %rsi
testq %rsi, %rsi
je 0x5d38
movq (%r15), %rax
movq -0x8(%rax,%rsi,8), %r12
decq %rsi
movq %r15, %rdi
callq 0x2c71
movq 0x10(%r12), %r13
testq %r13, %r13
je 0x5d2f
movq 0x8(%r13), %r12
cmpl $0x27, 0x8(%r12)
jne 0x5d29
movq (%r12), %rcx
movl 0x4(%r14), %eax
cmpq %rax, %rcx
jae 0x5ced
movq 0x8(%r14), %rdx
movq %rcx, %rsi
shrq $0x6, %rsi
movq (%rdx,%rsi,8), %rdx
btq %rcx, %rdx
jb 0x5d29
cmpq %rax, %rcx
jae 0x5d08
movl $0x1, %eax
shlq %cl, %rax
movq 0x8(%r14), %rdx
shrq $0x6, %rcx
orq %rax, (%rdx,%rcx,8)
jmp 0x5d13
movq %r14, %rdi
movq %rcx, %rsi
callq 0x2570
movq %rbx, %rdi
movq %r12, %rsi
callq 0x5b9f
movq %r15, %rdi
movq %rax, %rsi
callq 0x2e4a
movq (%r13), %r13
jmp 0x5cba
movq 0x10(%r15), %rsi
jmp 0x5c99
movq 0x8(%rbx), %rax
movl 0x10(%rax), %ecx
decl %ecx
js 0x5df8
movl %ecx, %r12d
xorl %r13d, %r13d
testq %r14, %r14
je 0x5d70
movl 0x4(%r14), %ecx
cmpq %rcx, %r12
jae 0x5d70
movq 0x8(%r14), %rcx
movq %r12, %rdx
shrq $0x6, %rdx
movq (%rcx,%rdx,8), %rcx
btq %r12, %rcx
jb 0x5de5
movq (%rax), %rax
movq (%rax,%r12,8), %rax
movq 0x10(%rax), %rdx
testq %rdx, %rdx
je 0x5d8b
xorl %edi, %edi
leaq 0x49a7(%rip), %rsi      # 0xa730
jmp 0x5daa
cmpl $0x0, 0x38(%rax)
leaq 0x49fb(%rip), %rdx      # 0xa791
leaq 0x49eb(%rip), %rax      # 0xa788
cmoveq %rax, %rdx
xorl %edi, %edi
leaq 0x49a9(%rip), %rsi      # 0xa753
xorl %eax, %eax
callq 0x22b9
movq 0x8(%rbx), %rdi
movq %r12, %rsi
callq 0x2c71
movq 0x8(%rbx), %rax
movq 0x10(%rax), %rcx
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpq %r12, %rcx
jbe 0x5de5
movq (%rax), %rdx
movq %r12, %rsi
movq (%rdx,%rsi,8), %rdi
decq (%rdi)
incq %rsi
cmpq %rsi, %rcx
jne 0x5dd6
leaq -0x1(%r12), %rcx
testq %r12, %r12
movq %rcx, %r12
jg 0x5d4d
jmp 0x5dfb
xorl %r13d, %r13d
movq %r14, %rdi
callq 0x2486
movq %r15, %rdi
callq 0x2b8e
movl %r13d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq