// File: /workspace/github_c_makefile_star2_O2/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, %rbx
movq %rdi, %r14
leaq 0x10(%rsp), %rdi
callq 0x10c0
testl %eax, %eax
js 0x14a0
leaq 0x8(%rsp), %rdi
callq 0x10c0
testl %eax, %eax
js 0x14a0
leaq 0x18(%rsp), %rdi
callq 0x10c0
testl %eax, %eax
js 0x14a0
callq 0x1180
cmpl $-0x1, %eax
je 0x14bf
movl %eax, %ebp
pushq $0x50
popq %rdi
callq 0x1110
movq %r14, (%rax)
movq %rbx, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movl 0x1c(%rsp), %r12d
testl %ebp, %ebp
je 0x141e
movl 0x8(%rsp), %ebx
movl 0x10(%rsp), %r14d
movl 0x14(%rsp), %edi
callq 0x10b0
movl 0xc(%rsp), %edi
callq 0x10b0
movl 0x18(%rsp), %edi
callq 0x10b0
shlq $0x20, %r14
jmp 0x14f1
movq %rax, %r15
movl %r12d, %edi
callq 0x10b0
movl 0x10(%rsp), %edi
callq 0x10b0
movl 0x8(%rsp), %edi
callq 0x10b0
movl 0x18(%rsp), %edi
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x1090
movl 0x14(%rsp), %edi
pushq $0x1
popq %rsi
callq 0x1090
movl 0xc(%rsp), %edi
pushq $0x2
popq %rsi
callq 0x1090
movq %r14, %rdi
movq %r15, %rsi
callq 0x1140
testl %eax, %eax
je 0x14eb
movq 0x2b82(%rip), %rax      # 0x3ff8
movq (%rax), %r15
callq 0x1040
movl (%rax), %edi
callq 0x1170
leaq 0xbbc(%rip), %rsi       # 0x2048
xorl %ebx, %ebx
movq %r15, %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x10f0
jmp 0x14eb
movq 0x2b51(%rip), %rax      # 0x3ff8
movq (%rax), %r14
callq 0x1040
movl (%rax), %edi
callq 0x1170
leaq 0xb6b(%rip), %rsi       # 0x2028
jmp 0x14dc
movq 0x2b32(%rip), %rax      # 0x3ff8
movq (%rax), %r14
callq 0x1040
movl (%rax), %edi
callq 0x1170
leaq 0xb5c(%rip), %rsi       # 0x2038
xorl %ebx, %ebx
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x10f0
xorl %r14d, %r14d
xorl %r12d, %r12d
orq %r12, %r14
movq %r14, %rax
movl %ebx, %edx
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq