// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, -0x38(%rbp)
testq %rdi, %rdi
je 0x7176
callq 0x2924
movq %rax, -0x30(%rbp)
pushq $0x1
popq %rbx
callq 0x230c
movq %rax, %r15
movq %rbx, %r14
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
cmpq 0x10(%rax), %r14
jae 0x6dac
movq (%rax), %rax
movq (%rax,%r14,8), %rax
cmpb $0x0, 0x22(%rax)
jne 0x6da7
movq (%rax), %rcx
movl 0x4(%r15), %eax
cmpq %rax, %rcx
jae 0x6d9c
movq %rbx, %rax
shlq %cl, %rax
movq 0x8(%r15), %rdx
shrq $0x6, %rcx
orq %rax, (%rdx,%rcx,8)
jmp 0x6da7
movq %r15, %rdi
movq %rcx, %rsi
callq 0x23f9
incq %r14
jmp 0x6d61
movq %r15, %rdi
callq 0x257c
testb %al, %al
jne 0x6dc8
movq -0x30(%rbp), %rdi
movq 0x10(%rdi), %rsi
movq %r15, %rdx
callq 0x2a16
pushq $0x1
popq %r14
callq 0x230c
movq %rax, %r15
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
cmpq 0x10(%rax), %r14
jae 0x6ee2
movq (%rax), %rax
movq (%rax,%r14,8), %r13
cmpb $0x1, 0x22(%r13)
jne 0x6eda
testq %r15, %r15
je 0x6e23
movq (%r13), %rax
movl 0x4(%r15), %ecx
cmpq %rcx, %rax
jae 0x6e23
movq 0x8(%r15), %rcx
movq %rax, %rdx
shrq $0x6, %rdx
movq (%rcx,%rdx,8), %rcx
btq %rax, %rcx
jb 0x6eda
callq 0x230c
movq %rax, %r12
movq %r14, -0x50(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
cmpq 0x10(%rax), %r14
jae 0x6eca
movq (%rax), %rax
movq (%rax,%r14,8), %rbx
movl 0x28(%rbx), %eax
cmpl 0x28(%r13), %eax
jne 0x6ec2
movl 0x24(%rbx), %eax
cmpl 0x24(%r13), %eax
jne 0x6ec2
movq (%rbx), %rcx
movl 0x4(%r12), %eax
cmpq %rax, %rcx
jae 0x6e80
pushq $0x1
popq %rax
shlq %cl, %rax
movq 0x8(%r12), %rdx
shrq $0x6, %rcx
orq %rax, (%rdx,%rcx,8)
jmp 0x6e8b
movq %r12, %rdi
movq %rcx, %rsi
callq 0x23f9
movq (%rbx), %rcx
movl 0x4(%r15), %eax
cmpq %rax, %rcx
jae 0x6eab
pushq $0x1
popq %rax
shlq %cl, %rax
movq 0x8(%r15), %rdx
shrq $0x6, %rcx
orq %rax, (%rdx,%rcx,8)
jmp 0x6eb6
movq %r15, %rdi
movq %rcx, %rsi
callq 0x23f9
movq -0x30(%rbp), %rdi
movl 0x10(%rdi), %eax
incl %eax
movl %eax, 0x2c(%rbx)
incq %r14
jmp 0x6e33
movq 0x10(%rdi), %rsi
movq %r12, %rdx
callq 0x2a16
movq -0x50(%rbp), %r14
incq %r14
jmp 0x6dd4
movq %r15, %rdi
callq 0x2351
movq -0x30(%rbp), %rcx
movl 0x10(%rcx), %eax
movl %eax, -0x3c(%rbp)
incl -0x3c(%rbp)
movl 0x10(%rcx), %edx
xorl %ebx, %ebx
movq $0x0, -0x60(%rbp)
movl %edx, %eax
decl %eax
js 0x707b
movq %rdx, -0x58(%rbp)
movq (%rcx), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %r14
movq %r14, %rdi
callq 0x288d
cmpq $0x1, %rax
jne 0x6f36
movq -0x30(%rbp), %rcx
movq -0x58(%rbp), %rdx
jmp 0x7073
movq %rbx, -0x48(%rbp)
movq %r14, %rdi
callq 0x273a
cltq
movq %rax, -0x68(%rbp)
movq %r14, -0x50(%rbp)
movq -0x50(%rbp), %r14
movq %r14, %rdi
callq 0x273a
cmpl $-0x1, %eax
je 0x7049
movq -0x38(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq (%rcx), %r12
movq -0x68(%rbp), %rcx
movq (%r12,%rcx,8), %rcx
cltq
movq %rax, -0x70(%rbp)
movq (%r12,%rax,8), %r13
movq 0x18(%rcx), %r14
xorl %ebx, %ebx
cmpq $0x100, %rbx            # imm = 0x100
je 0x6f4c
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7185
movq %rax, %r15
movq 0x18(%r13), %rdi
movq %rbx, %rsi
callq 0x7185
cmpq %rax, %r15
je 0x6fc6
movq (%r12,%r15,8), %rcx
testq %rcx, %rcx
je 0x6fcb
movq (%r12,%rax,8), %rax
testq %rax, %rax
je 0x6fcb
movl 0x2c(%rcx), %ecx
cmpl 0x2c(%rax), %ecx
jne 0x6fcb
incq %rbx
jmp 0x6f84
movl -0x3c(%rbp), %eax
movl %eax, 0x2c(%r13)
movq -0x48(%rbp), %rbx
testq %rbx, %rbx
jne 0x6fe9
movb $0x1, %al
movq %rax, -0x60(%rbp)
callq 0x230c
movq %rax, %rbx
movl 0x4(%rbx), %eax
movq -0x70(%rbp), %r15
cmpq %rax, %r15
movq -0x50(%rbp), %r14
jae 0x7013
pushq $0x1
popq %rax
movl %r15d, %ecx
shlq %cl, %rax
movq 0x8(%rbx), %rcx
movq %r15, %rdx
shrq $0x6, %rdx
orq %rax, (%rcx,%rdx,8)
jmp 0x701e
movq %rbx, %rdi
movq %r15, %rsi
callq 0x23f9
movq %rbx, -0x48(%rbp)
movl 0x4(%r14), %eax
cmpq %rax, %r15
jae 0x6f4c
pushq $-0x2
popq %rax
movl %r15d, %ecx
rolq %cl, %rax
movq 0x8(%r14), %rcx
shrq $0x6, %r15
andq %rax, (%rcx,%r15,8)
jmp 0x6f4c
testq %r14, %r14
movq -0x30(%rbp), %rcx
movq -0x58(%rbp), %rdx
je 0x706f
xorl %eax, %eax
cmpb $0x1, 0x54(%r14)
movq -0x48(%rbp), %rbx
jne 0x7069
movl 0x4(%r14), %eax
decl %eax
movl %eax, 0x50(%r14)
jmp 0x7073
movq -0x48(%rbp), %rbx
decq %rdx
jmp 0x6f04
testq %rbx, %rbx
je 0x7094
movq 0x10(%rcx), %rsi
movq -0x30(%rbp), %rdi
movq %rbx, %rdx
callq 0x2a16
movq -0x30(%rbp), %rcx
testb $0x1, -0x60(%rbp)
jne 0x6ef4
callq 0x2924
movq %rax, %r15
movq 0x10(%rax), %rsi
xorl %ebx, %ebx
movq %rax, %rdi
xorl %edx, %edx
callq 0x2a16
movq -0x30(%rbp), %r14
cmpq 0x10(%r14), %rbx
jae 0x713e
movq (%r14), %rax
movq (%rax,%rbx,8), %rdi
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %r14
callq 0x273a
cltq
movq (%r14,%rax,8), %r14
leaq 0x18(%r14), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x7109
movq -0x38(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq (%rcx), %rcx
movslq 0xc(%rax), %rdx
movq (%rcx,%rdx,8), %rcx
testq %rcx, %rcx
je 0x70e1
movl 0x2c(%rcx), %ecx
movl %ecx, 0xc(%rax)
jmp 0x70e1
xorl %edi, %edi
movq %r15, %rsi
callq 0x7f70
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups %xmm0, (%rax)
movups %xmm1, 0x10(%rax)
movups %xmm2, 0x20(%rax)
andq $0x0, 0x8(%rax)
andq $0x0, 0x18(%r14)
incq %rbx
jmp 0x70b6
movq -0x38(%rbp), %rbx
movq 0x28(%rbx), %rdi
leaq 0xe96(%rip), %rsi       # 0x7fe3
callq 0x2b98
movq 0x28(%rbx), %rdi
callq 0x29c6
leaq -0x4e11(%rip), %rsi     # 0x2351
movq %r14, %rdi
callq 0x2b98
movq %r14, %rdi
callq 0x29c6
movq %r15, 0x28(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq