// File: /workspace/github_cpp_makefile_star2_O1/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/bamtk.c
// Function: bam_tagview
int bam_tagview(int argc, char *argv[])
{
	bamFile fp;
	bam_header_t *header;
	bam1_t *b;
	char tag[2];
	int ret;
	if (argc < 3) {
		fprintf(stderr, "Usage: samtools tagview <in.bam> <tag>\n");
		return 1;
	}
	fp = strcmp(argv[1], "-")? bam_open(argv[1], "r") : bam_dopen(fileno(stdin), "r");
	assert(fp);
	header = bam_header_read(fp);
	if (header == 0) {
		fprintf(stderr, "[bam_view] fail to read the BAM header. Abort!\n");
		return 1;
	}
	tag[0] = argv[2][0]; tag[1] = argv[2][1];
	b = (bam1_t*)calloc(1, sizeof(bam1_t));
	while ((ret = bam_read1(fp, b)) >= 0) {
		uint8_t *d = bam_aux_get(b, tag);
		if (d) {
			printf("%s\t%d\t", bam1_qname(b), b->core.flag);
			if (d[0] == 'Z' || d[0] == 'H') printf("%s\n", bam_aux2Z(d));
			else if (d[0] == 'f') printf("%f\n", bam_aux2f(d));
			else if (d[0] == 'd') printf("%lf\n", bam_aux2d(d));
			else if (d[0] == 'A') printf("%c\n", bam_aux2A(d));
			else if (d[0] == 'c' || d[0] == 's' || d[0] == 'i') printf("%d\n", bam_aux2i(d));
			else if (d[0] == 'C' || d[0] == 'S' || d[0] == 'I') printf("%u\n", bam_aux2i(d));
			else printf("\n");
		}
	}
	if (ret < -1) fprintf(stderr, "[bam_view] truncated file? Continue anyway. (%d)\n", ret);
	free(b->data); free(b);
	bam_header_destroy(header);
	bam_close(fp);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cmpl $0x2, %edi
jle 0xe196
movq %rsi, %r15
movq 0x8(%rsi), %rbx
leaq 0x16e0d(%rip), %rsi     # 0x24db6
movq %rbx, %rdi
callq 0x34e0
testl %eax, %eax
je 0xdfc6
leaq 0x1a00b(%rip), %rsi     # 0x27fc7
movq %rbx, %rdi
callq 0xfa04
jmp 0xdfe3
movq 0x21003(%rip), %rax     # 0x2efd0
movq (%rax), %rdi
callq 0x3030
leaq 0x19feb(%rip), %rsi     # 0x27fc7
movl %eax, %edi
callq 0xfb6d
movq %rax, %rbx
testq %rax, %rax
je 0xe1c5
movq %rbx, %rdi
callq 0x11d21
testq %rax, %rax
je 0xe19d
movq %rax, %r14
movq 0x10(%r15), %rax
movb (%rax), %cl
movb %cl, 0xe(%rsp)
movb 0x1(%rax), %al
movb %al, 0xf(%rsp)
movl $0x1, %edi
movl $0x38, %esi
callq 0x3530
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1204b
testl %eax, %eax
js 0xe15f
movq %r14, 0x10(%rsp)
leaq 0xe(%rsp), %r12
leaq 0x17cfc(%rip), %r13     # 0x25d46
leaq 0x17c5b(%rip), %r14     # 0x25cac
movq %r15, %rdi
movq %r12, %rsi
callq 0x1110a
testq %rax, %rax
je 0xe147
movq %rax, %rbp
movq 0x30(%r15), %rsi
movzwl 0xc(%r15), %edx
movq %r13, %rdi
xorl %eax, %eax
callq 0x3040
movzbl (%rbp), %eax
cmpl $0x59, %eax
jle 0xe0a9
leal -0x63(%rax), %ecx
cmpl $0x6, %ecx
ja 0xe0d5
movslq (%r14,%rcx,4), %rax
addq %r14, %rax
jmpq *%rax
movq %rbp, %rdi
callq 0x11983
leaq 0x17cad(%rip), %rdi     # 0x25d51
jmp 0xe140
leal -0x41(%rax), %ecx
cmpl $0x8, %ecx
ja 0xe102
leaq 0x17bd0(%rip), %rdx     # 0x25c88
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq %rbp, %rdi
callq 0x11991
movsbl %al, %esi
leaq 0x17c83(%rip), %rdi     # 0x25d56
jmp 0xe118
cmpl $0x73, %eax
je 0xe0f1
cmpl $0x5a, %eax
jne 0xe121
movq %rbp, %rdi
callq 0x1199d
movq %rax, %rdi
callq 0x30e0
jmp 0xe147
movq %rbp, %rdi
callq 0x1192e
leaq 0x191e9(%rip), %rdi     # 0x272e9
jmp 0xe116
cmpl $0x53, %eax
jne 0xe121
movq %rbp, %rdi
callq 0x1192e
leaq 0x17c44(%rip), %rdi     # 0x25d5a
movl %eax, %esi
xorl %eax, %eax
callq 0x3040
jmp 0xe147
movl $0xa, %edi
callq 0x3170
jmp 0xe147
movq %rbp, %rdi
callq 0x11975
cvtss2sd %xmm0, %xmm0
leaq 0x17c0d(%rip), %rdi     # 0x25d4d
movb $0x1, %al
callq 0x3040
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1204b
testl %eax, %eax
jns 0xe051
movq 0x10(%rsp), %r14
cmpl $-0x1, %eax
jne 0xe1a9
movq 0x30(%r15), %rdi
callq 0x32c0
movq %r15, %rdi
callq 0x32c0
movq %r14, %rdi
callq 0x11c9f
movq %rbx, %rdi
callq 0x1050e
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3c3f
jmp 0xe1a2
callq 0x3c23
movl $0x1, %eax
jmp 0xe187
movq 0x20e38(%rip), %rcx     # 0x2efe8
movq (%rcx), %rdi
leaq 0x17ba4(%rip), %rsi     # 0x25d5e
movl %eax, %edx
xorl %eax, %eax
callq 0x3630
jmp 0xe164
leaq 0x15ef5(%rip), %rdi     # 0x240c1
leaq 0x17b1d(%rip), %rsi     # 0x25cf0
leaq 0x17b1e(%rip), %rcx     # 0x25cf8
movl $0x2c, %edx
callq 0x3140