// File: /workspace/github_c_makefile_star2_O1/MaoKo[P]FGFX/fgfl/src/dfa_minimization.c
// Function: minimizing_dfa
void
minimizing_dfa(lexical_spec_t* spec) {
    if (!spec)
        { return; }
    vector_t* groups = init_groups(spec);

    int next_group_id = SIZE_VECTOR(groups);
    bool change;

    do {
        change = false;

        bitset_t* new_group = NULL_BITSET;
        ++next_group_id;

        for (int i = SIZE_VECTOR(groups) - 1; i >= 0; --i) {
            bitset_t* crt_group = (bitset_t*)AT_VECTOR(groups, (size_t)i);
            if (count_elt_bitset(crt_group) == 1)
                { continue; }

            int first = IT_NEXT(crt_group);
            int next;

            while ((next = IT_NEXT(crt_group)) != IT_NULL) {
                dfa_state_t* first_st = DFA_STATE_AT(spec, first);
                dfa_state_t* next_st = DFA_STATE_AT(spec, next);

                for (size_t j = MIN_ASCII; j < MAX_ASCII; ++j) {
                    int first_i = input_to_state(first_st->trans, j);
                    int next_i = input_to_state(next_st->trans, j);

                    if (first_i != next_i) {
                        dfa_state_t* first_out = DFA_STATE_AT(spec, first_i);
                        dfa_state_t* next_out = DFA_STATE_AT(spec, next_i);

                        if ((!first_out || !next_out)
                                || (first_out->group != next_out->group)) {
                            next_st->group = next_group_id;

                            if (!new_group) {
                                new_group = new_bitset();
                                change = true;
                            }

                            ADD_BITSET(new_group, (size_t)next);
                            OFF_BITSET(crt_group, (size_t)next);

                            break;
                        }
                    }
                }
            }
            IT_RESET(crt_group);
        }
        if (new_group)
            { PUSH_BACK_VECTOR(groups, new_group); }
    } while (change);
    merge_dfa_state(spec, groups);
}

// Assembly:
testq %rdi, %rdi
je 0x7946
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, -0x30(%rbp)
callq 0x2b3c
movq %rax, %r13
callq 0x247c
movq -0x30(%rbp), %rsi
movq %rax, %r15
movq 0x28(%rsi), %rax
cmpq $0x2, 0x10(%rax)
jb 0x74d5
movl $0x1, %ebx
movq (%rax), %rax
movq (%rax,%rbx,8), %rax
cmpb $0x0, 0x22(%rax)
jne 0x74c8
movq (%rax), %rcx
movl 0x4(%r15), %eax
cmpq %rax, %rcx
jae 0x74b9
movl $0x1, %eax
shlq %cl, %rax
movq 0x8(%r15), %rdx
shrq $0x6, %rcx
orq %rax, (%rdx,%rcx,8)
jmp 0x74c8
movq %r15, %rdi
movq %rcx, %rsi
callq 0x25a8
movq -0x30(%rbp), %rsi
incq %rbx
movq 0x28(%rsi), %rax
cmpq 0x10(%rax), %rbx
jb 0x748a
movq %r15, %rdi
callq 0x2725
testb %al, %al
jne 0x74f0
movq 0x10(%r13), %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x2c31
callq 0x247c
movq %rax, %rdi
movq -0x30(%rbp), %rsi
movq 0x28(%rsi), %rax
cmpq $0x2, 0x10(%rax)
movq %r13, -0x40(%rbp)
jb 0x7635
movl $0x1, %ebx
movq %rdi, -0x38(%rbp)
movq (%rax), %rax
movq (%rax,%rbx,8), %r14
cmpb $0x1, 0x22(%r14)
jne 0x7624
testq %rdi, %rdi
je 0x7553
movq (%r14), %rax
movl 0x4(%rdi), %ecx
cmpq %rcx, %rax
jae 0x7553
movq 0x8(%rdi), %rcx
movq %rax, %rdx
shrq $0x6, %rdx
movq (%rcx,%rdx,8), %rcx
btq %rax, %rcx
jb 0x7624
callq 0x247c
movq -0x30(%rbp), %rcx
movq %rax, %r12
movq 0x28(%rcx), %rax
movq %rbx, %r13
cmpq 0x10(%rax), %rbx
jae 0x7609
movq (%rax), %rax
movq (%rax,%r13,8), %r15
movl 0x28(%r15), %eax
cmpl 0x28(%r14), %eax
jne 0x75f8
movl 0x24(%r15), %eax
cmpl 0x24(%r14), %eax
jne 0x75f8
movq (%r15), %rcx
movl 0x4(%r12), %eax
cmpq %rax, %rcx
jae 0x75af
movl $0x1, %eax
shlq %cl, %rax
movq 0x8(%r12), %rdx
shrq $0x6, %rcx
orq %rax, (%rdx,%rcx,8)
jmp 0x75ba
movq %r12, %rdi
movq %rcx, %rsi
callq 0x25a8
movq -0x38(%rbp), %rdi
movq (%r15), %rcx
movl 0x4(%rdi), %eax
cmpq %rax, %rcx
jae 0x75df
movl $0x1, %eax
shlq %cl, %rax
movq 0x8(%rdi), %rdx
shrq $0x6, %rcx
orq %rax, (%rdx,%rcx,8)
jmp 0x75e7
movq %rcx, %rsi
callq 0x25a8
movq -0x30(%rbp), %rcx
movq -0x40(%rbp), %rax
movl 0x10(%rax), %eax
incl %eax
movl %eax, 0x2c(%r15)
incq %r13
movq 0x28(%rcx), %rax
cmpq 0x10(%rax), %r13
jb 0x7570
movq -0x40(%rbp), %r13
movq 0x10(%r13), %rsi
movq %r13, %rdi
movq %r12, %rdx
callq 0x2c31
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdi
incq %rbx
movq 0x28(%rsi), %rax
cmpq 0x10(%rax), %rbx
jb 0x7518
callq 0x24ca
movl 0x10(%r13), %eax
movl %eax, -0x44(%rbp)
incl -0x44(%rbp)
movl 0x10(%r13), %eax
decl %eax
js 0x7827
movl %eax, %ebx
movq $0x0, -0x58(%rbp)
xorl %r15d, %r15d
movq (%r13), %rax
movq (%rax,%rbx,8), %r14
movq %r14, %rdi
callq 0x2a99
cmpq $0x1, %rax
je 0x7815
movq %rbx, -0x60(%rbp)
movq %r14, %rdi
callq 0x292b
movl %eax, %r13d
movq %r14, -0x50(%rbp)
movq %r14, %rdi
callq 0x292b
cmpl $-0x1, %eax
je 0x77ea
movslq %r13d, %rcx
movq %rcx, -0x68(%rbp)
movq -0x30(%rbp), %r8
movq 0x28(%r8), %rcx
movq (%rcx), %rcx
movq -0x68(%rbp), %rdx
movq (%rcx,%rdx,8), %rbx
movslq %eax, %r13
movq (%rcx,%r13,8), %r14
movl $0x1, %eax
movl %r13d, %ecx
shlq %cl, %rax
movq %rax, -0x78(%rbp)
movq %r13, %rax
shrq $0x6, %rax
movq %rax, -0x38(%rbp)
movq $-0x2, %rax
rolq %cl, %rax
movq %rax, -0x70(%rbp)
xorl %r12d, %r12d
movq -0x50(%rbp), %rdi
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x7702
movslq 0x8(%rax), %rcx
cmpq %rcx, %r12
je 0x7706
movq (%rax), %rax
jmp 0x76ef
xorl %ecx, %ecx
jmp 0x770a
movslq 0xc(%rax), %rcx
movq 0x18(%r14), %rax
testq %rax, %rax
je 0x7721
movslq 0x8(%rax), %rdx
cmpq %rdx, %r12
je 0x7725
movq (%rax), %rax
jmp 0x770e
xorl %edx, %edx
jmp 0x7729
movslq 0xc(%rax), %rdx
movb $0x1, %al
cmpq %rdx, %rcx
je 0x77bf
movq 0x28(%r8), %rsi
movq (%rsi), %rsi
movq (%rsi,%rcx,8), %rcx
testq %rcx, %rcx
je 0x7755
movq (%rsi,%rdx,8), %rdx
testq %rdx, %rdx
je 0x7755
movl 0x2c(%rcx), %ecx
cmpl 0x2c(%rdx), %ecx
je 0x77bf
movl -0x44(%rbp), %eax
movl %eax, 0x2c(%r14)
testq %r15, %r15
jne 0x7777
movb $0x1, %al
movq %rax, -0x58(%rbp)
callq 0x247c
movq -0x50(%rbp), %rdi
movq -0x30(%rbp), %r8
movq %rax, %r15
movl 0x4(%r15), %eax
cmpq %rax, %r13
jae 0x7792
movq 0x8(%r15), %rax
movq -0x78(%rbp), %rcx
movq -0x38(%rbp), %rdx
orq %rcx, (%rax,%rdx,8)
jmp 0x77a5
movq %r15, %rdi
movq %r13, %rsi
callq 0x25a8
movq -0x50(%rbp), %rdi
movq -0x30(%rbp), %r8
movl 0x4(%rdi), %eax
cmpq %rax, %r13
jae 0x77bd
movq 0x8(%rdi), %rax
movq -0x38(%rbp), %rcx
movq -0x70(%rbp), %rdx
andq %rdx, (%rax,%rcx,8)
xorl %eax, %eax
testb %al, %al
je 0x77d8
leaq 0x1(%r12), %rax
cmpq $0xff, %r12
movq %rax, %r12
jb 0x76eb
callq 0x292b
movq -0x30(%rbp), %r8
cmpl $-0x1, %eax
jne 0x76a6
movq -0x50(%rbp), %rcx
testq %rcx, %rcx
je 0x780d
xorl %eax, %eax
cmpb $0x1, 0x54(%rcx)
movq -0x40(%rbp), %r13
movq -0x60(%rbp), %rbx
jne 0x7808
movl 0x4(%rcx), %eax
decl %eax
movl %eax, 0x50(%rcx)
jmp 0x7815
movq -0x40(%rbp), %r13
movq -0x60(%rbp), %rbx
leaq -0x1(%rbx), %rax
testq %rbx, %rbx
movq %rax, %rbx
jg 0x765d
jmp 0x7832
xorl %r15d, %r15d
movq $0x0, -0x58(%rbp)
testq %r15, %r15
je 0x7846
movq 0x10(%r13), %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x2c31
testb $0x1, -0x58(%rbp)
jne 0x7641
callq 0x2b3c
movq %rax, %r15
movq 0x10(%rax), %rsi
movq %rax, %rdi
xorl %edx, %edx
callq 0x2c31
cmpq $0x0, 0x10(%r13)
je 0x7900
xorl %ebx, %ebx
xorl %r14d, %r14d
movq (%r13), %rax
movq (%rax,%r14,8), %rdi
movq -0x30(%rbp), %r13
movq 0x28(%r13), %rax
movq (%rax), %r12
callq 0x292b
cltq
movq (%r12,%rax,8), %r12
movq 0x18(%r12), %rax
testq %rax, %rax
je 0x78c0
movq 0x28(%r13), %rcx
movq (%rcx), %rcx
movslq 0xc(%rax), %rdx
movq (%rcx,%rdx,8), %rdx
testq %rdx, %rdx
je 0x78b8
movl 0x2c(%rdx), %edx
movl %edx, 0xc(%rax)
movq (%rax), %rax
testq %rax, %rax
jne 0x78a5
xorl %edi, %edi
movq %r15, %rsi
callq 0x87d0
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups 0x20(%r12), %xmm2
movups %xmm0, (%rax)
movups %xmm1, 0x10(%rax)
movups %xmm2, 0x20(%rax)
movq %rbx, 0x8(%rax)
movq %rbx, 0x18(%r12)
incq %r14
movq -0x40(%rbp), %r13
cmpq 0x10(%r13), %r14
jb 0x7876
movq -0x30(%rbp), %rbx
movq 0x28(%rbx), %rdi
leaq 0xf39(%rip), %rsi       # 0x8848
callq 0x2db5
movq 0x28(%rbx), %rdi
callq 0x2bde
leaq -0x545a(%rip), %rsi     # 0x24ca
movq %r13, %rdi
callq 0x2db5
movq %r13, %rdi
callq 0x2bde
movq %r15, 0x28(%rbx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop