// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movq 0x98(%rsp), %rbx
cmpl $0xff, %edx
setne %al
cmpq $-0x1, %rcx
setne %r8b
testb %r8b, %al
jne 0x36aec
movq %r9, %rbp
movq (%rdi), %rax
movq 0x10(%rax), %rax
leaq (%rsi,%rsi,4), %rcx
leaq (%rax,%rcx,8), %r15
movq $0x0, (%rbx)
movl 0x10(%r15), %ecx
leal (%rcx,%rcx), %eax
cmpq %rax, 0x8(%rbx)
jae 0x36753
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 %rax, 0x10(%rbx)
movl 0x10(%r15), %ecx
testl %ecx, %ecx
je 0x36add
movq 0x10(%rbx), %rdi
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %rbp, 0x10(%rsp)
movq %r14, 0x38(%rsp)
movq %r15, 0x28(%rsp)
movq (%rbx), %rax
cmpq 0x8(%rbx), %rax
jne 0x367a4
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
leaq (,%r13,2), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movq %rcx, (%rdi,%rax,8)
movq (%rbx), %rcx
cmpq 0x8(%rbx), %rcx
jne 0x367e7
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
movq 0x90(%rsp), %r11
leaq 0x25fa3a(%rip), %rax    # 0x296230
movq 0x18(%rax), %rax
movq 0x18(%r15), %rdx
movq (%rdx,%r12,8), %rsi
shrq $0x21, %rsi
movq (%rax,%rsi,8), %rax
addq %r13, %rax
leaq 0x1(,%rax,2), %rax
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx)
movq %rdi, 0x8(%rsp)
movq %rax, (%rdi,%rcx,8)
movq (%rdx,%r12,8), %rax
movq %rax, %rcx
shrq $0x21, %rcx
movq %rcx, 0x40(%rsp)
leaq (%rcx,%rcx,2), %rdx
movl 0xc(%r14,%rdx,8), %ecx
testl %ecx, %ecx
je 0x36ac3
movq %r13, 0x18(%rsp)
movq %r12, 0x30(%rsp)
leaq (%r14,%rdx,8), %rbx
movl $0x20, %r12d
xorl %r13d, %r13d
movq (%rbx), %r9
cmpb $0x0, (%r9,%r12)
je 0x36943
movl -0x14(%r9,%r12), %r8d
cmpb $0x0, (%r11,%r8)
jne 0x36943
movq -0x20(%r9,%r12), %rdx
movl -0x18(%r9,%r12), %r14d
movl %r14d, %edi
subl %edx, %edi
cmpq %rbp, %rdi
jl 0x36943
movl -0x10(%r9,%r12), %r10d
movl -0xc(%r9,%r12), %eax
movl %eax, %r15d
subl %r10d, %r15d
cmpq %rbp, %r15
jl 0x36943
movq %rdx, %r11
shrq $0x20, %r11
leaq 0x25f976(%rip), %rsi    # 0x296230
movq 0x18(%rsi), %rsi
movl (%rsi,%r8,8), %r8d
subl %eax, %r8d
testb $-0x80, -0x5(%r9,%r12)
movl %r10d, %r9d
cmovel %r8d, %r9d
cmovel %r10d, %r8d
cmpl %edx, %r8d
movl %edx, %ebp
cmovll %r8d, %ebp
movl (%rsi,%r11,8), %r10d
movl %r10d, 0x24(%rsp)
subl %r14d, %r10d
cmpl %r9d, %r10d
movl %r9d, %r11d
cmovll %r10d, %r11d
movq 0x80(%rsp), %rax
cmpl %eax, %ebp
jg 0x36936
cmpl %eax, %r11d
jg 0x36936
movl %edi, %eax
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
addl %ebp, %r11d
addl %r11d, %edi
xorps %xmm2, %xmm2
cvtsi2ss %rdi, %xmm2
leaq 0x25ee33(%rip), %rax    # 0x295758
movss 0x158(%rax), %xmm0
mulss %xmm0, %xmm2
ucomiss %xmm1, %xmm2
jbe 0x3695a
movq 0x10(%rsp), %rbp
movq 0x90(%rsp), %r11
incq %r13
movl %ecx, %eax
addq $0x28, %r12
cmpq %rax, %r13
jb 0x3685d
jmp 0x36a9f
movl %r15d, %eax
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
addl %r15d, %r11d
xorps %xmm2, %xmm2
cvtsi2ss %r11, %xmm2
mulss %xmm2, %xmm0
ucomiss %xmm1, %xmm0
movq 0x10(%rsp), %rbp
ja 0x3693b
cmpl %r8d, %edx
jg 0x36988
cmpl %r9d, %r10d
jle 0x3693b
cmpl %r8d, %edx
jl 0x369ab
cmpl %r9d, %r10d
jl 0x369ab
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x30(%rsp), %rcx
testb $0x1, 0x4(%rax,%rcx,8)
jne 0x369d1
movl %edx, %esi
jmp 0x369e8
cmpl %ebp, %edi
jl 0x3693b
cmpl %ebp, %r11d
jl 0x3693b
addl %r14d, %r9d
movl 0x24(%rsp), %edi
subl %r9d, %edi
movl %edx, %eax
subl %r8d, %eax
cmovlel %edi, %eax
cmpl $-0x3, %eax
jne 0x3693b
jmp 0x36992
movq 0x40(%rsp), %rax
movq (%rsi,%rax,8), %rax
movq %rax, %rsi
subq %r14, %rsi
movl %edx, %ecx
subq %rcx, %rax
movq %rax, %r14
movq 0x8(%rsp), %rdi
movq 0x98(%rsp), %r15
movq (%r15), %rcx
cmpq 0x8(%r15), %rcx
jne 0x36a2f
movq %rsi, 0x8(%rsp)
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r15)
shlq $0x3, %rsi
callq 0x2370
movq 0x8(%rsp), %rsi
movq %rax, %rdi
movq %rax, 0x10(%r15)
movq (%r15), %rcx
addq 0x18(%rsp), %rsi
addq %rsi, %rsi
leaq 0x1(%rcx), %rax
movq %rax, (%r15)
movq %rsi, (%rdi,%rcx,8)
movq (%r15), %rcx
cmpq 0x8(%r15), %rcx
jne 0x36a72
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r15)
shlq $0x3, %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x10(%r15)
movq (%r15), %rcx
movq 0x90(%rsp), %r11
addq 0x18(%rsp), %r14
leaq 0x1(,%r14,2), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, (%r15)
movq %rdi, 0x8(%rsp)
movq %rax, (%rdi,%rcx,8)
movl 0xc(%rbx), %ecx
jmp 0x36943
movq 0x28(%rsp), %r15
movq 0x18(%r15), %rax
movq 0x30(%rsp), %r12
movl (%rax,%r12,8), %eax
movq 0x98(%rsp), %rbx
movq 0x38(%rsp), %r14
movq 0x18(%rsp), %r13
movl %eax, %eax
addq %rax, %r13
incq %r12
movl 0x10(%r15), %eax
cmpq %rax, %r12
movq 0x8(%rsp), %rdi
jb 0x36774
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
callq 0xa041c
jmp 0x36b56
testb %dl, %dl
je 0x36b09
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
testq %rax, %rax
je 0x36b4e
movq 0x10(%rbx), %rdx
xorl %esi, %esi
xorl %edi, %edi
xorl %r8d, %r8d
movq %r8, %r9
movq (%rdx,%rdi,8), %r14
movq %r14, %r8
shrq %r8
cmpq %r9, %rcx
jb 0x36b33
cmpq %r8, %rcx
jb 0x36b53
andl $0x1, %r14d
negl %r14d
orl $0x1, %r14d
addl %esi, %r14d
incq %rdi
movl %r14d, %esi
cmpq %rdi, %rax
jne 0x36b1c
jmp 0x36b56
xorl %r14d, %r14d
jmp 0x36b56
movl %esi, %r14d
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq