// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
movq %rsi, %r13
movq %rdi, %rbx
cmpq $0x0, (%rsi)
je 0x14e7e8
movl $0x1, %ebp
xorl %r12d, %r12d
movl $0x10, %r15d
movl 0x4(%rbx), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl (%rbx), %ecx
jne 0x14e7a5
leal (%rcx,%rcx), %eax
testl %ecx, %ecx
cmovel %r15d, %eax
movl %eax, (%rbx)
movq 0x8(%rbx), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq %rax, 0x8(%rbx)
movl 0x4(%rbx), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0x14e7a9
movq 0x8(%rbx), %rax
leal 0x1(%rdx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %esi, %edx
movl %edx, 0x4(%rbx)
movl %ecx, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%r13), %rdx
leaq (%r12,%r12,2), %rsi
movq 0x10(%rdx,%rsi,8), %rdi
movq %rdi, 0x10(%rax,%rcx,8)
movups (%rdx,%rsi,8), %xmm0
movups %xmm0, (%rax,%rcx,8)
movl %ebp, %r12d
incl %ebp
cmpq %r12, (%r13)
ja 0x14e769
andb $0x7f, 0x7(%rbx)
movq 0x28(%rbx), %rdi
callq 0x2220
movq $0x0, 0x28(%rbx)
movq %rbx, 0x10(%rsp)
movq %rbx, %rdi
callq 0xa0a7d
movq (%r13), %rax
movq 0x10(%r13), %rdi
leaq (%rax,%rax,2), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x138e9d
movq (%r13), %rax
testq %rax, %rax
je 0x14ea53
movl $0x1, %r12d
xorl %ebx, %ebx
movl $0x1, %esi
leaq 0x20(%rsp), %r10
leaq 0x28(%rsp), %r11
leaq 0xc(%rsp), %rcx
leaq 0x48(%rsp), %r8
movq %r13, 0x18(%rsp)
cmpq %rsi, %rax
je 0x14e87a
movq 0x10(%r13), %rax
leaq (%rsi,%rsi,2), %rsi
movl %ebx, %edx
leaq (%rdx,%rdx,2), %rdx
movq (%rax,%rdx,8), %rdx
xorq (%rax,%rsi,8), %rdx
shrq $0x20, %rdx
jne 0x14e87a
movl %ebx, %edx
jmp 0x14ea3e
movl %r12d, %eax
subl %ebx, %eax
movl %r12d, %edx
cmpl $0x2, %eax
jb 0x14ea3e
movl %r12d, %edx
cmpl %ebx, %r12d
jbe 0x14ea3e
movq %r12, 0x40(%rsp)
movl %r12d, %r9d
movq %rbx, 0x38(%rsp)
movl %ebx, %r12d
leaq (%r12,%r12,2), %rax
leaq 0x8(,%rax,8), %r13
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq $-0x1, %rbp
movq %r12, 0x30(%rsp)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rax,%r13), %edx
movq 0x10(%rsp), %rdi
xorl %esi, %esi
movq %r8, %rbx
movq %r9, %r15
leaq 0x50(%rsp), %r9
pushq $0x0
pushq $0x1
pushq %r10
pushq %r11
callq 0x1053a7
movq %r15, %r9
movq %rbx, %r8
leaq 0x2c(%rsp), %rcx
leaq 0x48(%rsp), %r11
leaq 0x40(%rsp), %r10
addq $0x20, %rsp
movq 0x48(%rsp), %rax
cmpq %rax, %rbp
cmovll %r12d, %r14d
cmovleq %rax, %rbp
incq %r12
addq $0x18, %r13
cmpq %r12, %r15
jne 0x14e8c5
movq 0x40(%rsp), %r12
movl %r12d, %edx
cmpl 0x38(%rsp), %r12d
movq 0x18(%rsp), %r13
jbe 0x14ea3e
movl %r14d, %eax
movq 0x10(%rsp), %r11
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq 0x30(%rsp), %r10
cmpq %rax, %r10
je 0x14ea1d
movq 0x10(%r13), %rdx
movq %r10, %rbp
leaq (%r10,%r10,2), %rdi
movq (%rdx,%rdi,8), %rcx
shrq $0x20, %rcx
movl 0x8(%rdx,%rdi,8), %edx
movq 0x8(%r11), %rsi
movq 0x28(%r11), %r8
movq (%r8,%rcx,8), %r9
movq %r9, %r10
andq %r14, %r10
je 0x14e9d2
shrq $0x20, %r9
shlq $0x3, %r10
leaq (%r10,%r10,2), %rcx
leaq (%r9,%r9,2), %r8
leaq (%rsi,%r8,8), %rsi
addq $0xc, %rsi
xorl %r8d, %r8d
movq %r15, %r9
movq %rbp, %r10
cmpl %edx, -0x4(%rsi,%r8)
jne 0x14e9b3
orb $-0x80, 0x3(%rsi,%r8)
addq $0x18, %r8
cmpq %r8, %rcx
jne 0x14e9a6
movq 0x10(%r13), %rdx
movl 0x4(%rdx,%rdi,8), %ecx
movl 0x8(%rdx,%rdi,8), %edx
movq 0x8(%r11), %rsi
movq 0x28(%r11), %r8
jmp 0x14e9d8
movq %r15, %r9
movq %rbp, %r10
xorl $0x1, %edx
movq (%r8,%rdx,8), %rdi
movq %rdi, %rdx
andq %r14, %rdx
je 0x14ea1d
shrq $0x20, %rdi
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rdi,%rdi,2), %rdi
leaq (%rsi,%rdi,8), %rsi
addq $0xc, %rsi
xorl %edi, %edi
movl -0x4(%rsi,%rdi), %r8d
xorl %ecx, %r8d
cmpl $0x1, %r8d
jne 0x14ea14
orb $-0x80, 0x3(%rsi,%rdi)
addq $0x18, %rdi
cmpq %rdi, %rdx
jne 0x14ea01
incq %r10
cmpq %r9, %r10
jne 0x14e951
movl %r12d, %edx
leaq 0x20(%rsp), %r10
leaq 0x28(%rsp), %r11
leaq 0xc(%rsp), %rcx
movq %rbx, %r8
incl %r12d
movq (%r13), %rax
movq %r12, %rsi
movl %edx, %ebx
cmpq %r12, %rax
jae 0x14e852
movq 0x10(%rsp), %rdi
callq 0xa0a7d
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq