// File: /workspace/github_c_makefile_star2_O0/MaoKo[P]FGFX/fgfl/src/nfa.c
// Function: build_nfa
int
build_nfa(lexical_spec_t* spec) {
    if (!spec)
        { return (ERROR); }

    // Transform all regex to nfa
    for (size_t i = 0; i < SIZE_VECTOR(spec->entry_vect); ++i) {
        spec_entry_t* entry = (spec_entry_t*)AT_VECTOR(spec->entry_vect, i);
        if (entry->kind == T_KEYWORD || entry->fragment)
            { continue; }
        else if (transform_regex_nfa(entry) == ERROR)
            { return (ERROR); }
    }

    bool active_state = (spec->start_state != -1);
    if (active_state)
        { return (build_nfa_from_state(spec)); }
    else {
        bitset_t* set_frag = new_bitset();
        for (size_t i = 0; i < SIZE_VECTOR(spec->entry_vect); ++i) {
            spec_entry_t* entry = (spec_entry_t*)AT_VECTOR(spec->entry_vect, i);
            if (entry->kind != T_KEYWORD && entry->nfa_m)
                { ADD_BITSET(set_frag, GET_INDEX(entry->nfa_m)); }
        }
        nfa_automaton_t* nfa_m = new_nfa_automaton(NFA_MASTER, set_frag);
        spec->master = new_nfa_state(EDGE_AUTOMATA, nfa_m, NULL_NFA_STATE);
    }

    return (DONE);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x67ff
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6999
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpq 0x10(%rcx), %rax
jae 0x6872
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x42, 0x8(%rax)
je 0x6844
movq -0x20(%rbp), %rax
testb $0x1, 0x18(%rax)
je 0x6846
jmp 0x6864
movq -0x20(%rbp), %rdi
callq 0x69b0
cmpl $-0x1, %eax
jne 0x6860
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6999
jmp 0x6862
jmp 0x6864
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x6807
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x18(%rax)
setne %al
andb $0x1, %al
movb %al, -0x21(%rbp)
testb $0x1, -0x21(%rbp)
je 0x6899
movq -0x10(%rbp), %rdi
callq 0x6a40
movl %eax, -0x4(%rbp)
jmp 0x6999
callq 0x12b0
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpq 0x10(%rcx), %rax
jae 0x6962
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpl $0x42, 0x8(%rax)
je 0x694f
movq -0x40(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x694f
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movl 0x4(%rcx), %ecx
cmpq %rcx, %rax
jb 0x6919
movq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rsi
callq 0x1440
jmp 0x694f
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rcx
andq $0x3f, %rcx
movl $0x1, %edx
shlq %cl, %rdx
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x40(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq (%rcx), %rcx
shrq $0x6, %rcx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0x6951
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x68aa
movq -0x30(%rbp), %rsi
xorl %edi, %edi
movb $0x0, %al
callq 0x6bf0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rsi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0x6460
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)