// File: ctSkennerton[P]fxtract/util/msutil.c
// Function: slurp
MEMBUF
slurp(const char *filename)
{
    MEMBUF      ret = NILBUF;
    int         fd = filename && *filename && strcmp(filename, "-") ? open(filename, O_RDONLY) : 0;
    struct stat s;
    if (fd < 0 || fstat(fd, &s))
        goto ERROR;

    if (S_ISREG(s.st_mode)) {
        ret = membuf(s.st_size);
	if (ret.len != (unsigned)read(fd, ret.ptr, ret.len))
            goto ERROR;

    } else {
        int     len, size = 4096;
        ret.ptr = malloc(size + 1);
        for (;0 < (len = read(fd, ret.ptr+ret.len, size-ret.len)); ret.len += len)
            if (len == size - (int)ret.len)
                ret.ptr = realloc(ret.ptr, (size <<= 1) + 1);
        if (len < 0)
            goto ERROR;
        ret.ptr = realloc(ret.ptr, ret.len + 1);
    }

    close(fd);
    ret.ptr[ret.len] = 0;
    return  ret;

ERROR:
    if (fd >= 0) close(fd);
    buffree(ret);
    return NILBUF;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x18(%rbp)
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x3110
cmpq $0x0, -0x18(%rbp)
je 0x915c
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x915c
movq -0x18(%rbp), %rdi
leaq 0x32d9(%rip), %rsi      # 0xc416
callq 0x32a0
cmpl $0x0, %eax
je 0x915c
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movb $0x0, %al
callq 0x3150
movl %eax, -0xdc(%rbp)
jmp 0x9166
xorl %eax, %eax
movl %eax, -0xdc(%rbp)
jmp 0x9166
movl -0xdc(%rbp), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jl 0x9189
movl -0x2c(%rbp), %edi
leaq -0xc0(%rbp), %rsi
callq 0x3340
cmpl $0x0, %eax
je 0x918e
jmp 0x92e0
movl -0xa8(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x9208
movq -0x90(%rbp), %rax
movl %eax, %edi
callq 0x9320
movq %rax, -0xd0(%rbp)
movq %rdx, -0xc8(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xe8(%rbp)
movl -0x2c(%rbp), %edi
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x32d0
movq %rax, %rcx
movq -0xe8(%rbp), %rax
movl %ecx, %ecx
cmpq %rcx, %rax
je 0x9203
jmp 0x92e0
jmp 0x92ba
movl $0x1000, -0xd8(%rbp)    # imm = 0x1000
movl -0xd8(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x3270
movq %rax, -0x28(%rbp)
movl -0x2c(%rbp), %edi
movq -0x28(%rbp), %rsi
addq -0x20(%rbp), %rsi
movslq -0xd8(%rbp), %rdx
subq -0x20(%rbp), %rdx
callq 0x32d0
movl %eax, %ecx
movl %ecx, -0xd4(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
jge 0x929a
movl -0xd4(%rbp), %eax
movl -0xd8(%rbp), %ecx
movq -0x20(%rbp), %rdx
subl %edx, %ecx
cmpl %ecx, %eax
jne 0x9287
movq -0x28(%rbp), %rdi
movl -0xd8(%rbp), %eax
shll %eax
movl %eax, -0xd8(%rbp)
addl $0x1, %eax
movslq %eax, %rsi
callq 0x3330
movq %rax, -0x28(%rbp)
jmp 0x9289
movslq -0xd4(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x9227
cmpl $0x0, -0xd4(%rbp)
jge 0x92a5
jmp 0x92e0
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
addq $0x1, %rsi
callq 0x3330
movq %rax, -0x28(%rbp)
movl -0x2c(%rbp), %edi
callq 0x33c0
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x28(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x930b
cmpl $0x0, -0x2c(%rbp)
jl 0x92ee
movl -0x2c(%rbp), %edi
callq 0x33c0
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x9370
movq $0x0, -0x10(%rbp)
movq $0x0, -0x8(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rdx
addq $0xf0, %rsp
popq %rbp
retq
nopl (%rax)