#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 */
struct plProc {
  int dummy;
};
typedef size_t ssize_t;

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int /*<<< orphan*/);
int /*<<< orphan*/ errAbort(char *, long long, long long);
int /*<<< orphan*/ errnoAbort(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ plProcSetup(struct plProc *, int /*<<< orphan*/, int, int);
size_t write(int /*<<< orphan*/, void *, size_t);
void plProcMemWrite(struct plProc *proc, int stdoutFd, int stderrFd,
                    void *otherEndBuf, size_t otherEndBufSize) {
  plProcSetup(proc, STDIN_FILENO, stdoutFd, stderrFd);
  ssize_t wrCnt = write(STDOUT_FILENO, otherEndBuf, otherEndBufSize);
  if (wrCnt < 0)
    errnoAbort("pipeline input buffer write failed");
  else if (wrCnt != otherEndBufSize)
    errAbort("pipeline input buffer short write %lld, expected %lld",
             (long long)wrCnt, (long long)otherEndBufSize);
  else {
    close(STDOUT_FILENO);
    exit(0);
  }
}


x86 assembly (clang, -O0):
<plProcMemWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1040 <plProcSetup@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jae    11c8 <plProcMemWrite+0x68>
lea    0xe42(%rip),%rdi
call   1050 <errnoAbort@plt>
jmp    1209 <plProcMemWrite+0xa9>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     11ef <plProcMemWrite+0x8f>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe3e(%rip),%rdi
call   1060 <errAbort@plt>
jmp    1204 <plProcMemWrite+0xa4>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1070 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    1209 <plProcMemWrite+0xa9>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plProcMemWrite>:
push   %r15
push   %r14
push   %rbx
mov    %r8,%rbx
mov    %rcx,%r14
mov    %edx,%ecx
mov    %esi,%edx
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
call   1040 <plProcSetup@plt>
mov    0x2e7c(%rip),%r15
mov    (%r15),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <write@plt>
cmp    %rbx,%rax
je     119e <plProcMemWrite+0x4e>
lea    0xe72(%rip),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <errAbort@plt>
mov    (%r15),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.plProc = type { i32 }
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@.str = [35 x i8] c"pipeline input buffer write failed\00"
@.str.1 = [54 x i8] c"pipeline input buffer short write %lld, expected %lld\00"
define void @plProcMemWrite(%struct.plProc* %0, i32 %1, i32 %2, i8* %3, i64 %4) {
%6 = alloca %struct.plProc*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
store %struct.plProc* %0, %struct.plProc** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i64 %4, i64* %10
%12 = load %struct.plProc*, %struct.plProc** %6
%13 = load i32, i32* @STDIN_FILENO
%14 = load i32, i32* %7
%15 = load i32, i32* %8
%16 = call i32 @plProcSetup(%struct.plProc* %12, i32 %13, i32 %14, i32 %15)
%17 = load i32, i32* @STDOUT_FILENO
%18 = load i8*, i8** %9
%19 = load i64, i64* %10
%20 = call i64 @write(i32 %17, i8* %18, i64 %19)
store i64 %20, i64* %11
%21 = load i64, i64* %11
%22 = icmp ult i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %5
%24 = call i32 @errnoAbort(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %38
25: ; preds = %5
%26 = load i64, i64* %11
%27 = load i64, i64* %10
%28 = icmp ne i64 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i64, i64* %11
%31 = load i64, i64* %10
%32 = call i32 @errAbort(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i64 %30, i64 %31)
br label %37
33: ; preds = %25
%34 = load i32, i32* @STDOUT_FILENO
%35 = call i32 @close(i32 %34)
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %29
br label %38
38: ; preds = %37, %23
ret void
}

LLVM IR (-O2):
%struct.plProc = type { i32 }
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@.str.1 = [54 x i8] c"pipeline input buffer short write %lld, expected %lld\00"
define void @plProcMemWrite(%struct.plProc* %0, i32 %1, i32 %2, i8* nocapture %3, i64 %4) {
%6 = load i32, i32* @STDIN_FILENO
%7 = tail call i32 @plProcSetup(%struct.plProc* %0, i32 %6, i32 %1, i32 %2)
%8 = load i32, i32* @STDOUT_FILENO
%9 = tail call i64 @write(i32 %8, i8* %3, i64 %4)
%10 = icmp eq i64 %9, %4
br i1 %10, label %13, label %11
11: ; preds = %5
%12 = tail call i32 @errAbort(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i64 %9, i64 %4)
ret void
13: ; preds = %5
%14 = load i32, i32* @STDOUT_FILENO
%15 = tail call i32 @close(i32 %14)
%16 = tail call i32 @exit(i32 0)
unreachable
}