// File: /workspace/github_c_makefile_star2_O0/MaoKo[P]FGFX/fgfl/src/lexical_spec.c
// Function: spec_action_pair
int
spec_action_pair(lexical_spec_t* spec, spec_entry_t* entry, size_t* count_pos) {
    int kind_action = advance_token(spec->lex);
    if ((kind_action != T_BEGIN)
                        && (kind_action != T_PUSH) && (kind_action != T_POP)) {
        errorf(CURRENT_LINE(spec->lex),
                        "Missing a $BEGIN, $PUSH or $POP directive.");
        return (ERROR);
    }
    else if ((kind_action == T_POP)) {
        if (!in_first(spec->lex, T_COMMA, T_RPAREN, -1)) {
            errorf(CURRENT_LINE(spec->lex), 
                    "A comma or a close paren must follow a $POP directive.");
            return (ERROR);
        }
    }
    else if (advance_token(spec->lex) != T_LPAREN) {
        errorf(CURRENT_LINE(spec->lex),
                        "Missing an open paren after the %s directive.",
                                            KIND_IN2_ACTION(kind_action));
        return (ERROR);
    }

    int kind_atom = peek_token(spec->lex);
    bool valid_kind = !((kind_atom != T_TERMINAL)
                        && (kind_atom != T_STAR) && (kind_atom != T_STAY));

    if (!valid_kind && (kind_action != T_POP)) {
        errorf(CURRENT_LINE(spec->lex),
                "Either a token name, a * or $STAY must follow the %s.",
                                            KIND_IN2_ACTION(kind_action));
        return (ERROR);
    }

    size_t seen_all = 0;

    size_t local_count = 0;
    size_t count_stay = 0;

    while (valid_kind || (kind_action == T_POP)) {
        if (kind_action != T_POP)
            { advance_token(spec->lex); }

        if (kind_atom == T_STAR)
            { ++seen_all; }
        else if (kind_atom == T_STAY)
            { ++count_stay; }

        if (seen_all) {
            if (seen_all > 1) {
                errorf(CURRENT_LINE(spec->lex),
                                        "A '*' can't follow another '*'.");
                return (ERROR);
            }
            else if (!local_count) {
                errorf(CURRENT_LINE(spec->lex),
                            "There must be a state name before the * token.");
                return (ERROR);
            }
            else if (kind_atom != T_STAR) {
                errorf(CURRENT_LINE(spec->lex),
                        "A state name can't follow the * token.");
                return (ERROR);
            }
        }

        trans_list_t* equiv_state =
                                trans_list_at(entry->state_lst, (*count_pos));

        if ((!equiv_state) && (*count_pos) && (!entry->all_state)) {
            errorf(CURRENT_LINE(spec->lex),
                        "More action move than the number of state.");
            return (ERROR);
        }
        else if ((kind_atom == T_TERMINAL) || (kind_action == T_POP)) {
            spec_entry_t* crt_state = NULL;
            size_t index_state = 0;

            if (kind_action != T_POP) {
                crt_state = add_entry_lexeme(spec, T_STATE);
                if (!crt_state)
                    { return (ERROR); }
                else if (!entry->fragment)
                    { crt_state->is_reach = true; }
                index_state = GET_INDEX(crt_state);
            }

            bool useless_move = false;
            if (equiv_state) {
                equiv_state->state = BUILD_ACTION(kind_action, index_state);
                if ((size_t)equiv_state->input == index_state)
                    { useless_move = true; }
            }
            else {
                entry->default_action =
                                    BUILD_ACTION(kind_action, index_state);
            }

            if (useless_move && (kind_action == T_BEGIN)) {
                warnf(0, "Useless to do a $BEGIN on state %s when"
                            " this state is already active.", crt_state->name);
            }
        }
        else if (seen_all) {
            if (entry->all_state) {
                errorf(CURRENT_LINE(spec->lex),
                    "You can't use star in token which is valid in all state.");
                return (ERROR);
            }

            int prev_index = (trans_list_at(entry->state_lst,
                                                    (*count_pos) - 1))->state;
            while (equiv_state) {
                equiv_state->state = prev_index;
                equiv_state = equiv_state->next;
            }
        }

        ++(*count_pos);
        ++(local_count);

        if (kind_action == T_POP)
            { return (DONE); }
        else if (peek_token(spec->lex) == T_COMMA)
            { advance_token(spec->lex); }

        kind_atom = peek_token(spec->lex);
        valid_kind = !((kind_atom != T_TERMINAL)
                        && (kind_atom != T_STAR) && (kind_atom != T_STAY));
    }

    if (advance_token(spec->lex) != T_RPAREN) {
        errorf(CURRENT_LINE(spec->lex),
                        "Missing a close paren after the %s directive.",
                                            KIND_IN2_ACTION(kind_action));
        return (ERROR);
    }
    else if (entry->all_state && (*count_pos) > 1) {
        errorf(CURRENT_LINE(spec->lex),
            "A token in all state can't have more than one outgoing begin.");
        return (ERROR);
    }
    else if ((kind_action == T_BEGIN)
            && (count_stay == ((seen_all) ? local_count - 1 : local_count))) {

        warnf(CURRENT_LINE(spec->lex), "The $BEGIN directive is useless"
                " because it goes always to the $STAY directive.");
    }
    return (DONE);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2cc0
movl %eax, -0x24(%rbp)
cmpl $0x47, -0x24(%rbp)
je 0x5ccd
cmpl $0x48, -0x24(%rbp)
je 0x5ccd
cmpl $0x49, -0x24(%rbp)
je 0x5ccd
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq 0x28(%rax), %rdi
leaq 0x8ae1(%rip), %rsi      # 0xe79b
movb $0x0, %al
callq 0x4230
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6349
cmpl $0x49, -0x24(%rbp)
jne 0x5d1b
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0x31, %esi
movl $0x35, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movb $0x0, %al
callq 0x3350
testb $0x1, %al
jne 0x5d19
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq 0x28(%rax), %rdi
leaq 0x8ac0(%rip), %rsi      # 0xe7c6
movb $0x0, %al
callq 0x4230
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6349
jmp 0x5d8f
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2cc0
cmpq $0x34, %rax
je 0x5d8d
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq 0x28(%rax), %rax
movq %rax, -0x70(%rbp)
cmpl $0x47, -0x24(%rbp)
jne 0x5d4f
leaq 0x831c(%rip), %rax      # 0xe065
movq %rax, -0x78(%rbp)
jmp 0x5d6b
movl -0x24(%rbp), %edx
leaq 0x8319(%rip), %rax      # 0xe072
leaq 0x830c(%rip), %rcx      # 0xe06c
cmpl $0x48, %edx
cmoveq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
movq -0x78(%rbp), %rdx
leaq 0x8a83(%rip), %rsi      # 0xe7fd
movb $0x0, %al
callq 0x4230
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6349
jmp 0x5d8f
jmp 0x5d91
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x3300
movl %eax, -0x28(%rbp)
xorl %eax, %eax
cmpl $0x2d, -0x28(%rbp)
movb %al, -0x79(%rbp)
je 0x5dc0
xorl %eax, %eax
cmpl $0x1, -0x28(%rbp)
movb %al, -0x79(%rbp)
je 0x5dc0
cmpl $0x46, -0x28(%rbp)
setne %al
movb %al, -0x79(%rbp)
movb -0x79(%rbp), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0x29(%rbp)
testb $0x1, -0x29(%rbp)
jne 0x5e45
cmpl $0x49, -0x24(%rbp)
je 0x5e45
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq 0x28(%rax), %rax
movq %rax, -0x88(%rbp)
cmpl $0x47, -0x24(%rbp)
jne 0x5dfe
leaq 0x8270(%rip), %rax      # 0xe065
movq %rax, -0x90(%rbp)
jmp 0x5e1d
movl -0x24(%rbp), %edx
leaq 0x826a(%rip), %rax      # 0xe072
leaq 0x825d(%rip), %rcx      # 0xe06c
cmpl $0x48, %edx
cmoveq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rdi
movq -0x90(%rbp), %rdx
leaq 0x89f9(%rip), %rsi      # 0xe82b
movb $0x0, %al
callq 0x4230
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6349
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movb $0x1, %al
testb $0x1, -0x29(%rbp)
movb %al, -0x91(%rbp)
jne 0x5e78
cmpl $0x49, -0x24(%rbp)
sete %al
movb %al, -0x91(%rbp)
movb -0x91(%rbp), %al
testb $0x1, %al
jne 0x5e87
jmp 0x6227
cmpl $0x49, -0x24(%rbp)
je 0x5e99
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2cc0
cmpl $0x1, -0x28(%rbp)
jne 0x5ead
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x5ec1
cmpl $0x46, -0x28(%rbp)
jne 0x5ebf
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x5ec1
cmpq $0x0, -0x38(%rbp)
je 0x5f55
cmpq $0x1, -0x38(%rbp)
jbe 0x5ef8
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq 0x28(%rax), %rdi
leaq 0x897c(%rip), %rsi      # 0xe861
movb $0x0, %al
callq 0x4230
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6349
cmpq $0x0, -0x40(%rbp)
jne 0x5f24
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq 0x28(%rax), %rdi
leaq 0x8970(%rip), %rsi      # 0xe881
movb $0x0, %al
callq 0x4230
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6349
cmpl $0x1, -0x28(%rbp)
je 0x5f4f
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq 0x28(%rax), %rdi
leaq 0x8974(%rip), %rsi      # 0xe8b0
movb $0x0, %al
callq 0x4230
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6349
jmp 0x5f51
jmp 0x5f53
jmp 0x5f55
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
callq 0x3c40
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x5fad
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
je 0x5fad
movq -0x18(%rbp), %rax
testb $0x1, 0x34(%rax)
jne 0x5fad
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq 0x28(%rax), %rdi
leaq 0x893d(%rip), %rsi      # 0xe8d7
movb $0x0, %al
callq 0x4230
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6349
cmpl $0x2d, -0x28(%rbp)
je 0x5fbd
cmpl $0x49, -0x24(%rbp)
jne 0x611a
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
cmpl $0x49, -0x24(%rbp)
je 0x6017
movq -0x10(%rbp), %rdi
movl $0x43, %esi
callq 0x5600
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x5ff8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6349
movq -0x18(%rbp), %rax
testb $0x1, 0x18(%rax)
jne 0x600a
movq -0x58(%rbp), %rax
movb $0x1, 0x21(%rax)
jmp 0x600c
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movb $0x0, -0x61(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x6094
cmpl $0x47, -0x24(%rbp)
jne 0x603b
movq -0x60(%rbp), %rax
orq $0x1000, %rax           # imm = 0x1000
movq %rax, -0xa0(%rbp)
jmp 0x6070
cmpl $0x48, -0x24(%rbp)
jne 0x6054
movq -0x60(%rbp), %rax
orq $0x2000, %rax           # imm = 0x2000
movq %rax, -0xa8(%rbp)
jmp 0x6062
movl $0x4000, %eax           # imm = 0x4000
movq %rax, -0xa8(%rbp)
jmp 0x6062
movq -0xa8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movl %eax, %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x50(%rbp), %rax
movslq 0x8(%rax), %rax
cmpq -0x60(%rbp), %rax
jne 0x6092
movb $0x1, -0x61(%rbp)
jmp 0x60f2
cmpl $0x47, -0x24(%rbp)
jne 0x60ad
movq -0x60(%rbp), %rax
orq $0x1000, %rax           # imm = 0x1000
movq %rax, -0xb0(%rbp)
jmp 0x60e2
cmpl $0x48, -0x24(%rbp)
jne 0x60c6
movq -0x60(%rbp), %rax
orq $0x2000, %rax           # imm = 0x2000
movq %rax, -0xb8(%rbp)
jmp 0x60d4
movl $0x4000, %eax           # imm = 0x4000
movq %rax, -0xb8(%rbp)
jmp 0x60d4
movq -0xb8(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x30(%rax)
testb $0x1, -0x61(%rbp)
je 0x6118
cmpl $0x47, -0x24(%rbp)
jne 0x6118
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rdx
xorl %eax, %eax
movl %eax, %edi
leaq 0x87f1(%rip), %rsi      # 0xe902
movb $0x0, %al
callq 0x43e0
jmp 0x6190
cmpq $0x0, -0x38(%rbp)
je 0x618e
movq -0x18(%rbp), %rax
testb $0x1, 0x34(%rax)
je 0x6150
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq 0x28(%rax), %rdi
leaq 0x880b(%rip), %rsi      # 0xe948
movb $0x0, %al
callq 0x4230
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6349
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
subq $0x1, %rsi
callq 0x3c40
movl 0xc(%rax), %eax
movl %eax, -0x68(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x618c
movl -0x68(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x616e
jmp 0x618e
jmp 0x6190
jmp 0x6192
movq -0x20(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
cmpl $0x49, -0x24(%rbp)
jne 0x61be
movl $0x0, -0x4(%rbp)
jmp 0x6349
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x3300
cmpl $0x31, %eax
jne 0x61db
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2cc0
jmp 0x61dd
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x3300
movl %eax, -0x28(%rbp)
xorl %eax, %eax
cmpl $0x2d, -0x28(%rbp)
movb %al, -0xb9(%rbp)
je 0x6215
xorl %eax, %eax
cmpl $0x1, -0x28(%rbp)
movb %al, -0xb9(%rbp)
je 0x6215
cmpl $0x46, -0x28(%rbp)
setne %al
movb %al, -0xb9(%rbp)
movb -0xb9(%rbp), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0x29(%rbp)
jmp 0x5e5d
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2cc0
cmpq $0x35, %rax
je 0x62a8
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq 0x28(%rax), %rax
movq %rax, -0xc8(%rbp)
cmpl $0x47, -0x24(%rbp)
jne 0x6261
leaq 0x7e0d(%rip), %rax      # 0xe065
movq %rax, -0xd0(%rbp)
jmp 0x6280
movl -0x24(%rbp), %edx
leaq 0x7e07(%rip), %rax      # 0xe072
leaq 0x7dfa(%rip), %rcx      # 0xe06c
cmpl $0x48, %edx
cmoveq %rcx, %rax
movq %rax, -0xd0(%rbp)
movq -0xc8(%rbp), %rdi
movq -0xd0(%rbp), %rdx
leaq 0x86ec(%rip), %rsi      # 0xe981
movb $0x0, %al
callq 0x4230
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6349
movq -0x18(%rbp), %rax
testb $0x1, 0x34(%rax)
je 0x62de
movq -0x20(%rbp), %rax
cmpq $0x1, (%rax)
jbe 0x62de
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq 0x28(%rax), %rdi
leaq 0x86e1(%rip), %rsi      # 0xe9af
movb $0x0, %al
callq 0x4230
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6349
cmpl $0x47, -0x24(%rbp)
jne 0x633e
movq -0x48(%rbp), %rax
movq %rax, -0xd8(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x6307
movq -0x40(%rbp), %rax
subq $0x1, %rax
movq %rax, -0xe0(%rbp)
jmp 0x6312
movq -0x40(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xd8(%rbp), %rax
movq -0xe0(%rbp), %rcx
cmpq %rcx, %rax
jne 0x633e
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq 0x28(%rax), %rdi
leaq 0x86b6(%rip), %rsi      # 0xe9ed
movb $0x0, %al
callq 0x43e0
jmp 0x6340
jmp 0x6342
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)