// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: mg_gchain_extra(asg_t const*, mg_gchains_t*)
void mg_gchain_extra(const asg_t *g, mg_gchains_t *gs)
{
	int32_t i, j, k;
	for (i = 0; i < gs->n_gc; ++i) { // iterate over gchains
		mg_gchain_t *p = &gs->gc[i];
		const mg_llchain_t *q;
		const mg128_t *last_a;
		int32_t q_span, rest_pl, tmp, n_mini;

		p->qs = p->qe = p->ps = p->pe = -1, p->plen = p->blen = p->mlen = 0, p->div = -1.0f;
		if (p->cnt == 0) continue;
		///some linear chains in middle might be [].cnt == 0
		///but for the first and the last linear chains, [].cnt > 0
		assert(gs->lc[p->off].cnt > 0 && gs->lc[p->off + p->cnt - 1].cnt > 0); // first and last lchains can't be empty
		q = &gs->lc[p->off];
		q_span = (int32_t)(gs->a[q->off].y>>32&0xff);
		/**
		 * a[].x: idx_in_minimizer_arr(32)r_pos(32)
 		 * a[].y: weight(8)query_id(8)flag(8)span(8)q_pos(32)
		 * **/
		p->qs = (int32_t)gs->a[q->off].y + 1 - q_span;///calculated by the first lchain
		p->ps = (int32_t)gs->a[q->off].x + 1 - q_span;///calculated by the first lchain
		tmp = (int32_t)(gs->a[q->off].x>>32);
		assert(p->qs >= 0 && p->ps >= 0);
		q = &gs->lc[p->off + p->cnt - 1];///last lchain
		p->qe = (int32_t)gs->a[q->off + q->cnt - 1].y + 1;
		p->pe = g->seq[q->v>>1].len - (int32_t)gs->a[q->off + q->cnt - 1].x - 1; // this is temporary
		n_mini = (int32_t)(gs->a[q->off + q->cnt - 1].x>>32) - tmp + 1;
		assert(p->n_anchor > 0);

		rest_pl = 0; // this value is never used if the first lchain is not empty (which should always be true)
		last_a = &gs->a[gs->lc[p->off].off];///first minizers in the first linear chain
		for (j = 0; j < p->cnt; ++j) { // iterate over lchains
			const mg_llchain_t *q = &gs->lc[p->off + j];
			int32_t vlen = g->seq[q->v>>1].len;///node length in graph
			p->plen += vlen;
			for (k = 0; k < q->cnt; ++k) { // iterate over anchors
				const mg128_t *r = &gs->a[q->off + k];
				int32_t pl, ql = (int32_t)r->y - (int32_t)last_a->y;
				int32_t span = (int32_t)(r->y>>32&0xff);
				if (j == 0 && k == 0) { // the first anchor on the first lchain
					pl = ql = span;
				} else if (j > 0 && k == 0) { // the first anchor but not on the first lchain
					pl = (int32_t)r->x + 1 + rest_pl;
				} else {
					pl = (int32_t)r->x - (int32_t)last_a->x;
				}
				if (ql < 0) ql = -ql, n_mini += (int32_t)(last_a->x>>32) - (int32_t)(r->x>>32); // dealing with overlapping query at junctions
				p->blen += pl > ql? pl : ql;
				p->mlen += pl > span && ql > span? span : pl < ql? pl : ql;
				last_a = r;
			}
			if (q->cnt == 0) rest_pl += vlen;
			else rest_pl = vlen - (int32_t)gs->a[q->off + q->cnt - 1].x - 1;
		}
		p->pe = p->plen - p->pe;
		assert(p->pe >= p->ps);
		// here n_mini >= p->n_anchor should stand almost all the time
		p->div = n_mini >= p->n_anchor? log((double)n_mini / p->n_anchor) / q_span : log((double)p->n_anchor / n_mini) / q_span;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, 0x40(%rsp)
xorl %r10d, %r10d
movq %rsi, 0x38(%rsp)
movslq 0x8(%rsi), %rax
cmpq %rax, %r10
jge 0x15e9e9
movq 0x18(%rsi), %r12
imulq $0x48, %r10, %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, 0x28(%r12,%rax)
movabsq $-0x4080000000000000, %rcx # imm = 0xBF80000000000000
movq %rcx, 0x30(%r12,%rax)
movaps 0x932bc(%rip), %xmm0    # 0x1f19a0
movups %xmm0, 0x18(%r12,%rax)
movl 0xc(%r12,%rax), %ecx
testl %ecx, %ecx
je 0x15e9e1
movq %rcx, %r11
addq %rax, %r12
movq 0x20(%rsi), %rax
movslq 0x8(%r12), %rcx
movq %rcx, %rdx
shlq $0x4, %rdx
cmpl $0x0, 0x4(%rax,%rdx)
jle 0x15e9f8
addl %r11d, %ecx
movslq %ecx, %rdi
shlq $0x4, %rdi
movslq -0xc(%rax,%rdi), %r9
testq %r9, %r9
jle 0x15e9f8
movq %rdx, %r8
addq %rax, %r8
movq 0x28(%rsi), %rdx
movq %r8, 0x60(%rsp)
movslq (%r8), %r15
shlq $0x4, %r15
movq 0x8(%rdx,%r15), %r8
movq %r8, %rcx
shrq $0x20, %rcx
movzbl %cl, %ebx
subl %ebx, %r8d
leal 0x1(%r8), %ecx
movl %ecx, 0x18(%r12)
movq (%rdx,%r15), %rcx
movl %ecx, %ebp
subl %ebx, %ebp
incl %ebp
incl %r8d
movl %ebp, 0x24(%r12)
js 0x15ea17
testl %ebp, %ebp
js 0x15ea17
movl %ebx, 0x24(%rsp)
movq %r10, 0x48(%rsp)
addq %rdi, %rax
movslq -0x10(%rax), %rdi
addq %r9, %rdi
shlq $0x4, %rdi
movl -0x8(%rdx,%rdi), %esi
incl %esi
movl %esi, 0x1c(%r12)
movq 0x40(%rsp), %rsi
movq 0x20(%rsi), %rsi
movl -0x8(%rax), %eax
shrl %eax
movq %rsi, 0x58(%rsp)
movl (%rsi,%rax,8), %eax
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %eax
movq -0x10(%rdx,%rdi), %rsi
movl %esi, %edi
notl %edi
addl %eax, %edi
movl %edi, 0x28(%rsp)
movl %edi, 0x28(%r12)
movl 0x10(%r12), %eax
movl %eax, 0x20(%rsp)
testl %eax, %eax
jle 0x15ea36
addq %rdx, %r15
shrq $0x20, %rcx
shrq $0x20, %rsi
subl %ecx, %esi
incl %esi
movq %rsi, 0x18(%rsp)
leaq -0x10(%rdx), %rax
movq %rax, 0x50(%rsp)
xorl %ebx, %ebx
testl %r11d, %r11d
cmovlel %ebx, %r11d
movq %r11, 0x68(%rsp)
xorl %esi, %esi
xorl %r10d, %r10d
xorl %r9d, %r9d
movq $0x0, 0x8(%rsp)
movl %ebp, 0x2c(%rsp)
cmpq 0x68(%rsp), %r9
je 0x15e983
movq %r9, %rax
shlq $0x4, %rax
movq 0x60(%rsp), %rdi
leaq (%rdi,%rax), %r13
movl 0x8(%rdi,%rax), %ecx
shrl %ecx
movq 0x58(%rsp), %r8
movl (%r8,%rcx,8), %r8d
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %r8d
movl %r8d, 0x30(%rsp)
addl %r8d, %r10d
movl %r10d, 0x34(%rsp)
movl %r10d, 0x20(%r12)
movslq 0x4(%rdi,%rax), %rcx
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x10(%rsp)
testl %ecx, %ecx
movl $0x0, %r10d
movq %rcx, 0x70(%rsp)
cmovgl %ecx, %r10d
xorl %ecx, %ecx
cmpl %ecx, %r10d
je 0x15e941
movslq (%r13), %rax
addq %rcx, %rax
shlq $0x4, %rax
leaq (%rdx,%rax), %r11
movq 0x8(%rdx,%rax), %rdi
movq %rdi, %rax
shrq $0x20, %rax
movzbl %al, %r14d
movl %ecx, %eax
orl %r9d, %eax
je 0x15e8dc
testq %r9, %r9
sete %bpl
testl %ecx, %ecx
setne %r8b
movq (%r11), %rax
orb %bpl, %r8b
jne 0x15e8e4
movq 0x10(%rsp), %r8
leal (%r8,%rax), %ebp
jmp 0x15e8ec
movl %r14d, %ebp
movl %r14d, %edi
jmp 0x15e909
movl (%r15), %r8d
movl %eax, %ebp
subl %r8d, %ebp
subl 0x8(%r15), %edi
jns 0x15e909
negl %edi
shrq $0x20, %rax
movq 0x18(%rsp), %r8
addl 0x4(%r15), %r8d
subl %eax, %r8d
movq %r8, 0x18(%rsp)
cmpl %edi, %ebp
movl %edi, %eax
cmovgl %ebp, %eax
movl %edi, %r8d
cmovll %ebp, %r8d
addl %eax, %esi
cmpl %r14d, %edi
movl %r8d, %eax
cmoval %r14d, %eax
movl %esi, 0x2c(%r12)
cmpl %r14d, %ebp
cmovlel %r8d, %eax
addl %eax, %ebx
movl %ebx, 0x30(%r12)
incq %rcx
movq %r11, %r15
jmp 0x15e88d
movq 0x70(%rsp), %rcx
testl %ecx, %ecx
je 0x15e964
movslq (%r13), %rax
addq %rcx, %rax
shlq $0x4, %rax
movq 0x50(%rsp), %rcx
movl (%rcx,%rax), %eax
notl %eax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
addl 0x30(%rsp), %eax
movq %rax, 0x8(%rsp)
incq %r9
movl 0x2c(%rsp), %ebp
movl 0x34(%rsp), %r10d
jmp 0x15e825
subl 0x28(%rsp), %r10d
movl %r10d, 0x28(%r12)
cmpl %ebp, %r10d
jl 0x15ea55
cvtsi2sdl 0x24(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x18(%rsp), %rcx
movl 0x20(%rsp), %edx
cmpl %edx, %ecx
movl %edx, %eax
cmovgl %ecx, %eax
cmovll %ecx, %edx
cvtsi2sd %eax, %xmm0
cvtsi2sd %edx, %xmm1
divsd %xmm1, %xmm0
callq 0x2150
divsd 0x10(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x34(%r12)
movq 0x38(%rsp), %rsi
movq 0x48(%rsp), %r10
incq %r10
jmp 0x15e6af
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x93418(%rip), %rdi     # 0x1f1e17
leaq 0x9311d(%rip), %rsi     # 0x1f1b23
leaq 0x93448(%rip), %rcx     # 0x1f1e55
movl $0x746, %edx            # imm = 0x746
callq 0x2110
leaq 0x9346b(%rip), %rdi     # 0x1f1e89
leaq 0x930fe(%rip), %rsi     # 0x1f1b23
leaq 0x93429(%rip), %rcx     # 0x1f1e55
movl $0x750, %edx            # imm = 0x750
callq 0x2110
leaq 0x93465(%rip), %rdi     # 0x1f1ea2
leaq 0x930df(%rip), %rsi     # 0x1f1b23
leaq 0x9340a(%rip), %rcx     # 0x1f1e55
movl $0x755, %edx            # imm = 0x755
callq 0x2110
leaq 0x93456(%rip), %rdi     # 0x1f1eb2
leaq 0x930c0(%rip), %rsi     # 0x1f1b23
leaq 0x933eb(%rip), %rcx     # 0x1f1e55
movl $0x771, %edx            # imm = 0x771
callq 0x2110