// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/htslib/faidx.c
// Function: fai_load
faidx_t *fai_load(const char *fn)
{
    char *str;
    FILE *fp;
    faidx_t *fai;
    str = (char*)calloc(strlen(fn) + 5, 1);
    sprintf(str, "%s.fai", fn);

    if (hisremote(str))
    {
        fp = download_and_open(str);
        if ( !fp )
        {
            fprintf(stderr, "[fai_load] failed to open remote FASTA index %s\n", str);
            free(str);
            return 0;
        }
    }
    else
        fp = fopen(str, "rb");

    if (fp == 0) {
        fprintf(stderr, "[fai_load] build FASTA index.\n");
        if (fai_build(fn) < 0) {
            free(str);
            return 0;
        }
        fp = fopen(str, "rb");
        if (fp == 0) {
            fprintf(stderr, "[fai_load] failed to open FASTA index: %s\n", strerror(errno));
            free(str);
            return 0;
        }
    }

    fai = fai_read(fp, str);
    fclose(fp);
    free(str);
    if (fai == NULL) {
        return NULL;
    }

    fai->bgzf = bgzf_open(fn, "rb");
    if (fai->bgzf == 0) {
        fprintf(stderr, "[fai_load] fail to open FASTA file.\n");
        return 0;
    }
    if ( fai->bgzf->is_compressed==1 )
    {
        if ( bgzf_index_load(fai->bgzf, fn, ".gzi") < 0 )
        {
            fprintf(stderr, "[fai_load] failed to load .gzi index: %s[.gzi]\n", fn);
            fai_destroy(fai);
            return NULL;
        }
    }
    return fai;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
callq 0x4230
leaq 0x5(%rax), %rdi
movl $0x1, %esi
callq 0x4360
movq %rax, %r14
leaq 0xd261(%rip), %rsi      # 0x53088
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4110
movq %r14, %rdi
callq 0x47b91
testl %eax, %eax
movq %rbx, 0x28(%rsp)
movq %r14, 0x8(%rsp)
je 0x45f4b
movq %r14, %rdi
callq 0x4230
cltq
addq %r14, %rax
decq %rax
movq %rax, %r15
cmpq %r14, %rax
jb 0x45e70
leaq -0x1(%r15), %rax
cmpb $0x2f, (%r15)
jne 0x45e5e
incq %r15
leaq 0xbac7(%rip), %rsi      # 0x51941
movq %r15, %rdi
callq 0x4600
testq %rax, %rax
jne 0x45fc7
leaq 0xb19a(%rip), %rsi      # 0x5102c
movq %r14, %rdi
callq 0x477e9
testq %rax, %rax
je 0x4616c
movq %rax, %r12
leaq 0xe02b(%rip), %rsi      # 0x53ed8
movq %r15, %rdi
callq 0x4600
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x46189
movl $0x100000, %edi         # imm = 0x100000
movl $0x1, %esi
callq 0x4360
movq %rax, %r14
movq 0x8(%r12), %rbp
movq 0x10(%r12), %rbx
subq %rbp, %rbx
movl $0x100000, %eax         # imm = 0x100000
cmpq %rax, %rbx
movl $0x100000, %r13d        # imm = 0x100000
cmovbq %rbx, %r13
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x4420
addq %r13, %rbp
movq %rbp, 0x8(%r12)
movl $0x100000, %eax         # imm = 0x100000
cmpq $0xfffff, %rbx          # imm = 0xFFFFF
ja 0x45f2f
movl $0x100000, %edx         # imm = 0x100000
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rcx
callq 0x4716b
testl %eax, %eax
jle 0x45f88
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl $0x1, %esi
movq %r14, %rdi
movq %rax, %rdx
movq 0x30(%rsp), %rcx
callq 0x4a30
jmp 0x45ed5
leaq 0xb0da(%rip), %rsi      # 0x5102c
movq %r14, %rdi
callq 0x4600
testq %rax, %rax
jne 0x45fc7
leaq 0x10(%rsp), %rdx
leaq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0x5f53
testb $0x1, %al
je 0x461e9
movq 0x18(%rsp), %r15
jmp 0x461b7
movq %r14, %rdi
callq 0x4610
movq 0x30(%rsp), %rdi
callq 0x4530
movq %r12, %rdi
callq 0x4745b
testl %eax, %eax
movq 0x8(%rsp), %r14
jne 0x461c9
leaq 0xb98b(%rip), %rsi      # 0x51941
movq %r15, %rdi
callq 0x4600
testq %rax, %rax
je 0x461ac
movq %rax, %r12
movl $0x1, %edi
movl $0x20, %esi
callq 0x4360
movq %rax, %r15
movl $0x1, %edi
movl $0x28, %esi
callq 0x4360
movq %rax, 0x18(%r15)
movl $0x10000, %edi          # imm = 0x10000
movl $0x1, %esi
callq 0x4360
movq %rax, %r13
leaq 0x20(%rsp), %rbp
leaq 0x24(%rsp), %rbx
movq %r13, %rdi
movl $0x10000, %esi          # imm = 0x10000
movq %r12, %rdx
callq 0x4860
testq %rax, %rax
je 0x460a9
movb (%r13), %r14b
movq %r13, %rdi
testb %r14b, %r14b
je 0x46052
callq 0x4580
movq (%rax), %rax
movq %r13, %rdi
movzbl %r14b, %ecx
cmpw $0x0, (%rax,%rcx,2)
jns 0x46052
movb 0x1(%rdi), %r14b
incq %rdi
testb %r14b, %r14b
jne 0x4603b
movb $0x0, (%rdi)
incq %rdi
leaq 0xe663(%rip), %rsi      # 0x546c2
leaq 0x10(%rsp), %rdx
leaq 0x18(%rsp), %rcx
movq %rbp, %r8
movq %rbx, %r9
xorl %eax, %eax
callq 0x4520
movslq 0x10(%rsp), %rdx
movl 0x24(%rsp), %ecx
movl 0x20(%rsp), %r8d
movq 0x18(%rsp), %r9
movq %r15, %rdi
movq %r13, %rsi
callq 0x4578b
testl %eax, %eax
je 0x4600b
movq %r13, %rdi
callq 0x4610
xorl %r15d, %r15d
jmp 0x460c1
movq %r13, %rdi
callq 0x4610
movq %r12, %rdi
callq 0x49f0
testl %eax, %eax
jne 0x46154
movq 0x8(%rsp), %rbx
movq %r12, %rdi
callq 0x4530
movq %rbx, %rdi
callq 0x4610
testq %r15, %r15
je 0x461b4
leaq 0xaf46(%rip), %rsi      # 0x5102c
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0x42768
movq %rax, (%r15)
testq %rax, %rax
je 0x4614d
movl $0x60000000, %ecx       # imm = 0x60000000
andl (%rax), %ecx
cmpl $0x20000000, %ecx       # imm = 0x20000000
jne 0x461b7
leaq 0xcf7a(%rip), %rdx      # 0x5308f
movq %rax, %rdi
movq %rbx, %rsi
callq 0x44c1e
testl %eax, %eax
jns 0x461b7
movq 0x1be99(%rip), %rax     # 0x61fc8
movq (%rax), %rdi
leaq 0xe2ec(%rip), %rsi      # 0x54425
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4770
movq %r15, %rdi
callq 0x45a85
jmp 0x461b4
callq 0x602e
jmp 0x461b4
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5fe8
xorl %r15d, %r15d
jmp 0x460c6
movq 0x1be55(%rip), %rax     # 0x61fc8
movq (%rax), %rdi
leaq 0xe494(%rip), %rsi      # 0x54611
movq %r14, %rdx
xorl %eax, %eax
callq 0x4770
jmp 0x461ac
movq 0x1be38(%rip), %rax     # 0x61fc8
movq (%rax), %rdi
leaq 0xe4ab(%rip), %rsi      # 0x54645
movq %r15, %rdx
xorl %eax, %eax
callq 0x4770
movq %r12, %rdi
callq 0x474b5
movq %r14, %rdi
callq 0x5f2b
xorl %r15d, %r15d
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1bdf8(%rip), %rax     # 0x61fc8
movq (%rax), %rdi
leaq 0xe4b3(%rip), %rsi      # 0x5468d
movq %r14, %rdx
xorl %eax, %eax
callq 0x4770
jmp 0x45faf
movq 0x10(%rsp), %r12
jmp 0x45fca