// File: /workspace/github_c_makefile_star2_O1/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, %ebp
movq %rsi, %r15
movq %rdi, %r13
leaq 0x2833e(%rip), %rsi     # 0x95e29
callq 0x4de6c
testq %rax, %rax
je 0x6db24
movq %rax, %rbx
movl 0x44(%rax), %eax
cmpl $0x4, %eax
je 0x6db2e
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
cmpl $0x6, %eax
jne 0x6dca5
movq 0x38(%rbx), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x53bd0
movl %eax, %ebp
jmp 0x6dca5
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
jmp 0x6dcad
movq 0x38(%rbx), %r12
movq %r12, %rdi
callq 0x6cdfe
testq %rax, %rax
movq %r13, 0x10(%rsp)
je 0x6db7d
movq %rax, %r14
testl %ebp, %ebp
movq %r15, 0x8(%rsp)
jle 0x6db85
movslq (%r14), %rcx
testq %rcx, %rcx
jle 0x6db97
movq 0x10(%r14), %rdx
xorl %esi, %esi
xorl %eax, %eax
movq %rax, %rdi
movl (%rdx,%rsi,4), %eax
cmpq %rax, %rdi
cmovgq %rdi, %rax
incq %rsi
cmpq %rsi, %rcx
jne 0x6db60
addq $0x100, %rax            # imm = 0x100
jmp 0x6db9c
xorl %r13d, %r13d
jmp 0x6dc78
movl $0xe, %ecx
movl $0x5, %r8d
movl $0x1, %esi
jmp 0x6dbca
movl $0x100, %eax            # imm = 0x100
movl $0x1, %edx
movl %ebp, %ecx
shll %cl, %edx
movslq %edx, %rdx
xorl %esi, %esi
movl $0x0, %r8d
movl %ebp, %ecx
cmpq %rdx, %rax
jle 0x6dbca
xorl %esi, %esi
xorl %r8d, %r8d
incl %r8d
shlq $0x3, %rdx
cmpq %rdx, %rax
jg 0x6dbbc
movl %ebp, %ecx
movl %ebp, 0x4(%rsp)
movl (%r14), %edi
movq 0x10(%r12), %rax
shlq $0x10, %rax
movzwl 0xc(%r12), %edx
orq %rax, %rdx
callq 0x4f58f
movq %rax, %r13
movq %r14, %rdi
callq 0x6cca3
movl $0x1, %edi
movl $0x38, %esi
callq 0x6470
movq %rax, %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x6d4ff
testl %eax, %eax
js 0x6dc57
movl (%r14), %ebp
movl 0x4(%r14), %r15d
movq %r14, %rdi
callq 0x6d4a2
movq 0x10(%r12), %rcx
shlq $0x10, %rcx
movzwl 0xc(%r12), %r8d
orq %rcx, %r8
xorl %r9d, %r9d
btq $0x22, 0x8(%r14)
setae %r9b
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %edx
movl %eax, %ecx
callq 0x4fe91
testl %eax, %eax
jns 0x6dc05
jmp 0x6dc5c
cmpl $-0x1, %eax
je 0x6dcbe
movq %r14, %rdi
callq 0x6d341
movq %r13, %rdi
callq 0x5049c
xorl %r13d, %r13d
movq 0x8(%rsp), %r15
movl 0x4(%rsp), %ebp
testq %r13, %r13
je 0x6dca0
xorl %ecx, %ecx
testl %ebp, %ebp
setle %cl
movq %r13, %rdi
movq 0x10(%rsp), %rsi
movq %r15, %rdx
callq 0x5064f
movl %eax, %ebp
movq %r13, %rdi
callq 0x5049c
jmp 0x6dca5
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0x4e56f
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%r12), %rax
shlq $0x10, %rax
movzwl 0xc(%r12), %esi
orq %rax, %rsi
movq %r13, %rdi
callq 0x4f675
movq %r14, %rdi
callq 0x6d341
jmp 0x6dc6f