// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x50(%rsp)
movq %r8, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
cmpl $0x0, 0x10(%rsi)
movq %rsi, 0x8(%rsp)
je 0xb5d22
xorl %ebp, %ebp
xorl %eax, %eax
xorl %r15d, %r15d
xorl %r10d, %r10d
movq 0x48(%rsp), %rbx
movq 0x50(%rsp), %r13
movq 0x18(%rsi), %rcx
cmpq $-0x1, (%rcx,%rbp,8)
jne 0xb5d11
movl %r10d, 0x4(%rsp)
movq %r15, 0x10(%rsp)
movl %eax, %esi
leaq (%rcx,%rsi,8), %rcx
movq %rcx, 0x30(%rsp)
movl %ebp, %edx
subl %eax, %edx
movl %edx, 0x28(%rsp)
movl %edx, 0x24(%rsp)
movl $0x0, 0x18(%rsp)
xorl %edx, %edx
cmpq %rsi, %rbp
je 0xb5c21
movl %ebp, %esi
subl %eax, %esi
xorl %eax, %eax
xorl %edx, %edx
addl (%rcx,%rax,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
incq %rax
cmpq %rax, %rsi
jne 0xb5c10
movl %edx, 0x18(%rsp)
leaq 0x18(%rsp), %rdi
movq 0x40(%rsp), %r15
movq %r15, %rsi
movq %rbx, %rdx
movq %r13, %rcx
movq 0x90(%rsp), %r8
movl 0xa8(%rsp), %r12d
movq %r12, %r9
movq 0xb8(%rsp), %r12
pushq %r12
movl 0xb8(%rsp), %r14d
pushq %r14
callq 0xb3a75
addq $0x8, %rsp
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
leaq 0x1d55b9(%rip), %rdx    # 0x28b230
movq %rbx, %rcx
movq %r13, %r8
movq 0x98(%rsp), %r9
pushq %r12
pushq %r14
movl 0xc0(%rsp), %eax
pushq %rax
pushq 0xc0(%rsp)
pushq 0xc0(%rsp)
callq 0xb5008
addq $0x30, %rsp
movl 0x28(%rsp), %eax
testq %rax, %rax
je 0xb5ce2
movq 0x30(%rsp), %rcx
movq 0x8(%rsp), %rsi
movq 0x18(%rsi), %rdx
movl 0x4(%rsp), %r10d
movl %r10d, %r11d
xorl %edi, %edi
leal (%r11,%rdi), %r8d
movq (%rcx,%rdi,8), %r9
movq %r9, (%rdx,%r8,8)
incq %rdi
cmpq %rdi, %rax
jne 0xb5cc9
addl %edi, %r10d
jmp 0xb5cec
movl 0x4(%rsp), %r10d
movq 0x8(%rsp), %rsi
movl 0x18(%rsp), %eax
movq 0x18(%rsi), %rcx
movl %r10d, %edx
movq $-0x1, (%rcx,%rdx,8)
incl %r10d
movq 0x10(%rsp), %r15
addl %eax, %r15d
addl $0x64, %r15d
leal 0x1(%rbp), %eax
incq %rbp
movl 0x10(%rsi), %ecx
cmpq %rcx, %rbp
jb 0xb5bc9
jmp 0xb5d2c
xorl %ebp, %ebp
xorl %r10d, %r10d
xorl %r15d, %r15d
xorl %eax, %eax
subl %eax, %ebp
je 0xb5e5b
movl %r10d, 0x4(%rsp)
movq %r15, 0x10(%rsp)
movl %eax, %eax
shlq $0x3, %rax
addq 0x18(%rsi), %rax
movq %rax, 0x30(%rsp)
movl $0x80000000, %ecx       # imm = 0x80000000
andl (%rsi), %ecx
movl %ebp, 0x28(%rsp)
movl %ebp, 0x24(%rsp)
movl %ecx, 0x18(%rsp)
xorl %edx, %edx
movl (%rax,%rdx,8), %esi
addl %ecx, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %esi, %ecx
incq %rdx
cmpq %rdx, %rbp
jne 0xb5d62
leaq 0x18(%rsp), %rbp
movl %ecx, (%rbp)
movq %rbp, %rdi
movq 0x40(%rsp), %r14
movq %r14, %rsi
movq 0x48(%rsp), %rbx
movq %rbx, %rdx
movq 0x50(%rsp), %r13
movq %r13, %rcx
movq 0x90(%rsp), %r8
movl 0xa8(%rsp), %r12d
movq %r12, %r9
movq 0xb8(%rsp), %r15
pushq %r15
movl 0xb8(%rsp), %r12d
pushq %r12
callq 0xb3a75
addq $0x8, %rsp
leaq 0x1d5459(%rip), %rdx    # 0x28b230
movq %rbp, %rdi
movq %r14, %rsi
movq %rbx, %rcx
movq %r13, %r8
movq 0x98(%rsp), %r9
pushq %r15
pushq %r12
movl 0xc0(%rsp), %eax
pushq %rax
pushq 0xc0(%rsp)
pushq 0xc0(%rsp)
callq 0xb5008
addq $0x30, %rsp
movl 0x10(%rbp), %eax
testq %rax, %rax
je 0xb5e47
movq 0x30(%rsp), %rcx
movq 0x8(%rsp), %rsi
movq 0x18(%rsi), %r11
movl 0x4(%rsp), %r10d
movl %r10d, %edi
xorl %edx, %edx
leal (%rdi,%rdx), %r8d
movq (%rcx,%rdx,8), %r9
movq %r9, (%r11,%r8,8)
incq %rdx
cmpq %rdx, %rax
jne 0xb5e2e
addl %edx, %r10d
jmp 0xb5e51
movl 0x4(%rsp), %r10d
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %r15
addl 0x18(%rsp), %r15d
movl %r10d, 0x10(%rsi)
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movl $0x80000000, %eax       # imm = 0x80000000
andl (%rsi), %eax
orl %r15d, %eax
movl %eax, (%rsi)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq