// File: /workspace/github_c_makefile_star2_O2/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
pushq %rax
movq %rsi, %r12
movq %rdi, %rbx
movabsq $0x7fffffffffffffff, %r13 # imm = 0x7FFFFFFFFFFFFFFF
xorl %r15d, %r15d
cmpb $0x0, 0xbe03e(%rip)     # 0x119c08
movl $0x0, %r14d
cmovneq %r13, %r14
movb 0x24c(%rdi), %dil
movq 0x8(%rsi), %rbp
movq 0x10(%rsi), %rax
movq 0x110(%rbx), %rdx
cmpq %rdx, %rax
je 0x5bcc1
movq 0x8(%rax), %rcx
cmpq 0x120(%rbx), %rcx
je 0x5bc7f
pushq $0x1
popq %r15
cmpq 0x118(%rbx), %rcx
je 0x5bc7f
cmpq 0x18a0(%rbx), %rcx
je 0x5be36
cmpq 0x18a8(%rbx), %rcx
je 0x5bf7d
cmpq 0x18b0(%rbx), %rcx
je 0x5bc7f
movq 0x1380(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xb9d1e(%rip), %rdx     # 0x115960
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 0x8baba(%rip), %rax     # 0xe7728
movq %rax, 0x10(%r9)
movq $0x16, 0x8(%r9)
jmp 0x5bdd5
xorl %esi, %esi
movq 0x10(%rax), %rax
cmpq %rdx, %rax
je 0x5bca4
movq 0x8(%rax), %rcx
cmpb $0xb, (%rcx)
jne 0x5bdac
movq 0x8(%rcx), %r14
testq %r14, %r14
js 0x5bf4e
testb %sil, %sil
je 0x5bcc5
movb %dil, 0x3(%rsp)
movb $0x0, 0x24c(%rbx)
pushq $0x2
popq %r15
movb $0x1, %al
movl %eax, 0x4(%rsp)
jmp 0x5bd31
pushq $0x1
popq %r15
testb $0x40, 0x3(%rbp)
movb %dil, 0x3(%rsp)
je 0x5bd29
testb %dil, %dil
je 0x5bd29
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x88f3
movq 0x1380(%rbx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x888f
cmpq 0x128(%rbx), %rax
je 0x5bf87
movq %rax, %r13
movq %rbx, %rdi
movq %r12, %rsi
callq 0x35492
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa34c
movl $0x0, 0x4(%rsp)
movq %rbx, %rdi
callq 0x2b99b
movq %rax, %r12
movq %r14, 0x288(%rbx)
movq %rbx, %rdi
movq %rbp, %rsi
movq %rax, %rdx
movl %r15d, %ecx
callq 0x2ba5b
xorl %eax, %eax
cmpb $0x0, 0xbdeab(%rip)     # 0x119c08
cmovneq %r13, %rax
movq %rax, 0x288(%rbx)
movq 0x20(%r12), %r13
cmpq %r14, %r13
jle 0x5befa
cmpb $0x0, 0x4(%rsp)
je 0x5bdeb
movq 0x1380(%rbx), %rax
movq 0x8(%rax), %r15
movq 0xb9bd9(%rip), %r12     # 0x115968
cmpq $0x7ff, %r13            # imm = 0x7FF
ja 0x5be66
leaq 0xb9bad(%rip), %rax     # 0x115950
movq (%rax,%r13,8), %rcx
jmp 0x5be9f
movq 0x1380(%rbx), %rdx
testb %sil, %sil
je 0x5be42
movq 0x8(%rdx), %rsi
movq 0xb9ba1(%rip), %rdx     # 0x115968
movq 0x140(%rbx), %r8
movq 0xbdce3(%rip), %r9      # 0x119ab8
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9bbb
cmpq $0x2, %r14
ja 0x5bede
movq 0x7e8(%rbx), %rax
movq 0x28(%r12), %rcx
movq %rax, 0x18(%rcx)
movq %r12, 0x7e8(%rbx)
movb 0x3(%rsp), %al
movb %al, 0x24c(%rbx)
leaq 0x86d25(%rip), %rsi     # 0xe2b42
pushq $0x3
popq %rdx
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd11d
pushq $0x2
popq %r15
movb $0x1, %sil
jmp 0x5bc81
pushq $0xb
popq %r8
pushq $0x3
popq %r9
movq %rbx, %rdi
movq %rcx, %rsi
movq %r12, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xcd70
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x5be85
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rcx
movq $0xb, (%rcx)
movq %r13, 0x8(%rcx)
movq 0x820(%rbx), %rax
movslq 0x7dc(%rbx), %rdx
movq (%rax,%rdx,8), %r8
leal 0x1(%rdx), %eax
andl $0x7, %eax
movl %eax, 0x7dc(%rbx)
leaq 0x8b87b(%rip), %rax     # 0xe773f
movq %rax, 0x10(%r8)
movq $0x1f, 0x8(%r8)
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
jmp 0x5bf6a
pushq $-0x3
popq %rax
testq %rax, %rax
je 0x5bef7
movq 0x10(%r12), %rcx
addq %r14, %rcx
movb $0x2e, (%rax,%rcx)
incq %rax
jmp 0x5bee1
movq %r14, %r13
movq 0x8(%r12), %rax
movq 0x38(%rax), %rsi
cmpq 0x18(%r12), %r13
jl 0x5bf19
leaq 0x1(%r13), %rdx
movq %rbx, %rdi
callq 0x9859
movq %rax, %rsi
movq %rbx, %rdi
movq %r13, %rdx
callq 0x2bf22
movq %rax, %r14
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2bfa4
movb 0x3(%rsp), %al
movb %al, 0x24c(%rbx)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1380(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xb9a08(%rip), %rdx     # 0x115968
movq 0xc5c71(%rip), %r8      # 0x121bd8
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xcb8f
xorl %esi, %esi
xorl %r15d, %r15d
jmp 0x5bc81
movl $0x0, 0x4(%rsp)
movabsq $0x7fffffffffffffff, %r13 # imm = 0x7FFFFFFFFFFFFFFF
jmp 0x5bd31