// File: /workspace/github_c_makefile_star2_O2/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:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rax
movq %rdi, %rbx
movq 0x10(%rsi), %rcx
cmpb $0x1, (%rcx)
jne 0x4f043
movq 0x8(%rcx), %rcx
cmpb $0x7, (%rcx)
jne 0x4f11a
cmpq 0x118(%rbx), %rcx
sete %cl
jmp 0x4f045
xorl %ecx, %ecx
movq 0x8(%rax), %r14
cmpb $0x22, (%r14)
jne 0x4f0bc
movq 0x8(%r14), %rsi
cmpl $0x1, 0x4(%rsi)
jne 0x4f0bc
cmpb $0x1, 0x2(%rsi)
jne 0x4f164
movq 0xf50(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0x140(%rbx), %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 0x985b9(%rip), %rax     # 0xe7653
movq %rax, 0x10(%r8)
movq $0x1c, 0x8(%r8)
movq %rbx, %rdi
movq %r14, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xd456
cmpq 0x120(%rbx), %r14
je 0x4f14d
movq 0xf50(%rbx), %rdx
movq 0x820(%rbx), %rcx
movslq 0x7dc(%rbx), %rsi
movq (%rcx,%rsi,8), %r8
leal 0x1(%rsi), %ecx
andl $0x7, %ecx
movl %ecx, 0x7dc(%rbx)
leaq 0x8a629(%rip), %rcx     # 0xd971e
movq %rcx, 0x10(%r8)
movq $0x15, 0x8(%r8)
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xc736d
movq 0xf50(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xc6834(%rip), %rdx     # 0x115960
movq 0x140(%rbx), %r8
movq 0xca95e(%rip), %r9      # 0x119a98
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x9bbb
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xd239
movq 0x20(%r14), %rdx
cmpq 0x2a8(%rbx), %rdx
jle 0x4f1ee
movq 0x1948(%rbx), %r15
movq 0x820(%rbx), %rax
movslq 0x7dc(%rbx), %rcx
movq (%rax,%rcx,8), %r12
leal 0x1(%rcx), %eax
andl $0x7, %eax
movl %eax, 0x7dc(%rbx)
leaq 0x9629f(%rip), %rax     # 0xe543c
movq %rax, 0x10(%r12)
movq $0x3a, 0x8(%r12)
movq 0x20(%r14), %rsi
movq %rbx, %rdi
callq 0xc049
movq 0x6e0(%rbx), %rcx
movq %r12, 0x8(%rcx)
movq 0x6e0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movq %rax, 0x8(%rcx)
movq 0x6e0(%rbx), %rdx
movq %rbx, %rdi
movq %r15, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x2cdc0
testb %cl, %cl
je 0x4f240
cmpq 0x18(%r14), %rdx
jge 0x4f240
movq 0x38(%rsi), %rsi
movq %rbx, %rdi
callq 0x2bf22
movq %rax, %r15
movq 0x278(%rbx), %rsi
movq %rsi, 0x18(%r14)
movq %rbx, %rdi
callq 0x9037
movq 0x8(%r14), %rcx
movq %rax, 0x38(%rcx)
movq (%rax), %rax
movq %rax, 0x10(%r14)
andq $0x0, 0x20(%r14)
movb $0x0, (%rax)
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x10(%r14), %rsi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xd11d