// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x158, %rsp            # imm = 0x158
movq %rdi, 0x148(%rsp)
movq %rsi, 0x140(%rsp)
movq 0x18d68a(%rip), %rax    # 0x21a738
movq %rax, 0x110(%rsp)
movq 0x148(%rsp), %rax
movb 0x24c(%rax), %al
andb $0x1, %al
movb %al, 0x10f(%rsp)
movq 0x140(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x130(%rsp)
movq 0x140(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x148(%rsp), %rcx
cmpq 0x110(%rcx), %rax
je 0x8d5d6
movq 0x140(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x100(%rsp)
movq 0x100(%rsp), %rax
movq 0x148(%rsp), %rcx
cmpq 0x120(%rcx), %rax
jne 0x8d143
movl $0x0, 0x13c(%rsp)
jmp 0x8d377
movq 0x100(%rsp), %rax
movq 0x148(%rsp), %rcx
cmpq 0x118(%rcx), %rax
jne 0x8d16c
movl $0x1, 0x13c(%rsp)
jmp 0x8d375
movq 0x100(%rsp), %rax
movq 0x148(%rsp), %rcx
cmpq 0x18a0(%rcx), %rax
jne 0x8d195
movl $0x2, 0x13c(%rsp)
jmp 0x8d373
movq 0x100(%rsp), %rax
movq 0x148(%rsp), %rcx
cmpq 0x18a8(%rcx), %rax
jne 0x8d1be
movl $0x0, 0x13c(%rsp)
jmp 0x8d371
movq 0x100(%rsp), %rax
movq 0x148(%rsp), %rcx
cmpq 0x18b0(%rcx), %rax
jne 0x8d1e7
movl $0x1, 0x13c(%rsp)
jmp 0x8d36f
movq 0x148(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x148(%rsp), %rax
movq 0x1380(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x88(%rsp)
movq $0x2, 0xf8(%rsp)
movq 0xf8(%rsp), %rax
andq $-0x800, %rax           # imm = 0xF800
cmpq $0x0, %rax
jne 0x8d24f
movq 0xf8(%rsp), %rcx
leaq 0x18923f(%rip), %rax    # 0x216480
movq (%rax,%rcx,8), %rax
movq %rax, 0x78(%rsp)
jmp 0x8d2e7
jmp 0x8d251
movq 0x148(%rsp), %rax
movq 0x90(%rax), %rax
movq 0x148(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0x8d27e
movq 0x148(%rsp), %rdi
callq 0xc670
movq 0x148(%rsp), %rcx
movq 0x90(%rcx), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, 0x90(%rcx)
movq -0x8(%rax), %rax
movq %rax, 0xe8(%rsp)
movq 0xe8(%rsp), %rax
movq $0xb, (%rax)
movq 0xf8(%rsp), %rcx
movq 0xe8(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0xe8(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0xf0(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x148(%rsp), %rax
movq 0x140(%rax), %rax
movq %rax, 0x70(%rsp)
movq 0x148(%rsp), %rdi
leaq 0x1663b2(%rip), %rsi    # 0x1f36e3
movl $0x16, %edx
callq 0xb880
movq 0x80(%rsp), %rdi
movq 0x88(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq 0x68(%rsp), %rcx
movq 0x70(%rsp), %r8
movq %rax, %r9
callq 0xc560
movq %rax, 0x150(%rsp)
jmp 0x8da80
jmp 0x8d371
jmp 0x8d373
jmp 0x8d375
jmp 0x8d377
movq 0x140(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movq 0x148(%rsp), %rcx
cmpq 0x110(%rcx), %rax
je 0x8d5d4
movq 0x140(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x100(%rsp)
movq 0x100(%rsp), %rdi
callq 0x11340
testb $0x1, %al
jne 0x8d569
cmpl $0x2, 0x13c(%rsp)
jne 0x8d524
movq 0x148(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x148(%rsp), %rax
movq 0x1380(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x58(%rsp)
movq $0x3, 0xd8(%rsp)
movq 0xd8(%rsp), %rax
andq $-0x800, %rax           # imm = 0xF800
cmpq $0x0, %rax
jne 0x8d43d
movq 0xd8(%rsp), %rcx
leaq 0x189051(%rip), %rax    # 0x216480
movq (%rax,%rcx,8), %rax
movq %rax, 0x48(%rsp)
jmp 0x8d4d5
jmp 0x8d43f
movq 0x148(%rsp), %rax
movq 0x90(%rax), %rax
movq 0x148(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0x8d46c
movq 0x148(%rsp), %rdi
callq 0xc670
movq 0x148(%rsp), %rcx
movq 0x90(%rcx), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, 0x90(%rcx)
movq -0x8(%rax), %rax
movq %rax, 0xc8(%rsp)
movq 0xc8(%rsp), %rax
movq $0xb, (%rax)
movq 0xd8(%rsp), %rcx
movq 0xc8(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0xc8(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rdx
movq 0x100(%rsp), %rcx
movq 0x148(%rsp), %rax
movq 0x140(%rax), %r8
movq 0x18d0d6(%rip), %r9     # 0x21a5e8
callq 0xc560
movq %rax, 0x150(%rsp)
jmp 0x8da80
movq 0x148(%rsp), %rdi
movq 0x100(%rsp), %rsi
movq 0x148(%rsp), %rax
movq 0x1380(%rax), %rdx
movq 0x140(%rsp), %rcx
movl $0xb, %r8d
movl $0x3, %r9d
callq 0x13c50
movq %rax, 0x150(%rsp)
jmp 0x8da80
movq 0x100(%rsp), %rdi
callq 0x10790
cmpq $0x0, %rax
jge 0x8d5bf
movq 0x148(%rsp), %rdi
movq 0x148(%rsp), %rax
movq 0x1380(%rax), %rax
movq 0x8(%rax), %rsi
movq 0x188efa(%rip), %rdx    # 0x216498
movq 0x100(%rsp), %rcx
movq 0x19517b(%rip), %r8     # 0x222728
callq 0x13880
movq %rax, 0x150(%rsp)
jmp 0x8da80
movq 0x100(%rsp), %rdi
callq 0x10790
movq %rax, 0x110(%rsp)
jmp 0x8d5e1
movl $0x1, 0x13c(%rsp)
cmpl $0x2, 0x13c(%rsp)
jne 0x8d5ff
movq 0x148(%rsp), %rax
movb $0x0, 0x24c(%rax)
jmp 0x8d6d6
movq 0x130(%rsp), %rax
movq (%rax), %rax
andq $0x40000000, %rax       # imm = 0x40000000
cmpq $0x0, %rax
je 0x8d6d4
movq 0x148(%rsp), %rax
testb $0x1, 0x24c(%rax)
je 0x8d6d4
movq 0x148(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x148(%rsp), %rdi
movq 0x130(%rsp), %rsi
callq 0x9a10
movq 0x40(%rsp), %rdi
movq %rax, %rsi
movq 0x148(%rsp), %rax
movq 0x1380(%rax), %rdx
callq 0x98d0
movq %rax, 0xb8(%rsp)
movq 0x148(%rsp), %rcx
cmpq 0x128(%rcx), %rax
je 0x8d6d4
movq 0x148(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x148(%rsp), %rdi
movq 0x140(%rsp), %rsi
callq 0x44270
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq %rax, %rdx
callq 0xda50
movq %rax, 0x150(%rsp)
jmp 0x8da80
jmp 0x8d6d6
movq 0x148(%rsp), %rdi
callq 0x2cfa0
movq %rax, 0x128(%rsp)
movq 0x110(%rsp), %rcx
movq 0x148(%rsp), %rax
movq %rcx, 0x288(%rax)
movq 0x148(%rsp), %rdi
movq 0x130(%rsp), %rsi
movq 0x128(%rsp), %rdx
movl 0x13c(%rsp), %ecx
callq 0x2d120
movq 0x18d00b(%rip), %rcx    # 0x21a738
movq 0x148(%rsp), %rax
movq %rcx, 0x288(%rax)
movq 0x128(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x118(%rsp)
cmpq $0x0, 0x110(%rsp)
jl 0x8d9ad
movq 0x118(%rsp), %rax
cmpq 0x110(%rsp), %rax
jle 0x8d9ad
cmpl $0x2, 0x13c(%rsp)
jne 0x8d8e9
movq 0x148(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x148(%rsp), %rax
movq 0x1380(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x188ce9(%rip), %rax    # 0x216498
movq %rax, 0x28(%rsp)
movq 0x118(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq 0xa8(%rsp), %rax
andq $-0x800, %rax           # imm = 0xF800
cmpq $0x0, %rax
jne 0x8d7f5
movq 0xa8(%rsp), %rcx
leaq 0x188c99(%rip), %rax    # 0x216480
movq (%rax,%rcx,8), %rax
movq %rax, 0x10(%rsp)
jmp 0x8d88d
jmp 0x8d7f7
movq 0x148(%rsp), %rax
movq 0x90(%rax), %rax
movq 0x148(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0x8d824
movq 0x148(%rsp), %rdi
callq 0xc670
movq 0x148(%rsp), %rcx
movq 0x90(%rcx), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, 0x90(%rcx)
movq -0x8(%rax), %rax
movq %rax, 0x98(%rsp)
movq 0x98(%rsp), %rax
movq $0xb, (%rax)
movq 0xa8(%rsp), %rcx
movq 0x98(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x98(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x148(%rsp), %rdi
leaq 0x165e44(%rip), %rsi    # 0x1f36fa
movl $0x1f, %edx
callq 0xb880
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x8(%rsp), %rcx
movq %rax, %r8
callq 0x13880
movq %rax, 0x150(%rsp)
jmp 0x8da80
movq 0x110(%rsp), %rax
movq %rax, 0x118(%rsp)
cmpq $0x3, 0x118(%rsp)
jge 0x8d957
movq 0x148(%rsp), %rdi
movq 0x128(%rsp), %rsi
callq 0x2d1e0
movb 0x10f(%rsp), %cl
movq 0x148(%rsp), %rax
andb $0x1, %cl
movb %cl, 0x24c(%rax)
movq 0x148(%rsp), %rdi
leaq 0x160d22(%rip), %rsi    # 0x1ee662
movl $0x3, %edx
callq 0x144d0
movq %rax, 0x150(%rsp)
jmp 0x8da80
movq 0x118(%rsp), %rax
subq $0x3, %rax
movq %rax, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
cmpq 0x118(%rsp), %rax
jge 0x8d9ab
movq 0x128(%rsp), %rax
movq 0x10(%rax), %rax
movq 0xb0(%rsp), %rcx
movb $0x2e, (%rax,%rcx)
movq 0xb0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xb0(%rsp)
jmp 0x8d96b
jmp 0x8d9ad
movq 0x118(%rsp), %rax
movq 0x128(%rsp), %rcx
cmpq 0x18(%rcx), %rax
jl 0x8da16
movq 0x148(%rsp), %rax
movq %rax, (%rsp)
movq 0x148(%rsp), %rdi
movq 0x128(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x38(%rax), %rsi
movq 0x118(%rsp), %rdx
addq $0x1, %rdx
callq 0xbb60
movq (%rsp), %rdi
movq %rax, %rsi
movq 0x118(%rsp), %rdx
callq 0x2d220
movq %rax, 0x120(%rsp)
jmp 0x8da43
movq 0x148(%rsp), %rdi
movq 0x128(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x38(%rax), %rsi
movq 0x118(%rsp), %rdx
callq 0x2d220
movq %rax, 0x120(%rsp)
movq 0x148(%rsp), %rdi
movq 0x128(%rsp), %rsi
callq 0x2d300
movb 0x10f(%rsp), %cl
movq 0x148(%rsp), %rax
andb $0x1, %cl
movb %cl, 0x24c(%rax)
movq 0x120(%rsp), %rax
movq %rax, 0x150(%rsp)
movq 0x150(%rsp), %rax
addq $0x158, %rsp            # imm = 0x158
retq