// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: gen_affine_traceback(overlap_region*, ul_idx_t const*, hpc_t*, All_reads*, char*, char*, unsigned long, unsigned long*, unsigned long, Candidates_list*, unsigned int, unsigned int, unsigned int)
uint64_t gen_affine_traceback(overlap_region *o, const ul_idx_t *uref, hpc_t *hpc_g, All_reads *rref, char* qstr, char *tstr, uint64_t ql, 
uint64_t *qhp, uint64_t qhp_l, Candidates_list *ac, uint32_t hpc_max, uint32_t min_ach, uint32_t block)
{
    if(o->w_list.n <= 0) return 0;
    int64_t nw = o->w_list.n, snw, k, t, qi, ti, ci, p_qi, p_ti, cn, qs, qe, ts, te, tl; 
    window_list *z; uint8_t c; uint32_t cl, pcl, id = o->y_id, rev = o->y_pos_strand; k_mer_hit *p;
    uint64_t hm, aocc = 0, bocc = 0; qi = ti = 0; p_qi = p_ti = INT32_MIN; pcl = 0;
    clear_Candidates_list(ac); 
    if(o->w_list.n > (uint64_t)ac->size) {
        ac->size = o->w_list.n; REALLOC(ac->list, ac->size);
    }

    if(hpc_g) tl = hpc_len(*hpc_g, id);
    else if(uref) tl = uref->ug->u.a[id].len;
    else tl = Get_READ_LENGTH((*rref), id);
    for (k = 0; k < nw; k++) {
        z = &(o->w_list.a[k]); ci = 0; cn = z->clen;
        qi = z->x_start; ti = z->y_start;
        for (ci = 0; ci < cn; ci++) {
            get_cigar_cell(z, &(o->w_list), ci, &c, &cl);
            if (c == 0) { //match   
                if((p_qi == qi) && (p_ti == ti)) {
                    pcl += cl;
                } else {
                    ///push
                    if(pcl > 0) {
                        hm = 0; qs = qi - pcl; qe = qi; ts = ti - pcl; te = ti;
                        if(pcl > min_ach) hm = trim_hpc(uref, hpc_g, rref, qstr, tstr, hpc_max, ql, tl, id, rev, &qs, &qe, &ts, &te);
                        if(hm) aocc++;
                        if(hm || aocc == 0) {
                            cl_pushp(k_mer_hit, *ac, &p);
                            p->readID = p->strand = !!hm;
                            p->cnt = qe - qs; p->self_offset = qe; p->offset = te;
                            if(p->cnt > min_ach) bocc++;
                        }
                    }
                    ///push
                    pcl = 0;
                }
                qi += cl; ti += cl;
                p_qi = qi; p_ti = ti;
            } else {
                ///push
                if(pcl > 0) {
                    hm = 0; qs = qi - pcl; qe = qi; ts = ti - pcl; te = ti;
                    if(pcl > min_ach) hm = trim_hpc(uref, hpc_g, rref, qstr, tstr, hpc_max, ql, tl, id, rev, &qs, &qe, &ts, &te);
                    if(hm) aocc++;
                    if(hm || aocc == 0) {
                        cl_pushp(k_mer_hit, *ac, &p);
                        p->readID = p->strand = !!hm;
                        p->cnt = qe - qs; p->self_offset = qe; p->offset = te;
                        if(p->cnt > min_ach) bocc++;
                    }
                }
                pcl = 0;
                ///push
                if (c == 1) {
                    qi += cl; ti += cl; 
                } if (c == 2) {///t has more bases than p
                    ti += cl; 
                } if (c == 3) {///p has more bases than t
                    qi += cl; 
                }
            } 
        }
    }

    ///push
    if(pcl > 0) {
        hm = 0; qs = qi - pcl; qe = qi; ts = ti - pcl; te = ti;
        if(pcl > min_ach) hm = trim_hpc(uref, hpc_g, rref, qstr, tstr, hpc_max, ql, tl, id, rev, &qs, &qe, &ts, &te);
        if(hm) aocc++;
        if(hm || aocc == 0) {
            cl_pushp(k_mer_hit, *ac, &p);
            p->readID = p->strand = !!hm;
            p->cnt = qe - qs; p->self_offset = qe; p->offset = te;
            if(p->cnt > min_ach) bocc++;
        }
    }
    ///push

    nw = ac->length; snw = -1;
    if(aocc > 0) {
        if(aocc < (uint64_t)ac->length) {
            for (k = t = snw = 0; k < nw; k++) {
                if(ac->list[k].readID) {
                    ac->list[t] = ac->list[k]; 
                    if(ac->list[t].cnt <= block) snw++;
                    else snw += (ac->list[t].cnt/block) + (((ac->list[t].cnt%block) > 0)?1:0);
                    t++;
                }
            }
            ac->length = t;
        }
    } else if (bocc > 0) {
        if(bocc < (uint64_t)ac->length) {
            for (k = t = snw = 0; k < nw; k++) {
                if(ac->list[k].cnt > min_ach) {
                    ac->list[t] = ac->list[k]; 
                    if(ac->list[t].cnt <= block) snw++;
                    else snw += (ac->list[t].cnt/block) + (((ac->list[t].cnt%block) > 0)?1:0);
                    t++;
                }
            }
            ac->length = t;
        }
    }
    nw = ac->length;
    gen_affine_traceback_dp(ac, 25, 5000, 5000, block, snw);
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r9, 0x90(%rsp)
movq %r8, 0x88(%rsp)
movq %rcx, 0x40(%rsp)
movq 0x48(%rdi), %rax
testq %rax, %rax
je 0x2e170
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rcx
movq %rax, %r12
movq 0x108(%rsp), %rbx
movl 0x10(%rdi), %eax
movq %rax, 0x20(%rsp)
movl 0x1c(%rdi), %eax
movq %rax, 0x80(%rsp)
movq %rbx, %rdi
movq %rcx, 0x28(%rsp)
callq 0x13d24
movq 0x28(%rsp), %r9
movq %rbx, %rdi
movq 0x48(%r9), %rsi
cmpq 0x10(%rbx), %rsi
jbe 0x2e140
movq %rsi, 0x10(%rdi)
movq (%rdi), %rdi
shlq $0x4, %rsi
callq 0x2370
movq 0x28(%rsp), %r9
movq 0x108(%rsp), %rdi
movq %rax, (%rdi)
movl 0x110(%rsp), %eax
testq %r14, %r14
movq %r14, 0x78(%rsp)
movq %r15, 0x70(%rsp)
je 0x2e177
movq (%r14), %rcx
movq 0x10(%rcx), %rcx
imulq $0x28, 0x20(%rsp), %rdx
movl (%rcx,%rdx), %ecx
shrl %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
jmp 0x2e1a6
xorl %eax, %eax
jmp 0x2e840
testq %r15, %r15
je 0x2e194
movq (%r15), %rcx
movq 0x10(%rcx), %rcx
imulq $0x28, 0x20(%rsp), %rdx
movl (%rcx,%rdx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0x2e1a6
movq 0x40(%rsp), %rcx
movq 0x18(%rcx), %rcx
movq 0x20(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq %rcx, 0x30(%rsp)
movl %eax, %eax
movq %rax, 0x68(%rsp)
xorl %r15d, %r15d
testq %r12, %r12
cmovleq %r15, %r12
movq %r12, 0xa0(%rsp)
movq $-0x80000000, %rsi      # imm = 0x80000000
xorl %r12d, %r12d
movq $-0x80000000, 0x60(%rsp) # imm = 0x80000000
xorl %edx, %edx
xorl %eax, %eax
xorl %r8d, %r8d
movq $0x0, 0x48(%rsp)
cmpq 0xa0(%rsp), %rdx
je 0x2e5d6
movq 0x58(%r9), %rcx
movq %rdx, 0xa8(%rsp)
shlq $0x5, %rdx
leaq (%rcx,%rdx), %r10
movl 0x1c(%rcx,%rdx), %r11d
movslq (%rcx,%rdx), %r15
movslq 0x8(%rcx,%rdx), %r12
xorl %ebp, %ebp
movq %r10, 0x58(%rsp)
movq %r11, 0x50(%rsp)
cmpq %rbp, %r11
je 0x2e5c6
movq 0x70(%r9), %rcx
movl 0x18(%r10), %edx
addl %ebp, %edx
movzwl (%rcx,%rdx,2), %r14d
movl %r14d, %ebx
andl $0x3fff, %ebx           # imm = 0x3FFF
movl %eax, %ecx
cmpw $0x3fff, %r14w          # imm = 0x3FFF
ja 0x2e26c
cmpq %r15, %rsi
jne 0x2e343
cmpq %r12, 0x60(%rsp)
jne 0x2e343
addl %ebx, %eax
movl %eax, %r13d
jmp 0x2e5ad
testl %eax, %eax
je 0x2e4c4
movq %r15, %rdx
subq %rcx, %rdx
movq %rdx, 0x18(%rsp)
movq %r15, 0x10(%rsp)
movq %r12, %rdx
subq %rcx, %rdx
movq %rdx, 0x38(%rsp)
movq %r12, 0x8(%rsp)
cmpl 0x118(%rsp), %eax
movq %rsi, 0x98(%rsp)
jbe 0x2e40d
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x88(%rsp), %rcx
movq %r8, %r13
movq 0x90(%rsp), %r8
movq 0x68(%rsp), %r9
leaq 0x8(%rsp), %rax
pushq %rax
leaq 0x40(%rsp), %rax
pushq %rax
leaq 0x20(%rsp), %rax
pushq %rax
leaq 0x30(%rsp), %rax
pushq %rax
pushq 0xa0(%rsp)
pushq 0x48(%rsp)
pushq 0x60(%rsp)
pushq 0x128(%rsp)
callq 0x2d922
movq 0xd8(%rsp), %rsi
movq 0x90(%rsp), %r11
movq 0x98(%rsp), %r10
movq 0x68(%rsp), %r9
movq %r13, %r8
movq 0x148(%rsp), %rdi
addq $0x40, %rsp
testq %rax, %rax
je 0x2e40d
incq %r8
movb $0x1, %r13b
jmp 0x2e41c
xorl %r13d, %r13d
testl %eax, %eax
je 0x2e5ad
movq %r15, %rdx
subq %rcx, %rdx
movq %rdx, 0x18(%rsp)
movq %r15, 0x10(%rsp)
movq %r12, %rdx
subq %rcx, %rdx
movq %rdx, 0x38(%rsp)
movq %r12, 0x8(%rsp)
cmpl 0x118(%rsp), %eax
jbe 0x2e501
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x88(%rsp), %rcx
movq %r8, %r14
movq 0x90(%rsp), %r8
movq 0x68(%rsp), %r9
leaq 0x8(%rsp), %rax
pushq %rax
leaq 0x40(%rsp), %rax
pushq %rax
leaq 0x20(%rsp), %rax
pushq %rax
leaq 0x30(%rsp), %rax
pushq %rax
pushq 0xa0(%rsp)
pushq 0x48(%rsp)
pushq 0x60(%rsp)
pushq 0x128(%rsp)
callq 0x2d922
movq 0x90(%rsp), %r11
movq 0x98(%rsp), %r10
movq 0x68(%rsp), %r9
movq %r14, %r8
movq 0x148(%rsp), %rdi
addq $0x40, %rsp
testq %rax, %rax
je 0x2e501
incq %r8
movb $0x1, %sil
jmp 0x2e513
testq %r8, %r8
jne 0x2e4c4
xorl %r8d, %r8d
xorl %r13d, %r13d
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
cmpq 0x10(%rdi), %rcx
jne 0x2e47b
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%rdi)
shlq $0x4, %rsi
movq %rax, %rdi
movq %r13, 0xb0(%rsp)
movq %r8, %r13
callq 0x2370
movq 0x50(%rsp), %r11
movq 0x58(%rsp), %r10
movq 0x28(%rsp), %r9
movq %r13, %r8
movq 0xb0(%rsp), %r13
movq 0x108(%rsp), %rdi
movq %rax, (%rdi)
movq 0x8(%rdi), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rdi)
shlq $0x4, %rcx
movzbl %r13b, %edx
movl %edx, %esi
shll $0x1f, %esi
orl %edx, %esi
movl %esi, (%rax,%rcx)
movl 0x10(%rsp), %edx
movl %edx, %esi
subl 0x18(%rsp), %esi
movl %esi, 0xc(%rax,%rcx)
movl %edx, 0x8(%rax,%rcx)
movl 0x8(%rsp), %edx
movl %edx, 0x4(%rax,%rcx)
cmpl %esi, 0x118(%rsp)
adcq $0x0, 0x48(%rsp)
movq 0x98(%rsp), %rsi
shrl $0xe, %r14d
xorl %r13d, %r13d
cmpw $0x1, %r14w
movzwl %bx, %eax
movl $0x0, %ecx
cmoveq %rax, %rcx
addq %rcx, %r12
cmpw $0x2, %r14w
movl $0x0, %edx
cmoveq %rax, %rdx
addq %rdx, %r12
cmpw $0x3, %r14w
cmoveq %rax, %rcx
addq %rcx, %r15
jmp 0x2e5bb
xorl %esi, %esi
testq %r8, %r8
je 0x2e510
xorl %r13d, %r13d
jmp 0x2e5ad
xorl %r8d, %r8d
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
cmpq 0x10(%rdi), %rcx
jne 0x2e56c
movq %rsi, 0x60(%rsp)
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%rdi)
shlq $0x4, %rsi
movq %rax, %rdi
movq %r8, %r14
callq 0x2370
movq 0x60(%rsp), %rsi
movq 0x50(%rsp), %r11
movq 0x58(%rsp), %r10
movq 0x28(%rsp), %r9
movq %r14, %r8
movq 0x108(%rsp), %rdi
movq %rax, (%rdi)
movq 0x8(%rdi), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rdi)
shlq $0x4, %rcx
movzbl %sil, %edx
movl %edx, %esi
shll $0x1f, %esi
orl %edx, %esi
movl %esi, (%rax,%rcx)
movl 0x10(%rsp), %edx
movl %edx, %esi
subl 0x18(%rsp), %esi
movl %esi, 0xc(%rax,%rcx)
movl %edx, 0x8(%rax,%rcx)
movl 0x8(%rsp), %edx
movl %edx, 0x4(%rax,%rcx)
cmpl %esi, 0x118(%rsp)
adcq $0x0, 0x48(%rsp)
addq %rbx, %r15
addq %rbx, %r12
movq %r15, %rsi
movq %r12, 0x60(%rsp)
incq %rbp
movl %r13d, %eax
jmp 0x2e223
movq 0xa8(%rsp), %rdx
incq %rdx
jmp 0x2e1e7
testl %eax, %eax
je 0x2e69a
movl %eax, %ecx
movq %r15, %rdx
subq %rcx, %rdx
movq %rdx, 0x18(%rsp)
movq %r15, 0x10(%rsp)
movq %r12, %rdx
subq %rcx, %rdx
movq %rdx, 0x38(%rsp)
movq %r12, 0x8(%rsp)
cmpl 0x118(%rsp), %eax
jbe 0x2e685
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x88(%rsp), %rcx
movq %r8, %rbx
movq 0x90(%rsp), %r8
movq 0x68(%rsp), %r9
leaq 0x8(%rsp), %rax
pushq %rax
leaq 0x40(%rsp), %rax
pushq %rax
leaq 0x20(%rsp), %rax
pushq %rax
leaq 0x30(%rsp), %rax
pushq %rax
pushq 0xa0(%rsp)
pushq 0x48(%rsp)
pushq 0x60(%rsp)
pushq 0x128(%rsp)
callq 0x2d922
movq %rbx, %r8
movq 0x148(%rsp), %rdi
addq $0x40, %rsp
testq %rax, %rax
je 0x2e685
incq %r8
movb $0x1, %bl
movl 0x120(%rsp), %ebp
jmp 0x2e6b0
testq %r8, %r8
movl 0x120(%rsp), %ebp
je 0x2e6ab
movq 0x8(%rdi), %rsi
jmp 0x2e73c
movl 0x120(%rsp), %ebp
movq 0x48(%rsp), %r15
jmp 0x2e733
xorl %r8d, %r8d
xorl %ebx, %ebx
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
cmpq 0x10(%rdi), %rcx
movq 0x48(%rsp), %r15
jne 0x2e6f5
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%rdi)
shlq $0x4, %rsi
movq %rax, %rdi
movq %r8, %r14
callq 0x2370
movq %r14, %r8
movq 0x108(%rsp), %rdi
movq %rax, (%rdi)
movq 0x8(%rdi), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rdi)
shlq $0x4, %rcx
movzbl %bl, %edx
movl %edx, %esi
shll $0x1f, %esi
orl %edx, %esi
movl %esi, (%rax,%rcx)
movl 0x10(%rsp), %edx
movl %edx, %esi
subl 0x18(%rsp), %esi
movl %esi, 0xc(%rax,%rcx)
movl %edx, 0x8(%rax,%rcx)
movl 0x8(%rsp), %edx
movl %edx, 0x4(%rax,%rcx)
cmpl %esi, 0x118(%rsp)
adcq $0x0, %r15
movq 0x8(%rdi), %rsi
testq %r8, %r8
je 0x2e7a8
cmpq %rsi, %r8
jae 0x2e81e
pushq $0x1
popq %r8
xorl %r10d, %r10d
testq %rsi, %rsi
cmovleq %r10, %rsi
xorl %r11d, %r11d
xorl %r9d, %r9d
subq $0x1, %rsi
jb 0x2e824
movq (%rdi), %rax
testl $0x7fffffff, (%rax,%r10) # imm = 0x7FFFFFFF
je 0x2e7a2
leaq (%rax,%r10), %rcx
movq %r11, %rdx
shlq $0x4, %rdx
movups (%rcx), %xmm0
movups %xmm0, (%rax,%rdx)
movq (%rdi), %rax
movl 0xc(%rax,%rdx), %ecx
movq %r8, %rax
cmpl %ebp, %ecx
jbe 0x2e79c
movl %ecx, %eax
xorl %edx, %edx
divl %ebp
cmpl $0x1, %edx
sbbl $-0x1, %eax
addq %rax, %r9
incq %r11
addq $0x10, %r10
jmp 0x2e759
testq %r15, %r15
setne %al
cmpq %rsi, %r15
setb %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x2e81e
xorl %r8d, %r8d
testq %rsi, %rsi
cmovleq %r8, %rsi
pushq $0x1
popq %r10
xorl %r11d, %r11d
xorl %r9d, %r9d
subq $0x1, %rsi
jb 0x2e824
movq (%rdi), %rax
movl 0x118(%rsp), %ecx
cmpl %ecx, 0xc(%rax,%r8)
jbe 0x2e818
leaq (%rax,%r8), %rcx
movq %r11, %rdx
shlq $0x4, %rdx
movups (%rcx), %xmm0
movups %xmm0, (%rax,%rdx)
movq (%rdi), %rax
movl 0xc(%rax,%rdx), %ecx
movq %r10, %rax
cmpl %ebp, %ecx
jbe 0x2e812
movl %ecx, %eax
xorl %edx, %edx
divl %ebp
cmpl $0x1, %edx
sbbl $-0x1, %eax
addq %rax, %r9
incq %r11
addq $0x10, %r8
jmp 0x2e7cf
pushq $-0x1
popq %r9
jmp 0x2e828
movq %r11, 0x8(%rdi)
movl %ebp, %r8d
pushq $0x19
popq %rsi
movl $0x1388, %edx           # imm = 0x1388
movl $0x1388, %ecx           # imm = 0x1388
callq 0x2dcf0
pushq $0x1
popq %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq