// File: /workspace/github_cpp_makefile_star2_O2/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 0x1818c1
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
cmpl $0x0, 0x8(%rsi)
je 0x1818b3
cmpl $0x0, 0xc(%r14)
je 0x1818b3
movq %rdi, %r15
movq (%rdi), %rcx
cmpq 0x8(%rdi), %rcx
movl %edx, 0x4(%rsp)
jne 0x1816ae
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmovneq %rax, %rcx
movq %rcx, 0x8(%r15)
movq 0x10(%r15), %rdi
imulq $0x28, %rcx, %rsi
callq 0x2370
movl 0x4(%rsp), %edx
movq %rax, 0x10(%r15)
movq (%r15), %rcx
jmp 0x1816b2
movq 0x10(%r15), %rax
leaq 0x1(%rcx), %rsi
movq %rsi, (%r15)
imulq $0x28, %rcx, %rcx
leaq (%rax,%rcx), %r12
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax,%rcx)
andq $0x0, 0x20(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
movups 0x30(%r14), %xmm0
movups %xmm0, 0x18(%rax,%rcx)
movl 0x8(%r14), %ebp
movslq %ebp, %rax
xorl %r8d, %r8d
xorl %r13d, %r13d
xorl %ecx, %ecx
subq $0x1, %rax
jb 0x181722
movq 0x18(%r14), %rsi
testl %edx, %edx
je 0x181705
movl (%rsi,%r8), %edi
cmpl 0x4(%rsi,%r8), %edi
jne 0x18171c
movl 0xc(%rsi,%r8), %esi
testl %esi, %esi
je 0x18171c
incl %ecx
movl %ecx, (%r12)
addl %esi, %r13d
movl %r13d, 0x4(%r12)
addq $0x48, %r8
jmp 0x1816ec
testl %ecx, %ecx
je 0x1818b0
movslq %ecx, %rax
imulq $0x48, %rax, %rdi
callq 0x2280
movq %rax, 0x8(%rsp)
movq %rax, 0x8(%r12)
movslq %r13d, %rax
imulq $0x1c, %rax, %rdi
callq 0x2280
movl 0x4(%rsp), %esi
movq %rax, 0x10(%r12)
andq $0x0, (%r12)
xorl %eax, %eax
pushq $-0x1
popq %r10
xorl %edi, %edi
movslq %ebp, %rcx
cmpq %rcx, %rdi
jae 0x1818b3
imulq $0x48, %rdi, %rdx
addq 0x18(%r14), %rdx
testl %esi, %esi
je 0x181785
movl (%rdx), %ecx
cmpl 0x4(%rdx), %ecx
jne 0x1818a8
cmpl $0x0, 0xc(%rdx)
je 0x1818a8
movq %rdi, 0x20(%rsp)
cltq
imulq $0x48, %rax, %rax
movq 0x8(%rsp), %rdi
addq %rax, %rdi
pushq $0x12
popq %rcx
movq %rdx, %rsi
rep  movsl (%rsi), %es:(%rdi)
movslq 0x4(%r12), %rdi
movq 0x8(%r12), %rcx
movslq (%r12), %rax
movq %rax, 0x10(%rsp)
imulq $0x48, %rax, %rax
movq %rcx, 0x8(%rsp)
movl %edi, 0x8(%rcx,%rax)
movslq 0xc(%rdx), %rsi
movq %rdi, 0x18(%rsp)
imulq $0x1c, %rdi, %r11
addq $0x18, %r11
pushq $0xc
popq %r13
movq %rsi, %rbp
subq $0x1, %rbp
jb 0x181887
movslq 0x8(%rdx), %rcx
shlq $0x4, %rcx
addq 0x20(%r14), %rcx
movq 0x10(%r12), %rax
movl (%r13,%rcx), %edi
movl %edi, -0x10(%rax,%r11)
movq -0x8(%r13,%rcx), %rdi
movq %rdi, -0x18(%rax,%r11)
movl %r10d, %r15d
movl %r10d, %r9d
movl %r10d, %r8d
movl %r10d, %ebx
testl %edi, %edi
je 0x181867
movq 0x28(%r14), %r8
movslq -0xc(%rcx,%r13), %rcx
movslq %edi, %rdi
addq %rcx, %rdi
shlq $0x4, %rcx
movq 0x8(%r8,%rcx), %rbx
movq %rbx, %r9
shrq $0x20, %r9
movzbl %r9b, %r15d
subl %r15d, %ebx
incl %ebx
movl (%r8,%rcx), %r9d
subl %r15d, %r9d
incl %r9d
shlq $0x4, %rdi
movl -0x10(%r8,%rdi), %r15d
movl -0x8(%r8,%rdi), %r8d
incl %r8d
incl %r15d
movl %r15d, (%rax,%r11)
movl %r9d, -0x4(%rax,%r11)
movl %r8d, -0x8(%rax,%r11)
movl %ebx, -0xc(%rax,%r11)
addq $0x1c, %r11
addq $0x10, %r13
jmp 0x1817e2
movq 0x10(%rsp), %rax
incl %eax
movl %eax, (%r12)
addl 0x18(%rsp), %esi
movl %esi, 0x4(%r12)
movl 0x8(%r14), %ebp
movl 0x4(%rsp), %esi
movq 0x20(%rsp), %rdi
incq %rdi
jmp 0x181762
decq (%r15)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq