// File: /workspace/github_cpp_makefile_star2_O2/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, 0x40(%rsp)
movq %r8, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movq %rsi, %rbx
xorl %edi, %edi
xorl %esi, %esi
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %eax, %eax
movq 0x30(%rsp), %r15
movq 0x40(%rsp), %rbp
movl 0x10(%rbx), %edx
movl %eax, %ecx
cmpq %rdx, %rsi
jae 0x7bd5e
movq 0x18(%rbx), %rdx
cmpq $-0x1, (%rdx,%rsi,8)
je 0x7bc3a
incq %rsi
jmp 0x7bd57
movq %r12, (%rsp)
leaq (%rdx,%rcx,8), %rcx
movq %rcx, 0x20(%rsp)
movq %rsi, 0x48(%rsp)
movl %esi, %edx
subl %eax, %edx
movl %edx, 0x18(%rsp)
movl %edx, 0x14(%rsp)
xorl %eax, %eax
xorl %esi, %esi
cmpq %rax, %rdx
je 0x7bc6f
addl (%rcx,%rax,8), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
incq %rax
jmp 0x7bc5c
movq %rdi, 0x50(%rsp)
movl %esi, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
movq 0x38(%rsp), %r12
movq %r12, %rdx
movq %rbp, %rcx
movq 0x90(%rsp), %r8
movl 0xa8(%rsp), %r13d
movq %r13, %r9
movq 0xb8(%rsp), %rax
pushq %rax
movl 0xb8(%rsp), %r13d
pushq %r13
callq 0x79ed9
popq %rcx
popq %rdx
subq $0x8, %rsp
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
leaq 0x1d8565(%rip), %rdx    # 0x254230
movq %r12, %rcx
movq %rbp, %r8
movq 0x98(%rsp), %r9
pushq 0xc0(%rsp)
pushq %r13
movl 0xc0(%rsp), %eax
pushq %rax
pushq 0xc0(%rsp)
pushq 0xc0(%rsp)
callq 0x7b187
addq $0x30, %rsp
movl 0x18(%rsp), %eax
movq 0x20(%rsp), %rcx
shlq $0x3, %rax
xorl %edx, %edx
movl %r14d, %esi
cmpq %rdx, %rax
je 0x7bd2d
movq (%rcx,%rdx), %rdi
movq 0x18(%rbx), %r8
movq %rdi, (%r8,%rsi,8)
incl %r14d
addq $0x8, %rdx
jmp 0x7bd10
movl 0x8(%rsp), %eax
movq 0x18(%rbx), %rcx
orq $-0x1, (%rcx,%rsi,8)
incl %r14d
movq (%rsp), %r12
addl %eax, %r12d
addl $0x64, %r12d
movq 0x48(%rsp), %rsi
incq %rsi
movl %esi, %eax
movq 0x50(%rsp), %rdi
incl %edi
jmp 0x7bc19
subl %eax, %esi
je 0x7be75
movq %r12, (%rsp)
shlq $0x3, %rcx
addq 0x18(%rbx), %rcx
movq %rcx, 0x20(%rsp)
movl $0x80000000, %edx       # imm = 0x80000000
andl (%rbx), %edx
movl %esi, 0x18(%rsp)
movl %esi, 0x14(%rsp)
subl %eax, %edi
xorl %eax, %eax
cmpq %rax, %rdi
je 0x7bda7
movl (%rcx,%rax,8), %esi
addl %edx, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %esi, %edx
incq %rax
jmp 0x7bd8a
leaq 0x8(%rsp), %rdi
movl %edx, (%rdi)
movq 0x30(%rsp), %r13
movq %r13, %rsi
movq 0x38(%rsp), %rbp
movq %rbp, %rdx
movq 0x40(%rsp), %r12
movq %r12, %rcx
movq 0x90(%rsp), %r8
movl 0xa8(%rsp), %r15d
movq %r15, %r9
movq 0xb8(%rsp), %r15
pushq %r15
movl 0xb8(%rsp), %eax
pushq %rax
callq 0x79ed9
popq %rcx
popq %rdx
subq $0x8, %rsp
leaq 0x1d8433(%rip), %rdx    # 0x254230
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rcx
movq %r12, %r8
movq 0x98(%rsp), %r9
pushq %r15
movl 0xc0(%rsp), %eax
pushq %rax
movl 0xc0(%rsp), %eax
pushq %rax
pushq 0xc0(%rsp)
pushq 0xc0(%rsp)
callq 0x7b187
addq $0x30, %rsp
leaq 0x8(%rsp), %rax
movl 0x10(%rax), %ecx
movq 0x18(%rax), %rdx
movl %r14d, %esi
xorl %eax, %eax
cmpq %rax, %rcx
je 0x7be69
leaq (%rsi,%rax), %rdi
movq (%rdx,%rax,8), %r8
movq 0x18(%rbx), %r9
movl %edi, %edi
movq %r8, (%r9,%rdi,8)
incq %rax
jmp 0x7be4d
movq (%rsp), %r12
addl 0x8(%rsp), %r12d
addl %eax, %r14d
movl %r14d, 0x10(%rbx)
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movl $0x80000000, %eax       # imm = 0x80000000
andl (%rbx), %eax
orl %r12d, %eax
movl %eax, (%rbx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq