// File: /workspace/github_cpp_makefile_star2_O3/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, 0x38(%rsp)
movl 0x8(%rsi), %eax
testl %eax, %eax
jle 0x1a6377
xorl %r10d, %r10d
movq %rsi, 0x30(%rsp)
movq 0x18(%rsi), %rcx
leaq (%r10,%r10,8), %rdx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movq %rdi, 0x28(%rcx,%rdx,8)
movabsq $-0x4080000000000000, %rdi # imm = 0xBF80000000000000
movq %rdi, 0x30(%rcx,%rdx,8)
movaps 0x99a75(%rip), %xmm0    # 0x23fae0
movups %xmm0, 0x18(%rcx,%rdx,8)
movl 0xc(%rcx,%rdx,8), %edi
movq %rdi, 0x8(%rsp)
testq %rdi, %rdi
je 0x1a6368
leaq (%rcx,%rdx,8), %rbx
movq 0x20(%rsi), %rax
movslq 0x8(%rbx), %rcx
movq %rcx, %rdx
shlq $0x4, %rdx
cmpl $0x0, 0x4(%rax,%rdx)
jle 0x1a6386
addl 0x8(%rsp), %ecx
movslq %ecx, %rdi
shlq $0x4, %rdi
movslq -0xc(%rax,%rdi), %r9
testq %r9, %r9
jle 0x1a6386
movq %rdx, %r8
addq %rax, %r8
movq 0x28(%rsi), %r14
movq %r8, 0x60(%rsp)
movslq (%r8), %rcx
shlq $0x4, %rcx
movq 0x8(%r14,%rcx), %r8
movq %r8, %rdx
shrq $0x20, %rdx
movzbl %dl, %r11d
subl %r11d, %r8d
leal 0x1(%r8), %edx
movl %edx, 0x18(%rbx)
movq %r14, (%rsp)
movq (%r14,%rcx), %rdx
movl %edx, %ebp
subl %r11d, %ebp
incl %ebp
incl %r8d
movl %ebp, 0x24(%rbx)
js 0x1a63c4
testl %ebp, %ebp
js 0x1a63c4
addq %rdi, %rax
movslq -0x10(%rax), %rdi
addq %r9, %rdi
shlq $0x4, %rdi
movq (%rsp), %r9
movl -0x8(%r9,%rdi), %r8d
incl %r8d
movl %r8d, 0x1c(%rbx)
movq 0x38(%rsp), %r8
movq 0x20(%r8), %r8
movl -0x8(%rax), %eax
shrl %eax
movq %r8, 0x58(%rsp)
movl (%r8,%rax,8), %eax
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl %r8d, %eax
movq -0x10(%r9,%rdi), %r9
movl %r9d, %edi
notl %edi
addl %eax, %edi
movl %edi, 0x28(%rbx)
movl 0x10(%rbx), %eax
testl %eax, %eax
jle 0x1a63a5
movl %edi, 0x24(%rsp)
movl %eax, 0x1c(%rsp)
movl %ebp, 0x28(%rsp)
movl %r11d, 0x20(%rsp)
movq %r10, 0x40(%rsp)
shrq $0x20, %rdx
shrq $0x20, %r9
subl %edx, %r9d
incl %r9d
cmpl $0x0, 0x8(%rsp)
jle 0x1a6304
movq (%rsp), %rax
addq %rax, %rcx
addq $-0x10, %rax
movq %rax, 0x48(%rsp)
xorl %edx, %edx
xorl %ebp, %ebp
xorl %r15d, %r15d
xorl %r10d, %r10d
xorl %r11d, %r11d
movq %rbx, 0x50(%rsp)
movq %r15, %rax
shlq $0x4, %rax
movq 0x60(%rsp), %rdi
leaq (%rdi,%rax), %r14
movl 0x8(%rdi,%rax), %esi
shrl %esi
movq 0x58(%rsp), %r8
movl (%r8,%rsi,8), %r8d
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %r8d
addl %r8d, %r10d
movl %r10d, 0x20(%rbx)
movslq 0x4(%rdi,%rax), %r13
testq %r13, %r13
jle 0x1a62d6
movl %r8d, 0x2c(%rsp)
movl %r10d, 0x10(%rsp)
movq %r14, 0x68(%rsp)
movslq (%r14), %rdi
movq %r11, 0x70(%rsp)
leal 0x1(%r11), %esi
movq 0x8(%rcx), %rax
shlq $0x4, %rdi
addq (%rsp), %rdi
xorl %r11d, %r11d
movq %rcx, %r8
movq %rax, %r14
movq %rdi, %rcx
movq 0x8(%rdi), %rax
movq %rax, %rdi
shrq $0x20, %rdi
movzbl %dil, %ebx
movl %r11d, %edi
orl %r15d, %edi
je 0x1a6257
testq %r15, %r15
sete %dil
testq %r11, %r11
setne %r12b
movq (%rcx), %r10
orb %dil, %r12b
jne 0x1a625e
leal (%rsi,%r10), %r12d
jmp 0x1a6267
movl %ebx, %r12d
movl %ebx, %edi
jmp 0x1a627b
movl (%r8), %edi
movl %r10d, %r12d
subl %edi, %r12d
movl %eax, %edi
subl %r14d, %edi
jns 0x1a627b
negl %edi
shrq $0x20, %r10
addl 0x4(%r8), %r9d
subl %r10d, %r9d
cmpl %edi, %r12d
movl %edi, %r8d
cmovgl %r12d, %r8d
movl %edi, %r10d
cmovll %r12d, %r10d
addl %r8d, %ebp
cmpl %ebx, %edi
movl %r10d, %edi
cmoval %ebx, %edi
cmpl %ebx, %r12d
cmovlel %r10d, %edi
addl %edi, %edx
incq %r11
leaq 0x10(%rcx), %rdi
cmpq %r11, %r13
jne 0x1a621b
movq 0x50(%rsp), %rbx
movl %ebp, 0x2c(%rbx)
movl %edx, 0x30(%rbx)
addq $-0x10, %rdi
movq %rdi, %rcx
movl 0x10(%rsp), %r10d
movq 0x70(%rsp), %r11
movl 0x2c(%rsp), %r8d
movq 0x68(%rsp), %r14
testl %r13d, %r13d
je 0x1a62f1
movslq (%r14), %rax
addq %r13, %rax
shlq $0x4, %rax
movq 0x48(%rsp), %rsi
movl (%rsi,%rax), %r11d
notl %r11d
addl %r8d, %r11d
incq %r15
cmpq 0x8(%rsp), %r15
jne 0x1a61b5
jmp 0x1a6307
xorl %r10d, %r10d
subl 0x24(%rsp), %r10d
movl %r10d, 0x28(%rbx)
cmpl 0x28(%rsp), %r10d
jl 0x1a63e3
cvtsi2sdl 0x20(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movl 0x1c(%rsp), %ecx
cmpl %ecx, %r9d
movl %ecx, %eax
cmovgl %r9d, %eax
cmovll %r9d, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
callq 0x2150
divsd 0x10(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x34(%rbx)
movq 0x30(%rsp), %rsi
movl 0x8(%rsi), %eax
movq 0x40(%rsp), %r10
incq %r10
movslq %eax, %rcx
cmpq %rcx, %r10
jl 0x1a6043
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x99bc2(%rip), %rdi     # 0x23ff4f
leaq 0x998c7(%rip), %rsi     # 0x23fc5b
leaq 0x99bf2(%rip), %rcx     # 0x23ff8d
movl $0x746, %edx            # imm = 0x746
callq 0x2110
leaq 0x99c2e(%rip), %rdi     # 0x23ffda
leaq 0x998a8(%rip), %rsi     # 0x23fc5b
leaq 0x99bd3(%rip), %rcx     # 0x23ff8d
movl $0x755, %edx            # imm = 0x755
callq 0x2110
leaq 0x99bf6(%rip), %rdi     # 0x23ffc1
leaq 0x99889(%rip), %rsi     # 0x23fc5b
leaq 0x99bb4(%rip), %rcx     # 0x23ff8d
movl $0x750, %edx            # imm = 0x750
callq 0x2110
leaq 0x99c00(%rip), %rdi     # 0x23ffea
leaq 0x9986a(%rip), %rsi     # 0x23fc5b
leaq 0x99b95(%rip), %rcx     # 0x23ff8d
movl $0x771, %edx            # imm = 0x771
callq 0x2110