// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/sam_view.c
// Function: main_bam2fq
int main_bam2fq(int argc, char *argv[])
{
	bamFile fp;
	bam_header_t *h;
	bam1_t *b;
	int8_t *buf;
	int max_buf, c, no12 = 0;
	while ((c = getopt(argc, argv, "n")) > 0)
		if (c == 'n') no12 = 1;
	if (argc == 1) {
		fprintf(stderr, "Usage: samtools bam2fq <in.bam>\n");
		return 1;
	}
	fp = strcmp(argv[optind], "-")? bam_open(argv[optind], "r") : bam_dopen(fileno(stdin), "r");
	if (fp == 0) return 1;
	h = bam_header_read(fp);
	b = bam_init1();
	buf = 0;
	max_buf = 0;
	while (bam_read1(fp, b) >= 0) {
		int i, qlen = b->core.l_qseq;
		uint8_t *seq;
		putchar('@'); fputs(bam1_qname(b), stdout);
		if (no12) putchar('\n');
		else {
			if ((b->core.flag & 0x40) && !(b->core.flag & 0x80)) puts("/1");
			else if ((b->core.flag & 0x80) && !(b->core.flag & 0x40)) puts("/2");
			else putchar('\n');
		}
		if (max_buf < qlen + 1) {
			max_buf = qlen + 1;
			kroundup32(max_buf);
			buf = realloc(buf, max_buf);
		}
		buf[qlen] = 0;
		seq = bam1_seq(b);
		for (i = 0; i < qlen; ++i)
			buf[i] = bam1_seqi(seq, i);
		if (b->core.flag & 16) { // reverse complement
			for (i = 0; i < qlen>>1; ++i) {
				int8_t t = seq_comp_table[buf[qlen - 1 - i]];
				buf[qlen - 1 - i] = seq_comp_table[buf[i]];
				buf[i] = t;
			}
			if (qlen&1) buf[i] = seq_comp_table[buf[i]];
		}
		for (i = 0; i < qlen; ++i)
			buf[i] = bam_nt16_rev_table[buf[i]];
		puts((char*)buf);
		puts("+");
		seq = bam1_qual(b);
		for (i = 0; i < qlen; ++i)
			buf[i] = 33 + seq[i];
		if (b->core.flag & 16) { // reverse
			for (i = 0; i < qlen>>1; ++i) {
				int8_t t = buf[qlen - 1 - i];
				buf[qlen - 1 - i] = buf[i];
				buf[i] = t;
			}
		}
		puts((char*)buf);
	}
	free(buf);
	bam_destroy1(b);
	bam_header_destroy(h);
	bam_close(fp);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x38552(%rip), %rdx     # 0x433c1
callq 0x3210
testl %eax, %eax
jle 0xaeaa
xorl %r15d, %r15d
movl $0x1, %r12d
leaq 0x38539(%rip), %r14     # 0x433c1
cmpl $0x6e, %eax
cmovel %r12d, %r15d
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3210
testl %eax, %eax
jg 0xae88
testl %r15d, %r15d
sete 0x7(%rsp)
jmp 0xaeaf
movb $0x1, 0x7(%rsp)
cmpl $0x1, %ebp
je 0xb1ac
movq 0x450f9(%rip), %rax     # 0x4ffb8
movslq (%rax), %rax
movq (%rbx,%rax,8), %rdi
cmpb $0x2d, (%rdi)
jne 0xaed5
cmpb $0x0, 0x1(%rdi)
je 0xb18a
leaq 0x3ae73(%rip), %rsi     # 0x45d4f
callq 0x20308
movq %rax, %rbx
testq %rax, %rax
je 0xb1b1
movq %rbx, %rdi
callq 0x235fb
movq %rax, 0x8(%rsp)
movl $0x1, %edi
movl $0x38, %esi
callq 0x3610
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2393b
xorl %r13d, %r13d
testl %eax, %eax
js 0xb153
leaq 0x461b7(%rip), %rbp     # 0x510e0
leaq 0x45570(%rip), %r12     # 0x504a0
xorl %r14d, %r14d
movq %rbx, 0x10(%rsp)
movslq 0x10(%r15), %rbx
movl $0x40, %edi
callq 0x31e0
movq 0x30(%r15), %rdi
movq 0x450a7(%rip), %rax     # 0x4fff8
movq (%rax), %rsi
callq 0x34a0
cmpb $0x0, 0x7(%rsp)
je 0xaf84
movq 0x8(%r15), %rax
shrq $0x20, %rax
movl %eax, %ecx
andb $-0x40, %cl
negb %cl
jo 0xaf90
andl $0xc0, %eax
cmpl $0x40, %eax
jne 0xaf84
leaq 0x3555b(%rip), %rdi     # 0x404dd
jmp 0xaf97
movl $0xa, %edi
callq 0x31e0
jmp 0xaf9c
leaq 0x35549(%rip), %rdi     # 0x404e0
callq 0x3150
cmpl %ebx, %r13d
jg 0xafd7
movl %ebx, %eax
sarl %eax
orl %ebx, %eax
movl %eax, %ecx
sarl $0x2, %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x4, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x8, %ecx
orl %eax, %ecx
movl %ecx, %r13d
sarl $0x10, %r13d
orl %ecx, %r13d
incl %r13d
movslq %r13d, %rsi
movq %r14, %rdi
callq 0x3720
movq %rax, %r14
movb $0x0, (%r14,%rbx)
movq 0x8(%r15), %rax
testl %ebx, %ebx
jle 0xb026
movq %rax, %rcx
shrq $0x30, %rcx
shlq $0x2, %rcx
addq 0x30(%r15), %rcx
shrl $0x18, %eax
addq %rcx, %rax
xorl %edx, %edx
xorl %esi, %esi
movl %esi, %ecx
shrl %ecx
movb (%rax,%rcx), %dil
movl %edx, %ecx
notb %cl
andb $0x4, %cl
shrb %cl, %dil
andb $0xf, %dil
movb %dil, (%r14,%rsi)
incq %rsi
addb $0x4, %dl
cmpq %rsi, %rbx
jne 0xaffd
movq 0x8(%r15), %rax
movabsq $0x1000000000, %rcx     # imm = 0x1000000000
testq %rcx, %rax
je 0xb081
movl %ebx, %eax
sarl %eax
testl %eax, %eax
jle 0xb06d
movl %eax, %eax
leal -0x1(%rbx), %ecx
xorl %edx, %edx
movslq %ecx, %rcx
movsbq (%r14,%rcx), %rsi
movb (%rsi,%r12), %sil
movsbq (%r14,%rdx), %rdi
movb (%rdi,%r12), %dil
movb %dil, (%r14,%rcx)
movb %sil, (%r14,%rdx)
incq %rdx
decl %ecx
cmpq %rdx, %rax
jne 0xb044
jmp 0xb06f
xorl %eax, %eax
testb $0x1, %bl
je 0xb081
movsbq (%r14,%rax), %rcx
movb (%rcx,%r12), %cl
movb %cl, (%r14,%rax)
testl %ebx, %ebx
jle 0xb09f
xorl %eax, %eax
movq (%rbp), %rcx
movsbq (%r14,%rax), %rdx
movb (%rcx,%rdx), %cl
movb %cl, (%r14,%rax)
incq %rax
cmpq %rax, %rbx
jne 0xb087
movq %r14, %rdi
callq 0x3150
leaq 0x35435(%rip), %rdi     # 0x404e3
callq 0x3150
movq 0x8(%r15), %rax
testl %ebx, %ebx
jle 0xb0f6
movq %rax, %rdx
shrq $0x30, %rdx
shlq $0x2, %rdx
addq 0x30(%r15), %rdx
shrl $0x18, %eax
movl 0x10(%r15), %ecx
incl %ecx
sarl %ecx
movslq %ecx, %rcx
addq %rax, %rcx
addq %rdx, %rcx
xorl %eax, %eax
movb (%rcx,%rax), %dl
addb $0x21, %dl
movb %dl, (%r14,%rax)
incq %rax
cmpq %rax, %rbx
jne 0xb0e0
movq 0x8(%r15), %rax
movabsq $0x1000000000, %rcx     # imm = 0x1000000000
testq %rcx, %rax
je 0xb131
movl %ebx, %eax
sarl %eax
testl %eax, %eax
jle 0xb131
movl %eax, %eax
leal -0x1(%rbx), %ecx
xorl %edx, %edx
movslq %ecx, %rcx
movb (%r14,%rcx), %sil
movb (%r14,%rdx), %dil
movb %dil, (%r14,%rcx)
movb %sil, (%r14,%rdx)
incq %rdx
decl %ecx
cmpq %rdx, %rax
jne 0xb114
movq %r14, %rdi
callq 0x3150
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2393b
testl %eax, %eax
jns 0xaf38
jmp 0xb156
xorl %r14d, %r14d
movq %r14, %rdi
callq 0x3350
testq %r15, %r15
je 0xb174
movq 0x30(%r15), %rdi
callq 0x3350
movq %r15, %rdi
callq 0x3350
movq 0x8(%rsp), %rdi
callq 0x23577
movq %rbx, %rdi
callq 0x21311
xorl %eax, %eax
jmp 0xb1b6
movq 0x44e3f(%rip), %rax     # 0x4ffd0
movq (%rax), %rdi
callq 0x3030
leaq 0x3abaf(%rip), %rsi     # 0x45d4f
movl %eax, %edi
callq 0x20487
jmp 0xaee1
callq 0x3daa
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq