// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, -0x30(%rbp)
testq %rdi, %rdi
je 0x5a5d
movq %rdi, %rbx
movq 0x8(%rdi), %rax
cmpq $0x0, 0x10(%rax)
setne %r12b
je 0x58b8
xorl %r13d, %r13d
movq (%rax), %rax
movq (%rax,%r13,8), %r15
movl $0x4, %r14d
cmpl $0x42, 0x8(%r15)
je 0x5895
cmpb $0x0, 0x18(%r15)
jne 0x5895
movq 0x20(%r15), %rdi
movq %rdi, -0x38(%rbp)
callq 0x5c5e
movq %rax, 0x28(%r15)
testq %rax, %rax
je 0x5867
movl (%r15), %ecx
movq 0x28(%rax), %rdx
movl %ecx, 0x8(%rdx)
cmpb $0x1, 0x19(%r15)
jne 0x587a
movq 0x28(%r15), %rcx
movq 0x28(%rcx), %rcx
movb $0x1, 0xc(%rcx)
xorl %r14d, %r14d
testq %rax, %rax
sete %r14b
movq -0x38(%rbp), %rdi
callq 0x7cad
movq $0x0, 0x20(%r15)
testb $0x3, %r14b
jne 0x58ae
incq %r13
movq 0x8(%rbx), %rax
cmpq 0x10(%rax), %r13
setb %r12b
jb 0x582c
jmp 0x58b8
testb $0x1, %r12b
jne 0x5a5d
cmpl $-0x1, 0x18(%rbx)
je 0x59c4
movq 0x10(%rbx), %rax
cmpq $0x0, 0x10(%rax)
je 0x5a55
xorl %ecx, %ecx
movq (%rax), %rax
movq %rcx, -0x38(%rbp)
movq (%rax,%rcx,8), %r13
callq 0x247c
movq %rax, %r15
movq 0x8(%rbx), %rax
cmpq $0x0, 0x10(%rax)
je 0x5981
xorl %r14d, %r14d
movq (%rax), %rax
movq (%rax,%r14,8), %r12
cmpl $0x42, 0x8(%r12)
je 0x5970
cmpq $0x0, 0x28(%r12)
je 0x5970
movq 0x38(%r12), %rdi
movl (%r13), %esi
callq 0x3cf7
cmpl $-0x1, %eax
je 0x5949
movq 0x28(%r12), %rax
movq (%rax), %rcx
movl 0x4(%r15), %eax
cmpq %rax, %rcx
jae 0x5965
movl $0x1, %eax
shlq %cl, %rax
movq 0x8(%r15), %rdx
shrq $0x6, %rcx
orq %rax, (%rdx,%rcx,8)
jmp 0x5970
cmpq $0x0, 0x38(%r12)
jne 0x5970
movslq 0x18(%rbx), %rax
cmpq %rax, (%r13)
je 0x5922
cmpb $0x1, 0x34(%r12)
je 0x5922
jmp 0x5970
movq %r15, %rdi
movq %rcx, %rsi
callq 0x25a8
incq %r14
movq 0x8(%rbx), %rax
cmpq 0x10(%rax), %r14
jb 0x58f8
movq $0x0, -0x30(%rbp)
xorl %edi, %edi
movq %r15, %rsi
xorl %eax, %eax
callq 0x5a70
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movq %rax, %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x562e
movq %rax, 0x18(%r13)
movq -0x38(%rbp), %rcx
incq %rcx
movq 0x10(%rbx), %rax
cmpq 0x10(%rax), %rcx
jb 0x58d3
jmp 0x5a5d
callq 0x247c
movq %rax, %r15
movq 0x8(%rbx), %rax
cmpq $0x0, 0x10(%rax)
je 0x5a2a
xorl %r14d, %r14d
movq (%rax), %rax
movq (%rax,%r14,8), %rax
cmpl $0x42, 0x8(%rax)
je 0x5a1d
movq 0x28(%rax), %rax
testq %rax, %rax
je 0x5a1d
movq (%rax), %rcx
movl 0x4(%r15), %eax
cmpq %rax, %rcx
jae 0x5a12
movl $0x1, %eax
shlq %cl, %rax
movq 0x8(%r15), %rdx
shrq $0x6, %rcx
orq %rax, (%rdx,%rcx,8)
jmp 0x5a1d
movq %r15, %rdi
movq %rcx, %rsi
callq 0x25a8
incq %r14
movq 0x8(%rbx), %rax
cmpq 0x10(%rax), %r14
jb 0x59da
movq $0x0, -0x30(%rbp)
xorl %edi, %edi
movq %r15, %rsi
xorl %eax, %eax
callq 0x5a70
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movq %rax, %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x562e
movq %rax, 0x20(%rbx)
jmp 0x5a5d
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq