// File: /workspace/github_c_makefile_star2_O2/nh13[P]ksw/src/parasail/src/io.c
// Function: parasail_open
parasail_file_t* parasail_open(const char *fname)
{
    parasail_file_t *pf = NULL;
    char *buf = NULL;
#if defined(HAVE_SYS_MMAN_H)
    int fd = -1;
    STATBUF fs;
#else
    FILE *fd = NULL;
    STATBUF fs;
#endif

    if (NULL == fname) {
        fprintf(stderr, "parasail_open: NULL filename\n");
        return NULL;
    }

#if defined(HAVE_SYS_MMAN_H)
    fd = open(fname, O_RDONLY);
    if (fd == -1) {
        perror("open");
        fprintf(stderr, "parasail_open: "
                "cannot open input file `%s'\n", fname);
        return NULL;
    }

    if (-1 == FSTATFUNC(fd, &fs)) {
        perror("fstat");
        fprintf(stderr, "parasail_open: "
                "cannont stat input file `%s'\n", fname);
        return NULL;
    }

    buf = (char*)mmap(NULL, fs.st_size, PROT_READ, MAP_SHARED, fd, 0);
    if (MAP_FAILED == buf) {
        perror("mmap");
        fprintf(stderr, "parasail_open: "
                "cannont mmap input file `%s'\n", fname);
        return NULL;
    }
#else
    fd = fopen(fname, "rb");
    if (NULL == fd) {
        perror("fopen");
        fprintf(stderr, "parasail_open: "
                "cannot open input file `%s'\n", fname);
        return NULL;
    }

    if (0 != STATFUNC(fname, &fs)) {
        perror("_stat");
        fprintf(stderr, "parasail_open: "
                "cannont stat input file `%s'\n", fname);
        return NULL;
    }

    /* Allocate a buffer to hold the whole file */
    buf = (char*)malloc(fs.st_size + 1);
    if (NULL == buf) {
        perror("malloc");
        fprintf(stderr, "parasail_open: "
                "cannont malloc buffer for input file `%s'\n", fname);
        return NULL;
    }
    /* Slurp file into buffer */
    if (fs.st_size != fread(buf, 1, fs.st_size, fd)) {
        perror("fread");
        fprintf(stderr, "parasail_open: "
                "cannont read input file `%s'\n", fname);
        free(buf);
        return NULL;
    }
    /* Close the file early */
    fclose(fd);
#endif

    pf = (parasail_file_t*)malloc(sizeof(parasail_file_t));
    if (NULL == pf) {
        perror("malloc");
        fprintf(stderr, "parasail_open: "
                "cannont allocate parasail_file_t\n");
        free(buf);
        return NULL;
    }

#if defined(HAVE_SYS_MMAN_H)
    pf->fd = fd;
#else
    pf->fd = 0;
#endif
    pf->size = fs.st_size;
    pf->buf = buf;
    return pf;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x90, %rsp
testq %rdi, %rdi
je 0x1f2dfe
movq %rdi, %rbx
xorl %esi, %esi
xorl %eax, %eax
callq 0x1f0110
cmpl $-0x1, %eax
je 0x1f2e1f
movl %eax, %ebp
movq %rsp, %rsi
movl %eax, %edi
callq 0x1f0280
cmpl $-0x1, %eax
je 0x1f2e3e
movq 0x30(%rsp), %r12
pushq $0x1
popq %rcx
xorl %edi, %edi
movq %r12, %rsi
movl %ecx, %edx
movl %ebp, %r8d
xorl %r9d, %r9d
callq 0x1f02a0
cmpq $-0x1, %rax
je 0x1f2e5d
movq %rax, %r15
pushq $0x18
popq %rdi
callq 0x1f01f0
testq %rax, %rax
je 0x1f2e8c
movq %rax, %r14
movl %ebp, (%rax)
movq %r12, 0x8(%rax)
movq %r15, 0x10(%rax)
movq %r14, %rax
addq $0x90, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x5511d3(%rip), %rax    # 0x743fd8
movq (%rax), %rcx
leaq 0x3f7c81(%rip), %rdi    # 0x5eaa90
pushq $0x1d
popq %rsi
pushq $0x1
popq %rdx
callq 0x1f02b0
jmp 0x1f2ebc
leaq 0x3c3331(%rip), %rdi    # 0x5b6157
callq 0x1f0140
movq 0x5511a6(%rip), %rax    # 0x743fd8
movq (%rax), %rdi
leaq 0x3f7c72(%rip), %rsi    # 0x5eaaae
jmp 0x1f2e7a
leaq 0x3f7c95(%rip), %rdi    # 0x5eaada
callq 0x1f0140
movq 0x551187(%rip), %rax    # 0x743fd8
movq (%rax), %rdi
leaq 0x3f7c85(%rip), %rsi    # 0x5eaae0
jmp 0x1f2e7a
leaq 0x3f7ca9(%rip), %rdi    # 0x5eab0d
callq 0x1f0140
movq 0x551168(%rip), %rax    # 0x743fd8
movq (%rax), %rdi
leaq 0x3f7c98(%rip), %rsi    # 0x5eab12
xorl %r14d, %r14d
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1f0220
jmp 0x1f2deb
leaq 0x3f7cac(%rip), %rdi    # 0x5eab3f
callq 0x1f0140
movq 0x551139(%rip), %rax    # 0x743fd8
movq (%rax), %rcx
leaq 0x3f7c9d(%rip), %rdi    # 0x5eab46
pushq $0x30
popq %rsi
pushq $0x1
popq %rdx
callq 0x1f02b0
movq %r15, %rdi
callq 0x1f01c0
xorl %r14d, %r14d
jmp 0x1f2deb