// File: /workspace/github_c_makefile_star2_O1/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 $0x28, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movabsq $0x7fffffffffffffff, %r12 # imm = 0x7FFFFFFFFFFFFFFF
xorl %r13d, %r13d
cmpb $0x0, 0xdb92e(%rip)     # 0x152c08
movl $0x0, %ebp
cmovneq %r12, %rbp
movb 0x24c(%rdi), %al
movb %al, 0x7(%rsp)
movq 0x8(%rsi), %rsi
movq 0x10(%r15), %rax
movq 0x110(%rdi), %rdx
cmpq %rdx, %rax
movq %rsi, 0x8(%rsp)
je 0x773d8
movq 0x8(%rax), %rcx
cmpq 0x120(%rbx), %rcx
je 0x773b2
movl $0x1, %r13d
cmpq 0x118(%rbx), %rcx
je 0x773b2
cmpq 0x18a0(%rbx), %rcx
je 0x7741b
cmpq 0x18a8(%rbx), %rcx
je 0x77607
cmpq 0x18b0(%rbx), %rcx
je 0x773b2
movq 0x1380(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xd75fd(%rip), %rdx     # 0x14e960
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 0xad2e9(%rip), %rax     # 0x124678
movq %rax, 0x10(%r9)
movq $0x16, 0x8(%r9)
movq %rbx, %rdi
callq 0xb31d
movq 0x8(%rsp), %rsi
movq %rax, %r14
xorl %eax, %eax
jmp 0x774ac
xorl %edi, %edi
movq 0x10(%rax), %rcx
movb $0x1, %al
cmpq %rdx, %rcx
je 0x773d3
movq 0x8(%rcx), %rcx
cmpb $0xb, (%rcx)
jne 0x773e3
cmpq $0x0, 0x8(%rcx)
js 0x7744c
movq 0x8(%rcx), %rbp
jmp 0x774ac
movl $0x1, %r13d
jmp 0x774b4
movq 0x1380(%rbx), %rdx
testb %dil, %dil
je 0x77426
movq 0x8(%rdx), %rsi
movq 0xd756e(%rip), %rdx     # 0x14e968
movq 0x140(%rbx), %r8
movq 0xdb6b0(%rip), %r9      # 0x152ab8
movq %rbx, %rdi
callq 0xb31d
movq %rax, %r14
movl $0x2, %r13d
jmp 0x77443
movl $0x2, %r13d
movb $0x1, %dil
jmp 0x773b4
movq %rbx, %rdi
movq %rcx, %rsi
movq %r15, %rcx
movl $0xb, %r8d
movl $0x3, %r9d
callq 0xf1ae
movq %rax, %r14
xorl %eax, %eax
movq 0x8(%rsp), %rsi
jmp 0x774ac
movq 0x1380(%rbx), %rax
movq 0x8(%rax), %rax
movq 0xd750a(%rip), %rdx     # 0x14e968
movq 0xe3773(%rip), %rsi     # 0x15abd8
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), %r14
movq 0x1ee8(%rbx), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3b366
movq 0x8(%rsp), %rsi
xorl %eax, %eax
testb %al, %al
je 0x77ae9
cmpl $0x2, %r13d
jne 0x774c6
movb $0x0, 0x24c(%rbx)
jmp 0x77644
movq %r14, %r12
movb $0x1, %r14b
testb $0x40, 0x3(%rsi)
je 0x7762e
cmpb $0x1, 0x24c(%rbx)
jne 0x7762e
movq %rbx, %rdi
movq %r13, 0x18(%rsp)
callq 0x9a55
movq 0x1380(%rbx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x99ef
movq 0x18(%rsp), %r13
cmpq 0x128(%rbx), %rax
je 0x7762e
cmpb $0x1, (%r15)
jne 0x77611
movq %rax, 0x20(%rsp)
movq %r15, 0x4c8(%rbx)
movq 0x8(%r15), %r14
movq 0x90(%rbx), %rax
movq 0x110(%rbx), %r12
cmpq 0x98(%rbx), %rax
ja 0x7754d
movq %rbx, %rdi
callq 0xb389
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0x200001, (%rax)       # imm = 0x200001
movq %r14, 0x8(%rax)
movq %r12, 0x10(%rax)
movq %rax, 0x10(%rsp)
movq %rax, 0x4e8(%rbx)
movq 0x10(%r15), %r15
cmpb $0x1, (%r15)
jne 0x775e6
movq 0x10(%rsp), %r14
movq 0x8(%r15), %r12
movq 0x90(%rbx), %rax
movq 0x110(%rbx), %r13
cmpq 0x98(%rbx), %rax
ja 0x775b0
movq %rbx, %rdi
callq 0xb389
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0x200001, (%rax)       # imm = 0x200001
movq %r12, 0x8(%rax)
movq %r13, 0x10(%rax)
movq %rax, 0x10(%r14)
movq 0x10(%r15), %r15
cmpb $0x1, (%r15)
movq %rax, %r14
je 0x7758d
movq 0x110(%rbx), %rax
movq %rax, 0x4e8(%rbx)
movq %rax, 0x4c8(%rbx)
movq 0x20(%rsp), %rax
movq 0x10(%rsp), %rdx
jmp 0x77618
xorl %edi, %edi
xorl %r13d, %r13d
jmp 0x773b4
movq 0x110(%rbx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0xbd41
movq %rax, %r12
xorl %r14d, %r14d
movq 0x18(%rsp), %r13
testb %r14b, %r14b
movq %r12, %r14
movabsq $0x7fffffffffffffff, %r12 # imm = 0x7FFFFFFFFFFFFFFF
je 0x77ae9
movq %rbx, %rdi
callq 0x3a285
movq 0x8(%rsp), %rsi
movq %rax, %r15
movq %rbp, 0x288(%rbx)
movzbl (%rsi), %eax
leaq 0xe2cdb(%rip), %rcx     # 0x15a340
cmpb $0x1, (%rax,%rcx)
jne 0x7768f
cmpl $0x15, %eax
jne 0x77676
testb $0x1, 0x7(%rsi)
jne 0x7768f
cmpq %rsi, 0x150(%rbx)
je 0x7768f
movq %rbx, %rdi
movq %r15, %rdx
movl %r13d, %ecx
callq 0x9b866
jmp 0x776a6
leaq 0xe2cea(%rip), %r9      # 0x15a380
movq %rbx, %rdi
movq %r15, %rdx
movl %r13d, %ecx
xorl %r8d, %r8d
callq *(%r9,%rax,8)
xorl %eax, %eax
cmpb $0x0, 0xdb559(%rip)     # 0x152c08
cmovneq %r12, %rax
movq %rax, 0x288(%rbx)
movq 0x20(%r15), %r12
testq %rbp, %rbp
setns %al
cmpq %rbp, %r12
setg %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x77994
cmpl $0x2, %r13d
jne 0x7770a
movq 0x1380(%rbx), %rax
movq 0x8(%rax), %r13
movq 0xd727b(%rip), %r14     # 0x14e968
cmpq $0x7ff, %r12            # imm = 0x7FF
ja 0x7778a
leaq 0xd724f(%rip), %rax     # 0x14e950
movq (%rax,%r12,8), %rax
jmp 0x777c3
cmpq $0x2, %rbp
jg 0x7783a
movq 0x7e8(%rbx), %rax
movq 0x28(%r15), %rcx
movq %rax, 0x18(%rcx)
movq %r15, 0x7e8(%rbx)
movb 0x7(%rsp), %al
movb %al, 0x24c(%rbx)
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x7774c
movq %rbx, %rdi
callq 0xb389
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r14
movq $0x200013, (%r14)       # imm = 0x200013
movq 0x850(%rbx), %r12
testq %r12, %r12
je 0x77858
movq 0x18(%r12), %rax
movq %rax, 0x850(%rbx)
jmp 0x77910
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x777a2
movq %rbx, %rdi
callq 0xb389
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0xb, (%rax)
movq %r12, 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 0xacea8(%rip), %rdx     # 0x12468f
movq %rdx, 0x10(%rcx)
movq $0x1f, 0x8(%rcx)
movq 0x1ee8(%rbx), %rdx
movq 0x10(%rdx), %rdx
movq %r13, 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)
movq 0x1948(%rbx), %r14
movq 0x1ee8(%rbx), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3b366
xorl %eax, %eax
jmp 0x7798c
movq $-0x3, %rax
movq 0x10(%r15), %rcx
addq %rbp, %rcx
movb $0x2e, (%rax,%rcx)
incq %rax
jne 0x77841
movb $0x1, %al
jmp 0x77989
cmpq $0x0, 0x838(%rbx)
jne 0x7789e
movl $0x2800, %edi           # imm = 0x2800
callq 0x9480
movq %rax, 0x838(%rbx)
addq $0x28, %rax
movl $0xff, %ecx
movq %rax, -0x10(%rax)
movl $0x0, -0x20(%rax)
addq $0x28, %rax
decl %ecx
jne 0x7787c
movq $0x0, -0x10(%rax)
movl $0x0, -0x20(%rax)
movq 0x838(%rbx), %r12
movq 0x18(%r12), %rax
movq %rax, 0x838(%rbx)
movl $0x0, 0x8(%r12)
movq 0x8c8(%rbx), %rax
addq $0x8, %rax
cmpq $0x10001, %rax          # imm = 0x10001
jb 0x778ee
movl $0x10000, %edi          # imm = 0x10000
callq 0x9480
movq %rax, 0x8d0(%rbx)
movq $0x0, 0x8c8(%rbx)
movl $0x8, %eax
movq 0x8d0(%rbx), %rcx
addq 0x8c8(%rbx), %rcx
movq %rax, 0x8c8(%rbx)
movq %rcx, (%r12)
movl $0x3, 0x8(%r12)
movq $0x4, 0x10(%r12)
movq %r12, 0x20(%r14)
movq (%r12), %rax
movq %rax, 0x10(%r14)
movb $0x2e, 0x2(%rax)
movw $0x2e2e, (%rax)         # imm = 0x2E2E
movq 0x10(%r14), %rax
movb $0x0, 0x3(%rax)
movq $0x3, 0x8(%r14)
movq %r14, %r12
movq $0x0, 0x18(%r14)
movq 0x738(%rbx), %r14
movq 0x8(%r14), %rsi
cmpq %rsi, 0x10(%r14)
jne 0x77971
leaq (%rsi,%rsi), %rax
movq %rax, 0x8(%r14)
movq (%r14), %rdi
shlq $0x4, %rsi
callq 0x9510
movq %rax, (%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x10(%r14)
movq %r12, %r14
movq %r12, (%rax,%rcx,8)
xorl %eax, %eax
movq %rbp, %r12
testb %al, %al
je 0x77ae9
movq 0x8(%r15), %rax
movq 0x38(%rax), %rsi
cmpq 0x18(%r15), %r12
jl 0x779b2
leaq 0x1(%r12), %rdx
movq %rbx, %rdi
callq 0xae0f
movq %rax, %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x3a419
movq %rax, %r14
movq 0x870(%rbx), %r12
testq %r12, %r12
je 0x779dd
movq 0x18(%r12), %rax
movq %rax, 0x870(%rbx)
jmp 0x77a95
cmpq $0x0, 0x838(%rbx)
jne 0x77a23
movl $0x2800, %edi           # imm = 0x2800
callq 0x9480
movq %rax, 0x838(%rbx)
addq $0x28, %rax
movl $0xff, %ecx
movq %rax, -0x10(%rax)
movl $0x0, -0x20(%rax)
addq $0x28, %rax
decl %ecx
jne 0x77a01
movq $0x0, -0x10(%rax)
movl $0x0, -0x20(%rax)
movq 0x838(%rbx), %r12
movq 0x18(%r12), %rax
movq %rax, 0x838(%rbx)
movl $0x0, 0x8(%r12)
movq 0x8c8(%rbx), %rax
subq $-0x80, %rax
cmpq $0x10001, %rax          # imm = 0x10001
jb 0x77a73
movl $0x10000, %edi          # imm = 0x10000
callq 0x9480
movq %rax, 0x8d0(%rbx)
movq $0x0, 0x8c8(%rbx)
movl $0x80, %eax
movq 0x8d0(%rbx), %rcx
addq 0x8c8(%rbx), %rcx
movq %rax, 0x8c8(%rbx)
movq %rcx, (%r12)
movl $0x7, 0x8(%r12)
movl $0x80, %eax
movq %rax, 0x10(%r12)
movq (%r12), %rcx
movq %rcx, 0x10(%r15)
movq 0x8(%r15), %rcx
movq %r12, 0x38(%rcx)
movq 0x10(%r15), %rcx
xorl %edx, %edx
movb %dl, (%rcx)
movq $0x0, 0x20(%r15)
movq %rax, 0x18(%r15)
movq 0x8(%r15), %rax
movb %dl, (%rax)
movq 0x7e8(%rbx), %rax
movq 0x28(%r15), %rcx
movq %rax, 0x18(%rcx)
movq %r15, 0x7e8(%rbx)
movb 0x7(%rsp), %al
movb %al, 0x24c(%rbx)
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq