// File: chhylp123[P]hifiasm/Assembly.cpp
// Function: get_corrected_read_from_cigar(Cigar_record*, char*, int, char*, int*)
void get_corrected_read_from_cigar(Cigar_record* cigar, char* pre_read, int pre_length, char* new_read, int* new_length)
{
    int i, j;
    int pre_i, new_i;
    int operation, operation_length;
    pre_i = new_i = 0;
    int diff_char_i = 0;


    for (i = 0; i < (long long)cigar->length; i++)
    {
        operation = Get_Cigar_Type(cigar->record[i]);
        operation_length = Get_Cigar_Length(cigar->record[i]);

        if (operation == 0)
        {
            memcpy(new_read + new_i, pre_read + pre_i, operation_length);
            pre_i = pre_i + operation_length;
            new_i = new_i + operation_length;
        }
        else if (operation == 1)
        {

            for (j = 0; j < operation_length; j++)
            {
                new_read[new_i] = Get_MisMatch_Base(cigar->lost_base[diff_char_i]);
                new_i++;
                diff_char_i++;
            }
            pre_i = pre_i + operation_length;
        }
        else if (operation == 3)
        {
            pre_i = pre_i + operation_length;
            diff_char_i = diff_char_i + operation_length;
        }
        else if (operation == 2)
        {
            memcpy(new_read + new_i, cigar->lost_base + diff_char_i, operation_length);
            new_i = new_i + operation_length;
            diff_char_i = diff_char_i + operation_length;
        }
    }
    *new_length = new_i;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x2c(%rbp)
movslq -0x2c(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jge 0x13e72
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0x3, %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x2, %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x13d9f
movq -0x20(%rbp), %rdi
movslq -0x38(%rbp), %rax
addq %rax, %rdi
movq -0x10(%rbp), %rsi
movslq -0x34(%rbp), %rax
addq %rax, %rsi
movslq -0x40(%rbp), %rdx
callq 0x2180
movl -0x34(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x13e62
cmpl $0x1, -0x3c(%rbp)
jne 0x13e07
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x13dfc
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x44(%rbp), %rcx
movsbl (%rax,%rcx), %eax
sarl $0x3, %eax
movslq %eax, %rcx
leaq 0x3b097f(%rip), %rax    # 0x3c4750
movb (%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movslq -0x38(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x13dac
movl -0x34(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x13e60
cmpl $0x3, -0x3c(%rbp)
jne 0x13e21
movl -0x34(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x44(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x44(%rbp)
jmp 0x13e5e
cmpl $0x2, -0x3c(%rbp)
jne 0x13e5c
movq -0x20(%rbp), %rdi
movslq -0x38(%rbp), %rax
addq %rax, %rdi
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rsi
movslq -0x44(%rbp), %rax
addq %rax, %rsi
movslq -0x40(%rbp), %rdx
callq 0x2180
movl -0x38(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x44(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x44(%rbp)
jmp 0x13e5e
jmp 0x13e60
jmp 0x13e62
jmp 0x13e64
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x13d27
movl -0x38(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)