// File: /workspace/github_c_makefile_star2_O1/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 0x69cd8
movq 0x10(%rcx), %rax
cmpb $0x1, (%rax)
jne 0x69cb4
movq 0x8(%rax), %rax
cmpq 0x118(%r12), %rax
je 0x69d41
movq 0x10(%rsi), %rdi
callq 0x91c0
movslq %eax, %rbx
cmpl $0x7ff, %ebx            # imm = 0x7FF
ja 0x69cff
leaq 0xe4c81(%rip), %rax     # 0x14e950
movq (%rax,%rbx,8), %rax
jmp 0x69e97
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 0x9b739
movq 0x90(%r12), %rax
cmpq 0x98(%r12), %rax
ja 0x69d19
movq %r12, %rdi
callq 0xb389
movq 0x90(%r12), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%r12)
movq -0x8(%rax), %rax
movq $0xb, (%rax)
movq %rbx, 0x8(%rax)
jmp 0x69e97
movq 0x10(%rsi), %rdi
leaq 0xb96eb(%rip), %rsi     # 0x123437
callq 0x95a0
leaq 0x10(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
movq %rax, (%rsp)
movq %rax, %rdx
callq 0x9330
xorl %r14d, %r14d
testq %rax, %rax
je 0x69e07
movq %r12, 0x8(%rsp)
leaq 0x10(%rsp), %r13
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpb $0x0, 0x10(%rsp)
je 0x69da1
movq $-0x1, %rax
leaq 0x1(%rax), %rbp
cmpb $0x0, 0x11(%rsp,%rax)
movq %rbp, %rax
jne 0x69d91
jmp 0x69da3
xorl %ebp, %ebp
movslq %r12d, %rbx
leaq (%rbx,%rbp), %r12
movslq %r14d, %rax
cmpq %rax, %r12
jl 0x69dd6
addl $0x200, %r14d           # imm = 0x200
movslq %r14d, %rsi
testq %r15, %r15
je 0x69dcb
movq %r15, %rdi
callq 0x9510
jmp 0x69dd3
movq %rsi, %rdi
callq 0x9480
movq %rax, %r15
addq %r15, %rbx
movq %rbx, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x93e0
movq %r13, %rdi
movl $0x100, %esi            # imm = 0x100
movq (%rsp), %rdx
callq 0x9330
testq %rax, %rax
jne 0x69d83
movslq %r12d, %r14
movq 0x8(%rsp), %r12
jmp 0x69e0a
xorl %r15d, %r15d
movq (%rsp), %rdi
callq 0x9200
testq %r15, %r15
je 0x69e8b
cmpq $0x0, 0x838(%r12)
jne 0x69e60
movl $0x2800, %edi           # imm = 0x2800
callq 0x9480
movq %rax, 0x838(%r12)
addq $0x28, %rax
movl $0xff, %ecx
movq %rax, -0x10(%rax)
movl $0x0, -0x20(%rax)
addq $0x28, %rax
decl %ecx
jne 0x69e3e
movq $0x0, -0x10(%rax)
movl $0x0, -0x20(%rax)
movq 0x838(%r12), %rsi
movq 0x18(%rsi), %rax
movq %rax, 0x838(%r12)
movq %r15, (%rsi)
movl $0x11, 0x8(%rsi)
movq %r12, %rdi
movq %r14, %rdx
callq 0x3a419
jmp 0x69e97
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf83b
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq