// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/sam.c
// Function: sam_idx_init
int sam_idx_init(htsFile *fp, sam_hdr_t *h, int min_shift, const char *fnidx) {
    fp->fnidx = fnidx;
    if (fp->format.format == bam || fp->format.format == bcf ||
        (fp->format.format == sam && fp->format.compression == bgzf)) {
        int n_lvls, fmt = HTS_FMT_CSI;
        if (min_shift > 0) {
            int64_t max_len = 0, s;
            int i;
            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);

        } else min_shift = 14, n_lvls = 5, fmt = HTS_FMT_BAI;

        fp->idx = hts_idx_init(h->n_targets, fmt, bgzf_tell(fp->fp.bgzf), min_shift, n_lvls);
        return fp->idx ? 0 : -1;
    }

    if (fp->format.format == cram) {
        fp->fp.cram->idxfp = bgzf_open(fnidx, "wg");
        return fp->fp.cram->idxfp ? 0 : -1;
    }

    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x10(%rbp), %rax
cmpl $0x4, 0x4c(%rax)
je 0x35293
movq -0x10(%rbp), %rax
cmpl $0x9, 0x4c(%rax)
je 0x35293
movq -0x10(%rbp), %rax
cmpl $0x3, 0x4c(%rax)
jne 0x353b5
movq -0x10(%rbp), %rax
cmpl $0x2, 0x54(%rax)
jne 0x353b5
movl $0x0, -0x30(%rbp)
cmpl $0x0, -0x1c(%rbp)
jle 0x35340
movq $0x0, -0x38(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x352f6
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x44(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
cmpq %rcx, %rax
jge 0x352e9
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x44(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq %rax, -0x38(%rbp)
jmp 0x352eb
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x352b3
movq -0x38(%rbp), %rax
addq $0x100, %rax            # imm = 0x100
movq %rax, -0x38(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x1c(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
cltq
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jle 0x3533e
jmp 0x35327
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x40(%rbp), %rax
shlq $0x3, %rax
movq %rax, -0x40(%rbp)
jmp 0x3531b
jmp 0x35355
movl $0xe, -0x1c(%rbp)
movl $0x5, -0x2c(%rbp)
movl $0x1, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %edi
movl -0x30(%rbp), %esi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x18(%rax), %rdx
shlq $0x10, %rdx
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movl 0x10(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
cltq
orq %rax, %rdx
movl -0x1c(%rbp), %ecx
movl -0x2c(%rbp), %r8d
callq 0x1ecb0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x3540a
movq -0x10(%rbp), %rax
cmpl $0x6, 0x4c(%rax)
jne 0x35403
movq -0x28(%rbp), %rdi
leaq 0xb8392(%rip), %rsi     # 0xed75c
callq 0xc090
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rcx, 0x8988(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8988(%rax), %rdx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x3540a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)