// File: /workspace/github_c_makefile_star2_O1/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 0x67e8e
movq 0x8(%rcx), %rcx
cmpb $0x7, (%rcx)
jne 0x67f65
cmpq 0x118(%rbx), %rcx
sete %cl
jmp 0x67e90
xorl %ecx, %ecx
movq 0x8(%rax), %r14
cmpb $0x22, (%r14)
jne 0x67f07
movq 0x8(%r14), %rdx
cmpl $0x1, 0x4(%rdx)
jne 0x67f07
cmpb $0x1, 0x2(%rdx)
jne 0x67faf
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 0xbc6be(%rip), %rax     # 0x1245a3
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 0xfac8
cmpq 0x120(%rbx), %r14
je 0x67f98
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 0xae72e(%rip), %rcx     # 0x11666e
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 0x103001
movq 0xf50(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xe69e9(%rip), %rdx     # 0x14e960
movq 0x140(%rbx), %r8
movq 0xeab13(%rip), %r9      # 0x152a98
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xb31d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xf83b
movq 0x20(%r14), %r12
cmpq 0x2a8(%rbx), %r12
jle 0x68033
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 0xba3a4(%rip), %rax     # 0x12238c
movq %rax, 0x10(%r12)
movq $0x3a, 0x8(%r12)
movq 0x20(%r14), %rsi
movq %rbx, %rdi
callq 0xdff8
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 0x3b366
jmp 0x68132
testb %cl, %cl
je 0x68081
cmpq 0x18(%r14), %r12
jge 0x68081
movq 0x38(%rdx), %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x3a419
movq %rax, %r15
movq 0x278(%rbx), %rsi
movq %rsi, 0x18(%r14)
movq %rbx, %rdi
callq 0xa305
movq 0x8(%r14), %rcx
movq %rax, 0x38(%rcx)
movq (%rax), %rax
movq %rax, 0x10(%r14)
movq $0x0, 0x20(%r14)
movb $0x0, (%rax)
jmp 0x68132
movq 0x10(%r14), %r14
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x6809d
movq %rbx, %rdi
callq 0xb389
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 0xa305
movq %rax, 0x20(%r15)
movq (%rax), %rdi
movq %rdi, 0x10(%r15)
testq %r12, %r12
jle 0x680e2
movq %r14, %rsi
movq %r12, %rdx
callq 0x93e0
movq 0x10(%r15), %rax
movb $0x0, (%rax,%r12)
movq %r12, 0x8(%r15)
movq $0x0, 0x18(%r15)
movq 0x738(%rbx), %rbx
movq 0x8(%rbx), %rsi
cmpq %rsi, 0x10(%rbx)
jne 0x6811f
leaq (%rsi,%rsi), %rax
movq %rax, 0x8(%rbx)
movq (%rbx), %rdi
shlq $0x4, %rsi
callq 0x9510
movq %rax, (%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x10(%rbx)
movq %r15, (%rax,%rcx,8)
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq