// File: /workspace/github_c_makefile_star2_O3/icebert[P]pblat/htslib/sam.c
// Function: sam_index_build2
int sam_index_build2(const char *fn, const char *fnidx, int min_shift)
{
    hts_idx_t *idx;
    htsFile *fp;
    int ret = 0;

    if ((fp = hts_open(fn, "r")) == 0) return -2;
    switch (fp->format.format) {
    case cram:
        ret = cram_index_build(fp->fp.cram, fn, fnidx);
        break;

    case bam:
        idx = bam_index(fp->fp.bgzf, min_shift);
        if (idx) {
            ret = hts_idx_save_as(idx, fn, fnidx, (min_shift > 0)? HTS_FMT_CSI : HTS_FMT_BAI);
            hts_idx_destroy(idx);
        }
        else ret = -1;
        break;

    default:
        ret = -3;
        break;
    }
    hts_close(fp);

    return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r12d
movq %rsi, %r14
movq %rdi, %r15
leaq 0x284ad(%rip), %rsi     # 0x95f09
callq 0x4e07e
testq %rax, %rax
je 0x6da95
movq %rax, %rbx
movl 0x44(%rax), %eax
cmpl $0x4, %eax
je 0x6da9f
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
cmpl $0x6, %eax
jne 0x6dbe8
movq 0x38(%rbx), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x53ed2
movl %eax, %ebp
jmp 0x6dbe8
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
jmp 0x6dbf0
movq 0x38(%rbx), %r13
movq %r13, %rdi
callq 0x6cdb3
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x6dbe8
movl (%rax), %edi
testl %r12d, %r12d
movq %r14, 0x10(%rsp)
movq %r15, 0x8(%rsp)
jle 0x6daf6
testl %edi, %edi
jle 0x6db0b
movq %rax, %rbp
movq 0x10(%rax), %rcx
xorl %edx, %edx
xorl %eax, %eax
movq %rax, %rsi
movl (%rcx,%rdx,4), %eax
cmpq %rax, %rsi
cmovgq %rsi, %rax
incq %rdx
cmpq %rdx, %rdi
jne 0x6dad9
addq $0x100, %rax            # imm = 0x100
jmp 0x6db13
movq %rax, %rbp
movl $0xe, %ecx
movl $0x5, %r8d
movl $0x1, %esi
jmp 0x6db44
movq %rax, %rbp
movl $0x100, %eax            # imm = 0x100
movl $0x1, %edx
movl %r12d, %ecx
shll %cl, %edx
movslq %edx, %rdx
xorl %esi, %esi
movl $0x0, %r8d
movl %r12d, %ecx
cmpq %rdx, %rax
jle 0x6db44
xorl %esi, %esi
xorl %r8d, %r8d
incl %r8d
shlq $0x3, %rdx
cmpq %rdx, %rax
jg 0x6db35
movl %r12d, %ecx
movl %r12d, 0x4(%rsp)
movq 0x10(%r13), %rax
shlq $0x10, %rax
movzwl 0xc(%r13), %edx
orq %rax, %rdx
callq 0x4f7dc
movq %rax, %r14
movq %rbp, %rdi
callq 0x6cc63
movl $0x1, %edi
movl $0x38, %esi
callq 0x6470
movq %rax, %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x6d4a0
testl %eax, %eax
js 0x6dbce
movl (%r12), %ebp
movl 0x4(%r12), %r15d
movq %r12, %rdi
callq 0x6d440
movq 0x10(%r13), %rcx
shlq $0x10, %rcx
movzwl 0xc(%r13), %r8d
orq %rcx, %r8
xorl %r9d, %r9d
btq $0x22, 0x8(%r12)
setae %r9b
movq %r14, %rdi
movl %ebp, %esi
movl %r15d, %edx
movl %eax, %ecx
callq 0x501d6
testl %eax, %eax
jns 0x6db7b
jmp 0x6dbd3
cmpl $-0x1, %eax
je 0x6dc01
movq %r12, %rdi
callq 0x6d2dc
movq %r14, %rdi
callq 0x507d6
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0x4e788
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%r13), %rax
shlq $0x10, %rax
movzwl 0xc(%r13), %esi
orq %rax, %rsi
movq %r14, %rdi
callq 0x4f8bc
movq %r12, %rdi
callq 0x6d2dc
testq %r14, %r14
movq 0x10(%rsp), %rdx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rsi
je 0x6dbe8
xorl %ecx, %ecx
cmpl $0x0, 0x4(%rsp)
setle %cl
movq %r14, %rdi
callq 0x5098e
movl %eax, %ebp
movq %r14, %rdi
callq 0x507d6
jmp 0x6dbe8