// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: generate_consensus(overlap_region_alloc*, All_reads*, UC_Read*, Correct_dumy*, Graph*, Graph*, Cigar_record*, Round2_alignment*, window_list_alloc*)
void generate_consensus(overlap_region_alloc* overlap_list, All_reads* R_INF, 
                        UC_Read* g_read, Correct_dumy* dumy, Graph* g, Graph* DAGCon, Cigar_record* current_cigar,
                        Round2_alignment* second_round, window_list_alloc* win_ciagr_buf)
{
    clear_Cigar_record(current_cigar);
    
    long long window_start, window_end;

    long long num_availiable_win = 0;
    
    


    Window_Pool w_inf;
    init_Window_Pool(&w_inf, g_read->length, WINDOW, (int)(1.0/asm_opt.max_ov_diff_ec));

    int flag = 0;
    ///for last window
    dumy->last_boundary_length = 0;
    while(get_Window(&w_inf, &window_start, &window_end) && flag != -2)
    {

        

        dumy->length = 0;
        dumy->lengthNT = 0;

        ///return overlaps that are overlaped with [window_start, window_end]
        flag = get_available_interval(window_start, window_end, overlap_list, dumy);
        switch (flag)
        {
            case 1:    ///match
                break;
            case 0:    ///unmatch
                break;
            case -2: ///unmatch, and cannot match for next window
                break;
        }

        num_availiable_win = num_availiable_win + dumy->length;

        // fprintf(stderr, "[M::%s] window_start::%lld, window_end::%lld, g_read->length::%lld, dumy->length::%lu\n", __func__, 
        // window_start, window_end, g_read->length, dumy->length);
        
        ///number of overlaps, also be the coverage
        if(dumy->length >= MIN_COVERAGE_THRESHOLD)
        {
            window_consensus(g_read->seq, g_read->length, window_start, window_end, overlap_list, 
            dumy, R_INF, g, DAGCon, current_cigar);

            if(dumy->last_boundary_length != 0)
            {
                process_boundary(overlap_list, R_INF, dumy, g, DAGCon, current_cigar, 
                window_start, second_round, win_ciagr_buf);
            }
            
        }
        else
        {
            add_segment_to_correct_read(dumy, g_read->seq + window_start, window_end - window_start + 1);
            add_cigar_record(g_read->seq + window_start, window_end - window_start + 1, current_cigar, 0);
        }


        dumy->last_boundary_length = current_cigar->new_read_length;
    }

    if (window_start < g_read->length)
    {
        add_segment_to_correct_read(dumy, g_read->seq + window_start, g_read->length - window_start);
        add_cigar_record(g_read->seq + window_start, g_read->length - window_start, current_cigar, 0);        
    }

    ///if type == 0, x_string here is not useful
    ///output matches to cigar
    if (current_cigar->new_read_length != second_round->obtained_cigar_length)
    {
        add_cigar_record(dumy->corrected_read, current_cigar->new_read_length - second_round->obtained_cigar_length, 
        &(second_round->cigar), 0);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, 0x18(%rsp)
movq %r8, 0x10(%rsp)
movq %rcx, %r15
movq %rsi, 0x8(%rsp)
movq 0x80(%rsp), %r14
xorl %r13d, %r13d
movl %r13d, 0x20(%r14)
movq %r13, 0x18(%r14)
movq %r13, 0x38(%r14)
movl %r13d, 0x4(%r14)
movb $0x7f, (%r14)
movq 0x8(%rdx), %rax
movl $0x177, %ecx            # imm = 0x177
cmpq %rcx, %rax
movl $0x177, %ebp            # imm = 0x177
cmovlq %rax, %rbp
decq %rbp
movq %rax, 0x28(%rsp)
decq %rax
movq %rax, 0x30(%rsp)
leaq 0x30(%r15), %r11
xorps %xmm0, %xmm0
movl $0x0, (%rsp)
xorl %eax, %eax
movl $0x0, 0x4(%rsp)
movq %rdx, 0x20(%rsp)
movq %r11, 0x38(%rsp)
movq %rax, 0x10(%r15)
cmpq 0x30(%rsp), %rbp
jne 0x4f2c5
cmpq $0x0, 0x28(%rsp)
sete %al
cmpl $0x1, (%rsp)
sete %cl
orb %al, %cl
movl $0x1, %ecx
je 0x4f2c8
xorl %eax, %eax
movq %r13, %r12
movq %rbp, %rbx
jmp 0x4f2e5
movl (%rsp), %ecx
movl $0x177, %eax            # imm = 0x177
leaq (%rax,%r13), %r12
leaq (%rax,%rbp), %rbx
cmpq 0x28(%rsp), %rbx
cmovgeq 0x30(%rsp), %rbx
movb $0x1, %al
movl %ecx, (%rsp)
cmpl $-0x2, 0x4(%rsp)
je 0x4f511
testb %al, %al
je 0x4f511
movaps %xmm0, (%r11)
testq %r13, %r13
jne 0x4f309
movq $0x0, 0x48(%r15)
movq 0x48(%r15), %rax
movq 0x10(%rdi), %rcx
cmpq %rcx, %rax
jae 0x4f33d
movq (%rdi), %rsi
imulq $0xa8, %rax, %rcx
movl 0x4(%rsi,%rcx), %esi
cmpq %rsi, %rbp
jge 0x4f448
movq $0x0, 0x48(%r15)
movaps %xmm0, (%r11)
xorl %esi, %esi
jmp 0x4f34a
movq %rcx, 0x48(%r15)
movaps %xmm0, (%r11)
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movl %esi, 0x4(%rsp)
movq %r12, 0x40(%rsp)
movq %rdi, %r12
cmpq $0x3, (%r11)
movq (%rdx), %r14
jb 0x4f3d6
movq 0x8(%rdx), %rsi
movq %r14, %rdi
movq %r13, %rdx
movq %rbp, %rcx
movq %r12, %r8
movq %r15, %r9
movq 0x80(%rsp), %r14
pushq %r14
pushq 0x20(%rsp)
pushq 0x20(%rsp)
pushq 0x20(%rsp)
callq 0x4e28c
addq $0x20, %rsp
cmpq $0x0, 0x10(%r15)
je 0x4f4f0
subq $0x8, %rsp
movq %r12, %rdi
movq 0x10(%rsp), %rsi
movq %r15, %rdx
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
movq %r14, %r9
pushq 0x98(%rsp)
pushq 0x98(%rsp)
pushq %r13
callq 0x4ea30
addq $0x20, %rsp
jmp 0x4f4f0
subq %r13, %rbp
movq 0x8(%r15), %rax
leaq (%rax,%rbp), %rsi
addq $0x3, %rsi
cmpq 0x18(%r15), %rsi
jle 0x4f3fa
movq %rsi, 0x18(%r15)
movq (%r15), %rdi
callq 0x2370
movq %rax, (%r15)
addq %r13, %r14
leaq 0x1(%rbp), %r13
movq (%r15), %rdi
addq 0x8(%r15), %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x2160
addq 0x8(%r15), %r13
movq %r13, 0x8(%r15)
movq (%r15), %rax
movb $0x0, (%rax,%r13)
incl %ebp
movq 0x80(%rsp), %r14
cmpb $0x0, (%r14)
je 0x4f4ce
movq %r14, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x5965e
jmp 0x4f4e8
movaps %xmm0, (%r11)
xorl %esi, %esi
cmpq 0x10(%rdi), %rax
jae 0x4f34a
movq (%rdi), %rsi
addq %rsi, %rcx
addq $0x4, %rcx
xorl %r10d, %r10d
xorl %esi, %esi
movl (%rcx), %r14d
movl 0x4(%rcx), %r8d
cmpq %rbp, %r8
cmovgeq %rbp, %r8
cmpq %r13, %r14
movq %r13, %r9
cmovgq %r14, %r9
cmpq %r9, %r8
jl 0x4f4ab
cmpb $0x1, 0x28(%rcx)
jne 0x4f49a
movq 0x28(%r15), %r8
movq 0x30(%r15), %r9
movq %rax, (%r8,%r9,8)
incq 0x30(%r15)
incq %r10
testq %rsi, %rsi
jne 0x4f4a6
movq %rax, 0x48(%r15)
movl $0x1, %esi
cmpq %r14, %rbp
jl 0x4f4c0
incq %rax
addq $0xa8, %rcx
cmpq 0x10(%rdi), %rax
jb 0x4f467
xorl %esi, %esi
testq %r10, %r10
setne %sil
jmp 0x4f34a
movq 0x8(%r14), %rax
movq 0x18(%r14), %rcx
leal (,%rbp,4), %edx
addl -0x4(%rax,%rcx,4), %edx
andl $-0x4, %edx
movl %edx, -0x4(%rax,%rcx,4)
addl %ebp, 0x20(%r14)
movb $0x0, (%r14)
movl 0x20(%r14), %eax
movq 0x40(%rsp), %r13
movq %rbx, %rbp
movq 0x20(%rsp), %rdx
movq 0x38(%rsp), %r11
movq %r12, %rdi
xorps %xmm0, %xmm0
jmp 0x4f297
movq 0x8(%rdx), %r12
subq %r13, %r12
jle 0x4f5b4
movq (%rdx), %r14
addq %r13, %r14
movq 0x8(%r15), %rax
leaq (%r12,%rax), %rsi
addq $0x2, %rsi
cmpq 0x18(%r15), %rsi
jle 0x4f545
movq %rsi, 0x18(%r15)
movq (%r15), %rdi
callq 0x2370
movq %rax, (%r15)
movq (%r15), %rdi
addq 0x8(%r15), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2160
addq 0x8(%r15), %r12
movq %r12, 0x8(%r15)
movq (%r15), %rax
movb $0x0, (%rax,%r12)
movq 0x20(%rsp), %rax
movl 0x8(%rax), %r14d
subl %r13d, %r14d
movq 0x80(%rsp), %rbx
cmpb $0x0, (%rbx)
je 0x4f58f
movq %rbx, %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x5965e
jmp 0x4f5aa
movq 0x8(%rbx), %rax
movq 0x18(%rbx), %rcx
leal (,%r14,4), %edx
addl -0x4(%rax,%rcx,4), %edx
andl $-0x4, %edx
movl %edx, -0x4(%rax,%rcx,4)
addl %r14d, 0x20(%rbx)
movb $0x0, (%rbx)
movq %rbx, %r14
movl 0x20(%r14), %ebx
movq 0x88(%rsp), %r14
movq 0x8e00(%r14), %rax
cmpq %rbx, %rax
je 0x4f619
subl %eax, %ebx
cmpb $0x0, 0x8d80(%r14)
je 0x4f5ea
leaq 0x8d80(%r14), %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0x5965e
jmp 0x4f60a
movq 0x8d88(%r14), %rax
movq 0x8d98(%r14), %rcx
leal (,%rbx,4), %edx
addl -0x4(%rax,%rcx,4), %edx
andl $-0x4, %edx
movl %edx, -0x4(%rax,%rcx,4)
addl %ebx, 0x8da0(%r14)
movb $0x0, 0x8d80(%r14)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq