// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bcftools/index.c
// Function: bcf_idx_core
bcf_idx_t *bcf_idx_core(bcf_t *bp, bcf_hdr_t *h)
{
	bcf_idx_t *idx;
	int32_t last_coor, last_tid;
	uint64_t last_off;
	kstring_t *str;
	BGZF *fp = bp->fp;
	bcf1_t *b;
	int ret;

	b = calloc(1, sizeof(bcf1_t));
	str = calloc(1, sizeof(kstring_t));
	idx = (bcf_idx_t*)calloc(1, sizeof(bcf_idx_t));
	idx->n = h->n_ref;
	idx->index2 = calloc(h->n_ref, sizeof(bcf_lidx_t));

	last_tid = 0xffffffffu;
	last_off = bgzf_tell(fp); last_coor = 0xffffffffu;
	while ((ret = bcf_read(bp, h, b)) > 0) {
		int end, tmp;
		if (last_tid != b->tid) { // change of chromosomes
			last_tid = b->tid;
		} else if (last_coor > b->pos) {
			fprintf(stderr, "[bcf_idx_core] the input is out of order\n");
			free(str->s); free(str); free(idx); bcf_destroy(b);
			return 0;
		}
		tmp = strlen(b->ref);
		end = b->pos + (tmp > 0? tmp : 1);
		insert_offset2(&idx->index2[b->tid], b->pos, end, last_off);
		last_off = bgzf_tell(fp);
		last_coor = b->pos;
	}
	free(str->s); free(str); bcf_destroy(b);
	return idx;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movq %rdi, %r13
movq 0x10(%rdi), %rbx
movl $0x1, %edi
movl $0x68, %esi
callq 0x2260
movq %rax, %r12
movl $0x1, %edi
movl $0x10, %esi
callq 0x2260
movq %rax, %r15
movslq (%r14), %rdi
movl %edi, (%rax)
movl $0x10, %esi
callq 0x2260
movq %r15, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movq %rax, 0x8(%r15)
movq 0x10(%rbx), %r15
movq %rbx, 0x20(%rsp)
movzwl 0xc(%rbx), %ebx
movq %r13, 0x28(%rsp)
movq %r13, %rdi
movq %r14, 0x30(%rsp)
movq %r14, %rsi
movq %r12, %rdx
callq 0xbcac
testl %eax, %eax
jle 0x1759f
shlq $0x10, %r15
orq %rbx, %r15
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl (%r12), %eax
movl 0x4(%r12), %ebp
movl %eax, %edx
cmpl %eax, %ecx
jne 0x1748c
movl %ecx, %edx
cmpl %ebp, %ebx
jg 0x175bb
movl %edx, 0xc(%rsp)
movslq %eax, %rbx
movq 0x20(%r12), %rdi
callq 0x2180
cmpl $0x2, %eax
movl $0x1, %ecx
cmovll %ecx, %eax
shlq $0x4, %rbx
movq 0x18(%rsp), %rcx
leaq (%rcx,%rbx), %r14
addl %ebp, %eax
decl %eax
movl %eax, %r13d
sarl $0xd, %r13d
movslq 0x4(%rcx,%rbx), %rbx
cmpl %r13d, %ebx
jg 0x17520
sarl $0xe, %eax
orl %r13d, %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, %eax
sarl $0x10, %eax
orl %ecx, %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x4(%r14)
movq 0x8(%r14), %rdi
leal 0x8(,%rax,8), %eax
movslq %eax, %rsi
callq 0x23d0
movq %rax, 0x8(%r14)
leaq (%rax,%rbx,8), %rdi
movslq 0x4(%r14), %rdx
subq %rbx, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x21f0
sarl $0xd, %ebp
leal 0x1(%r13), %eax
cmpl %r13d, %ebp
jne 0x17540
movq 0x8(%r14), %rcx
movslq %ebp, %rdx
cmpq $0x0, (%rcx,%rdx,8)
jne 0x1755f
movq %r15, (%rcx,%rdx,8)
jmp 0x1755f
jg 0x1755f
movq 0x8(%r14), %rcx
movslq %ebp, %rdx
movslq %eax, %rsi
cmpq $0x0, (%rcx,%rdx,8)
jne 0x17557
movq %r15, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rsi
jne 0x1754c
cmpl %r13d, (%r14)
jg 0x17567
movl %eax, (%r14)
movq 0x20(%rsp), %rcx
movq 0x10(%rcx), %rax
shlq $0x10, %rax
movzwl 0xc(%rcx), %r15d
orq %rax, %r15
movl 0x4(%r12), %ebx
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq %r12, %rdx
callq 0xbcac
movl 0xc(%rsp), %ecx
testl %eax, %eax
jg 0x17473
movq %r12, %rdi
callq 0xbdf9
movq 0x10(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x2b23
xorl %eax, %eax
jmp 0x175ac