// File: /workspace/github_cpp_makefile_star2_O3/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 0xfcdae
cmpq $-0x1, %rdi
je 0xfcdd1
cmpq $0x1, %rdi
setne %cl
testq %rsi, %rsi
sete %dil
movl 0x10(%rdx), %eax
orb %cl, %dil
jne 0xfce05
movq %rax, %rcx
subq %rsi, %rcx
jbe 0xfcda7
movq 0x18(%rdx), %rdi
movq (%rdi,%rsi,8), %r8
movq %r8, (%rdi)
addq $0x8, %rdi
decq %rcx
jne 0xfcd97
subl %esi, %eax
movl %eax, 0x10(%rdx)
jmp 0xfce05
cmpq $-0x1, %rdi
je 0xfce44
cmpq $0x1, %rdi
jne 0xfce5a
movq 0x18(%rdx), %rax
movl 0x4(%rax), %eax
movl %eax, 0x4(%rdx)
jmp 0xfce5a
movl 0x10(%rdx), %eax
movq %rax, %rdi
decq %rdi
cmpq %rsi, %rdi
je 0xfce05
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)
movl $0x80000000, %ecx       # imm = 0x80000000
andl (%rdx), %ecx
movl %ecx, (%rdx)
testl %eax, %eax
je 0xfcec9
movl %eax, %eax
movq 0x18(%rdx), %rsi
xorl %edi, %edi
movl (%rsi,%rdi,8), %r8d
addl %ecx, %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %r8d, %ecx
movl %ecx, (%rdx)
incq %rdi
cmpq %rdi, %rax
jne 0xfce1e
jmp 0xfcec9
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 0xfcec9
subq %rdi, %rsi
js 0xfcec9
movl 0x10(%rdx), %eax
cmpq %rax, %rsi
jae 0xfcec9
movq 0x18(%rdx), %rax
movq (%rax,%rsi,8), %rax
movq 0x20(%rcx), %r9
shrq $0x21, %rax
andl $0x7fffffff, (%r9,%rax,8) # imm = 0x7FFFFFFF
movq (%r8), %r9
testq %r9, %r9
je 0xfce5f
movl $0xc, %r10d
xorl %r11d, %r11d
movq 0x10(%r8), %rbx
movq -0xc(%rbx,%r10), %r14
shrq $0x21, %r14
cmpl %r14d, %eax
je 0xfceb2
movl -0x4(%rbx,%r10), %ebp
shrl %ebp
cmpl %eax, %ebp
jne 0xfcebb
andb $0x7f, 0x3(%rbx,%r10)
movq (%r8), %r9
incq %r11
addq $0x18, %r10
cmpq %r9, %r11
jb 0xfce95
jmp 0xfce5f
popq %rbx
popq %r14
popq %rbp
retq