// File: /workspace/github_cpp_makefile_star2_O1/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)
cmpl $0x0, 0x8(%rsi)
jle 0x19d6e8
xorl %r9d, %r9d
movq %rsi, 0x38(%rsp)
movq 0x18(%rsi), %rax
leaq (%r9,%r9,8), %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rdx, 0x28(%rax,%rcx,8)
movq $-0x1, 0x18(%rax,%rcx,8)
movabsq $-0x4080000000000000, %rdx # imm = 0xBF80000000000000
movq %rdx, 0x30(%rax,%rcx,8)
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
movq %rdx, 0x20(%rax,%rcx,8)
movl 0xc(%rax,%rcx,8), %edx
movq %rdx, 0x10(%rsp)
testq %rdx, %rdx
je 0x19d6d8
leaq (%rax,%rcx,8), %rbx
movq 0x20(%rsi), %rax
movslq 0x8(%rbx), %rdx
movq %rdx, %rcx
shlq $0x4, %rcx
cmpl $0x0, 0x4(%rax,%rcx)
jle 0x19d6f7
movq %rcx, %rdi
movslq 0x10(%rsp), %rcx
addq %rcx, %rdx
shlq $0x4, %rdx
movslq -0xc(%rax,%rdx), %r8
testq %r8, %r8
jle 0x19d6f7
addq %rax, %rdi
movq 0x28(%rsi), %r14
movq %rdi, 0x68(%rsp)
movslq (%rdi), %r11
shlq $0x4, %r11
movq 0x8(%r14,%r11), %rdi
movq %rdi, %rcx
shrq $0x20, %rcx
movzbl %cl, %r10d
subl %r10d, %edi
leal 0x1(%rdi), %ecx
movl %ecx, 0x18(%rbx)
movq %r14, 0x8(%rsp)
movq (%r14,%r11), %rcx
movl %ecx, %ebp
subl %r10d, %ebp
incl %ebp
incl %edi
movl %ebp, 0x24(%rbx)
js 0x19d735
testl %ebp, %ebp
js 0x19d735
addq %rdx, %rax
movslq -0x10(%rax), %rdx
addq %r8, %rdx
shlq $0x4, %rdx
movq 0x8(%rsp), %r8
movl -0x8(%r8,%rdx), %edi
incl %edi
movl %edi, 0x1c(%rbx)
movq 0x40(%rsp), %rdi
movq 0x20(%rdi), %rdi
movl -0x8(%rax), %eax
shrl %eax
movq %rdi, 0x60(%rsp)
movl (%rdi,%rax,8), %eax
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andl %edi, %eax
movq -0x10(%r8,%rdx), %r8
movl %r8d, %edx
notl %edx
addl %eax, %edx
movl %edx, 0x28(%rbx)
movl 0x10(%rbx), %eax
testl %eax, %eax
jle 0x19d716
movl %edx, 0x2c(%rsp)
movl %eax, 0x24(%rsp)
movl %ebp, 0x30(%rsp)
movl %r10d, 0x28(%rsp)
movq %r9, 0x48(%rsp)
shrq $0x20, %rcx
shrq $0x20, %r8
subl %ecx, %r8d
incl %r8d
cmpl $0x0, 0x10(%rsp)
jle 0x19d67a
movq 0x8(%rsp), %rax
addq %rax, %r11
addq $-0x10, %rax
movq %rax, 0x50(%rsp)
movl 0x20(%rbx), %r9d
xorl %edx, %edx
xorl %r12d, %r12d
movq %rbx, 0x58(%rsp)
movq %rdx, %rax
shlq $0x4, %rax
movq 0x68(%rsp), %rsi
leaq (%rsi,%rax), %r10
movl 0x8(%rsi,%rax), %ecx
shrl %ecx
movq 0x60(%rsp), %rdi
movl (%rdi,%rcx,8), %edi
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %edi
addl %edi, %r9d
movl %r9d, 0x20(%rbx)
movslq 0x4(%rsi,%rax), %r14
testq %r14, %r14
jle 0x19d64e
movl %edi, 0x34(%rsp)
movl %r9d, 0x18(%rsp)
movq %r10, 0x70(%rsp)
movslq (%r10), %rcx
leal 0x1(%r12), %esi
movl 0x2c(%rbx), %ebp
movl 0x30(%rbx), %edi
shlq $0x4, %rcx
addq 0x8(%rsp), %rcx
xorl %eax, %eax
movq %rcx, %r10
movq 0x8(%rcx), %rbx
movq %rbx, %rcx
shrq $0x20, %rcx
movzbl %cl, %r9d
movl %eax, %ecx
orl %edx, %ecx
movl %r9d, %ecx
movl %r9d, %r13d
je 0x19d5e4
movl %ebx, %r13d
movl (%r10), %ecx
subl 0x8(%r11), %r13d
testq %rdx, %rdx
sete %bl
testq %rax, %rax
setne %r15b
orb %bl, %r15b
jne 0x19d5e1
addl %esi, %ecx
jmp 0x19d5e4
subl (%r11), %ecx
testl %r13d, %r13d
jns 0x19d5f4
negl %r13d
addl 0x4(%r11), %r8d
subl 0x4(%r10), %r8d
cmpl %r13d, %ecx
movl %r13d, %r11d
cmovgl %ecx, %r11d
movl %r13d, %ebx
cmovll %ecx, %ebx
addl %r11d, %ebp
cmpl %r9d, %r13d
movl %ebx, %r11d
cmovgl %r9d, %r11d
cmpl %r9d, %ecx
cmovlel %ebx, %r11d
addl %r11d, %edi
incq %rax
leaq 0x10(%r10), %rcx
movq %r10, %r11
cmpq %rax, %r14
jne 0x19d5a3
movq 0x58(%rsp), %rbx
movl %ebp, 0x2c(%rbx)
movl %edi, 0x30(%rbx)
addq $-0x10, %rcx
movq %rcx, %r11
movl 0x18(%rsp), %r9d
movl 0x34(%rsp), %edi
movq 0x70(%rsp), %r10
testl %r14d, %r14d
je 0x19d669
movslq (%r10), %rax
addq %r14, %rax
shlq $0x4, %rax
movq 0x50(%rsp), %rcx
movl (%rcx,%rax), %r12d
notl %r12d
addl %edi, %r12d
incq %rdx
cmpq 0x10(%rsp), %rdx
jne 0x19d542
movl 0x20(%rbx), %eax
subl 0x2c(%rsp), %eax
movl %eax, 0x28(%rbx)
cmpl 0x30(%rsp), %eax
jl 0x19d754
cvtsi2sdl 0x28(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movl 0x24(%rsp), %ecx
cmpl %ecx, %r8d
movl %ecx, %eax
cmovgl %r8d, %eax
cmovll %r8d, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
callq 0x2150
divsd 0x18(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x34(%rbx)
movq 0x38(%rsp), %rsi
movq 0x48(%rsp), %r9
incq %r9
movslq 0x8(%rsi), %rax
cmpq %rax, %r9
jl 0x19d3cb
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x96581(%rip), %rdi     # 0x233c7f
leaq 0x96286(%rip), %rsi     # 0x23398b
leaq 0x965b1(%rip), %rcx     # 0x233cbd
movl $0x746, %edx            # imm = 0x746
callq 0x2110
leaq 0x965ed(%rip), %rdi     # 0x233d0a
leaq 0x96267(%rip), %rsi     # 0x23398b
leaq 0x96592(%rip), %rcx     # 0x233cbd
movl $0x755, %edx            # imm = 0x755
callq 0x2110
leaq 0x965b5(%rip), %rdi     # 0x233cf1
leaq 0x96248(%rip), %rsi     # 0x23398b
leaq 0x96573(%rip), %rcx     # 0x233cbd
movl $0x750, %edx            # imm = 0x750
callq 0x2110
leaq 0x965bf(%rip), %rdi     # 0x233d1a
leaq 0x96229(%rip), %rsi     # 0x23398b
leaq 0x96554(%rip), %rcx     # 0x233cbd
movl $0x771, %edx            # imm = 0x771
callq 0x2110