// File: chhylp123[P]hifiasm/ecovlp.cpp
// Function: worker_sl_ec(void*, long, int)
static void worker_sl_ec(void *data, long i, int tid)
{
    // if(i != 0) return;

	sl_v *p = &(((sl_v*)data)[tid]); uint8_t *oa = NULL; char *na = NULL; uint64_t tqual, wqual;
    uint32_t ci = 0, len, xk, yk, wx[2], wy[2], k, Nn, yn = 0, tot_e; uint16_t c, bq, bt; 


    ci = 0; xk = yk = 0; tot_e = 0;
    while (ci < scc.a[i].n) {
        // ci = pop_trace_bp(&scc.a[i], ci, &c, &b, &len);
        ci = pop_trace_bp_f(&scc.a[i], ci, &c, &bq, &bt, &len);
        if(c != 3) yk += len;
        if(c != 0) tot_e += len;
        // fprintf(stderr, "|%u%c(%c)", len, cm[c], ((c==1)||(c==2))?(cc[b]):('*')); // s_H
    }
    if(tot_e == 0) return;///no change

    yn = yk; yk++; kv_resize(char, (*p), yk); p->a[yn] = '\0';
    recover_UC_Read(&p->z, &R_INF, i); ///b->z.length


    // char cm[4], cc[4]; 
    // cm[0] = 'M'; cm[1] = 'S'; cm[2] = 'I'; cm[3] = 'D';
    // cc[0] = 'A'; cc[1] = 'C'; cc[2] = 'G'; cc[3] = 'T';

    ci = 0; xk = yk = 0; Nn = 0;
    while (ci < scc.a[i].n) {
        wx[0] = xk; wy[0] = yk;
        // ci = pop_trace_bp(&scc.a[i], ci, &c, &b, &len);
        ci = pop_trace_bp_f(&scc.a[i], ci, &c, &bq, &bt, &len);
        if(c != 2) xk += len;
        if(c != 3) yk += len;
        wx[1] = xk; wy[1] = yk;
        // if(xk > (uint32_t)p->z.length) fprintf(stderr, "[M::%s] xk::%u, len::%u, c::%u, rid::%ld\n", __func__, xk, (uint32_t)p->z.length, c, i);
        if(c == 0) {
            // memcpy(p->a + wy[0], p->z.seq + wx[0], (wx[1]-wx[0])*sizeof((*(p->a))));
            for (; wx[0] < wx[1]; wx[0]++, wy[0]++) {
                p->a[wy[0]] = p->z.seq[wx[0]];
                if(p->a[wy[0]] == 'N') Nn++;
            }
        } else if(c == 1 || c == 2) {
            for (k = wy[0]; k < wy[1]; k++) {
                p->a[k] = s_H[bt]; 
                if(p->a[k] == 'N') Nn++;
            }
        }

        // if(i == 700) fprintf(stderr, "|%u%c(%c)(x::%u)(y::%u)", len, cm[c], ((c==1)||(c==2))?(cc[b]):('*'), wx[1], wy[1]); // s_H
    }

    // if(i == 700) fprintf(stderr, "|\n");
    if(asm_opt.is_sc) retrive_bqual(&(p->q), NULL, i, -1, -1, 0, sc_bn);


    if (R_INF.read_size[i] < yn) {
		R_INF.read_size[i] = yn;
		REALLOC(R_INF.read_sperate[i], R_INF.read_size[i]/4+1);
        if(asm_opt.is_sc) REALLOC(R_INF.rsc[i], ((R_INF.read_size[i]/sc_bn) + ((R_INF.read_size[i]%sc_bn)?1:0)));
	}
	R_INF.read_length[i] = yn;
    // if(Nn > 0) fprintf(stderr, "[M::%s] Nn->%u\n", __func__, Nn);

    // for (k = 0; k < yn; k++) {
    //     c = seq_nt6_table[(uint8_t)p->a[k]]; 
    //     if (c >= 4) { 
    //         fprintf(stderr, "[M::%s] Nn->%u, yn::%u, xn::%lld, k::%u, str::%c, c::%u, rid::%ld\n", __func__, Nn, yn, p->z.length, k, p->a[k], c, i);
    //     }
    // }


    ///debug
    // resize_UC_Read(&p->z, p->z.length * 2); 
    // dbg_rsc(p->z.seq + p->z.length, p->z.length, p->a, yn, &(scc.a[i]), p->z.seq, i);


	ha_compress_base(Get_READ(R_INF, i), p->a, yn, &R_INF.N_site[i], Nn);
    if(asm_opt.is_sc) {
        oa = p->q.a; na = p->a; 
        ci = 0; xk = yk = 0; Nn = 0;
        while (ci < scc.a[i].n) {
            wx[0] = xk; wy[0] = yk;
            ci = pop_trace_bp_f(&scc.a[i], ci, &c, &bq, &bt, &len);
            if(c != 2) xk += len;
            if(c != 3) yk += len;
            wx[1] = xk; wy[1] = yk;
            if(c == 0 || c == 1) {
                memcpy(na + wy[0], oa + wx[0], (wx[1]-wx[0])*sizeof((*oa)));
            } else if(c == 2) {
                get_wqual(i, wx[0], 0, NULL, oa, sc_wn, &tqual, &wqual);
                for (k = wy[0]; k < wy[1]; k++) na[k] = wqual;
            }
        }
        assert(yk == yn);
        ha_compress_qual_bit(Get_QUAL(R_INF, i), na, yn, sc_bn);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x70(%rbp)
movl -0x44(%rbp), %eax
movq 0x15accb(%rip), %rcx    # 0x3c55e8
imulq $0x18, -0x10(%rbp), %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x26a97a
movq 0x15acb7(%rip), %rdi    # 0x3c55e8
imulq $0x18, -0x10(%rbp), %rax
addq %rax, %rdi
movl -0x44(%rbp), %esi
leaq -0x72(%rbp), %rdx
leaq -0x74(%rbp), %rcx
leaq -0x76(%rbp), %r8
leaq -0x48(%rbp), %r9
callq 0x1b53f0
movl %eax, -0x44(%rbp)
movzwl -0x72(%rbp), %eax
cmpl $0x3, %eax
je 0x26a966
movl -0x48(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
movzwl -0x72(%rbp), %eax
cmpl $0x0, %eax
je 0x26a978
movl -0x48(%rbp), %eax
addl -0x70(%rbp), %eax
movl %eax, -0x70(%rbp)
jmp 0x26a913
cmpl $0x0, -0x70(%rbp)
jne 0x26a985
jmp 0x26af66
movl -0x50(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x50(%rbp), %ecx
cmpq %rcx, %rax
jae 0x26aa70
movl -0x50(%rbp), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
shrq %rcx
movq -0x20(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x2, %rcx
movq -0x20(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x4, %rcx
movq -0x20(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x8, %rcx
movq -0x20(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x10, %rcx
movq -0x20(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x0, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x26aa72
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x6c(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movq -0x20(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rdx
leaq 0x15a83c(%rip), %rsi    # 0x3c52d0
callq 0xa380
movl $0x0, -0x44(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x68(%rbp)
movl -0x44(%rbp), %eax
movq 0x15ab29(%rip), %rcx    # 0x3c55e8
imulq $0x18, -0x10(%rbp), %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x26ac0b
movl -0x4c(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x60(%rbp)
movq 0x15ab05(%rip), %rdi    # 0x3c55e8
imulq $0x18, -0x10(%rbp), %rax
addq %rax, %rdi
movl -0x44(%rbp), %esi
leaq -0x72(%rbp), %rdx
leaq -0x74(%rbp), %rcx
leaq -0x76(%rbp), %r8
leaq -0x48(%rbp), %r9
callq 0x1b53f0
movl %eax, -0x44(%rbp)
movzwl -0x72(%rbp), %eax
cmpl $0x2, %eax
je 0x26ab18
movl -0x48(%rbp), %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movzwl -0x72(%rbp), %eax
cmpl $0x3, %eax
je 0x26ab2a
movl -0x48(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x5c(%rbp)
movzwl -0x72(%rbp), %eax
cmpl $0x0, %eax
jne 0x26ab9a
jmp 0x26ab41
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x26ab98
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x58(%rbp), %ecx
movb (%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %ecx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x4e, %eax
jne 0x26ab82
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x26ab84
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x26ab41
jmp 0x26ac06
movzwl -0x72(%rbp), %eax
cmpl $0x1, %eax
je 0x26abac
movzwl -0x72(%rbp), %eax
cmpl $0x2, %eax
jne 0x26ac04
movl -0x60(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jae 0x26ac02
movzwl -0x76(%rbp), %eax
movl %eax, %ecx
leaq 0x159b89(%rip), %rax    # 0x3c4750
movb (%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x64(%rbp), %ecx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x64(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x4e, %eax
jne 0x26abf5
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x26abf7
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x26abb2
jmp 0x26ac04
jmp 0x26ac06
jmp 0x26aab5
leaq 0x159be6(%rip), %rax    # 0x3c47f8
cmpq $0x0, 0x2b0(%rax)
je 0x26ac46
movq -0x20(%rbp), %rdi
addq $0x38, %rdi
movq -0x10(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
movq $-0x1, %r8
xorl %r9d, %r9d
movq %r8, %rcx
movq $0x2, (%rsp)
callq 0xaec0
leaq 0x15a683(%rip), %rax    # 0x3c52d0
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x6c(%rbp), %ecx
cmpq %rcx, %rax
jae 0x26ad4f
movl -0x6c(%rbp), %eax
movl %eax, %edx
leaq 0x15a65f(%rip), %rax    # 0x3c52d0
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
leaq 0x15a64c(%rip), %rax    # 0x3c52d0
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x15a639(%rip), %rax    # 0x3c52d0
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
shrq $0x2, %rsi
addq $0x1, %rsi
shlq $0x0, %rsi
callq 0x2360
movq %rax, %rdx
leaq 0x15a612(%rip), %rax    # 0x3c52d0
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
leaq 0x159b27(%rip), %rax    # 0x3c47f8
cmpq $0x0, 0x2b0(%rax)
je 0x26ad4d
leaq 0x15a5ee(%rip), %rax    # 0x3c52d0
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x15a5db(%rip), %rax    # 0x3c52d0
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
shrq %rsi
leaq 0x15a5c5(%rip), %rax    # 0x3c52d0
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
andq $0x1, %rdx
xorl %eax, %eax
movl $0x1, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
cltq
addq %rax, %rsi
shlq $0x0, %rsi
callq 0x2360
movq %rax, %rdx
leaq 0x15a58f(%rip), %rax    # 0x3c52d0
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x26ad4f
movl -0x6c(%rbp), %eax
movl %eax, %edx
leaq 0x15a575(%rip), %rax    # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
leaq 0x15a562(%rip), %rax    # 0x3c52d0
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
movl -0x6c(%rbp), %eax
movl %eax, %edx
leaq 0x15a542(%rip), %rax    # 0x3c52d0
movq (%rax), %rcx
movq -0x10(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rcx
movl -0x68(%rbp), %eax
movl %eax, %r8d
callq 0xa710
leaq 0x159a4a(%rip), %rax    # 0x3c47f8
cmpq $0x0, 0x2b0(%rax)
je 0x26af66
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x68(%rbp)
movl -0x44(%rbp), %eax
movq 0x15a7ee(%rip), %rcx    # 0x3c55e8
imulq $0x18, -0x10(%rbp), %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x26af17
movl -0x4c(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x60(%rbp)
movq 0x15a7ca(%rip), %rdi    # 0x3c55e8
imulq $0x18, -0x10(%rbp), %rax
addq %rax, %rdi
movl -0x44(%rbp), %esi
leaq -0x72(%rbp), %rdx
leaq -0x74(%rbp), %rcx
leaq -0x76(%rbp), %r8
leaq -0x48(%rbp), %r9
callq 0x1b53f0
movl %eax, -0x44(%rbp)
movzwl -0x72(%rbp), %eax
cmpl $0x2, %eax
je 0x26ae53
movl -0x48(%rbp), %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movzwl -0x72(%rbp), %eax
cmpl $0x3, %eax
je 0x26ae65
movl -0x48(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x5c(%rbp)
movzwl -0x72(%rbp), %eax
cmpl $0x0, %eax
je 0x26ae83
movzwl -0x72(%rbp), %eax
cmpl $0x1, %eax
jne 0x26aeac
movq -0x30(%rbp), %rdi
movl -0x60(%rbp), %eax
addq %rax, %rdi
movq -0x28(%rbp), %rsi
movl -0x58(%rbp), %eax
addq %rax, %rsi
movl -0x54(%rbp), %eax
subl -0x58(%rbp), %eax
movl %eax, %eax
movl %eax, %edx
shlq $0x0, %rdx
callq 0x2180
jmp 0x26af12
movzwl -0x72(%rbp), %eax
cmpl $0x2, %eax
jne 0x26af10
movq -0x10(%rbp), %rdi
movl -0x58(%rbp), %eax
movl %eax, %esi
movq -0x28(%rbp), %r8
xorl %eax, %eax
movl %eax, %ecx
movl $0x5, %r9d
leaq -0x38(%rbp), %r10
leaq -0x40(%rbp), %rax
movq %rcx, %rdx
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x45d00
movl -0x60(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jae 0x26af0e
movq -0x40(%rbp), %rax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x64(%rbp), %ecx
movb %dl, (%rax,%rcx)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x26aeeb
jmp 0x26af10
jmp 0x26af12
jmp 0x26adf0
movl -0x50(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jne 0x26af21
jmp 0x26af40
leaq 0x1255d3(%rip), %rdi    # 0x3904fb
leaq 0x123cdc(%rip), %rsi    # 0x38ec0b
movl $0x17aa, %edx           # imm = 0x17AA
leaq 0x1255c9(%rip), %rcx    # 0x390504
callq 0x2130
leaq 0x15a389(%rip), %rax    # 0x3c52d0
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x30(%rbp), %rsi
movl -0x6c(%rbp), %eax
movl %eax, %edx
movl $0x2, %ecx
callq 0xab10
addq $0x90, %rsp
popq %rbp
retq
nop