// File: /workspace/github_c_makefile_star2_O1/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 0x68946
movq 0x8(%rsi), %r12
testq %r12, %r12
js 0x6896f
cmpq 0x2a8(%rbx), %r12
jle 0x689b7
movq 0x1458(%rbx), %rax
movq 0x8(%rax), %rax
movq 0xe607d(%rip), %rcx     # 0x14e958
movq 0x1f00(%rbx), %rdx
movq %r12, 0x8(%rdx)
movq 0x1ee8(%rbx), %rdx
movq 0x1f00(%rbx), %rsi
movq 0xea145(%rip), %rdi     # 0x152a40
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), %r15
movq 0x1ee8(%rbx), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3b366
movq %r15, %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 0xf1ae
movq 0x1458(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xe5fd7(%rip), %rdx     # 0x14e958
movq 0x1f00(%rbx), %rax
movq %r12, 0x8(%rax)
movq 0x1f00(%rbx), %rcx
movq 0x140(%rbx), %r8
movq 0xf2237(%rip), %r9      # 0x15abd8
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb31d
movq 0x10(%rcx), %rax
cmpq 0x110(%rbx), %rax
je 0x689ca
movq 0x8(%rax), %r14
jmp 0x689de
movq %rbx, %rdi
callq 0x103191
movq %rax, %r14
testq %rax, %rax
je 0x68b7f
cmpb $0x23, (%r14)
jne 0x68a20
movq 0x8(%r14), %rax
cmpb $0x1, 0x2(%rax)
jne 0x68a44
movq 0x1458(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0x140(%rbx), %rcx
movq 0xf1921(%rip), %r8      # 0x15a328
movq %rbx, %rdi
movq %r14, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xfac8
movq 0x1458(%rbx), %r15
cmpq $0x7ff, %r12            # imm = 0x7FF
ja 0x68ab6
leaq 0xe5f15(%rip), %rax     # 0x14e950
movq (%rax,%r12,8), %r13
jmp 0x68af0
testq %r12, %r12
je 0x68b8b
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0xf83b
movq %rax, %r15
movq 0x10(%rax), %r13
movq 0x8(%r14), %rax
movl 0x4(%rax), %ecx
testl %ecx, %ecx
je 0x68ba5
cmpl $0x1, %ecx
jne 0x68bc8
movq 0x18(%r14), %rbx
movq 0x20(%r14), %rsi
subq %rsi, %rbx
cmpq %r12, %rbx
cmovgeq %r12, %rbx
testq %rbx, %rbx
jle 0x68b7f
addq 0x10(%r14), %rsi
movq %r13, %rdi
movq %rbx, %rdx
callq 0x93e0
movq %rbx, 0x8(%r15)
movb $0x0, (%r13,%rbx)
addq %rbx, 0x20(%r14)
jmp 0x68934
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x68ace
movq %rbx, %rdi
callq 0xb389
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r13
movq $0xb, (%r13)
movq %r12, 0x8(%r13)
movq 0x90(%rbx), %rax
movq 0x110(%rbx), %r12
cmpq 0x98(%rbx), %rax
ja 0x68b0f
movq %rbx, %rdi
callq 0xb389
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 %r12, 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 0xea0a3(%rip), %r8      # 0x152c00
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
movl $0x2, %r9d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xf3da
movq 0xe5bda(%rip), %r15     # 0x14e760
jmp 0x68934
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 0xf83b
movq 0x8(%rax), %rcx
movl $0x1, %esi
movq %r13, %rdi
movq %r12, %rdx
callq 0x9110
movb $0x0, (%r13,%rax)
movq %rax, 0x8(%r15)
jmp 0x68934
cmpq $0x2, %r12
movl $0x1, %ebp
cmovgeq %r12, %rbp
xorl %r12d, %r12d
movq 0x8(%r14), %rax
movq 0x48(%rax), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *(%rax)
cmpl $-0x1, %eax
je 0x68bf4
movb %al, (%r13,%r12)
jmp 0x68c0e
testq %r12, %r12
je 0x68c03
movq %r12, 0x8(%r15)
movq %r15, (%rsp)
jmp 0x68c0e
movq 0xe5b56(%rip), %rcx     # 0x14e760
movq %rcx, (%rsp)
cmpl $-0x1, %eax
je 0x68c20
incq %r12
cmpq %r12, %rbp
jne 0x68bd8
jmp 0x68934
movq (%rsp), %r15
jmp 0x68934