// File: /workspace/github_c_makefile_star2_O0/lh3[P]miniprot/format.c
// Function: mp_write_gff
static void mp_write_gff(kstring_t *s, void *km, const mp_idx_t *mi, const mp_bseq1_t *seq, const mp_reg1_t *r, const char *gff_prefix, int64_t id, const char *qname, int32_t gff_delim, int32_t hit_idx)
{
	const mp_ctg_t *ctg;
	const mp_feat_t *f, *feat = r->feat;
	int64_t vs, ve, ve_mRNA;
	int32_t j, has_stop = 0;
	char dec[16], *id_str = 0;

	if (r == 0 || r->p == 0) return;
	has_stop = (r->qe == seq->l_seq && r->p->dist_stop == 0);
	ve_mRNA = has_stop? r->ve + 3 : r->ve;

	if (gff_delim >= 33 && gff_delim <= 126 && hit_idx >= 0) {
		id_str = Kmalloc(km, char, strlen(qname) + 16);
		sprintf(id_str, "%s%c%d", qname, gff_delim, hit_idx);
	} else {
		id_str = Kmalloc(km, char, strlen(gff_prefix) + 16);
		sprintf(id_str, "%s%.6ld", gff_prefix, (long)id);
	}
	ctg = &mi->nt->ctg[r->vid>>1];
	vs = r->vid&1? ctg->len - ve_mRNA : r->vs;
	ve = r->vid&1? ctg->len - r->vs   : ve_mRNA;
	mp_sprintf_lite(s, "%s\tminiprot\tmRNA\t%ld\t%ld\t%d\t%c\t.\tID=%s;Rank=%d", ctg->name, (long)vs + 1, (long)ve, r->p->dp_max, "+-"[r->vid&1], id_str, hit_idx);
	snprintf(dec, 16, "%.4f", (double)r->p->n_iden * 3 / r->p->blen);
	mp_sprintf_lite(s, ";Identity=%s", dec);
	snprintf(dec, 16, "%.4f", (double)r->p->n_plus * 3 / r->p->blen);
	mp_sprintf_lite(s, ";Positive=%s", dec);
	if (r->p->n_fs > 0) mp_sprintf_lite(s, ";Frameshift=%d", r->p->n_fs);
	if (r->p->n_stop > 0) mp_sprintf_lite(s, ";StopCodon=%d", r->p->n_stop);
	mp_sprintf_lite(s, ";Target=%s %d %d\n", seq->name, r->qs + 1, r->qe);

	for (j = 0; j < r->n_feat; ++j) {
		f = &feat[j];
		ve = f->ve;
		if (has_stop && f->type == MP_FEAT_CDS && j + 1 < r->n_feat && feat[j+1].type == MP_FEAT_STOP) // in GFF3, the last CDS includes stop codon. GTF is different!
			ve += 3;
		vs = r->vid&1? ctg->len - ve    : f->vs;
		ve = r->vid&1? ctg->len - f->vs : ve;
		mp_sprintf_lite(s, "%s\tminiprot\t%s\t%ld\t%ld\t%d\t%c\t%d\tParent=%s;Rank=%d", ctg->name, f->type == MP_FEAT_STOP? "stop_codon" : "CDS",
			(long)vs + 1, (long)ve, f->score, "+-"[r->vid&1], f->phase, id_str, hit_idx);
		if (f->type == MP_FEAT_CDS) {
			snprintf(dec, 16, "%.4f", (double)f->n_iden * 3 / f->blen);
			mp_sprintf_lite(s, ";Identity=%s", dec);
			if (f->acceptor[0] && strncmp(f->acceptor, "AG", 2) != 0) mp_sprintf_lite(s, ";Acceptor=%c%c", f->acceptor[0], f->acceptor[1]);
			if (f->donor[0]    && strncmp(f->donor,    "GT", 2) != 0) mp_sprintf_lite(s, ";Donor=%c%c",    f->donor[0],    f->donor[1]);
			if (f->n_fs > 0) mp_sprintf_lite(s, ";Frameshift=%d", f->n_fs);
			if (f->n_stop > 0) mp_sprintf_lite(s, ";StopCodon=%d", f->n_stop);
			mp_sprintf_lite(s, ";Target=%s %d %d", seq->name, f->qs + 1, f->qe);
		}
		mp_sprintf_lite(s, "\n");
	}
	kfree(km, id_str);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xf0, %rsp
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x78(%rbp)
movq $0x0, -0x98(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x1ef84
movq -0x38(%rbp), %rax
cmpq $0x0, 0x60(%rax)
jne 0x1ef89
jmp 0x1f614
movq -0x38(%rbp), %rax
movl 0x38(%rax), %ecx
movq -0x30(%rbp), %rdx
xorl %eax, %eax
cmpl (%rdx), %ecx
movb %al, -0x99(%rbp)
jne 0x1efb5
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rax
cmpl $0x0, 0x20(%rax)
sete %al
movb %al, -0x99(%rbp)
movb -0x99(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x78(%rbp)
cmpl $0x0, -0x78(%rbp)
je 0x1efde
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
addq $0x3, %rax
movq %rax, -0xa8(%rbp)
jmp 0x1efed
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpl $0x21, 0x20(%rbp)
jl 0x1f05e
cmpl $0x7e, 0x20(%rbp)
jg 0x1f05e
cmpl $0x0, 0x28(%rbp)
jl 0x1f05e
movq -0x20(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq 0x18(%rbp), %rdi
callq 0x2110
movq -0xb0(%rbp), %rdi
movq %rax, %rsi
addq $0x10, %rsi
shlq $0x0, %rsi
callq 0xaeb0
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
movq 0x18(%rbp), %rdx
movl 0x20(%rbp), %ecx
movl 0x28(%rbp), %r8d
leaq 0x3182(%rip), %rsi      # 0x221d7
movb $0x0, %al
callq 0x2300
jmp 0x1f0ad
movq -0x20(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x40(%rbp), %rdi
callq 0x2110
movq -0xb8(%rbp), %rdi
movq %rax, %rsi
addq $0x10, %rsi
shlq $0x0, %rsi
callq 0xaeb0
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
movq -0x40(%rbp), %rdx
movq 0x10(%rbp), %rcx
leaq 0x3138(%rip), %rsi      # 0x221de
movb $0x0, %al
callq 0x2300
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rax
movq -0x38(%rbp), %rcx
movl 0x30(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1f0f3
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
subq -0x70(%rbp), %rax
movq %rax, -0xc0(%rbp)
jmp 0x1f102
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1f135
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x38(%rbp), %rcx
subq 0x40(%rcx), %rax
movq %rax, -0xc8(%rbp)
jmp 0x1f140
movq -0x70(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x60(%rbp), %rcx
addq $0x1, %rcx
movq -0x68(%rbp), %r8
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rax
movl 0x4(%rax), %r9d
movq -0x38(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
leaq 0x23f0(%rip), %rax      # 0x21574
movsbl (%rax,%rsi), %r11d
movq -0x98(%rbp), %r10
movl 0x28(%rbp), %eax
leaq 0x304c(%rip), %rsi      # 0x221e6
movl %r11d, (%rsp)
movq %r10, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x1bc80
leaq -0x90(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rax
cvtsi2sdl 0x28(%rax), %xmm0
movsd 0x2cae(%rip), %xmm1     # 0x21e78
mulsd %xmm1, %xmm0
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rax
cvtsi2sdl 0x14(%rax), %xmm1
divsd %xmm1, %xmm0
movl $0x10, %esi
leaq 0x302a(%rip), %rdx      # 0x22215
movb $0x1, %al
callq 0x2150
movq -0x18(%rbp), %rdi
leaq -0x90(%rbp), %rdx
leaq 0x3016(%rip), %rsi      # 0x2221a
movb $0x0, %al
callq 0x1bc80
leaq -0x90(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rax
cvtsi2sdl 0x2c(%rax), %xmm0
movsd 0x2c51(%rip), %xmm1     # 0x21e78
mulsd %xmm1, %xmm0
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rax
cvtsi2sdl 0x14(%rax), %xmm1
divsd %xmm1, %xmm0
movl $0x10, %esi
leaq 0x2fcd(%rip), %rdx      # 0x22215
movb $0x1, %al
callq 0x2150
movq -0x18(%rbp), %rdi
leaq -0x90(%rbp), %rdx
leaq 0x2fc6(%rip), %rsi      # 0x22227
movb $0x0, %al
callq 0x1bc80
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rax
cmpl $0x0, 0x18(%rax)
jle 0x1f293
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rax
movl 0x18(%rax), %edx
leaq 0x2fa8(%rip), %rsi      # 0x22234
movb $0x0, %al
callq 0x1bc80
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rax
cmpl $0x0, 0x1c(%rax)
jle 0x1f2be
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rax
movl 0x1c(%rax), %edx
leaq 0x2f8c(%rip), %rsi      # 0x22243
movb $0x0, %al
callq 0x1bc80
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x38(%rbp), %rax
movl 0x34(%rax), %ecx
addl $0x1, %ecx
movq -0x38(%rbp), %rax
movl 0x38(%rax), %r8d
leaq 0x2f6e(%rip), %rsi      # 0x22251
movb $0x0, %al
callq 0x1bc80
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x1f604
movq -0x58(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
cmpl $0x0, -0x78(%rbp)
je 0x1f36b
movq -0x50(%rbp), %rax
movswl 0x18(%rax), %eax
cmpl $0x0, %eax
jne 0x1f36b
movl -0x74(%rbp), %eax
addl $0x1, %eax
movq -0x38(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x1f36b
movq -0x58(%rbp), %rax
movl -0x74(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movswl 0x18(%rax), %eax
cmpl $0x1, %eax
jne 0x1f36b
movq -0x68(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1f38f
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
subq -0x68(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0x1f39d
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1f3cf
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x50(%rbp), %rcx
subq (%rcx), %rax
movq %rax, -0xd8(%rbp)
jmp 0x1f3da
movq -0x68(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x50(%rbp), %rax
movswl 0x18(%rax), %esi
leaq 0x2ea0(%rip), %rcx      # 0x222a0
leaq 0x2e8e(%rip), %rax      # 0x22295
cmpl $0x1, %esi
cmoveq %rax, %rcx
movq -0x60(%rbp), %r8
addq $0x1, %r8
movq -0x68(%rbp), %r9
movq -0x50(%rbp), %rax
movl 0x24(%rax), %r14d
movq -0x38(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
leaq 0x213d(%rip), %rax      # 0x21574
movsbl (%rax,%rsi), %ebx
movq -0x50(%rbp), %rax
movswl 0x1a(%rax), %r11d
movq -0x98(%rbp), %r10
movl 0x28(%rbp), %eax
leaq 0x2e0e(%rip), %rsi      # 0x22263
movl %r14d, (%rsp)
movl %ebx, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movl %eax, 0x20(%rsp)
movb $0x0, %al
callq 0x1bc80
movq -0x50(%rbp), %rax
movswl 0x18(%rax), %eax
cmpl $0x0, %eax
jne 0x1f5e4
leaq -0x90(%rbp), %rdi
movq -0x50(%rbp), %rax
cvtsi2sdl 0x28(%rax), %xmm0
movsd 0x29dd(%rip), %xmm1     # 0x21e78
mulsd %xmm1, %xmm0
movq -0x50(%rbp), %rax
cvtsi2sdl 0x2c(%rax), %xmm1
divsd %xmm1, %xmm0
movl $0x10, %esi
leaq 0x2d5d(%rip), %rdx      # 0x22215
movb $0x1, %al
callq 0x2150
movq -0x18(%rbp), %rdi
leaq -0x90(%rbp), %rdx
leaq 0x2d49(%rip), %rsi      # 0x2221a
movb $0x0, %al
callq 0x1bc80
movq -0x50(%rbp), %rax
movsbl 0x32(%rax), %eax
cmpl $0x0, %eax
je 0x1f525
movq -0x50(%rbp), %rdi
addq $0x32, %rdi
leaq 0x2db0(%rip), %rsi      # 0x222a4
movl $0x2, %edx
callq 0x2060
cmpl $0x0, %eax
je 0x1f525
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rax
movsbl 0x32(%rax), %edx
movq -0x50(%rbp), %rax
movsbl 0x33(%rax), %ecx
leaq 0x2d89(%rip), %rsi      # 0x222a7
movb $0x0, %al
callq 0x1bc80
movq -0x50(%rbp), %rax
movsbl 0x30(%rax), %eax
cmpl $0x0, %eax
je 0x1f572
movq -0x50(%rbp), %rdi
addq $0x30, %rdi
leaq 0x2d75(%rip), %rsi      # 0x222b6
movl $0x2, %edx
callq 0x2060
cmpl $0x0, %eax
je 0x1f572
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rax
movsbl 0x30(%rax), %edx
movq -0x50(%rbp), %rax
movsbl 0x31(%rax), %ecx
leaq 0x2d4e(%rip), %rsi      # 0x222b9
movb $0x0, %al
callq 0x1bc80
movq -0x50(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
jle 0x1f595
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rax
movl 0x1c(%rax), %edx
leaq 0x2ca6(%rip), %rsi      # 0x22234
movb $0x0, %al
callq 0x1bc80
movq -0x50(%rbp), %rax
cmpl $0x0, 0x20(%rax)
jle 0x1f5b8
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rax
movl 0x20(%rax), %edx
leaq 0x2c92(%rip), %rsi      # 0x22243
movb $0x0, %al
callq 0x1bc80
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x50(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movq -0x50(%rbp), %rax
movl 0x14(%rax), %r8d
leaq 0x2ce8(%rip), %rsi      # 0x222c5
movb $0x0, %al
callq 0x1bc80
movq -0x18(%rbp), %rdi
leaq 0x248e(%rip), %rsi      # 0x21a7d
movb $0x0, %al
callq 0x1bc80
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x1f2f1
movq -0x20(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0xac90
addq $0xf0, %rsp
popq %rbx
popq %r14
popq %rbp
retq