// File: /workspace/github_cpp_makefile_star2_O1/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 %r8, %rax
orq %rdx, %rax
je 0x1884fd
movq %r8, %r13
movq %rdx, %rbp
movq %rdi, %r15
movq %rsi, 0x8(%rsp)
movq %rcx, 0x18(%rsp)
testq %r8, %r8
setne %al
testq %rdx, %rdx
sete %cl
orb %al, %cl
jne 0x1884ad
xorl %r14d, %r14d
leaq 0x1021bb(%rip), %rbx    # 0x28a630
movq 0x8(%rsp), %r12
movsbq (%r12,%r14), %rax
movl %eax, %eax
movzbl (%rbx,%rax), %edx
movq %r15, %rdi
movl $0x3, %esi
movl $0xffff, %ecx           # imm = 0xFFFF
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x18d9ca
incq %r14
cmpq %r14, %rbp
jne 0x18847a
jmp 0x1884fd
testq %rbp, %rbp
setne %al
testq %r13, %r13
sete %cl
orb %al, %cl
jne 0x18850c
xorl %r14d, %r14d
leaq 0x102169(%rip), %rbx    # 0x28a630
movq 0x18(%rsp), %r12
movsbq (%r12,%r14), %rax
movl %eax, %eax
movzbl (%rbx,%rax), %ecx
movq %r15, %rdi
movl $0x2, %esi
movl $0xffff, %edx           # imm = 0xFFFF
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x18d9ca
incq %r14
cmpq %r14, %r13
jne 0x1884cc
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %rax
xorq $0x1, %rax
movq %r13, %rcx
xorq $0x1, %rcx
orq %rax, %rcx
movq 0x18(%rsp), %rdi
jne 0x18854d
movq 0x8(%rsp), %rax
movsbq (%rax), %rcx
movsbq (%rdi), %rax
cmpb %al, %cl
jne 0x1885d0
movq %r15, %rdi
xorl %esi, %esi
movl $0xffff, %edx           # imm = 0xFFFF
movl $0xffff, %ecx           # imm = 0xFFFF
jmp 0x1885eb
movq %r15, 0x20(%rsp)
movq 0x88(%rsp), %r14
movq 0x80(%rsp), %rax
movq %rax, 0x40(%rsp)
movq %rbp, %rax
subq %r13, %rax
negq %rax
movq %rbp, %r12
subq %r13, %r12
movq %r13, %r15
cmovaq %rbp, %r15
cmovbeq %rax, %r12
cmpq $0x1e, %r12
movq %r9, 0x10(%rsp)
movsd %xmm0, 0x38(%rsp)
ja 0x18860a
cmpq $0x1f, %r15
movl $0x1f, %ebx
cmovbq %r15, %rbx
movl $0x7fffffff, 0x2c(%r9)  # imm = 0x7FFFFFFF
movl %r13d, %esi
movq 0x8(%rsp), %rdx
movl %ebp, %ecx
movl %ebx, %r8d
movq 0x10(%rsp), %r9
callq 0x6424a
movq 0x10(%rsp), %r9
movl 0x2c(%r9), %eax
cmpl 0x28(%r9), %eax
setg %al
jmp 0x18860e
movl %ecx, %ecx
leaq 0x102057(%rip), %rsi    # 0x28a630
movzbl (%rsi,%rcx), %edx
movl %eax, %eax
movzbl (%rsi,%rax), %ecx
movq %r15, %rdi
movl $0x1, %esi
movl $0x1, %r8d
movl $0x1, %r9d
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x18d9ca
movb $0x1, %al
xorl %ebx, %ebx
testb %al, %al
je 0x188668
cmpq $0x3f, %r12
setae %cl
cmpq %rbx, %r15
setbe %dl
movb $0x1, %al
orb %cl, %dl
jne 0x18866a
cmpq $0x3f, %r15
movl $0x3f, %ebx
cmovbq %r15, %rbx
movl $0x7fffffff, 0x2c(%r9)  # imm = 0x7FFFFFFF
movq 0x18(%rsp), %rdi
movl %r13d, %esi
movq 0x8(%rsp), %rdx
movl %ebp, %ecx
movl %ebx, %r8d
movq 0x10(%rsp), %r9
callq 0x6424a
movq 0x10(%rsp), %r9
movl 0x2c(%r9), %eax
cmpl 0x28(%r9), %eax
setg %al
jmp 0x18866a
xorl %eax, %eax
testb %al, %al
je 0x1887c9
cmpq 0x40(%rsp), %r15
setae %al
cmpq %r14, %r12
setae %cl
orb %al, %cl
jne 0x188719
movq %r15, %xmm0
punpckldq 0x9cbab(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x9cbb3(%rip), %xmm0    # 0x225250
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x38(%rsp), %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rcx
subsd 0x9cba9(%rip), %xmm1    # 0x225268
cvttsd2si %xmm1, %rdx
sarq $0x3f, %rcx
andq %rcx, %rdx
orq %rax, %rdx
cmpq $0x1, %rdx
movq %rdx, %r8
adcq $0x0, %r8
cmpq %r14, %rdx
cmovaq %r14, %r8
cmpq %rbx, %r8
jbe 0x188719
movl $0x7fffffff, 0x2c(%r9)  # imm = 0x7FFFFFFF
movq 0x18(%rsp), %rdi
movl %r13d, %esi
movq 0x8(%rsp), %rdx
movl %ebp, %ecx
movq 0x10(%rsp), %r9
callq 0x6424a
movq 0x10(%rsp), %r9
movl 0x2c(%r9), %eax
cmpl 0x28(%r9), %eax
jle 0x1887c9
testq %rbp, %rbp
movq 0x20(%rsp), %r15
movq 0x8(%rsp), %r12
je 0x18876d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %rbp
je 0x18876d
xorl %ebx, %ebx
leaq 0x101ef5(%rip), %r14    # 0x28a630
movsbq (%r12,%rbx), %rax
movl %eax, %eax
movzbl (%r14,%rax), %edx
movq %r15, %rdi
movl $0x3, %esi
movl $0xffff, %ecx           # imm = 0xFFFF
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x18d9ca
incq %rbx
cmpq %rbx, %rbp
jne 0x18873b
testq %r13, %r13
movq 0x18(%rsp), %r12
je 0x1884fd
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %r13
je 0x1884fd
xorl %ebx, %ebx
leaq 0x101e9e(%rip), %r14    # 0x28a630
movsbq (%r12,%rbx), %rax
movl %eax, %eax
movzbl (%r14,%rax), %ecx
movq %r15, %rdi
movl $0x2, %esi
movl $0xffff, %edx           # imm = 0xFFFF
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x18d9ca
incq %rbx
cmpq %rbx, %r13
jne 0x188792
jmp 0x1884fd
movq 0xa8(%r9), %rax
testq %rax, %rax
movq 0x20(%rsp), %r12
je 0x1884fd
leaq 0x101e4b(%rip), %r10    # 0x28a630
xorl %edi, %edi
movq $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq 0xb8(%r9), %rsi
movzwl (%rsi,%rdi,2), %edx
movl %edx, %ecx
shrl $0xe, %ecx
andl $0x3fff, %edx           # imm = 0x3FFF
leal 0x1(%rdi), %r14d
cmpq %r14, %rax
jbe 0x188836
movzwl (%rsi,%r14,2), %edi
movl %edi, %r8d
shrl $0xe, %r8d
cmpl %ecx, %r8d
jne 0x188836
andl $0x3fff, %edi           # imm = 0x3FFF
addl %edi, %edx
incl %r14d
jmp 0x188813
cmpw $0x2, %cx
movl %edx, %r13d
movq %r13, %rdx
movl $0x0, %eax
cmoveq %rax, %rdx
movq %rdx, 0x40(%rsp)
cmpw $0x3, %cx
movq %r13, %rdx
cmoveq %rax, %rdx
movq %rdx, 0x38(%rsp)
movzwl %cx, %ebp
leaq 0xa94d8(%rip), %rcx     # 0x231d40
movslq (%rcx,%rbp,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r12, %rdi
movl %ebp, %esi
movl $0xffff, %edx           # imm = 0xFFFF
movl $0xffff, %ecx           # imm = 0xFFFF
movl %r13d, %r8d
movl $0x1, %r9d
callq 0x18d9ca
leaq 0x101d9b(%rip), %r10    # 0x28a630
jmp 0x1889aa
testq %r13, %r13
je 0x1889aa
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
leaq (%rax,%rcx), %rbx
xorl %r15d, %r15d
movsbq (%rbx,%r15), %rax
movl %eax, %eax
movzbl (%r10,%rax), %ecx
movq %r12, %rdi
movl %ebp, %esi
movl $0xffff, %edx           # imm = 0xFFFF
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x18d9ca
leaq 0x101d4e(%rip), %r10    # 0x28a630
incq %r15
cmpq %r15, %r13
jne 0x1888b4
jmp 0x1889aa
testq %r13, %r13
je 0x1889aa
movq 0x8(%rsp), %rax
movq 0x30(%rsp), %rcx
leaq (%rax,%rcx), %rbx
xorl %r15d, %r15d
movsbq (%rbx,%r15), %rax
movl %eax, %eax
movzbl (%r10,%rax), %edx
movq %r12, %rdi
movl %ebp, %esi
movl $0xffff, %ecx           # imm = 0xFFFF
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x18d9ca
leaq 0x101cf9(%rip), %r10    # 0x28a630
incq %r15
cmpq %r15, %r13
jne 0x188909
jmp 0x1889aa
testq %r13, %r13
je 0x1889aa
movq 0x8(%rsp), %rax
movq 0x30(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
leaq (%rax,%rcx), %r15
xorl %ebx, %ebx
movq 0x20(%rsp), %rax
movsbq (%rax,%rbx), %rax
movl %eax, %eax
movzbl (%r10,%rax), %edx
movsbq (%r15,%rbx), %rax
movl %eax, %eax
movzbl (%r10,%rax), %ecx
movq %r12, %rdi
movl %ebp, %esi
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x18d9ca
leaq 0x101c8e(%rip), %r10    # 0x28a630
incq %rbx
cmpq %rbx, %r13
jne 0x188968
movl %r14d, %edi
movq 0x40(%rsp), %rax
addq %rax, 0x30(%rsp)
movq 0x38(%rsp), %rax
addq %rax, 0x28(%rsp)
movq 0x10(%rsp), %r9
movq 0xa8(%r9), %rax
cmpq %rdi, %rax
ja 0x1887f9
jmp 0x1884fd