// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
xorl %eax, %eax
cmpq -0x10(%rbp), %rax
jne 0x1f4193
movq 0xc2de63(%rip), %rax    # 0xe21fd8
movq (%rax), %rdi
leaq 0xb0d941(%rip), %rsi    # 0xd01ac0
movb $0x0, %al
callq 0x1f01f0
movq $0x0, -0x8(%rbp)
jmp 0x1f4308
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movb $0x0, %al
callq 0x1f00f0
movl %eax, -0x24(%rbp)
cmpl $-0x1, -0x24(%rbp)
jne 0x1f41de
leaq 0xad8fd7(%rip), %rdi    # 0xccd187
callq 0x1f0120
movq 0xc2de1c(%rip), %rax    # 0xe21fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0xb0d914(%rip), %rsi    # 0xd01ade
movb $0x0, %al
callq 0x1f01f0
movq $0x0, -0x8(%rbp)
jmp 0x1f4308
movl -0x24(%rbp), %edi
leaq -0xb8(%rbp), %rsi
callq 0x1f0250
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x1f422d
leaq 0xb0d90b(%rip), %rdi    # 0xd01b0a
callq 0x1f0120
movq 0xc2ddcd(%rip), %rax    # 0xe21fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0xb0d8f7(%rip), %rsi    # 0xd01b10
movb $0x0, %al
callq 0x1f01f0
movq $0x0, -0x8(%rbp)
jmp 0x1f4308
movq -0x88(%rbp), %rsi
movl -0x24(%rbp), %r8d
xorl %eax, %eax
movl %eax, %r9d
movl $0x1, %ecx
movq %r9, %rdi
movl %ecx, %edx
callq 0x1f0270
movq %rax, -0x20(%rbp)
movq $-0x1, %rax
cmpq -0x20(%rbp), %rax
jne 0x1f428f
leaq 0xb0d8d9(%rip), %rdi    # 0xd01b3d
callq 0x1f0120
movq 0xc2dd68(%rip), %rax    # 0xe21fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0xb0d8c4(%rip), %rsi    # 0xd01b42
movb $0x0, %al
callq 0x1f01f0
movq $0x0, -0x8(%rbp)
jmp 0x1f4308
movl $0x18, %edi
callq 0x1f01c0
movq %rax, -0x18(%rbp)
xorl %eax, %eax
cmpq -0x18(%rbp), %rax
jne 0x1f42dc
leaq 0xb0d8c3(%rip), %rdi    # 0xd01b6f
callq 0x1f0120
movq 0xc2dd20(%rip), %rax    # 0xe21fd8
movq (%rax), %rdi
leaq 0xb0d8b4(%rip), %rsi    # 0xd01b76
movb $0x0, %al
callq 0x1f01f0
movq -0x20(%rbp), %rdi
callq 0x1f01a0
movq $0x0, -0x8(%rbp)
jmp 0x1f4308
movl -0x24(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x88(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)