// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movq %r8, 0x18(%rsp)
movq 0x98(%rsp), %rbx
cmpl $0xff, %edx
setne %al
cmpq $-0x1, %rcx
setne %r8b
testb %r8b, %al
jne 0x37540
movq (%rdi), %rax
movq 0x10(%rax), %rax
leaq (%rsi,%rsi,4), %rcx
leaq (%rax,%rcx,8), %rax
movq $0x0, (%rbx)
movq %rax, 0x8(%rsp)
movl 0x10(%rax), %eax
addl %eax, %eax
cmpq %rax, 0x8(%rbx)
movq %r9, (%rsp)
jae 0x37251
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(%rbx)
movq 0x10(%rbx), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq (%rsp), %r9
movq %rax, 0x10(%rbx)
movq 0x8(%rsp), %rax
cmpl $0x0, 0x10(%rax)
je 0x37531
movq 0x90(%rsp), %r8
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x372a8
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x90(%rsp), %r8
movq (%rsp), %r9
movq %rax, 0x10(%rbx)
leaq (%r15,%r15), %rax
movq (%rbx), %rcx
movq 0x10(%rbx), %rdi
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
movq %rax, (%rdi,%rcx,8)
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x372f4
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
callq 0x2370
movq 0x90(%rsp), %r8
movq (%rsp), %r9
movq %rax, 0x10(%rbx)
leaq 0x253f35(%rip), %rax    # 0x28b230
movq 0x18(%rax), %rax
movq 0x8(%rsp), %rcx
movq 0x18(%rcx), %rcx
movq (%rcx,%r14,8), %rdx
shrq $0x21, %rdx
movq (%rax,%rdx,8), %rax
movq %r15, 0x10(%rsp)
addq %r15, %rax
leaq 0x1(,%rax,2), %rax
movq (%rbx), %rdx
movq 0x10(%rbx), %rsi
leaq 0x1(%rdx), %rdi
movq %rdi, (%rbx)
movq %rax, (%rsi,%rdx,8)
movq %r14, 0x20(%rsp)
movq (%rcx,%r14,8), %rax
shrq $0x21, %rax
movq %rax, 0x28(%rsp)
leaq (%rax,%rax,2), %rax
movq 0x18(%rsp), %rcx
cmpl $0x0, 0xc(%rcx,%rax,8)
je 0x37500
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,8), %r12
xorl %ebp, %ebp
xorl %r14d, %r14d
movq (%r12), %rdi
cmpb $0x0, 0x20(%rdi,%rbp)
je 0x374eb
movl 0xc(%rdi,%rbp), %eax
cmpb $0x0, (%r8,%rax)
jne 0x374eb
movq (%rdi,%rbp), %r15
movl 0x8(%rdi,%rbp), %ebx
movl %ebx, %ecx
subl %r15d, %ecx
cmpq %r9, %rcx
jl 0x374eb
movl 0x14(%rdi,%rbp), %ecx
subl 0x10(%rdi,%rbp), %ecx
cmpq %r9, %rcx
jl 0x374eb
addq %rbp, %rdi
movq %r15, %rcx
shrq $0x20, %rcx
leaq 0x253e70(%rip), %rdx    # 0x28b230
movq 0x18(%rdx), %r13
movl (%r13,%rcx,8), %esi
movl (%r13,%rax,8), %edx
leaq 0x253383(%rip), %rax    # 0x28a758
movss 0x158(%rax), %xmm0
movq 0x80(%rsp), %rcx
movl %r9d, %r8d
leaq 0x30(%rsp), %r9
callq 0x35c89
movq 0x90(%rsp), %r8
movq (%rsp), %r9
cmpl $-0x3, %eax
jne 0x374eb
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rsp), %rcx
testb $0x1, 0x4(%rax,%rcx,8)
jne 0x37421
movl %r15d, %r13d
jmp 0x3743a
movq 0x28(%rsp), %rax
movq (%r13,%rax,8), %rax
movq %rax, %r13
subq %rbx, %r13
movl %r15d, %ecx
subq %rcx, %rax
movq %rax, %rbx
movq 0x98(%rsp), %r15
movq 0x8(%r15), %rax
cmpq %rax, (%r15)
jne 0x3747c
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r15)
movq 0x10(%r15), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x90(%rsp), %r8
movq (%rsp), %r9
movq %rax, 0x10(%r15)
addq 0x10(%rsp), %r13
addq %r13, %r13
movq (%r15), %rax
movq 0x10(%r15), %rdi
leaq 0x1(%rax), %rcx
movq %rcx, (%r15)
movq %r13, (%rdi,%rax,8)
movq 0x8(%r15), %rax
cmpq %rax, (%r15)
jne 0x374cc
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r15)
shlq $0x3, %rsi
callq 0x2370
movq 0x90(%rsp), %r8
movq (%rsp), %r9
movq %rax, 0x10(%r15)
addq 0x10(%rsp), %rbx
leaq 0x1(,%rbx,2), %rax
movq (%r15), %rcx
movq 0x10(%r15), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r15)
movq %rax, (%rdx,%rcx,8)
incq %r14
movl 0xc(%r12), %eax
addq $0x28, %rbp
cmpq %rax, %r14
jb 0x3736a
movq 0x8(%rsp), %rcx
movq 0x18(%rcx), %rax
movq 0x20(%rsp), %r14
movl (%rax,%r14,8), %eax
movq 0x10(%rsp), %r15
addq %rax, %r15
incq %r14
movl 0x10(%rcx), %eax
cmpq %rax, %r14
movq 0x98(%rsp), %rbx
jb 0x3726e
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x9fc63
jmp 0x375a4
testb %dl, %dl
je 0x3755d
movq (%rdi), %rax
movq 0x10(%rax), %rax
leaq (%rsi,%rsi,4), %rdx
movl (%rax,%rdx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
notq %rcx
addq %rax, %rcx
movq (%rbx), %rax
xorl %r14d, %r14d
testq %rax, %rax
je 0x375a4
xorl %edx, %edx
xorl %esi, %esi
cmpq %rsi, %rcx
jb 0x37581
movq 0x10(%rbx), %rsi
movq (%rsi,%rdx,8), %rsi
shrq %rsi
cmpq %rsi, %rcx
jb 0x375a4
movq 0x10(%rbx), %rsi
movq (%rsi,%rdx,8), %rdi
movq %rdi, %rsi
shrq %rsi
andl $0x1, %edi
negq %rdi
orq $0x1, %rdi
addq %rdi, %r14
incq %rdx
cmpq %rdx, %rax
jne 0x3756c
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq