// File: /workspace/github_c_makefile_star2_O0/sc932[P]ALE/src/samtools-0.1.19/faidx.c
// Function: download_and_open
FILE *download_and_open(const char *fn)
{
    const int buf_size = 1 * 1024 * 1024;
    uint8_t *buf;
    FILE *fp;
    knetFile *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 = knet_open(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);
        knet_close(fp_remote);
        return NULL;
    }
    buf = (uint8_t*)calloc(buf_size, 1);
    while ((l = knet_read(fp_remote, buf, buf_size)) != 0)
        fwrite(buf, 1, l, fp);
    free(buf);
    fclose(fp);
    knet_close(fp_remote);

    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 0x31d0
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 0x1f2f2
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x1f2e2
jmp 0x1f2f2
jmp 0x1f2e4
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x1f2ca
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x14116(%rip), %rsi     # 0x3341f
callq 0x3380
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x1f326
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1f427
movq -0x38(%rbp), %rdi
leaq 0x1293d(%rip), %rsi     # 0x31c6e
callq 0x216d0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x1f36a
movq 0x19cb0(%rip), %rax     # 0x38ff8
movq (%rax), %rdi
movq -0x38(%rbp), %rdx
leaq 0x13702(%rip), %rsi     # 0x32a58
movb $0x0, %al
callq 0x3350
movq $0x0, -0x8(%rbp)
jmp 0x1f427
movq -0x10(%rbp), %rdi
leaq 0x136b6(%rip), %rsi     # 0x32a2b
callq 0x3380
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x1f3b3
movq 0x19c6d(%rip), %rax     # 0x38ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x136f3(%rip), %rsi     # 0x32a8c
movb $0x0, %al
callq 0x3350
movq -0x30(%rbp), %rdi
callq 0x21870
movq $0x0, -0x8(%rbp)
jmp 0x1f427
movl $0x100000, %edi         # imm = 0x100000
movl $0x1, %esi
callq 0x3310
movq %rax, -0x20(%rbp)
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x100000, %edx         # imm = 0x100000
callq 0x21980
movl %eax, -0x44(%rbp)
cmpl $0x0, %eax
je 0x1f3f8
movq -0x20(%rbp), %rdi
movslq -0x44(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl $0x1, %esi
callq 0x35d0
jmp 0x1f3c6
movq -0x20(%rbp), %rdi
callq 0x3050
movq -0x28(%rbp), %rdi
callq 0x31c0
movq -0x30(%rbp), %rdi
callq 0x21870
movq -0x10(%rbp), %rdi
leaq 0x14001(%rip), %rsi     # 0x3341f
callq 0x3380
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)