// File: /workspace/github_c_makefile_star2_O3/c-zhou[P]oatk/path.c
// Function: select_best_seq
uint32_t select_best_seq(asg_t *g, path_v *paths, FILE *fo, int type, double seq_cf, int seq_id, int is_pltd)
{
    if (paths->n == 0)
        return UINT32_MAX;

    uint64_t l;
    size_t i, j, k;
    l = 0, j = 0;
    for (i = 0; i < paths->n; ++i) {
        if ((paths->a[i].circ || !type) && paths->a[i].len > l) {
            l = paths->a[i].len;
            j = i;
        }
    }
    
    if (!paths->a[j].circ) {
        k = UINT32_MAX, l = 0;
        for (i = 0; i < paths->n; ++i) {
            if (paths->a[i].circ && paths->a[i].len > l) {
                l = paths->a[i].len;
                k = i;
            }
        }
        if (k != UINT32_MAX) {
            uint64_t L = paths->a[j].len;
            if (is_pltd) L = MIN(L, COMMON_AVG_PLTD_SIZE);
            if ((double) l / L >= seq_cf) j = k;
        }
    }

    // TODO need more sophisticated rules for cmp_coeff
    if (is_pltd) {
        double coeff;
        uint32_t circ;
        circ = (paths->a[j].circ || type);
        k = UINT32_MAX, coeff = .0;
        for (i = 0; i < paths->n; ++i) {
            if ((paths->a[i].circ || !circ) && paths->a[i].srcc > coeff) {
                coeff = paths->a[i].srcc;
                k = i;
            }
        }
        if (k != UINT32_MAX && paths->a[k].len + 1000 >= paths->a[j].len)
            j = k;
    }
    
    if (fo) print_seq(g, &paths->a[j], fo, seq_id > 0? seq_id : 1, 0, 60, 100);

    return j;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq (%rsi), %rax
testq %rax, %rax
je 0xab78
movq 0x10(%rsi), %rsi
leaq 0x18(%rsi), %r10
xorl %ebx, %ebx
movl $0x40000000, %r11d      # imm = 0x40000000
xorl %r14d, %r14d
xorl %r15d, %r15d
testl %ecx, %ecx
je 0xaa35
movl -0x10(%r10), %ebp
andl %r11d, %ebp
je 0xaa43
movl (%r10), %r12d
cmpq %r12, %r15
cmovbeq %r12, %r15
cmovbq %r14, %rbx
incq %r14
addq $0x30, %r10
cmpq %r14, %rax
jne 0xaa28
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
leaq (%rbx,%rbx,2), %r14
shlq $0x4, %r14
testb $0x40, 0xb(%rsi,%r14)
jne 0xaad2
leaq 0x18(%rsi), %r12
xorl %r13d, %r13d
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
xorl %r15d, %r15d
testb $0x40, -0xd(%r12)
je 0xaa8c
movl (%r12), %ebp
cmpq %rbp, %r15
cmovbeq %rbp, %r15
cmovbq %r13, %r11
incq %r13
addq $0x30, %r12
cmpq %r13, %rax
jne 0xaa75
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpq %r12, %r11
je 0xaad2
movl 0x18(%rsi,%r14), %r14d
movl $0x27100, %r12d         # imm = 0x27100
cmpq %r12, %r14
cmovbq %r14, %r12
testl %r9d, %r9d
cmoveq %r14, %r12
cvtsi2sd %r15, %xmm1
cvtsi2sd %r12, %xmm2
divsd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
cmovaeq %r11, %rbx
testl %r9d, %r9d
je 0xab44
leaq (%rbx,%rbx,2), %r9
shlq $0x4, %r9
movl $0x40000000, %r11d      # imm = 0x40000000
andl 0x8(%rsi,%r9), %r11d
orl %ecx, %r11d
leaq 0x28(%rsi), %rcx
xorpd %xmm0, %xmm0
xorl %r14d, %r14d
testb $0x40, -0x1d(%rcx)
jne 0xab03
testl %r11d, %r11d
jne 0xab14
movsd (%rcx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0xab14
movq %r14, %r10
movapd %xmm1, %xmm0
incq %r14
addq $0x30, %rcx
cmpq %r14, %rax
jne 0xaaf8
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %r10
je 0xab44
leaq (%r10,%r10,2), %rax
shlq $0x4, %rax
movl $0x3e8, %ecx            # imm = 0x3E8
addl 0x18(%rsi,%rax), %ecx
cmpl 0x18(%rsi,%r9), %ecx
cmovaeq %r10, %rbx
testq %rdx, %rdx
je 0xab7d
leaq (%rbx,%rbx,2), %rax
shlq $0x4, %rax
addq %rax, %rsi
cmpl $0x2, %r8d
movl $0x1, %ecx
cmovgel %r8d, %ecx
movl $0x64, (%rsp)
xorl %r8d, %r8d
movl $0x3c, %r9d
callq 0xa101
jmp 0xab7d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq