// File: chhylp123[P]hifiasm/Correct.cpp
// Function: gen_sub_ov_adv(ul_idx_t const*, overlap_region*, double, utg_ct_t*, unsigned long, kv_ul_ov_t*)
uint64_t gen_sub_ov_adv(const ul_idx_t *udb, overlap_region* o, double o_rate, utg_ct_t *ct_a, uint64_t ct_n, kv_ul_ov_t *res)
{
	uint64_t ts, te, i, l, rn = res->n, rev = o->y_pos_strand, s, e, rid, t[2]; ul_ov_t z;
	ma_utg_t *u = &(udb->ug->u.a[o->y_id]); int64_t k;
    if(!rev){
        ts = o->y_pos_s; te = o->y_pos_e + 1; k = 0;
    } else {
        ts = u->len - (o->y_pos_e+1); te = u->len - o->y_pos_s; 
        k = ((int64_t)o->w_list.n)-1; if(k < 0) k = 0;
    }

    if(!ct_a) {    
        for (i = l = 0; i < u->n; i++) {
            rid = u->a[i]>>33; 
            s = l; e = l + Get_READ_LENGTH(R_INF, rid);
            l += (uint32_t)u->a[i];
            if(e <= ts) continue; 
            if(s >= te) break;
            t[0] = (rev?(u->len-e):(s)); t[1] = (rev?(u->len-s):(e));
            if(extract_subov(t[0], t[1], o, o_rate, &k, &z)) {
                ///[ts, te) -> whole interval rid at the unitig adjusted by the reverse 
                // z.ts = t[0]; z.te = t[1]; 
                ///the strand of rid at the unitig
                z.rev = rev; 
                ///non-contained read at the unitg
                z.el = 0; 
                ///rid
                z.tn = rid;
                ///i-th read at the unitig
                z.qn = i;
                kv_push(ul_ov_t, *res, z);
            }
        }
    } else {
        for (i = 0; i < ct_n; i++) {
            rid = ct_a[i].x>>1; s = ct_a[i].s; e = ct_a[i].e;
            if(e <= ts) continue; 
            if(s >= te) break;
            t[0] = (rev?(u->len-e):(s)); t[1] = (rev?(u->len-s):(e));
            if(extract_subov(t[0], t[1], o, o_rate, &k, &z)) {
                ///[ts, te) -> whole interval rid at the unitig adjusted by the reverse 
                // z.ts = t[0]; z.te = t[1]; 
                ///the strand of rid at the unitig
                z.rev = rev; 
                ///contained read at the unitg
                z.el = 1; 
                ///rid
                z.tn = rid;
                ///i-th read at the unitig
                z.qn = i;
                kv_push(ul_ov_t, *res, z);
            }
        }
    }
    return res->n-rn;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x10(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xb8(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x8d65a
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
addl $0x1, %eax
movl %eax, %eax
movq %rax, -0x40(%rbp)
movq $0x0, -0xc0(%rbp)
jmp 0x8d6bf
movq -0xb8(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x10(%rbp), %rcx
movl 0x18(%rcx), %ecx
addl $0x1, %ecx
subl %ecx, %eax
movl %eax, %eax
movq %rax, -0x38(%rbp)
movq -0xb8(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x10(%rbp), %rcx
subl 0x14(%rcx), %eax
movl %eax, %eax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
subq $0x1, %rax
movq %rax, -0xc0(%rbp)
cmpq $0x0, -0xc0(%rbp)
jge 0x8d6bd
movq $0x0, -0xc0(%rbp)
jmp 0x8d6bf
cmpq $0x0, -0x20(%rbp)
jne 0x8d930
movq $0x0, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0xb8(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
jae 0x8d92b
movq -0xb8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movq %rax, -0x78(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x50(%rbp), %rax
leaq 0x337bb1(%rip), %rcx    # 0x3c52d0
movq 0x18(%rcx), %rcx
movq -0x78(%rbp), %rdx
addq (%rcx,%rdx,8), %rax
movq %rax, -0x70(%rbp)
movq -0xb8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x38(%rbp), %rax
ja 0x8d75b
jmp 0x8d91a
movq -0x68(%rbp), %rax
cmpq -0x40(%rbp), %rax
jb 0x8d76a
jmp 0x8d92b
cmpq $0x0, -0x60(%rbp)
je 0x8d78e
movq -0xb8(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
subq -0x70(%rbp), %rax
movq %rax, -0xc8(%rbp)
jmp 0x8d799
movq -0x68(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x8d7cb
movq -0xb8(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
subq -0x68(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0x8d7d6
movq -0x70(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0x10(%rbp), %rdx
movsd -0x18(%rbp), %xmm0
leaq -0xc0(%rbp), %rcx
leaq -0xac(%rbp), %r8
callq 0x8d140
cmpq $0x0, %rax
je 0x8d918
movq -0x60(%rbp), %rax
movl %eax, %ecx
movl -0x94(%rbp), %eax
andl $0x1, %ecx
shll $0x1f, %ecx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
orl %ecx, %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
andl $0xbfffffff, %eax       # imm = 0xBFFFFFFF
orl $0x0, %eax
movl %eax, -0x94(%rbp)
movq -0x78(%rbp), %rax
movl %eax, -0xa0(%rbp)
movq -0x48(%rbp), %rax
movl %eax, -0xac(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x8d8cc
movq -0x30(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x8d890
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0xd8(%rbp)
jmp 0x8d89e
movl $0x2, %eax
movq %rax, -0xd8(%rbp)
jmp 0x8d89e
movq -0xd8(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq -0xac(%rbp), %rcx
movq %rcx, (%rax)
movq -0xa4(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x9c(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x94(%rbp), %ecx
movl %ecx, 0x18(%rax)
jmp 0x8d918
jmp 0x8d91a
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x8d6da
jmp 0x8db65
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x8db63
movq -0x20(%rbp), %rax
imulq $0xc, -0x48(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl %eax
movl %eax, %eax
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rax
imulq $0xc, -0x48(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rax
imulq $0xc, -0x48(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x38(%rbp), %rax
ja 0x8d991
jmp 0x8db52
movq -0x68(%rbp), %rax
cmpq -0x40(%rbp), %rax
jb 0x8d9a0
jmp 0x8db63
cmpq $0x0, -0x60(%rbp)
je 0x8d9c4
movq -0xb8(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
subq -0x70(%rbp), %rax
movq %rax, -0xe0(%rbp)
jmp 0x8d9cf
movq -0x68(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x8da01
movq -0xb8(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
subq -0x68(%rbp), %rax
movq %rax, -0xe8(%rbp)
jmp 0x8da0c
movq -0x70(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0x10(%rbp), %rdx
movsd -0x18(%rbp), %xmm0
leaq -0xc0(%rbp), %rcx
leaq -0xac(%rbp), %r8
callq 0x8d140
cmpq $0x0, %rax
je 0x8db50
movq -0x60(%rbp), %rax
movl %eax, %ecx
movl -0x94(%rbp), %eax
andl $0x1, %ecx
shll $0x1f, %ecx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
orl %ecx, %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
andl $0xbfffffff, %eax       # imm = 0xBFFFFFFF
orl $0x40000000, %eax       # imm = 0x40000000
movl %eax, -0x94(%rbp)
movq -0x78(%rbp), %rax
movl %eax, -0xa0(%rbp)
movq -0x48(%rbp), %rax
movl %eax, -0xac(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x8db04
movq -0x30(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x8dac8
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0xf0(%rbp)
jmp 0x8dad6
movl $0x2, %eax
movq %rax, -0xf0(%rbp)
jmp 0x8dad6
movq -0xf0(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq -0xac(%rbp), %rcx
movq %rcx, (%rax)
movq -0xa4(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x9c(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x94(%rbp), %ecx
movl %ecx, 0x18(%rax)
jmp 0x8db50
jmp 0x8db52
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x8d938
jmp 0x8db65
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
subq -0x58(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
nopw (%rax,%rax)