// File: /workspace/github_c_makefile_star2_O2/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 0x904b
movq 0x10(%rsi), %rsi
leaq 0x18(%rsi), %r10
xorl %r11d, %r11d
movl $0x40000000, %ebp       # imm = 0x40000000
xorl %r14d, %r14d
xorl %ebx, %ebx
cmpq %r14, %rax
je 0x9004
testl %ecx, %ecx
je 0x8fed
movl -0x10(%r10), %r15d
andl %ebp, %r15d
je 0x8ffb
movl (%r10), %r15d
cmpq %r15, %r11
cmovbeq %r15, %r11
cmovbq %r14, %rbx
incq %r14
addq $0x30, %r10
jmp 0x8fdb
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
imulq $0x30, %rbx, %r15
testb $0x40, 0xb(%rsi,%r15)
jne 0x908d
leaq 0x18(%rsi), %r12
xorl %r14d, %r14d
xorl %r13d, %r13d
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
cmpq %r13, %rax
je 0x9053
testb $0x40, -0xd(%r12)
je 0x9042
movl (%r12), %ebp
cmpq %rbp, %r14
cmovbeq %rbp, %r14
cmovbq %r13, %r11
incq %r13
addq $0x30, %r12
jmp 0x9026
pushq $-0x1
popq %rbx
jmp 0x9123
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpq %r12, %r11
je 0x908d
movl 0x18(%rsi,%r15), %r15d
movl $0x27100, %r12d         # imm = 0x27100
cmpq %r12, %r15
cmovbq %r15, %r12
testl %r9d, %r9d
cmoveq %r15, %r12
cvtsi2sd %r14, %xmm1
cvtsi2sd %r12, %xmm2
divsd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
cmovaeq %r11, %rbx
testl %r9d, %r9d
je 0x90f9
imulq $0x30, %rbx, %r9
movl $0x40000000, %r11d      # imm = 0x40000000
andl 0x8(%rsi,%r9), %r11d
orl %ecx, %r11d
leaq 0x28(%rsi), %rcx
xorpd %xmm0, %xmm0
xorl %r14d, %r14d
cmpq %r14, %rax
je 0x90d9
testb $0x40, -0x1d(%rcx)
jne 0x90bf
testl %r11d, %r11d
jne 0x90d0
movsd (%rcx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x90d0
movq %r14, %r10
movapd %xmm1, %xmm0
incq %r14
addq $0x30, %rcx
jmp 0x90af
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %r10
je 0x90f9
imulq $0x30, %r10, %rax
movl $0x3e8, %ecx            # imm = 0x3E8
addl 0x18(%rsi,%rax), %ecx
cmpl 0x18(%rsi,%r9), %ecx
cmovaeq %r10, %rbx
testq %rdx, %rdx
je 0x9123
imulq $0x30, %rbx, %rax
addq %rax, %rsi
cmpl $0x2, %r8d
pushq $0x1
popq %rcx
cmovgel %r8d, %ecx
movl $0x64, (%rsp)
pushq $0x3c
popq %r9
xorl %r8d, %r8d
callq 0x8746
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq