// File: /workspace/github_cpp_makefile_star2_O1/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 %rbx
testl %r9d, %r9d
je 0xf982f
cmpq $-0x1, %rdi
jne 0xf97ba
movl 0x10(%rdx), %eax
decq %rax
cmpq %rsi, %rax
je 0xf97ba
movq 0x20(%rcx), %rax
movq 0x18(%rdx), %rcx
movq (%rcx,%rsi,8), %r8
shrq $0x21, %r8
movl (%rax,%r8,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leal 0x1(%rsi), %r8d
movl %r8d, 0x10(%rdx)
movl %esi, %r8d
movl 0x4(%rcx,%r8,8), %r9d
shlq $0x20, %r9
orq %rax, %r9
movq %r9, (%rcx,%r8,8)
cmpq $0x1, %rdi
setne %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
jne 0xf97ef
movl 0x10(%rdx), %eax
movq %rax, %rcx
subq %rsi, %rcx
jbe 0xf97ea
movq 0x18(%rdx), %rdi
movq (%rdi,%rsi,8), %r8
movq %r8, (%rdi)
addq $0x8, %rdi
decq %rcx
jne 0xf97da
subl %esi, %eax
movl %eax, 0x10(%rdx)
andl $0x80000000, (%rdx)     # imm = 0x80000000
movl 0x10(%rdx), %eax
testq %rax, %rax
je 0xf98c6
movq 0x18(%rdx), %rcx
movl (%rdx), %esi
xorl %edi, %edi
movl (%rcx,%rdi,8), %r8d
addl %esi, %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl $0x80000000, %esi       # imm = 0x80000000
orl %r8d, %esi
movl %esi, (%rdx)
incq %rdi
cmpq %rdi, %rax
jne 0xf9809
jmp 0xf98c6
cmpq $-0x1, %rdi
je 0xf9847
cmpq $0x1, %rdi
jne 0xf985d
movq 0x18(%rdx), %rax
movl 0x4(%rax), %eax
movl %eax, 0x4(%rdx)
jmp 0xf985d
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 0xf98c6
subq %rdi, %rsi
js 0xf98c6
movl 0x10(%rdx), %eax
cmpq %rax, %rsi
jge 0xf98c6
movq 0x18(%rdx), %rax
movq (%rax,%rsi,8), %rax
movq 0x20(%rcx), %r9
shrq $0x21, %rax
andl $0x7fffffff, (%r9,%rax,8) # imm = 0x7FFFFFFF
cmpq $0x0, (%r8)
je 0xf9862
movl $0xc, %r9d
xorl %r10d, %r10d
movq 0x10(%r8), %r11
movq -0xc(%r11,%r9), %rbx
shrq $0x21, %rbx
cmpl %ebx, %eax
je 0xf98b2
movl -0x4(%r11,%r9), %ebx
shrl %ebx
cmpl %eax, %ebx
jne 0xf98b8
andb $0x7f, 0x3(%r11,%r9)
incq %r10
addq $0x18, %r9
cmpq (%r8), %r10
jb 0xf9896
jmp 0xf9862
popq %rbx
retq