// File: chhylp123[P]hifiasm/Assembly.cpp
// Function: Final_phasing(overlap_region_alloc*, Cigar_record_alloc*, UC_Read*, UC_Read*, unsigned char*)
void Final_phasing(overlap_region_alloc* overlap_list, Cigar_record_alloc* cigarline,
UC_Read* g_read, UC_Read* overlap_read, uint8_t* c2n)
{
    uint64_t i, xLen, yStrand;
    char* x_string;
    char* y_string;
    Cigar_record* cigar;
    resize_Cigar_record_alloc(cigarline, overlap_list->length);



    for (i = 0; i < overlap_list->length; i++)
    {
        if(overlap_list->list[i].is_match == 1 ||
           overlap_list->list[i].is_match == 2 ||
           overlap_list->list[i].is_match == 3)
        {
            xLen = overlap_list->list[i].x_pos_e - overlap_list->list[i].x_pos_s + 1;
            yStrand = overlap_list->list[i].y_pos_strand;
            cigar = &(cigarline->buffer[i]);
            ///has already been matched exactly
            if(overlap_list->list[i].is_match == 1 && overlap_list->list[i].shared_seed == 1)
            {
                add_cigar_record(g_read->seq + overlap_list->list[i].x_pos_s, xLen, cigar, 0);
            }
            else 
            {
                if(yStrand == 0)
                {
                    recover_UC_Read(overlap_read, &R_INF, overlap_list->list[i].y_id);
                }
                else
                {
                    recover_UC_Read_RC(overlap_read, &R_INF, overlap_list->list[i].y_id);
                }
                x_string = g_read->seq;
                y_string = overlap_read->seq;

                fill_chain(&(overlap_list->list[i].f_cigar), x_string, y_string, 
                overlap_list->list[i].x_pos_s, overlap_list->list[i].y_pos_s,
                Get_READ_LENGTH(R_INF, overlap_list->list[i].x_id), 
                Get_READ_LENGTH(R_INF, overlap_list->list[i].y_id), cigar, c2n);
            }

        }
    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x4c9b0
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x194d2
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
cmpl $0x1, %eax
je 0x192dc
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
cmpl $0x2, %eax
je 0x192dc
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
cmpl $0x3, %eax
jne 0x194bf
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0xa8, -0x30(%rbp), %rdx
addq %rdx, %rcx
subl 0x4(%rcx), %eax
addl $0x1, %eax
movl %eax, %eax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
cmpl $0x1, %eax
jne 0x193a7
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
cmpl $0x1, 0x24(%rax)
jne 0x193a7
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addq %rax, %rdi
movq -0x38(%rbp), %rax
movl %eax, %esi
movq -0x58(%rbp), %rdx
xorl %ecx, %ecx
callq 0x1c6a0
jmp 0x194bd
cmpq $0x0, -0x40(%rbp)
jne 0x193d7
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, %edx
leaq 0x3abf00(%rip), %rsi    # 0x3c52d0
callq 0xa380
jmp 0x193fe
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, %edx
leaq 0x3abed7(%rip), %rsi    # 0x3c52d0
callq 0xa500
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
imulq $0xa8, -0x30(%rbp), %rax
addq %rax, %rdi
addq $0x38, %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %r8
addq %r8, %rax
movl 0x14(%rax), %eax
movl %eax, %r8d
movq 0x3abe80(%rip), %rax    # 0x3c52e8
movq -0x8(%rbp), %r9
movq (%r9), %r9
imulq $0xa8, -0x30(%rbp), %r10
addq %r10, %r9
movl (%r9), %r9d
movq (%rax,%r9,8), %r9
movq 0x3abe60(%rip), %rax    # 0x3c52e8
movq -0x8(%rbp), %r10
movq (%r10), %r10
imulq $0xa8, -0x30(%rbp), %r11
addq %r11, %r10
movl 0x10(%r10), %r10d
movq (%rax,%r10,8), %r11
movq -0x58(%rbp), %r10
movq -0x28(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x19210
jmp 0x194bf
jmp 0x194c1
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x19275
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)