// File: /workspace/github_c_makefile_star2_O0/c0stya[P]fslib/src/compose.c
// Function: fst_compose
struct _fst * fst_compose(
    const struct _fst * fst_a, 
    const struct _fst * fst_b, 
    struct _fst * fst_c )
{
    struct _sr sr = sr_get(fst_a->sr_type);
    struct _queue * q = queue_create(sizeof(struct _spair));
    struct _queue * mq = queue_create(sizeof(struct _arc_pair)); 

    struct _hash * marked = hash_create(
                    hash_pair,
                    cmp_pair,
                    sizeof(struct _spair),
                    sizeof(state_t), 
                    1000 ); // try to predict

    struct _spair      pair;
    struct _arc_pair   mi;    // composition item

    state_t sc, dst_sc;

    struct _state * state_a, * state_b;
    struct _state * dst_state_a, * dst_state_b;
    struct _arc * arc_a, * arc_b;

    // Add initial stack to agenda
    pair.a = fst_a->start;
    pair.b = fst_b->start;
    
    queue_enque(q, &pair);

    while( (queue_deque(q, &pair)) != NULL ) {

        state_a = &fst_a->states[pair.a];
        state_b = &fst_b->states[pair.b];


        if (hash_get(marked, &pair, &sc) == NULL) {

            // Create a new state
            sc = fst_add_state(fst_c);
            
            if (state_a->final && state_b->final)
                fst_set_final(fst_c, sc, sr.one);

            if (pair.a == fst_a->start && pair.b == fst_b->start)
                fst_c->start = sc;

            hash_add(marked, &pair, &sc);
        }

        // Match procedure
        match_arcs(     fst_a, fst_b, 
                        &pair,
                        &sr,
                        mq  );

        while ( queue_deque(mq, &mi) != NULL ) {

            arc_a = &mi.a;
            arc_b = &mi.b;
            
            pair.a = arc_a->state;
            pair.b = arc_b->state;

                
            // State lookup
            if (hash_get(marked, &pair, &dst_sc) == NULL) {
                
                // Create a new state
                dst_state_a = &fst_a->states[pair.a];
                dst_state_b = &fst_b->states[pair.b];

                dst_sc = fst_add_state(fst_c);
                
                if (dst_state_a->final && dst_state_b->final) {
                    fst_set_final(fst_c, dst_sc, sr.one);
                }

                queue_enque(q, &pair);

                // Add to a makred table
                hash_add(marked, &pair, &dst_sc);
            }

            fst_add_arc(
                fst_c,
                sc, 
                dst_sc, 
                arc_a->ilabel, 
                arc_b->olabel,
                sr.prod(arc_a->weight, arc_b->weight));
        }
    }

    queue_remove(q);
    queue_remove(mq);
    hash_remove(marked);

    return fst_c;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
leaq -0x30(%rbp), %rdi
movzbl 0xc(%rax), %esi
callq 0x26a0
movl $0x8, %edi
callq 0x3aa0
movq %rax, -0x38(%rbp)
movl $0x20, %edi
callq 0x3aa0
movq %rax, -0x40(%rbp)
leaq 0x2c5(%rip), %rdi       # 0x4ee0
leaq 0x2fe(%rip), %rsi       # 0x4f20
movl $0x8, %edx
movl $0x4, %ecx
movl $0x3e8, %r8d            # imm = 0x3E8
callq 0x1e90
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3b00
movq -0x38(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3bd0
cmpq $0x0, %rax
je 0x4ea9
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x50(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x74(%rbp), %rdx
callq 0x2410
cmpq $0x0, %rax
jne 0x4d1b
movq -0x18(%rbp), %rdi
callq 0x27a0
movl %eax, -0x74(%rbp)
movq -0x80(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x4ceb
movq -0x88(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x4ceb
movq -0x18(%rbp), %rdi
movl -0x74(%rbp), %esi
movss -0x1c(%rbp), %xmm0
callq 0x2a30
movl -0x50(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x4d0a
movl -0x4c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x4d0a
movl -0x74(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x74(%rbp), %rdx
callq 0x20e0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x40(%rbp), %r8
leaq -0x50(%rbp), %rdx
leaq -0x30(%rbp), %rcx
callq 0x49c0
movq -0x40(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x3bd0
cmpq $0x0, %rax
je 0x4ea4
leaq -0x70(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x70(%rbp), %rax
addq $0x10, %rax
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x50(%rbp)
movq -0xa8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x2410
cmpq $0x0, %rax
jne 0x4e1f
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x50(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rdi
callq 0x27a0
movl %eax, -0x78(%rbp)
movq -0x90(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x4e01
movq -0x98(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x4e01
movq -0x18(%rbp), %rdi
movl -0x78(%rbp), %esi
movss -0x1c(%rbp), %xmm0
callq 0x2a30
movq -0x38(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3b00
movq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x20e0
movq -0x18(%rbp), %rax
movq %rax, -0xc0(%rbp)
movl -0x74(%rbp), %eax
movl %eax, -0xb8(%rbp)
movl -0x78(%rbp), %eax
movl %eax, -0xb4(%rbp)
movq -0xa0(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0xb0(%rbp)
movq -0xa8(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0xac(%rbp)
movq -0x28(%rbp), %rax
movq -0xa0(%rbp), %rcx
movss 0x4(%rcx), %xmm0
movq -0xa8(%rbp), %rcx
movss 0x4(%rcx), %xmm1
callq *%rax
movq -0xc0(%rbp), %rdi
movl -0xb8(%rbp), %esi
movl -0xb4(%rbp), %edx
movl -0xb0(%rbp), %ecx
movl -0xac(%rbp), %r8d
callq 0x2870
jmp 0x4d34
jmp 0x4c5a
movq -0x38(%rbp), %rdi
callq 0x3cd0
movq -0x40(%rbp), %rdi
callq 0x3cd0
movq -0x48(%rbp), %rdi
callq 0x23a0
movq -0x18(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)