// File: /workspace/github_c_makefile_star2_O3/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 0x77cd
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
callq 0x2b2c
movq %rax, %r13
callq 0x247c
movq %rax, %r15
movq %rbx, -0x30(%rbp)
movq 0x28(%rbx), %rax
cmpq $0x2, 0x10(%rax)
jb 0x73b4
movl $0x1, %ebx
movq (%rax), %rcx
movq (%rcx,%rbx,8), %rcx
cmpb $0x0, 0x22(%rcx)
jne 0x73ab
movq (%rcx), %rcx
movl 0x4(%r15), %edx
cmpq %rdx, %rcx
jae 0x7398
movl $0x1, %edx
shlq %cl, %rdx
movq 0x8(%r15), %rsi
shrq $0x6, %rcx
orq %rdx, (%rsi,%rcx,8)
jmp 0x73ab
movq %r15, %rdi
movq %rcx, %rsi
callq 0x25b0
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
incq %rbx
cmpq 0x10(%rax), %rbx
jb 0x7369
movq %r15, %rdi
callq 0x273a
testb %al, %al
jne 0x73cf
movq 0x10(%r13), %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x2c21
callq 0x247c
movq %rax, %rdi
movq -0x30(%rbp), %r15
movq 0x28(%r15), %rax
cmpq $0x2, 0x10(%rax)
movq %r13, -0x40(%rbp)
jb 0x7510
movl $0x1, %ebx
movq %rdi, -0x38(%rbp)
movq (%rax), %rcx
movq (%rcx,%rbx,8), %r14
cmpb $0x1, 0x22(%r14)
jne 0x7503
testq %rdi, %rdi
je 0x7432
movq (%r14), %rcx
movl 0x4(%rdi), %edx
cmpq %rdx, %rcx
jae 0x7432
movq 0x8(%rdi), %rdx
movq %rcx, %rsi
shrq $0x6, %rsi
movq (%rdx,%rsi,8), %rdx
btq %rcx, %rdx
jb 0x7503
callq 0x247c
movq %rax, %r12
movq 0x28(%r15), %rax
movq %rbx, %r13
cmpq 0x10(%rax), %rbx
jae 0x74e4
movq (%rax), %rcx
movq (%rcx,%r13,8), %r15
movl 0x28(%r15), %ecx
cmpl 0x28(%r14), %ecx
jne 0x74d7
movl 0x24(%r15), %ecx
cmpl 0x24(%r14), %ecx
jne 0x74d7
movq (%r15), %rcx
movl 0x4(%r12), %eax
cmpq %rax, %rcx
jae 0x748a
movl $0x1, %eax
shlq %cl, %rax
movq 0x8(%r12), %rdx
shrq $0x6, %rcx
orq %rax, (%rdx,%rcx,8)
jmp 0x7495
movq %r12, %rdi
movq %rcx, %rsi
callq 0x25b0
movq -0x38(%rbp), %rdi
movq (%r15), %rcx
movl 0x4(%rdi), %eax
cmpq %rax, %rcx
jae 0x74ba
movl $0x1, %eax
shlq %cl, %rax
movq 0x8(%rdi), %rdx
shrq $0x6, %rcx
orq %rax, (%rdx,%rcx,8)
jmp 0x74c2
movq %rcx, %rsi
callq 0x25b0
movq -0x40(%rbp), %rax
movl 0x10(%rax), %eax
incl %eax
movl %eax, 0x2c(%r15)
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
incq %r13
cmpq 0x10(%rax), %r13
jb 0x744b
movq -0x40(%rbp), %r13
movq 0x10(%r13), %rsi
movq %r13, %rdi
movq %r12, %rdx
callq 0x2c21
movq -0x30(%rbp), %r15
movq 0x28(%r15), %rax
movq -0x38(%rbp), %rdi
incq %rbx
cmpq 0x10(%rax), %rbx
jb 0x73f7
callq 0x24c6
movl 0x10(%r13), %eax
decl %eax
js 0x76d7
movl 0x10(%r13), %ecx
movl %ecx, -0x38(%rbp)
incl -0x38(%rbp)
movl %eax, %ebx
movq $0x0, -0x48(%rbp)
xorl %r15d, %r15d
movq (%r13), %rax
movq (%rax,%rbx,8), %r12
movq %r12, %rdi
callq 0x2a88
cmpq $0x1, %rax
je 0x76a1
movq %r12, %rdi
callq 0x291c
movl %eax, %r13d
movq %r12, %rdi
callq 0x291c
cmpl $-0x1, %eax
je 0x7682
movslq %r13d, %r14
movq -0x30(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq (%rcx), %rcx
movq (%rcx,%r14,8), %rdx
movslq %eax, %r13
movq (%rcx,%r13,8), %rax
movq 0x18(%rdx), %rdx
movq 0x18(%rax), %rsi
xorl %edi, %edi
testq %rdx, %rdx
je 0x75aa
movq %rdx, %r8
movslq 0x8(%r8), %r9
cmpq %r9, %rdi
je 0x75af
movq (%r8), %r8
testq %r8, %r8
jne 0x7599
xorl %r8d, %r8d
jmp 0x75b3
movslq 0xc(%r8), %r8
testq %rsi, %rsi
je 0x75cc
movq %rsi, %r9
movslq 0x8(%r9), %r10
cmpq %r10, %rdi
je 0x75d1
movq (%r9), %r9
testq %r9, %r9
jne 0x75bb
xorl %r9d, %r9d
jmp 0x75d5
movslq 0xc(%r9), %r9
cmpq %r9, %r8
je 0x75f6
movq (%rcx,%r8,8), %r8
testq %r8, %r8
je 0x7604
movq (%rcx,%r9,8), %r9
testq %r9, %r9
je 0x7604
movl 0x2c(%r8), %r8d
cmpl 0x2c(%r9), %r8d
jne 0x7604
incq %rdi
cmpq $0x100, %rdi            # imm = 0x100
jne 0x7591
jmp 0x7671
movl -0x38(%rbp), %ecx
movl %ecx, 0x2c(%rax)
testq %r15, %r15
jne 0x761d
movb $0x1, %al
movq %rax, -0x48(%rbp)
callq 0x247c
movq %rax, %r15
movl 0x4(%r15), %eax
cmpq %rax, %r13
jae 0x7642
movl $0x1, %eax
movl %r13d, %ecx
shlq %cl, %rax
movq 0x8(%r15), %rcx
movq %r13, %rdx
shrq $0x6, %rdx
orq %rax, (%rcx,%rdx,8)
jmp 0x764d
movq %r15, %rdi
movq %r13, %rsi
callq 0x25b0
movl 0x4(%r12), %eax
cmpq %rax, %r13
jae 0x7671
movq $-0x2, %rax
movl %r13d, %ecx
rolq %cl, %rax
movq 0x8(%r12), %rcx
shrq $0x6, %r13
andq %rax, (%rcx,%r13,8)
movq %r12, %rdi
callq 0x291c
cmpl $-0x1, %eax
jne 0x7571
testq %r12, %r12
movq -0x40(%rbp), %r13
je 0x76a1
xorl %eax, %eax
cmpb $0x1, 0x54(%r12)
jne 0x769c
movl 0x4(%r12), %eax
decl %eax
movl %eax, 0x50(%r12)
leaq -0x1(%rbx), %rax
testq %rbx, %rbx
movq %rax, %rbx
jg 0x7538
testq %r15, %r15
je 0x76c5
movq 0x10(%r13), %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x2c21
testb $0x1, -0x48(%rbp)
je 0x76d7
movl 0x10(%r13), %eax
decl %eax
jns 0x7528
callq 0x2b2c
movq %rax, %r15
movq 0x10(%rax), %rsi
movq %rax, %rdi
xorl %edx, %edx
callq 0x2c21
cmpq $0x0, 0x10(%r13)
je 0x7787
xorl %ebx, %ebx
xorl %r14d, %r14d
movq (%r13), %rax
movq (%rax,%r14,8), %rdi
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %r12
callq 0x291c
cltq
movq (%r12,%rax,8), %r12
movq 0x18(%r12), %rax
testq %rax, %rax
je 0x774b
movq -0x30(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq (%rcx), %rcx
movslq 0xc(%rax), %rdx
movq (%rcx,%rdx,8), %rdx
testq %rdx, %rdx
je 0x7743
movl 0x2c(%rdx), %edx
movl %edx, 0xc(%rax)
movq (%rax), %rax
testq %rax, %rax
jne 0x7730
xorl %edi, %edi
movq %r15, %rsi
callq 0x8654
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
cmpq 0x10(%r13), %r14
jb 0x76fd
movq -0x30(%rbp), %rbx
movq 0x28(%rbx), %rdi
leaq 0xf32(%rip), %rsi       # 0x86c8
callq 0x2db5
movq 0x28(%rbx), %rdi
callq 0x2bce
leaq -0x52e5(%rip), %rsi     # 0x24c6
movq %r13, %rdi
callq 0x2db5
movq %r13, %rdi
callq 0x2bce
movq %r15, 0x28(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop