// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/ecovlp.cpp
// Function: gen_cc_fly(asg16_v*, char*, unsigned long, char*, unsigned long, bit_extz_t*, double, unsigned long, unsigned long)
void gen_cc_fly(asg16_v *sc, char *qstr, uint64_t ql, char *tstr, uint64_t tl, bit_extz_t *exz, double e_rate, uint64_t maxn, uint64_t maxe)
{
    // fprintf(stderr, "[M::%s] ql::%lu, tl::%lu\n", __func__, ql, tl);
    if(ql == 0 && tl == 0) return;
    uint64_t k, ck, qk, tk, wq[2], wt[2], maxl, minl, diff, f, diff0 = 0;
    if(ql > 0 && tl == 0) {
        for (k = 0; k < ql; k++) {
            push_trace_bp_f(sc, 3, seq_nt6_table[(uint32_t)(qstr[k])], (uint16_t)-1, 1, 1); 
        }
        return;
    }
    if(ql == 0 && tl > 0) {
        for (k = 0; k < tl; k++) {
            push_trace_bp_f(sc, 2, (uint16_t)-1, seq_nt6_table[(uint32_t)(tstr[k])], 1, 1); 
        }
        return;
    }
    if(ql == tl && ql == 1) {
        if(qstr[0] == tstr[0]) push_trace_bp_f(sc, 0, (uint16_t)-1, (uint16_t)-1, 1, 1); 
        else push_trace_bp_f(sc, 1, seq_nt6_table[(uint32_t)(qstr[0])], seq_nt6_table[(uint32_t)(tstr[0])], 1, 1); 
        return;
    }



    if(ql >= tl) {
        maxl = ql; minl = tl;
    } else {
        maxl = tl; minl = ql;
    }
    f = 0;
            
    diff = 31;
    if(diff > (maxl - minl)) {
        if(diff > maxl) diff = maxl; 
        diff0 = diff; clear_align(*exz);
        cal_exz_global(tstr, tl, qstr, ql, diff, exz);
        if(is_align(*exz)) f = 1; 
    }

    if(!f) {
        diff = 63;
        if(diff > (maxl - minl)) {
            if(diff > maxl) diff = maxl; 
            if(diff > diff0) {
                diff0 = diff; clear_align(*exz);
                cal_exz_global(tstr, tl, qstr, ql, diff, exz);
                if(is_align(*exz)) f = 1; 
            }
        }
    }

    if(!f) {
        if((maxn > maxl) && (maxe > (maxl - minl))) {
            diff = maxl * e_rate;
            if(diff < 1) diff = 1;
            if(diff > maxe) diff = maxe;
            if(diff > diff0) {
                diff0 = diff; clear_align(*exz);
                cal_exz_global(tstr, tl, qstr, ql, diff, exz);
                if(is_align(*exz)) f = 1; 
            }
        }
    }

    // fprintf(stderr, "[M::%s] f::%lu, err::%d\n", __func__, f, exz->err);

    uint32_t on; uint16_t op;
    if(f) {
        
        for (ck = qk = tk = 0; ck < exz->cigar.n;) {
            wq[0] = qk; wt[0] = tk;
            ck = pop_trace(&(exz->cigar), ck, &op, &on);
            if(op!=2) qk += on;
            if(op!=3) tk += on; 
            wq[1] = qk; wt[1] = tk;

            if(op == 0) {
                push_trace_bp_f(sc, op, (uint16_t)-1, (uint16_t)-1, on, 1); 
            } else if(op == 1) {
                for (k = 0; k < on; k++) {
                    push_trace_bp_f(sc, op, seq_nt6_table[(uint32_t)(qstr[wq[0]+k])], seq_nt6_table[(uint32_t)(tstr[wt[0]+k])], 1, 1); 
                }
            } else if(op == 2) {
                for (k = 0; k < on; k++) {
                    push_trace_bp_f(sc, op, (uint16_t)-1, seq_nt6_table[(uint32_t)(tstr[wt[0]+k])], 1, 1); 
                }
            } else if(op == 3) {
                for (k = 0; k < on; k++) {
                    push_trace_bp_f(sc, op, seq_nt6_table[(uint32_t)(qstr[wq[0]+k])], (uint16_t)-1, 1, 1); 
                }
            }
        }
    } else {
        if(ql > 0) {
            op = 3; on = ql;
            for (k = 0; k < on; k++) {
                push_trace_bp_f(sc, op, seq_nt6_table[(uint32_t)(qstr[k])], (uint16_t)-1, 1, 1); 
            }
        }

        if(tl > 0) {
            op = 2; on = tl;
            for (k = 0; k < on; k++) {
                push_trace_bp_f(sc, op, (uint16_t)-1, seq_nt6_table[(uint32_t)(tstr[k])], 1, 1); 
            }
        }
        
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, 0x18(%rsp)
movq %rsi, 0x20(%rsp)
movq %r8, %rax
orq %rdx, %rax
je 0x14ae1a
movq %r8, %r13
movq %rdx, %rbp
movq %rdi, %rbx
testq %r8, %r8
setne %al
testq %rdx, %rdx
sete %cl
orb %al, %cl
jne 0x14a964
xorl %r15d, %r15d
leaq 0x108d0a(%rip), %r13    # 0x253630
pushq $0x3
popq %r14
pushq $0x1
popq %r12
cmpq %r15, %rbp
je 0x14ae1a
movq 0x20(%rsp), %rax
movsbq (%rax,%r15), %rax
movl %eax, %eax
movzbl (%r13,%rax), %edx
movq %rbx, %rdi
movl %r14d, %esi
movl $0xffff, %ecx           # imm = 0xFFFF
movl %r12d, %r8d
movl %r12d, %r9d
callq 0x14f542
incq %r15
jmp 0x14a92e
testq %rbp, %rbp
setne %al
testq %r13, %r13
sete %cl
orb %al, %cl
jne 0x14a9b9
xorl %r14d, %r14d
leaq 0x108cb2(%rip), %r12    # 0x253630
pushq $0x2
popq %rbp
pushq $0x1
popq %r15
cmpq %r14, %r13
je 0x14ae1a
movq 0x18(%rsp), %rax
movsbq (%rax,%r14), %rax
movl %eax, %eax
movzbl (%r12,%rax), %ecx
movq %rbx, %rdi
movl %ebp, %esi
movl $0xffff, %edx           # imm = 0xFFFF
movl %r15d, %r8d
movl %r15d, %r9d
callq 0x14f542
incq %r14
jmp 0x14a985
movq %rbp, %rax
xorq $0x1, %rax
movq %r13, %rcx
xorq $0x1, %rcx
orq %rax, %rcx
jne 0x14aa01
movq 0x20(%rsp), %rax
movsbq (%rax), %rcx
movq 0x18(%rsp), %rax
movsbq (%rax), %rax
cmpb %al, %cl
jne 0x14aaa0
pushq $0x1
popq %r8
movq %rbx, %rdi
xorl %esi, %esi
movl $0xffff, %edx           # imm = 0xFFFF
movl $0xffff, %ecx           # imm = 0xFFFF
movl %r8d, %r9d
jmp 0x14aabf
movq %r9, 0x28(%rsp)
movq 0x88(%rsp), %rsi
movq 0x80(%rsp), %rcx
movq %rbp, %rax
subq %r13, %rax
negq %rax
movq %rbp, %r12
subq %r13, %r12
movq %r13, %rdx
cmovaq %rbp, %rdx
cmovbeq %rax, %r12
cmpq $0x1e, %r12
movsd %xmm0, 0x40(%rsp)
ja 0x14aad2
cmpq $0x1f, %rdx
pushq $0x1f
popq %r15
cmovbq %rdx, %r15
movq 0x28(%rsp), %r14
movl $0x7fffffff, 0x2c(%r14) # imm = 0x7FFFFFFF
movq 0x18(%rsp), %rdi
movq %rsi, 0x38(%rsp)
movl %r13d, %esi
movq %rdx, 0x30(%rsp)
movq 0x20(%rsp), %rdx
movq %rcx, 0x10(%rsp)
movl %ebp, %ecx
movl %r15d, %r8d
movq %r14, %r9
callq 0x335d2
movq 0x10(%rsp), %rcx
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rsi
movl 0x2c(%r14), %eax
cmpl 0x28(%r14), %eax
jg 0x14aadb
jmp 0x14ac7c
movl %ecx, %ecx
leaq 0x108b87(%rip), %rsi    # 0x253630
movzbl (%rsi,%rcx), %edx
movl %eax, %eax
movzbl (%rsi,%rax), %ecx
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl %esi, %r8d
movl %esi, %r9d
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x14f542
xorl %r15d, %r15d
cmpq $0x3e, %r12
ja 0x14ab3f
cmpq %r15, %rdx
jbe 0x14ab3f
cmpq $0x3f, %rdx
pushq $0x3f
popq %r15
cmovbq %rdx, %r15
movq 0x28(%rsp), %r14
movl $0x7fffffff, 0x2c(%r14) # imm = 0x7FFFFFFF
movq 0x18(%rsp), %rdi
movq %rsi, 0x38(%rsp)
movl %r13d, %esi
movq %rdx, 0x30(%rsp)
movq 0x20(%rsp), %rdx
movq %rcx, 0x10(%rsp)
movl %ebp, %ecx
movl %r15d, %r8d
movq %r14, %r9
callq 0x335d2
movq 0x10(%rsp), %rcx
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rsi
movl 0x2c(%r14), %eax
cmpl 0x28(%r14), %eax
jle 0x14ac7c
cmpq %rcx, %rdx
setae %al
cmpq %rsi, %r12
setae %cl
orb %al, %cl
jne 0x14abe2
movq %rdx, %xmm0
punpckldq 0x98710(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x98718(%rip), %xmm0    # 0x1e3280
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x40(%rsp), %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rcx
subsd 0x9870e(%rip), %xmm1    # 0x1e3298
cvttsd2si %xmm1, %rdx
sarq $0x3f, %rcx
andq %rcx, %rdx
orq %rax, %rdx
cmpq $0x1, %rdx
movq %rdx, %r8
adcq $0x0, %r8
cmpq %rsi, %rdx
cmovaq %rsi, %r8
cmpq %r15, %r8
jbe 0x14abe2
movq 0x28(%rsp), %r15
movl $0x7fffffff, 0x2c(%r15) # imm = 0x7FFFFFFF
movq 0x18(%rsp), %rdi
movl %r13d, %esi
movq 0x20(%rsp), %rdx
movl %ebp, %ecx
movq %r15, %r9
callq 0x335d2
movl 0x2c(%r15), %eax
cmpl 0x28(%r15), %eax
jle 0x14ac81
testq %rbp, %rbp
je 0x14ac2a
movl %ebp, %r14d
xorl %r15d, %r15d
pushq $0x3
popq %rbp
pushq $0x1
popq %r12
cmpq %r15, %r14
je 0x14ac2a
movq 0x20(%rsp), %rax
movsbq (%rax,%r15), %rax
movl %eax, %eax
leaq 0x108a24(%rip), %rcx    # 0x253630
movzbl (%rcx,%rax), %edx
movq %rbx, %rdi
movl %ebp, %esi
movl $0xffff, %ecx           # imm = 0xFFFF
movl %r12d, %r8d
movl %r12d, %r9d
callq 0x14f542
incq %r15
jmp 0x14abf4
testq %r13, %r13
je 0x14ae1a
movl %r13d, %r14d
xorl %r12d, %r12d
leaq 0x1089f0(%rip), %r13    # 0x253630
pushq $0x2
popq %rbp
pushq $0x1
popq %r15
cmpq %r12, %r14
je 0x14ae1a
movq 0x18(%rsp), %rax
movsbq (%rax,%r12), %rax
movl %eax, %eax
movzbl (%r13,%rax), %ecx
movq %rbx, %rdi
movl %ebp, %esi
movl $0xffff, %edx           # imm = 0xFFFF
movl %r15d, %r8d
movl %r15d, %r9d
callq 0x14f542
incq %r12
jmp 0x14ac47
movq 0x28(%rsp), %r15
addq $0xa8, %r15
pushq $0x1
popq %r13
leaq 0x10899d(%rip), %r12    # 0x253630
xorl %eax, %eax
movq $0x0, 0x30(%rsp)
movl $0x0, 0x38(%rsp)
movq %r15, 0x28(%rsp)
movq 0x30(%rsp), %r14
movq %rax, %rbp
movl 0x38(%rsp), %esi
movl %esi, %eax
cmpq %rax, (%r15)
jbe 0x14ae1a
movq %r15, %rdi
leaq 0xa(%rsp), %rdx
leaq 0xc(%rsp), %rcx
callq 0x53a7d
movzwl 0xa(%rsp), %ecx
cmpq $0x2, %rcx
movl 0xc(%rsp), %r8d
movq %r8, %rsi
movl $0x0, %edx
cmoveq %rdx, %rsi
movl %eax, 0x38(%rsp)
addq %r14, %rsi
movq %rsi, 0x30(%rsp)
cmpq $0x3, %rcx
movq %r8, %rax
cmoveq %rdx, %rax
addq %rbp, %rax
cmpq $0x3, %rcx
ja 0x14acab
movq %rax, 0x10(%rsp)
leaq 0xa5136(%rip), %rdx     # 0x1efe50
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq %rbx, %rdi
xorl %esi, %esi
movl $0xffff, %edx           # imm = 0xFFFF
movl $0xffff, %ecx           # imm = 0xFFFF
movl %r13d, %r9d
callq 0x14f542
jmp 0x14ae10
addq 0x18(%rsp), %rbp
xorl %r14d, %r14d
movl %r8d, %eax
cmpq %rax, %r14
jae 0x14ae10
movzwl 0xa(%rsp), %esi
movsbq (%rbp,%r14), %rax
movl %eax, %eax
movzbl (%r12,%rax), %ecx
movq %rbx, %rdi
movl $0xffff, %edx           # imm = 0xFFFF
movl %r13d, %r8d
movl %r13d, %r9d
callq 0x14f542
incq %r14
movl 0xc(%rsp), %r8d
jmp 0x14ad47
addq 0x20(%rsp), %r14
xorl %r15d, %r15d
movl %r8d, %eax
cmpq %rax, %r15
jae 0x14ae0b
movzwl 0xa(%rsp), %esi
movsbq (%r14,%r15), %rax
movl %eax, %eax
movzbl (%r12,%rax), %edx
movq %rbx, %rdi
movl $0xffff, %ecx           # imm = 0xFFFF
movl %r13d, %r8d
movl %r13d, %r9d
callq 0x14f542
incq %r15
movl 0xc(%rsp), %r8d
jmp 0x14ad8a
addq 0x20(%rsp), %r14
addq 0x18(%rsp), %rbp
xorl %r15d, %r15d
movl %r8d, %eax
cmpq %rax, %r15
jae 0x14ae0b
movzwl 0xa(%rsp), %esi
movsbq (%r14,%r15), %rax
movl %eax, %eax
movzbl (%r12,%rax), %edx
movsbq (%rbp,%r15), %rax
movl %eax, %eax
movzbl (%r12,%rax), %ecx
movq %rbx, %rdi
movl %r13d, %r8d
movl %r13d, %r9d
callq 0x14f542
incq %r15
movl 0xc(%rsp), %r8d
jmp 0x14adcd
movq 0x28(%rsp), %r15
movq 0x10(%rsp), %rax
jmp 0x14acab
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq