#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*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ pm_error(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void stub1(int, void *const);
void createPipeFeeder(void pipeFeederRtn(int, void *), void *const feederParm,
                      int *const fdP, pid_t *const pidP) {
  int pipeToFeed[2];
  pid_t rc;
  pipe(pipeToFeed);
  rc = fork();
  if (rc < 0) {
    pm_error("fork() of stdin feeder failed.  errno=%d (%s)", errno,
             strerror(errno));
  } else if (rc == 0) {
    close(pipeToFeed[0]);
    (*pipeFeederRtn)(pipeToFeed[1], feederParm);
    exit(0);
  } else {
    pid_t const feederPid = rc;
    close(pipeToFeed[1]);
    *fdP = pipeToFeed[0];
    *pidP = feederPid;
  }
}


x86 assembly (clang, -O0):
<createPipeFeeder>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
call   1040 <pipe@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    11c7 <createPipeFeeder+0x67>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x3c(%rbp),%esi
mov    %eax,%edx
lea    0xe43(%rip),%rdi
call   1070 <pm_error@plt>
jmp    1217 <createPipeFeeder+0xb7>
cmpq   $0x0,-0x30(%rbp)
jne    11ee <createPipeFeeder+0x8e>
mov    -0x28(%rbp),%edi
call   1030 <close@plt>
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   *%rax
xor    %edi,%edi
call   1050 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <close@plt>
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
jmp    1217 <createPipeFeeder+0xb7>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createPipeFeeder>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r14
lea    0x8(%rsp),%rdi
call   1040 <pipe@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
js     11ab <createPipeFeeder+0x4b>
je     11d9 <createPipeFeeder+0x79>
mov    %rax,%rbx
mov    0xc(%rsp),%edi
call   1030 <close@plt>
mov    0x8(%rsp),%eax
mov    %eax,0x0(%r13)
mov    %rbx,(%r12)
jmp    11cb <createPipeFeeder+0x6b>
mov    0x2e2e(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1060 <strerror@plt>
lea    0xe3e(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1070 <pm_error@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x8(%rsp),%edi
call   1030 <close@plt>
mov    0xc(%rsp),%edi
mov    %r15,%rsi
call   *%r14
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [46 x i8] c"fork() of stdin feeder failed. errno=%d (%s)\00"
@errno = global i32 0
define void @createPipeFeeder(void (i32, i8*)* %0, i8* %1, i32* %2, i64* %3) {
%5 = alloca void (i32, i8*)*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i64*
%9 = alloca [2 x i32]
%10 = alloca i64
%11 = alloca i64
store void (i32, i8*)* %0, void (i32, i8*)** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i64* %3, i64** %8
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%13 = call i32 @pipe(i32* %12)
%14 = call i64 (...) @fork()
store i64 %14, i64* %10
%15 = load i64, i64* %10
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %4
%18 = load i32, i32* @errno
%19 = load i32, i32* @errno
%20 = call i32 @strerror(i32 %19)
%21 = call i32 @pm_error(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %20)
br label %45
22: ; preds = %4
%23 = load i64, i64* %10
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %22
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%27 = load i32, i32* %26
%28 = call i32 @close(i32 %27)
%29 = load void (i32, i8*)*, void (i32, i8*)** %5
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%31 = load i32, i32* %30
%32 = load i8*, i8** %6
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %22
%35 = load i64, i64* %10
store i64 %35, i64* %11
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%37 = load i32, i32* %36
%38 = call i32 @close(i32 %37)
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%40 = load i32, i32* %39
%41 = load i32*, i32** %7
store i32 %40, i32* %41
%42 = load i64, i64* %11
%43 = load i64*, i64** %8
store i64 %42, i64* %43
br label %44
44: ; preds = %34
br label %45
45: ; preds = %44, %17
ret void
}

LLVM IR (-O2):
@.str = [46 x i8] c"fork() of stdin feeder failed. errno=%d (%s)\00"
@errno = global i32 0
define void @createPipeFeeder(void (i32, i8*)* nocapture %0, i8* %1, i32* nocapture writeonly %2, i64* nocapture writeonly %3) {
%5 = alloca [2 x i32]
%6 = bitcast [2 x i32]* %5 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = call i64 (...) @fork()
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %4
%12 = load i32, i32* @errno
%13 = call i32 @strerror(i32 %12)
%14 = call i32 @pm_error(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
br label %28
15: ; preds = %4
%16 = icmp eq i64 %9, 0
br i1 %16, label %17, label %23
17: ; preds = %15
%18 = load i32, i32* %7
%19 = call i32 @close(i32 %18)
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%21 = load i32, i32* %20
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %15
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* %7
store i32 %27, i32* %2
store i64 %9, i64* %3
br label %28
28: ; preds = %23, %11
ret void
}