// File: /workspace/github_c_makefile_star2_O3/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 0xed4b
movq %rcx, %rbx
movq 0x48(%rcx), %rax
testq %rax, %rax
je 0xed4b
movl 0x14(%rax), %ecx
shrl $0x1e, %ecx
decl %ecx
cmpl $0x1, %ecx
ja 0xed4b
movl 0x18(%rbx), %ebp
cmpl $0x0, 0x18(%rax)
jle 0xed42
movq %rdx, 0x28(%rsp)
xorl %r15d, %r15d
xorl %r8d, %r8d
movq %rbx, 0x30(%rsp)
movq %rdi, 0x20(%rsp)
movl 0x1c(%rax,%r15,4), %ecx
movl %ecx, %edx
shrl $0x4, %edx
testb $0x7, %cl
je 0xeb21
movl %ecx, %esi
andl $0xf, %esi
cmpl $0x7, %esi
je 0xeb21
cmpl $0x3, %esi
je 0xeb3a
cmpl $0x2, %esi
jne 0xebbb
addl %ebp, %edx
movl %edx, %r13d
incq %r15
movslq 0x18(%rax), %rcx
movl %r13d, %ebp
cmpq %rcx, %r15
jl 0xeafa
jmp 0xed45
cmpl $0x1f, %ecx
jbe 0xed5a
movl %r8d, 0x8(%rsp)
movl 0x14(%rax), %eax
movl $0xc0000000, %ecx       # imm = 0xC0000000
andl %ecx, %eax
xorl %edi, %edi
negl %eax
seto %dil
movl 0x8(%rbx), %esi
movl 0x3c(%rbx), %r12d
shrl $0xa, %r12d
andl $0x1, %r12d
leal 0x2(%rbp), %ecx
leal (%rdx,%rbp), %r13d
leal (%rdx,%rbp), %eax
addl $-0x2, %eax
movl %eax, 0xc(%rsp)
movl %edi, 0x1c(%rsp)
cmpl %edi, %r12d
jne 0xebc3
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl %ebp, %edx
leaq 0x6(%rsp), %r8
callq 0x71d0
movl 0x8(%rbx), %esi
movq %r14, %rdi
movl 0xc(%rsp), %edx
movl %r13d, %ecx
leaq 0x4(%rsp), %r8
callq 0x71d0
movb 0x6(%rsp), %al
movb 0x7(%rsp), %cl
jmp 0xec54
movl %ebp, %r13d
jmp 0xeb26
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl %ebp, %edx
leaq 0x4(%rsp), %r8
callq 0x71d0
movl 0x8(%rbx), %esi
movq %r14, %rdi
movl 0xc(%rsp), %edx
movl %r13d, %ecx
leaq 0x6(%rsp), %r8
callq 0x71d0
movb 0x6(%rsp), %cl
movb 0x7(%rsp), %al
movb $0x3, %dl
subb %al, %dl
cmpb $0x4, %al
movzbl %dl, %eax
movl $0x4, %r8d
cmovael %r8d, %eax
movb $0x3, %dl
subb %cl, %dl
cmpb $0x4, %cl
movzbl %dl, %ecx
cmovael %r8d, %ecx
movb %cl, 0x7(%rsp)
movb %al, 0x6(%rsp)
movb 0x4(%rsp), %dl
movb 0x5(%rsp), %sil
movb $0x3, %dil
subb %sil, %dil
cmpb $0x4, %sil
movzbl %dil, %esi
cmovael %r8d, %esi
movb $0x3, %dil
subb %dl, %dil
cmpb $0x4, %dl
movzbl %dil, %edx
cmovael %r8d, %edx
movb %dl, 0x5(%rsp)
movb %sil, 0x4(%rsp)
cmpb $0x2, %al
movl 0x8(%rsp), %edi
jne 0xec67
movl $0x3, %r8d
cmpb $0x3, %cl
je 0xec82
cmpb $0x2, %al
jne 0xec76
movl $0x2, %r8d
cmpb $0x1, %cl
je 0xec82
xorb $0x3, %cl
xorl %r8d, %r8d
orb %cl, %al
sete %r8b
movb 0x4(%rsp), %al
testb %al, %al
sete %cl
movb 0x5(%rsp), %dl
cmpb $0x1, %dl
sete %sil
andb %cl, %sil
cmpb $0x2, %dl
movzbl %sil, %ecx
movl %ecx, %ebx
movl $0x3, %edx
cmovel %edx, %ebx
testb %al, %al
cmovnel %ecx, %ebx
testl %edi, %edi
movq 0x20(%rsp), %r14
je 0xecd9
movq %r14, %rdi
leaq 0x1c6e9(%rip), %rsi     # 0x2b3ab
xorl %eax, %eax
movl %r12d, 0x8(%rsp)
movl %r8d, %r12d
callq 0xe575
movl %r12d, %r8d
movl 0x8(%rsp), %r12d
xorl 0x1c(%rsp), %r12d
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x30(%rsp), %r11
movslq 0x8(%r11), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rdx
movq 0x28(%rsp), %rax
movq 0x8(%rax), %r9
addl %r8d, %ebx
movl %r12d, %eax
leaq 0x1ea9b(%rip), %rcx     # 0x2d7a9
movsbl (%rax,%rcx), %r10d
movq %r14, %rdi
leaq 0x1ed69(%rip), %rsi     # 0x2da86
movl %ebp, %ecx
movl %r13d, %r8d
xorl %eax, %eax
pushq %r10
pushq %rbx
movq %r11, %rbx
callq 0xe575
addq $0x10, %rsp
movq 0x48(%rbx), %rax
movl $0x1, %r8d
jmp 0xeb26
movl %ebp, %r13d
cmpl 0x1c(%rbx), %r13d
jne 0xed79
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1ecba(%rip), %rdi     # 0x2da1b
leaq 0x1ecbc(%rip), %rsi     # 0x2da24
leaq 0x1ecbe(%rip), %rcx     # 0x2da2d
movl $0x114, %edx            # imm = 0x114
callq 0x21a0
leaq 0x1ed18(%rip), %rdi     # 0x2da98
leaq 0x1ec9d(%rip), %rsi     # 0x2da24
leaq 0x1ec9f(%rip), %rcx     # 0x2da2d
movl $0x12b, %edx            # imm = 0x12B
callq 0x21a0