// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: update_unitig(long long, long long, ma_utg_t*, asg_t*, kvec_asg_arc_t_warp*, unsigned int)
void update_unitig(long long step, long long init, ma_utg_t* nsu, asg_t *r_g, 
kvec_asg_arc_t_warp* recover_edges, uint32_t update_mode)
{
    uint64_t l, k;
    uint32_t v;
    ///recover
    if(update_mode == 0)
    {
        if(step == 1) nsu->start = ((uint64_t)(nsu->a[0])>>32);
        if(step == -1) nsu->end = ((uint64_t)(nsu->a[nsu->n-1])>>32)^1;
        if(recover_edges)
        {
            ///the first node has not been deleted, others has been deleted
            for (init = init - step; init >= 0 && init < (long long)nsu->n; init = init - step)
            {
                v = (uint64_t)nsu->a[init]>>32;
                r_g->seq[v>>1].del = 0;
                for (k = 0; k < recover_edges->a.n; k++)
                {
                    if(((v>>1)==(recover_edges->a.a[k].ul>>33)) || 
                                        ((v>>1)==(recover_edges->a.a[k].v>>1)))
                    {
                        recover_edges->a.a[k].del = 0;
                    }
                }
            }
        }
    }
    else ///update
    {
        //end of unitig
        if(step == -1 && init != (long long)((long long)nsu->n - 1))
        {
            l = r_g->seq[(nsu->a[init]>>33)].len;
            nsu->n = init+1;
            nsu->a[nsu->n-1] = nsu->a[nsu->n-1]>>32;
            nsu->a[nsu->n-1] = nsu->a[nsu->n-1]<<32;
            nsu->a[nsu->n-1] = nsu->a[nsu->n-1] | (uint64_t)(l);
        }

        //beg of unitig
        if(step == 1 && init != 0)
        {
            for(k = init; k < nsu->n; k++)
            {
                nsu->a[k-init] = nsu->a[k];
            }
            nsu->n = nsu->n - init;
        }

        nsu->len = 0;
        for(k = 0; k < nsu->n; k++)
        {
            nsu->len += (uint32_t)nsu->a[k];
        }
    }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
testl %r9d, %r9d
je 0xbb355
cmpq $-0x1, %rdi
je 0xbb378
cmpq $0x1, %rdi
setne %cl
testq %rsi, %rsi
sete %dil
movl 0x10(%rdx), %eax
orb %cl, %dil
jne 0xbb3b3
xorl %ecx, %ecx
movq %rsi, %rdi
cmpq %rax, %rdi
jae 0xbb3ae
movq 0x18(%rdx), %r8
movq (%r8,%rdi,8), %r9
movq %r9, (%r8,%rcx)
incq %rdi
addq $0x8, %rcx
jmp 0xbb33b
cmpq $-0x1, %rdi
je 0xbb3e7
cmpq $0x1, %rdi
jne 0xbb3fd
movq 0x18(%rdx), %rax
movl 0x4(%rax), %eax
movl %eax, 0x4(%rdx)
jmp 0xbb3fd
movl 0x10(%rdx), %eax
movq %rax, %rdi
decq %rdi
cmpq %rsi, %rdi
je 0xbb3b3
movq 0x20(%rcx), %rax
movq 0x18(%rdx), %rcx
movq (%rcx,%rsi,8), %rdi
shrq $0x21, %rdi
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl (%rax,%rdi,8), %r8d
leal 0x1(%rsi), %eax
movl %eax, 0x10(%rdx)
movl %esi, %esi
movl %r8d, (%rcx,%rsi,8)
jmp 0xbb3b3
subl %esi, %eax
movl %eax, 0x10(%rdx)
movl $0x80000000, %ecx       # imm = 0x80000000
andl (%rdx), %ecx
movl %ecx, (%rdx)
movl %eax, %eax
xorl %esi, %esi
cmpq %rsi, %rax
je 0xbb46a
movq 0x18(%rdx), %rdi
movl (%rdi,%rsi,8), %edi
addl %ecx, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %edi, %ecx
movl %ecx, (%rdx)
incq %rsi
jmp 0xbb3c0
movq 0x18(%rdx), %rax
movl 0x10(%rdx), %r9d
decl %r9d
movl 0x4(%rax,%r9,8), %eax
xorl $0x1, %eax
movl %eax, 0x8(%rdx)
testq %r8, %r8
je 0xbb46a
movabsq $0xc, %rax
subq %rdi, %rsi
js 0xbb46a
movl 0x10(%rdx), %r9d
cmpq %r9, %rsi
jae 0xbb46a
movq 0x18(%rdx), %r9
movq (%r9,%rsi,8), %r9
movq 0x20(%rcx), %r10
shrq $0x21, %r9
andl $0x7fffffff, (%r10,%r9,8) # imm = 0x7FFFFFFF
movq %rax, %r10
xorl %r11d, %r11d
cmpq (%r8), %r11
jae 0xbb40c
movq 0x10(%r8), %rbx
movq -0xc(%rbx,%r10), %r14
shrq $0x21, %r14
cmpl %r14d, %r9d
je 0xbb45b
movl -0x4(%rbx,%r10), %ebp
shrl %ebp
cmpl %r9d, %ebp
jne 0xbb461
andb $0x7f, 0x3(%rbx,%r10)
incq %r11
addq $0x18, %r10
jmp 0xbb438
popq %rbx
popq %r14
popq %rbp
retq