// File: /workspace/github_c_makefile_star2_O3/BernardTatin[P]s7sh/s7.c
// Function: g_read_string
static s7_pointer g_read_string(s7_scheme *sc, s7_pointer args)
    {
        /* read-chars would be a better name -- read-string could mean CL-style read-from-string (like eval-string)
         *   similarly read-bytes could return a byte-vector (rather than r7rs's read-bytevector)
         *   and write-string -> write-chars, write-bytevector -> write-bytes
         */
#define H_read_string "(read-string k port) reads k characters from port into a new string and returns it."
#define Q_read_string s7_make_signature(sc, 3, s7_make_signature(sc, 2, sc->is_string_symbol, sc->is_eof_object_symbol), sc->is_integer_symbol, sc->is_input_port_symbol)
        s7_pointer k, port, s;
        s7_int i, nchars;
        uint8_t *str;

        k = car(args);
        if (!s7_is_integer(k))
            return(method_or_bust(sc, k, sc->read_string_symbol, args, T_INTEGER, 1));
        nchars = s7_integer(k);
        if (nchars < 0)
            return(wrong_type_argument_with_type(sc, sc->read_string_symbol, 1, wrap_integer1(sc, nchars), a_non_negative_integer_string));
        if (nchars > sc->max_string_length)
            return(out_of_range(sc, sc->read_string_symbol, small_int(1), wrap_integer1(sc, nchars), its_too_large_string));

        if (!is_null(cdr(args)))
            port = cadr(args);
        else
        {
            port = input_port_if_not_loading(sc);
            if (!port) return(eof_object);
        }
        if (!is_input_port(port))
            return(method_or_bust_with_type(sc, port, sc->read_string_symbol, list_2(sc, make_integer(sc, nchars), port), an_input_port_string, 2));
        if (port_is_closed(port))
            return(simple_wrong_type_argument_with_type(sc, sc->read_string_symbol, port, an_open_port_string));

        if (nchars == 0)
            return(make_empty_string(sc, 0, 0));

        s = make_empty_string(sc, nchars, 0);
        str = (uint8_t *)string_value(s);
        if (is_string_port(port))
        {
            s7_int pos, end, len;
            pos = port_position(port);
            end = port_data_size(port);
            len = end - pos;
            if (len > nchars) len = nchars;
            if (len <= 0) return(eof_object);
            memcpy((void *)str, (void *)(port_data(port) + pos), len);
            string_length(s) = len;
            str[len] = '\0';
            port_position(port) += len;
            return(s);
        }
        if (is_file_port(port))
        {
            size_t len;
            len = fread((void *)str, 1, nchars, port_file(port));
            str[len] = '\0';
            string_length(s) = len;
            return(s);
        }
        for (i = 0; i < nchars; i++)
        {
            int32_t c;
            c = port_read_character(port)(sc, port);
            if (c == EOF)
            {
                if (i == 0)
                    return(eof_object);
                string_length(s) = i;
                return(s);
            }
            str[i] = (uint8_t)c;
        }
        return(s);
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rcx
movq %rdi, %rbx
movq 0x8(%rsi), %rsi
cmpb $0xb, (%rsi)
jne 0x6391c
movq 0x8(%rsi), %r15
testq %r15, %r15
js 0x63945
cmpq 0x2a8(%rbx), %r15
jle 0x6398d
movq 0x1458(%rbx), %rax
movq 0x8(%rax), %rax
movq 0xe30a7(%rip), %rcx     # 0x146958
movq 0x1f00(%rbx), %rdx
movq %r15, 0x8(%rdx)
movq 0x1ee8(%rbx), %rdx
movq 0x1f00(%rbx), %rsi
movq 0xe716f(%rip), %rdi     # 0x14aa40
movq 0x10(%rdx), %rdx
movq %rax, 0x8(%rdx)
movq 0x10(%rdx), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rax), %rax
movq %rsi, 0x8(%rax)
movq 0x10(%rax), %rax
movq %rdi, 0x8(%rax)
movq 0x1948(%rbx), %r12
movq 0x1ee8(%rbx), %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x38dfa
movq %r12, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1458(%rbx), %rdx
movq %rbx, %rdi
movl $0xb, %r8d
movl $0x1, %r9d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe42d
movq 0x1458(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xe3001(%rip), %rdx     # 0x146958
movq 0x1f00(%rbx), %rax
movq %r15, 0x8(%rax)
movq 0x1f00(%rbx), %rcx
movq 0x140(%rbx), %r8
movq 0xef261(%rip), %r9      # 0x152bd8
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa4e4
movq 0x10(%rcx), %rax
cmpq 0x110(%rbx), %rax
je 0x639a0
movq 0x8(%rax), %r14
jmp 0x639b4
movq %rbx, %rdi
callq 0xfa3f2
movq %rax, %r14
testq %rax, %rax
je 0x63bcc
cmpb $0x23, (%r14)
jne 0x639f6
movq 0x8(%r14), %rax
cmpb $0x1, 0x2(%rax)
jne 0x63a1a
movq 0x1458(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0x140(%rbx), %rcx
movq 0xee94b(%rip), %r8      # 0x152328
movq %rbx, %rdi
movq %r14, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xed2a
movq 0x1458(%rbx), %r12
cmpq $0x7ff, %r15            # imm = 0x7FF
ja 0x63a8d
leaq 0xe2f3f(%rip), %rax     # 0x146950
movq (%rax,%r15,8), %r13
jmp 0x63ac7
testq %r15, %r15
je 0x63b56
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0xeab0
movq %rax, %r12
movq 0x10(%rax), %r13
movq 0x8(%r14), %rax
movl 0x4(%rax), %ecx
testl %ecx, %ecx
je 0x63b70
cmpl $0x1, %ecx
jne 0x63b94
movq 0x18(%r14), %rbx
movq 0x20(%r14), %rsi
subq %rsi, %rbx
cmpq %r15, %rbx
cmovgeq %r15, %rbx
testq %rbx, %rbx
jle 0x63bcc
addq 0x10(%r14), %rsi
movq %r13, %rdi
movq %rbx, %rdx
callq 0x83e0
movq %rbx, 0x8(%r12)
movb $0x0, (%r13,%rbx)
addq %rbx, 0x20(%r14)
jmp 0x6390a
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x63aac
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r13
movq $0xb, (%r13)
movq %r15, 0x8(%r13)
movq 0x90(%rbx), %rax
movq 0x110(%rbx), %r15
cmpq 0x98(%rbx), %rax
ja 0x63aed
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movl $0x200001, %edx         # imm = 0x200001
movq %rdx, (%rax)
movq %r14, 0x8(%rax)
movq %r15, 0x10(%rax)
movq 0x90(%rbx), %rcx
leaq -0x8(%rcx), %rsi
movq %rsi, 0x90(%rbx)
movq -0x8(%rcx), %rcx
movq %rdx, (%rcx)
movq %r13, 0x8(%rcx)
movq %rax, 0x10(%rcx)
movq 0xe70cc(%rip), %r8      # 0x14ac00
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
movl $0x2, %r9d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe659
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xeab0
movq 0x8(%rax), %rcx
movl $0x1, %esi
movq %r13, %rdi
movq %r15, %rdx
callq 0x8110
movb $0x0, (%r13,%rax)
movq %rax, 0x8(%r12)
jmp 0x6390a
xorl %ebp, %ebp
movq 0x8(%r14), %rax
movq 0x48(%rax), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *(%rax)
cmpl $-0x1, %eax
je 0x63bbd
movb %al, (%r13,%rbp)
incq %rbp
cmpq %rbp, %r15
jne 0x63b96
jmp 0x6390a
testq %rbp, %rbp
je 0x63bcc
movq %rbp, 0x8(%r12)
jmp 0x6390a
movq 0xe2b8d(%rip), %r12     # 0x146760
jmp 0x6390a