// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/htslib/sam.c
// Function: bam_index
static hts_idx_t *bam_index(BGZF *fp, int min_shift)
{
    int n_lvls, i, fmt, ret;
    bam1_t *b;
    hts_idx_t *idx;
    bam_hdr_t *h;
    h = bam_hdr_read(fp);
    if (h == NULL) return NULL;
    if (min_shift > 0) {
        int64_t max_len = 0, s;
        for (i = 0; i < h->n_targets; ++i)
            if (max_len < h->target_len[i]) max_len = h->target_len[i];
        max_len += 256;
        for (n_lvls = 0, s = 1<<min_shift; max_len > s; ++n_lvls, s <<= 3);
        fmt = HTS_FMT_CSI;
    } else min_shift = 14, n_lvls = 5, fmt = HTS_FMT_BAI;
    idx = hts_idx_init(h->n_targets, fmt, bgzf_tell(fp), min_shift, n_lvls);
    bam_hdr_destroy(h);
    b = bam_init1();
    while ((ret = bam_read1(fp, b)) >= 0) {
        ret = hts_idx_push(idx, b->core.tid, b->core.pos, bam_endpos(b), bgzf_tell(fp), !(b->core.flag&BAM_FUNMAP));
        if (ret < 0) goto err; // unsorted
    }
    if (ret < -1) goto err; // corrupted BAM file

    hts_idx_finish(idx, bgzf_tell(fp));
    bam_destroy1(b);
    return idx;

err:
    bam_destroy1(b);
    hts_idx_destroy(idx);
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rdi
callq 0xa55d0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0xa6c20
movq $0x0, -0x8(%rbp)
jmp 0xa6e23
cmpl $0x0, -0x14(%rbp)
jle 0xa6ccd
movq $0x0, -0x48(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl (%rcx), %eax
jge 0xa6c7c
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x1c(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
cmpq %rcx, %rax
jge 0xa6c6f
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq %rax, -0x48(%rbp)
jmp 0xa6c71
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xa6c39
movq -0x48(%rbp), %rax
addq $0x100, %rax            # imm = 0x100
movq %rax, -0x48(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x14(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
cltq
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jle 0xa6cc4
jmp 0xa6cad
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movq -0x50(%rbp), %rax
shlq $0x3, %rax
movq %rax, -0x50(%rbp)
jmp 0xa6ca1
movl $0x0, -0x20(%rbp)
jmp 0xa6ce2
movl $0xe, -0x14(%rbp)
movl $0x5, -0x18(%rbp)
movl $0x1, -0x20(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %edi
movl -0x20(%rbp), %esi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
shlq $0x10, %rdx
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
cltq
orq %rax, %rdx
movl -0x14(%rbp), %ecx
movl -0x18(%rbp), %r8d
callq 0x74230
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rdi
callq 0xa53b0
callq 0xa5e60
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xa6190
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
jl 0xa6dc8
movq -0x38(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x54(%rbp)
movq -0x30(%rbp), %rdi
callq 0xa60f0
movq -0x60(%rbp), %rdi
movl -0x58(%rbp), %esi
movl -0x54(%rbp), %edx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %r8
shlq $0x10, %r8
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
cltq
orq %rax, %r8
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
andl $0x4, %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %r9d
callq 0x74d00
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0xa6dc3
jmp 0xa6e09
jmp 0xa6d2a
cmpl $-0x1, -0x24(%rbp)
jge 0xa6dd0
jmp 0xa6e09
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
shlq $0x10, %rsi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
cltq
orq %rax, %rsi
callq 0x743c0
movq -0x30(%rbp), %rdi
callq 0xa5e80
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xa6e23
movq -0x30(%rbp), %rdi
callq 0xa5e80
movq -0x38(%rbp), %rdi
callq 0x75440
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)