// File: /workspace/github_c_makefile_star2_O3/BernardTatin[P]s7sh/s7.c
// Function: s7_open_output_file
s7_pointer s7_open_output_file(s7_scheme *sc, const char *name, const char *mode)
    {
        FILE *fp;
        s7_pointer x;
        block_t *block, *b;
        /* see if we can open this file before allocating a port */

        errno = 0;
        fp = fopen(name, mode);
        if (!fp)
        {
#if (!MS_WINDOWS)
            if (errno == EINVAL)
                return(file_error(sc, "open-output-file", "invalid mode", mode));
#endif
            return(file_error(sc, "open-output-file", strerror(errno), name));
        }

        new_cell(sc, x, T_OUTPUT_PORT);
        b = mallocate_port(sc);
        port_block(x) = b;
        port_port(x) = (port_t *)block_data(b);
        port_type(x) = FILE_PORT;
        port_set_closed(x, false);
        port_filename_length(x) = safe_strlen(name);
        port_set_filename(sc, x, name, port_filename_length(x));
        port_line_number(x) = 1;
        port_file_number(x) = 0;
        port_file(x) = fp;
        port_needs_free(x) = true;  /* hmm -- I think these are freed via s7_close_output_port -> close_output_port */
        port_position(x) = 0;
        port_data_size(x) = PORT_DATA_SIZE;
        block = mallocate(sc, PORT_DATA_SIZE);
        port_data_block(x) = block;
        port_data(x) = (uint8_t *)(block_data(block));
        port_port(x)->pf = &output_file_functions;
        add_output_port(sc, x);
        return(x);
    }

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
callq 0x8090
movq %rax, %r13
movl $0x0, (%rax)
movq %r15, %rdi
movq %r14, %rsi
callq 0x85b0
testq %rax, %rax
je 0xf2ac
movq %rax, %r12
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0xf1bc
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r14
movq $0x22, (%r14)
movq %rbx, %rdi
callq 0xf54a
movq %rax, 0x28(%r14)
movq (%rax), %rax
movq %rax, 0x8(%r14)
movl $0x0, 0x4(%rax)
movq 0x8(%r14), %rax
movb $0x0, 0x2(%rax)
testq %r15, %r15
je 0xf212
cmpb $0x0, (%r15)
je 0xf212
xorl %ecx, %ecx
leaq 0x1(%rcx), %rax
cmpb $0x0, 0x1(%r15,%rcx)
movq %rax, %rcx
jne 0xf201
jmp 0xf214
xorl %eax, %eax
movq 0x8(%r14), %rcx
movq %rax, 0x30(%rcx)
movq 0x8(%r14), %rax
movq 0x30(%rax), %r13
leaq 0x1(%r13), %rsi
movq %rbx, %rdi
callq 0x9357
movq 0x8(%r14), %rcx
movq %rax, 0x18(%rcx)
movq (%rax), %rdi
movq 0x8(%r14), %rax
movq %rdi, 0x10(%rax)
movq %r15, %rsi
movq %r13, %rdx
callq 0x83e0
movq 0x8(%r14), %rax
movq 0x10(%rax), %rax
movb $0x0, (%rax,%r13)
movq 0x8(%r14), %rax
movl $0x1, 0x20(%rax)
movq 0x8(%r14), %rax
movl $0x0, 0x24(%rax)
movq 0x8(%r14), %rax
movq %r12, 0x8(%rax)
movq 0x8(%r14), %rax
movb $0x1, (%rax)
movq $0x0, 0x20(%r14)
movq $0x100, 0x18(%r14)      # imm = 0x100
movq 0x878(%rbx), %r15
testq %r15, %r15
je 0xf2d2
movq 0x18(%r15), %rax
movq %rax, 0x878(%rbx)
jmp 0xf398
movl (%r13), %edi
cmpl $0x16, %edi
jne 0xf359
leaq 0xfadf5(%rip), %rsi     # 0x10a0b5
leaq 0xfadff(%rip), %rdx     # 0x10a0c6
movq %rbx, %rdi
movq %r14, %rcx
jmp 0xf36e
movq 0x838(%rbx), %r15
testq %r15, %r15
jne 0xf31d
movl $0x2800, %edi           # imm = 0x2800
callq 0x8480
movq %rax, %r15
movq %rax, 0x838(%rbx)
addq $0x28, %rax
movl $0xff, %ecx
movq %rax, -0x10(%rax)
movl $0x0, -0x20(%rax)
addq $0x28, %rax
decl %ecx
jne 0xf2fb
movq $0x0, -0x10(%rax)
movl $0x0, -0x20(%rax)
movq 0x18(%r15), %rax
movq %rax, 0x838(%rbx)
movq 0x8c8(%rbx), %rcx
leaq 0x100(%rcx), %rdx
cmpq $0x10000, %rdx          # imm = 0x10000
jbe 0xf37c
movl $0x10000, %edi          # imm = 0x10000
callq 0x8480
movq %rax, 0x8d0(%rbx)
movl $0x100, %edx            # imm = 0x100
xorl %ecx, %ecx
jmp 0xf383
callq 0x86b0
leaq 0xfad50(%rip), %rsi     # 0x10a0b5
movq %rbx, %rdi
movq %rax, %rdx
movq %r15, %rcx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0xf406
movq 0x8d0(%rbx), %rax
addq %rax, %rcx
movq %rdx, 0x8c8(%rbx)
movq %rcx, (%r15)
movl $0x8, 0x8(%r15)
movq $0x100, 0x10(%r15)      # imm = 0x100
movq 0x8(%r14), %rax
movq %r15, 0x38(%rax)
movq (%r15), %rax
movq %rax, 0x10(%r14)
movq 0x8(%r14), %rax
leaq 0x137006(%rip), %rcx    # 0x1463c0
movq %rcx, 0x48(%rax)
movq 0x750(%rbx), %rbx
movq (%rbx), %rax
movq 0x10(%rbx), %rsi
cmpq 0x8(%rbx), %rsi
jne 0xf3ed
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 %r14, (%rax,%rsi,8)
movq %r14, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq