// File: /workspace/github_c_makefile_star2_O0/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
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movzbl 0xc(%rax), %eax
cmpl $0x0, %eax
jne 0x4f82
jmp 0x4fa1
leaq 0x349b(%rip), %rdi      # 0x8424
leaq 0x34b0(%rip), %rsi      # 0x8440
movl $0x37, %edx
leaq 0x34b3(%rip), %rcx      # 0x844f
callq 0x10b0
movq -0x8(%rbp), %rax
leaq -0x58(%rbp), %rdi
movzbl 0xc(%rax), %esi
callq 0x26a0
movq -0x58(%rbp), %rax
movq %rax, 0x613b(%rip)      # 0xb0f8
movq -0x50(%rbp), %rax
movq %rax, 0x6138(%rip)      # 0xb100
movq -0x48(%rbp), %rax
movq %rax, 0x6135(%rip)      # 0xb108
leaq 0x2d6(%rip), %rdi       # 0x52b0
movl $0x4, %esi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x5b10
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
leaq 0x336(%rip), %rsi       # 0x5330
leaq 0x34f(%rip), %rdx       # 0x5350
callq 0x5be0
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %edi
shlq $0x2, %rdi
callq 0x1120
movq %rax, 0x60f1(%rip)      # 0xb110
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %edi
shlq $0x4, %rdi
callq 0x1120
movq %rax, 0x60e0(%rip)      # 0xb118
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x506d
movss 0x60b5(%rip), %xmm0     # 0xb108
movq 0x60b6(%rip), %rax      # 0xb110
movl -0x64(%rbp), %ecx
movss %xmm0, (%rax,%rcx,4)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x503f
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x38(%rbp)
movss 0x608e(%rip), %xmm0     # 0xb10c
movq 0x608b(%rip), %rax      # 0xb110
movl -0x38(%rbp), %ecx
movss %xmm0, (%rax,%rcx,4)
movq -0x60(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x60a0
movq -0x60(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x5d40
cmpq $0x0, %rax
je 0x5275
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x1, 0xc(%rax)
jne 0x50e2
movq -0x10(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x5380
jmp 0x5275
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x5270
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x68(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movss 0x4(%rax), %xmm0
ucomiss 0x5fe1(%rip), %xmm0     # 0xb108
jne 0x5130
jp 0x5130
jmp 0x5262
movq 0x5fd9(%rip), %rax      # 0xb110
movl -0x38(%rbp), %ecx
movss (%rax,%rcx,4), %xmm0
ucomiss 0x5fc2(%rip), %xmm0     # 0xb108
jne 0x5157
jp 0x5157
movq -0x60(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x60a0
movq 0x5fb2(%rip), %rax      # 0xb110
movl -0x38(%rbp), %ecx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x6c(%rbp)
movq 0x5f86(%rip), %rax      # 0xb0f8
movq %rax, -0x78(%rbp)
movq 0x5f93(%rip), %rax      # 0xb110
movl -0x38(%rbp), %ecx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x70(%rbp)
movq 0x5f6f(%rip), %rax      # 0xb100
movq 0x5f78(%rip), %rcx      # 0xb110
movl -0x34(%rbp), %edx
movss (%rcx,%rdx,4), %xmm0
movq -0x20(%rbp), %rcx
movss 0x4(%rcx), %xmm1
callq *%rax
movq -0x78(%rbp), %rax
movaps %xmm0, %xmm1
movss -0x70(%rbp), %xmm0
callq *%rax
movaps %xmm0, %xmm1
movss -0x6c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jne 0x51cd
jp 0x51cd
jmp 0x5260
movq 0x5f2c(%rip), %rax      # 0xb100
movq 0x5f35(%rip), %rcx      # 0xb110
movl -0x34(%rbp), %edx
movss (%rcx,%rdx,4), %xmm0
movq -0x20(%rbp), %rcx
movss 0x4(%rcx), %xmm1
callq *%rax
movq 0x5f1b(%rip), %rax      # 0xb110
movl -0x38(%rbp), %ecx
movss %xmm0, (%rax,%rcx,4)
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x30(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x30(%rbp)
movq 0x5efb(%rip), %rax      # 0xb118
movl -0x38(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x30(%rbp), %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x60(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0x6430
cmpq $0x0, %rax
je 0x525e
movq -0x60(%rbp), %rdi
movq -0x40(%rbp), %rdx
leaq -0x38(%rbp), %rsi
callq 0x61a0
jmp 0x5260
jmp 0x5262
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x50e9
jmp 0x509a
movq -0x60(%rbp), %rdi
callq 0x5ca0
movq 0x5e8b(%rip), %rdi      # 0xb110
callq 0x1030
movq 0x5e87(%rip), %rdi      # 0xb118
callq 0x1030
movq -0x10(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)