// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, 0x18(%rsp)
movl %edx, 0x1c(%rsp)
movq %rdi, 0x8(%rsp)
movq %r8, %rax
movq %r9, 0x28(%rsp)
orq %r9, %rax
sete %al
testq %rsi, %rsi
je 0x1f137
testb %al, %al
jne 0x1f137
movq %rsi, %r12
cmpl $0x0, 0x8(%rsi)
je 0x1f137
cmpl $0x0, 0x8(%r12)
jle 0x1f137
movq %r8, %r14
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movsd 0xa371(%rip), %xmm2     # 0x290c0
xorl %ecx, %ecx
movq 0x18(%r12), %rdx
movq %rcx, 0x30(%rsp)
imulq $0x68, %rcx, %rax
movl 0xc(%rdx,%rax), %esi
testl %esi, %esi
jle 0x1f146
addq %rax, %rdx
cmpl $0x0, 0x10(%rdx)
jle 0x1f146
movzbl 0x44(%rdx), %eax
cmpl 0x1c(%rsp), %eax
jl 0x1f121
movl 0x18(%rsp), %eax
cmpl %eax, 0x2c(%rdx)
jl 0x1f121
movq %rdx, (%rsp)
movslq 0x8(%rdx), %rcx
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
leal -0x1(%rsi), %edx
leaq (%rcx,%rcx,4), %rcx
shlq $0x2, %rcx
addq 0x20(%r12), %rcx
shlq $0x2, %rdx
leaq (%rdx,%rdx,4), %rdx
shlq $0x2, %rsi
leaq (%rsi,%rsi,4), %rsi
xorl %edi, %edi
xorl %r8d, %r8d
testq %rdi, %rdi
jne 0x1edeb
movq 0x28(%r12), %r8
movslq (%rcx,%rdi), %r9
shlq $0x4, %r9
movl (%r8,%r9), %r10d
notl %r10d
movzbl 0xc(%r8,%r9), %r8d
addl %r10d, %r8d
movl 0x8(%rcx,%rdi), %r9d
shrl %r9d
movq %r9, %r10
shlq $0x6, %r10
movl (%rax,%r10), %r10d
movl %r10d, %r11d
cmpq %rdi, %rdx
jne 0x1ee23
movq 0x28(%r12), %r11
movslq (%rcx,%rdi), %rbx
movslq 0x4(%rcx,%rdi), %r13
addq %rbx, %r13
shlq $0x4, %r13
movl -0x10(%r11,%r13), %r11d
incl %r11d
testq %r14, %r14
je 0x1ee4b
addl %r8d, %r11d
xorps %xmm0, %xmm0
cvtsi2sd %r11d, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r10d, %xmm1
divsd %xmm1, %xmm0
addsd (%r14,%r9,8), %xmm0
movsd %xmm0, (%r14,%r9,8)
addq $0x14, %rdi
cmpq %rdi, %rsi
jne 0x1edc6
movq 0x20(%r12), %rcx
movq (%rsp), %r8
movslq 0x8(%r8), %rax
leaq (%rax,%rax,4), %rdx
movslq 0x4(%rcx,%rdx,4), %rax
testq %rax, %rax
jle 0x1f184
cmpl $0x2, 0xc(%r8)
jl 0x1f121
leaq (%rcx,%rdx,4), %rcx
movq 0x28(%r12), %rdx
movslq (%rcx), %rcx
addq %rax, %rcx
shlq $0x4, %rcx
leaq (%rdx,%rcx), %r9
addq $-0x10, %r9
movl $0x1, %ebx
movq 0x20(%r12), %rax
movslq 0x8(%r8), %rcx
movslq %ebx, %rdx
addq %rcx, %rdx
leaq (%rdx,%rdx,4), %rcx
leaq (%rax,%rcx,4), %rax
movslq 0x4(%rax), %rcx
testq %rcx, %rcx
jle 0x1eef3
movq 0x28(%r12), %rdx
movslq (%rax), %rsi
addq %rsi, %rcx
shlq $0x4, %rsi
movq 0x8(%r9), %rdi
xorq 0x8(%rdx,%rsi), %rdi
shrq $0x30, %rdi
shlq $0x4, %rcx
leaq (%rdx,%rcx), %r9
addq $-0x10, %r9
testb %dil, %dil
jne 0x1f08a
movq %r9, 0x10(%rsp)
movl -0xc(%rax), %r8d
movl 0x8(%rax), %r10d
movq 0x8(%rsp), %rcx
movq 0x48(%rcx), %rax
movq 0x58(%rcx), %rcx
movq (%rcx,%r8,8), %rdi
movq %rdi, %rdx
shrq $0x20, %rdx
shlq $0x5, %rdx
andq %rbp, %rdi
je 0x1ef56
leaq (%rax,%rdx), %r9
addq $0x8, %r9
xorl %r13d, %r13d
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
xorl %esi, %esi
xorl %r15d, %r15d
cmpl %r10d, (%r9)
sete %r15b
cmovel %r13d, %r11d
addl %r15d, %esi
incq %r13
addq $0x20, %r9
cmpq %r13, %rdi
jne 0x1ef34
movl %r11d, %r11d
jmp 0x1ef5e
xorl %esi, %esi
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
cmpl $0x1, %esi
jne 0x1ef76
addq %rax, %rdx
shlq $0x5, %r11
addq %rdx, %r11
subq %rax, %r11
sarq $0x5, %r11
jmp 0x1ef83
xorl %r11d, %r11d
testl %esi, %esi
sete %r11b
orq $-0x2, %r11
movq %r10, %rdx
xorq $0x1, %rdx
movq (%rcx,%rdx,8), %rsi
movq %rsi, %rcx
shrq $0x20, %rcx
shlq $0x5, %rcx
andq %rbp, %rsi
je 0x1efeb
movq %r14, %rbp
movq %r12, %r14
leaq (%rax,%rcx), %rdi
addq $0x8, %rdi
xorl %r13d, %r13d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
xorl %edx, %edx
movl (%rdi), %r15d
xorl %r8d, %r15d
xorl %r12d, %r12d
cmpl $0x1, %r15d
sete %r12b
cmovel %r13d, %r9d
addl %r12d, %edx
incq %r13
addq $0x20, %rdi
cmpq %r13, %rsi
jne 0x1efb7
movl %r9d, %r13d
movq %r14, %r12
movq %rbp, %r14
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x1eff3
xorl %edx, %edx
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x1, %edx
jne 0x1f00b
addq %rax, %rcx
shlq $0x5, %r13
addq %rcx, %r13
subq %rax, %r13
sarq $0x5, %r13
jmp 0x1f018
xorl %r13d, %r13d
testl %edx, %edx
sete %r13b
orq $-0x2, %r13
testq %r11, %r11
js 0x1f075
testq %r13, %r13
js 0x1f075
movq %r11, %rcx
shlq $0x5, %rcx
movq %r13, %rdx
shlq $0x5, %rdx
movq 0x18(%rax,%rdx), %rdx
xorq 0x18(%rax,%rcx), %rdx
jns 0x1f165
movq 0x28(%rsp), %rax
testq %rax, %rax
movq (%rsp), %r8
movq 0x10(%rsp), %r9
je 0x1f08a
movsd (%rax,%r11,8), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, (%rax,%r11,8)
movsd (%rax,%r13,8), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, (%rax,%r13,8)
jmp 0x1f08a
leaq 0x13384(%rip), %rax     # 0x32400
cmpl $0x2, (%rax)
jge 0x1f09b
movq (%rsp), %r8
movq 0x10(%rsp), %r9
incl %ebx
cmpl 0xc(%r8), %ebx
jl 0x1eea2
jmp 0x1f121
movq 0x12f56(%rip), %rax     # 0x31ff8
movq (%rax), %rdi
movl %r8d, %eax
andl $0x1, %eax
leaq 0x95f8(%rip), %rsi      # 0x286aa
movsbl (%rax,%rsi), %edx
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rcx
movq %rcx, 0x20(%rsp)
movl %r8d, %eax
shrl %eax
shlq $0x6, %rax
movq 0x18(%rcx,%rax), %rcx
movl %r10d, %eax
andl $0x1, %eax
movsbl (%rax,%rsi), %r9d
movl %r10d, %r15d
shrl %r15d
shlq $0x6, %r15
subq $0x8, %rsp
leaq 0xabf2(%rip), %rsi      # 0x29ce4
xorl %eax, %eax
pushq %r13
pushq %r11
pushq 0x88(%rsp)
pushq %r10
movq 0x48(%rsp), %r10
pushq 0x18(%r10,%r15)
callq 0x2210
movsd 0x9fa8(%rip), %xmm2     # 0x290c0
addq $0x30, %rsp
jmp 0x1f081
movq 0x30(%rsp), %rcx
incq %rcx
movslq 0x8(%r12), %rax
cmpq %rax, %rcx
jl 0x1ed51
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xaaec(%rip), %rdi      # 0x29c39
leaq 0xab05(%rip), %rsi      # 0x29c59
leaq 0xab08(%rip), %rcx      # 0x29c63
movl $0x10, %edx
callq 0x2160
leaq 0xabcc(%rip), %rdi      # 0x29d38
leaq 0xaae6(%rip), %rsi      # 0x29c59
leaq 0xaae9(%rip), %rcx      # 0x29c63
movl $0x31, %edx
callq 0x2160
leaq 0xab41(%rip), %rdi      # 0x29ccc
leaq 0xaac7(%rip), %rsi      # 0x29c59
leaq 0xaaca(%rip), %rcx      # 0x29c63
movl $0x1c, %edx
callq 0x2160