// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1e2cf2
movq -0x8(%rbp), %rdi
callq 0x1cef50
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movl -0x1c(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1e2ca2
movq -0x8(%rbp), %rax
movl 0x4(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x8(%rbp), %rdi
callq 0xcdd10
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x10(%rbp), %rax
imulq $0x18, (%rax), %rax
addq %rax, %rsi
callq 0x1bc970
movl $0x1, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
ja 0x1e2f15
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
je 0x1e2dac
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x20(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
je 0x1e2f05
movl -0x1c(%rbp), %eax
subl -0x20(%rbp), %eax
cmpl $0x1, %eax
jbe 0x1e2eff
movl -0x20(%rbp), %eax
movl %eax, -0x24(%rbp)
movq $-0x1, -0x38(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movl -0x24(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x1e2e4d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rcx
leaq -0x40(%rbp), %r8
leaq -0x48(%rbp), %r9
leaq -0x50(%rbp), %r10
leaq -0x58(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
callq 0x166c30
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jge 0x1e2e40
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x1e2e42
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1e2dd0
movl -0x20(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x1e2efd
movl -0x24(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0x1e2e6c
jmp 0x1e2eef
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, %esi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movl $0x1, %ecx
callq 0x1de8a0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movl %eax, %edx
movl $0x1, %ecx
callq 0x1de8a0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1e2e53
jmp 0x1e2eff
movl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x1e2f07
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1e2d55
movq -0x8(%rbp), %rdi
callq 0xcdd10
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)