// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: polish_unitig_scaffold(unsigned int, ma_utg_t*, asg_t*, All_reads*, ma_hit_t_alloc*, ma_sub_t*, kvec_asg_arc_t_warp*, UC_Read*, UC_Read*, int, int, kvec_asg_arc_t_warp*)
void polish_unitig_scaffold(uint32_t uid, ma_utg_t* collection, asg_t* read_g, All_reads *RNF, 
ma_hit_t_alloc* sources, ma_sub_t *coverage_cut, kvec_asg_arc_t_warp* edge, 
UC_Read* r_read, UC_Read* q_read, int max_hang, int min_ovlp, kvec_asg_arc_t_warp* newE)
{
    uint32_t i, k, m, len, p_idx;
    ma_utg_t qu;
    for (i = p_idx = m = len = 0; i < collection->n; i++)
    {
        if(collection->a[i] == (uint64_t)-1)
        {
            qu.a = collection->a + p_idx;
            qu.circ = 0;
            qu.m = qu.n = i - p_idx;
            for (k = qu.len = 0; k < qu.n; k++)
            {
                qu.len += (uint32_t)qu.a[k];
            }

            polish_unitig(&qu, read_g, sources, coverage_cut, edge, max_hang, min_ovlp, newE);
            polish_unitig_advance(&qu, read_g, &R_INF, sources, coverage_cut, edge, r_read, q_read, max_hang, min_ovlp, newE);
            
            for (k = 0; k < qu.n; k++)
            {
                collection->a[m] = qu.a[k];
                m++;
            }
            len += qu.len;

            collection->a[m] = (uint64_t)-1;
            m++;
            len += GAP_LEN;
            p_idx = i + 1;
        }
    }

    if(i - p_idx > 0)
    {
        qu.a = collection->a + p_idx;
        qu.circ = collection->circ;
        qu.m = qu.n = i - p_idx;
        for (k = qu.len = 0; k < qu.n; k++)
        {
            qu.len += (uint32_t)qu.a[k];
        }
    
        polish_unitig(&qu, read_g, sources, coverage_cut, edge, max_hang, min_ovlp, newE);
        polish_unitig_advance(&qu, read_g, &R_INF, sources, coverage_cut, edge, r_read, q_read, max_hang, min_ovlp, newE);
        
        for (k = 0; k < qu.n; k++)
        {
            collection->a[m] = qu.a[k];
            m++;
        }
        len += qu.len;
    }
    collection->n = m;
    collection->len = len;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xa0, %rsp
movq 0x38(%rbp), %rax
movl 0x30(%rbp), %eax
movl 0x28(%rbp), %eax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movl %edi, -0x14(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0xeda61
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x44(%rbp), %ecx
cmpq $-0x1, (%rax,%rcx,8)
jne 0xeda51
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x54(%rbp), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movl -0x80(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
orl $0x0, %eax
movl %eax, -0x80(%rbp)
movl -0x44(%rbp), %eax
subl -0x54(%rbp), %eax
movl %eax, -0x70(%rbp)
movl %eax, -0x74(%rbp)
movl -0x80(%rbp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
orl $0x0, %eax
movl %eax, -0x80(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x70(%rbp), %eax
jae 0xed95e
movq -0x68(%rbp), %rax
movl -0x48(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl -0x80(%rbp), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addl %eax, %ecx
movl -0x80(%rbp), %eax
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl $0x80000000, %eax       # imm = 0x80000000
orl %ecx, %eax
movl %eax, -0x80(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xed922
movq -0x28(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq 0x10(%rbp), %r8
movl 0x28(%rbp), %r9d
movl 0x30(%rbp), %r10d
movq 0x38(%rbp), %rax
leaq -0x80(%rbp), %rdi
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0xeaa00
movq -0x28(%rbp), %rsi
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
movq 0x10(%rbp), %r9
movq 0x18(%rbp), %r14
movq 0x20(%rbp), %rbx
movl 0x28(%rbp), %r11d
movl 0x30(%rbp), %r10d
movq 0x38(%rbp), %rax
leaq -0x80(%rbp), %rdi
leaq 0x2d7915(%rip), %rdx    # 0x3c52d0
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0xec620
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x70(%rbp), %eax
jae 0xeda15
movq -0x68(%rbp), %rax
movl -0x48(%rbp), %ecx
movq (%rax,%rcx,8), %rdx
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x4c(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xed9df
movl -0x80(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x4c(%rbp), %ecx
movq $-0x1, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movl -0x50(%rbp), %eax
addl $0x64, %eax
movl %eax, -0x50(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0xeda53
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xed8b7
movl -0x44(%rbp), %eax
subl -0x54(%rbp), %eax
cmpl $0x0, %eax
jbe 0xedbc4
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x54(%rbp), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %ecx
shrl $0x1f, %ecx
movl -0x80(%rbp), %eax
andl $0x1, %ecx
shll $0x1f, %ecx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
orl %ecx, %eax
movl %eax, -0x80(%rbp)
movl -0x44(%rbp), %eax
subl -0x54(%rbp), %eax
movl %eax, -0x70(%rbp)
movl %eax, -0x74(%rbp)
movl -0x80(%rbp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
orl $0x0, %eax
movl %eax, -0x80(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x70(%rbp), %eax
jae 0xedaff
movq -0x68(%rbp), %rax
movl -0x48(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl -0x80(%rbp), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addl %eax, %ecx
movl -0x80(%rbp), %eax
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl $0x80000000, %eax       # imm = 0x80000000
orl %ecx, %eax
movl %eax, -0x80(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xedac3
movq -0x28(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq 0x10(%rbp), %r8
movl 0x28(%rbp), %r9d
movl 0x30(%rbp), %r10d
movq 0x38(%rbp), %rax
leaq -0x80(%rbp), %rdi
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0xeaa00
movq -0x28(%rbp), %rsi
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
movq 0x10(%rbp), %r9
movq 0x18(%rbp), %r14
movq 0x20(%rbp), %rbx
movl 0x28(%rbp), %r11d
movl 0x30(%rbp), %r10d
movq 0x38(%rbp), %rax
leaq -0x80(%rbp), %rdi
leaq 0x2d7774(%rip), %rdx    # 0x3c52d0
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0xec620
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x70(%rbp), %eax
jae 0xedbb6
movq -0x68(%rbp), %rax
movl -0x48(%rbp), %ecx
movq (%rax,%rcx,8), %rdx
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x4c(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xedb80
movl -0x80(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x4c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x50(%rbp), %edx
movq -0x20(%rbp), %rax
movl (%rax), %ecx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %edx, %ecx
movl %ecx, (%rax)
addq $0xa0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopw %cs:(%rax,%rax)