// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/horder.cpp
// Function: get_max_anchor(horder_t*, sc_lay_t*, unsigned char*, double*, unsigned char*, unsigned int*, unsigned int*, unsigned int*)
uint32_t get_max_anchor(horder_t *h, sc_lay_t *sl, uint8_t *vis, double *w, uint8_t *sgv, uint32_t *idx,
uint32_t *max_utg, uint32_t *max_sc)
{
    (*max_utg) = (*max_sc) = (uint32_t)-1;
    double max_utg_w = -1;
    uint32_t i, k, v, nv, max_k;
    osg_arc_t *av = NULL;
    for (i = 0; i < h->sg.g->n_seq; i++)
    {
        if(vis[i<<1]) continue;
        if(!asg_arc_n(h->sg.g, i<<1)&&!asg_arc_n(h->sg.g, (i<<1)+1)) continue;
        for (k = 0; k < sl->n; k++) w[k] = 0, sgv[k] = 0;

        v = i<<1;
        nv = asg_arc_n(h->sg.g, v);
        av = asg_arc_a(h->sg.g, v);
        for (k = 0; k < nv; k++)
        {
            if(av[k].del || idx[av[k].v>>1] == (uint32_t)-1) continue;
            w[idx[av[k].v>>1]] += av[k].nw;
            sgv[idx[av[k].v>>1]] = 1;
        }
        

        v = (i<<1) + 1;
        nv = asg_arc_n(h->sg.g, v);
        av = asg_arc_a(h->sg.g, v);
        for (k = 0; k < nv; k++)
        {
            if(av[k].del || idx[av[k].v>>1] == (uint32_t)-1) continue;
            w[idx[av[k].v>>1]] += av[k].nw;
            sgv[idx[av[k].v>>1]] = 1;
        }

        for (k = 0, max_k = (uint32_t)-1; k < sl->n; k++)
        {
            if(!sgv[k]) continue;
            if(max_k == (uint32_t)-1 || w[max_k] < w[k]) max_k = k;
        }     

        if(max_k != (uint32_t)-1)
        {
            if((*max_utg) == (uint32_t)-1 || max_utg_w < w[max_k])
            {
                max_utg_w = w[max_k];
                (*max_utg) = i;
                (*max_sc) = max_k;
            }
        }    
    }

    return (*max_utg) == (uint32_t)-1?0:1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x40(%rsp), %rax
movq 0x38(%rsp), %r10
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movl %r11d, (%rax)
movl %r11d, (%r10)
movq 0xd8(%rdi), %r15
testl $0x7fffffff, 0x14(%r15) # imm = 0x7FFFFFFF
je 0x17ca0b
movsd 0xb4de8(%rip), %xmm0    # 0x231638
xorl %r11d, %r11d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpb $0x0, (%rdx,%r11,2)
je 0x17c87e
incq %r11
movq 0xd8(%rdi), %r15
movl 0x14(%r15), %r14d
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
cmpq %r14, %r11
jb 0x17c858
jmp 0x17ca00
leaq (%r11,%r11), %r14
movq 0x20(%r15), %r12
movq (%r12,%r14,8), %r13
testl %r13d, %r13d
jne 0x17c897
cmpl $0x0, 0x8(%r12,%r14,8)
je 0x17c85f
cmpq $0x0, 0x8(%rsi)
je 0x17c8cd
movl $0x1, %ebp
xorl %r15d, %r15d
movq $0x0, (%rcx,%r15,8)
movb $0x0, (%r8,%r15)
movl %ebp, %r15d
incl %ebp
cmpq %r15, 0x8(%rsi)
ja 0x17c8a6
movq 0xd8(%rdi), %r15
movq 0x20(%r15), %r12
movq (%r12,%r14,8), %r13
movq 0x8(%r15), %r15
testl %r13d, %r13d
je 0x17c935
movq %r13, %r12
shrq $0x1b, %r12
andq $-0x20, %r12
addq %r12, %r15
movl %r13d, %r12d
shlq $0x5, %r12
xorl %r13d, %r13d
cmpl $0x0, 0x8(%r15,%r13)
js 0x17c91b
movl (%r15,%r13), %ebp
shrl %ebp
movl (%r9,%rbp,4), %ebp
cmpq %rbx, %rbp
je 0x17c91b
movsd 0x18(%r15,%r13), %xmm1
addsd (%rcx,%rbp,8), %xmm1
movsd %xmm1, (%rcx,%rbp,8)
movb $0x1, (%r8,%rbp)
addq $0x20, %r13
cmpq %r13, %r12
jne 0x17c8ee
movq 0xd8(%rdi), %r12
movq 0x8(%r12), %r15
movq 0x20(%r12), %r12
movq 0x8(%r12,%r14,8), %r14
testl %r14d, %r14d
je 0x17c990
movq %r14, %r12
shrq $0x1b, %r12
andq $-0x20, %r12
addq %r12, %r15
movl %r14d, %r14d
shlq $0x5, %r14
xorl %r12d, %r12d
cmpl $0x0, 0x8(%r15,%r12)
js 0x17c987
movl (%r15,%r12), %r13d
shrl %r13d
movl (%r9,%r13,4), %r13d
cmpq %rbx, %r13
je 0x17c987
movsd 0x18(%r15,%r12), %xmm1
addsd (%rcx,%r13,8), %xmm1
movsd %xmm1, (%rcx,%r13,8)
movb $0x1, (%r8,%r13)
addq $0x20, %r12
cmpq %r12, %r14
jne 0x17c957
movq 0x8(%rsi), %r14
testq %r14, %r14
je 0x17c85f
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r15d, %r15d
cmpb $0x0, (%r8,%r15)
je 0x17c9c5
cmpl $-0x1, %ebp
je 0x17c9c2
movl %ebp, %r12d
movsd (%rcx,%r15,8), %xmm1
ucomisd (%rcx,%r12,8), %xmm1
jbe 0x17c9c5
movl %r15d, %ebp
incq %r15
movl %r15d, %r12d
cmpq %r12, %r14
ja 0x17c9a5
cmpl $-0x1, %ebp
je 0x17c85f
cmpl $-0x1, (%r10)
movl %ebp, %r14d
movsd (%rcx,%r14,8), %xmm1
je 0x17c9f2
ucomisd %xmm0, %xmm1
jbe 0x17c85f
movl %r11d, (%r10)
movl %ebp, (%rax)
movapd %xmm1, %xmm0
jmp 0x17c85f
xorl %eax, %eax
cmpl $-0x1, (%r10)
setne %al
jmp 0x17ca0d
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq