// File: /workspace/github_c_makefile_star2_O3/c0stya[P]fslib/src/shortest.c
// Function: fst_shortest
struct _fst * fst_shortest(const struct _fst * fst, struct _fst * path) {
    struct _state *     state;
    struct _arc   *     arc;
    struct _arc         r_arc;
    state_t             p,q;
    size_t              i;

    assert ( fst->sr_type == SR_TROPICAL );
    sr = sr_get(fst->sr_type);
    
    struct _heap * Q = heap_create(states_cmp, sizeof(state_t), 0, 0);
    heap_index(Q, states_hash, states_key_eq);

    W = malloc(sizeof(weight_t) * fst->n_states);
    B = malloc(sizeof(struct _arc) * fst->n_states);

    // initialize arrays
    for (state_t i=0; i < fst->n_states; ++i)
        W[i] = sr.zero;  

    q = fst->start; 
    W[q] = sr.one;

    heap_insert(Q, &q); 

    while( ( heap_pop(Q, &p)) !=NULL ) {
        state = &fst->states[p];

        if (state->final == 1) {
            backtrace(path, p);
            break;
        }
    
        for (arc_t a=0; a < state->n_arcs; ++a) {
            arc = &state->arcs[a];
            q = arc->state;
            
            // Technical check: do not explore unreacheble states
            if (arc->weight == sr.zero)
                continue;
            
            // Using the zero weights as marker of unexplored states

            if (W[q] == sr.zero) {
                heap_insert(Q, &q);
            }
        
            if (W[q] != sr.sum( 
                    W[q], sr.prod(W[p], arc->weight) ) ) {
    
                W[q] = sr.prod(W[p], arc->weight);  

                r_arc = *arc;
                r_arc.state = p;
                
                B[q] = r_arc;

                if ((heap_find(Q, &q, &i)) != NULL) {
                    heap_update(Q, &q, i);
                }
            }

        }
    }

    heap_remove(Q);

    free(W);
    free(B);

    return path;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
cmpb $0x0, 0xc(%rdi)
jne 0x400f
movq %rsi, %r13
movq %rdi, %r15
leaq -0x70(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x20d4
movq 0x10(%r14), %rax
movq %rax, 0x5412(%rip)      # 0x9118
movups (%r14), %xmm0
movups %xmm0, 0x53f7(%rip)     # 0x9108
leaq 0x316(%rip), %rdi       # 0x402e
movl $0x4, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4504
leaq 0x33c(%rip), %rsi       # 0x4069
leaq 0x33e(%rip), %rdx       # 0x4072
movq %rax, -0x38(%rbp)
movq %rax, %rdi
callq 0x457d
movl 0x4(%r15), %ebx
leaq (,%rbx,4), %rdi
callq 0x1160
movq %rax, %r12
movq %rax, 0x53c5(%rip)      # 0x9120
movq %rbx, %rdi
shlq $0x4, %rdi
callq 0x1160
movq %rax, 0x53ba(%rip)      # 0x9128
testq %rbx, %rbx
je 0x3d8b
movss 0x539d(%rip), %xmm0     # 0x9118
xorl %eax, %eax
movss %xmm0, (%r12,%rax,4)
incq %rax
cmpq %rax, %rbx
jne 0x3d7d
movl (%r15), %eax
leaq -0x2c(%rbp), %rsi
movl %eax, (%rsi)
movss 0x5380(%rip), %xmm0     # 0x911c
movss %xmm0, (%r12,%rax,4)
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x4889
leaq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x467f
testq %rax, %rax
je 0x3fdc
movq %r13, -0x50(%rbp)
movq %r15, -0x48(%rbp)
movq 0x10(%r15), %rax
movl -0x30(%rbp), %ebx
leaq (%rbx,%rbx,2), %rcx
cmpl $0x1, 0xc(%rax,%rcx,8)
je 0x3f42
leaq (%rax,%rcx,8), %rbx
cmpl $0x0, (%rbx)
je 0x3f1f
movl $0x4, %r15d
xorl %r12d, %r12d
movq 0x10(%rbx), %r13
movl -0x4(%r13,%r15), %ecx
movl %ecx, -0x2c(%rbp)
movss (%r13,%r15), %xmm1
movss 0x5306(%rip), %xmm0     # 0x9118
ucomiss %xmm0, %xmm1
jne 0x3e2c
jp 0x3e2c
incq %r12
movl (%rbx), %eax
addq $0x10, %r15
cmpq %rax, %r12
jb 0x3df7
jmp 0x3f1f
addq %r15, %r13
movq 0x52ea(%rip), %rax      # 0x9120
movss (%rax,%rcx,4), %xmm2
ucomiss %xmm0, %xmm2
jne 0x3e64
jp 0x3e64
movq -0x38(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x4889
movq 0x52ca(%rip), %rax      # 0x9120
movl -0x2c(%rbp), %ecx
movss (%rax,%rcx,4), %xmm2
movss (%r13), %xmm1
movss %xmm2, -0x3c(%rbp)
movq 0x5298(%rip), %r14      # 0x9108
movl -0x30(%rbp), %ecx
movss (%rax,%rcx,4), %xmm0
callq *0x5292(%rip)           # 0x9110
movaps %xmm0, %xmm1
movss -0x3c(%rbp), %xmm0
callq *%r14
movss -0x3c(%rbp), %xmm1
ucomiss %xmm0, %xmm1
jne 0x3e95
jnp 0x3e19
movq 0x5284(%rip), %rax      # 0x9120
movl -0x30(%rbp), %ecx
movss (%rax,%rcx,4), %xmm0
movss (%r13), %xmm1
callq *0x5260(%rip)           # 0x9110
movq 0x5269(%rip), %rax      # 0x9120
movl -0x2c(%rbp), %ecx
movss %xmm0, (%rax,%rcx,4)
movl 0x8(%r13), %eax
movl %eax, -0x68(%rbp)
movq (%r13), %rax
movq %rax, -0x70(%rbp)
movl -0x30(%rbp), %eax
movq 0x5250(%rip), %rdx      # 0x9128
shlq $0x4, %rcx
movl %eax, (%rdx,%rcx)
movq -0x70(%rbp), %rax
movq %rax, 0x4(%rdx,%rcx)
movl -0x68(%rbp), %eax
movl %eax, 0xc(%rdx,%rcx)
movq -0x38(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x4b0c
testq %rax, %rax
je 0x3e19
movq -0x58(%rbp), %rdx
movq -0x38(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x49fb
jmp 0x3e19
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x467f
testq %rax, %rax
movq -0x50(%rbp), %r13
movq -0x48(%rbp), %r15
jne 0x3dcb
jmp 0x3fdc
movq %r13, %rdi
callq 0x212d
testl %ebx, %ebx
je 0x3fca
xorl %r15d, %r15d
movl %ebx, %r12d
movq %r13, %rdi
callq 0x212d
movq 0x51c5(%rip), %rax      # 0x9128
movl %r12d, %ecx
shlq $0x4, %rcx
movl (%rax,%rcx), %r12d
incl %r15d
testl %r12d, %r12d
jne 0x3f54
movss 0x519e(%rip), %xmm0     # 0x911c
movq %r13, %rdi
movl %r15d, %esi
callq 0x22a0
movq 0x5198(%rip), %rax      # 0x9128
movl %ebx, %ebx
shlq $0x4, %rbx
movss 0x4(%rax,%rbx), %xmm0
movl 0x8(%rax,%rbx), %ecx
movl 0xc(%rax,%rbx), %r8d
leal -0x1(%r15), %r12d
movq %r13, %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0x2189
movq 0x516a(%rip), %rax      # 0x9128
movl (%rax,%rbx), %ebx
movl %r12d, %r15d
testl %ebx, %ebx
jne 0x3f90
jmp 0x3fdc
movss 0x514a(%rip), %xmm0     # 0x911c
movq %r13, %rdi
xorl %esi, %esi
callq 0x22a0
movq -0x38(%rbp), %rdi
callq 0x4602
movq 0x5134(%rip), %rdi      # 0x9120
callq 0x1030
movq 0x5130(%rip), %rdi      # 0x9128
callq 0x1030
movq %r13, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2405(%rip), %rdi      # 0x641b
leaq 0x241a(%rip), %rsi      # 0x6437
leaq 0x2422(%rip), %rcx      # 0x6446
movl $0x37, %edx
callq 0x10c0