// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x178, %rsp            # imm = 0x178
movq %rdi, 0x168(%rsp)
movq %rsi, 0x160(%rsp)
movq 0x160(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x158(%rsp)
movq 0x158(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x13, %eax
je 0x6f76a
movq 0x168(%rsp), %rdi
movq 0x158(%rsp), %rsi
movq 0x168(%rsp), %rax
movq 0x1e90(%rax), %rdx
movq 0x160(%rsp), %rcx
movl $0x13, %r8d
callq 0xcfd30
movq %rax, 0x170(%rsp)
jmp 0x6f9e7
movq 0x160(%rsp), %rax
movq 0x10(%rax), %rax
movzbl (%rax), %eax
cmpl $0x1, %eax
jne 0x6f90d
movq 0x160(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq 0x168(%rsp), %rcx
cmpq 0x118(%rcx), %rax
jne 0x6f90d
movq $0x0, 0x48(%rsp)
movl $0x0, 0x44(%rsp)
movl $0x0, 0x40(%rsp)
movq 0x158(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x182c9a(%rip), %rsi    # 0x1f246d
callq 0x95a0
movq %rax, 0x38(%rsp)
leaq 0x50(%rsp), %rdi
movq 0x38(%rsp), %rdx
movl $0x100, %esi            # imm = 0x100
callq 0x9330
cmpq $0x0, %rax
je 0x6f88c
leaq 0x50(%rsp), %rdi
callq 0xa430
movq %rax, 0x30(%rsp)
movslq 0x44(%rsp), %rax
addq 0x30(%rsp), %rax
movslq 0x40(%rsp), %rcx
cmpq %rcx, %rax
jl 0x6f85a
movl 0x40(%rsp), %eax
addl $0x200, %eax            # imm = 0x200
movl %eax, 0x40(%rsp)
cmpq $0x0, 0x48(%rsp)
je 0x6f849
movq 0x48(%rsp), %rdi
movslq 0x40(%rsp), %rsi
callq 0x9510
movq %rax, 0x48(%rsp)
jmp 0x6f858
movslq 0x40(%rsp), %rdi
callq 0x9480
movq %rax, 0x48(%rsp)
jmp 0x6f85a
movq 0x48(%rsp), %rdi
movslq 0x44(%rsp), %rax
addq %rax, %rdi
leaq 0x50(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0x93e0
movq 0x30(%rsp), %rcx
movslq 0x44(%rsp), %rax
addq %rcx, %rax
movl %eax, 0x44(%rsp)
jmp 0x6f7dd
movq 0x38(%rsp), %rdi
callq 0x9200
cmpq $0x0, 0x48(%rsp)
je 0x6f8ed
movq 0x168(%rsp), %rdi
callq 0x11020
movq %rax, 0x28(%rsp)
movq 0x48(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, (%rax)
movq 0x28(%rsp), %rax
movl $0x11, 0x8(%rax)
movq 0x168(%rsp), %rdi
movq 0x28(%rsp), %rsi
movslq 0x44(%rsp), %rdx
callq 0x2d220
movq %rax, 0x170(%rsp)
jmp 0x6f9e7
movq 0x168(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x146a0
movq %rax, 0x170(%rsp)
jmp 0x6f9e7
movq 0x158(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x91c0
cltq
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
andq $-0x800, %rax           # imm = 0xF800
cmpq $0x0, %rax
jne 0x6f94f
movq 0x20(%rsp), %rcx
leaq 0x1a6b3e(%rip), %rax    # 0x216480
movq (%rax,%rcx,8), %rax
movq %rax, (%rsp)
jmp 0x6f9d1
jmp 0x6f951
movq 0x168(%rsp), %rax
movq 0x90(%rax), %rax
movq 0x168(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0x6f97e
movq 0x168(%rsp), %rdi
callq 0xc670
movq 0x168(%rsp), %rcx
movq 0x90(%rcx), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, 0x90(%rcx)
movq -0x8(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq $0xb, (%rax)
movq 0x20(%rsp), %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq %rax, (%rsp)
movq (%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x170(%rsp)
movq 0x170(%rsp), %rax
addq $0x178, %rsp            # imm = 0x178
retq
nopw (%rax,%rax)