// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x178, %rsp            # imm = 0x178
movq %rdi, 0x170(%rsp)
movq %rsi, 0x168(%rsp)
movq %rdx, 0x160(%rsp)
movq %rcx, 0x158(%rsp)
movq %r8, 0x150(%rsp)
movq 0x170(%rsp), %rax
movq 0x90(%rax), %rax
movq 0x170(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0xc877c
movq 0x170(%rsp), %rdi
callq 0xc670
movq 0x170(%rsp), %rcx
movq 0x90(%rcx), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, 0x90(%rcx)
movq -0x8(%rax), %rax
movq %rax, 0x148(%rsp)
movq 0x148(%rsp), %rax
movq $0x23, (%rax)
movq 0x170(%rsp), %rdi
movq 0x148(%rsp), %rsi
callq 0x9cb0
movq %rax, 0x138(%rsp)
movq 0x170(%rsp), %rdi
callq 0x15570
movq %rax, 0x130(%rsp)
movq 0x130(%rsp), %rcx
movq 0x148(%rsp), %rax
movq %rcx, 0x28(%rax)
movq 0x130(%rsp), %rax
movq (%rax), %rcx
movq 0x148(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movb $0x0, 0x2(%rax)
movq 0x170(%rsp), %rax
movq 0x110(%rax), %rcx
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x40(%rax)
movq 0x160(%rsp), %rdi
callq 0xa430
movq %rax, %rcx
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x30(%rax)
movq 0x170(%rsp), %rdi
movq 0x148(%rsp), %rsi
movq 0x160(%rsp), %rdx
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x30(%rax), %rcx
callq 0x15600
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movl $0x1, 0x20(%rax)
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movl $0x0, 0x24(%rax)
movq 0x170(%rsp), %rax
movq 0x748(%rax), %rdi
movq 0x148(%rsp), %rsi
callq 0x11230
movq 0x168(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x9500
movq 0x168(%rsp), %rdi
callq 0x93a0
movq %rax, 0x140(%rsp)
movq 0x168(%rsp), %rdi
callq 0x91e0
cmpq $0x0, 0x140(%rsp)
jle 0xc8b41
cmpq $0x0, 0x158(%rsp)
jl 0xc8937
movq 0x140(%rsp), %rax
cmpq 0x158(%rsp), %rax
jge 0xc8b41
movq 0x170(%rsp), %rdi
movq 0x140(%rsp), %rsi
addq $0x2, %rsi
callq 0xaa80
movq %rax, 0x120(%rsp)
movq 0x120(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x118(%rsp)
movq 0x118(%rsp), %rdi
movq 0x140(%rsp), %rdx
movq 0x168(%rsp), %rcx
movl $0x1, %esi
callq 0x9110
movq %rax, 0x128(%rsp)
movq 0x128(%rsp), %rax
cmpq 0x140(%rsp), %rax
je 0xc8a59
movq 0x170(%rsp), %rax
movq 0x188(%rax), %rax
movq 0x170(%rsp), %rcx
cmpq 0x120(%rcx), %rax
je 0xc8a49
leaq 0x10(%rsp), %rdi
movq 0x150(%rsp), %rcx
movq 0x160(%rsp), %r8
movq 0x128(%rsp), %r9
movq 0x140(%rsp), %rax
movl $0x100, %esi            # imm = 0x100
leaq 0x125903(%rip), %rdx    # 0x1ee2ff
movq %rax, (%rsp)
movb $0x0, %al
callq 0x9210
movl %eax, 0xc(%rsp)
movq 0x170(%rsp), %rax
movq 0x188(%rax), %rax
movq 0x8(%rax), %rax
movq 0x48(%rax), %rax
movq 0x10(%rax), %rax
movq 0x170(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movslq 0xc(%rsp), %rdx
movq 0x170(%rsp), %rcx
movq 0x188(%rcx), %rcx
callq *%rax
movq 0x128(%rsp), %rax
movq %rax, 0x140(%rsp)
movq 0x118(%rsp), %rax
movq 0x140(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x118(%rsp), %rax
movq 0x140(%rsp), %rcx
movb $0x0, 0x1(%rax,%rcx)
movq 0x168(%rsp), %rdi
callq 0x9180
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movq $0x0, 0x8(%rax)
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movl $0x1, 0x4(%rax)
movq 0x118(%rsp), %rcx
movq 0x148(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x120(%rsp), %rcx
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x38(%rax)
movq 0x140(%rsp), %rcx
movq 0x148(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x148(%rsp), %rax
movq $0x0, 0x20(%rax)
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movb $0x1, (%rax)
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movb $0x0, 0x1(%rax)
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
leaq 0x14d010(%rip), %rcx    # 0x215b48
movq %rcx, 0x48(%rax)
jmp 0xc8bd6
movq 0x168(%rsp), %rcx
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movl $0x0, 0x4(%rax)
movq 0x148(%rsp), %rax
movq $0x0, 0x10(%rax)
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movq $0x0, 0x38(%rax)
movq 0x148(%rsp), %rax
movq $0x0, 0x18(%rax)
movq 0x148(%rsp), %rax
movq $0x0, 0x20(%rax)
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movb $0x0, (%rax)
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
leaq 0x14cfc6(%rip), %rcx    # 0x215b98
movq %rcx, 0x48(%rax)
movq 0x170(%rsp), %rdi
movq 0x138(%rsp), %rsi
callq 0x9f60
movq 0x148(%rsp), %rax
addq $0x178, %rsp            # imm = 0x178
retq
nopl (%rax,%rax)