// File: 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
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x15a7bc
cmpq $0x1, -0x8(%rbp)
jne 0x15a675
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
cmpq $-0x1, -0x8(%rbp)
jne 0x15a6a5
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
cmpq $0x0, -0x28(%rbp)
je 0x15a7b7
movq -0x10(%rbp), %rax
subq -0x8(%rbp), %rax
movq %rax, -0x10(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x10(%rbp)
movb %al, -0x45(%rbp)
jl 0x15a6dc
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
setl %al
movb %al, -0x45(%rbp)
movb -0x45(%rbp), %al
testb $0x1, %al
jne 0x15a6e8
jmp 0x15a7b5
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x44(%rbp)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x44(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orl $0x0, %edx
movl %edx, (%rax,%rcx,8)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x15a7a2
movl -0x44(%rbp), %eax
shrl %eax
movl %eax, %eax
movq -0x28(%rbp), %rcx
movq 0x10(%rcx), %rcx
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
shrq $0x21, %rcx
cmpq %rcx, %rax
je 0x15a773
movl -0x44(%rbp), %eax
shrl %eax
movq -0x28(%rbp), %rcx
movq 0x10(%rcx), %rcx
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
cmpl %ecx, %eax
jne 0x15a792
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, 0xc(%rax)
jmp 0x15a794
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x15a725
jmp 0x15a7a4
movq -0x10(%rbp), %rax
subq -0x8(%rbp), %rax
movq %rax, -0x10(%rbp)
jmp 0x15a6bc
jmp 0x15a7b7
jmp 0x15a98d
cmpq $-0x1, -0x8(%rbp)
jne 0x15a8b6
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
subq $0x1, %rcx
cmpq %rcx, %rax
je 0x15a8b6
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x10(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
shrq $0x20, %rdx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
shlq $0x20, %rdx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
orq -0x38(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
cmpq $0x1, -0x8(%rbp)
jne 0x15a922
cmpq $0x0, -0x10(%rbp)
je 0x15a922
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
jae 0x15a90e
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rcx
subq -0x10(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x15a8cc
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
subq -0x10(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
andl $0x80000000, %ecx       # imm = 0x80000000
orl $0x0, %ecx
movl %ecx, (%rax)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
jae 0x15a98b
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl (%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
addl %ecx, %edx
movl (%rax), %ecx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %edx, %ecx
movl %ecx, (%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x15a93b
jmp 0x15a98d
popq %rbp
retq
nop