// File: /workspace/github_c_makefile_star2_O3/BernardTatin[P]s7sh/s7.c
// Function: g_system
static s7_pointer g_system(s7_scheme *sc, s7_pointer args)
    {
#define H_system "(system command) executes the command.  If the optional second argument is #t, \
        system captures the output as a string and returns it."
#define Q_system s7_make_signature(sc, 3, s7_make_signature(sc, 2, sc->is_integer_symbol, sc->is_string_symbol), sc->is_string_symbol, sc->is_boolean_symbol)

        s7_pointer name;
        name = car(args);

        if (!is_string(name))
            return(method_or_bust_one_arg(sc, name, sc->system_symbol, args, T_STRING));

        if ((is_pair(cdr(args))) &&
                (cadr(args) == sc->T))
        {
#define BUF_SIZE 256
            char buf[BUF_SIZE];
            char *str = NULL;
            int32_t cur_len = 0, full_len = 0;
            FILE *fd;

            fd = popen(string_value(name), "r");
            while (fgets(buf, BUF_SIZE, fd))
            {
                s7_int buf_len;
                buf_len = safe_strlen(buf);
                if (cur_len + buf_len >= full_len)
                {
                    full_len += BUF_SIZE * 2;
                    if (str)
                        str = (char *)realloc(str, full_len);
                    else str = (char *)malloc(full_len);
                }
                memcpy((void *)(str + cur_len), (void *)buf, buf_len);
                cur_len += buf_len;
            }
            pclose(fd);
            if (str)
            {
                block_t *b;
                b = mallocate_block(sc);
                block_data(b) = (void *)str;
                block_set_index(b, TOP_BLOCK_LIST);
                return(block_to_string(sc, b, cur_len));
            }
            return(make_empty_string(sc, 0, 0));
        }
        return(make_integer(sc, system(string_value(name))));
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, %rcx
movq %rdi, %r12
movq 0x8(%rsi), %rsi
cmpb $0x13, (%rsi)
jne 0x64c64
movq 0x10(%rcx), %rax
cmpb $0x1, (%rax)
jne 0x64c40
movq 0x8(%rax), %rax
cmpq 0x118(%r12), %rax
je 0x64ccd
movq 0x10(%rsi), %rdi
callq 0x81c0
movslq %eax, %rbx
cmpl $0x7ff, %ebx            # imm = 0x7FF
ja 0x64c8b
leaq 0xe1cf5(%rip), %rax     # 0x146950
movq (%rax,%rbx,8), %rax
jmp 0x64e27
movq 0x1e90(%r12), %rdx
movq %r12, %rdi
movl $0x13, %r8d
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x95069
movq 0x90(%r12), %rax
cmpq 0x98(%r12), %rax
ja 0x64cad
movq %r12, %rdi
callq 0xa550
movq 0x90(%r12), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%r12)
movq -0x8(%rax), %rax
movq $0xb, (%rax)
movq %rbx, 0x8(%rax)
jmp 0x64e27
movq 0x10(%rsi), %rdi
leaq 0xb586f(%rip), %rsi     # 0x11a547
callq 0x85a0
movq %rax, %r13
leaq 0x10(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
movq %rax, %rdx
callq 0x8330
testq %rax, %rax
je 0x64e13
movq %r12, 0x8(%rsp)
xorl %r14d, %r14d
xorl %ebx, %ebx
xorl %r15d, %r15d
movq %r13, %r12
cmpb $0x0, 0x10(%rsp)
je 0x64d24
xorl %eax, %eax
leaq 0x1(%rax), %r13
cmpb $0x0, 0x11(%rsp,%rax)
movq %r13, %rax
jne 0x64d14
jmp 0x64d27
xorl %r13d, %r13d
movslq %ebx, %rbp
movq %r13, %rbx
addq %rbp, %rbx
movslq %r15d, %rax
cmpq %rax, %rbx
jl 0x64d5c
addl $0x200, %r15d           # imm = 0x200
movslq %r15d, %rsi
testq %r14, %r14
je 0x64d51
movq %r14, %rdi
callq 0x8510
jmp 0x64d59
movq %rsi, %rdi
callq 0x8480
movq %rax, %r14
addq %r14, %rbp
movq %rbp, %rdi
leaq 0x10(%rsp), %rbp
movq %rbp, %rsi
movq %r13, %rdx
callq 0x83e0
movq %rbp, %rdi
movl $0x100, %esi            # imm = 0x100
movq %r12, %r13
movq %r12, %rdx
callq 0x8330
testq %rax, %rax
jne 0x64d08
movq %r13, %rdi
callq 0x8200
testq %r14, %r14
movq 0x8(%rsp), %r12
je 0x64e1b
movslq %ebx, %r15
movq 0x838(%r12), %rsi
testq %rsi, %rsi
jne 0x64df0
movl $0x2800, %edi           # imm = 0x2800
callq 0x8480
movq %rax, %rsi
movq %rax, 0x838(%r12)
addq $0x28, %rax
movl $0xff, %ecx
movq %rax, -0x10(%rax)
movl $0x0, -0x20(%rax)
addq $0x28, %rax
decl %ecx
jne 0x64dce
movq $0x0, -0x10(%rax)
movl $0x0, -0x20(%rax)
movq 0x18(%rsi), %rax
movq %rax, 0x838(%r12)
movq %r14, (%rsi)
movl $0x11, 0x8(%rsi)
movq %r12, %rdi
movq %r15, %rdx
callq 0x37ebe
jmp 0x64e27
movq %r13, %rdi
callq 0x8200
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xeab0
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq