// File: /workspace/github_c_makefile_star2_O0/lh3[P]miniprot/format.c
// Function: mp_write_gtf
static void mp_write_gtf(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)
{
	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 *id_g_str = 0, *id_t_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;

	id_g_str = Kmalloc(km, char, strlen(gff_prefix) + 16);
	id_t_str = Kmalloc(km, char, strlen(gff_prefix) + 16);
	sprintf(id_g_str, "%sG%.6ld", gff_prefix, (long)id);
	sprintf(id_t_str, "%sT%.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\tgene\t%ld\t%ld\t%d\t%c\t.\tgene_id \"%s\";\n", ctg->name, (long)vs + 1, (long)ve, r->p->dp_max, "+-"[r->vid&1], id_g_str);
	mp_sprintf_lite(s, "%s\tminiprot\ttranscript\t%ld\t%ld\t%d\t%c\t.\ttranscript_id \"%s\"; gene_id \"%s\";\n", ctg->name, (long)vs + 1, (long)ve, r->p->dp_max, "+-"[r->vid&1], id_t_str, id_g_str);

	for (j = 0; j < r->n_feat; ++j) {
		int64_t vs2, ve2;
		f = &feat[j];
		if (f->type != MP_FEAT_CDS) continue; // GTF is simpler without stop_codon and additional attributes
		vs2 = vs = r->vid&1? ctg->len - f->ve : f->vs;
		ve2 = ve = r->vid&1? ctg->len - f->vs : f->ve;
		if (f->ve == r->ve) { // last exon; then adjust for stop codon
			if (r->vid&1) vs2 = ctg->len - ve_mRNA;
			else ve2 = ve_mRNA;
		}
		mp_sprintf_lite(s, "%s\tminiprot\texon\t%ld\t%ld\t%d\t%c\t.\ttranscript_id \"%s\"; gene_id \"%s\";\n", ctg->name, (long)vs2 + 1, (long)ve2, f->score, "+-"[r->vid&1], id_t_str, id_g_str);
		mp_sprintf_lite(s, "%s\tminiprot\tCDS\t%ld\t%ld\t%d\t%c\t%d\ttranscript_id \"%s\"; gene_id \"%s\";\n", ctg->name, (long)vs + 1,  (long)ve,  f->score, "+-"[r->vid&1], f->phase, id_t_str, id_g_str);
	}
	kfree(km, id_g_str);
	kfree(km, id_t_str);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0xe8, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x1eab1
movq -0x30(%rbp), %rax
cmpq $0x0, 0x60(%rax)
jne 0x1eab6
jmp 0x1ef15
movq -0x30(%rbp), %rax
movl 0x38(%rax), %ecx
movq -0x28(%rbp), %rdx
xorl %eax, %eax
cmpl (%rdx), %ecx
movb %al, -0x91(%rbp)
jne 0x1eae2
movq -0x30(%rbp), %rax
movq 0x60(%rax), %rax
cmpl $0x0, 0x20(%rax)
sete %al
movb %al, -0x91(%rbp)
movb -0x91(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x70(%rbp)
cmpl $0x0, -0x70(%rbp)
je 0x1eb0b
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rax
addq $0x3, %rax
movq %rax, -0xa0(%rbp)
jmp 0x1eb1a
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x38(%rbp), %rdi
callq 0x2110
movq -0xb0(%rbp), %rdi
movq %rax, %rsi
addq $0x10, %rsi
shlq $0x0, %rsi
callq 0xaeb0
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x38(%rbp), %rdi
callq 0x2110
movq -0xa8(%rbp), %rdi
movq %rax, %rsi
addq $0x10, %rsi
shlq $0x0, %rsi
callq 0xaeb0
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
movq -0x38(%rbp), %rdx
movq 0x10(%rbp), %rcx
leaq 0x352d(%rip), %rsi      # 0x220c3
movb $0x0, %al
callq 0x2300
movq -0x80(%rbp), %rdi
movq -0x38(%rbp), %rdx
movq 0x10(%rbp), %rcx
leaq 0x351c(%rip), %rsi      # 0x220cc
movb $0x0, %al
callq 0x2300
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rax
movq -0x30(%rbp), %rcx
movl 0x30(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1ebfd
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
subq -0x68(%rbp), %rax
movq %rax, -0xb8(%rbp)
jmp 0x1ec0c
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1ec3f
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x30(%rbp), %rcx
subq 0x40(%rcx), %rax
movq %rax, -0xc0(%rbp)
jmp 0x1ec4a
movq -0x68(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x58(%rbp), %rcx
addq $0x1, %rcx
movq -0x60(%rbp), %r8
movq -0x30(%rbp), %rax
movq 0x60(%rax), %rax
movl 0x4(%rax), %r9d
movq -0x30(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
leaq 0x28e6(%rip), %rax      # 0x21574
movsbl (%rax,%rsi), %r10d
movq -0x78(%rbp), %rax
leaq 0x3437(%rip), %rsi      # 0x220d5
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x1bc80
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x58(%rbp), %rcx
addq $0x1, %rcx
movq -0x60(%rbp), %r8
movq -0x30(%rbp), %rax
movq 0x60(%rax), %rax
movl 0x4(%rax), %r9d
movq -0x30(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
leaq 0x288d(%rip), %rax      # 0x21574
movsbl (%rax,%rsi), %r11d
movq -0x80(%rbp), %r10
movq -0x78(%rbp), %rax
leaq 0x340a(%rip), %rsi      # 0x22105
movl %r11d, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x1bc80
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x1eefb
movq -0x50(%rbp), %rax
movslq -0x6c(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movswl 0x18(%rax), %eax
cmpl $0x0, %eax
je 0x1ed4c
jmp 0x1eeed
movq -0x30(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1ed74
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x48(%rbp), %rcx
subq 0x8(%rcx), %rax
movq %rax, -0xc8(%rbp)
jmp 0x1ed82
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq %rax, -0x88(%rbp)
movq -0x30(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1edbb
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x48(%rbp), %rcx
subq (%rcx), %rax
movq %rax, -0xd0(%rbp)
jmp 0x1edca
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq %rax, -0x90(%rbp)
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jne 0x1ee1f
movq -0x30(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1ee12
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
subq -0x68(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x1ee1d
movq -0x68(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x1ee1f
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x88(%rbp), %rcx
addq $0x1, %rcx
movq -0x90(%rbp), %r8
movq -0x48(%rbp), %rax
movl 0x24(%rax), %r9d
movq -0x30(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
leaq 0x271a(%rip), %rax      # 0x21574
movsbl (%rax,%rsi), %r11d
movq -0x80(%rbp), %r10
movq -0x78(%rbp), %rax
leaq 0x32e1(%rip), %rsi      # 0x2214f
movl %r11d, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x1bc80
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x58(%rbp), %rcx
addq $0x1, %rcx
movq -0x60(%rbp), %r8
movq -0x48(%rbp), %rax
movl 0x24(%rax), %r9d
movq -0x30(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
leaq 0x26bc(%rip), %rax      # 0x21574
movsbl (%rax,%rsi), %ebx
movq -0x48(%rbp), %rax
movswl 0x1a(%rax), %r11d
movq -0x80(%rbp), %r10
movq -0x78(%rbp), %rax
leaq 0x32bf(%rip), %rsi      # 0x22193
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movb $0x0, %al
callq 0x1bc80
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x1ed17
movq -0x18(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0xac90
movq -0x18(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0xac90
addq $0xe8, %rsp
popq %rbx
popq %rbp
retq
nop