// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %rbx
movq %rdx, %r10
movq %rsi, %rbp
movq %rdi, %r13
movq 0x88(%rsp), %r12
movb 0x80(%rsp), %dil
movslq 0x14(%r12), %r15
movl 0x10(%r12), %r14d
movl 0x1c(%r12), %eax
movslq %r14d, %rsi
subq %rsi, %r15
leaq 0x1(%r15), %r9
movl 0x20(%r12), %edx
movl %edx, 0x2c(%rsp)
movl %eax, 0x14(%rsp)
cltq
movq %rax, 0x40(%rsp)
addq %rax, %r13
testq %rcx, %rcx
movq %r9, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
je 0x6401f
movq (%rcx), %rax
movq 0x10(%rax), %rcx
leaq (%rbx,%rbx,4), %rdx
movq 0x20(%rcx,%rdx,8), %rax
testb %dil, %dil
je 0x6409d
leaq (%rcx,%rdx,8), %rcx
movl (%rcx), %ecx
shrl %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
jmp 0x6409f
movq %r9, 0x8(%rbp)
movq (%rbp), %rax
cmpq %r9, 0x10(%rbp)
jge 0x64061
movq %rax, %rdi
movq %r9, %rsi
movq %r8, 0x38(%rsp)
movq %r10, 0x30(%rsp)
callq 0x2370
movq 0x30(%rsp), %r10
movq 0x38(%rsp), %r8
movb 0x80(%rsp), %dil
movq 0x20(%rsp), %r9
movq %rax, (%rbp)
movq %r9, 0x10(%rbp)
cmpl $-0x1, %r14d
jne 0x6406c
testl %r15d, %r15d
js 0x640c9
testq %r10, %r10
je 0x640a7
movq (%r10), %rcx
leaq (%rbx,%rbx,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rcx), %rdx
movq $0x0, (%rsp)
movzbl %dil, %ecx
xorl %edi, %edi
movq %rax, %rsi
movq 0x18(%rsp), %r8
callq 0x36049
jmp 0x640c5
xorl %ecx, %ecx
addq %rsi, %rcx
addq %rcx, %rax
jmp 0x640c9
testq %r8, %r8
je 0x640c5
movzbl %dil, %ecx
movq %rax, %rdi
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %rbx, %r9
callq 0x32ef8
movq (%rbp), %rax
xorl %ecx, %ecx
movl %ecx, 0x1c(%r12)
movl %ecx, 0x10(%r12)
movq %rax, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x98a19
testl %eax, %eax
je 0x64104
movl %r14d, 0x10(%r12)
movl 0x14(%rsp), %eax
movl %eax, 0x1c(%r12)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x230ed5(%rip), %r14    # 0x294fe0
movq (%r14), %rdi
movl 0xa8(%r12), %ecx
leaq 0x1cea71(%rip), %rsi    # 0x232b8e
leaq 0x1cea81(%rip), %rdx    # 0x232ba5
xorl %eax, %eax
callq 0x22b0
cmpl $0x0, 0xa8(%r12)
jle 0x64146
leaq 0xa8(%r12), %rsi
movq %r12, %rdi
callq 0x5f9f
movl 0x2c(%rsp), %eax
subl 0x14(%rsp), %eax
incl %eax
movslq %eax, %rbx
movq (%r14), %rdi
leaq 0x1cea7b(%rip), %r15    # 0x232bd8
leaq 0x1cea41(%rip), %r12    # 0x232ba5
movq %r15, %rsi
movq %r12, %rdx
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %r8
xorl %eax, %eax
callq 0x22b0
movq (%r14), %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %rbx, %rcx
movq 0x40(%rsp), %r8
xorl %eax, %eax
callq 0x22b0
movl $0x1, %edi
callq 0x2250