// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Process_Read.cpp
// Function: produce_u_cov(ul_idx_t*, unsigned long, unsigned char, unsigned long, ma_hit_t_alloc*, long, long, long, unsigned char*, kvec_t_u64_warp*)
uint32_t produce_u_cov(ul_idx_t *ul, uint64_t id, uint8_t strand, uint64_t pos, ma_hit_t_alloc* src, int64_t min_ovlp, int64_t max_hang, int64_t gap_fuzz,
uint8_t *sset, kvec_t_u64_warp *buf)
{
	uint64_t k, l, i, z, s = 0, e = 0, qn, tn, qs, qe;
	ma_utg_t *u = NULL;
	int64_t dp, r; 
	asg_arc_t t;

	if(strand == (uint8_t)-1 || pos == (uint64_t)-1) {
		u = &(ul->ug->u.a[id]);
		buf->a.n = 0; kv_resize(uint64_t, buf->a, u->n*2);
		for (k = l = 0; k < u->n; k++) {
			kv_push(uint64_t, buf->a, l<<1);
			kv_push(uint64_t, buf->a, ((l + Get_READ_LENGTH(R_INF, u->a[k]>>33))<<1)|1);


			i = u->a[k]>>33;///rid
			for (z = 0; z < src[i].length; z++) {
				if(!src[i].buffer[z].el) continue;
				qn = Get_qn(src[i].buffer[z]); tn = Get_tn(src[i].buffer[z]);
				if(sset[tn]) continue;
				if((Get_qe(src[i].buffer[z]) - Get_qs(src[i].buffer[z])) < min_ovlp) continue;
				if((Get_te(src[i].buffer[z]) - Get_ts(src[i].buffer[z])) < min_ovlp) continue;
				r = ma_hit2arc(&(src[i].buffer[z]), Get_READ_LENGTH(R_INF, qn), Get_READ_LENGTH(R_INF, tn), 
				max_hang, asm_opt.max_hang_rate, min_ovlp, &t);
				if(r != MA_HT_TCONT) continue;///tn is contained
				if(((u->a[k]>>32)&1) == 0) {
					qs = Get_qs(src[i].buffer[z]); qe = Get_qe(src[i].buffer[z]);
				} else {
					qs = (Get_READ_LENGTH(R_INF, i)) - Get_qe(src[i].buffer[z]);
					qe = (Get_READ_LENGTH(R_INF, i)) - Get_qs(src[i].buffer[z]);
				}
				kv_push(uint64_t, buf->a, (l+qs)<<1);
				kv_push(uint64_t, buf->a, ((l+qe)<<1)|1);
			}

			l += (uint32_t)u->a[k];
		}
		sort_kvec_t_u64_warp(buf, 0);
		return 0;
	}

	if(strand) pos = ul->ug->u.a[id].len - pos - 1;
	for (k = 0, dp = 0, s = e = 0; k < buf->a.n; k++) {        
		e = buf->a.a[k]>>1;
		// fprintf(stderr, "[M::%s::k:%lu] [s, e)->[%lu, %lu), dp->%ld\n", __func__, k, s, e, dp);
		if(pos >= s && pos < e) break;
		s = buf->a.a[k]>>1;
        if (buf->a.a[k]&1) --dp;
        else ++dp;
	}

	return dp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, 0x30(%rsp)
movq 0xa8(%rsp), %r14
cmpl $0xff, %edx
setne %al
cmpq $-0x1, %rcx
setne %r8b
testb %r8b, %al
jne 0xa863
movq (%rdi), %rax
movq 0x10(%rax), %r15
imulq $0x28, %rsi, %rbx
andq $0x0, (%r14)
movl 0x10(%r15,%rbx), %eax
addl %eax, %eax
cmpq %rax, 0x8(%r14)
movq %r9, 0x8(%rsp)
jae 0xa5ab
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%r14)
movq 0x10(%r14), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x10(%r14)
addq %rbx, %r15
xorl %ebx, %ebx
xorl %r12d, %r12d
movq %r15, 0x18(%rsp)
movl 0x10(%r15), %eax
cmpq %rax, %r12
jae 0xa8bb
movq (%r14), %rax
movq 0x10(%r14), %r9
cmpq 0x8(%r14), %rax
jne 0xa5fa
leaq (%rax,%rax), %rsi
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
movq %r9, %rdi
callq 0x2370
movq %rax, %r9
movq %rax, 0x10(%r14)
movq (%r14), %rax
leaq (%rbx,%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
movq %rcx, (%r9,%rax,8)
movq (%r14), %rax
cmpq 0x8(%r14), %rax
jne 0xa63a
leaq (%rax,%rax), %rsi
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
movq %r9, %rdi
callq 0x2370
movq %rax, %r9
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x8(%rsp), %r8
leaq 0x249bea(%rip), %rcx    # 0x254230
movq 0x18(%rcx), %rcx
movq 0x18(%r15), %rdx
movq (%rdx,%r12,8), %rsi
shrq $0x21, %rsi
movq (%rcx,%rsi,8), %rcx
movq %rbx, 0x10(%rsp)
addq %rbx, %rcx
leaq 0x1(,%rcx,2), %rcx
leaq 0x1(%rax), %rsi
movq %rsi, (%r14)
movq %rcx, (%r9,%rax,8)
movq %r12, 0x20(%rsp)
movq (%rdx,%r12,8), %rcx
shrq $0x21, %rcx
movq %rcx, 0x38(%rsp)
imulq $0x18, %rcx, %r13
addq 0x30(%rsp), %r13
xorl %ebx, %ebx
xorl %r12d, %r12d
movq 0xa0(%rsp), %rdx
movl 0xc(%r13), %eax
cmpq %rax, %r12
jae 0xa841
movq (%r13), %rdi
cmpb $0x0, 0x20(%rdi,%rbx)
je 0xa835
movl 0xc(%rdi,%rbx), %eax
cmpb $0x0, (%rdx,%rax)
jne 0xa835
movq (%rdi,%rbx), %rbp
movl 0x8(%rdi,%rbx), %r15d
movl %r15d, %ecx
subl %ebp, %ecx
cmpq %r8, %rcx
jl 0xa835
movl 0x14(%rdi,%rbx), %ecx
subl 0x10(%rdi,%rbx), %ecx
cmpq %r8, %rcx
jl 0xa835
movq %r9, 0x28(%rsp)
addq %rbx, %rdi
movq %rbp, %rcx
shrq $0x20, %rcx
leaq 0x249b2b(%rip), %rdx    # 0x254230
movq 0x18(%rdx), %r14
movl (%r14,%rcx,8), %esi
movl (%r14,%rax,8), %edx
leaq 0x249040(%rip), %rax    # 0x253758
movss 0x158(%rax), %xmm0
movq 0x90(%rsp), %rcx
leaq 0x40(%rsp), %r9
callq 0x905e
cmpl $-0x3, %eax
jne 0xa756
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rsp), %rcx
testb $0x1, 0x4(%rax,%rcx,8)
movq 0x28(%rsp), %r9
jne 0xa775
movl %ebp, %r14d
jmp 0xa78c
movq 0xa8(%rsp), %r14
movq 0x8(%rsp), %r8
movq 0xa0(%rsp), %rdx
movq 0x28(%rsp), %r9
jmp 0xa835
movq 0x38(%rsp), %rax
movq (%r14,%rax,8), %rax
movq %rax, %r14
subq %r15, %r14
movl %ebp, %ecx
subq %rcx, %rax
movq %rax, %r15
movq 0xa8(%rsp), %rbp
movq (%rbp), %rax
cmpq 0x8(%rbp), %rax
jne 0xa7c7
leaq (%rax,%rax), %rsi
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbp)
shlq $0x3, %rsi
movq %r9, %rdi
callq 0x2370
movq %rax, %r9
movq %rax, 0x10(%rbp)
movq (%rbp), %rax
addq 0x10(%rsp), %r14
addq %r14, %r14
leaq 0x1(%rax), %rcx
movq %rcx, (%rbp)
movq %r14, (%r9,%rax,8)
movq (%rbp), %rax
cmpq 0x8(%rbp), %rax
movq %rbp, %r14
jne 0xa810
leaq (%rax,%rax), %rsi
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
movq %r9, %rdi
callq 0x2370
movq %rax, %r9
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x8(%rsp), %r8
addq 0x10(%rsp), %r15
leaq 0x1(,%r15,2), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
movq %rcx, (%r9,%rax,8)
movq 0xa0(%rsp), %rdx
incq %r12
addq $0x28, %rbx
jmp 0xa69d
movq 0x18(%rsp), %r15
movq 0x18(%r15), %rax
movq 0x20(%rsp), %r12
movl (%rax,%r12,8), %eax
movq 0x10(%rsp), %rbx
addq %rax, %rbx
incq %r12
jmp 0xa5b8
testb %dl, %dl
je 0xa880
movq (%rdi), %rax
movq 0x10(%rax), %rax
imulq $0x28, %rsi, %rdx
movl (%rax,%rdx), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
notq %rcx
addq %rax, %rcx
movq (%r14), %rax
xorl %r8d, %r8d
xorl %edx, %edx
xorl %ebp, %ebp
cmpq %rdx, %rax
je 0xa8c7
movq 0x10(%r14), %rsi
movq (%rsi,%rdx,8), %rsi
movq %rsi, %rdi
shrq %rdi
cmpq %r8, %rcx
jb 0xa8a7
cmpq %rdi, %rcx
jb 0xa8c7
andl $0x1, %esi
negl %esi
orl $0x1, %esi
addl %ebp, %esi
incq %rdx
movq %rdi, %r8
movl %esi, %ebp
jmp 0xa88a
xorl %ebp, %ebp
movq %r14, %rdi
xorl %esi, %esi
callq 0x68eff
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq