// File: /workspace/github_c_makefile_star2_O2/MaoKo[P]FGFX/fgfp/src/gen_lr.c
// Function: gen_action_table
void
gen_action_table(int filde, cfg_t const* cfg,
							vector_t const* lr1_states, char const* header) {

	dprintf(filde, STATIC SP INT NL);
	gen_verbatim_file(filde, header);

	dprintf(filde, "_lr_action_table[%zu][" MACRO_TOKEN "] = " BEG_BLOCK NL,
			SIZE_VECTOR(lr1_states));

	for (size_t i = 0; i < SIZE_VECTOR(lr1_states); ++i) {
		lr1_state_t* state = (lr1_state_t*)AT_VECTOR(lr1_states, i);
		dprintf(filde, "/* %3zu */" TAB BEG_BLOCK, i);
		trans_list_t* action = state->shift_lst;
		while (action) {
			symbol_t* ter = (symbol_t*)AT_VECTOR(cfg->terminal,
													action->input ^ _SHIFT);
			dprintf(filde, "[" TOKEN_PREFIX SEP "%s]="
					SHIFT_STR "(%d)", ter->name, action->state);
			if (action->next)
				{ dprintf(filde, COMMA SP); }
			action = action->next;
		}
	
		if (state->reduces && state->shift_lst) 
			{ dprintf(filde, COMMA SP); }
		
		action = state->reduces;
		while (action) {
			symbol_t* ter = (symbol_t*)AT_VECTOR(cfg->terminal, action->input);
			dprintf(filde, "[" TOKEN_PREFIX SEP "%s]="
												REDUCE_STR "(", ter->name);
			gen_nproduction(filde, cfg, action->state ^ _REDUCE);		
			dprintf(filde, ")");
	
			if  (action->next)
				{ dprintf(filde, COMMA SP); }
			action = action->next;
		}

		if (state->accept && (state->reduces || state->shift_lst))
			{ dprintf(filde, COMMA SP); }

		if (state->accept)
			{ dprintf(filde, "[T_EOF]=" ACCEPT_STR COMMA); }
		dprintf(filde, END_BLOCK COMMA NL);
	}
	dprintf(filde, END_BLOCK SEMI NL NL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %r15
movl %edi, %ebx
leaq 0x2ad4(%rip), %rsi      # 0xa887
xorl %eax, %eax
callq 0x20f0
movl %ebx, %edi
movq %r14, %rsi
callq 0x3b37
movq 0x10(%r12), %rdx
leaq 0x2bc8(%rip), %rsi      # 0xa998
movl %ebx, %edi
xorl %eax, %eax
callq 0x20f0
leaq 0x2c4b(%rip), %r14      # 0xaa2b
leaq 0x2be6(%rip), %r13      # 0xa9cd
xorl %edx, %edx
movq %r12, -0x38(%rbp)
cmpq 0x10(%r12), %rdx
jae 0x7f67
movq (%r12), %rax
movq (%rax,%rdx,8), %r12
movl %ebx, %edi
leaq 0x2bb7(%rip), %rsi      # 0xa9c0
movq %rdx, -0x50(%rbp)
xorl %eax, %eax
callq 0x20f0
movq %r12, -0x30(%rbp)
addq $0x10, %r12
movq %r12, -0x40(%rbp)
movq (%r12), %r12
testq %r12, %r12
je 0x7e6e
movq 0x10(%r15), %rax
movq (%rax), %rax
movslq 0x8(%r12), %rcx
xorq $0x1000, %rcx           # imm = 0x1000
movq (%rax,%rcx,8), %rax
movq 0x10(%rax), %rdx
movl 0xc(%r12), %ecx
movl %ebx, %edi
movq %r13, %rsi
xorl %eax, %eax
callq 0x20f0
cmpq $0x0, (%r12)
je 0x7e20
movl %ebx, %edi
leaq 0x2ce1(%rip), %rsi      # 0xab46
xorl %eax, %eax
callq 0x20f0
jmp 0x7e20
movq -0x30(%rbp), %rax
leaq 0x20(%rax), %r12
cmpq $0x0, 0x20(%rax)
movq %r12, -0x48(%rbp)
je 0x7e8f
movq -0x40(%rbp), %rax
cmpq $0x0, (%rax)
movq -0x48(%rbp), %r12
jne 0x7ee5
movq (%r12), %r12
testq %r12, %r12
je 0x7ef7
movq 0x10(%r15), %rax
movq (%rax), %rax
movslq 0x8(%r12), %rcx
movq (%rax,%rcx,8), %rax
movq 0x10(%rax), %rdx
movl %ebx, %edi
leaq 0x2b29(%rip), %rsi      # 0xa9de
xorl %eax, %eax
callq 0x20f0
movslq 0xc(%r12), %rdx
xorq $0x4000, %rdx           # imm = 0x4000
movl %ebx, %edi
movq %r15, %rsi
callq 0x82e2
movl %ebx, %edi
movq %r14, %rsi
xorl %eax, %eax
callq 0x20f0
cmpq $0x0, (%r12)
je 0x7e8f
movl %ebx, %edi
leaq 0x2c58(%rip), %rsi      # 0xab46
xorl %eax, %eax
callq 0x20f0
jmp 0x7e8f
movq -0x30(%rbp), %rax
movb 0x29(%rax), %al
cmpb $0x1, %al
jne 0x7f33
movq -0x48(%rbp), %rcx
cmpq $0x0, (%rcx)
movq -0x38(%rbp), %r12
jne 0x7f1a
movq -0x40(%rbp), %rcx
cmpq $0x0, (%rcx)
je 0x7f37
movl %ebx, %edi
leaq 0x2c23(%rip), %rsi      # 0xab46
xorl %eax, %eax
callq 0x20f0
movq -0x30(%rbp), %rax
movb 0x29(%rax), %al
jmp 0x7f37
movq -0x38(%rbp), %r12
testb $0x1, %al
je 0x7f4b
movl %ebx, %edi
leaq 0x2aa9(%rip), %rsi      # 0xa9ed
xorl %eax, %eax
callq 0x20f0
movl %ebx, %edi
leaq 0x2bf8(%rip), %rsi      # 0xab4c
xorl %eax, %eax
callq 0x20f0
movq -0x50(%rbp), %rdx
incq %rdx
jmp 0x7ded
leaq 0x2956(%rip), %rsi      # 0xa8c4
movl %ebx, %edi
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x20f0