#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ cleanupFeederProcess(scalar_t__);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ createPipeFeeder(void (*)(int, void *), void *const, int *,
                                    scalar_t__ *);
int /*<<< orphan*/ spawnProcessor(char const *const, char const **const, int,
                                  int *, scalar_t__ *);
void stub1(int, void *const);
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
void pm_system2_vp(const char *const progName, const char **const argArray,
                   void stdinFeeder(int, void *), void *const feederParm,
                   void stdoutAccepter(int, void *), void *const accepterParm,
                   int *const termStatusP) {
  int progStdinFd;
  pid_t feederPid;
  pid_t processorPid;
  int termStatus;
  if (stdinFeeder)
    createPipeFeeder(stdinFeeder, feederParm, &progStdinFd, &feederPid);
  else {
    progStdinFd = 0;
    feederPid = 0;
  }
  if (stdoutAccepter) {
    int progStdoutFd;
    spawnProcessor(progName, argArray, progStdinFd, &progStdoutFd,
                   &processorPid);
    close(progStdinFd);
    (*stdoutAccepter)(progStdoutFd, accepterParm);
    close(progStdoutFd);
  } else {
    spawnProcessor(progName, argArray, progStdinFd, NULL, &processorPid);
  }
  waitpid(processorPid, &termStatus, 0);
  if (feederPid)
    cleanupFeederProcess(feederPid);
  *termStatusP = termStatus;
}


x86 assembly (clang, -O0):
<pm_system2_vp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1199 <pm_system2_vp+0x49>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x34(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1060 <createPipeFeeder@plt>
jmp    11a8 <pm_system2_vp+0x58>
movl   $0x0,-0x34(%rbp)
movq   $0x0,-0x40(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ed <pm_system2_vp+0x9d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x34(%rbp),%edx
lea    -0x50(%rbp),%rcx
lea    -0x48(%rbp),%r8
call   1040 <spawnProcessor@plt>
mov    -0x34(%rbp),%edi
call   1030 <close@plt>
mov    -0x28(%rbp),%rax
mov    -0x50(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   *%rax
mov    -0x50(%rbp),%edi
call   1030 <close@plt>
jmp    1205 <pm_system2_vp+0xb5>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x34(%rbp),%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x48(%rbp),%r8
call   1040 <spawnProcessor@plt>
mov    -0x48(%rbp),%rdi
lea    -0x4c(%rbp),%rsi
xor    %edx,%edx
call   1070 <waitpid@plt>
cmpq   $0x0,-0x40(%rbp)
je     1228 <pm_system2_vp+0xd8>
mov    -0x40(%rbp),%rdi
call   1050 <cleanupFeederProcess@plt>
mov    -0x4c(%rbp),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pm_system2_vp>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r14
mov    %r8,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
test   %rdx,%rdx
je     11be <pm_system2_vp+0x6e>
lea    0x4(%rsp),%rax
lea    0x10(%rsp),%r8
mov    %rdx,%rdi
mov    %rcx,%rsi
mov    %rax,%rdx
mov    %r8,%rcx
call   1060 <createPipeFeeder@plt>
test   %rbx,%rbx
je     11d4 <pm_system2_vp+0x84>
mov    0x4(%rsp),%edx
mov    %rsp,%rcx
lea    0x8(%rsp),%r8
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <spawnProcessor@plt>
mov    0x4(%rsp),%edi
call   1030 <close@plt>
mov    (%rsp),%edi
mov    %r14,%rsi
call   *%rbx
mov    (%rsp),%edi
call   1030 <close@plt>
jmp    11ea <pm_system2_vp+0x9a>
movl   $0x0,0x4(%rsp)
movq   $0x0,0x10(%rsp)
test   %rbx,%rbx
jne    118c <pm_system2_vp+0x3c>
mov    0x4(%rsp),%edx
lea    0x8(%rsp),%r8
mov    %r12,%rdi
mov    %r15,%rsi
xor    %ecx,%ecx
call   1040 <spawnProcessor@plt>
mov    0x40(%rsp),%rbx
mov    0x8(%rsp),%rdi
mov    %rsp,%rsi
xor    %edx,%edx
call   1070 <waitpid@plt>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     120d <pm_system2_vp+0xbd>
call   1050 <cleanupFeederProcess@plt>
mov    (%rsp),%eax
mov    %eax,(%rbx)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @pm_system2_vp(i8* %0, i8** %1, void (i32, i8*)* %2, i8* %3, void (i32, i8*)* %4, i8* %5, i32* %6) {
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca void (i32, i8*)*
%11 = alloca i8*
%12 = alloca void (i32, i8*)*
%13 = alloca i8*
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i64
%17 = alloca i64
%18 = alloca i32
%19 = alloca i32
store i8* %0, i8** %8
store i8** %1, i8*** %9
store void (i32, i8*)* %2, void (i32, i8*)** %10
store i8* %3, i8** %11
store void (i32, i8*)* %4, void (i32, i8*)** %12
store i8* %5, i8** %13
store i32* %6, i32** %14
%20 = load void (i32, i8*)*, void (i32, i8*)** %10
%21 = icmp ne void (i32, i8*)* %20, null
br i1 %21, label %22, label %26
22: ; preds = %7
%23 = load void (i32, i8*)*, void (i32, i8*)** %10
%24 = load i8*, i8** %11
%25 = call i32 @createPipeFeeder(void (i32, i8*)* %23, i8* %24, i32* %15, i64* %16)
br label %27
26: ; preds = %7
store i32 0, i32* %15
store i64 0, i64* %16
br label %27
27: ; preds = %26, %22
%28 = load void (i32, i8*)*, void (i32, i8*)** %12
%29 = icmp ne void (i32, i8*)* %28, null
br i1 %29, label %30, label %42
30: ; preds = %27
%31 = load i8*, i8** %8
%32 = load i8**, i8*** %9
%33 = load i32, i32* %15
%34 = call i32 @spawnProcessor(i8* %31, i8** %32, i32 %33, i32* %19, i64* %17)
%35 = load i32, i32* %15
%36 = call i32 @close(i32 %35)
%37 = load void (i32, i8*)*, void (i32, i8*)** %12
%38 = load i32, i32* %19
%39 = load i8*, i8** %13
%40 = load i32, i32* %19
%41 = call i32 @close(i32 %40)
br label %47
42: ; preds = %27
%43 = load i8*, i8** %8
%44 = load i8**, i8*** %9
%45 = load i32, i32* %15
%46 = call i32 @spawnProcessor(i8* %43, i8** %44, i32 %45, i32* null, i64* %17)
br label %47
47: ; preds = %42, %30
%48 = load i64, i64* %17
%49 = call i32 @waitpid(i64 %48, i32* %18, i32 0)
%50 = load i64, i64* %16
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = load i64, i64* %16
%54 = call i32 @cleanupFeederProcess(i64 %53)
br label %55
55: ; preds = %52, %47
%56 = load i32, i32* %18
%57 = load i32*, i32** %14
store i32 %56, i32* %57
ret void
}

LLVM IR (-O2):
define void @pm_system2_vp(i8* %0, i8** %1, void (i32, i8*)* %2, i8* %3, void (i32, i8*)* %4, i8* %5, i32* nocapture writeonly %6) {
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = bitcast i32* %8 to i8*
%14 = bitcast i64* %9 to i8*
%15 = bitcast i64* %10 to i8*
%16 = bitcast i32* %11 to i8*
%17 = icmp eq void (i32, i8*)* %2, null
br i1 %17, label %20, label %18
18: ; preds = %7
%19 = call i32 @createPipeFeeder(void (i32, i8*)* %2, i8* %3, i32* %8, i64* %9)
br label %21
20: ; preds = %7
store i32 0, i32* %8
store i64 0, i64* %9
br label %21
21: ; preds = %20, %18
%22 = icmp eq void (i32, i8*)* %4, null
br i1 %22, label %32, label %23
23: ; preds = %21
%24 = bitcast i32* %12 to i8*
%25 = load i32, i32* %8
%26 = call i32 @spawnProcessor(i8* %0, i8** %1, i32 %25, i32* %12, i64* %10)
%27 = load i32, i32* %8
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* %12
%30 = load i32, i32* %12
%31 = call i32 @close(i32 %30)
br label %35
32: ; preds = %21
%33 = load i32, i32* %8
%34 = call i32 @spawnProcessor(i8* %0, i8** %1, i32 %33, i32* null, i64* %10)
br label %35
35: ; preds = %32, %23
%36 = load i64, i64* %10
%37 = call i32 @waitpid(i64 %36, i32* %11, i32 0)
%38 = load i64, i64* %9
%39 = icmp eq i64 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %35
%41 = call i32 @cleanupFeederProcess(i64 %38)
br label %42
42: ; preds = %40, %35
%43 = load i32, i32* %11
store i32 %43, i32* %6
ret void
}