// File: /workspace/github_c_makefile_star2_O3/lh3[P]minigraph/gchain1.c
// Function: mg_gchain_extra
void mg_gchain_extra(const gfa_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;

		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);
		p->qs = (int32_t)gs->a[q->off].y + 1 - q_span;
		p->ps = (int32_t)gs->a[q->off].x + 1 - q_span;
		tmp = (int32_t)(gs->a[q->off].x>>32);
		assert(p->qs >= 0 && p->ps >= 0);
		q = &gs->lc[p->off + p->cnt - 1];
		p->qe = (int32_t)gs->a[q->off + q->cnt - 1].y + 1;
		p->pe = g->seg[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];
		for (j = 0; j < p->cnt; ++j) { // iterate over lchains
			const mg_llchain_t *q = &gs->lc[p->off + j];
			int32_t vlen = g->seg[q->v>>1].len;
			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 0x19e08
movq %rsi, %rbx
xorl %r14d, %r14d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movq %rsi, 0x30(%rsp)
movq 0x18(%rbx), %r12
imulq $0x68, %r14, %rcx
movq %r15, 0x28(%r12,%rcx)
movabsq $-0x4080000000000000, %rdx # imm = 0xBF80000000000000
movq %rdx, 0x30(%r12,%rcx)
movaps 0xf9ae(%rip), %xmm0     # 0x294a0
movups %xmm0, 0x18(%r12,%rcx)
movl 0xc(%r12,%rcx), %edx
movq %rdx, 0x8(%rsp)
testq %rdx, %rdx
je 0x19df9
addq %rcx, %r12
movq 0x20(%rbx), %rcx
movslq 0x8(%r12), %rdx
leaq (%rdx,%rdx,4), %rax
cmpl $0x0, 0x4(%rcx,%rax,4)
jle 0x19e17
addl 0x8(%rsp), %edx
movslq %edx, %rdx
leaq (%rdx,%rdx,4), %rsi
movslq -0x10(%rcx,%rsi,4), %rdx
testq %rdx, %rdx
jle 0x19e17
leaq (%rcx,%rax,4), %rax
movq 0x28(%rbx), %r9
movq %rax, 0x60(%rsp)
movslq (%rax), %rbp
shlq $0x4, %rbp
movq 0x8(%r9,%rbp), %rdi
movq %rdi, %rax
shrq $0x20, %rax
movzbl %al, %r8d
subl %r8d, %edi
leal 0x1(%rdi), %eax
movl %eax, 0x18(%r12)
movq %r9, (%rsp)
movq (%r9,%rbp), %rax
movl %eax, %r10d
subl %r8d, %r10d
incl %r10d
incl %edi
movl %r10d, 0x24(%r12)
js 0x19e55
testl %r10d, %r10d
js 0x19e55
leaq (%rcx,%rsi,4), %rcx
movslq -0x14(%rcx), %rsi
addq %rdx, %rsi
shlq $0x4, %rsi
movq (%rsp), %rdi
movl -0x8(%rdi,%rsi), %edx
incl %edx
movl %edx, 0x1c(%r12)
movq 0x38(%rsp), %rdx
movq 0x10(%rdx), %r11
movl -0xc(%rcx), %ecx
shrl %ecx
shlq $0x6, %rcx
movq -0x10(%rdi,%rsi), %r9
movl %r9d, %edx
notl %edx
movq %r11, 0x58(%rsp)
addl (%r11,%rcx), %edx
movl %edx, 0x28(%r12)
movl 0x10(%r12), %ecx
testl %ecx, %ecx
jle 0x19e36
shrq $0x20, %rax
shrq $0x20, %r9
subl %eax, %r9d
incl %r9d
cmpl $0x0, 0x8(%rsp)
jle 0x19da7
movl %edx, 0x1c(%rsp)
movl %ecx, 0x20(%rsp)
movl %r10d, 0x24(%rsp)
movl %r8d, 0x28(%rsp)
movq %r14, 0x40(%rsp)
movq (%rsp), %rax
addq %rax, %rbp
addq $-0x10, %rax
movq %rax, 0x48(%rsp)
xorl %ebx, %ebx
xorl %ecx, %ecx
xorl %r15d, %r15d
xorl %esi, %esi
xorl %edi, %edi
movq %r12, 0x50(%rsp)
leaq (%r15,%r15,4), %rax
movq 0x60(%rsp), %rdx
leaq (%rdx,%rax,4), %r10
movl 0x8(%r10), %eax
shrl %eax
shlq $0x6, %rax
movq 0x58(%rsp), %rdx
movl (%rdx,%rax), %r8d
movslq 0x4(%r10), %r11
testq %r11, %r11
jle 0x19d51
movl %r8d, 0x2c(%rsp)
movl %esi, 0x10(%rsp)
movq %r10, 0x68(%rsp)
movslq (%r10), %r14
movq %rdi, 0x70(%rsp)
leal 0x1(%rdi), %esi
movq 0x8(%rbp), %rax
shlq $0x4, %r14
addq (%rsp), %r14
xorl %edx, %edx
movq %rbp, %r8
movq %rax, %rdi
movq %r14, %rbp
movq 0x8(%r14), %rax
movq %rax, %r10
shrq $0x20, %r10
movzbl %r10b, %r13d
movl %edx, %r10d
orl %r15d, %r10d
je 0x19ccb
testq %r15, %r15
sete %r14b
testq %rdx, %rdx
setne %r12b
movq (%rbp), %r10
orb %r14b, %r12b
jne 0x19cd3
leal (%rsi,%r10), %r12d
jmp 0x19cdc
movl %r13d, %r12d
movl %r13d, %r14d
jmp 0x19cf2
movl (%r8), %r14d
movl %r10d, %r12d
subl %r14d, %r12d
movl %eax, %r14d
subl %edi, %r14d
jns 0x19cf2
negl %r14d
shrq $0x20, %r10
addl 0x4(%r8), %r9d
subl %r10d, %r9d
cmpl %r14d, %r12d
movl %r14d, %edi
cmovgl %r12d, %edi
movl %r14d, %r8d
cmovll %r12d, %r8d
addl %edi, %ecx
cmpl %r13d, %r14d
movl %r8d, %edi
cmoval %r13d, %edi
cmpl %r13d, %r12d
cmovlel %r8d, %edi
addl %edi, %ebx
incq %rdx
leaq 0x10(%rbp), %r14
cmpq %rdx, %r11
jne 0x19c8e
movq 0x50(%rsp), %r12
movl %ecx, 0x2c(%r12)
movl %ebx, 0x30(%r12)
addq $-0x10, %r14
movq %r14, %rbp
movl 0x10(%rsp), %esi
movq 0x70(%rsp), %rdi
movl 0x2c(%rsp), %r8d
movq 0x68(%rsp), %r10
testl %r11d, %r11d
je 0x19d6a
movslq (%r10), %rax
addq %r11, %rax
shlq $0x4, %rax
movq 0x48(%rsp), %rdx
movl (%rdx,%rax), %edi
notl %edi
addl %r8d, %esi
addl %r8d, %edi
incq %r15
cmpq 0x8(%rsp), %r15
jne 0x19c3a
movl %esi, 0x20(%r12)
movq 0x30(%rsp), %rbx
movq 0x40(%rsp), %r14
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl 0x28(%rsp), %r8d
movl 0x24(%rsp), %r10d
movl 0x20(%rsp), %ecx
movl 0x1c(%rsp), %edx
jmp 0x19da9
xorl %esi, %esi
subl %edx, %esi
movl %esi, 0x28(%r12)
cmpl %r10d, %esi
jl 0x19e74
cvtsi2sd %r8d, %xmm0
movsd %xmm0, 0x10(%rsp)
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 0x21a0
divsd 0x10(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x34(%r12)
movl 0x8(%rbx), %eax
incq %r14
movslq %eax, %rcx
cmpq %rcx, %r14
jl 0x19acf
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf846(%rip), %rdi      # 0x29664
leaq 0xf697(%rip), %rsi      # 0x294bc
leaq 0xf876(%rip), %rcx      # 0x296a2
movl $0xfe, %edx
callq 0x2160
leaq 0xf8b2(%rip), %rdi      # 0x296ef
leaq 0xf678(%rip), %rsi      # 0x294bc
leaq 0xf857(%rip), %rcx      # 0x296a2
movl $0x109, %edx            # imm = 0x109
callq 0x2160
leaq 0xf87a(%rip), %rdi      # 0x296d6
leaq 0xf659(%rip), %rsi      # 0x294bc
leaq 0xf838(%rip), %rcx      # 0x296a2
movl $0x104, %edx            # imm = 0x104
callq 0x2160
leaq 0xf884(%rip), %rdi      # 0x296ff
leaq 0xf63a(%rip), %rsi      # 0x294bc
leaq 0xf819(%rip), %rcx      # 0x296a2
movl $0x125, %edx            # imm = 0x125
callq 0x2160