// File: /workspace/github_c_makefile_star2_O0/MaoKo[P]FGFX/fgfp/src/cfg.c
// Function: add_symbol_cfg
static symbol_t*
add_symbol_cfg(cfg_t* cfg, int kind, char const* crt_lexeme) {
	vector_t* dest = (kind == T_NON_TERMINAL)
						? cfg->non_terminal : cfg->terminal;
	if (crt_lexeme) {
		int index = get_index_vector(dest, crt_lexeme, &cmp_symbol_name);
		if (index != -1)
			{ return ((symbol_t*)AT_VECTOR(dest, index)); }
	}

	symbol_t* symbol = NEW(symbol_t, 1);
	if (!symbol)
		{ return (NULL); }
	memset(symbol, 0, sizeof(*symbol));

	symbol->kind = kind;
	if (crt_lexeme)
		{ symbol->name = strdup(crt_lexeme); }

	int fail = 0;
	if (crt_lexeme && !symbol->name)
		{ fail = 1; }
	
	if (kind == T_LITERAL) 
		{ symbol->terminal_alias = -1; }
	else {
		symbol->is_used = true;
		if (kind == T_TERMINAL)
			{ symbol->is_defined = true; }
		else {
			symbol->prod_lst = new_bitset();
			if (!symbol->prod_lst)
				{ fail = 1; }
		}
	}

	if (fail) {
		free_symbol(symbol);
		return (NULL);
	}

/*
	if (kind == T_NON_TERMINAL)
		{ *strchr(sym->name, '>') = EOS; }

	//vector_t** dst = (kind == T_NON_TERMINAL)
	//? cfg->non_terminal : cfg->terminal;
	//size_t hs = hash_str(sym->name) % HASH_SIZE;
	//else
	//	{ FREE(sym); }
*/

	symbol->index = SIZE_VECTOR(dest);
	PUSH_BACK_VECTOR(dest, symbol);

	return (symbol);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
cmpl $0x27, -0x14(%rbp)
jne 0x4b97
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x4ba3
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x4be9
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq 0x6ff(%rip), %rdx       # 0x52c0
callq 0x22e0
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x2c(%rbp)
je 0x4be7
movq -0x28(%rbp), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x8(%rbp)
jmp 0x4cf6
jmp 0x4be9
movl $0x58, %edi
callq 0x38b0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x4c0b
movq $0x0, -0x8(%rbp)
jmp 0x4cf6
movq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x58, %edx
callq 0x10b0
movl -0x14(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
cmpq $0x0, -0x20(%rbp)
je 0x4c40
movq -0x20(%rbp), %rdi
callq 0x1170
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x0, -0x3c(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x4c60
movq -0x38(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x4c60
movl $0x1, -0x3c(%rbp)
cmpl $0x28, -0x14(%rbp)
jne 0x4c73
movq -0x38(%rbp), %rax
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
jmp 0x4cb1
movq -0x38(%rbp), %rax
movb $0x1, 0xd(%rax)
cmpl $0x2d, -0x14(%rbp)
jne 0x4c8b
movq -0x38(%rbp), %rax
movb $0x1, 0xc(%rax)
jmp 0x4caf
callq 0x1290
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x4cad
movl $0x1, -0x3c(%rbp)
jmp 0x4caf
jmp 0x4cb1
cmpl $0x0, -0x3c(%rbp)
je 0x4cca
movq -0x38(%rbp), %rdi
callq 0x48e0
movq $0x0, -0x8(%rbp)
jmp 0x4cf6
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x38(%rbp), %rdx
callq 0x2070
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq