// File: /workspace/github_c_makefile_star2_O2/samsonjs[P]lake/src/repl.c
// Function: read_file
static char *read_file(char const *filename)
{
    FILE *fp = fopen(filename, "r");
    if (fp)
    {
        size_t size = 4096;
        char buf[size];
        size_t n = size;
        size_t i = 0;
        size_t read;
        char *s = malloc(n);

        while (!feof(fp) && !ferror(fp))
        {
            read = fread(buf, 1, size, fp);
            if (i + read > n)
            {
                n += size;
                if (!(s = realloc(s, n))) OOM();
            }
            memcpy(s + i, buf, read);
            i += read;
        }
        s[i] = '\0';
        if (ferror(fp))
        {
            ERR("failed to read file %s: %s", filename, strerror(errno));
            return NULL;
        }
        fclose(fp);

        return s;
    }
    else
    {
        ERR("cannot open file %s: %s", filename, strerror(errno));
        return NULL;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r12
leaq 0x14df(%rip), %rsi      # 0x64b4
callq 0x11d0
testq %rax, %rax
je 0x50bb
movq %rax, %r15
movq %r12, -0x40(%rbp)
movq %rsp, -0x48(%rbp)
movq %rsp, %rax
addq $-0x1000, %rax          # imm = 0xF000
movq %rax, -0x38(%rbp)
movq %rax, %rsp
movl $0x1000, %r13d          # imm = 0x1000
movl $0x1000, %edi           # imm = 0x1000
callq 0x11a0
movq %rax, -0x30(%rbp)
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x1180
testl %eax, %eax
jne 0x5088
movq %r15, %rdi
callq 0x1080
testl %eax, %eax
jne 0x5088
movl $0x1000, %edx           # imm = 0x1000
movq -0x38(%rbp), %rdi
pushq $0x1
popq %rsi
movq %r15, %rcx
callq 0x1090
movq %rax, %r12
leaq (%rax,%rbx), %r14
cmpq %r13, %r14
jbe 0x5069
addq $0x1000, %r13           # imm = 0x1000
movq -0x30(%rbp), %rdi
movq %r13, %rsi
callq 0x11c0
testq %rax, %rax
jne 0x506d
jmp 0x516d
movq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
addq %rax, %rbx
movq %rbx, %rdi
movq -0x38(%rbp), %rsi
movq %r12, %rdx
callq 0x1190
movq %r14, %rbx
jmp 0x5014
movq -0x30(%rbp), %rax
movb $0x0, (%rax,%rbx)
movq %r15, %rdi
callq 0x1080
testl %eax, %eax
jne 0x5112
movq %r15, %rdi
callq 0x10a0
movq -0x48(%rbp), %rsp
movq -0x30(%rbp), %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4f36(%rip), %r14      # 0x9ff8
movq (%r14), %rcx
leaq 0xf92(%rip), %rdi       # 0x605e
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x11f0
movq (%r14), %rbx
callq 0x1050
movl (%rax), %edi
callq 0x1210
leaq 0x14fd(%rip), %rsi      # 0x65ea
movq $0x0, -0x30(%rbp)
movq %rbx, %rdi
movq %r12, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x1170
movq (%r14), %rsi
pushq $0xa
popq %rdi
callq 0x1100
jmp 0x50a8
movq 0x4edf(%rip), %r14      # 0x9ff8
movq (%r14), %rcx
leaq 0xf3b(%rip), %rdi       # 0x605e
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x11f0
movq (%r14), %rbx
callq 0x1050
movl (%rax), %edi
callq 0x1210
leaq 0x148b(%rip), %rsi      # 0x65cf
movq $0x0, -0x30(%rbp)
movq %rbx, %rdi
movq -0x40(%rbp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x1170
movq (%r14), %rsi
pushq $0xa
popq %rdi
callq 0x1100
jmp 0x50a4
movq 0x4e84(%rip), %rbx      # 0x9ff8
movq (%rbx), %rcx
leaq 0xee0(%rip), %rdi       # 0x605e
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x11f0
movq (%rbx), %rdi
leaq 0x122f(%rip), %rsi      # 0x63c2
leaq 0x142e(%rip), %rdx      # 0x65c8
pushq $0x7f
popq %rcx
xorl %eax, %eax
callq 0x1170
movq (%rbx), %rsi
pushq $0xa
popq %rdi
callq 0x1100
pushq $0x1
popq %rdi
callq 0x11e0