// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movq %rdi, %rbx
cmpq $0x0, (%rsi)
je 0x148266
movl $0x1, %ebp
xorl %r13d, %r13d
movl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movl $0x10, %r12d
movl 0x4(%rbx), %ecx
andl %r15d, %ecx
movl (%rbx), %eax
cmpl %eax, %ecx
jne 0x148214
leal (%rax,%rax), %ecx
testl %eax, %eax
cmovel %r12d, %ecx
movl %ecx, (%rbx)
movq 0x8(%rbx), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq %rax, 0x8(%rbx)
movq 0x8(%rbx), %rax
movl 0x4(%rbx), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leal 0x1(%rcx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %esi, %ecx
movl %ecx, 0x4(%rbx)
leaq (%rdx,%rdx,2), %rcx
movq 0x10(%r14), %rdx
leaq (,%r13,2), %rsi
addq %r13, %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, %r13d
incl %ebp
cmpq %r13, (%r14)
ja 0x1481e8
andb $0x7f, 0x7(%rbx)
movq 0x28(%rbx), %rdi
callq 0x2220
movq $0x0, 0x28(%rbx)
movq %rbx, %rdi
callq 0xa02fa
movq (%r14), %rax
movq 0x10(%r14), %rdi
leaq (%rax,%rax,2), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x132cd3
movq (%r14), %rax
testq %rax, %rax
je 0x1484ba
movl $0x1, %r10d
xorl %edi, %edi
movl $0x1, %esi
leaq 0x40(%rsp), %r11
leaq 0x48(%rsp), %r15
leaq 0xc(%rsp), %rcx
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq %rbx, 0x18(%rsp)
movq %r14, 0x10(%rsp)
cmpq %rsi, %rax
je 0x1482f7
movq 0x10(%r14), %rax
leaq (%rsi,%rsi,2), %rsi
movl %edi, %edx
leaq (%rdx,%rdx,2), %rdx
movq (%rax,%rdx,8), %rdx
xorq (%rax,%rsi,8), %rdx
shrq $0x20, %rdx
jne 0x1482f7
movl %edi, %edx
jmp 0x1484a6
movl %r10d, %eax
subl %edi, %eax
movl %r10d, %edx
cmpl $0x2, %eax
jb 0x1484a6
movl %r10d, %r13d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %edi, %r10d
jbe 0x1483ca
movq %r10, 0x30(%rsp)
movq %r13, 0x20(%rsp)
movq %rdi, 0x28(%rsp)
movl %edi, %r13d
leaq (,%r13,2), %rax
addq %r13, %rax
leaq 0x8(,%rax,8), %rbp
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq $-0x1, %r14
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rax,%rbp), %edx
movq 0x18(%rsp), %rdi
xorl %esi, %esi
leaq 0x38(%rsp), %r8
leaq 0x50(%rsp), %r9
pushq $0x0
pushq $0x1
pushq %r11
pushq %r15
movq %r15, %rbx
movq %r11, %r15
callq 0x10109f
leaq 0x2c(%rsp), %rcx
movq %r15, %r11
movq %rbx, %r15
addq $0x20, %rsp
movq 0x38(%rsp), %rax
cmpq %rax, %r14
cmovll %r13d, %r12d
cmovleq %rax, %r14
incq %r13
addq $0x18, %rbp
cmpq %r13, 0x20(%rsp)
jne 0x14834b
movl %r12d, %eax
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rbx
movq 0x30(%rsp), %r10
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq 0x20(%rsp), %r13
movq 0x28(%rsp), %rdi
movl %r10d, %edx
cmpl %edi, %r10d
jbe 0x1484a6
movl %edi, %ecx
cmpq %rax, %rcx
je 0x148492
movq 0x10(%r14), %rsi
leaq (%rcx,%rcx,2), %rdx
movl 0x4(%rsi,%rdx,8), %edi
movq 0x28(%rbx), %r8
movq (%r8,%rdi,8), %r8
movq %r8, %rdi
andq %r12, %rdi
je 0x148436
movl 0x8(%rsi,%rdx,8), %esi
movq 0x8(%rbx), %r9
shrq $0x20, %r8
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rdi
leaq (%r8,%r8,2), %r8
leaq (%r9,%r8,8), %r8
addq $0xc, %r8
xorl %r9d, %r9d
cmpl %esi, -0x4(%r8,%r9)
jne 0x14842d
orb $-0x80, 0x3(%r8,%r9)
addq $0x18, %r9
cmpq %r9, %rdi
jne 0x148420
movq 0x10(%r14), %rsi
movl 0x8(%rsi,%rdx,8), %edi
xorq $0x1, %rdi
movq 0x28(%rbx), %r8
movq (%r8,%rdi,8), %rdi
movq %rdi, %r8
andq %r12, %r8
je 0x148492
movl 0x4(%rsi,%rdx,8), %edx
movq 0x8(%rbx), %r9
shrq $0x20, %rdi
shlq $0x3, %r8
leaq (%r8,%r8,2), %rsi
leaq (%rdi,%rdi,2), %rdi
leaq (%r9,%rdi,8), %rdi
addq $0xc, %rdi
xorl %r8d, %r8d
movl -0x4(%rdi,%r8), %r9d
xorl %edx, %r9d
cmpl $0x1, %r9d
jne 0x148489
orb $-0x80, 0x3(%rdi,%r8)
addq $0x18, %r8
cmpq %r8, %rsi
jne 0x148475
incq %rcx
cmpq %r13, %rcx
jne 0x1483d8
movl %r10d, %edx
leaq 0xc(%rsp), %rcx
incl %r10d
movq (%r14), %rax
movq %r10, %rsi
movl %edx, %edi
cmpq %r10, %rax
jae 0x1482cf
movq %rbx, %rdi
callq 0xa02fa
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq