// File: /workspace/github_c_makefile_star2_O1/lh3[P]minimap2/format.c
// Function: mm_write_junc
void mm_write_junc(kstring_t *s, const mm_idx_t *mi, const mm_bseq1_t *t, const mm_reg1_t *r)
{
	int32_t i, t_off, swritten = 0;
	s->l = 0;
	if (!r->is_spliced || r->p == 0) return; // no junctions
	if (r->p->trans_strand != 1 && r->p->trans_strand != 2) return; // no preferred strand
	for (i = 0, t_off = r->rs; i < (int)r->p->n_cigar; ++i) {
		int op = r->p->cigar[i]&0xf, len = r->p->cigar[i]>>4;
		if (op == MM_CIGAR_MATCH || op == MM_CIGAR_EQ_MATCH || op == MM_CIGAR_X_MISMATCH || op == MM_CIGAR_DEL) {
			t_off += len;
		} else if (op == MM_CIGAR_N_SKIP) { // intron
			uint8_t donor[2], acceptor[2];
			int32_t score1 = 0, score2 = 0, rev;
			assert(len >= 2);
			rev = (r->p->trans_strand == 2) ^ r->rev;
			if (!rev) {
				mm_idx_getseq(mi, r->rid, t_off, t_off + 2, donor);
				mm_idx_getseq(mi, r->rid, t_off + len - 2, t_off + len, acceptor);
			} else {
				mm_idx_getseq(mi, r->rid, t_off, t_off + 2, acceptor);
				mm_idx_getseq(mi, r->rid, t_off + len - 2, t_off + len, donor);
				revcomp_splice(donor);
				revcomp_splice(acceptor);
			}
			//fprintf(stderr, "%c%c-%c%c\n", "ACGTN"[donor[0]], "ACGTN"[donor[1]], "ACGTN"[acceptor[0]], "ACGTN"[acceptor[1]]);
			if (donor[0] == 2 && donor[1] == 3) score1 = 3;
			else if (donor[0] == 2 && donor[1] == 1) score1 = 2;
			else if (donor[0] == 0 && donor[1] == 3) score1 = 1;
			if (acceptor[0] == 0 && acceptor[1] == 2) score2 = 3;
			else if (acceptor[0] == 0 && acceptor[1] == 1) score2 = 1;
			if (swritten) mm_sprintf_lite(s, "\n");
			else swritten = 1;
			mm_sprintf_lite(s, "%s\t%d\t%d\t%s\t%d\t%c", mi->seq[r->rid].name, t_off, t_off + len, t->name, score1 + score2, "+-"[rev]);
			t_off += len;
		}
	}
	assert(t_off == r->re);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, 0x10(%rsp)
movq $0x0, (%rdi)
testb $0x8, 0x3f(%rcx)
je 0xee29
movq %rcx, %rbx
movq 0x48(%rcx), %rax
testq %rax, %rax
je 0xee29
movl 0x14(%rax), %eax
shrl $0x1e, %eax
decl %eax
cmpl $0x1, %eax
ja 0xee29
movl 0x18(%rbx), %ebp
movq 0x48(%rbx), %rax
cmpl $0x0, 0x18(%rax)
jle 0xee20
movq %rdx, 0x30(%rsp)
xorl %r15d, %r15d
xorl %r8d, %r8d
movq %rbx, 0x28(%rsp)
movl 0x1c(%rax,%r15,4), %ecx
movl %ecx, %edx
shrl $0x4, %edx
testb $0x7, %cl
je 0xec0d
movl %ecx, %esi
andl $0xf, %esi
cmpl $0x7, %esi
je 0xec0d
cmpl $0x3, %esi
je 0xec2a
cmpl $0x2, %esi
jne 0xeca5
addl %ebp, %edx
movl %edx, %r13d
incq %r15
movq 0x48(%rbx), %rax
movslq 0x18(%rax), %rcx
movl %r13d, %ebp
cmpq %rcx, %r15
jl 0xebe6
jmp 0xee23
cmpl $0x1f, %ecx
jbe 0xee38
movq %rdi, %r12
movl %r8d, 0x24(%rsp)
movl 0x14(%rax), %eax
movl $0xc0000000, %ecx       # imm = 0xC0000000
andl %ecx, %eax
xorl %esi, %esi
negl %eax
seto %sil
movl 0x3c(%rbx), %eax
shrl $0xa, %eax
andl $0x1, %eax
leal 0x2(%rbp), %ecx
leal (%rdx,%rbp), %r13d
addl %ebp, %edx
addl $-0x2, %edx
movl %edx, 0xc(%rsp)
movl %eax, 0x20(%rsp)
movl %esi, 0x1c(%rsp)
cmpl %esi, %eax
jne 0xecad
movl 0x8(%rbx), %esi
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl %ebp, %edx
leaq 0xa(%rsp), %r8
callq 0x7224
movl 0x8(%rbx), %esi
movq %r14, %rdi
movl 0xc(%rsp), %edx
movl %r13d, %ecx
leaq 0x8(%rsp), %r8
callq 0x7224
jmp 0xed32
movl %ebp, %r13d
jmp 0xec12
movl 0x8(%rbx), %esi
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl %ebp, %edx
leaq 0x8(%rsp), %r8
callq 0x7224
movl 0x8(%rbx), %esi
movq %r14, %rdi
movl 0xc(%rsp), %edx
movl %r13d, %ecx
leaq 0xa(%rsp), %r8
callq 0x7224
movb 0xa(%rsp), %al
movb 0xb(%rsp), %cl
movb $0x3, %dl
subb %cl, %dl
cmpb $0x4, %cl
movzbl %dl, %ecx
movl $0x4, %esi
cmovael %esi, %ecx
movb $0x3, %dl
subb %al, %dl
cmpb $0x4, %al
movzbl %dl, %eax
cmovael %esi, %eax
movb %al, 0xb(%rsp)
movb %cl, 0xa(%rsp)
movb 0x8(%rsp), %al
movb 0x9(%rsp), %cl
movb $0x3, %dl
subb %cl, %dl
cmpb $0x4, %cl
movzbl %dl, %ecx
cmovael %esi, %ecx
movb $0x3, %dl
subb %al, %dl
cmpb $0x4, %al
movzbl %dl, %eax
cmovael %esi, %eax
movb %al, 0x9(%rsp)
movb %cl, 0x8(%rsp)
movb 0xa(%rsp), %al
movb 0xb(%rsp), %dl
movl %eax, %esi
xorb $0x2, %sil
movl %edx, %ecx
xorb $0x3, %cl
movl $0x3, %r8d
movl %esi, %edi
orb %cl, %dil
movl 0x24(%rsp), %edi
je 0xed6d
xorb $0x1, %dl
movl $0x2, %r8d
orb %dl, %sil
je 0xed6d
xorl %r8d, %r8d
orb %cl, %al
sete %r8b
movb 0x8(%rsp), %al
testb %al, %al
sete %cl
movb 0x9(%rsp), %dl
cmpb $0x1, %dl
sete %sil
andb %cl, %sil
cmpb $0x2, %dl
movzbl %sil, %ecx
movl %ecx, %r14d
movl $0x3, %edx
cmovel %edx, %r14d
testb %al, %al
cmovnel %ecx, %r14d
testl %edi, %edi
je 0xedbd
movq %r12, %rdi
leaq 0x1b600(%rip), %rsi     # 0x2a3ab
xorl %eax, %eax
movl %r8d, %ebx
callq 0xe671
movl %ebx, %r8d
movq 0x28(%rsp), %rbx
movl 0x20(%rsp), %esi
xorl 0x1c(%rsp), %esi
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x8(%rbx), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rdx
movq 0x30(%rsp), %rax
movq 0x8(%rax), %r9
addl %r8d, %r14d
movl %esi, %eax
leaq 0x1d99a(%rip), %rcx     # 0x2c789
movsbl (%rax,%rcx), %r10d
movq %r12, %rdi
leaq 0x1dc68(%rip), %rsi     # 0x2ca66
movl %ebp, %ecx
movl %r13d, %r8d
xorl %eax, %eax
pushq %r10
pushq %r14
callq 0xe671
addq $0x10, %rsp
movl $0x1, %r8d
movq %r12, %rdi
jmp 0xec12
movl %ebp, %r13d
cmpl 0x1c(%rbx), %r13d
jne 0xee57
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1dbbc(%rip), %rdi     # 0x2c9fb
leaq 0x1dbbe(%rip), %rsi     # 0x2ca04
leaq 0x1dbc0(%rip), %rcx     # 0x2ca0d
movl $0x114, %edx            # imm = 0x114
callq 0x21a0
leaq 0x1dc1a(%rip), %rdi     # 0x2ca78
leaq 0x1db9f(%rip), %rsi     # 0x2ca04
leaq 0x1dba1(%rip), %rcx     # 0x2ca0d
movl $0x12b, %edx            # imm = 0x12B
callq 0x21a0