// File: chhylp123[P]hifiasm/Correct.cpp
// Function: ref_cigar_check(char*, UC_Read*, ul_idx_t const*, hpc_t*, All_reads*, long, long, bit_extz_t*)
void ref_cigar_check(char* qstr, UC_Read *tu, const ul_idx_t *uref, hpc_t *hpc_g, All_reads *rref, int64_t id, int64_t rev, bit_extz_t *ez)
{
    int64_t pts = -1, pte = -1, tl = ez->pe-ez->ps+1, ql = ez->te-ez->ts+1, bps, bts, k; 
    char *q, *t; bps = ez->ps; bts = ez->ts;

    q = qstr + ez->ts; 
    t = retrieve_str_seq_exz(tu, ez->ps, tl, pts, pte-pts, rev, uref, hpc_g, rref, id);
    ez->ps = ez->ts = 0; 
    if(!cigar_check(t, q, ez)){
        fprintf(stderr, "[M::%s::] cigar_n::%d\n", __func__, (int32_t)ez->cigar.n);
        for (k = 0; k < (int32_t)ez->cigar.n; k++) {
            fprintf(stderr, "[M::%s::%ld] cigar_len::%u, c::%u\n", __func__, k,
            ez->cigar.a[k]&(0x3fff), (ez->cigar.a[k]>>14));
        }
        
        // fprintf(stderr, "[M::%s::l->%ld] s::%ld, pstr::%.*s\n", __func__, tl, bps, (int32_t)tl, t);
        // fprintf(stderr, "[M::%s::l->%ld] s::%ld, tstr::%.*s\n", __func__, ql, bts, (int32_t)ql, q);
        fprintf(stderr, "[M::%s::l->%ld] s::%ld\n", __func__, tl, bps);
        fprintf(stderr, "[M::%s::l->%ld] s::%ld\n", __func__, ql, bts);
        exit(1);
    }
    ez->ps = bps; ez->ts = bts;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x98, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq $-0x1, -0x40(%rbp)
movq $-0x1, -0x48(%rbp)
movq 0x18(%rbp), %rax
movl 0x14(%rax), %eax
movq 0x18(%rbp), %rcx
subl 0x10(%rcx), %eax
addl $0x1, %eax
cltq
movq %rax, -0x50(%rbp)
movq 0x18(%rbp), %rax
movl 0x20(%rax), %eax
movq 0x18(%rbp), %rcx
subl 0x1c(%rcx), %eax
addl $0x1, %eax
cltq
movq %rax, -0x58(%rbp)
movq 0x18(%rbp), %rax
movslq 0x10(%rax), %rax
movq %rax, -0x60(%rbp)
movq 0x18(%rbp), %rax
movslq 0x1c(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rbp), %rcx
movslq 0x1c(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rdi
movq 0x18(%rbp), %rax
movslq 0x10(%rax), %rsi
movq -0x50(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
subq -0x40(%rbp), %r8
movq 0x10(%rbp), %rax
movb %al, %r9b
movq -0x20(%rbp), %rbx
movq -0x28(%rbp), %r11
movq -0x30(%rbp), %r10
movq -0x38(%rbp), %rax
movzbl %r9b, %r9d
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0xc0c80
movq %rax, -0x80(%rbp)
movq 0x18(%rbp), %rax
movl $0x0, 0x1c(%rax)
movq 0x18(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq 0x18(%rbp), %rdx
callq 0xc0e50
cmpl $0x0, %eax
jne 0x5efbf
movq 0x365121(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq 0x18(%rbp), %rax
movq 0xa8(%rax), %rax
movl %eax, %ecx
leaq 0x324880(%rip), %rsi    # 0x383756
leaq 0x324890(%rip), %rdx    # 0x38376d
movb $0x0, %al
callq 0x22a0
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq 0x18(%rbp), %rcx
movq 0xa8(%rcx), %rcx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x5ef67
movq 0x3650d6(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x70(%rbp), %rcx
movq 0x18(%rbp), %rax
movq 0xb8(%rax), %rax
movq -0x70(%rbp), %rdx
movzwl (%rax,%rdx,2), %r8d
andl $0x3fff, %r8d           # imm = 0x3FFF
movq 0x18(%rbp), %rax
movq 0xb8(%rax), %rax
movq -0x70(%rbp), %rdx
movzwl (%rax,%rdx,2), %r9d
sarl $0xe, %r9d
leaq 0x324832(%rip), %rsi    # 0x38377d
leaq 0x32481b(%rip), %rdx    # 0x38376d
movb $0x0, %al
callq 0x22a0
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x5eeec
movq 0x365072(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x50(%rbp), %rcx
movq -0x60(%rbp), %r8
leaq 0x324820(%rip), %rsi    # 0x3837a0
leaq 0x3247e6(%rip), %rdx    # 0x38376d
movb $0x0, %al
callq 0x22a0
movq 0x36504b(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x58(%rbp), %rcx
movq -0x68(%rbp), %r8
leaq 0x3247f9(%rip), %rsi    # 0x3837a0
leaq 0x3247bf(%rip), %rdx    # 0x38376d
movb $0x0, %al
callq 0x22a0
movl $0x1, %edi
callq 0x2240
movq -0x60(%rbp), %rax
movl %eax, %ecx
movq 0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x68(%rbp), %rax
movl %eax, %ecx
movq 0x18(%rbp), %rax
movl %ecx, 0x1c(%rax)
addq $0x98, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)