// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/htslib/faidx.c
// Function: download_and_open
static FILE *download_and_open(const char *fn)
{
    const int buf_size = 1 * 1024 * 1024;
    uint8_t *buf;
    FILE *fp;
    hFILE *fp_remote;
    const char *url = fn;
    const char *p;
    int l = strlen(fn);
    for (p = fn + l - 1; p >= fn; --p)
        if (*p == '/') break;
    fn = p + 1;

    // First try to open a local copy
    fp = fopen(fn, "r");
    if (fp)
        return fp;

    // If failed, download from remote and open
    fp_remote = hopen(url, "rb");
    if (fp_remote == 0) {
        fprintf(stderr, "[download_from_remote] fail to open remote file %s\n",url);
        return NULL;
    }
    if ((fp = fopen(fn, "wb")) == 0) {
        fprintf(stderr, "[download_from_remote] fail to create file in the working directory %s\n",fn);
        hclose_abruptly(fp_remote);
        return NULL;
    }
    buf = (uint8_t*)calloc(buf_size, 1);
    while ((l = hread(fp_remote, buf, buf_size)) > 0)
        fwrite(buf, 1, l, fp);
    free(buf);
    fclose(fp);
    if (hclose(fp_remote) != 0)
        fprintf(stderr, "[download_from_remote] fail to close remote file %s\n", url);

    return fopen(fn, "r");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl $0x100000, -0x14(%rbp)  # imm = 0x100000
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0x62c0
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
addq %rcx, %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x10(%rbp), %rax
jb 0xa0682
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0xa0672
jmp 0xa0682
jmp 0xa0674
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xa065a
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x3f6fd(%rip), %rsi     # 0xdfd96
callq 0x6860
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xa06b6
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xa07db
movq -0x38(%rbp), %rdi
leaq 0x37c7d(%rip), %rsi     # 0xd833e
callq 0xa2a70
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xa06fa
movq 0x648f8(%rip), %rax     # 0x104fd0
movq (%rax), %rdi
movq -0x38(%rbp), %rdx
leaq 0x439d4(%rip), %rsi     # 0xe40ba
movb $0x0, %al
callq 0x6a80
movq $0x0, -0x8(%rbp)
jmp 0xa07db
movq -0x10(%rbp), %rdi
leaq 0x3c310(%rip), %rsi     # 0xdca15
callq 0x6860
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0xa0746
movq 0x648b5(%rip), %rax     # 0x104fd0
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x439c5(%rip), %rsi     # 0xe40ee
movb $0x0, %al
callq 0x6a80
movq -0x30(%rbp), %rdi
callq 0xa2480
movq $0x0, -0x8(%rbp)
jmp 0xa07db
movl $0x100000, %edi         # imm = 0x100000
movl $0x1, %esi
callq 0x6460
movq %rax, -0x20(%rbp)
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x100000, %edx         # imm = 0x100000
callq 0xa1920
movl %eax, -0x44(%rbp)
cmpl $0x0, %eax
jle 0xa078b
movq -0x20(%rbp), %rdi
movslq -0x44(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl $0x1, %esi
callq 0x6e80
jmp 0xa0759
movq -0x20(%rbp), %rdi
callq 0x6880
movq -0x28(%rbp), %rdi
callq 0x66e0
movq -0x30(%rbp), %rdi
callq 0xa23e0
cmpl $0x0, %eax
je 0xa07c7
movq 0x6481e(%rip), %rax     # 0x104fd0
movq (%rax), %rdi
movq -0x38(%rbp), %rdx
leaq 0x43976(%rip), %rsi     # 0xe4136
movb $0x0, %al
callq 0x6a80
movq -0x10(%rbp), %rdi
leaq 0x3f5c4(%rip), %rsi     # 0xdfd96
callq 0x6860
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)