// File: /workspace/github_cpp_makefile_star2_O3/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, %r12d
movq %rsi, %r14
movq %rdi, %r15
leaq 0x3ca58(%rip), %rsi     # 0x51941
callq 0xf5db
testq %rax, %rax
je 0x14f22
movq %rax, %rbx
movl 0x44(%rax), %eax
cmpl $0x4, %eax
je 0x14f2c
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
cmpl $0x6, %eax
jne 0x15075
movq 0x38(%rbx), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x2f5ea
movl %eax, %ebp
jmp 0x15075
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
jmp 0x1507d
movq 0x38(%rbx), %r13
movq %r13, %rdi
callq 0x141e3
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x15075
movl (%rax), %edi
testl %r12d, %r12d
movq %r14, 0x10(%rsp)
movq %r15, 0x8(%rsp)
jle 0x14f83
testl %edi, %edi
jle 0x14f98
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 0x14f66
addq $0x100, %rax            # imm = 0x100
jmp 0x14fa0
movq %rax, %rbp
movl $0xe, %ecx
movl $0x5, %r8d
movl $0x1, %esi
jmp 0x14fd1
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 0x14fd1
xorl %esi, %esi
xorl %r8d, %r8d
incl %r8d
shlq $0x3, %rdx
cmpq %rdx, %rax
jg 0x14fc2
movl %r12d, %ecx
movl %r12d, 0x4(%rsp)
movq 0x10(%r13), %rax
shlq $0x10, %rax
movzwl 0xc(%r13), %edx
orq %rax, %rdx
callq 0x10dbf
movq %rax, %r14
movq %rbp, %rdi
callq 0x14093
movl $0x1, %edi
movl $0x38, %esi
callq 0x4360
movq %rax, %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x1492d
testl %eax, %eax
js 0x1505b
movl (%r12), %r15d
movl 0x4(%r12), %ebp
movq %r12, %rdi
callq 0x148cd
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 %r15d, %esi
movl %ebp, %edx
movl %eax, %ecx
callq 0x117b9
testl %eax, %eax
jns 0x15008
jmp 0x15060
cmpl $-0x1, %eax
je 0x1508e
movq %r12, %rdi
callq 0x14769
movq %r14, %rdi
callq 0x11de1
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0xfd29
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 0x10e9f
movq %r12, %rdi
callq 0x14769
testq %r14, %r14
movq 0x10(%rsp), %rdx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rsi
je 0x15075
xorl %ecx, %ecx
cmpl $0x0, 0x4(%rsp)
setle %cl
movq %r14, %rdi
callq 0x11f99
testl %eax, %eax
movl $0xfffffffc, %ebp       # imm = 0xFFFFFFFC
cmovnsl %eax, %ebp
movq %r14, %rdi
callq 0x11de1
jmp 0x15075