// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: cal_exact_simi_exz(ul_idx_t const*, hpc_t*, All_reads*, bit_extz_t*, char*, UC_Read*, long, long, long, long, long*, long*, long, long, int, int, long, overlap_region*)
int64_t cal_exact_simi_exz(const ul_idx_t *uref, hpc_t *hpc_g, All_reads *rref, 
bit_extz_t *exz, char* qstr, UC_Read *tu, int64_t qs, int64_t qe, int64_t ts, int64_t te, 
int64_t *pts, int64_t *pte, int64_t q_tot_l, int64_t t_tot_l, int32_t rev, int32_t id, 
int64_t mode, overlap_region *z)
{
    clear_align(*exz); exz->thre = 0; exz->cigar.n = 0;
    int64_t ql, tl; char *q_string, *t_string; ql = qe - qs;

    if(mode == 3 && z) {//semi
        ts = (qs - z->x_pos_s) + z->y_pos_s; ts += y_start_offset(qs, &(z->f_cigar));
        te = ts + ql; 
    } else if(mode == 1) {///forward extension
        te = ts + ql; 
    } else if(mode == 2) {///backward extension
        ts = te - ql; 
    }
    if(ts < 0) ts = 0;
    if(ts > t_tot_l) ts = t_tot_l;
    if(te > t_tot_l) te = t_tot_l;
    ql = qe - qs; tl = te - ts; 
    if(ql != tl) return 0;

    q_string = qstr + qs; 
    t_string = retrieve_str_seq_exz(tu, ts, tl, (*pts), (*pte)-(*pts), rev, uref, hpc_g, rref, id);
    (*pts) = ts; (*pte) = te;

    if(memcmp(q_string, t_string, ql)) return 0;
    exz->err = 0; push_trace(&(exz->cigar), 0, ql);
    exz->pl = tl; exz->ps = 0; exz->pe = tl-1;
    exz->tl = ql; exz->ts = 0; exz->te = ql-1;
    
    exz->ps += ts; exz->pe += ts;
    exz->ts += qs; exz->te += qs;
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %rbx
movq %rsi, %r14
movq %rdi, %r11
movq 0xb8(%rsp), %rsi
movq 0xb0(%rsp), %rax
movq 0x98(%rsp), %rbp
movabsq $0x7fffffff00000000, %rcx # imm = 0x7FFFFFFF00000000
movq %rcx, 0x28(%rbx)
andq $0x0, 0xa8(%rbx)
movq 0x60(%rsp), %rdi
movq 0x68(%rsp), %r15
subq %rdi, %r15
cmpq $0x3, %rax
setne %cl
testq %rsi, %rsi
sete %r10b
orb %cl, %r10b
movq %r8, 0x20(%rsp)
movq %r14, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq %r9, 0x8(%rsp)
jne 0x34697
movl 0x4(%rsi), %eax
movl 0x14(%rsi), %r14d
movq %rdi, %r12
subq %rax, %r12
addq $0x38, %rsi
movq %r11, %r13
callq 0x1bebf
movq %r13, %r11
movq %rax, %r13
addq %r14, %r13
addq %r12, %r13
leaq (%r15,%r13), %rcx
jmp 0x346b9
movq 0x78(%rsp), %rcx
cmpq $0x2, %rax
je 0x346b3
movq 0x70(%rsp), %r13
cmpq $0x1, %rax
jne 0x346b9
leaq (%r15,%r13), %rcx
jmp 0x346b9
movq %rcx, %r13
subq %r15, %r13
xorl %eax, %eax
testq %r13, %r13
cmovleq %rax, %r13
cmpq %rbp, %r13
cmovgeq %rbp, %r13
cmpq %rbp, %rcx
cmovlq %rcx, %rbp
movq %rbp, %rcx
subq %r13, %rcx
cmpq %rcx, %r15
jne 0x3479d
movl 0xa0(%rsp), %eax
movq 0x88(%rsp), %rdx
movq 0x80(%rsp), %rcx
movq 0x60(%rsp), %r14
movq 0x20(%rsp), %r12
addq %r14, %r12
movq (%rcx), %rcx
movq (%rdx), %r8
subq %rcx, %r8
movslq 0xa8(%rsp), %r10
movzbl %al, %r9d
movq 0x8(%rsp), %rdi
movq %r13, %rsi
movq %r15, %rdx
pushq %r10
pushq 0x18(%rsp)
pushq 0x28(%rsp)
pushq %r11
callq 0x625fc
addq $0x20, %rsp
movq 0x80(%rsp), %rcx
movq %r13, (%rcx)
movq 0x88(%rsp), %rcx
movq %rbp, (%rcx)
movq %r12, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x21a0
testl %eax, %eax
je 0x34764
xorl %eax, %eax
jmp 0x3479d
leaq 0xa8(%rbx), %rdi
andl $0x0, 0x2c(%rbx)
xorl %esi, %esi
movl %r15d, %edx
callq 0x62885
movl %r15d, 0x18(%rbx)
movl %r15d, 0x24(%rbx)
movl %r13d, 0x10(%rbx)
leal (%r15,%r13), %eax
decl %eax
movl %eax, 0x14(%rbx)
movl %r14d, 0x1c(%rbx)
leal -0x1(%r15,%r14), %eax
movl %eax, 0x20(%rbx)
pushq $0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq