// File: /workspace/github_cpp_makefile_star2_O1/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 %r8, %r10
movq %rdx, %r11
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, %r8
subq %r8, %r15
leaq 0x1(%r15), %r9
movl 0x20(%r12), %edx
movl %edx, 0x24(%rsp)
movl %eax, 0x14(%rsp)
cltq
movq %rax, 0x40(%rsp)
addq %rax, %r13
testq %rcx, %rcx
movq %r9, 0x18(%rsp)
movq %r8, 0x28(%rsp)
je 0x644fe
movq (%rcx), %rax
movq 0x10(%rax), %rax
leaq (%rbx,%rbx,4), %rcx
movq 0x20(%rax,%rcx,8), %rsi
testb %dil, %dil
je 0x64584
leaq (%rax,%rcx,8), %rax
movl (%rax), %eax
shrl %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
jmp 0x64586
movq %rsi, %rbp
movq %r9, 0x8(%rsi)
cmpq %r9, 0x10(%rsi)
jge 0x64545
movq (%rbp), %rdi
movq %r9, %rsi
movq %r10, 0x38(%rsp)
movq %r11, 0x30(%rsp)
callq 0x2370
movq 0x30(%rsp), %r11
movq 0x38(%rsp), %r10
movb 0x80(%rsp), %dil
movq 0x18(%rsp), %r9
movq 0x28(%rsp), %r8
movq %rax, (%rbp)
movq %r9, 0x10(%rbp)
movq (%rbp), %rsi
cmpl $-0x1, %r14d
jne 0x6455b
movq $-0x1, %r8
testl %r15d, %r15d
js 0x645b1
testq %r11, %r11
je 0x6458e
movq (%r11), %rax
leaq (%rbx,%rbx,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rax), %rdx
movq $0x0, (%rsp)
movzbl %dil, %ecx
xorl %edi, %edi
callq 0x36b0d
jmp 0x645ad
xorl %eax, %eax
addq %r8, %rax
addq %rax, %rsi
jmp 0x645b1
testq %r10, %r10
je 0x645ad
movzbl %dil, %ecx
movq %rsi, %rdi
movq %r8, %rsi
movq 0x18(%rsp), %rdx
movq %r10, %r8
movq %rbx, %r9
callq 0x337f7
movq (%rbp), %rsi
xorl %eax, %eax
movl %eax, 0x1c(%r12)
movl %eax, 0x10(%r12)
movq %rsi, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x97ed2
testl %eax, %eax
je 0x645ec
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 0x2259ed(%rip), %r14    # 0x289fe0
movq (%r14), %rdi
movl 0xa8(%r12), %ecx
leaq 0x1c2479(%rip), %rsi    # 0x226a7e
leaq 0x1c2489(%rip), %rdx    # 0x226a95
xorl %eax, %eax
callq 0x22b0
cmpl $0x0, 0xa8(%r12)
jle 0x6462e
leaq 0xa8(%r12), %rsi
movq %r12, %rdi
callq 0x5e34
movl 0x24(%rsp), %eax
subl 0x14(%rsp), %eax
incl %eax
movslq %eax, %rbx
movq (%r14), %rdi
leaq 0x1c2483(%rip), %r15    # 0x226ac8
leaq 0x1c2449(%rip), %r12    # 0x226a95
movq %r15, %rsi
movq %r12, %rdx
movq 0x18(%rsp), %rcx
movq 0x28(%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