// File: /workspace/github_c_makefile_star2_O3/BernardTatin[P]s7sh/s7.c
// Function: g_object_to_string
static s7_pointer g_object_to_string(s7_scheme *sc, s7_pointer args)
    {
#define H_object_to_string "(object->string obj (write #t) (max-len most-positive-fixnum)) returns a string representation of obj."
#define Q_object_to_string s7_make_signature(sc, 4, sc->is_string_symbol, sc->T, s7_make_signature(sc, 2, sc->is_boolean_symbol, sc->is_keyword_symbol), sc->is_integer_symbol)

        use_write_t choice;
        s7_pointer obj, strport, res;
        s7_int out_len, pending_max;
        bool old_openlets;

        pending_max = s7_int_max;
        old_openlets = sc->has_openlets;
        obj = car(args);

        if (is_not_null(cdr(args)))
        {
            s7_pointer arg;
            arg = cadr(args);
            if (arg == sc->F) choice = P_DISPLAY;
            else {if (arg == sc->T) choice = P_WRITE;
                else {if (arg == sc->key_readable_symbol) choice = P_READABLE;
                    else {if (arg == sc->key_display_symbol) choice = P_DISPLAY;
                        else {if (arg == sc->key_write_symbol) choice = P_WRITE;
                            else return(wrong_type_argument_with_type(sc, sc->object_to_string_symbol, 2, arg, wrap_string(sc, "a boolean or :readable", 22)));}}}}

                            if (is_not_null(cddr(args)))
                            {
                                arg = caddr(args);
                                if (!s7_is_integer(arg))
                                {
                                    if (choice == P_READABLE) /* (object->string #r(1 2 3) :readable "hi") */
                                        return(wrong_type_argument(sc, sc->object_to_string_symbol, 3, arg, T_INTEGER));
                                    return(method_or_bust(sc, arg, sc->object_to_string_symbol, args, T_INTEGER, 3));
                                }
                                if (s7_integer(arg) < 0)
                                    return(out_of_range(sc, sc->object_to_string_symbol, small_int(3), arg, a_non_negative_integer_string));
                                pending_max = s7_integer(arg);
                            }
        }
        else choice = P_WRITE;
        /* can't use s7_object_to_string here anymore because it assumes use_write arg is a boolean */

        if (choice == P_READABLE)
            sc->has_openlets = false;
        else check_method(sc, obj, sc->object_to_string_symbol, args);

        strport = open_format_port(sc);
        sc->objstr_max_len = pending_max;
        object_out(sc, obj, strport, choice);
        sc->objstr_max_len = s7_int_max;
        out_len = port_position(strport);

        if ((pending_max >= 0) &&
                (out_len > pending_max))
        {
            s7_int i;
            if (choice == P_READABLE)  /* (object->string #r(1 2 3) :readable 4) */
                return(out_of_range(sc, sc->object_to_string_symbol, small_int(3), make_integer(sc, out_len), wrap_string(sc, "the readable string is too long", 31)));

            out_len = pending_max;
            if (out_len < 3)
            {
                close_format_port(sc, strport);
                sc->has_openlets = old_openlets;
                return(make_string_with_length(sc, "...", 3));
            }
            for (i = out_len - 3; i < out_len; i++)
                port_data(strport)[i] = (uint8_t)'.';
        }

        if (out_len >= port_data_size(strport))
            res = block_to_string(sc, reallocate(sc, port_data_block(strport), out_len + 1), out_len);
        else res = block_to_string(sc, port_data_block(strport), out_len);
        restore_format_port(sc, strport);
        sc->has_openlets = old_openlets;
        return(res);
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
xorl %r12d, %r12d
cmpb $0x0, 0xd91a2(%rip)     # 0x14ac08
movl $0x0, %r13d
cmovneq %rax, %r13
movb 0x24c(%rdi), %al
movb %al, 0x8(%rsp)
movq 0x8(%rsi), %rbp
movq 0x10(%rsi), %rax
movq 0x110(%rdi), %r15
cmpq %r15, %rax
je 0x71bb7
movq 0x8(%rax), %rcx
cmpq 0x120(%rbx), %rcx
je 0x71b24
movl $0x1, %r12d
cmpq 0x118(%rbx), %rcx
je 0x71b24
cmpq 0x18a0(%rbx), %rcx
je 0x71ea2
cmpq 0x18a8(%rbx), %rcx
je 0x7212c
cmpq 0x18b0(%rbx), %rcx
je 0x71b24
movq 0x1380(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xd4e79(%rip), %rdx     # 0x146960
movq 0x140(%rbx), %r8
movq 0x820(%rbx), %rax
movslq 0x7dc(%rbx), %rdi
movq (%rax,%rdi,8), %r9
leal 0x1(%rdi), %eax
andl $0x7, %eax
movl %eax, 0x7dc(%rbx)
leaq 0xa9c75(%rip), %rax     # 0x11b788
movq %rax, 0x10(%r9)
movq $0x16, 0x8(%r9)
jmp 0x71d8d
xorl %esi, %esi
movq 0x10(%rax), %rax
cmpq %r15, %rax
je 0x71b49
movq 0x8(%rax), %rcx
cmpb $0xb, (%rcx)
jne 0x71d64
movq 0x8(%rcx), %r13
testq %r13, %r13
js 0x720ce
testb %sil, %sil
je 0x71bbd
movb $0x0, 0x24c(%rbx)
movq %rbx, %rdi
callq 0x37d3b
movq %rax, %r14
leaq 0x288(%rbx), %r15
movq %r13, 0x288(%rbx)
movzbl (%rbp), %eax
leaq 0xe07c7(%rip), %rcx     # 0x152340
cmpb $0x1, (%rax,%rcx)
jne 0x71da3
cmpl $0x15, %eax
jne 0x71b92
testb $0x1, 0x7(%rbp)
jne 0x71da3
cmpq %rbp, 0x150(%rbx)
je 0x71da3
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
movl $0x2, %ecx
callq 0x95196
jmp 0x71dbf
movl $0x1, %r12d
testb $0x40, 0x3(%rbp)
je 0x71ce2
cmpb $0x0, 0x8(%rsp)
je 0x71ce2
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x8a63
movq 0x1380(%rbx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x89ff
cmpq 0x128(%rbx), %rax
je 0x71ce2
cmpb $0x1, (%r14)
jne 0x72136
movq %rax, 0x8(%rsp)
movq %r14, 0x4c8(%rbx)
movq 0x8(%r14), %r13
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x71c35
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r12
movq $0x200001, (%r12)       # imm = 0x200001
movq %r13, 0x8(%r12)
movq %r15, 0x10(%r12)
movq %r12, 0x4e8(%rbx)
movq 0x10(%r14), %r14
cmpb $0x1, (%r14)
jne 0x71cc3
movq %r12, %r15
movq 0x8(%r14), %r13
movq 0x90(%rbx), %rax
movq 0x110(%rbx), %rbp
cmpq 0x98(%rbx), %rax
ja 0x71c94
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0x200001, (%rax)       # imm = 0x200001
movq %r13, 0x8(%rax)
movq %rbp, 0x10(%rax)
movq %rax, 0x10(%r15)
movq 0x10(%r14), %r14
cmpb $0x1, (%r14)
movq %rax, %r15
je 0x71c6a
movq 0x110(%rbx), %rax
movq %rax, 0x4e8(%rbx)
movq %rax, 0x4c8(%rbx)
movq 0x8(%rsp), %rax
jmp 0x72139
movq %rbx, %rdi
callq 0x37d3b
movq %rax, %r14
leaq 0x288(%rbx), %r15
movq %r13, 0x288(%rbx)
movzbl (%rbp), %eax
leaq 0xe063a(%rip), %rcx     # 0x152340
cmpb $0x1, (%rax,%rcx)
jne 0x71d3f
cmpl $0x15, %eax
jne 0x71d17
testb $0x1, 0x7(%rbp)
jne 0x71d3f
cmpq %rbp, 0x150(%rbx)
je 0x71d3f
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
movl %r12d, %ecx
callq 0x95196
movq $0x0, 0x10(%rsp)
jmp 0x71dc6
leaq 0xe063a(%rip), %r9      # 0x152380
movq $0x0, 0x10(%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
movl %r12d, %ecx
xorl %r8d, %r8d
callq *(%r9,%rax,8)
jmp 0x71dc6
movq 0x1380(%rbx), %rdx
testb %sil, %sil
je 0x71eb0
movq 0x8(%rdx), %rsi
movq 0xd4be9(%rip), %rdx     # 0x146968
movq 0x140(%rbx), %r8
movq 0xd8d2b(%rip), %r9      # 0x14aab8
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa4e4
leaq 0xe05d6(%rip), %r9      # 0x152380
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
movl $0x2, %ecx
xorl %r8d, %r8d
callq *(%r9,%rax,8)
movb $0x1, %al
movq %rax, 0x10(%rsp)
xorl %eax, %eax
cmpb $0x0, 0xd8e39(%rip)     # 0x14ac08
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
cmovneq %rcx, %rax
movq %rax, (%r15)
movq 0x20(%r14), %r15
cmpq %r13, %r15
jle 0x71f87
cmpb $0x0, 0x10(%rsp)
je 0x71e23
movq 0x1380(%rbx), %rax
movq 0x8(%rax), %r12
movq 0xd4b62(%rip), %r14     # 0x146968
cmpq $0x7ff, %r15            # imm = 0x7FF
ja 0x71ed8
leaq 0xd4b36(%rip), %rax     # 0x146950
movq (%rax,%r15,8), %rax
jmp 0x71f11
cmpq $0x2, %r13
ja 0x71f6d
movq 0x7e8(%rbx), %rax
movq 0x28(%r14), %rcx
movq %rax, 0x18(%rcx)
movq %r14, 0x7e8(%rbx)
movb 0x8(%rsp), %al
movb %al, 0x24c(%rbx)
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x71e6c
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r15
movq $0x200013, (%r15)       # imm = 0x200013
movq 0x850(%rbx), %r14
testq %r14, %r14
je 0x72155
movq 0x18(%r14), %rax
movq %rax, 0x850(%rbx)
jmp 0x721f5
movl $0x2, %r12d
movb $0x1, %sil
jmp 0x71b26
movq %rbx, %rdi
movq %rcx, %rsi
movq %r14, %rcx
movl $0xb, %r8d
movl $0x3, %r9d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe42d
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x71ef7
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0xb, (%rax)
movq %r15, 0x8(%rax)
movq 0x820(%rbx), %rcx
movslq 0x7dc(%rbx), %rdx
movq (%rcx,%rdx,8), %rcx
incl %edx
andl $0x7, %edx
movl %edx, 0x7dc(%rbx)
leaq 0xa986a(%rip), %rdx     # 0x11b79f
movq %rdx, 0x10(%rcx)
movq $0x1f, 0x8(%rcx)
movq 0x1ee8(%rbx), %rdx
movq 0x10(%rdx), %rdx
movq %r12, 0x8(%rdx)
movq 0x10(%rdx), %rdx
movq %r14, 0x8(%rdx)
movq 0x10(%rdx), %rdx
movq %rax, 0x8(%rdx)
movq 0x10(%rdx), %rax
movq %rcx, 0x8(%rax)
jmp 0x7210e
movq $-0x3, %rax
movq 0x10(%r14), %rcx
addq %r13, %rcx
movb $0x2e, (%rax,%rcx)
incq %rax
jne 0x71f74
movq %r13, %r15
movq 0x8(%r14), %rax
movq 0x38(%rax), %rsi
cmpq 0x18(%r14), %r15
jl 0x71fa4
leaq 0x1(%r15), %rdx
movq %rbx, %rdi
callq 0x9fd6
movq %rax, %rsi
movq %rbx, %rdi
movq %r15, %rdx
callq 0x37ebe
movq %rax, %r15
movq 0x870(%rbx), %r12
testq %r12, %r12
je 0x71fd3
movq 0x18(%r12), %rax
movq %rax, 0x870(%rbx)
movq (%r12), %rcx
jmp 0x72079
movq 0x838(%rbx), %r12
testq %r12, %r12
jne 0x7201e
movl $0x2800, %edi           # imm = 0x2800
callq 0x8480
movq %rax, %r12
movq %rax, 0x838(%rbx)
addq $0x28, %rax
movl $0xff, %ecx
movq %rax, -0x10(%rax)
movl $0x0, -0x20(%rax)
addq $0x28, %rax
decl %ecx
jne 0x71ffc
movq $0x0, -0x10(%rax)
movl $0x0, -0x20(%rax)
movq 0x18(%r12), %rax
movq %rax, 0x838(%rbx)
movq 0x8c8(%rbx), %rcx
leaq 0x80(%rcx), %rdx
cmpq $0x10000, %rdx          # imm = 0x10000
jbe 0x7205b
movl $0x10000, %edi          # imm = 0x10000
callq 0x8480
movq %rax, 0x8d0(%rbx)
movl $0x80, %edx
xorl %ecx, %ecx
jmp 0x72062
movq 0x8d0(%rbx), %rax
addq %rax, %rcx
movq %rdx, 0x8c8(%rbx)
movq %rcx, (%r12)
movl $0x7, 0x8(%r12)
movl $0x80, %eax
movq %rax, 0x10(%r12)
movq %rcx, 0x10(%r14)
movq 0x8(%r14), %rcx
movq %r12, 0x38(%rcx)
movq 0x10(%r14), %rcx
xorl %edx, %edx
movb %dl, (%rcx)
movq $0x0, 0x20(%r14)
movq %rax, 0x18(%r14)
movq 0x8(%r14), %rax
movb %dl, (%rax)
movq 0x7e8(%rbx), %rax
movq 0x28(%r14), %rcx
movq %rax, 0x18(%rcx)
movq %r14, 0x7e8(%rbx)
movb 0x8(%rsp), %al
movb %al, 0x24c(%rbx)
jmp 0x72264
movq 0x1380(%rbx), %rax
movq 0x8(%rax), %rax
movq 0xd4888(%rip), %rdx     # 0x146968
movq 0xe0af1(%rip), %rsi     # 0x152bd8
movq 0x1ee8(%rbx), %rdi
movq 0x10(%rdi), %rdi
movq %rax, 0x8(%rdi)
movq 0x10(%rdi), %rax
movq %rdx, 0x8(%rax)
movq 0x10(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rax), %rax
movq %rsi, 0x8(%rax)
movq 0x1948(%rbx), %r15
movq 0x1ee8(%rbx), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x38dfa
jmp 0x72264
xorl %esi, %esi
xorl %r12d, %r12d
jmp 0x71b26
movq %r15, %r12
movq %rbx, %rdi
movq %rax, %rsi
movq %r12, %rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xaee6
movq 0x838(%rbx), %r14
testq %r14, %r14
jne 0x721a0
movl $0x2800, %edi           # imm = 0x2800
callq 0x8480
movq %rax, %r14
movq %rax, 0x838(%rbx)
addq $0x28, %rax
movl $0xff, %ecx
movq %rax, -0x10(%rax)
movl $0x0, -0x20(%rax)
addq $0x28, %rax
decl %ecx
jne 0x7217e
movq $0x0, -0x10(%rax)
movl $0x0, -0x20(%rax)
movq 0x18(%r14), %rax
movq %rax, 0x838(%rbx)
movq 0x8c8(%rbx), %rcx
leaq 0x8(%rcx), %rdx
cmpq $0x10000, %rdx          # imm = 0x10000
jbe 0x721d9
movl $0x10000, %edi          # imm = 0x10000
callq 0x8480
movq %rax, 0x8d0(%rbx)
movl $0x8, %edx
xorl %ecx, %ecx
jmp 0x721e0
movq 0x8d0(%rbx), %rax
addq %rax, %rcx
movq %rdx, 0x8c8(%rbx)
movq %rcx, (%r14)
movl $0x3, 0x8(%r14)
movq $0x4, 0x10(%r14)
movq %r14, 0x20(%r15)
movq (%r14), %rax
movq %rax, 0x10(%r15)
movb $0x2e, 0x2(%rax)
movw $0x2e2e, (%rax)         # imm = 0x2E2E
movq 0x10(%r15), %rax
movb $0x0, 0x3(%rax)
movq $0x3, 0x8(%r15)
movq $0x0, 0x18(%r15)
movq 0x738(%rbx), %rbx
movq (%rbx), %rax
movq 0x10(%rbx), %rsi
cmpq 0x8(%rbx), %rsi
jne 0x72258
leaq (%rsi,%rsi), %rcx
movq %rcx, 0x8(%rbx)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x8510
movq %rax, (%rbx)
movq 0x10(%rbx), %rsi
leaq 0x1(%rsi), %rcx
movq %rcx, 0x10(%rbx)
movq %r15, (%rax,%rsi,8)
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq