// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movsd %xmm0, -0x38(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x264853
cmpq $0x0, -0x28(%rbp)
jne 0x264853
jmp 0x265038
movq $0x0, -0xa8(%rbp)
cmpq $0x0, -0x18(%rbp)
jbe 0x2648cb
cmpq $0x0, -0x28(%rbp)
jne 0x2648cb
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x2648c6
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x15fdb7(%rip), %rax    # 0x3c4650
movzbl (%rax,%rcx), %eax
movl $0x3, %esi
movl $0xffff, %ecx           # imm = 0xFFFF
movl $0x1, %r9d
movzwl %ax, %edx
movl %r9d, %r8d
callq 0x26d790
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x264874
jmp 0x265038
cmpq $0x0, -0x18(%rbp)
jne 0x264938
cmpq $0x0, -0x28(%rbp)
jbe 0x264938
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x264933
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x15fd4a(%rip), %rax    # 0x3c4650
movzbl (%rax,%rcx), %eax
movl $0x2, %esi
movl $0xffff, %edx           # imm = 0xFFFF
movl $0x1, %r9d
movzwl %ax, %ecx
movl %r9d, %r8d
callq 0x26d790
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x2648e1
jmp 0x265038
movq -0x18(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0x2649cb
cmpq $0x1, -0x18(%rbp)
jne 0x2649cb
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
movq -0x20(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x26497c
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0xffff, %ecx           # imm = 0xFFFF
movl $0x1, %r9d
movl %ecx, %edx
movl %r9d, %r8d
callq 0x26d790
jmp 0x2649c6
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x15fcbe(%rip), %rax    # 0x3c4650
movzbl (%rax,%rcx), %eax
movw %ax, %cx
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
movl %eax, %eax
movl %eax, %edx
leaq 0x15fca5(%rip), %rax    # 0x3c4650
movzbl (%rax,%rdx), %eax
movl $0x1, %r9d
movl %r9d, %esi
movzwl %cx, %edx
movzwl %ax, %ecx
movl %r9d, %r8d
callq 0x26d790
jmp 0x265038
movq -0x18(%rbp), %rax
cmpq -0x28(%rbp), %rax
jb 0x2649ed
movq -0x18(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x264a03
movq -0x28(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x90(%rbp)
movq $0x0, -0xa0(%rbp)
movq $0x1f, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq -0x88(%rbp), %rcx
subq -0x90(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x264aae
movq -0x98(%rbp), %rax
cmpq -0x88(%rbp), %rax
jbe 0x264a51
movq -0x88(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x30(%rbp), %rax
movl $0x7fffffff, 0x2c(%rax) # imm = 0x7FFFFFFF
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %esi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rax
movl %eax, %ecx
movq -0x98(%rbp), %rax
movl %eax, %r8d
movq -0x30(%rbp), %r9
callq 0x5e760
movq -0x30(%rbp), %rax
movl 0x2c(%rax), %eax
movq -0x30(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jg 0x264aac
movq $0x1, -0xa0(%rbp)
jmp 0x264aae
cmpq $0x0, -0xa0(%rbp)
jne 0x264b74
movq $0x3f, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq -0x88(%rbp), %rcx
subq -0x90(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x264b72
movq -0x98(%rbp), %rax
cmpq -0x88(%rbp), %rax
jbe 0x264b03
movq -0x88(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq -0xa8(%rbp), %rax
jbe 0x264b70
movq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x30(%rbp), %rax
movl $0x7fffffff, 0x2c(%rax) # imm = 0x7FFFFFFF
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %esi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rax
movl %eax, %ecx
movq -0x98(%rbp), %rax
movl %eax, %r8d
movq -0x30(%rbp), %r9
callq 0x5e760
movq -0x30(%rbp), %rax
movl 0x2c(%rax), %eax
movq -0x30(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jg 0x264b6e
movq $0x1, -0xa0(%rbp)
jmp 0x264b70
jmp 0x264b72
jmp 0x264b74
cmpq $0x0, -0xa0(%rbp)
jne 0x264cac
movq 0x10(%rbp), %rax
cmpq -0x88(%rbp), %rax
jbe 0x264caa
movq 0x18(%rbp), %rax
movq -0x88(%rbp), %rcx
subq -0x90(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x264caa
movaps 0x11d45b(%rip), %xmm1   # 0x382010
movq -0x88(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x11d457(%rip), %xmm1   # 0x382020
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x11d400(%rip), %xmm1   # 0x381ff8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x98(%rbp)
cmpq $0x1, -0x98(%rbp)
jae 0x264c23
movq $0x1, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq 0x18(%rbp), %rax
jbe 0x264c3b
movq 0x18(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq -0xa8(%rbp), %rax
jbe 0x264ca8
movq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x30(%rbp), %rax
movl $0x7fffffff, 0x2c(%rax) # imm = 0x7FFFFFFF
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %esi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rax
movl %eax, %ecx
movq -0x98(%rbp), %rax
movl %eax, %r8d
movq -0x30(%rbp), %r9
callq 0x5e760
movq -0x30(%rbp), %rax
movl 0x2c(%rax), %eax
movq -0x30(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jg 0x264ca6
movq $0x1, -0xa0(%rbp)
jmp 0x264ca8
jmp 0x264caa
jmp 0x264cac
cmpq $0x0, -0xa0(%rbp)
je 0x264f36
movq $0x0, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0xa8(%rcx), %rax
jae 0x264f31
movq -0x50(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x30(%rbp), %rdi
addq $0xa8, %rdi
movq -0x48(%rbp), %rax
movl %eax, %esi
leaq -0xae(%rbp), %rdx
leaq -0xac(%rbp), %rcx
callq 0xa1ee0
movl %eax, %eax
movq %rax, -0x48(%rbp)
movzwl -0xae(%rbp), %eax
cmpl $0x2, %eax
je 0x264d3b
movl -0xac(%rbp), %eax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movzwl -0xae(%rbp), %eax
cmpl $0x3, %eax
je 0x264d55
movl -0xac(%rbp), %eax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x78(%rbp)
movzwl -0xae(%rbp), %eax
cmpl $0x0, %eax
jne 0x264d9d
movq -0x8(%rbp), %rdi
movw -0xae(%rbp), %ax
movl -0xac(%rbp), %r8d
movl $0xffff, %ecx           # imm = 0xFFFF
movl $0x1, %r9d
movzwl %ax, %esi
movl %ecx, %edx
callq 0x26d790
jmp 0x264f2c
movzwl -0xae(%rbp), %eax
cmpl $0x1, %eax
jne 0x264e3a
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl -0xac(%rbp), %ecx
cmpq %rcx, %rax
jae 0x264e35
movq -0x8(%rbp), %rdi
movw -0xae(%rbp), %dx
movq -0x10(%rbp), %rax
movq -0x70(%rbp), %rcx
addq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x15f866(%rip), %rax    # 0x3c4650
movzbl (%rax,%rcx), %eax
movw %ax, %cx
movq -0x20(%rbp), %rax
movq -0x80(%rbp), %rsi
addq -0x40(%rbp), %rsi
movsbl (%rax,%rsi), %eax
movl %eax, %eax
movl %eax, %esi
leaq 0x15f844(%rip), %rax    # 0x3c4650
movzbl (%rax,%rsi), %eax
movl $0x1, %r9d
movzwl %dx, %esi
movzwl %cx, %edx
movzwl %ax, %ecx
movl %r9d, %r8d
callq 0x26d790
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x264db5
jmp 0x264f2a
movzwl -0xae(%rbp), %eax
cmpl $0x2, %eax
jne 0x264eb0
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl -0xac(%rbp), %ecx
cmpq %rcx, %rax
jae 0x264eae
movq -0x8(%rbp), %rdi
movw -0xae(%rbp), %cx
movq -0x20(%rbp), %rax
movq -0x80(%rbp), %rdx
addq -0x40(%rbp), %rdx
movsbl (%rax,%rdx), %eax
movl %eax, %eax
movl %eax, %edx
leaq 0x15f7cd(%rip), %rax    # 0x3c4650
movzbl (%rax,%rdx), %eax
movl $0xffff, %edx           # imm = 0xFFFF
movl $0x1, %r9d
movzwl %cx, %esi
movzwl %ax, %ecx
movl %r9d, %r8d
callq 0x26d790
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x264e4e
jmp 0x264f28
movzwl -0xae(%rbp), %eax
cmpl $0x3, %eax
jne 0x264f26
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl -0xac(%rbp), %ecx
cmpq %rcx, %rax
jae 0x264f24
movq -0x8(%rbp), %rdi
movw -0xae(%rbp), %dx
movq -0x10(%rbp), %rax
movq -0x70(%rbp), %rcx
addq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x15f757(%rip), %rax    # 0x3c4650
movzbl (%rax,%rcx), %eax
movl $0xffff, %ecx           # imm = 0xFFFF
movl $0x1, %r9d
movzwl %dx, %esi
movzwl %ax, %edx
movl %r9d, %r8d
callq 0x26d790
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x264ec4
jmp 0x264f26
jmp 0x264f28
jmp 0x264f2a
jmp 0x264f2c
jmp 0x264cd2
jmp 0x265038
cmpq $0x0, -0x18(%rbp)
jbe 0x264fb6
movw $0x3, -0xae(%rbp)
movq -0x18(%rbp), %rax
movl %eax, -0xac(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl -0xac(%rbp), %ecx
cmpq %rcx, %rax
jae 0x264fb4
movq -0x8(%rbp), %rdi
movw -0xae(%rbp), %dx
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x15f6c7(%rip), %rax    # 0x3c4650
movzbl (%rax,%rcx), %eax
movl $0xffff, %ecx           # imm = 0xFFFF
movl $0x1, %r9d
movzwl %dx, %esi
movzwl %ax, %edx
movl %r9d, %r8d
callq 0x26d790
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x264f58
jmp 0x264fb6
cmpq $0x0, -0x28(%rbp)
jbe 0x265036
movw $0x2, -0xae(%rbp)
movq -0x28(%rbp), %rax
movl %eax, -0xac(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl -0xac(%rbp), %ecx
cmpq %rcx, %rax
jae 0x265034
movq -0x8(%rbp), %rdi
movw -0xae(%rbp), %cx
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rdx
movsbl (%rax,%rdx), %eax
movl %eax, %eax
movl %eax, %edx
leaq 0x15f647(%rip), %rax    # 0x3c4650
movzbl (%rax,%rdx), %eax
movl $0xffff, %edx           # imm = 0xFFFF
movl $0x1, %r9d
movzwl %cx, %esi
movzwl %ax, %ecx
movl %r9d, %r8d
callq 0x26d790
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x264fd8
jmp 0x265036
jmp 0x265038
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)