// File: /workspace/github_c_makefile_star2_O0/MaoKo[P]FGFX/fgfp/src/cfg.c
// Function: enclosed_element
static int
enclosed_element(cfg_t* cfg, production_t* prod) {
	int kind = ((advance_token(cfg->lex) == T_LBRACK) ? OPT : LST);

	int greater_depth = (LHS(prod)->depth > 2);
	int empty_opt = ((peek_token(cfg->lex) == T_RBRACK)
								|| (peek_token(cfg->lex) == T_RBRACE));

	if (greater_depth || empty_opt) {
		int exit_st;
		if (empty_opt) {
			warnf(CURRENT_LINE(cfg->lex), "Empty optional elements '%s'.",
											(kind == OPT) ? "[]" : "{}");
			advance_token(cfg->lex);
			exit_st = DONE;
		}
		if (greater_depth) {
			errorf(CURRENT_LINE(cfg->lex),
								"A nesting depth must be less than 3.");
			exit_st = ERROR;
		}
		return (exit_st);
	}

	symbol_t* opt_nter = add_symbol_cfg(cfg, T_NON_TERMINAL, NULL);

	opt_nter->is_defined = true;
	opt_nter->spec_kind = kind;

	int crt_depth = LHS(prod)->depth;

	if (!crt_depth)
		{ opt_nter->special = LHS(prod); }
	else
		{ opt_nter->special = LHS(prod)->special; }
	opt_nter->depth = crt_depth + 1;	

	opt_nter->spec_nth = ++special_pos;
	add_symbol_rhs(prod, opt_nter);	

	production_t* empty_prod = new_production(opt_nter, cfg);
	ADD_BITSET(opt_nter->prod_lst, GET_INDEX(empty_prod));

	size_t base_index = SIZE_VECTOR(cfg->productions);
	special_pos = 0;
	if (cfg_rhs(cfg, opt_nter) == ERROR)
		{ return (ERROR); }
	else if ((kind == OPT) && (advance_token(cfg->lex) != T_RBRACK)) {
		errorf(CURRENT_LINE(cfg->lex),
				"A close bracket must follow the optional elements.");
		return (ERROR);
	}
	else if ((kind == LST) && (advance_token(cfg->lex) != T_RBRACE)) {
		errorf(CURRENT_LINE(cfg->lex),
				"A close brace must follow the list elements.");
		return (ERROR);
	}

	if (kind == LST && (add_recursive(cfg, opt_nter, base_index) == ERROR))
		{ return (ERROR); }

	special_pos = opt_nter->spec_nth;
	return (DONE);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2ca0
movq %rax, %rdx
movl $0x1, %eax
xorl %ecx, %ecx
cmpq $0x2a, %rdx
cmovel %ecx, %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
cmpq $0x2, 0x48(%rax)
seta %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x32e0
movl %eax, %ecx
movb $0x1, %al
cmpl $0x2b, %ecx
movb %al, -0x49(%rbp)
je 0x6198
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x32e0
cmpl $0x33, %eax
sete %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0x61af
cmpl $0x0, -0x24(%rbp)
je 0x622d
cmpl $0x0, -0x24(%rbp)
je 0x61fb
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq 0x28(%rax), %rdi
movl -0x1c(%rbp), %ecx
leaq 0x65af(%rip), %rdx      # 0xc77a
leaq 0x65a5(%rip), %rax      # 0xc777
cmpl $0x0, %ecx
cmoveq %rax, %rdx
leaq 0x6579(%rip), %rsi      # 0xc759
movb $0x0, %al
callq 0x43c0
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2ca0
movl $0x0, -0x28(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x6222
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq 0x28(%rax), %rdi
leaq 0x6569(%rip), %rsi      # 0xc77d
movb $0x0, %al
callq 0x4210
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x6427
movq -0x10(%rbp), %rdi
movl $0x27, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x4b70
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movb $0x1, 0xc(%rax)
movl -0x1c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x48(%rax), %rax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x627c
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x40(%rax)
jmp 0x6290
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x40(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x40(%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x48(%rax)
movq 0x19b00(%rip), %rcx     # 0x1fda8
addq $0x1, %rcx
movq %rcx, 0x19af5(%rip)     # 0x1fda8
movq -0x30(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x6990
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x68a0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq 0x30(%rcx), %rcx
movl 0x4(%rcx), %ecx
cmpq %rcx, %rax
jb 0x6306
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x40(%rbp), %rax
movq (%rax), %rsi
callq 0x1420
jmp 0x6338
movq -0x40(%rbp), %rax
movq (%rax), %rcx
andq $0x3f, %rcx
movl $0x1, %edx
shlq %cl, %rdx
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rcx), %rcx
shrq $0x6, %rcx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movq $0x0, 0x19a56(%rip) # 0x1fda8
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x5bc0
cmpl $-0x1, %eax
jne 0x6370
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6427
cmpl $0x0, -0x1c(%rbp)
jne 0x63ac
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2ca0
cmpq $0x2b, %rax
je 0x63ac
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq 0x28(%rax), %rdi
leaq 0x6406(%rip), %rsi      # 0xc7a2
movb $0x0, %al
callq 0x4210
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6427
cmpl $0x1, -0x1c(%rbp)
jne 0x63e8
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2ca0
cmpq $0x33, %rax
je 0x63e8
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq 0x28(%rax), %rdi
leaq 0x63fd(%rip), %rsi      # 0xc7d5
movb $0x0, %al
callq 0x4210
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6427
jmp 0x63ea
jmp 0x63ec
cmpl $0x1, -0x1c(%rbp)
jne 0x6411
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x6430
cmpl $-0x1, %eax
jne 0x6411
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6427
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, 0x19988(%rip)     # 0x1fda8
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq