// File: chhylp123[P]hifiasm/Correct.cpp
// Function: add_cigar_to_cigar(Correct_dumy*, Cigar_record*, Round2_alignment*, long long, long long, long long, long long)
void add_cigar_to_cigar(Correct_dumy* backbone_dumy, Cigar_record* backbone_cigar,
Round2_alignment* second_round,
long long back_bone_start, long long back_bone_length,
long long new_start, long long new_length)
{
    Correct_dumy* new_dumy = &(second_round->dumy);
    Cigar_record* new_cigar = &(second_round->tmp_cigar);
    Cigar_record* result_cigar = &(second_round->cigar);

    char* x_string = backbone_dumy->corrected_read + back_bone_start;
    char* y_string = new_dumy->corrected_read + new_start;
    /**
    if(verify_cigar_2(x_string, back_bone_length, y_string, new_length, new_cigar, -1))
    {
        fprintf(stderr, "error\n");
    }
    **/


   ///if type == 0, x_string here is not useful
   ///output matches to cigar
   add_cigar_record(x_string, back_bone_start - second_round->obtained_cigar_length, result_cigar, 0);
   second_round->obtained_cigar_length = back_bone_start + back_bone_length;

    long long i, cigar_i, x_i, y_i;
    int operation;
    int operationLen;
    x_i = y_i = 0;
    char merge_base;

    for (i = 0; i < (long long)new_cigar->length; i++)
    {
        operation = Get_Cigar_Type(new_cigar->record[i]);
        operationLen = Get_Cigar_Length(new_cigar->record[i]);
        if (operation == 0)
        {
            ///if type == 0, x_string here is not useful
            add_cigar_record(x_string, operationLen, result_cigar, 0);
            x_i += operationLen;
            y_i += operationLen;
        }
        else if (operation == 1)
        {
            for (cigar_i = 0; cigar_i < operationLen; cigar_i++)
            {
                merge_base = 0;
                merge_base = seq_nt6_table[(uint8_t)y_string[y_i]];
                merge_base = merge_base << 3;
                merge_base = merge_base | seq_nt6_table[(uint8_t)x_string[x_i]];

                add_cigar_record(&merge_base, 1, result_cigar, 1);
                x_i++;
                y_i++;
            }
        }
        else if (operation == INSERTION)///2是x缺字符（y多字符）
        {
            add_cigar_record(y_string+y_i, operationLen, result_cigar, INSERTION);
            y_i += operationLen;
        }
        else if (operation == DELETION)
        {
            add_cigar_record(x_string+x_i, operationLen, result_cigar, DELETION);
            x_i += operationLen;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
addq $0x8dc0, %rax           # imm = 0x8DC0
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
addq $0x8d80, %rax           # imm = 0x8D80
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
subq 0x8e00(%rcx), %rax
movl %eax, %esi
movq -0x48(%rbp), %rdx
xorl %ecx, %ecx
callq 0x1c6a0
movq -0x20(%rbp), %rcx
addq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8e00(%rax)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jge 0x3a1b8
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x60(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0x3, %eax
movl %eax, -0x7c(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x60(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x2, %eax
movl %eax, -0x80(%rbp)
cmpl $0x0, -0x7c(%rbp)
jne 0x3a085
movq -0x50(%rbp), %rdi
movl -0x80(%rbp), %esi
movq -0x48(%rbp), %rdx
xorl %ecx, %ecx
callq 0x1c6a0
movslq -0x80(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movslq -0x80(%rbp), %rax
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x3a1a5
cmpl $0x1, -0x7c(%rbp)
jne 0x3a147
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
movslq -0x80(%rbp), %rcx
cmpq %rcx, %rax
jge 0x3a145
movb $0x0, -0x81(%rbp)
movq -0x58(%rbp), %rax
movq -0x78(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x38a58c(%rip), %rax    # 0x3c4650
movb (%rax,%rcx), %al
movb %al, -0x81(%rbp)
movsbl -0x81(%rbp), %eax
shll $0x3, %eax
movb %al, -0x81(%rbp)
movsbl -0x81(%rbp), %eax
movq -0x50(%rbp), %rcx
movq -0x70(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
movl %ecx, %edx
leaq 0x38a557(%rip), %rcx    # 0x3c4650
movzbl (%rcx,%rdx), %ecx
orl %ecx, %eax
movb %al, -0x81(%rbp)
movq -0x48(%rbp), %rdx
leaq -0x81(%rbp), %rdi
movl $0x1, %ecx
movl %ecx, %esi
callq 0x1c6a0
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x3a097
jmp 0x3a1a3
cmpl $0x2, -0x7c(%rbp)
jne 0x3a174
movq -0x58(%rbp), %rdi
addq -0x78(%rbp), %rdi
movl -0x80(%rbp), %esi
movq -0x48(%rbp), %rdx
movl $0x2, %ecx
callq 0x1c6a0
movslq -0x80(%rbp), %rax
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x3a1a1
cmpl $0x3, -0x7c(%rbp)
jne 0x3a19f
movq -0x50(%rbp), %rdi
addq -0x70(%rbp), %rdi
movl -0x80(%rbp), %esi
movq -0x48(%rbp), %rdx
movl $0x3, %ecx
callq 0x1c6a0
movslq -0x80(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x3a1a1
jmp 0x3a1a3
jmp 0x3a1a5
jmp 0x3a1a7
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x3a014
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)