// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x2cde4e
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x2cde4e
movq -0x10(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x2cde53
jmp 0x2ce36e
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x2cdec0
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x2cde88
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x58(%rbp)
jmp 0x2cde93
movl $0x2, %eax
movq %rax, -0x58(%rbp)
jmp 0x2cde93
movq -0x58(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x8(%rbp), %rax
imulq $0x28, 0x8(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rdx
movq (%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, (%rdx)
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x2100
movq -0x38(%rbp), %rax
movl $0x0, (%rax)
movq -0x38(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x20(%rax)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x8(%rcx), %rcx
cmpq %rcx, %rax
jae 0x2cdfa3
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
imulq $0x48, -0x20(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x2cdf6d
movq -0x40(%rbp), %rax
movl (%rax), %eax
movq -0x40(%rbp), %rcx
cmpl 0x4(%rcx), %eax
je 0x2cdf6d
jmp 0x2cdf95
movq -0x40(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x2cdf79
jmp 0x2cdf95
movq -0x38(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x40(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x38(%rbp), %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x2cdf31
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x2cdfbf
movq -0x8(%rbp), %rax
movq (%rax), %rcx
addq $-0x1, %rcx
movq %rcx, (%rax)
jmp 0x2ce36e
movq -0x38(%rbp), %rax
movslq (%rax), %rax
imulq $0x48, %rax, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movslq 0x4(%rax), %rax
imulq $0x1c, %rax, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x38(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x8(%rcx), %rcx
cmpq %rcx, %rax
jae 0x2ce36e
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
imulq $0x48, -0x20(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x2ce056
movq -0x48(%rbp), %rax
movl (%rax), %eax
movq -0x48(%rbp), %rcx
cmpl 0x4(%rcx), %eax
je 0x2ce056
jmp 0x2ce35d
movq -0x48(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x2ce065
jmp 0x2ce35d
movq -0x48(%rbp), %rsi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x38(%rbp), %rax
movslq (%rax), %rax
imulq $0x48, %rax, %rax
addq %rax, %rdi
movl $0x48, %edx
callq 0x2180
movq -0x38(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x38(%rbp), %rdx
movslq (%rdx), %rdx
imulq $0x48, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x48(%rbp), %rcx
movslq 0xc(%rcx), %rcx
cmpq %rcx, %rax
jae 0x2ce341
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movslq 0x8(%rcx), %rcx
addq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rdx
movslq 0x4(%rdx), %rdx
addq -0x28(%rbp), %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x50(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rdx
movslq 0x4(%rdx), %rdx
addq -0x28(%rbp), %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movq -0x50(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rdx
movslq 0x4(%rdx), %rdx
addq -0x28(%rbp), %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movq -0x50(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x2ce2a6
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x50(%rbp), %rcx
movslq (%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xff, %rax
cltq
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x50(%rbp), %rcx
movslq (%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
addl $0x1, %eax
cltq
subq -0x30(%rbp), %rax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rdx
movslq 0x4(%rdx), %rdx
addq -0x28(%rbp), %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x50(%rbp), %rcx
movslq (%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
addl $0x1, %eax
cltq
subq -0x30(%rbp), %rax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rdx
movslq 0x4(%rdx), %rdx
addq -0x28(%rbp), %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x14(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x50(%rbp), %rcx
movl (%rcx), %ecx
movq -0x50(%rbp), %rdx
addl 0x4(%rdx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movl %eax, %ecx
addl $0x1, %ecx
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rdx
movslq 0x4(%rdx), %rdx
addq -0x28(%rbp), %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x50(%rbp), %rcx
movl (%rcx), %ecx
movq -0x50(%rbp), %rdx
addl 0x4(%rdx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, %ecx
addl $0x1, %ecx
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rdx
movslq 0x4(%rdx), %rdx
addq -0x28(%rbp), %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x18(%rax)
jmp 0x2ce32e
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
movslq 0x4(%rcx), %rcx
addq -0x28(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
movslq 0x4(%rcx), %rcx
addq -0x28(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x14(%rax) # imm = 0xFFFFFFFF
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
movslq 0x4(%rcx), %rcx
addq -0x28(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x10(%rax) # imm = 0xFFFFFFFF
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
movslq 0x4(%rcx), %rcx
addq -0x28(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0xc(%rax)  # imm = 0xFFFFFFFF
jmp 0x2ce330
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x2ce0b1
movq -0x38(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x48(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x38(%rbp), %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x2ce013
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)