// File: /workspace/github_c_makefile_star2_O2/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 $-0x1
popq %rax
testq %rdi, %rdi
je 0x5561
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
xorl %r14d, %r14d
movq 0x8(%rbx), %rax
cmpq 0x10(%rax), %r14
jae 0x53f9
movq (%rax), %rax
movq (%rax,%r14,8), %r13
cmpl $0x42, 0x8(%r13)
je 0x53f4
cmpb $0x0, 0x18(%r13)
jne 0x53f4
movq 0x20(%r13), %r15
movq %r15, %rdi
callq 0x57b2
movq %rax, %r12
movq %rax, 0x28(%r13)
testq %rax, %rax
je 0x53cb
movl (%r13), %eax
movq 0x28(%r12), %rcx
movl %eax, 0x8(%rcx)
cmpb $0x1, 0x19(%r13)
jne 0x53de
movq 0x28(%r13), %rax
movq 0x28(%rax), %rax
movb $0x1, 0xc(%rax)
movq %r15, %rdi
callq 0x751f
andq $0x0, 0x20(%r13)
testq %r12, %r12
je 0x5562
incq %r14
jmp 0x5388
cmpl $-0x1, 0x18(%rbx)
je 0x54d3
xorl %ecx, %ecx
movq 0x10(%rbx), %rax
cmpq 0x10(%rax), %rcx
jae 0x5551
movq (%rax), %rax
movq %rcx, -0x30(%rbp)
movq (%rax,%rcx,8), %r15
callq 0x230c
movq %rax, %r12
xorl %r13d, %r13d
movq 0x8(%rbx), %rax
cmpq 0x10(%rax), %r13
jae 0x54a8
movq (%rax), %rax
movq (%rax,%r13,8), %r14
cmpl $0x42, 0x8(%r14)
je 0x54a3
cmpq $0x0, 0x28(%r14)
je 0x54a3
movq 0x38(%r14), %rdi
movl (%r15), %esi
callq 0x38c4
cmpl $-0x1, %eax
je 0x547f
movq 0x28(%r14), %rax
movq (%rax), %rcx
movl 0x4(%r12), %eax
cmpq %rax, %rcx
jae 0x5498
pushq $0x1
popq %rax
shlq %cl, %rax
movq 0x8(%r12), %rdx
shrq $0x6, %rcx
orq %rax, (%rdx,%rcx,8)
jmp 0x54a3
cmpq $0x0, 0x38(%r14)
jne 0x54a3
movslq 0x18(%rbx), %rax
cmpq %rax, (%r15)
je 0x5459
cmpb $0x1, 0x34(%r14)
je 0x5459
jmp 0x54a3
movq %r12, %rdi
movq %rcx, %rsi
callq 0x23f9
incq %r13
jmp 0x5429
xorl %edi, %edi
movq %r12, %rsi
xorl %eax, %eax
callq 0x5567
pushq $-0x1
popq %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x519a
movq %rax, 0x18(%r15)
movq -0x30(%rbp), %rcx
incq %rcx
jmp 0x5405
xorl %r14d, %r14d
callq 0x230c
movq %rax, %r15
pushq $0x1
popq %r12
movq 0x8(%rbx), %rax
cmpq 0x10(%rax), %r14
jae 0x5532
movq (%rax), %rax
movq (%rax,%r14,8), %rax
cmpl $0x42, 0x8(%rax)
je 0x552d
movq 0x28(%rax), %rax
testq %rax, %rax
je 0x552d
movq (%rax), %rcx
movl 0x4(%r15), %eax
cmpq %rax, %rcx
jae 0x5522
movq %r12, %rax
shlq %cl, %rax
movq 0x8(%r15), %rdx
shrq $0x6, %rcx
orq %rax, (%rdx,%rcx,8)
jmp 0x552d
movq %r15, %rdi
movq %rcx, %rsi
callq 0x23f9
incq %r14
jmp 0x54e2
xorl %edi, %edi
movq %r15, %rsi
xorl %eax, %eax
callq 0x5567
pushq $-0x1
popq %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x519a
movq %rax, 0x20(%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $-0x1
popq %rax
jmp 0x5553