// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/samtools-0.1.18/bam.c
// Function: bam_format1_core
char *bam_format1_core(const bam_header_t *header, const bam1_t *b, int of)
{
	uint8_t *s = bam1_seq(b), *t = bam1_qual(b);
	int i;
	const bam1_core_t *c = &b->core;
	kstring_t str;
	str.l = str.m = 0; str.s = 0;

	kputsn(bam1_qname(b), c->l_qname-1, &str); kputc('\t', &str);
	if (of == BAM_OFDEC) { kputw(c->flag, &str); kputc('\t', &str); }
	else if (of == BAM_OFHEX) ksprintf(&str, "0x%x\t", c->flag);
	else { // BAM_OFSTR
		for (i = 0; i < 16; ++i)
			if ((c->flag & 1<<i) && bam_flag2char_table[i])
				kputc(bam_flag2char_table[i], &str);
		kputc('\t', &str);
	}
	if (c->tid < 0) kputsn("*\t", 2, &str);
	else {
		if (header) kputs(header->target_name[c->tid] , &str);
		else kputw(c->tid, &str);
		kputc('\t', &str);
	}
	kputw(c->pos + 1, &str); kputc('\t', &str); kputw(c->qual, &str); kputc('\t', &str);
	if (c->n_cigar == 0) kputc('*', &str);
	else {
		for (i = 0; i < c->n_cigar; ++i) {
			kputw(bam1_cigar(b)[i]>>BAM_CIGAR_SHIFT, &str);
			kputc("MIDNSHP=X"[bam1_cigar(b)[i]&BAM_CIGAR_MASK], &str);
		}
	}
	kputc('\t', &str);
	if (c->mtid < 0) kputsn("*\t", 2, &str);
	else if (c->mtid == c->tid) kputsn("=\t", 2, &str);
	else {
		if (header) kputs(header->target_name[c->mtid], &str);
		else kputw(c->mtid, &str);
		kputc('\t', &str);
	}
	kputw(c->mpos + 1, &str); kputc('\t', &str); kputw(c->isize, &str); kputc('\t', &str);
	if (c->l_qseq) {
		for (i = 0; i < c->l_qseq; ++i) kputc(bam_nt16_rev_table[bam1_seqi(s, i)], &str);
		kputc('\t', &str);
		if (t[0] == 0xff) kputc('*', &str);
		else for (i = 0; i < c->l_qseq; ++i) kputc(t[i] + 33, &str);
	} else kputsn("*\t*", 3, &str);
	s = bam1_aux(b);
	while (s < b->data + b->data_len) {
		uint8_t type, key[2];
		key[0] = s[0]; key[1] = s[1];
		s += 2; type = *s; ++s;
		kputc('\t', &str); kputsn((char*)key, 2, &str); kputc(':', &str);
		if (type == 'A') { kputsn("A:", 2, &str); kputc(*s, &str); ++s; }
		else if (type == 'C') { kputsn("i:", 2, &str); kputw(*s, &str); ++s; }
		else if (type == 'c') { kputsn("i:", 2, &str); kputw(*(int8_t*)s, &str); ++s; }
		else if (type == 'S') { kputsn("i:", 2, &str); kputw(*(uint16_t*)s, &str); s += 2; }
		else if (type == 's') { kputsn("i:", 2, &str); kputw(*(int16_t*)s, &str); s += 2; }
		else if (type == 'I') { kputsn("i:", 2, &str); kputuw(*(uint32_t*)s, &str); s += 4; }
		else if (type == 'i') { kputsn("i:", 2, &str); kputw(*(int32_t*)s, &str); s += 4; }
		else if (type == 'f') { ksprintf(&str, "f:%g", *(float*)s); s += 4; }
		else if (type == 'd') { ksprintf(&str, "d:%lg", *(double*)s); s += 8; }
		else if (type == 'Z' || type == 'H') { kputc(type, &str); kputc(':', &str); while (*s) kputc(*s++, &str); ++s; }
		else if (type == 'B') {
			uint8_t sub_type = *(s++);
			int32_t n;
			memcpy(&n, s, 4);
			s += 4; // no point to the start of the array
			kputc(type, &str); kputc(':', &str); kputc(sub_type, &str); // write the typing
			for (i = 0; i < n; ++i) {
				kputc(',', &str);
				if ('c' == sub_type || 'c' == sub_type) { kputw(*(int8_t*)s, &str); ++s; }
				else if ('C' == sub_type) { kputw(*(uint8_t*)s, &str); ++s; }
				else if ('s' == sub_type) { kputw(*(int16_t*)s, &str); s += 2; }
				else if ('S' == sub_type) { kputw(*(uint16_t*)s, &str); s += 2; }
				else if ('i' == sub_type) { kputw(*(int32_t*)s, &str); s += 4; }
				else if ('I' == sub_type) { kputuw(*(uint32_t*)s, &str); s += 4; }
				else if ('f' == sub_type) { ksprintf(&str, "%g", *(float*)s); s += 4; }
			}
		}
	}
	return str.s;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r15
movq 0x30(%rsi), %r13
movq 0x8(%rsi), %rax
movq %rax, 0x38(%rsp)
shrl $0x18, %eax
movl 0x10(%rsi), %r14d
movq %rax, 0x40(%rsp)
leal -0x1(%rax), %esi
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r12
movaps %xmm0, (%r12)
andq $0x0, 0x10(%r12)
movq %r13, %rdi
movq %r12, %rdx
callq 0x1f58fc
pushq $0x9
popq %rdi
movq %r12, %rsi
callq 0x1f5990
testl %ebp, %ebp
movq %r15, 0x30(%rsp)
je 0x1f52e5
cmpl $0x1, %ebp
jne 0x1f5303
movzwl 0xc(%rbx), %edx
leaq 0x1752e1(%rip), %rsi    # 0x36a5b8
leaq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0x2d6df0
jmp 0x1f5353
movzwl 0xc(%rbx), %edi
leaq 0x10(%rsp), %r12
movq %r12, %rsi
callq 0x1f5a13
pushq $0x9
popq %rdi
movq %r12, %rsi
callq 0x1f5990
jmp 0x1f5353
movq %r13, %rbp
xorl %r15d, %r15d
leaq 0x244d18(%rip), %r13    # 0x43a028
leaq 0x10(%rsp), %r12
cmpq $0x10, %r15
je 0x1f533e
movl 0xc(%rbx), %eax
btl %r15d, %eax
jae 0x1f5339
movq (%r13), %rax
movsbl (%rax,%r15), %edi
testl %edi, %edi
je 0x1f5339
movq %r12, %rsi
callq 0x1f5990
incq %r15
jmp 0x1f5315
pushq $0x9
popq %rdi
leaq 0x10(%rsp), %rsi
callq 0x1f5990
movq %rbp, %r13
movq 0x30(%rsp), %r15
movslq (%rbx), %rdi
testq %rdi, %rdi
js 0x1f5374
testq %r15, %r15
je 0x1f538a
movq 0x8(%r15), %rax
movq (%rax,%rdi,8), %rdi
leaq 0x10(%rsp), %rsi
callq 0x1f5af1
jmp 0x1f5394
leaq 0x175243(%rip), %rdi    # 0x36a5be
pushq $0x2
popq %rsi
leaq 0x10(%rsp), %rdx
callq 0x1f58fc
jmp 0x1f53a1
leaq 0x10(%rsp), %rsi
callq 0x1f5a13
pushq $0x9
popq %rdi
leaq 0x10(%rsp), %rsi
callq 0x1f5990
movl 0x4(%rbx), %edi
incl %edi
leaq 0x10(%rsp), %r12
movq %r12, %rsi
callq 0x1f5a13
pushq $0x9
popq %rbp
movl %ebp, %edi
movq %r12, %rsi
callq 0x1f5990
movzbl 0xa(%rbx), %edi
movq %r12, %rsi
callq 0x1f5a13
movl %ebp, %edi
movq %r12, %rsi
callq 0x1f5990
movq 0x8(%rbx), %rax
movq %rax, %rcx
shrq $0x30, %rcx
jne 0x1f5413
pushq $0x2a
popq %rdi
leaq 0x10(%rsp), %rsi
callq 0x1f5990
pushq $0x9
popq %rdi
leaq 0x10(%rsp), %rsi
callq 0x1f5990
movslq 0x14(%rbx), %rdi
testq %rdi, %rdi
js 0x1f5466
cmpl (%rbx), %edi
jne 0x1f547c
leaq 0x1751ba(%rip), %rdi    # 0x36a5cb
jmp 0x1f546d
xorl %ebp, %ebp
leaq 0x10(%rsp), %r12
leaq 0x1751a0(%rip), %r15    # 0x36a5c1
movq %rax, %rcx
shrq $0x30, %rcx
cmpq %rcx, %rbp
jae 0x1f53f0
shrl $0x18, %eax
addq 0x30(%rbx), %rax
movl (%rax,%rbp,4), %edi
shrl $0x4, %edi
movq %r12, %rsi
callq 0x1f5a13
movzbl 0xb(%rbx), %eax
addq 0x30(%rbx), %rax
movl (%rax,%rbp,4), %eax
andl $0xf, %eax
movsbl (%rax,%r15), %edi
movq %r12, %rsi
callq 0x1f5990
incq %rbp
movq 0x8(%rbx), %rax
jmp 0x1f5421
leaq 0x175151(%rip), %rdi    # 0x36a5be
pushq $0x2
popq %rsi
leaq 0x10(%rsp), %rdx
callq 0x1f58fc
jmp 0x1f54b1
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0x1f549a
movq 0x8(%rax), %rax
movq (%rax,%rdi,8), %rdi
leaq 0x10(%rsp), %rsi
callq 0x1f5af1
jmp 0x1f54a4
leaq 0x10(%rsp), %rsi
callq 0x1f5a13
pushq $0x9
popq %rdi
leaq 0x10(%rsp), %rsi
callq 0x1f5990
movl 0x18(%rbx), %edi
incl %edi
leaq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0x1f5a13
pushq $0x9
popq %r12
movl %r12d, %edi
movq %r15, %rsi
callq 0x1f5990
movl 0x1c(%rbx), %edi
movq %r15, %rsi
callq 0x1f5a13
movl %r12d, %edi
movq %r15, %rsi
callq 0x1f5990
movl 0x10(%rbx), %eax
testl %eax, %eax
je 0x1f55a8
movq 0x38(%rsp), %rcx
shrq $0x30, %rcx
incl %r14d
leaq (,%rcx,4), %rcx
addq %r13, %rcx
movq 0x40(%rsp), %rdx
addq %rcx, %rdx
sarl %r14d
movslq %r14d, %rcx
movq %rdx, %r15
addq %rdx, %rcx
movq %rcx, 0x30(%rsp)
xorl %ebp, %ebp
leaq 0x244e04(%rip), %r12    # 0x43a330
leaq 0x10(%rsp), %r14
xorl %r13d, %r13d
cmpl %eax, %r13d
jge 0x1f556a
movl %r13d, %eax
shrl %eax
movzbl (%r15,%rax), %eax
movl %ebp, %ecx
notb %cl
andb $0x4, %cl
shrl %cl, %eax
movq (%r12), %rcx
andl $0xf, %eax
movsbl (%rcx,%rax), %edi
movq %r14, %rsi
callq 0x1f5990
incl %r13d
movl 0x10(%rbx), %eax
addl $0x4, %ebp
jmp 0x1f5534
pushq $0x9
popq %rdi
leaq 0x10(%rsp), %rsi
callq 0x1f5990
movq 0x30(%rsp), %r15
cmpb $-0x1, (%r15)
je 0x1f55be
xorl %r12d, %r12d
leaq 0x10(%rsp), %r14
movslq 0x10(%rbx), %rax
cmpq %rax, %r12
jge 0x1f55cb
movzbl (%r15,%r12), %edi
addl $0x21, %edi
movq %r14, %rsi
callq 0x1f5990
incq %r12
jmp 0x1f558a
leaq 0x17501f(%rip), %rdi    # 0x36a5ce
pushq $0x3
popq %rsi
leaq 0x10(%rsp), %rdx
callq 0x1f58fc
jmp 0x1f55cb
pushq $0x2a
popq %rdi
leaq 0x10(%rsp), %rsi
callq 0x1f5990
movq 0x8(%rbx), %rsi
movq 0x30(%rbx), %rcx
movq %rsi, %rax
shrq $0x30, %rax
leaq (%rcx,%rax,4), %rax
shrl $0x18, %esi
movslq 0x10(%rbx), %rdx
addq %rdx, %rsi
addq %rax, %rsi
leal 0x1(%rdx), %eax
cltd
pushq $0x2
popq %r14
idivl %r14d
movslq %eax, %r13
addq %rsi, %r13
leaq 0x10(%rsp), %r15
movslq 0x24(%rbx), %rax
addq %rcx, %rax
cmpq %rax, %r13
jae 0x1f58e8
movb (%r13), %al
movb %al, 0xe(%rsp)
movb 0x1(%r13), %al
movb %al, 0xf(%rsp)
movzbl 0x2(%r13), %r12d
leaq 0x3(%r13), %rbp
pushq $0x9
popq %rdi
movq %r15, %rsi
callq 0x1f5990
leaq 0xe(%rsp), %rdi
movl %r14d, %esi
movq %r15, %rdx
callq 0x1f58fc
pushq $0x3a
popq %rdi
movq %r15, %rsi
callq 0x1f5990
leal -0x41(%r12), %eax
cmpl $0x8, %eax
jbe 0x1f5690
leal -0x63(%r12), %eax
cmpl $0x6, %eax
ja 0x1f56c1
leaq 0x174e69(%rip), %rcx    # 0x36a4d4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x1565f4(%rip), %rdi    # 0x34bc6f
movl %r14d, %esi
movq %r15, %rdx
callq 0x1f58fc
movsbl 0x3(%r13), %edi
jmp 0x1f5734
leaq 0x174e19(%rip), %rcx    # 0x36a4b0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x174f2b(%rip), %rdi    # 0x36a5d2
movl %r14d, %esi
movq %r15, %rdx
callq 0x1f58fc
movzbl 0x3(%r13), %edi
movq %r15, %rsi
callq 0x1f5990
jmp 0x1f573c
cmpl $0x53, %r12d
je 0x1f58b6
cmpl $0x5a, %r12d
je 0x1f56f7
cmpl $0x73, %r12d
jne 0x1f58dc
leaq 0x15658d(%rip), %rdi    # 0x34bc6f
movl %r14d, %esi
movq %r15, %rdx
callq 0x1f58fc
movswl 0x3(%r13), %edi
jmp 0x1f58cd
movl %r12d, %edi
movq %r15, %rsi
callq 0x1f5990
pushq $0x3a
popq %rdi
movq %r15, %rsi
callq 0x1f5990
movzbl (%rbp), %edi
incq %rbp
testl %edi, %edi
jne 0x1f5705
jmp 0x1f58dc
leaq 0x15654b(%rip), %rdi    # 0x34bc6f
movl %r14d, %esi
movq %r15, %rdx
callq 0x1f58fc
movzbl 0x3(%r13), %edi
movq %r15, %rsi
callq 0x1f5a13
addq $0x4, %r13
jmp 0x1f58d9
movzbl 0x3(%r13), %r12d
movl 0x4(%r13), %r14d
addq $0x8, %r13
pushq $0x42
popq %rdi
movq %r15, %rsi
callq 0x1f5990
pushq $0x3a
popq %rdi
movq %r15, %rsi
callq 0x1f5990
movl %r12d, %edi
movq %r15, %rsi
callq 0x1f5990
testl %r14d, %r14d
movl $0x0, %eax
cmovlel %eax, %r14d
movq %r13, %rbp
pushq $0x2c
popq %r13
subl $0x1, %r14d
jb 0x1f5833
movl %r13d, %edi
movq %r15, %rsi
callq 0x1f5990
cmpl $0x43, %r12d
je 0x1f57f6
cmpl $0x49, %r12d
je 0x1f581f
cmpl $0x53, %r12d
je 0x1f580a
cmpl $0x73, %r12d
je 0x1f57cb
cmpl $0x66, %r12d
je 0x1f57de
cmpl $0x69, %r12d
je 0x1f57d1
cmpl $0x63, %r12d
jne 0x1f5786
movsbl (%rbp), %edi
jmp 0x1f57fa
movswl (%rbp), %edi
jmp 0x1f580e
movl (%rbp), %edi
movq %r15, %rsi
callq 0x1f5a13
jmp 0x1f582a
cvtss2sd (%rbp), %xmm0
movq %r15, %rdi
leaq 0x174dea(%rip), %rsi    # 0x36a5d7
movb $0x1, %al
callq 0x2d6df0
jmp 0x1f582a
movzbl (%rbp), %edi
movq %r15, %rsi
callq 0x1f5a13
incq %rbp
jmp 0x1f5786
movzwl (%rbp), %edi
movq %r15, %rsi
callq 0x1f5a13
addq $0x2, %rbp
jmp 0x1f5786
movl (%rbp), %edi
movq %r15, %rsi
callq 0x1f5b14
addq $0x4, %rbp
jmp 0x1f5786
pushq $0x2
popq %r14
jmp 0x1f58dc
leaq 0x15642c(%rip), %rdi    # 0x34bc6f
movl %r14d, %esi
movq %r15, %rdx
callq 0x1f58fc
movl 0x3(%r13), %edi
movq %r15, %rsi
callq 0x1f5b14
jmp 0x1f58b0
movsd 0x3(%r13), %xmm0
movq %r15, %rdi
leaq 0x174d6e(%rip), %rsi    # 0x36a5da
movb $0x1, %al
callq 0x2d6df0
addq $0xb, %r13
jmp 0x1f58d9
leaq 0x1563ef(%rip), %rdi    # 0x34bc6f
movl %r14d, %esi
movq %r15, %rdx
callq 0x1f58fc
movl 0x3(%r13), %edi
movq %r15, %rsi
callq 0x1f5a13
jmp 0x1f58b0
cvtss2sd 0x3(%r13), %xmm0
movq %r15, %rdi
leaq 0x174d2c(%rip), %rsi    # 0x36a5d5
movb $0x1, %al
callq 0x2d6df0
addq $0x7, %r13
jmp 0x1f58d9
leaq 0x1563b2(%rip), %rdi    # 0x34bc6f
movl %r14d, %esi
movq %r15, %rdx
callq 0x1f58fc
movzwl 0x3(%r13), %edi
movq %r15, %rsi
callq 0x1f5a13
addq $0x5, %r13
movq %r13, %rbp
movq 0x30(%rbx), %rcx
movq %rbp, %r13
jmp 0x1f5601
movq 0x20(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq