// File: /workspace/github_c_makefile_star2_O1/robertdavidgraham[P]wc2/wcdiff.c
// Function: my_spawn
struct handles
my_spawn(const char *progname, const char *parms)
{
    int pid;
    int pipe_stdout[2];
    int pipe_stderr[2];
    int pipe_stdin[2];
    struct handles handles = {0,0,0};
    int err;
    char **new_argv;


    err = pipe(pipe_stdout);
    if (err < 0) {
        fprintf(stderr, "[-] pipe(): %s\n", strerror(errno));
        return handles;
    }
    err = pipe(pipe_stderr);
    if (err < 0) {
        fprintf(stderr, "[-] pipe(): %s\n", strerror(errno));
        return handles;
    }
    err = pipe(pipe_stdin);
    if (err < 0) {
        fprintf(stderr, "[-] pipe(): %s\n", strerror(errno));
        return handles;
    }



    /* Configure the parent end of the pipes be be non-inheritable.
     * In other words, none of the children can read from these
     * pipes, nor will they exist in child process space */
    /*fcntl(pipe_stdout[0], F_SETFD, FD_CLOEXEC);
    fcntl(pipe_stderr[0], F_SETFD, FD_CLOEXEC);
    fcntl(pipe_stdin[0], F_SETFD, FD_CLOEXEC);*/

    pid = fork();
    if (pid == -1) {
        fprintf(stderr, "[-] fork(): %s\n", strerror(errno));
        return handles;
    }

    /* Setup child parameters */
    new_argv = malloc(10 * sizeof(char*));
    new_argv[0] = (char *)progname;
    new_argv[1] = (char *)parms;
    new_argv[2] = NULL;
    new_argv[3] = NULL;

    if (pid == 0) {
        int err;

        close(pipe_stdin[1]);
        close(pipe_stdout[0]);
        close(pipe_stderr[0]);

        dup2(pipe_stdin[0], 0);
        dup2(pipe_stdout[1], 1);
        dup2(pipe_stderr[1], 2);

        /* Now execute our child with new program */
        err = execvp(progname, new_argv);
        if (err) {
            fprintf(stderr, "[+] execvp(%s) failed: %s\n", progname, strerror(errno));
            return handles;
        }

    } else {
        handles.child_stdin = pipe_stdin[1];
        handles.child_stdout = pipe_stdout[0];
        handles.child_stderr = pipe_stderr[0];

        close(pipe_stdout[1]);
        close(pipe_stderr[1]);
        close(pipe_stdin[0]);

        /* we are the parent */
        return handles;
    }
    return handles;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x10(%rsp), %rdi
callq 0x10c0
testl %eax, %eax
js 0x1652
leaq 0x8(%rsp), %rdi
callq 0x10c0
testl %eax, %eax
js 0x1659
leaq 0x18(%rsp), %rdi
callq 0x10c0
testl %eax, %eax
js 0x1660
callq 0x1180
cmpl $-0x1, %eax
je 0x1667
movl %eax, %ebp
movl $0x50, %edi
callq 0x1110
movq %rbx, (%rax)
movq %r14, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movl 0x1c(%rsp), %r15d
testl %ebp, %ebp
je 0x15f2
movl 0x8(%rsp), %r14d
movl 0x10(%rsp), %ebx
movl 0x14(%rsp), %edi
callq 0x10b0
movl 0xc(%rsp), %edi
callq 0x10b0
movl 0x18(%rsp), %edi
callq 0x10b0
shlq $0x20, %rbx
jmp 0x1674
movq %rax, %r12
movl %r15d, %edi
callq 0x10b0
movl 0x10(%rsp), %edi
callq 0x10b0
movl 0x8(%rsp), %edi
callq 0x10b0
movl 0x18(%rsp), %edi
xorl %r14d, %r14d
xorl %esi, %esi
callq 0x1090
movl 0x14(%rsp), %edi
movl $0x1, %esi
callq 0x1090
movl 0xc(%rsp), %edi
movl $0x2, %esi
callq 0x1090
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1140
testl %eax, %eax
je 0x166f
movq %rbx, %rdi
callq 0x1226
jmp 0x166c
callq 0x12e9
jmp 0x166c
callq 0x12bc
jmp 0x166c
callq 0x128f
jmp 0x166c
callq 0x1262
xorl %r14d, %r14d
xorl %ebx, %ebx
xorl %r15d, %r15d
orq %r15, %rbx
movq %rbx, %rax
movl %r14d, %edx
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq