// File: chhylp123[P]hifiasm/Assembly.cpp
// Function: debug_cigar(Cigar_record*, char*, int, char*, int, int)
int debug_cigar(Cigar_record* cigar, char* pre_read, int pre_length, char* new_read, int new_length, int correct_base)
{
    int i;
    int total_errors = 0;
    for (i = 0; i < (long long)cigar->length; i++)
    {
        if (Get_Cigar_Type(cigar->record[i]) > 0)
        {
            total_errors = total_errors + Get_Cigar_Length(cigar->record[i]);
        }
    }

    if(total_errors!=correct_base)
    {
        fprintf(stderr, "total_errors: %d, correct_base: %d\n", total_errors, correct_base);
    }

    int pre_i, new_i;
    int operation, operation_length;
    pre_i = new_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)
        {
            pre_i = pre_i + operation_length;
            new_i = new_i + operation_length;
        }

        if (operation == 1)
        {
            pre_i = pre_i + operation_length;
            new_i = new_i + operation_length;
        }

        if (operation == 3)
        {
            pre_i = pre_i + operation_length;
        }

        if (operation == 2)
        {
            new_i = new_i + operation_length;
        }

    }

    if (pre_i != pre_length)
    {
        fprintf(stderr, "pre_i: %d, pre_length: %d\n", pre_i, pre_length);
    }


    if(new_i != new_length)
    {
        fprintf(stderr, "new_i: %d, new_length: %d\n", new_i, new_length);
    }

    return 1;

    char* tmp_seq = (char*)malloc(new_length + pre_length);
    int tmp_length;

    get_corrected_read_from_cigar(cigar, pre_read, pre_length, tmp_seq, &tmp_length);

    if(tmp_length != new_length)
    {
        fprintf(stderr, "tmp_length: %d, new_length: %d\n", tmp_length, new_length);
    }

    if(memcmp(new_read, tmp_seq, new_length)!=0)
    {
        fprintf(stderr, "error new string\n");
    }


    get_uncorrected_read_from_cigar(cigar, new_read, new_length, tmp_seq, &tmp_length);


    if(tmp_length != pre_length)
    {
        fprintf(stderr, "tmp_length: %d, pre_length: %d\n", tmp_length, pre_length);
    }

    if(memcmp(pre_read, tmp_seq, pre_length)!=0)
    {
        fprintf(stderr, "error pre string\n");
    }


    free(tmp_seq);

    if((int)cigar->new_read_length != new_length)
    {
        fprintf(stderr, "cigar->new_read_length: %d, new_length: %d\n", cigar->new_read_length, new_length);
    }
}

// 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)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movslq -0x2c(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jge 0x140a9
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0x3, %eax
cmpl $0x0, %eax
jbe 0x1409c
movl -0x30(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movslq -0x2c(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
shrl $0x2, %ecx
addl %ecx, %eax
movl %eax, -0x30(%rbp)
jmp 0x1409e
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1405d
movl -0x30(%rbp), %eax
cmpl -0x28(%rbp), %eax
je 0x140cf
movq 0x3aff28(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x30(%rbp), %edx
movl -0x28(%rbp), %ecx
leaq 0x36d890(%rip), %rsi    # 0x381958
movb $0x0, %al
callq 0x22a0
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x2c(%rbp)
movslq -0x2c(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jge 0x1417e
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 0x14138
movl -0x34(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x38(%rbp)
cmpl $0x1, -0x3c(%rbp)
jne 0x14150
movl -0x34(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x38(%rbp)
cmpl $0x3, -0x3c(%rbp)
jne 0x1415f
movl -0x34(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x2, -0x3c(%rbp)
jne 0x1416e
movl -0x38(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x14170
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x140e4
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
je 0x141a4
movq 0x3afe53(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x34(%rbp), %edx
movl -0x14(%rbp), %ecx
leaq 0x36d7df(%rip), %rsi    # 0x38197c
movb $0x0, %al
callq 0x22a0
movl -0x38(%rbp), %eax
cmpl -0x24(%rbp), %eax
je 0x141ca
movq 0x3afe2d(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x38(%rbp), %edx
movl -0x24(%rbp), %ecx
leaq 0x36d7d4(%rip), %rsi    # 0x381997
movb $0x0, %al
callq 0x22a0
movl $0x1, %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)