// File: /workspace/github_cpp_makefile_star2_O3/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 0xe756
movq %rsi, %r15
movq 0x8(%rsi), %rdi
cmpb $0x2d, (%rdi)
jne 0xe575
cmpb $0x0, 0x1(%rdi)
je 0xe734
leaq 0x18b4b(%rip), %rsi     # 0x270c7
callq 0x10048
movq %rax, %rbx
testq %rax, %rax
je 0xe788
movq %rbx, %rdi
callq 0x12383
testq %rax, %rax
je 0xe75d
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 0x126b5
testl %eax, %eax
js 0xe6fd
movq %r14, 0x10(%rsp)
leaq 0xe(%rsp), %r12
leaq 0x167ae(%rip), %r13     # 0x24d96
leaq 0x1670d(%rip), %r14     # 0x24cfc
movq %r15, %rdi
movq %r12, %rsi
callq 0x1175c
testq %rax, %rax
je 0xe6e5
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 0xe647
leal -0x63(%rax), %ecx
cmpl $0x6, %ecx
ja 0xe673
movslq (%r14,%rcx,4), %rax
addq %r14, %rax
jmpq *%rax
movq %rbp, %rdi
callq 0x12237
leaq 0x1675f(%rip), %rdi     # 0x24da1
jmp 0xe6de
leal -0x41(%rax), %ecx
cmpl $0x8, %ecx
ja 0xe6a0
leaq 0x16682(%rip), %rdx     # 0x24cd8
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq %rbp, %rdi
callq 0x12245
movsbl %al, %esi
leaq 0x16735(%rip), %rdi     # 0x24da6
jmp 0xe6b6
cmpl $0x73, %eax
je 0xe68f
cmpl $0x5a, %eax
jne 0xe6bf
movq %rbp, %rdi
callq 0x12251
movq %rax, %rdi
callq 0x30e0
jmp 0xe6e5
movq %rbp, %rdi
callq 0x121e2
leaq 0x17d4b(%rip), %rdi     # 0x263e9
jmp 0xe6b4
cmpl $0x53, %eax
jne 0xe6bf
movq %rbp, %rdi
callq 0x121e2
leaq 0x166f6(%rip), %rdi     # 0x24daa
movl %eax, %esi
xorl %eax, %eax
callq 0x3040
jmp 0xe6e5
movl $0xa, %edi
callq 0x3170
jmp 0xe6e5
movq %rbp, %rdi
callq 0x12229
cvtss2sd %xmm0, %xmm0
leaq 0x166bf(%rip), %rdi     # 0x24d9d
movb $0x1, %al
callq 0x3040
movq %rbx, %rdi
movq %r15, %rsi
callq 0x126b5
testl %eax, %eax
jns 0xe5ef
movq 0x10(%rsp), %r14
cmpl $-0x1, %eax
jne 0xe769
movq 0x30(%r15), %rdi
callq 0x32c0
movq %r15, %rdi
callq 0x32c0
movq %r14, %rdi
callq 0x122ff
movq %rbx, %rdi
callq 0x10d25
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1f895(%rip), %rax     # 0x2dfd0
movq (%rax), %rdi
callq 0x3030
leaq 0x1897d(%rip), %rsi     # 0x270c7
movl %eax, %edi
callq 0x101a3
jmp 0xe581
callq 0x3c3f
jmp 0xe762
callq 0x3c23
movl $0x1, %eax
jmp 0xe725
movq 0x1f878(%rip), %rcx     # 0x2dfe8
movq (%rcx), %rdi
leaq 0x16634(%rip), %rsi     # 0x24dae
movl %eax, %edx
xorl %eax, %eax
callq 0x3630
jmp 0xe702
leaq 0x1494a(%rip), %rdi     # 0x230d9
leaq 0x165aa(%rip), %rsi     # 0x24d40
leaq 0x165ab(%rip), %rcx     # 0x24d48
movl $0x2c, %edx
callq 0x3140