// File: /workspace/github_cpp_makefile_star2_O3/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)
movl 0x10(%rsi), %ecx
testl %ecx, %ecx
je 0xb6e5d
movq 0x18(%rsi), %rax
xorl %ebp, %ebp
xorl %edx, %edx
xorl %r10d, %r10d
xorl %ebx, %ebx
movq %rsi, 0x10(%rsp)
movq 0x40(%rsp), %r14
movq 0x48(%rsp), %r13
movq 0x50(%rsp), %r15
cmpq $-0x1, (%rax,%rbp,8)
je 0xb6c11
incq %rbp
jmp 0xb6d3b
movl %ebx, 0x4(%rsp)
movq %r10, 0x8(%rsp)
movl %edx, %edi
leaq (%rax,%rdi,8), %rax
movq %rax, 0x30(%rsp)
movl %ebp, %esi
subl %edx, %esi
movl %esi, 0x28(%rsp)
movl %esi, 0x24(%rsp)
movl $0x0, 0x18(%rsp)
xorl %ecx, %ecx
cmpq %rdi, %rbp
je 0xb6c57
movl %esi, %edx
xorl %esi, %esi
xorl %ecx, %ecx
addl (%rax,%rsi,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
incq %rsi
cmpq %rsi, %rdx
jne 0xb6c46
movl %ecx, 0x18(%rsp)
leaq 0x18(%rsp), %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq 0x90(%rsp), %r8
movl 0xa8(%rsp), %ebx
movq %rbx, %r9
movq 0xb8(%rsp), %rbx
pushq %rbx
movl 0xb8(%rsp), %r12d
pushq %r12
callq 0xb4bb4
addq $0x8, %rsp
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
leaq 0x1df58a(%rip), %rdx    # 0x296230
movq %r13, %rcx
movq %r15, %r8
movq 0x98(%rsp), %r9
pushq %rbx
pushq %r12
movl 0xc0(%rsp), %eax
pushq %rax
pushq 0xc0(%rsp)
pushq 0xc0(%rsp)
callq 0xb606b
addq $0x30, %rsp
movl 0x28(%rsp), %ecx
movq 0x10(%rsp), %rsi
movq 0x18(%rsi), %rax
testq %rcx, %rcx
je 0xb6d13
movq 0x30(%rsp), %rdx
movl 0x4(%rsp), %ebx
movl %ebx, %r11d
xorl %edi, %edi
movq 0x8(%rsp), %r10
leal (%r11,%rdi), %r8d
movq (%rdx,%rdi,8), %r9
movq %r9, (%rax,%r8,8)
incq %rdi
cmpq %rdi, %rcx
jne 0xb6cfb
addl %edi, %ebx
jmp 0xb6d1c
movq 0x8(%rsp), %r10
movl 0x4(%rsp), %ebx
movl 0x18(%rsp), %ecx
movl %ebx, %edx
movq $-0x1, (%rax,%rdx,8)
incl %ebx
addl %ecx, %r10d
addl $0x64, %r10d
incq %rbp
movl 0x10(%rsi), %ecx
movl %ebp, %edx
movl %ecx, %edi
cmpq %rdi, %rbp
jb 0xb6c02
subl %edx, %ebp
je 0xb6e77
movl %ebx, 0x4(%rsp)
movq %r10, 0x8(%rsp)
movl %edx, %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)
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 0xb6d77
leaq 0x18(%rsp), %r14
movl %ecx, (%r14)
movq %r14, %rdi
movq 0x40(%rsp), %rbp
movq %rbp, %rsi
movq 0x48(%rsp), %r13
movq %r13, %rdx
movq 0x50(%rsp), %r15
movq %r15, %rcx
movq 0x90(%rsp), %r8
movl 0xa8(%rsp), %ebx
movq %rbx, %r9
movq 0xb8(%rsp), %rbx
pushq %rbx
movl 0xb8(%rsp), %eax
movq %rax, %r12
pushq %rax
callq 0xb4bb4
addq $0x8, %rsp
leaq 0x1df445(%rip), %rdx    # 0x296230
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rcx
movq %r15, %r8
movq 0x98(%rsp), %r9
pushq %rbx
pushq %r12
movl 0xc0(%rsp), %eax
pushq %rax
pushq 0xc0(%rsp)
pushq 0xc0(%rsp)
callq 0xb606b
addq $0x30, %rsp
movl 0x10(%r14), %eax
testq %rax, %rax
je 0xb6e64
movq 0x30(%rsp), %rcx
movq 0x10(%rsp), %rsi
movq 0x18(%rsi), %r11
movl 0x4(%rsp), %ebx
movl %ebx, %edi
xorl %edx, %edx
movq 0x8(%rsp), %r10
leal (%rdi,%rdx), %r8d
movq (%rcx,%rdx,8), %r9
movq %r9, (%r11,%r8,8)
incq %rdx
cmpq %rdx, %rax
jne 0xb6e45
addl %edx, %ebx
jmp 0xb6e72
xorl %ebx, %ebx
xorl %r10d, %r10d
jmp 0xb6e77
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %rsi
movl 0x4(%rsp), %ebx
addl 0x18(%rsp), %r10d
movl %ebx, 0x10(%rsi)
andl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movl $0x80000000, %eax       # imm = 0x80000000
andl (%rsi), %eax
orl %r10d, %eax
movl %eax, (%rsi)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq