// File: /workspace/github_c_makefile_star2_O0/lh3[P]minigraph/cal_cov.c
// Function: mg_cov_map
void mg_cov_map(const gfa_t *g, const mg_gchains_t *gt, int32_t min_mapq, int32_t min_blen, double *c_seg, double *c_link, const char *qname)
{
	int32_t i, j;
	if (c_seg == 0 && c_link == 0) return;
	if (gt == 0 || gt->n_gc == 0) return;
	for (i = 0; i < gt->n_gc; ++i) {
		const mg_gchain_t *gc = &gt->gc[i];
		const mg128_t *last_an;
		assert(gc->cnt > 0 && gc->n_anchor > 0);
		if (gc->mapq < min_mapq || gc->blen < min_blen) continue;
		// count segment coverage
		for (j = 0; j < gc->cnt; ++j) {
			const mg_llchain_t *lc = &gt->lc[gc->off + j];
			int32_t s, e;
			s = 0, e = g->seg[lc->v>>1].len;
			if (j == 0) s = (int32_t)gt->a[lc->off].x + 1 - (int32_t)(gt->a[lc->off].y>>32&0xff);
			if (j == gc->cnt - 1) e = (int32_t)gt->a[lc->off + lc->cnt - 1].x + 1;
			if (c_seg) c_seg[lc->v>>1] += (double)(e - s) / g->seg[lc->v>>1].len;
		}
		// count link
		assert(gt->lc[gc->off].cnt > 0);
		last_an = &gt->a[gt->lc[gc->off].off + gt->lc[gc->off].cnt - 1];
		for (j = 1; j < gc->cnt; ++j) {
			const mg_llchain_t *lc0 = &gt->lc[gc->off + j - 1];
			const mg_llchain_t *lc1 = &gt->lc[gc->off + j];
			int64_t a01, a10;
			if (lc1->cnt > 0) {
				const mg128_t *curr_an = &gt->a[lc1->off];
				int32_t is_skip = (mg_seg_id(*curr_an) != mg_seg_id(*last_an));
				last_an = &gt->a[lc1->off + lc1->cnt - 1];
				if (is_skip) continue;
			}
			a01 = gfa_find_arc(g, lc0->v, lc1->v);
			a10 = gfa_find_arc(g, lc1->v^1, lc0->v^1);
			if (a01 < 0 || a10 < 0) {
				if (mg_verbose >= 2)
					fprintf(stderr, "[W] Multi/disconnected link: %c%s[%d] -> %c%s[%d] (%s, %ld, %ld). Continue anyway!\n",
							"><"[lc0->v&1], g->seg[lc0->v>>1].name, lc0->v,
							"><"[lc1->v&1], g->seg[lc1->v>>1].name, lc1->v, qname, (long)a01, (long)a10);
				continue;
			}
			assert((g->arc[a01].comp ^ g->arc[a10].comp) == 1);
			if (c_link) c_link[a01] += 1.0, c_link[a10] += 1.0;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xb0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movl %edx, -0x24(%rbp)
movl %ecx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x2f79b
cmpq $0x0, -0x38(%rbp)
jne 0x2f79b
jmp 0x2fcd0
cmpq $0x0, -0x20(%rbp)
je 0x2f7ac
movq -0x20(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x2f7b1
jmp 0x2fcd0
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x2fcd0
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jle 0x2f7f5
movq -0x48(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jle 0x2f7f5
jmp 0x2f814
leaq 0xe391(%rip), %rdi      # 0x3db8d
leaq 0xe3aa(%rip), %rsi      # 0x3dbad
movl $0x10, %edx
leaq 0xe3a8(%rip), %rcx      # 0x3dbb7
callq 0x2170
movq -0x48(%rbp), %rax
movl 0x44(%rax), %eax
andl $0xff, %eax
cmpl -0x24(%rbp), %eax
jl 0x2f831
movq -0x48(%rbp), %rax
movl 0x2c(%rax), %eax
cmpl -0x28(%rbp), %eax
jge 0x2f836
jmp 0x2fcc2
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x2f977
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0x40(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x58(%rbp), %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
shlq $0x6, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x60(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0x2f8df
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x58(%rbp), %rcx
movslq (%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
addl $0x1, %eax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x58(%rbp), %rdx
movslq (%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq 0x8(%rcx), %rcx
shrq $0x20, %rcx
andq $0xff, %rcx
subl %ecx, %eax
movl %eax, -0x5c(%rbp)
movl -0x40(%rbp), %eax
movq -0x48(%rbp), %rcx
movl 0xc(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2f91b
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x58(%rbp), %rcx
movl (%rcx), %ecx
movq -0x58(%rbp), %rdx
addl 0x4(%rdx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x2f967
movl -0x60(%rbp), %eax
subl -0x5c(%rbp), %eax
cvtsi2sd %eax, %xmm0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x58(%rbp), %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
shlq $0x6, %rcx
addq %rcx, %rax
cvtsi2sdl (%rax), %xmm1
divsd %xmm1, %xmm0
movq -0x30(%rbp), %rax
movq -0x58(%rbp), %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2f969
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x2f83d
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movslq 0x8(%rcx), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x4(%rax)
jle 0x2f996
jmp 0x2f9b5
leaq 0xe283(%rip), %rdi      # 0x3dc20
leaq 0xe209(%rip), %rsi      # 0x3dbad
movl $0x1c, %edx
leaq 0xe207(%rip), %rcx      # 0x3dbb7
callq 0x2170
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq -0x48(%rbp), %rdx
movslq 0x8(%rdx), %rdx
imulq $0x14, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
movq -0x20(%rbp), %rdx
movq 0x20(%rdx), %rdx
movq -0x48(%rbp), %rsi
movslq 0x8(%rsi), %rsi
imulq $0x14, %rsi, %rsi
addq %rsi, %rdx
addl 0x4(%rdx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl $0x1, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x2fcc0
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0x40(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0x40(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jle 0x2fafb
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x70(%rbp), %rcx
movslq (%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rcx
movabsq $0xff000000000000, %rax # imm = 0xFF000000000000
andq 0x8(%rcx), %rax
shrq $0x30, %rax
movq -0x50(%rbp), %rdx
movabsq $0xff000000000000, %rcx # imm = 0xFF000000000000
andq 0x8(%rdx), %rcx
shrq $0x30, %rcx
cmpl %ecx, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x8c(%rbp)
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x70(%rbp), %rcx
movl (%rcx), %ecx
movq -0x70(%rbp), %rdx
addl 0x4(%rdx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
cmpl $0x0, -0x8c(%rbp)
je 0x2faf9
jmp 0x2fcb2
jmp 0x2fafb
movq -0x18(%rbp), %rdi
movq -0x68(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x70(%rbp), %rax
movl 0x8(%rax), %edx
callq 0x2fce0
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rdi
movq -0x70(%rbp), %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
movq -0x68(%rbp), %rax
movl 0x8(%rax), %edx
xorl $0x1, %edx
callq 0x2fce0
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x78(%rbp)
jl 0x2fb49
cmpq $0x0, -0x80(%rbp)
jge 0x2fc17
leaq 0x158a0(%rip), %rax     # 0x453f0
cmpl $0x2, (%rax)
jl 0x2fc12
movq 0x15498(%rip), %rax     # 0x44ff8
movq (%rax), %rdi
movq -0x68(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0xcb14(%rip), %rax      # 0x3c68c
movsbl (%rax,%rcx), %edx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x68(%rbp), %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
shlq $0x6, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rcx
movq -0x68(%rbp), %rax
movl 0x8(%rax), %r8d
movq -0x70(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
leaq 0xcad5(%rip), %rax      # 0x3c68c
movsbl (%rax,%rsi), %r9d
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x70(%rbp), %rsi
movl 0x8(%rsi), %esi
shrl %esi
movl %esi, %esi
shlq $0x6, %rsi
addq %rsi, %rax
movq 0x18(%rax), %r14
movq -0x70(%rbp), %rax
movl 0x8(%rax), %ebx
movq 0x10(%rbp), %r11
movq -0x78(%rbp), %r10
movq -0x80(%rbp), %rax
leaq 0xe044(%rip), %rsi      # 0x3dc38
movq %r14, (%rsp)
movl %ebx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movb $0x0, %al
callq 0x2210
jmp 0x2fcb2
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x78(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
shrq $0x3f, %rax
movq -0x18(%rbp), %rcx
movq 0x48(%rcx), %rcx
movq -0x80(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movq 0x18(%rcx), %rcx
shrq $0x3f, %rcx
xorl %ecx, %eax
cmpl $0x1, %eax
jne 0x2fc56
jmp 0x2fc75
leaq 0xe02f(%rip), %rdi      # 0x3dc8c
leaq 0xdf49(%rip), %rsi      # 0x3dbad
movl $0x31, %edx
leaq 0xdf47(%rip), %rcx      # 0x3dbb7
callq 0x2170
cmpq $0x0, -0x38(%rbp)
je 0x2fcb0
movq -0x38(%rbp), %rax
movq -0x78(%rbp), %rcx
movsd 0xd38c(%rip), %xmm0     # 0x3d018
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
movq -0x80(%rbp), %rcx
movsd 0xd372(%rip), %xmm0     # 0x3d018
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2fcb2
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x2fa08
jmp 0x2fcc2
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2f7b8
addq $0xb0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopl (%rax)