// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movq %r8, %rax
orq %rdx, %rax
je 0x1900a3
movq %r8, %r13
movq %rdx, %rbp
movq %rdi, %rbx
movq %rsi, 0x20(%rsp)
testq %r8, %r8
setne %al
testq %rdx, %rdx
sete %dl
orb %al, %dl
jne 0x19004d
xorl %r14d, %r14d
leaq 0x10561c(%rip), %r15    # 0x295630
movq 0x20(%rsp), %r12
movsbq (%r12,%r14), %rax
movl %eax, %eax
movzbl (%r15,%rax), %edx
movq %rbx, %rdi
movl $0x3, %esi
movl $0xffff, %ecx           # imm = 0xFFFF
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x1967e1
incq %r14
cmpq %r14, %rbp
jne 0x190019
jmp 0x1900a3
testq %rbp, %rbp
setne %al
testq %r13, %r13
sete %dl
orb %al, %dl
movq %rcx, 0x8(%rsp)
jne 0x1900b2
xorl %r14d, %r14d
leaq 0x1055c4(%rip), %r15    # 0x295630
movsbq (%rcx,%r14), %rax
movl %eax, %eax
movzbl (%r15,%rax), %ecx
movq %rbx, %rdi
movl $0x2, %esi
movl $0xffff, %edx           # imm = 0xFFFF
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x1967e1
movq 0x8(%rsp), %rcx
incq %r14
cmpq %r14, %r13
jne 0x19006c
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %rax
xorq $0x1, %rax
movq %r13, %rdx
xorq $0x1, %rdx
orq %rax, %rdx
jne 0x1900ee
movq 0x20(%rsp), %rax
movsbq (%rax), %rdx
movsbq (%rcx), %rax
cmpb %al, %dl
jne 0x19017a
movq %rbx, %rdi
xorl %esi, %esi
movl $0xffff, %edx           # imm = 0xFFFF
movl $0xffff, %ecx           # imm = 0xFFFF
jmp 0x190195
movsd %xmm0, 0x30(%rsp)
movq 0x78(%rsp), %rsi
movq 0x70(%rsp), %rdx
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, 0x28(%rsp)
ja 0x1901b4
cmpq $0x1f, %r15
movl $0x1f, %r14d
cmovbq %r15, %r14
movl $0x7fffffff, 0x2c(%r9)  # imm = 0x7FFFFFFF
movq %rcx, %rdi
movq %rsi, 0x18(%rsp)
movl %r13d, %esi
movq %rdx, 0x10(%rsp)
movq 0x20(%rsp), %rdx
movl %ebp, %ecx
movl %r14d, %r8d
callq 0x63d6a
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rsi
movq 0x28(%rsp), %r9
movl 0x2c(%r9), %eax
cmpl 0x28(%r9), %eax
jg 0x1901bd
jmp 0x190368
movl %edx, %ecx
leaq 0x1054ad(%rip), %rsi    # 0x295630
movzbl (%rsi,%rcx), %edx
movl %eax, %eax
movzbl (%rsi,%rax), %ecx
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %r8d
movl $0x1, %r9d
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1967e1
xorl %r14d, %r14d
cmpq $0x3e, %r12
ja 0x190216
cmpq %r14, %r15
jbe 0x190216
cmpq $0x3f, %r15
movl $0x3f, %r14d
cmovbq %r15, %r14
movl $0x7fffffff, 0x2c(%r9)  # imm = 0x7FFFFFFF
movq 0x8(%rsp), %rdi
movq %rsi, 0x18(%rsp)
movl %r13d, %esi
movq %rdx, 0x10(%rsp)
movq 0x20(%rsp), %rdx
movl %ebp, %ecx
movl %r14d, %r8d
callq 0x63d6a
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rsi
movq 0x28(%rsp), %r9
movl 0x2c(%r9), %eax
cmpl 0x28(%r9), %eax
jle 0x190368
cmpq %rdx, %r15
setae %al
cmpq %rsi, %r12
setae %cl
orb %al, %cl
jne 0x1902b6
movq %r15, %xmm0
punpckldq 0xa1049(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xa1051(%rip), %xmm0    # 0x231290
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x30(%rsp), %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rcx
subsd 0xa10a7(%rip), %xmm1    # 0x231308
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 %r14, %r8
jbe 0x1902b6
movl $0x7fffffff, 0x2c(%r9)  # imm = 0x7FFFFFFF
movq 0x8(%rsp), %rdi
movl %r13d, %esi
movq 0x20(%rsp), %rdx
movl %ebp, %ecx
callq 0x63d6a
movq 0x28(%rsp), %r9
movl 0x2c(%r9), %eax
cmpl 0x28(%r9), %eax
jle 0x190368
testq %rbp, %rbp
movq 0x20(%rsp), %r12
je 0x190306
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %rbp
je 0x190306
xorl %r14d, %r14d
leaq 0x10535c(%rip), %r15    # 0x295630
movsbq (%r12,%r14), %rax
movl %eax, %eax
movzbl (%r15,%rax), %edx
movq %rbx, %rdi
movl $0x3, %esi
movl $0xffff, %ecx           # imm = 0xFFFF
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x1967e1
incq %r14
cmpq %r14, %rbp
jne 0x1902d4
testq %r13, %r13
movq 0x8(%rsp), %rcx
je 0x1900a3
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %r13
je 0x1900a3
xorl %r14d, %r14d
leaq 0x105304(%rip), %r15    # 0x295630
movsbq (%rcx,%r14), %rax
movl %eax, %eax
movzbl (%r15,%rax), %ecx
movq %rbx, %rdi
movl $0x2, %esi
movl $0xffff, %edx           # imm = 0xFFFF
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x1967e1
movq 0x8(%rsp), %rcx
incq %r14
cmpq %r14, %r13
jne 0x19032c
jmp 0x1900a3
movq 0xa8(%r9), %rcx
testq %rcx, %rcx
movq 0x8(%rsp), %r10
je 0x1900a3
xorl %ebp, %ebp
leaq 0x1052aa(%rip), %r11    # 0x295630
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0xb8(%r9), %rsi
movzwl (%rsi,%r12,2), %edx
movl %edx, %eax
shrl $0xe, %eax
andl $0x3fff, %edx           # imm = 0x3FFF
incl %r12d
cmpq %r12, %rcx
jbe 0x1903cc
movzwl (%rsi,%r12,2), %edi
movl %edi, %r8d
shrl $0xe, %r8d
cmpl %eax, %r8d
jne 0x1903fe
andl $0x3fff, %edi           # imm = 0x3FFF
addl %edi, %edx
incl %r12d
jmp 0x1903a9
cmpw $0x2, %ax
movl %edx, %r13d
movq %r13, %rdx
cmoveq %rbp, %rdx
addq %r14, %rdx
cmpw $0x3, %ax
movq %r13, %rsi
cmoveq %rbp, %rsi
addq %r15, %rsi
movzwl %ax, %eax
leaq 0xadb9b(%rip), %rcx     # 0x23df90
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl %r12d, %r12d
cmpw $0x2, %ax
movl %edx, %r13d
movq %r13, %rdx
cmoveq %rbp, %rdx
addq %r14, %rdx
cmpw $0x3, %ax
movq %r13, %rsi
cmoveq %rbp, %rsi
addq %r15, %rsi
movzwl %ax, %eax
leaq 0xadb66(%rip), %rcx     # 0x23df90
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
movq %rsi, %r15
xorl %esi, %esi
movq %rdx, %r14
movl $0xffff, %edx           # imm = 0xFFFF
movl $0xffff, %ecx           # imm = 0xFFFF
movl %r13d, %r8d
movl $0x1, %r9d
callq 0x1967e1
movq %r15, %rsi
movq %r14, %rdx
leaq 0x1051cd(%rip), %r11    # 0x295630
movq 0x28(%rsp), %r9
movq 0x8(%rsp), %r10
jmp 0x190595
testq %r13, %r13
je 0x190595
movq %rsi, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
addq %r10, %r15
xorl %r14d, %r14d
movsbq (%r15,%r14), %rax
movl %eax, %eax
movzbl (%r11,%rax), %ecx
movq %rbx, %rdi
movl $0x2, %esi
movl $0xffff, %edx           # imm = 0xFFFF
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x1967e1
leaq 0x105174(%rip), %r11    # 0x295630
incq %r14
cmpq %r14, %r13
jne 0x19048b
jmp 0x19051a
testq %r13, %r13
je 0x190595
movq %rsi, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
addq 0x20(%rsp), %r14
xorl %r15d, %r15d
movsbq (%r14,%r15), %rax
movl %eax, %eax
movzbl (%r11,%rax), %edx
movq %rbx, %rdi
movl $0x3, %esi
movl $0xffff, %ecx           # imm = 0xFFFF
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x1967e1
leaq 0x10511e(%rip), %r11    # 0x295630
incq %r15
cmpq %r15, %r13
jne 0x1904e1
movq 0x8(%rsp), %r10
movq 0x28(%rsp), %r9
jmp 0x19058b
testq %r13, %r13
je 0x190595
movq %rsi, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
addq 0x20(%rsp), %r14
addq %r10, %r15
xorl %ebp, %ebp
movsbq (%r14,%rbp), %rax
movl %eax, %eax
movzbl (%r11,%rax), %edx
movsbq (%r15,%rbp), %rax
movl %eax, %eax
movzbl (%r11,%rax), %ecx
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x1967e1
leaq 0x1050b9(%rip), %r11    # 0x295630
incq %rbp
cmpq %rbp, %r13
jne 0x19053f
movq 0x8(%rsp), %r10
movq 0x28(%rsp), %r9
xorl %ebp, %ebp
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rsi
movq 0xa8(%r9), %rcx
movq %rdx, %r14
movq %rsi, %r15
cmpq %r12, %rcx
ja 0x19038f
jmp 0x1900a3