// File: /workspace/github_c_makefile_star2_O2/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, %r14
movq 0x8(%rsi), %rsi
cmpb $0x13, (%rsi)
jne 0x50840
movq 0x10(%rcx), %rax
cmpb $0x1, (%rax)
jne 0x5081c
movq 0x8(%rax), %rax
cmpq 0x118(%r14), %rax
je 0x508a2
movq 0x10(%rsi), %rdi
callq 0x81c0
movslq %eax, %rbx
cmpl $0x7ff, %ebx            # imm = 0x7FF
ja 0x50864
leaq 0xc5119(%rip), %rax     # 0x115950
movq (%rax,%rbx,8), %rax
jmp 0x50971
movq 0x1e90(%r14), %rdx
pushq $0x13
popq %r8
movq %r14, %rdi
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x77745
movq 0x90(%r14), %rax
cmpq 0x98(%r14), %rax
ja 0x50883
movq %r14, %rdi
callq 0x9c27
movq 0x90(%r14), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%r14)
movq -0x8(%rax), %rax
movq $0xb, (%rax)
movq %rbx, 0x8(%rax)
jmp 0x50971
movq %r14, (%rsp)
movq 0x10(%rsi), %rdi
leaq 0x95c36(%rip), %rsi     # 0xe64e7
callq 0x85a0
movq %rax, 0x8(%rsp)
xorl %ebx, %ebx
leaq 0x10(%rsp), %r12
xorl %r14d, %r14d
xorl %r15d, %r15d
movq %r12, %rdi
movl $0x100, %esi            # imm = 0x100
movq 0x8(%rsp), %rdx
callq 0x8330
movslq %r14d, %r13
testq %rax, %rax
je 0x5092f
movq %r12, %rdi
callq 0x8d06
movq %rax, %rbp
leaq (%rax,%r13), %r14
movslq %ebx, %rax
cmpq %rax, %r14
jl 0x5091c
addl $0x200, %ebx            # imm = 0x200
movslq %ebx, %rsi
testq %r15, %r15
je 0x50911
movq %r15, %rdi
callq 0x8510
jmp 0x50919
movq %rsi, %rdi
callq 0x8480
movq %rax, %r15
addq %r15, %r13
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x83e0
jmp 0x508c8
movq 0x8(%rsp), %rdi
callq 0x8200
testq %r15, %r15
je 0x50964
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0xb93f
movq %r15, (%rax)
movl $0x11, 0x8(%rax)
movq %rbx, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0x2bf22
jmp 0x50971
movq (%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd239
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq