// File: /workspace/github_c_makefile_star2_O0/BernardTatin[P]s7sh/s7.c
// Function: g_get_output_string
static s7_pointer g_get_output_string(s7_scheme *sc, s7_pointer args)
    {
#define H_get_output_string "(get-output-string port clear-port) returns the output accumulated in port.  \
        If the optional 'clear-port' is #t, the current string is flushed."
#define Q_get_output_string s7_make_signature(sc, 3, sc->is_string_symbol, s7_make_signature(sc, 2, sc->is_output_port_symbol, sc->not_symbol), sc->is_boolean_symbol)

        s7_pointer p;
        bool clear_port = false;

        if (is_pair(cdr(args)))
        {
            p = cadr(args);
            if (!s7_is_boolean(p))
                return(wrong_type_argument(sc, sc->get_output_string_symbol, 2, p, T_BOOLEAN));
            clear_port = (p == sc->T);
        }
        p = car(args);
        if ((!is_output_port(p)) ||
                (!is_string_port(p)))
        {
            if (p == sc->F) return(make_empty_string(sc, 0, 0));
            return(method_or_bust_with_type_one_arg(sc, p, sc->get_output_string_symbol, args, wrap_string(sc, "an output string port", 21)));
        }
        if (port_is_closed(p))
            return(simple_wrong_type_argument_with_type(sc, sc->get_output_string_symbol, p, wrap_string(sc, "an active (open) string port", 28)));

        if (port_position(p) > sc->max_string_length)
            return(s7_error(sc, sc->out_of_range_symbol,
                        set_elist_2(sc, wrap_string(sc, "port-position ~D is greater than (*s7* 'max-string-length)", 58), s7_make_integer(sc, port_position(p)))));

        if ((clear_port) &&
                (port_position(p) < port_data_size(p)))
        {
            block_t *block;
            s7_pointer result;
            result = block_to_string(sc, port_data_block(p), port_position(p));
            port_data_size(p) = sc->initial_string_port_length;
            block = mallocate(sc, port_data_size(p));
            port_data_block(p) = block;
            port_data(p) = (uint8_t *)(block_data(block));
            port_position(p) = 0;
            port_data(p)[0] = '\0';
            return(result);
        }
        return(make_string_with_length(sc, (const char *)port_data(p), port_position(p)));
    }

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xc8(%rsp)
movq %rsi, 0xc0(%rsp)
movb $0x0, 0xb7(%rsp)
movq 0xc0(%rsp), %rax
movq 0x10(%rax), %rax
movzbl (%rax), %eax
cmpl $0x1, %eax
jne 0x6c200
movq 0xc0(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x9c50
testb $0x1, %al
jne 0x6c1dd
movq 0xc8(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0xc8(%rsp), %rax
movq 0xf50(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x78(%rsp)
movq $0x2, 0xa8(%rsp)
movq 0xa8(%rsp), %rax
andq $-0x800, %rax           # imm = 0xF800
cmpq $0x0, %rax
jne 0x6c0f6
movq 0xa8(%rsp), %rcx
leaq 0x1aa398(%rip), %rax    # 0x216480
movq (%rax,%rcx,8), %rax
movq %rax, 0x68(%rsp)
jmp 0x6c18e
jmp 0x6c0f8
movq 0xc8(%rsp), %rax
movq 0x90(%rax), %rax
movq 0xc8(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0x6c125
movq 0xc8(%rsp), %rdi
callq 0xc670
movq 0xc8(%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, 0x68(%rsp)
movq 0x78(%rsp), %rsi
movq 0x70(%rsp), %rdi
movq 0x68(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0xa0(%rsp), %rdx
movq 0xb8(%rsp), %rcx
movq 0xc8(%rsp), %rax
movq 0x140(%rax), %r8
movq 0x1ae3fd(%rip), %r9     # 0x21a5c8
callq 0xc560
movq %rax, 0xd0(%rsp)
jmp 0x6c56b
movq 0xb8(%rsp), %rax
movq 0xc8(%rsp), %rcx
cmpq 0x118(%rcx), %rax
sete %al
andb $0x1, %al
movb %al, 0xb7(%rsp)
movq 0xc0(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x22, %eax
jne 0x6c23a
movq 0xb8(%rsp), %rax
movq 0x8(%rax), %rax
cmpl $0x1, 0x4(%rax)
je 0x6c2f0
movq 0xb8(%rsp), %rax
movq 0xc8(%rsp), %rcx
cmpq 0x120(%rcx), %rax
jne 0x6c273
movq 0xc8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x146a0
movq %rax, 0xd0(%rsp)
jmp 0x6c56b
movq 0xc8(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0xc8(%rsp), %rax
movq 0xf50(%rax), %rax
movq %rax, 0x58(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0xc8(%rsp), %rdi
leaq 0x178f96(%rip), %rsi    # 0x1e5253
movl $0x15, %edx
callq 0xb880
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq %rax, %r8
callq 0x1ba7e0
movq %rax, 0xd0(%rsp)
jmp 0x6c56b
movq 0xb8(%rsp), %rax
movq 0x8(%rax), %rax
testb $0x1, 0x2(%rax)
je 0x6c38e
movq 0xc8(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xc8(%rsp), %rax
movq 0xf50(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0xc8(%rsp), %rax
movq 0x140(%rax), %rax
movq %rax, 0x40(%rsp)
movq 0xc8(%rsp), %rdi
leaq 0x1872b3(%rip), %rsi    # 0x1f360e
movl $0x1c, %edx
callq 0xb880
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq %rax, %r8
callq 0x14a60
movq %rax, 0xd0(%rsp)
jmp 0x6c56b
movq 0xb8(%rsp), %rax
movq 0x20(%rax), %rax
movq 0xc8(%rsp), %rcx
cmpq 0x2a8(%rcx), %rax
jle 0x6c445
movq 0xc8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xc8(%rsp), %rax
movq 0x1948(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xc8(%rsp), %rdi
leaq 0x184fc8(%rip), %rsi    # 0x1f13b4
movl $0x3a, %edx
callq 0xb880
movq %rax, 0x10(%rsp)
movq 0xc8(%rsp), %rdi
movq 0xb8(%rsp), %rax
movq 0x20(%rax), %rsi
callq 0x120f0
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %rax, %rdx
callq 0xb830
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %rax, %rdx
callq 0x2f940
movq %rax, 0xd0(%rsp)
jmp 0x6c56b
testb $0x1, 0xb7(%rsp)
je 0x6c53e
movq 0xb8(%rsp), %rax
movq 0x20(%rax), %rax
movq 0xb8(%rsp), %rcx
cmpq 0x18(%rcx), %rax
jge 0x6c53e
movq 0xc8(%rsp), %rdi
movq 0xb8(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x38(%rax), %rsi
movq 0xb8(%rsp), %rax
movq 0x20(%rax), %rdx
callq 0x2d220
movq %rax, 0x80(%rsp)
movq 0xc8(%rsp), %rax
movq 0x278(%rax), %rcx
movq 0xb8(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0xc8(%rsp), %rdi
movq 0xb8(%rsp), %rax
movq 0x18(%rax), %rsi
callq 0xaa80
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rcx
movq 0xb8(%rsp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x38(%rax)
movq 0x88(%rsp), %rax
movq (%rax), %rcx
movq 0xb8(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0xb8(%rsp), %rax
movq $0x0, 0x20(%rax)
movq 0xb8(%rsp), %rax
movq 0x10(%rax), %rax
movb $0x0, (%rax)
movq 0x80(%rsp), %rax
movq %rax, 0xd0(%rsp)
jmp 0x6c56b
movq 0xc8(%rsp), %rdi
movq 0xb8(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0xb8(%rsp), %rax
movq 0x20(%rax), %rdx
callq 0x144d0
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rax
addq $0xd8, %rsp
retq
nopl (%rax,%rax)