// File: 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
movq %rsp, %rbp
pushq %rbx
subq $0x78, %rsp
movq 0x68(%rbp), %rax
movq 0x60(%rbp), %rax
movl 0x58(%rbp), %eax
movl 0x50(%rbp), %eax
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movq -0x30(%rbp), %rax
movl $0x7fffffff, 0x2c(%rax) # imm = 0x7FFFFFFF
movq -0x30(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0xa8(%rax)
movq 0x18(%rbp), %rax
subq 0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x3, 0x60(%rbp)
jne 0x60631
cmpq $0x0, 0x68(%rbp)
je 0x60631
movq 0x10(%rbp), %rax
movq 0x68(%rbp), %rcx
movl 0x4(%rcx), %ecx
subq %rcx, %rax
movq 0x68(%rbp), %rcx
movl 0x14(%rcx), %ecx
addq %rcx, %rax
movq %rax, 0x20(%rbp)
movq 0x10(%rbp), %rdi
movq 0x68(%rbp), %rsi
addq $0x38, %rsi
callq 0x331a0
addq 0x20(%rbp), %rax
movq %rax, 0x20(%rbp)
movq 0x20(%rbp), %rax
addq -0x48(%rbp), %rax
movq %rax, 0x28(%rbp)
jmp 0x6065d
cmpq $0x1, 0x60(%rbp)
jne 0x60646
movq 0x20(%rbp), %rax
addq -0x48(%rbp), %rax
movq %rax, 0x28(%rbp)
jmp 0x6065b
cmpq $0x2, 0x60(%rbp)
jne 0x60659
movq 0x28(%rbp), %rax
subq -0x48(%rbp), %rax
movq %rax, 0x20(%rbp)
jmp 0x6065b
jmp 0x6065d
cmpq $0x0, 0x20(%rbp)
jge 0x6066c
movq $0x0, 0x20(%rbp)
movq 0x20(%rbp), %rax
cmpq 0x48(%rbp), %rax
jle 0x6067e
movq 0x48(%rbp), %rax
movq %rax, 0x20(%rbp)
movq 0x28(%rbp), %rax
cmpq 0x48(%rbp), %rax
jle 0x60690
movq 0x48(%rbp), %rax
movq %rax, 0x28(%rbp)
movq 0x18(%rbp), %rax
subq 0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq 0x28(%rbp), %rax
subq 0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
je 0x606bf
movq $0x0, -0x10(%rbp)
jmp 0x60820
movq -0x38(%rbp), %rax
addq 0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rdi
movq 0x20(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq 0x30(%rbp), %rax
movq (%rax), %rcx
movq 0x38(%rbp), %rax
movq (%rax), %r8
movq 0x30(%rbp), %rax
subq (%rax), %r8
movl 0x50(%rbp), %eax
movb %al, %r9b
movq -0x18(%rbp), %rbx
movq -0x20(%rbp), %r11
movq -0x28(%rbp), %r10
movslq 0x58(%rbp), %rax
movzbl %r9b, %r9d
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0xc0c80
movq %rax, -0x60(%rbp)
movq 0x20(%rbp), %rcx
movq 0x30(%rbp), %rax
movq %rcx, (%rax)
movq 0x28(%rbp), %rcx
movq 0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x20b0
cmpl $0x0, %eax
je 0x6075b
movq $0x0, -0x10(%rbp)
jmp 0x60820
movq -0x30(%rbp), %rax
movl $0x0, 0x2c(%rax)
movq -0x30(%rbp), %rdi
addq $0xa8, %rdi
movq -0x48(%rbp), %rax
movl %eax, %edx
xorl %esi, %esi
callq 0xc1070
movq -0x50(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x30(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x50(%rbp), %rax
subq $0x1, %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x48(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x30(%rbp), %rax
movl $0x0, 0x1c(%rax)
movq -0x48(%rbp), %rax
subq $0x1, %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x20(%rax)
movq 0x20(%rbp), %rdx
movq -0x30(%rbp), %rax
movslq 0x10(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x10(%rax)
movq 0x20(%rbp), %rdx
movq -0x30(%rbp), %rax
movslq 0x14(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x14(%rax)
movq 0x10(%rbp), %rdx
movq -0x30(%rbp), %rax
movslq 0x1c(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x1c(%rax)
movq 0x10(%rbp), %rdx
movq -0x30(%rbp), %rax
movslq 0x20(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x20(%rax)
movq $0x1, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0x78, %rsp
popq %rbx
popq %rbp
retq
nopl (%rax,%rax)