// File: /workspace/github_cpp_makefile_star2_O1/karel-brinda[P]ococo/ext/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);
            if (ret < 0) ret = -4;
            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 0x3e9f3(%rip), %rsi     # 0x53919
callq 0xf67a
testq %rax, %rax
je 0x14f5f
movq %rax, %rbx
movl 0x44(%rax), %eax
cmpl $0x4, %eax
je 0x14f69
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
cmpl $0x6, %eax
jne 0x150e8
movq 0x38(%rbx), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x3026c
movl %eax, %ebp
jmp 0x150e8
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
jmp 0x150f0
movq 0x38(%rbx), %r12
movq %r12, %rdi
callq 0x141da
testq %rax, %rax
movq %r13, 0x10(%rsp)
je 0x14fb8
movq %rax, %r14
testl %ebp, %ebp
movq %r15, 0x8(%rsp)
jle 0x14fc0
movslq (%r14), %rcx
testq %rcx, %rcx
jle 0x14fd2
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 0x14f9b
addq $0x100, %rax            # imm = 0x100
jmp 0x14fd7
xorl %r13d, %r13d
jmp 0x150b3
movl $0xe, %ecx
movl $0x5, %r8d
movl $0x1, %esi
jmp 0x15005
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 0x15005
xorl %esi, %esi
xorl %r8d, %r8d
incl %r8d
shlq $0x3, %rdx
cmpq %rdx, %rax
jg 0x14ff7
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 0x10e23
movq %rax, %r13
movq %r14, %rdi
callq 0x1407f
movl $0x1, %edi
movl $0x38, %esi
callq 0x4360
movq %rax, %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x1493a
testl %eax, %eax
js 0x15092
movl (%r14), %ebp
movl 0x4(%r14), %r15d
movq %r14, %rdi
callq 0x148dd
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 0x11725
testl %eax, %eax
jns 0x15040
jmp 0x15097
cmpl $-0x1, %eax
je 0x15101
movq %r14, %rdi
callq 0x1477c
movq %r13, %rdi
callq 0x11d33
xorl %r13d, %r13d
movq 0x8(%rsp), %r15
movl 0x4(%rsp), %ebp
testq %r13, %r13
je 0x150e3
xorl %ecx, %ecx
testl %ebp, %ebp
setle %cl
movq %r13, %rdi
movq 0x10(%rsp), %rsi
movq %r15, %rdx
callq 0x11ee6
testl %eax, %eax
movl $0xfffffffc, %ebp       # imm = 0xFFFFFFFC
cmovnsl %eax, %ebp
movq %r13, %rdi
callq 0x11d33
jmp 0x150e8
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0xfdc1
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 0x10f09
movq %r14, %rdi
callq 0x1477c
jmp 0x150aa