// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bam_index.c
// Function: bam_idxstats
int bam_idxstats(int argc, char *argv[])
{
	bam_index_t *idx;
	bam_header_t *header;
	bamFile fp;
	int i;
	if (argc < 2) {
		fprintf(stderr, "Usage: samtools idxstats <in.bam>\n");
		return 1;
	}
	fp = bam_open(argv[1], "r");
	if (fp == 0) { fprintf(stderr, "[%s] fail to open BAM.\n", __func__); return 1; }
	header = bam_header_read(fp);
	bam_close(fp);
	idx = bam_index_load(argv[1]);
	if (idx == 0) { fprintf(stderr, "[%s] fail to load the index.\n", __func__); return 1; }
	for (i = 0; i < idx->n; ++i) {
		khint_t k;
		khash_t(i) *h = idx->index[i];
		printf("%s\t%d", header->target_name[i], header->target_len[i]);
		k = kh_get(i, h, BAM_MAX_BIN);
		if (k != kh_end(h))
			printf("\t%llu\t%llu", (long long)kh_val(h, k).list[1].u, (long long)kh_val(h, k).list[1].v);
		else printf("\t0\t0");
		putchar('\n');
	}
	printf("*\t0\t0\t%llu\n", (long long)idx->n_no_coor);
	bam_header_destroy(header);
	bam_index_destroy(idx);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpl $0x1, %edi
jle 0x106b9
movq %rsi, %r14
movq 0x8(%rsi), %rdi
leaq 0xb2bf(%rip), %rsi      # 0x1b806
callq 0x17198
testq %rax, %rax
je 0x106c0
movq %rax, %r15
movq %rax, %rdi
callq 0x9806
movq %rax, %rbx
movq %r15, %rdi
callq 0x17e8e
movq 0x8(%r14), %rdi
callq 0x10380
testq %rax, %rax
je 0x106c7
movq %rax, %r14
cmpl $0x0, (%rax)
jle 0x10684
xorl %ebp, %ebp
leaq 0xaeaa(%rip), %r15      # 0x1b43c
xorl %r12d, %r12d
movq 0x10(%r14), %rax
movq (%rax,%r12,8), %r13
movq 0x8(%rbx), %rax
movq 0x10(%rbx), %rcx
movq (%rax,%r12,8), %rsi
movl (%rcx,%r12,4), %edx
movq %r15, %rdi
xorl %eax, %eax
callq 0x3210
movl (%r13), %edi
movl $0x0, %eax
testl %edi, %edi
je 0x10632
movl $0x924a, %eax           # imm = 0x924A
xorl %edx, %edx
divl %edi
movl %edx, %esi
leal -0x1(%rdi), %ecx
movl $0x924a, %eax           # imm = 0x924A
xorl %edx, %edx
divl %ecx
incl %edx
movq 0x10(%r13), %r8
movl %esi, %eax
movl %eax, %ecx
shrl $0x4, %ecx
movl (%r8,%rcx,4), %r9d
leal (%rax,%rax), %ecx
andl $0x1e, %ecx
movl %r9d, %r10d
shrl %cl, %r10d
testb $0x2, %r10b
jne 0x10628
testb $0x1, %r10b
jne 0x10615
movq 0x18(%r13), %r10
movl %eax, %r11d
cmpl $0x924a, (%r10,%r11,4)  # imm = 0x924A
je 0x10628
addl %edx, %eax
cmpl %edi, %eax
movl %edi, %ecx
cmovbl %ebp, %ecx
subl %ecx, %eax
cmpl %esi, %eax
jne 0x105e3
movl %edi, %eax
jmp 0x10632
shrl %cl, %r9d
testb $0x3, %r9b
cmovnel %edi, %eax
cmpl %edi, %eax
jne 0x10646
leaq 0xae10(%rip), %rdi      # 0x1b44d
xorl %eax, %eax
callq 0x3210
jmp 0x1066b
movq 0x20(%r13), %rcx
movl %eax, %eax
shlq $0x4, %rax
movq 0x8(%rcx,%rax), %rax
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
leaq 0xadde(%rip), %rdi      # 0x1b442
xorl %eax, %eax
callq 0x3210
movl $0xa, %edi
callq 0x3070
incq %r12
movslq (%r14), %rax
cmpq %rax, %r12
jl 0x10595
movq 0x8(%r14), %rsi
leaq 0xadc3(%rip), %rdi      # 0x1b452
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x3210
movq %rbx, %rdi
callq 0x9784
movq %r14, %rdi
callq 0xfb05
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3f1e
jmp 0x106cc
callq 0x3eff
jmp 0x106cc
callq 0x3ee0
movl $0x1, %ebp
jmp 0x106a8