// File: /workspace/github_c_makefile_star2_O3/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 0x62e80
movq 0x8(%rcx), %rcx
cmpb $0x7, (%rcx)
jne 0x62f57
cmpq 0x118(%rbx), %rcx
sete %cl
jmp 0x62e82
xorl %ecx, %ecx
movq 0x8(%rax), %r14
cmpb $0x22, (%r14)
jne 0x62ef9
movq 0x8(%r14), %rdx
cmpl $0x1, 0x4(%rdx)
jne 0x62ef9
cmpb $0x1, 0x2(%rdx)
jne 0x62fa1
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 0xb87dc(%rip), %rax     # 0x11b6b3
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 0xed2a
cmpq 0x120(%rbx), %r14
je 0x62f8a
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 0xaa84c(%rip), %rcx     # 0x10d77e
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 0xfa261
movq 0xf50(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xe39f7(%rip), %rdx     # 0x146960
movq 0x140(%rbx), %r8
movq 0xe7b21(%rip), %r9      # 0x14aa98
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xa4e4
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xeab0
movq 0x20(%r14), %r12
cmpq 0x2a8(%rbx), %r12
jle 0x63025
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 0xb64c2(%rip), %rax     # 0x11949c
movq %rax, 0x10(%r12)
movq $0x3a, 0x8(%r12)
movq 0x20(%r14), %rsi
movq %rbx, %rdi
callq 0xd27e
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
callq 0x38dfa
jmp 0x63124
testb %cl, %cl
je 0x63073
cmpq 0x18(%r14), %r12
jge 0x63073
movq 0x38(%rdx), %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x37ebe
movq %rax, %r15
movq 0x278(%rbx), %rsi
movq %rsi, 0x18(%r14)
movq %rbx, %rdi
callq 0x9357
movq 0x8(%r14), %rcx
movq %rax, 0x38(%rcx)
movq (%rax), %rax
movq %rax, 0x10(%r14)
movq $0x0, 0x20(%r14)
movb $0x0, (%rax)
jmp 0x63124
movq 0x10(%r14), %r14
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x63096
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r15
movq $0x200013, (%r15)       # imm = 0x200013
leaq 0x1(%r12), %rsi
movq %rbx, %rdi
callq 0x9357
movq %rax, 0x20(%r15)
movq (%rax), %rdi
movq %rdi, 0x10(%r15)
testq %r12, %r12
jle 0x630d8
movq %r14, %rsi
movq %r12, %rdx
callq 0x83e0
movq 0x10(%r15), %rdi
movb $0x0, (%rdi,%r12)
movq %r12, 0x8(%r15)
movq $0x0, 0x18(%r15)
movq 0x738(%rbx), %rbx
movq (%rbx), %rax
movq 0x10(%rbx), %rsi
cmpq 0x8(%rbx), %rsi
jne 0x63118
leaq (%rsi,%rsi), %rcx
movq %rcx, 0x8(%rbx)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x8510
movq %rax, (%rbx)
movq 0x10(%rbx), %rsi
leaq 0x1(%rsi), %rcx
movq %rcx, 0x10(%rbx)
movq %r15, (%rax,%rsi,8)
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq