// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %rsp
movq %r9, 0x10(%rsp)
movq %rcx, %rbx
movq %rsi, %r11
movq %rdi, %r10
movq 0xc8(%rsp), %rsi
movq 0xc0(%rsp), %rax
movq 0xa8(%rsp), %r13
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %r15
movabsq $0x7fffffff00000000, %rcx # imm = 0x7FFFFFFF00000000
movq %rcx, 0x28(%rbx)
movq $0x0, 0xa8(%rbx)
subq %rdi, %r15
cmpq $0x3, %rax
setne %cl
testq %rsi, %rsi
sete %r9b
orb %cl, %r9b
movq %rdx, 0x28(%rsp)
movq %r10, 0x30(%rsp)
jne 0x657f9
movl 0x4(%rsi), %eax
movl 0x14(%rsi), %ecx
movq %rcx, 0x8(%rsp)
movq %rdi, %r14
subq %rax, %r14
addq $0x38, %rsi
movq %r8, %r12
movq %r15, %rbp
movq %r11, %r15
callq 0x48df6
movq %r15, %r11
movq %rbp, %r15
movq %r12, %r8
movq %rax, %r12
addq 0x8(%rsp), %r12
addq %r14, %r12
leaq (%r12,%rbp), %rcx
jmp 0x65821
movq 0x88(%rsp), %rcx
cmpq $0x2, %rax
je 0x6581b
movq 0x80(%rsp), %r12
cmpq $0x1, %rax
jne 0x65821
leaq (%r15,%r12), %rcx
jmp 0x65821
movq %rcx, %r12
subq %r15, %r12
xorl %eax, %eax
testq %r12, %r12
cmovleq %rax, %r12
cmpq %r13, %r12
cmovgeq %r13, %r12
cmpq %r13, %rcx
cmovlq %rcx, %r13
movq %r13, %rbp
subq %r12, %rbp
cmpq %rbp, %r15
jne 0x65aa4
movl 0xb0(%rsp), %r10d
movq 0x98(%rsp), %rdx
movq 0x90(%rsp), %rdi
addq 0x70(%rsp), %r8
movslq 0xb8(%rsp), %rcx
testq %r11, %r11
je 0x65895
movq (%r11), %rax
movq 0x10(%rax), %rax
leaq (%rcx,%rcx,4), %rcx
movq 0x20(%rax,%rcx,8), %rsi
testb %r10b, %r10b
je 0x658f8
leaq (%rax,%rcx,8), %rax
movl (%rax), %eax
shrl %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
jmp 0x658fa
movq %rcx, 0x18(%rsp)
movq %r8, 0x8(%rsp)
movq (%rdi), %r14
movq (%rdx), %r11
movq 0x10(%rsp), %rcx
movq %rbp, 0x8(%rcx)
cmpq %rbp, 0x10(%rcx)
jge 0x658dd
movq (%rcx), %rdi
movq %rbp, %rsi
movq %r11, 0x20(%rsp)
callq 0x2370
movq 0x20(%rsp), %r11
movl 0xb0(%rsp), %r10d
movq 0x10(%rsp), %rcx
movq %rax, (%rcx)
movq %rbp, 0x10(%rcx)
movq (%rcx), %rsi
cmpq %r14, %r12
jne 0x65902
movq %r11, %rax
subq %r14, %rax
movq %rbp, %r9
subq %rax, %r9
jle 0x65967
addq %rax, %rsi
jmp 0x65908
xorl %eax, %eax
addq %rax, %rsi
addq %r12, %rsi
jmp 0x6597c
movq %r12, %r11
movq %rbp, %r9
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0x6593e
movq (%rax), %rax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rcx,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rax), %rdx
movq $0x0, (%rsp)
movzbl %r10b, %ecx
xorl %edi, %edi
movq %r11, %r8
callq 0x36b0d
jmp 0x6595f
movq 0x28(%rsp), %r8
testq %r8, %r8
je 0x6595f
movzbl %r10b, %ecx
movq %rsi, %rdi
movq %r11, %rsi
movq %r9, %rdx
movq 0x18(%rsp), %r9
callq 0x337f7
movq 0x10(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rsp), %r8
movq 0x98(%rsp), %rdx
movq 0x90(%rsp), %rdi
movq %r12, (%rdi)
movq %r13, (%rdx)
movq %r8, %rdi
movq %r15, %rdx
callq 0x21a0
testl %eax, %eax
je 0x65998
xorl %eax, %eax
jmp 0x65aa4
movl $0x0, 0x2c(%rbx)
movl %r15d, %r14d
cmpl $0x3fff, %r15d          # imm = 0x3FFF
jb 0x65a1b
movl $0x2, %r13d
movl %r15d, %r14d
movq 0xb0(%rbx), %rax
cmpq %rax, 0xa8(%rbx)
jne 0x659ec
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r13, %rsi
movq %rsi, 0xb0(%rbx)
movq 0xb8(%rbx), %rdi
addq %rsi, %rsi
callq 0x2370
movq %rax, 0xb8(%rbx)
movq 0xa8(%rbx), %rax
movq 0xb8(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0xa8(%rbx)
movw $0x3fff, (%rcx,%rax,2)  # imm = 0x3FFF
addl $0xffffc001, %r14d      # imm = 0xFFFFC001
cmpl $0x3ffe, %r14d          # imm = 0x3FFE
ja 0x659b4
testl %r14d, %r14d
je 0x65a7b
movq 0xb0(%rbx), %rax
cmpq %rax, 0xa8(%rbx)
jne 0x65a5d
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0xb0(%rbx)
movq 0xb8(%rbx), %rdi
addq %rsi, %rsi
callq 0x2370
movq %rax, 0xb8(%rbx)
movq 0xa8(%rbx), %rax
movq 0xb8(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0xa8(%rbx)
movw %r14w, (%rcx,%rax,2)
movl %ebp, 0x18(%rbx)
movl %r15d, 0x24(%rbx)
movl %r12d, 0x10(%rbx)
leal (%r12,%rbp), %eax
decl %eax
movl %eax, 0x14(%rbx)
movq 0x70(%rsp), %rax
movl %eax, 0x1c(%rbx)
addl %r15d, %eax
decl %eax
movl %eax, 0x20(%rbx)
movl $0x1, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq