// File: /workspace/github_c_makefile_star2_O2/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
movq %rsi, -0x40(%rbp)
cmpb $0x0, 0xc(%rdi)
jne 0x3cc8
movq %rdi, %r15
leaq -0x70(%rbp), %r14
xorl %ebx, %ebx
movq %r14, %rdi
xorl %esi, %esi
callq 0x1f64
movq 0x10(%r14), %rax
movq %rax, 0x570b(%rip)      # 0x9110
movups (%r14), %xmm0
movups %xmm0, 0x56f0(%rip)     # 0x9100
leaq 0x2ce(%rip), %rdi       # 0x3ce5
pushq $0x4
popq %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4154
leaq 0x2f6(%rip), %rsi       # 0x3d20
leaq 0x2f8(%rip), %rdx       # 0x3d29
movq %rax, -0x38(%rbp)
movq %rax, %rdi
callq 0x41c8
movq %r15, -0x50(%rbp)
movl 0x4(%r15), %r15d
leaq (,%r15,4), %rdi
callq 0x1150
movq %rax, %r12
movq %rax, 0x56bc(%rip)      # 0x9118
movq %r15, %rdi
shlq $0x4, %rdi
callq 0x1150
movq %rax, 0x56b1(%rip)      # 0x9120
movss 0x5699(%rip), %xmm0     # 0x9110
cmpq %rbx, %r15
je 0x3a87
movss %xmm0, (%r12,%rbx,4)
incq %rbx
jmp 0x3a77
movq -0x50(%rbp), %rax
movl (%rax), %eax
leaq -0x2c(%rbp), %rsi
movl %eax, (%rsi)
movss 0x5679(%rip), %xmm0     # 0x9114
movss %xmm0, (%r12,%rax,4)
movq -0x38(%rbp), %rdi
callq 0x44bb
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x42b4
testq %rax, %rax
je 0x3c94
movq -0x50(%rbp), %rax
movq 0x10(%rax), %r15
movl -0x30(%rbp), %ebx
imulq $0x18, %rbx, %rax
cmpl $0x1, 0xc(%r15,%rax)
je 0x3c0a
addq %rax, %r15
pushq $0x4
popq %rbx
xorl %r12d, %r12d
movl (%r15), %eax
cmpq %rax, %r12
jae 0x3aaa
movq 0x10(%r15), %r13
movl -0x4(%r13,%rbx), %ecx
movl %ecx, -0x2c(%rbp)
movss (%r13,%rbx), %xmm1
movss 0x5609(%rip), %xmm0     # 0x9110
ucomiss %xmm0, %xmm1
jne 0x3b17
jp 0x3b17
incq %r12
addq $0x10, %rbx
jmp 0x3ae4
addq %rbx, %r13
movq 0x55f7(%rip), %rax      # 0x9118
movss (%rax,%rcx,4), %xmm2
ucomiss %xmm0, %xmm2
jne 0x3b4f
jp 0x3b4f
movq -0x38(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x44bb
movq 0x55d7(%rip), %rax      # 0x9118
movl -0x2c(%rbp), %ecx
movss (%rax,%rcx,4), %xmm2
movss (%r13), %xmm1
movss %xmm2, -0x44(%rbp)
movq 0x55a5(%rip), %r14      # 0x9100
movl -0x30(%rbp), %ecx
movss (%rax,%rcx,4), %xmm0
callq *0x559f(%rip)           # 0x9108
movaps %xmm0, %xmm1
movss -0x44(%rbp), %xmm0
callq *%r14
movss -0x44(%rbp), %xmm1
ucomiss %xmm0, %xmm1
jne 0x3b80
jnp 0x3b0e
movq 0x5591(%rip), %rax      # 0x9118
movl -0x30(%rbp), %ecx
movss (%rax,%rcx,4), %xmm0
movss (%r13), %xmm1
callq *0x556d(%rip)           # 0x9108
movq 0x5576(%rip), %rax      # 0x9118
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 0x555d(%rip), %rdx      # 0x9120
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 0x4719
testq %rax, %rax
je 0x3b0e
movq -0x58(%rbp), %rdx
movq -0x38(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x4605
jmp 0x3b0e
movq -0x40(%rbp), %rdi
callq 0x1fbc
xorl %r15d, %r15d
movl %ebx, %r12d
testl %r12d, %r12d
je 0x3c3e
movq -0x40(%rbp), %rdi
callq 0x1fbc
movq 0x54f2(%rip), %rax      # 0x9120
movl %r12d, %ecx
shlq $0x4, %rcx
movl (%rax,%rcx), %r12d
incl %r15d
jmp 0x3c19
movss 0x54ce(%rip), %xmm0     # 0x9114
movq -0x40(%rbp), %rdi
movl %r15d, %esi
callq 0x210b
testl %ebx, %ebx
je 0x3c94
movq 0x54c3(%rip), %rax      # 0x9120
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 -0x40(%rbp), %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0x2011
movq 0x5494(%rip), %rax      # 0x9120
movl (%rax,%rbx), %ebx
movl %r12d, %r15d
jmp 0x3c52
movq -0x38(%rbp), %rdi
callq 0x423f
movq 0x5474(%rip), %rdi      # 0x9118
callq 0x1030
movq 0x5470(%rip), %rdi      # 0x9120
callq 0x1030
movq -0x40(%rbp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x274c(%rip), %rdi      # 0x641b
leaq 0x2761(%rip), %rsi      # 0x6437
leaq 0x2769(%rip), %rcx      # 0x6446
pushq $0x37
popq %rdx
callq 0x10c0