// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, 0x8(%rsp)
movq %rcx, (%rsp)
movq %rsi, 0x10(%rsp)
cmpq $0x0, 0x18(%rdi)
jle 0x37fc6
movq %rdi, %r12
xorl %ebp, %ebp
leaq 0x1f8ca1(%rip), %r8     # 0x230b70
leaq 0x25d85a(%rip), %rbx    # 0x295730
xorl %r9d, %r9d
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x8(%r12), %rax
movl (%rax,%rbp,4), %eax
movl %eax, %ecx
andl $0x3, %ecx
movl %eax, %r13d
shrl $0x2, %r13d
movslq (%r8,%rcx,4), %rcx
addq %r8, %rcx
jmpq *%rcx
movslq %r14d, %rdi
addq (%rsp), %rdi
movslq %r15d, %rsi
addq 0x10(%rsp), %rsi
movq %r13, %rdx
movl %r9d, %ebx
callq 0x2160
movl %ebx, %r9d
leaq 0x25d810(%rip), %rbx    # 0x295730
leaq 0x1f8c49(%rip), %r8     # 0x230b70
addl %r13d, %r15d
addl %r14d, %r13d
movl %r13d, %r14d
jmp 0x37fb6
movslq %r14d, %rdi
addq (%rsp), %rdi
movslq %r9d, %rsi
addq 0x28(%r12), %rsi
movl %r13d, %edx
movl %r9d, %ebx
callq 0x2160
leaq 0x1f8c1a(%rip), %r8     # 0x230b70
addl %r13d, %r14d
addl %ebx, %r13d
leaq 0x25d7cd(%rip), %rbx    # 0x295730
movl %r13d, %r9d
jmp 0x37fb6
addl %r13d, %r15d
addl %r13d, %r9d
jmp 0x37fb6
cmpl $0x4, %eax
jb 0x37fb0
movslq %r9d, %rax
movslq %r14d, %rcx
addq (%rsp), %rcx
movl %r13d, %esi
negl %esi
xorl %edx, %edx
movq 0x28(%r12), %rdi
movb (%rdi,%rax), %dil
sarb $0x3, %dil
movsbq %dil, %rdi
movb (%rbx,%rdi), %dil
movb %dil, (%rcx)
incq %rax
incq %rcx
decl %edx
cmpl %edx, %esi
jne 0x37f86
subl %edx, %r14d
subl %edx, %r9d
addl %r15d, %r13d
movl %r13d, %r15d
incq %rbp
cmpq %rbp, 0x18(%r12)
jg 0x37edf
jmp 0x37fc9
xorl %r14d, %r14d
movq 0x8(%rsp), %rax
movl %r14d, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq