// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/ecovlp.cpp
// Function: quick_exact_match(ma_hit_t*, All_reads*, UC_Read*, UC_Read*, cc_v*)
uint32_t quick_exact_match(ma_hit_t *z, All_reads *rref, UC_Read* qu, UC_Read* tu, cc_v *sc)
{
    uint64_t rts, rte, rqs, rqe, f = 0; int64_t ql, tl, qr, tr, qs, qe, ts, te;

    // fprintf(stderr, "-0-[M::%s]\tf::%lu\n", __func__, f);
    if(adjust_exact_match(&(sc->a[z->tn]), z->ts, z->te, ((uint32_t)(z->qns)), z->qe, &rts, &rte, &rqs, &rqe, z->rev)) {
        z->ts = rts; z->te = rte; f = 1;
        z->qns >>= 32; z->qns <<= 32; z->qns |= ((uint64_t)(rqs)); z->qe = rqe;

        ///debug
        // qs = rqs; qe = rqe; ts = rts; te = rte; 
        // resize_UC_Read(tu, te - ts); 
        // recover_UC_Read_sub_region(tu->seq, ts, te - ts, z->rev, rref, z->tn);
        
        // fprintf(stderr, "[M::%s]\trq::[%lu,%lu)\trt::[%lu,%lu)\n", __func__, rqs, rqe, rts, rte);
        // fprintf(stderr, "-0-[M::%s] qstr::%.*s\n", __func__, ((int)(qe - qs)), qu->seq + qs);
        // fprintf(stderr, "-0-[M::%s] tstr::%.*s\n", __func__, ((int)(te - ts)), tu->seq);

        // if(memcmp(qu->seq + qs, tu->seq, qe - qs) == 0) {
        //     fprintf(stderr, "-0-[M::%s]\tsb\n", __func__);
        // } else {
        //     fprintf(stderr, "-1-[M::%s]\tsa\n", __func__);
        // }
    }
    // fprintf(stderr, "-1-[M::%s]\tf::%lu\n", __func__, f);
    ql = qu->length; tl = Get_READ_LENGTH((*rref), z->tn);
    qs = ((uint32_t)(z->qns)); qe = z->qe; ts = z->ts; te = z->te;
    if(qs >= ql) qs = ql; if(qe > ql) qe = ql; if(qe <= qs) f = 0;
    // fprintf(stderr, "-2-[M::%s]\tf::%lu\n", __func__, f);
    if(ts >= tl) ts = tl; if(te > tl) te = tl; if(te <= ts) f = 0;
    // fprintf(stderr, "-3-[M::%s]\tf::%lu\n", __func__, f);
    if((qe - qs) != (te - ts)) f = 0;
    // fprintf(stderr, "-4-[M::%s]\tf::%lu\n", __func__, f);

    if(qs <= ts) {
        ts -= qs; qs = 0;
    } else {
        qs -= ts; ts = 0;
    }


    qr = ql - qe; tr = tl - te;
    if(qr <= tr) {
        qe = ql; te += qr;        
    } else {
        te = tl; qe += tr; 
    }

    // fprintf(stderr, "-5-[M::%s]\tzq::[%ld,\t%ld)\tzt::[%ld,\t%ld)\teq::[%u,\t%u)\tet::[%u,\t%u)\tql::%ld\ttl::%ld\tf::%lu\n", 
    // __func__, qs, qe, ts, te, ((uint32_t)(z->qns)), z->qe, z->ts, z->te, ql, tl, f);

    z->qns >>= 32; z->qns <<= 32; z->qns |= ((uint64_t)(qs)); z->qe = qe;
    z->ts = ts; z->te = te;

    if((f) && ((te - ts) == (qe - qs)) && (qe > qs)) {
        resize_UC_Read(tu, te - ts); 
        recover_UC_Read_sub_region(tu->seq, ts, te - ts, z->rev, rref, z->tn);

        // fprintf(stderr, "[M::%s] qstr::%.*s\n", __func__, ((int)(qe - qs)), qu->seq + qs);
        // fprintf(stderr, "[M::%s] tstr::%.*s\n", __func__, ((int)(te - ts)), tu->seq);

        if(memcmp(qu->seq + qs, tu->seq, qe - qs) == 0) return 1;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, 0x20(%rsp)
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, %r12
movabsq $-0x100000000, %r15     # imm = 0xFFFFFFFF00000000
movl 0xc(%rdi), %eax
imulq $0x18, %rax, %rdi
addq 0x10(%r8), %rdi
movl 0x10(%r12), %esi
movl 0x14(%r12), %edx
movl (%r12), %ecx
movl 0x8(%r12), %r8d
movl 0x18(%r12), %eax
shrl $0x1f, %eax
leaq 0x28(%rsp), %r10
leaq 0x30(%rsp), %r11
leaq 0x38(%rsp), %rbx
leaq 0x40(%rsp), %r9
pushq %rax
pushq %r10
pushq %r11
pushq %rbx
callq 0x144df4
addq $0x20, %rsp
movq (%r12), %rcx
movl %eax, 0xc(%rsp)
testl %eax, %eax
je 0x1450d1
movl 0x40(%rsp), %edx
movl 0x38(%rsp), %r14d
andq %r15, %rcx
orq 0x30(%rsp), %rcx
movq %rcx, (%r12)
movl 0x28(%rsp), %r10d
jmp 0x1450e0
movl 0x8(%r12), %r10d
movl 0x10(%r12), %edx
movl 0x14(%r12), %r14d
movq %r13, 0x18(%rsp)
movq 0x8(%r13), %r11
movq %rbp, 0x10(%rsp)
movq 0x18(%rbp), %rax
movl 0xc(%r12), %esi
movq (%rax,%rsi,8), %r9
movl %ecx, %eax
movl %edx, %esi
cmpq %r11, %rax
movq %r11, %rdi
cmovlq %rax, %rdi
cmpq %rsi, %r9
movq %rsi, %r8
cmovlq %r9, %r8
movq %rdi, %rbx
subq %r8, %rbx
negq %rbx
xorl %edx, %edx
movq %rdi, %rbp
subq %r8, %rbp
cmovleq %rdx, %rbp
cmovgq %rdx, %rbx
movl %r10d, %r10d
cmpq %r10, %r11
cmovlq %r11, %r10
movl %r14d, %edx
cmpq %rdx, %r9
cmovlq %r9, %rdx
movq %r11, %r14
subq %r10, %r14
movq %r9, %r13
subq %rdx, %r13
cmpq %r13, %r14
leaq (%r13,%r10), %r13
cmovleq %r11, %r13
leaq (%rdx,%r14), %r14
cmovgq %r9, %r14
andq %rcx, %r15
orq %rbp, %r15
movq %r15, (%r12)
movl %r13d, 0x8(%r12)
movl %ebx, 0x10(%r12)
movl %r14d, 0x14(%r12)
cmpl $0x0, 0xc(%rsp)
je 0x1451f2
movq %r10, %rcx
subq %rdi, %rcx
movq %rdx, %rdi
subq %r8, %rdi
cmpq %rdi, %rcx
jne 0x1451f2
cmpq %rsi, %rdx
jle 0x1451f2
cmpq %r10, %rax
jge 0x1451f2
subq %rbp, %r13
jle 0x1451f2
subq %rbx, %r14
cmpq %r13, %r14
jne 0x1451f2
movq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x562fa
movq (%r15), %rdi
movl 0xc(%r12), %r9d
movl 0x18(%r12), %ecx
shrl $0x1f, %ecx
movq %rbx, %rsi
movq %r14, %rdx
movq 0x10(%rsp), %r8
callq 0x6c9e
movq 0x18(%rsp), %rax
addq (%rax), %rbp
movq (%r15), %rsi
movq %rbp, %rdi
movq %r14, %rdx
callq 0x21a0
testl %eax, %eax
je 0x145203
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rax
jmp 0x1451f4