// File: chhylp123[P]hifiasm/Assembly.cpp
// Function: get_uncorrected_read_from_cigar(Cigar_record*, char*, int, char*, int*)
void get_uncorrected_read_from_cigar(Cigar_record* cigar, char* new_read, int new_length, char* pre_read, int* pre_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(pre_read + pre_i, new_read + new_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++)
            {
                pre_read[pre_i] = Get_Match_Base(cigar->lost_base[diff_char_i]);
                pre_i++;
                diff_char_i++;
            }
            new_i = new_i + operation_length;
        }
        else if (operation == 3)
        {
            memcpy(pre_read + pre_i, cigar->lost_base + diff_char_i, operation_length);
            pre_i = pre_i + operation_length;
            diff_char_i = diff_char_i + operation_length;
        }
        else if (operation == 2)
        {
            new_i = new_i + operation_length;
            diff_char_i = diff_char_i + operation_length;
        }
    }

    *pre_length = pre_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 0x14012
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 0x13f3f
movq -0x20(%rbp), %rdi
movslq -0x34(%rbp), %rax
addq %rax, %rdi
movq -0x10(%rbp), %rsi
movslq -0x38(%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 0x14002
cmpl $0x1, -0x3c(%rbp)
jne 0x13fa7
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x13f9c
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x44(%rbp), %rcx
movsbl (%rax,%rcx), %eax
andl $0x7, %eax
movslq %eax, %rcx
leaq 0x3b07df(%rip), %rax    # 0x3c4750
movb (%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x13f4c
movl -0x38(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x14000
cmpl $0x3, -0x3c(%rbp)
jne 0x13fe4
movq -0x20(%rbp), %rdi
movslq -0x34(%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 -0x34(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x44(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x44(%rbp)
jmp 0x13ffe
cmpl $0x2, -0x3c(%rbp)
jne 0x13ffc
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 0x13ffe
jmp 0x14000
jmp 0x14002
jmp 0x14004
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x13ec7
movl -0x34(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)