// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: dump_gaf(mg_gres_a*, mg_gchains_t const*, unsigned int)
void dump_gaf(mg_gres_a *hits, const mg_gchains_t *gs, uint32_t only_p)
{
	if (gs == NULL || gs->n_gc == 0 || gs->n_lc == 0) return;
	uint64_t i, j;
	int64_t q_span;
	mg_gres_t *p = NULL;
	kv_pushp(mg_gres_t, *hits, &p); memset(p, 0, sizeof(*p));
	p->n_gc = 0; p->n_lc = 0; p->qid = gs->qid; p->qlen = gs->qlen;
	// p->n_gc = gs->n_gc; p->n_lc = gs->n_lc; p->qid = gs->qid; p->qlen = gs->qlen;
	// MALLOC(p->gc, p->n_gc); memcpy(p->gc, gs->gc, p->n_gc);
	for (i = 0; i < (uint64_t)gs->n_gc; ++i) {
		const mg_gchain_t *t = &gs->gc[i];///one of the gchain
		if(only_p && t->id != t->parent) continue;
		if (t->cnt == 0) continue;
		p->n_gc++; p->n_lc += t->cnt;
	}
	if (p->n_gc == 0) {
		hits->n--;
		return;
	}
	MALLOC(p->gc, p->n_gc); MALLOC(p->lc, p->n_lc); 
	p->n_gc = p->n_lc = 0;
	for (i = 0; i < (uint64_t)gs->n_gc; ++i) {
		const mg_gchain_t *t = &gs->gc[i];///one of the gchain
		if(only_p && t->id != t->parent) continue;
		if (t->cnt == 0) continue;
		p->gc[p->n_gc] = *t; p->gc[p->n_gc].off = p->n_lc;
		for (j = 0; j < (uint64_t)t->cnt; ++j) {
			const mg_llchain_t *q = &gs->lc[t->off + j];
			p->lc[p->n_lc+j].cnt = q->cnt;
			p->lc[p->n_lc+j].score = q->score;
			p->lc[p->n_lc+j].v = q->v;
			if(q->cnt) {
				q_span = (int32_t)(gs->a[q->off].y>>32&0xff);
				p->lc[p->n_lc+j].qs = (int32_t)gs->a[q->off].y + 1 - q_span;///calculated by the first lchain
				p->lc[p->n_lc+j].ts = (int32_t)gs->a[q->off].x + 1 - q_span;///calculated by the first lchain
				p->lc[p->n_lc+j].qe = (int32_t)gs->a[q->off + q->cnt - 1].y + 1;
				p->lc[p->n_lc+j].te = (int32_t)gs->a[q->off + q->cnt - 1].x + 1;
			} else {
				p->lc[p->n_lc+j].qs = p->lc[p->n_lc+j].qe = p->lc[p->n_lc+j].ts = p->lc[p->n_lc+j].te = (uint32_t)-1;
			}
			
			// mg_sprintf_lite(s, "%c%s", "><"[q->v&1], g->seg[q->v>>1].name);
		}
		p->n_gc++; p->n_lc += t->cnt;
	}
}

// Assembly:
testq %rsi, %rsi
je 0x1c3503
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
cmpl $0x0, 0x8(%rsi)
je 0x1c34f5
cmpl $0x0, 0xc(%r14)
je 0x1c34f5
movl %edx, %ebx
movq %rdi, %r15
movq 0x8(%rdi), %rax
cmpq %rax, (%rdi)
jne 0x1c32f7
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmovneq %rcx, %rax
movq %rax, 0x8(%r15)
movq 0x10(%r15), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq %rax, 0x10(%r15)
movq (%r15), %rax
movq 0x10(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r15)
leaq (%rax,%rax,4), %rax
leaq (%rcx,%rax,8), %r12
pxor %xmm0, %xmm0
movdqu %xmm0, 0x10(%r12)
movdqu %xmm0, (%r12)
movq $0x0, 0x20(%r12)
movq 0x30(%r14), %rax
movq %rax, 0x18(%r12)
movq 0x38(%r14), %rax
movq %rax, 0x20(%r12)
movslq 0x8(%r14), %rax
testq %rax, %rax
je 0x1c336a
movq 0x18(%r14), %rcx
testl %ebx, %ebx
je 0x1c3351
movl (%rcx), %edx
cmpl 0x4(%rcx), %edx
jne 0x1c3361
movl 0xc(%rcx), %edx
testl %edx, %edx
je 0x1c3361
incl (%r12)
addl %edx, 0x4(%r12)
addq $0x48, %rcx
decq %rax
jne 0x1c3346
movslq (%r12), %rax
testq %rax, %rax
je 0x1c34f2
shlq $0x3, %rax
leaq (%rax,%rax,8), %rdi
callq 0x2280
movq %rax, 0x8(%r12)
movslq 0x4(%r12), %rax
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rdi
addq %rax, %rdi
callq 0x2280
movq %rax, 0x10(%r12)
movq $0x0, (%r12)
cmpl $0x0, 0x8(%r14)
je 0x1c34f5
xorl %edx, %edx
pcmpeqd %xmm0, %xmm0
leaq (%rdx,%rdx,8), %rax
shlq $0x3, %rax
addq 0x18(%r14), %rax
testl %ebx, %ebx
je 0x1c33d7
movl (%rax), %ecx
cmpl 0x4(%rax), %ecx
jne 0x1c34e0
cmpl $0x0, 0xc(%rax)
je 0x1c34e0
movslq (%r12), %rcx
leaq (%rcx,%rcx,8), %rdi
shlq $0x3, %rdi
addq 0x8(%r12), %rdi
movl $0x12, %ecx
movq %rax, %rsi
rep  movsl (%rsi), %es:(%rdi)
movslq 0x4(%r12), %rcx
movq 0x8(%r12), %rsi
movslq (%r12), %rdi
leaq (%rdi,%rdi,8), %r8
movl %ecx, 0x8(%rsi,%r8,8)
movslq 0xc(%rax), %rsi
testq %rsi, %rsi
je 0x1c34d3
movq 0x20(%r14), %r8
movslq 0x8(%rax), %rax
movq 0x10(%r12), %r9
shlq $0x4, %rax
addq %r8, %rax
addq $0xc, %rax
leaq (%rcx,%rcx,8), %r8
leaq (%r8,%r8,2), %r8
addq %rcx, %r8
addq %r9, %r8
addq $0x18, %r8
movq %rsi, %r9
movslq -0x8(%rax), %r10
movl %r10d, -0x18(%r8)
movl (%rax), %r11d
movl %r11d, -0x10(%r8)
movl -0x4(%rax), %r11d
movl %r11d, -0x14(%r8)
testq %r10, %r10
je 0x1c34bc
movq 0x28(%r14), %r11
movslq -0xc(%rax), %r15
addq %r15, %r10
shlq $0x4, %r15
movq 0x8(%r11,%r15), %r13
movq %r13, %rbp
shrq $0x20, %rbp
movzbl %bpl, %ebp
subl %ebp, %r13d
incl %r13d
movl %r13d, -0xc(%r8)
movl (%r11,%r15), %r15d
subl %ebp, %r15d
incl %r15d
movl %r15d, -0x4(%r8)
shlq $0x4, %r10
movl -0x8(%r11,%r10), %ebp
incl %ebp
movl %ebp, -0x8(%r8)
movl -0x10(%r11,%r10), %r10d
incl %r10d
movl %r10d, (%r8)
jmp 0x1c34c2
movdqu %xmm0, -0xc(%r8)
addq $0x10, %rax
addq $0x1c, %r8
decq %r9
jne 0x1c344d
incl %edi
movl %edi, (%r12)
addl %ecx, %esi
movl %esi, 0x4(%r12)
incq %rdx
movslq 0x8(%r14), %rax
cmpq %rax, %rdx
jb 0x1c33bc
jmp 0x1c34f5
decq (%r15)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq