// File: /workspace/github_c_makefile_star2_O2/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, 0x28(%rsp)
movl %edx, 0x2c(%rsp)
movq %rdi, 0x10(%rsp)
movq %r8, %rax
orq %r9, %rax
sete %al
movq %rsi, 0x8(%rsp)
testq %rsi, %rsi
je 0x1b5ba
testb %al, %al
jne 0x1b5ba
movq 0x8(%rsp), %rax
movl 0x8(%rax), %eax
testl %eax, %eax
je 0x1b5ba
xorl %edx, %edx
movq %r9, 0x40(%rsp)
movq %r8, 0x30(%rsp)
movslq %eax, %rcx
cmpq %rcx, %rdx
jge 0x1b5ba
movq 0x8(%rsp), %rcx
movq 0x18(%rcx), %r13
movq %rdx, 0x38(%rsp)
imulq $0x68, %rdx, %rcx
movl 0xc(%r13,%rcx), %r14d
testl %r14d, %r14d
jle 0x1b5e2
addq %rcx, %r13
cmpl $0x0, 0x10(%r13)
jle 0x1b5e2
movzbl 0x44(%r13), %ecx
cmpl 0x2c(%rsp), %ecx
jl 0x1b5ad
movl 0x28(%rsp), %ecx
cmpl %ecx, 0x2c(%r13)
jl 0x1b5ad
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rax
movl 0x8(%r13), %ecx
movq 0x10(%rsp), %rdx
movq 0x10(%rdx), %rdx
xorl %esi, %esi
movl %r14d, %ebp
addl %esi, %ebp
je 0x1b3c0
movslq %ecx, %rdi
imulq $0x14, %rdi, %r15
leaq (%rax,%r15), %r10
xorl %edi, %edi
subl $0x1, %esi
jae 0x1b360
movq 0x8(%rsp), %rdi
movq 0x28(%rdi), %rdi
movslq (%r10), %r11
shlq $0x4, %r11
movl (%rdi,%r11), %ebx
notl %ebx
movzbl 0xc(%rdi,%r11), %edi
addl %ebx, %edi
movl 0x8(%rax,%r15), %r12d
shrl %r12d
movq %r12, %r11
shlq $0x6, %r11
movl (%rdx,%r11), %r11d
movl %r11d, %ebx
cmpl $0x1, %ebp
jne 0x1b399
movq 0x8(%rsp), %rbx
movq 0x28(%rbx), %r15
movslq (%r10), %rbx
movslq 0x4(%r10), %r10
addq %rbx, %r10
shlq $0x4, %r10
movl -0x10(%r15,%r10), %ebx
incl %ebx
testq %r8, %r8
je 0x1b3b9
addl %edi, %ebx
cvtsi2sd %ebx, %xmm0
cvtsi2sd %r11d, %xmm1
divsd %xmm1, %xmm0
addsd (%r8,%r12,8), %xmm0
movsd %xmm0, (%r8,%r12,8)
incl %ecx
jmp 0x1b325
movq 0x8(%rsp), %r8
movq 0x20(%r8), %rax
movslq 0x8(%r13), %rcx
imulq $0x14, %rcx, %rdx
movslq 0x4(%rax,%rdx), %rcx
testq %rcx, %rcx
jle 0x1b5ff
addq %rdx, %rax
movq 0x28(%r8), %rdx
movslq (%rax), %rax
addq %rcx, %rax
shlq $0x4, %rax
leaq (%rdx,%rax), %r10
addq $-0x10, %r10
pushq $0x1
popq %r12
movq 0x10(%rsp), %rdi
movq %r13, 0x20(%rsp)
cmpl %r14d, %r12d
jge 0x1b5a4
movq 0x20(%r8), %rcx
movslq 0x8(%r13), %rax
addq %r12, %rax
imulq $0x14, %rax, %rdx
leaq (%rcx,%rdx), %rax
movslq 0x4(%rcx,%rdx), %rcx
testq %rcx, %rcx
jle 0x1b45c
movq 0x28(%r8), %rdx
movslq (%rax), %rsi
addq %rsi, %rcx
shlq $0x4, %rsi
movq 0x8(%r10), %r9
xorq 0x8(%rdx,%rsi), %r9
shrq $0x30, %r9
shlq $0x4, %rcx
leaq (%rdx,%rcx), %r10
addq $-0x10, %r10
testb %r9b, %r9b
jne 0x1b517
movq %r10, 0x18(%rsp)
movl -0xc(%rax), %ebx
movl 0x8(%rax), %r15d
movl %ebx, %esi
movl %r15d, %edx
movq %rdi, %r13
callq 0x1b618
movq %rax, %rbp
movl %r15d, %esi
xorl $0x1, %esi
movl %ebx, %edx
xorl $0x1, %edx
movq %r13, %rdi
callq 0x1b618
movq %rax, %r10
movq %rbp, %rax
orq %r10, %rax
jns 0x1b4b3
leaq 0x12f63(%rip), %rax     # 0x2e400
cmpl $0x2, (%rax)
movq 0x20(%rsp), %r13
jge 0x1b51f
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %rdi
jmp 0x1b512
movq 0x48(%r13), %rax
movq %rbp, %rcx
shlq $0x5, %rcx
movq %r10, %rdx
shlq $0x5, %rdx
movq 0x18(%rax,%rdx), %rdx
xorq 0x18(%rax,%rcx), %rdx
jns 0x1b5c9
movq %r13, %rdi
movq 0x40(%rsp), %rax
testq %rax, %rax
movq 0x8(%rsp), %r8
movq 0x20(%rsp), %r13
je 0x1b512
movsd (%rax,%rbp,8), %xmm0
movsd 0x8c27(%rip), %xmm1     # 0x24120
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rbp,8)
movsd (%rax,%r10,8), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%r10,8)
movq 0x18(%rsp), %r10
incq %r12
jmp 0x1b406
movq 0x12ad2(%rip), %rax     # 0x2dff8
movq (%rax), %rdi
movl %ebx, %eax
andl $0x1, %eax
leaq 0x817e(%rip), %rsi      # 0x236b3
movsbl (%rax,%rsi), %edx
movq 0x10(%rsp), %r14
movq 0x10(%r14), %r11
movl %ebx, %eax
shrl %eax
shlq $0x6, %rax
movq 0x18(%r11,%rax), %rcx
movl %r15d, %eax
andl $0x1, %eax
movsbl (%rax,%rsi), %r9d
movl %r15d, %r13d
shrl %r13d
shlq $0x6, %r13
subq $0x8, %rsp
leaq 0x97f5(%rip), %rsi      # 0x24d64
movl %ebx, %r8d
xorl %eax, %eax
pushq %r10
pushq %rbp
pushq 0x98(%rsp)
pushq %r15
pushq 0x18(%r11,%r13)
callq 0x2210
movq %r14, %rdi
movq 0x50(%rsp), %r13
addq $0x30, %rsp
movl 0xc(%r13), %r14d
movq 0x8(%rsp), %r8
jmp 0x1b512
movl 0x8(%r8), %eax
movq 0x30(%rsp), %r8
movq 0x38(%rsp), %rdx
incq %rdx
jmp 0x1b2b6
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x97e8(%rip), %rdi      # 0x24db8
leaq 0x9702(%rip), %rsi      # 0x24cd9
leaq 0x9705(%rip), %rcx      # 0x24ce3
pushq $0x31
jmp 0x1b5f9
leaq 0x96d0(%rip), %rdi      # 0x24cb9
leaq 0x96e9(%rip), %rsi      # 0x24cd9
leaq 0x96ec(%rip), %rcx      # 0x24ce3
pushq $0x10
popq %rdx
callq 0x2160
leaq 0x9746(%rip), %rdi      # 0x24d4c
leaq 0x96cc(%rip), %rsi      # 0x24cd9
leaq 0x96cf(%rip), %rcx      # 0x24ce3
pushq $0x1c
jmp 0x1b5f9