// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movl %ecx, 0x34(%rsp)
movq %rdi, 0x28(%rsp)
movq %r8, %rax
movq %r9, 0x40(%rsp)
orq %r9, %rax
sete %al
testq %rsi, %rsi
je 0x1f18a
testb %al, %al
jne 0x1f18a
movq %r8, %r14
movl 0x8(%rsi), %r8d
testl %r8d, %r8d
jle 0x1f18a
xorl %edi, %edi
movq %rsi, 0x20(%rsp)
movl %edx, 0x1c(%rsp)
movq 0x18(%rsi), %rbx
imulq $0x68, %rdi, %rcx
movl 0xc(%rbx,%rcx), %r10d
testl %r10d, %r10d
jle 0x1f199
addq %rcx, %rbx
cmpl $0x0, 0x10(%rbx)
jle 0x1f199
movzbl 0x44(%rbx), %ecx
cmpl %edx, %ecx
jl 0x1f17b
movl 0x34(%rsp), %eax
cmpl %eax, 0x2c(%rbx)
jl 0x1f17b
movl %r8d, 0x30(%rsp)
movq %rdi, 0x38(%rsp)
movq 0x20(%rsi), %rdx
movslq 0x8(%rbx), %rcx
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rdi
leal -0x1(%r10), %r9d
leaq (%rcx,%rcx,4), %rcx
movq %rdx, %rax
movq %rcx, 0x8(%rsp)
leaq (%rdx,%rcx,4), %r8
shlq $0x2, %r9
leaq (%r9,%r9,4), %r9
movq %r10, 0x10(%rsp)
leaq (,%r10,4), %rcx
leaq (%rcx,%rcx,4), %r10
xorl %r11d, %r11d
xorl %ebp, %ebp
testq %r11, %r11
jne 0x1ee47
movq 0x28(%rsi), %rcx
movslq (%r8,%r11), %r15
shlq $0x4, %r15
movl (%rcx,%r15), %r13d
notl %r13d
movzbl 0xc(%rcx,%r15), %ebp
addl %r13d, %ebp
movl 0x8(%r8,%r11), %r13d
shrl %r13d
movq %r13, %rcx
shlq $0x6, %rcx
movl (%rdi,%rcx), %ecx
movl %ecx, %r15d
cmpq %r11, %r9
jne 0x1ee7d
movq 0x28(%rsi), %r15
movslq (%r8,%r11), %rdx
movslq 0x4(%r8,%r11), %r12
addq %rdx, %r12
shlq $0x4, %r12
movl -0x10(%r15,%r12), %r15d
incl %r15d
testq %r14, %r14
je 0x1eea4
addl %ebp, %r15d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
addsd (%r14,%r13,8), %xmm0
movsd %xmm0, (%r14,%r13,8)
addq $0x14, %r11
cmpq %r11, %r10
jne 0x1ee24
movq 0x8(%rsp), %r10
movslq 0x4(%rax,%r10,4), %rcx
testq %rcx, %rcx
jle 0x1f1d7
movq %rax, %r9
movq 0x10(%rsp), %rax
cmpl $0x1, %eax
movl 0x1c(%rsp), %edx
movq 0x38(%rsp), %rdi
movl 0x30(%rsp), %r8d
je 0x1f17b
movq 0x28(%rsi), %rdx
movslq (%r9,%r10,4), %rdi
addq %rcx, %rdi
shlq $0x4, %rdi
leaq (%rdx,%rdi), %r9
addq $-0x10, %r9
movl $0x1, %ebp
movq 0x20(%rsi), %rcx
movslq 0x8(%rbx), %rdx
movslq %ebp, %rdi
addq %rdx, %rdi
leaq (%rdi,%rdi,4), %rdx
leaq (%rcx,%rdx,4), %rcx
movslq 0x4(%rcx), %rdx
testq %rdx, %rdx
jle 0x1ef4e
movq 0x28(%rsi), %r10
movslq (%rcx), %rdi
addq %rdi, %rdx
shlq $0x4, %rdi
movq 0x8(%r9), %r8
xorq 0x8(%r10,%rdi), %r8
shrq $0x30, %r8
shlq $0x4, %rdx
leaq (%r10,%rdx), %r9
addq $-0x10, %r9
testb %r8b, %r8b
jne 0x1f079
movq %r9, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movl -0xc(%rcx), %r8d
movl 0x8(%rcx), %r10d
movq 0x28(%rsp), %rax
movq 0x48(%rax), %rcx
movq 0x58(%rax), %rdx
movq (%rdx,%r8,8), %r9
movq %r9, %rdi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %rdi
je 0x1efe1
shrq $0x20, %r9
shlq $0x5, %r9
leaq (%rcx,%r9), %rsi
leaq (%rcx,%r9), %r11
addq $0x8, %r11
xorl %r13d, %r13d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
xorl %r15d, %r15d
xorl %eax, %eax
cmpl %r10d, (%r11)
sete %al
cmovel %r13d, %r9d
addl %eax, %r15d
incq %r13
addq $0x20, %r11
cmpq %r13, %rdi
jne 0x1ef9e
testl %r15d, %r15d
je 0x1efe1
movq $-0x2, %r12
cmpl $0x1, %r15d
jne 0x1efe8
movl %r9d, %eax
shlq $0x5, %rax
addq %rax, %rsi
subq %rcx, %rsi
sarq $0x5, %rsi
movq %rsi, %r12
jmp 0x1efe8
movq $-0x1, %r12
movq %r10, %rax
xorq $0x1, %rax
movq (%rdx,%rax,8), %rsi
movq %rsi, %rdx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %rdx
je 0x1f053
shrq $0x20, %rsi
shlq $0x5, %rsi
leaq (%rcx,%rsi), %r13
leaq (%rcx,%rsi), %rdi
addq $0x8, %rdi
xorl %r15d, %r15d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %r9d, %r9d
movl (%rdi), %eax
xorl %r8d, %eax
xorl %r11d, %r11d
cmpl $0x1, %eax
sete %r11b
cmovel %r15d, %esi
addl %r11d, %r9d
incq %r15
addq $0x20, %rdi
cmpq %r15, %rdx
jne 0x1f01f
cmpl $0x1, %r9d
je 0x1f088
movq $-0x2, %r13
testl %r9d, %r9d
jne 0x1f05a
movq $-0x1, %r13
leaq 0x1339f(%rip), %rax     # 0x32400
cmpl $0x2, (%rax)
jge 0x1f0f7
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %r9
movq 0x20(%rsp), %rsi
incl %ebp
cmpl %eax, %ebp
jl 0x1eeff
jmp 0x1f16e
movl %esi, %eax
shlq $0x5, %rax
addq %rax, %r13
subq %rcx, %r13
sarq $0x5, %r13
testq %r12, %r12
js 0x1f05a
testq %r13, %r13
js 0x1f05a
movq %r12, %rax
shlq $0x5, %rax
movq %r13, %rdx
shlq $0x5, %rdx
movq 0x18(%rcx,%rdx), %rdx
xorq 0x18(%rcx,%rax), %rdx
jns 0x1f1b8
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x1f06a
movsd (%rax,%r12,8), %xmm0
movsd 0xa038(%rip), %xmm1     # 0x29110
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%r12,8)
movsd (%rax,%r13,8), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%r13,8)
jmp 0x1f06a
movq 0x12efa(%rip), %rax     # 0x31ff8
movq (%rax), %rdi
movl %r8d, %eax
andl $0x1, %eax
leaq 0x959c(%rip), %rsi      # 0x286aa
movsbl (%rax,%rsi), %edx
movq 0x28(%rsp), %rax
movq 0x10(%rax), %r15
movl %r8d, %eax
shrl %eax
shlq $0x6, %rax
movq 0x18(%r15,%rax), %rcx
movl %r10d, %eax
andl $0x1, %eax
movsbl (%rax,%rsi), %r9d
movl %r10d, %r11d
shrl %r11d
shlq $0x6, %r11
subq $0x8, %rsp
leaq 0xac2f(%rip), %rsi      # 0x29d78
xorl %eax, %eax
pushq %r13
pushq %r12
pushq 0x98(%rsp)
pushq %r10
pushq 0x18(%r15,%r11)
callq 0x2210
addq $0x30, %rsp
movl 0xc(%rbx), %eax
jmp 0x1f06f
movl 0x8(%rsi), %r8d
movl 0x1c(%rsp), %edx
movq 0x38(%rsp), %rdi
incq %rdi
movslq %r8d, %rax
cmpq %rax, %rdi
jl 0x1ed9d
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xab2d(%rip), %rdi      # 0x29ccd
leaq 0xab46(%rip), %rsi      # 0x29ced
leaq 0xab49(%rip), %rcx      # 0x29cf7
movl $0x10, %edx
callq 0x2160
leaq 0xac0d(%rip), %rdi      # 0x29dcc
leaq 0xab27(%rip), %rsi      # 0x29ced
leaq 0xab2a(%rip), %rcx      # 0x29cf7
movl $0x31, %edx
callq 0x2160
leaq 0xab82(%rip), %rdi      # 0x29d60
leaq 0xab08(%rip), %rsi      # 0x29ced
leaq 0xab0b(%rip), %rcx      # 0x29cf7
movl $0x1c, %edx
callq 0x2160