// File: /workspace/github_cpp_makefile_star2_O1/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, %rbp
movq %rsi, 0x10(%rsp)
movq %rdi, %r12
movl 0xc(%rdi), %ebx
leaq (%rbx,%rbx,2), %rdi
shlq $0x3, %rdi
addq 0x10(%r8), %rdi
movabsq $-0x100000000, %r13     # imm = 0xFFFFFFFF00000000
movl 0x10(%r12), %esi
movl 0x14(%r12), %edx
movq (%r12), %r14
movl %r14d, %ecx
movl 0x8(%r12), %r8d
movl 0x18(%r12), %eax
shrl $0x1f, %eax
leaq 0x28(%rsp), %r10
leaq 0x30(%rsp), %r11
leaq 0x38(%rsp), %r15
leaq 0x40(%rsp), %r9
pushq %rax
pushq %r10
pushq %r11
pushq %r15
callq 0x18214e
addq $0x20, %rsp
movl %eax, 0xc(%rsp)
testl %eax, %eax
je 0x18261f
movl 0x40(%rsp), %eax
movl %eax, 0x10(%r12)
movl 0x38(%rsp), %eax
movl %eax, 0x14(%r12)
andq %r13, %r14
movq %r14, (%r12)
orq 0x30(%rsp), %r14
movq %r14, (%r12)
movl 0x28(%rsp), %eax
movl %eax, 0x8(%r12)
movq %rbp, 0x18(%rsp)
movq 0x8(%rbp), %r11
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movq (%rax,%rbx,8), %r10
movq (%r12), %r8
movl %r8d, %eax
movl 0x10(%r12), %edx
cmpq %r11, %rax
movq %r11, %rsi
cmovlq %rax, %rsi
cmpq %rdx, %r10
movq %rdx, %rdi
cmovlq %r10, %rdi
movq %rsi, %rbx
subq %rdi, %rbx
negq %rbx
xorl %ecx, %ecx
movq %rsi, %rbp
subq %rdi, %rbp
cmovleq %rcx, %rbp
cmovgq %rcx, %rbx
movl 0x8(%r12), %r9d
cmpq %r9, %r11
cmovlq %r11, %r9
movl 0x14(%r12), %ecx
cmpq %rcx, %r10
cmovlq %r10, %rcx
movq %r11, %r15
subq %r9, %r15
movq %r10, %r14
subq %rcx, %r14
cmpq %r14, %r15
leaq (%r14,%r9), %r14
cmovleq %r11, %r14
leaq (%rcx,%r15), %r15
cmovgq %r10, %r15
andq %r8, %r13
orq %rbp, %r13
movq %r13, (%r12)
movl %r14d, 0x8(%r12)
movl %ebx, 0x10(%r12)
movl %r15d, 0x14(%r12)
cmpl $0x0, 0xc(%rsp)
je 0x18274c
movq %r9, %r8
subq %rsi, %r8
movq %rcx, %rsi
subq %rdi, %rsi
cmpq %rsi, %r8
jne 0x18274c
cmpq %rdx, %rcx
jle 0x18274c
cmpq %r9, %rax
jge 0x18274c
subq %rbp, %r14
jle 0x18274c
subq %rbx, %r15
cmpq %r14, %r15
jne 0x18274c
movq 0x20(%rsp), %r13
cmpq %r15, 0x10(%r13)
jge 0x182710
movq (%r13), %rdi
movq %r15, %rsi
callq 0x2370
movq %rax, (%r13)
movq %r15, 0x10(%r13)
movq (%r13), %rdi
movl 0xc(%r12), %r9d
movl 0x18(%r12), %ecx
shrl $0x1f, %ecx
movq %rbx, %rsi
movq %r15, %rdx
movq 0x10(%rsp), %r8
callq 0x337f7
movq 0x18(%rsp), %rax
addq (%rax), %rbp
movq (%r13), %rsi
movq %rbp, %rdi
movq %r14, %rdx
callq 0x21a0
testl %eax, %eax
je 0x18275d
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %eax
jmp 0x18274e