// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/hic.cpp
// Function: update_bsg(asg_t*, kvec_asg_arc_t_warp*)
void update_bsg(asg_t *bsg, kvec_asg_arc_t_warp* edges)
{
    asg_arc_t *t = NULL;
    uint32_t k, l, i, convex, max_i;
    long long max, nodeLen, baseLen, max_stop_nodeLen, max_stop_baseLen;

    for (k = 0; k < edges->a.n; k++)
    {   
        t = asg_arc_pushp(bsg);
        *t = edges->a.a[k];
    }
    bsg->is_srt = 0; free(bsg->idx); bsg->idx = 0;
    asg_cleanup(bsg);



    radix_sort_asg_e(edges->a.a, edges->a.a + edges->a.n);
    for (k = 1, l = 0; k <= edges->a.n; ++k)
    {
        if (k == edges->a.n || (edges->a.a[k].ul>>32) != (edges->a.a[l].ul>>32))
        {
            if(k - l > 1)
            {
                for (i = l, max = -1, max_i = (uint32_t)-1; i < k; i++)
                {
                    get_unitig(bsg, NULL, edges->a.a[i].v, &convex, &nodeLen, &baseLen, &max_stop_nodeLen, 
                                                                    &max_stop_baseLen, 1, NULL);
                    if(max < nodeLen) max = nodeLen, max_i = i;
                }

                ///fprintf(stderr, "k - l: %u, max_i: %u\n", k - l, max_i);
                for (i = l; i < k; i++)
                {
                    // fprintf(stderr, "i: %u, +t->ul>>32: %lu, t->v: %u\n", 
                    //                     i, edges->a.a[i].ul>>32, edges->a.a[i].v);
                    if(i == max_i) continue;
                    asg_arc_del(bsg, (edges->a.a[i].ul>>32), (edges->a.a[i].v), 1);
                    asg_arc_del(bsg, (edges->a.a[i].v)^1, (edges->a.a[i].ul>>32)^1, 1);
                    ///edges->a.a[i].del = 1;
                }
            }
            l = k;
        }
    }
    
    asg_cleanup(bsg);
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r12
movq %rdi, (%rsp)
xorl %eax, %eax
movl %eax, %ebx
cmpq %rbx, (%r12)
jbe 0x10671d
movq (%rsp), %rdi
callq 0xfbf83
movq 0x10(%r12), %rcx
imulq $0x18, %rbx, %rdx
movups (%rcx,%rdx), %xmm0
movups %xmm0, (%rax)
movq 0x10(%rcx,%rdx), %rcx
movq %rcx, 0x10(%rax)
leal 0x1(%rbx), %eax
jmp 0x1066ee
movq (%rsp), %rbx
andb $0x7f, 0x7(%rbx)
movq 0x28(%rbx), %rdi
callq 0x2220
andq $0x0, 0x28(%rbx)
movq %rbx, %rdi
callq 0x694eb
movq 0x10(%r12), %rdi
imulq $0x18, (%r12), %rsi
addq %rdi, %rsi
callq 0xf254c
xorl %eax, %eax
pushq $0x1
popq %rdi
movq %r12, 0x10(%rsp)
movl %edi, %r8d
cmpq %r8, (%r12)
jb 0x106871
movl %eax, %r14d
je 0x106788
movq 0x10(%r12), %rcx
imulq $0x18, %r8, %rdx
imulq $0x18, %r14, %rsi
movq (%rcx,%rsi), %rsi
xorq (%rcx,%rdx), %rsi
shrq $0x20, %rsi
je 0x10686a
movl %edi, %ecx
subl %eax, %ecx
movl %edi, %eax
cmpl $0x2, %ecx
jb 0x10686a
movq %r8, 0x18(%rsp)
movl %edi, 0xc(%rsp)
imulq $0x18, %r14, %r13
addq $0x8, %r13
movq %r13, %r12
movq %r14, %r15
pushq $-0x1
popq %rbx
pushq $-0x1
popq %rbp
cmpq 0x18(%rsp), %r15
jae 0x10680f
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rax,%r12), %edx
movq (%rsp), %rdi
xorl %esi, %esi
leaq 0x2c(%rsp), %rcx
leaq 0x20(%rsp), %r8
leaq 0x40(%rsp), %r9
pushq $0x0
pushq $0x1
leaq 0x40(%rsp), %rax
pushq %rax
leaq 0x50(%rsp), %rax
pushq %rax
callq 0xc2ebf
addq $0x20, %rsp
movq 0x20(%rsp), %rax
cmpq %rax, %rbp
cmovll %r15d, %ebx
cmovleq %rax, %rbp
incq %r15
addq $0x18, %r12
jmp 0x1067b4
movl %ebx, %ebx
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %rbp
cmpq %rbp, %r14
jae 0x106864
cmpq %r14, %rbx
je 0x10685b
movq 0x10(%r12), %rax
movl -0x4(%rax,%r13), %esi
movl (%rax,%r13), %edx
movq (%rsp), %r15
movq %r15, %rdi
callq 0x10433c
movq 0x10(%r12), %rax
movl -0x4(%rax,%r13), %edx
movl (%rax,%r13), %esi
xorl $0x1, %esi
xorl $0x1, %edx
movq %r15, %rdi
callq 0x10433c
incq %r14
addq $0x18, %r13
jmp 0x10681b
movl 0xc(%rsp), %edi
movl %edi, %eax
incl %edi
jmp 0x106757
movq (%rsp), %rdi
callq 0x694eb
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq