// File: 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
movq %rsp, %rbp
pushq %rbx
subq $0xb8, %rsp
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
imulq $0x18, %rax, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %esi
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, %edx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %r8d
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x1f, %rax
andq $0x1, %rax
leaq -0x40(%rbp), %r9
leaq -0x48(%rbp), %rbx
leaq -0x50(%rbp), %r11
leaq -0x58(%rbp), %r10
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movl %eax, 0x18(%rsp)
callq 0x259710
cmpl $0x0, %eax
je 0x259cba
movq -0x40(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x48(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x14(%rax)
movq $0x1, -0x60(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
shrq $0x20, %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
shlq $0x20, %rcx
movq %rcx, (%rax)
movq -0x50(%rbp), %rcx
movq -0x18(%rbp), %rax
orq (%rax), %rcx
movq %rcx, (%rax)
movq -0x58(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0xc(%rcx), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, %eax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movq %rax, -0xa0(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x68(%rbp), %rax
jl 0x259d2f
movq -0x68(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x90(%rbp), %rax
cmpq -0x68(%rbp), %rax
jle 0x259d47
movq -0x68(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
cmpq -0x88(%rbp), %rax
jg 0x259d5f
movq $0x0, -0x60(%rbp)
movq -0x98(%rbp), %rax
cmpq -0x70(%rbp), %rax
jl 0x259d77
movq -0x70(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0xa0(%rbp), %rax
cmpq -0x70(%rbp), %rax
jle 0x259d8f
movq -0x70(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
cmpq -0x98(%rbp), %rax
jg 0x259da7
movq $0x0, -0x60(%rbp)
movq -0x90(%rbp), %rax
subq -0x88(%rbp), %rax
movq -0xa0(%rbp), %rcx
subq -0x98(%rbp), %rcx
cmpq %rcx, %rax
je 0x259dd0
movq $0x0, -0x60(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x98(%rbp), %rax
jg 0x259e05
movq -0x88(%rbp), %rcx
movq -0x98(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x98(%rbp)
movq $0x0, -0x88(%rbp)
jmp 0x259e28
movq -0x98(%rbp), %rcx
movq -0x88(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x88(%rbp)
movq $0x0, -0x98(%rbp)
movq -0x68(%rbp), %rax
subq -0x90(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
subq -0xa0(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x80(%rbp), %rax
jg 0x259e6f
movq -0x68(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x78(%rbp), %rax
addq -0xa0(%rbp), %rax
movq %rax, -0xa0(%rbp)
jmp 0x259e8c
movq -0x70(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x80(%rbp), %rax
addq -0x90(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
shrq $0x20, %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
shlq $0x20, %rcx
movq %rcx, (%rax)
movq -0x88(%rbp), %rcx
movq -0x18(%rbp), %rax
orq (%rax), %rcx
movq %rcx, (%rax)
movq -0x90(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x98(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0xa0(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x14(%rax)
cmpq $0x0, -0x60(%rbp)
je 0x259fbe
movq -0xa0(%rbp), %rax
subq -0x98(%rbp), %rax
movq -0x90(%rbp), %rcx
subq -0x88(%rbp), %rcx
cmpq %rcx, %rax
jne 0x259fbe
movq -0x90(%rbp), %rax
cmpq -0x88(%rbp), %rax
jle 0x259fbe
movq -0x30(%rbp), %rdi
movq -0xa0(%rbp), %rsi
subq -0x98(%rbp), %rsi
callq 0xa62c0
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq -0x98(%rbp), %rsi
movq -0xa0(%rbp), %rdx
subq -0x98(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x1f, %rax
andq $0x1, %rax
movq -0x20(%rbp), %r8
movq -0x18(%rbp), %rcx
movl 0xc(%rcx), %ecx
movl %ecx, %r9d
movzbl %al, %ecx
callq 0x9a30
movq -0x28(%rbp), %rax
movq (%rax), %rdi
addq -0x88(%rbp), %rdi
movq -0x30(%rbp), %rax
movq (%rax), %rsi
movq -0x90(%rbp), %rdx
subq -0x88(%rbp), %rdx
callq 0x20b0
cmpl $0x0, %eax
jne 0x259fbc
movl $0x1, -0xc(%rbp)
jmp 0x259fc5
jmp 0x259fbe
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0xb8, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)