// File: /workspace/github_c_makefile_star2_O1/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, 0x28(%rsp)
movq 0x10(%rdi), %r15
movl $0x1, %edi
movl $0x68, %esi
callq 0x2260
movq %rax, %rbx
movl $0x1, %edi
movl $0x18, %esi
callq 0x2260
movq %rax, %r13
movl $0x1, %edi
movl $0x10, %esi
callq 0x2260
movq %rax, %r12
movq %r14, 0x30(%rsp)
movslq (%r14), %rdi
movl %edi, (%rax)
movl $0x10, %esi
callq 0x2260
movq %r12, (%rsp)
movq %rax, 0x8(%r12)
movq 0x10(%r15), %rax
shlq $0x10, %rax
movq %r15, 0x20(%rsp)
movzwl 0xc(%r15), %ebp
orq %rax, %rbp
movq %r13, 0x10(%rsp)
addq $0x10, %r13
movq %r13, 0x18(%rsp)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq %rbx, %rdx
callq 0xbb50
testl %eax, %eax
jle 0x1727f
movl (%rbx), %eax
movl %eax, %ecx
cmpl %eax, %r15d
jne 0x17158
cmpl 0x4(%rbx), %r12d
jg 0x17265
movl %r15d, %ecx
movl %ecx, 0xc(%rsp)
movslq %eax, %r14
movq 0x20(%rbx), %rdi
callq 0x2180
movl 0x4(%rbx), %r13d
cmpl $0x2, %eax
movl $0x1, %ecx
cmovll %ecx, %eax
movq (%rsp), %rcx
movq 0x8(%rcx), %rcx
shlq $0x4, %r14
leaq (%rcx,%r14), %r15
addl %r13d, %eax
decl %eax
movl %eax, %r12d
sarl $0xd, %r12d
movslq 0x4(%rcx,%r14), %r14
cmpl %r12d, %r14d
jg 0x171f3
sarl $0xe, %eax
orl %r12d, %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(%r15)
movq 0x8(%r15), %rdi
leal 0x8(,%rax,8), %eax
movslq %eax, %rsi
callq 0x23d0
movq %rax, 0x8(%r15)
leaq (%rax,%r14,8), %rdi
movslq 0x4(%r15), %rdx
subq %r14, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x21f0
sarl $0xd, %r13d
leal 0x1(%r12), %eax
cmpl %r12d, %r13d
jne 0x17215
movq 0x8(%r15), %rcx
movslq %r13d, %rdx
cmpq $0x0, (%rcx,%rdx,8)
jne 0x17234
movq %rbp, (%rcx,%rdx,8)
jmp 0x17234
jg 0x17234
movq 0x8(%r15), %rcx
movslq %r13d, %rdx
movslq %eax, %rsi
cmpq $0x0, (%rcx,%rdx,8)
jne 0x1722c
movq %rbp, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rsi
jne 0x17221
cmpl %r12d, (%r15)
jg 0x1723c
movl %eax, (%r15)
movq 0x20(%rsp), %rcx
movq 0x10(%rcx), %rax
shlq $0x10, %rax
movzwl 0xc(%rcx), %ebp
orq %rax, %rbp
movl 0x4(%rbx), %r12d
movb $0x1, %al
movl 0xc(%rsp), %r15d
testb %al, %al
jne 0x17128
jmp 0x172a3
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
movq %rbx, %rcx
callq 0x2b23
xorl %eax, %eax
jmp 0x1725b
movq 0x10(%rsp), %r14
movq 0x10(%r14), %rdi
callq 0x2060
movq %r14, %rdi
callq 0x2060
movq %rbx, %rdi
callq 0xbc91
movq (%rsp), %rax
jmp 0x172a5
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq