// File: /workspace/github_c_makefile_star2_O2/BernardTatin[P]s7sh/s7.c
// Function: read_error_1
static s7_pointer read_error_1(s7_scheme *sc, const char *errmsg, bool string_error)
                {
                    /* reader errors happen before the evaluator gets involved, so forms such as:
                     *   (catch #t (lambda () (car '( . ))) (lambda arg 'error))
                     * do not catch the error if we simply signal an error when we encounter it.
                     */
                    char *msg;
                    s7_int len;
                    s7_pointer pt;

                    pt = sc->input_port;
                    if (!string_error)
                    {
                        /* make an heroic effort to find where we slid off the tracks */

                        if (is_string_port(sc->input_port))
                        {
#define QUOTE_SIZE 40
                            s7_int i, j, start = 0, end, slen, size;
                            char *recent_input = NULL;
                            s7_pointer p;

                            /* we can run off the end in cases like (eval-string "(. . ,.)") or (eval-string " (@ . ,.)") */
                            if (port_position(pt) >= port_data_size(pt))
                                port_position(pt) = port_data_size(pt) - 1;

                            /* start at current position and look back a few chars */
                            for (i = port_position(pt), j = 0; (i > 0) && (j < QUOTE_SIZE); i--, j++)
                                if ((port_data(pt)[i] == '\0') ||
                                        (port_data(pt)[i] == '\n') ||
                                        (port_data(pt)[i] == '\r'))
                                    break;
                            start = i;

                            /* start at current position and look ahead a few chars */
                            size = port_data_size(pt);
                            for (i = port_position(pt), j = 0; (i < size) && (j < QUOTE_SIZE); i++, j++)
                                if ((port_data(pt)[i] == '\0') ||
                                        (port_data(pt)[i] == '\n') ||
                                        (port_data(pt)[i] == '\r'))
                                    break;

                            end = i;
                            slen = end - start;
                            /* hopefully this is more or less the current line where the read error happened */

                            if (slen > 0)
                            {
                                recent_input = (char *)calloc(slen + 9, 1);
                                for (i = 0; i < (slen + 8); i++) recent_input[i] = '.';
                                recent_input[3] = ' ';
                                recent_input[slen + 4] = ' ';
                                for (i = 0; i < slen; i++) recent_input[i + 4] = port_data(pt)[start + i];
                            }

                            if ((port_line_number(pt) > 0) &&
                                    (port_filename(pt)))
                            {
                                len = safe_strlen(recent_input) + safe_strlen(errmsg) + port_filename_length(pt) + safe_strlen(sc->current_file) + 64;
                                p = make_empty_string(sc, len, '\0');
                                msg = string_value(p);
                                len = snprintf(msg, len, "%s: %s %s[%u], last top-level form at: %s[%" print_s7_int "]",
                                        errmsg, (recent_input) ? recent_input : "", port_filename(pt), port_line_number(pt),
                                        sc->current_file, sc->current_line);
                            }
                            else
                            {
                                len = safe_strlen(recent_input) + safe_strlen(errmsg) + safe_strlen(sc->current_file) + 64;
                                p = make_empty_string(sc, len, '\0');
                                msg = string_value(p);
                                if ((sc->current_file) &&
                                        (sc->current_line >= 0))
                                    len = snprintf(msg, len, "%s: %s, last top-level form at %s[%" print_s7_int "]",
                                            errmsg, (recent_input) ? recent_input : "",
                                            sc->current_file, sc->current_line);
                                else len = snprintf(msg, len, "%s: %s", errmsg, (recent_input) ? recent_input : "");
                            }

                            string_length(p) = len;
                            if (recent_input) free(recent_input);
                            return(s7_error(sc, sc->read_error_symbol, set_elist_1(sc, p)));
                        }
                    }

                    if ((port_line_number(pt) > 0) &&
                            (port_filename(pt)))
                    {
                        s7_pointer p;
                        len = safe_strlen(errmsg) + port_filename_length(pt) + safe_strlen(sc->current_file) + 128;
                        p = make_empty_string(sc, len, '\0');
                        msg = string_value(p);
                        if (string_error)
                            len = snprintf(msg, len, "%s %s[%u],\n;  possible culprit: \"%s...\"\n;  last top-level form at %s[%" print_s7_int "]",
                                    errmsg, port_filename(pt), port_line_number(pt),
                                    sc->strbuf, sc->current_file, sc->current_line);
                        else len = snprintf(msg, len, "%s %s[%u], last top-level form at %s[%" print_s7_int "]",
                                errmsg, port_filename(pt), port_line_number(pt),
                                sc->current_file, sc->current_line);
                        string_length(p) = len;
                        return(s7_error(sc, sc->read_error_symbol, set_elist_1(sc, p)));
                    }
                    return(s7_error(sc, (string_error) ? sc->string_read_error_symbol : sc->read_error_symbol, set_elist_1(sc, s7_make_string_wrapper(sc, (char *)errmsg))));
                }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
movq 0x170(%rdi), %rdi
movq 0x8(%rdi), %r12
testl %edx, %edx
jne 0x7dc0d
cmpl $0x1, 0x4(%r12)
jne 0x7dc0d
movq 0x18(%rdi), %rax
movq 0x20(%rdi), %rcx
cmpq %rax, %rcx
jl 0x7dbd1
leaq -0x1(%rax), %rcx
movq %rcx, 0x20(%rdi)
xorl %ebp, %ebp
movl $0x2401, %edx           # imm = 0x2401
movq %rcx, %r13
testq %r13, %r13
jle 0x7dccc
cmpq $0x28, %rbp
jae 0x7dccc
movq 0x10(%rdi), %rsi
movzbl (%rsi,%r13), %esi
cmpl $0xd, %esi
ja 0x7dc05
btl %esi, %edx
jb 0x7dccc
decq %r13
incq %rbp
jmp 0x7dbdb
cmpl $0x0, 0x20(%r12)
je 0x7dcad
cmpq $0x0, 0x10(%r12)
je 0x7dcad
movq %rdi, %r13
movq %rbx, %rdi
callq 0x8d06
movq %rax, %r15
movq 0x6a8(%r14), %rdi
addq 0x30(%r12), %r15
callq 0x8d06
addq %rax, %r15
addq $0x80, %r15
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0xd239
movq %rax, %r12
movq 0x10(%rax), %rdi
movq 0x8(%r13), %rax
movq 0x10(%rax), %r8
movl 0x20(%rax), %r9d
testb %bpl, %bpl
je 0x7dd7e
subq $0x8, %rsp
leaq 0x659ba(%rip), %rdx     # 0xe363c
movq %r15, %rsi
movq %rbx, %rcx
xorl %eax, %eax
pushq 0x690(%r14)
pushq 0x6a8(%r14)
pushq 0x4b0(%r14)
callq 0x8210
addq $0x20, %rsp
jmp 0x7dda4
movzbl %bpl, %eax
movq 0x1908(%r14,%rax,8), %r15
movq %r14, %rdi
movq %rbx, %rsi
callq 0xd1ba
movq %rax, %r12
jmp 0x7df2a
movq %r12, (%rsp)
xorl %r12d, %r12d
movl $0x2401, %edx           # imm = 0x2401
leaq (%rcx,%r12), %rsi
cmpq %rax, %rsi
jge 0x7dd02
cmpq $0x27, %r12
ja 0x7dd02
movq 0x10(%rdi), %rsi
addq %rcx, %rsi
movzbl (%r12,%rsi), %esi
cmpl $0xd, %esi
ja 0x7dcfd
btl %esi, %edx
jb 0x7dd02
incq %r12
jmp 0x7dcd8
movq %rbx, 0x10(%rsp)
leaq (%r12,%rbp), %rbx
testq %rbx, %rbx
jle 0x7ddb0
movq %r14, 0x8(%rsp)
leaq (%r12,%rbp), %r14
addq $0x8, %r14
movq %rdi, %r15
leaq 0x9(%rbp,%r12), %rdi
pushq $0x1
popq %rsi
callq 0x8360
movq %r15, %rdi
movq %rax, %r15
xorl %eax, %eax
cmpq %rax, %r14
je 0x7dd48
movb $0x2e, (%r15,%rax)
incq %rax
jmp 0x7dd39
movb $0x20, %al
movb %al, 0x3(%r15)
movq %r15, %rcx
addq %r12, %rcx
movb %al, 0x4(%rbp,%rcx)
xorl %eax, %eax
movq 0x8(%rsp), %r14
movq (%rsp), %r12
cmpq %rax, %rbx
je 0x7ddb7
movq 0x10(%rdi), %rcx
addq %rax, %rcx
movb (%r13,%rcx), %cl
movb %cl, 0x4(%r15,%rax)
incq %rax
jmp 0x7dd63
leaq 0x65901(%rip), %rdx     # 0xe3686
movq %r15, %rsi
movq %rbx, %rcx
xorl %eax, %eax
pushq 0x690(%r14)
pushq 0x6a8(%r14)
callq 0x8210
addq $0x10, %rsp
cltq
movq %rax, 0x8(%r12)
jmp 0x7df23
xorl %r15d, %r15d
movq (%rsp), %r12
cmpl $0x0, 0x20(%r12)
movq 0x10(%rsp), %rbx
je 0x7de6c
cmpq $0x0, 0x10(%r12)
je 0x7de6c
movq %rdi, (%rsp)
movq %r15, %rdi
callq 0x8d06
movq %rax, %rbp
movq %rbx, %rdi
callq 0x8d06
movq %rax, %r13
movq 0x6a8(%r14), %rdi
addq %rbp, %r13
addq 0x30(%r12), %r13
callq 0x8d06
addq %rax, %r13
addq $0x40, %r13
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0xd239
movq %rax, %r12
testq %r15, %r15
leaq 0x6a64b(%rip), %r8      # 0xe846e
cmovneq %r15, %r8
movq 0x10(%rax), %rdi
movq (%rsp), %rax
movq 0x8(%rax), %rax
movq 0x10(%rax), %r9
movl 0x20(%rax), %r10d
subq $0x8, %rsp
leaq 0x65799(%rip), %rdx     # 0xe35df
movq %r13, %rsi
movq %rbx, %rcx
xorl %eax, %eax
pushq 0x690(%r14)
pushq 0x6a8(%r14)
pushq %r10
callq 0x8210
addq $0x20, %rsp
jmp 0x7df14
movq %r15, %rdi
callq 0x8d06
movq %rax, %r12
movq %rbx, %rdi
callq 0x8d06
movq %rax, %r13
movq 0x6a8(%r14), %rdi
callq 0x8d06
addq %r12, %r13
addq %rax, %r13
addq $0x40, %r13
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0xd239
movq %rax, %r12
movq 0x10(%rax), %rdi
movq 0x6a8(%r14), %r9
testq %r9, %r9
je 0x7def2
movq 0x690(%r14), %r10
testq %r10, %r10
js 0x7def2
testq %r15, %r15
leaq 0x6a5a0(%rip), %r8      # 0xe846e
cmovneq %r15, %r8
subq $0x8, %rsp
leaq 0x65731(%rip), %rdx     # 0xe360e
movq %r13, %rsi
movq %rbx, %rcx
xorl %eax, %eax
pushq %r10
callq 0x8210
addq $0x10, %rsp
jmp 0x7df14
testq %r15, %r15
leaq 0x6a572(%rip), %r8      # 0xe846e
cmovneq %r15, %r8
leaq 0x6572e(%rip), %rdx     # 0xe3635
movq %r13, %rsi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x8210
cltq
movq %rax, 0x8(%r12)
movq %r15, %rdi
callq 0x8050
movq 0x1908(%r14), %r15
movq 0x6d8(%r14), %rax
movq %r12, 0x8(%rax)
movq 0x6d8(%r14), %rdx
movq %r14, %rdi
movq %r15, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2cdc0