// File: /workspace/github_c_makefile_star2_O3/BernardTatin[P]s7sh/s7.c
// Function: read_file
static s7_pointer read_file(s7_scheme *sc, FILE *fp, const char *name, s7_int max_size, const char *caller)
    {
        s7_pointer port;
#if (!MS_WINDOWS)
        s7_int size;
#endif
        s7_int port_loc;
        block_t *b;

        new_cell(sc, port, T_INPUT_PORT);
        port_loc = s7_gc_protect_1(sc, port);
        b = mallocate_port(sc);
        port_block(port) = b;
        port_port(port) = (port_t *)block_data(b);
        port_set_closed(port, false);
        port_original_input_string(port) = sc->nil;
        /* if we're constantly opening files, and each open saves the file name in permanent memory, we gradually core-up. */
        port_filename_length(port) = safe_strlen(name);
        port_set_filename(sc, port, name, port_filename_length(port));
        port_line_number(port) = 1;  /* first line is numbered 1 */
        port_file_number(port) = 0;
        add_input_port(sc, port);

#if (!MS_WINDOWS)
        /* this doesn't work in MS C */
        fseek(fp, 0, SEEK_END);
        size = ftell(fp);
        rewind(fp);

        /* pseudo files (under /proc for example) have size=0, but we can read them, so don't assume a 0 length file is empty */

        if ((size > 0) &&                          /* if (size != 0) we get (open-input-file "/dev/tty") -> (open "/dev/tty") read 0 bytes of an expected -1? */
                ((max_size < 0) || (size < max_size))) /* load uses max_size = -1 */
        {
            size_t bytes;
            block_t *block;
            uint8_t *content;

            block = mallocate(sc, size + 2);
            content = (uint8_t *)(block_data(block));
            bytes = fread(content, sizeof(uint8_t), size, fp);
            if (bytes != (size_t)size)
            {
                if (sc->output_port != sc->F)
                {
                    char tmp[256];
                    int32_t len;
                    len = snprintf(tmp, 256, "(%s \"%s\") read %ld bytes of an expected %" print_s7_int "?", caller, name, (long)bytes, size);
                    port_write_string(sc->output_port)(sc, tmp, len, sc->output_port);
                }
                size = bytes;
            }
            content[size] = '\0';
            content[size + 1] = '\0';
            fclose(fp);

            port_file(port) = NULL; /* make valgrind happy */
            port_type(port) = STRING_PORT;
            port_data(port) = content;
            port_data_block(port) = block;
            port_data_size(port) = size;
            port_position(port) = 0;
            port_needs_free(port) = true;
            port_needs_unprotect(port) = false;
            port_port(port)->pf = &input_string_functions_1;
        }
        else
        {
            port_file(port) = fp;
            port_type(port) = FILE_PORT;
            port_data(port) = NULL;
            port_data_block(port) = NULL;
            port_data_size(port) = 0;
            port_position(port) = 0;
            port_needs_free(port) = false;
            port_port(port)->pf = &input_file_functions;
        }
#else
        /* _stat64 is no better than the fseek/ftell route, and
         *    GetFileSizeEx and friends requires Windows.h which makes hash of everything else.
         *    fread until done takes too long on big files, so use a file port
         */
        port_file(port) = fp;
        port_type(port) = FILE_PORT;
        port_needs_free(port) = false;
        port_data(port) = NULL;
        port_data_block(port) = NULL;
        port_data_size(port) = 0;
        port_position(port) = 0;
        port_port(port)->pf = &input_file_functions;
#endif

        s7_gc_unprotect_at(sc, port_loc);
        return(port);
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %r8, 0x28(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %rbx
movq 0x90(%rdi), %rax
cmpq 0x98(%rdi), %rax
ja 0x9064f
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r14
movq $0x23, (%r14)
cmpq $0x0, 0x108(%rbx)
js 0x9067b
movq 0xe8(%rbx), %rax
jmp 0x9073e
movq 0xd0(%rbx), %rax
movq 0xf0(%rbx), %rbp
movq %r12, 0x18(%rsp)
leaq (,%rbp,2), %r12
movq 0x18(%rax), %rsi
movq %rbp, %r15
shlq $0x4, %r15
movq %rbx, %rdi
movq %r15, %rdx
callq 0x9fd6
movq $0x0, 0x20(%rax)
movq 0xd0(%rbx), %rcx
movq %rax, 0x18(%rcx)
movq (%rax), %rax
movq 0xd0(%rbx), %rcx
movq %rax, 0x10(%rcx)
movq 0xd0(%rbx), %rax
movq %r12, 0x8(%rax)
movq %r12, 0xf0(%rbx)
movq 0xe8(%rbx), %rdi
movq %r15, %rsi
callq 0x8510
movq %rax, 0xe8(%rbx)
cmpq %r12, %rbp
movq 0x18(%rsp), %r12
jge 0x9073e
movq 0x140(%rbx), %rcx
movq %rbp, %rdx
movq 0xd0(%rbx), %rax
movq 0x10(%rax), %rax
movq %rcx, (%rax,%rdx,8)
movq 0xe8(%rbx), %rax
movq 0x108(%rbx), %rsi
leaq 0x1(%rsi), %rdi
movq %rdi, 0x108(%rbx)
movq %rdx, 0x8(%rax,%rsi,8)
incq %rdx
decq %rbp
jne 0x90709
movq 0xd0(%rbx), %rcx
movq 0x108(%rbx), %rdx
leaq -0x1(%rdx), %rsi
movq %rsi, 0x108(%rbx)
movq (%rax,%rdx,8), %rdx
movq 0x10(%rcx), %rax
movq %rdx, 0x10(%rsp)
movq %r14, (%rax,%rdx,8)
movq %rbx, %rdi
callq 0xf54a
movq %rax, 0x28(%r14)
movq (%rax), %rax
movq %rax, 0x8(%r14)
movb $0x0, 0x2(%rax)
movq 0x110(%rbx), %rax
movq 0x8(%r14), %rcx
movq %rax, 0x40(%rcx)
testq %r13, %r13
je 0x907ad
cmpb $0x0, (%r13)
je 0x907ad
xorl %ecx, %ecx
leaq 0x1(%rcx), %rax
cmpb $0x0, 0x1(%r13,%rcx)
movq %rax, %rcx
jne 0x9079c
jmp 0x907af
xorl %eax, %eax
movq 0x8(%r14), %rcx
movq %rax, 0x30(%rcx)
movq 0x8(%r14), %rax
movq 0x30(%rax), %r15
leaq 0x1(%r15), %rsi
movq %rbx, %rdi
callq 0x9357
movq 0x8(%r14), %rcx
movq %rax, 0x18(%rcx)
movq (%rax), %rdi
movq 0x8(%r14), %rax
movq %rdi, 0x10(%rax)
movq %r13, %rsi
movq %r15, %rdx
callq 0x83e0
movq 0x8(%r14), %rax
movq 0x10(%rax), %rax
movb $0x0, (%rax,%r15)
movq 0x8(%r14), %rax
movl $0x1, 0x20(%rax)
movq 0x8(%r14), %rax
movl $0x0, 0x24(%rax)
movq 0x748(%rbx), %r15
movq (%r15), %rax
movq 0x10(%r15), %rsi
cmpq 0x8(%r15), %rsi
jne 0x9083b
leaq (%rsi,%rsi), %rcx
movq %rcx, 0x8(%r15)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x8510
movq %rax, (%r15)
movq 0x10(%r15), %rsi
leaq 0x1(%rsi), %rcx
movq %rcx, 0x10(%r15)
movq %r14, (%rax,%rsi,8)
movq %r12, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x8500
movq %r12, %rdi
callq 0x83a0
movq %rax, %rbp
movq %r12, %rdi
callq 0x81e0
testq %rbp, %rbp
setle %al
cmpq 0x20(%rsp), %rbp
setae %cl
orb %al, %cl
jne 0x908b4
leaq 0x2(%rbp), %rsi
movq %rbx, %rdi
callq 0x9357
movq %r12, %rcx
movq %rax, 0x20(%rsp)
movq (%rax), %r12
movl $0x1, %esi
movq %r12, %rdi
movq %rbp, %rdx
movq %rcx, 0x18(%rsp)
callq 0x8110
cmpq %rbp, %rax
jne 0x908f5
movq %rbp, %r15
jmp 0x9094e
movq 0x8(%r14), %rax
movq %r12, 0x8(%rax)
movq 0x8(%r14), %rax
movl $0x0, 0x4(%rax)
xorl %eax, %eax
movq %rax, 0x10(%r14)
movq 0x8(%r14), %rcx
movq %rax, 0x38(%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r14)
movq 0x8(%r14), %rax
movb $0x0, (%rax)
leaq 0xb5c15(%rip), %rax     # 0x146500
movq 0x10(%rsp), %r13
jmp 0x909a8
movq %rax, %r15
movq 0x188(%rbx), %rax
cmpq 0x120(%rbx), %rax
je 0x9094e
movq %rbp, (%rsp)
leaq 0x85f17(%rip), %rdx     # 0x11682a
leaq 0x30(%rsp), %rbp
movl $0x100, %esi            # imm = 0x100
movq %rbp, %rdi
movq 0x28(%rsp), %rcx
movq %r13, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x8210
movq 0x188(%rbx), %rcx
movq 0x8(%rcx), %rdx
movq 0x48(%rdx), %r8
movslq %eax, %rdx
movq %rbx, %rdi
movq %rbp, %rsi
callq *0x10(%r8)
movq 0x10(%rsp), %r13
movw $0x0, (%r12,%r15)
movq 0x18(%rsp), %rdi
callq 0x8180
movq 0x8(%r14), %rax
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq 0x8(%r14), %rax
movl $0x1, 0x4(%rax)
movq %r12, 0x10(%r14)
movq 0x8(%r14), %rax
movq 0x20(%rsp), %rdx
movq %rdx, 0x38(%rax)
movq %r15, 0x18(%r14)
movq %rcx, 0x20(%r14)
movq 0x8(%r14), %rax
movb $0x1, (%rax)
movq 0x8(%r14), %rax
movb $0x0, 0x1(%rax)
leaq 0xb5b08(%rip), %rax     # 0x1464b0
movq 0x8(%r14), %rcx
movq %rax, 0x48(%rcx)
cmpq %r13, 0xf0(%rbx)
jle 0x909f7
movq 0xd0(%rbx), %rcx
movq 0x140(%rbx), %rax
movq 0x10(%rcx), %rdx
cmpq %rax, (%rdx,%r13,8)
je 0x909f3
movq 0xe8(%rbx), %rdx
movq 0x108(%rbx), %rsi
leaq 0x1(%rsi), %rdi
movq %rdi, 0x108(%rbx)
movq %r13, 0x8(%rdx,%rsi,8)
movq 0x10(%rcx), %rdx
movq %rax, (%rdx,%r13,8)
movq %r14, %rax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq