#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 int /*<<< orphan*/ msg;

/* Variables and functions */
int /*<<< orphan*/ bread(void *, int);
int /*<<< orphan*/ bzero(void *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *malloc(int);
int read(int, int *, int);
int /*<<< orphan*/ stderr;
int write(int, int *, int);
void doit(int rd, int wr, int process_size) {
  int msg;
  void *data = NULL;
  if (process_size) {
    data = malloc(process_size);
    if (data)
      bzero(data, process_size);
  }
  for (;;) {
    if (read(rd, &msg, sizeof(msg)) != sizeof(msg)) {
      (void)fprintf(stderr, "read/write on pipe"
                            "\n");
      break;
    }
    bread(data, process_size);
    if (write(wr, &msg, sizeof(msg)) != sizeof(msg)) {
      (void)fprintf(stderr, "read/write on pipe"
                            "\n");
      break;
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<doit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11bb <doit+0x4b>
mov    -0xc(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b6 <doit+0x46>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1080 <bzero@plt>
jmp    11bb <doit+0x4b>
jmp    11c0 <doit+0x50>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cltq
cmp    $0x4,%rax
je     11f7 <doit+0x87>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
call   1060 <fprintf@plt>
jmp    123f <doit+0xcf>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <bread@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cltq
cmp    $0x4,%rax
je     123a <doit+0xca>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
call   1060 <fprintf@plt>
jmp    123f <doit+0xcf>
jmp    11c0 <doit+0x50>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<doit>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%r12d
test   %edx,%edx
je     1196 <doit+0x26>
mov    %r14d,%edi
call   1070 <malloc@plt>
test   %rax,%rax
jne    119a <doit+0x2a>
xor    %ebp,%ebp
jmp    11a8 <doit+0x38>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r14d,%esi
call   1080 <bzero@plt>
lea    0xc(%rsp),%rbx
nopl   (%rax)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    11e5 <doit+0x75>
mov    %rbp,%rdi
mov    %r14d,%esi
call   1040 <bread@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x4,%eax
je     11b0 <doit+0x40>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"read/write on pipe\0A\00"
define void @doit(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i8* null, i8** %8
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %3
%12 = load i32, i32* %6
%13 = call i8* @malloc(i32 %12)
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i8*, i8** %8
%18 = load i32, i32* %6
%19 = call i32 @bzero(i8* %17, i32 %18)
br label %20
20: ; preds = %16, %11
br label %21
21: ; preds = %20, %3
br label %22
22: ; preds = %41, %21
%23 = load i32, i32* %4
%24 = call i32 @read(i32 %23, i32* %7, i32 4)
%25 = sext i32 %24 to i64
%26 = icmp ne i64 %25, 4
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %42
30: ; preds = %22
%31 = load i8*, i8** %8
%32 = load i32, i32* %6
%33 = call i32 @bread(i8* %31, i32 %32)
%34 = load i32, i32* %5
%35 = call i32 @write(i32 %34, i32* %7, i32 4)
%36 = sext i32 %35 to i64
%37 = icmp ne i64 %36, 4
br i1 %37, label %38, label %41
38: ; preds = %30
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %42
41: ; preds = %30
br label %22
42: ; preds = %38, %27
%43 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"read/write on pipe\0A\00"
define void @doit(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = icmp eq i32 %2, 0
br i1 %6, label %12, label %7
7: ; preds = %3
%8 = tail call i8* @malloc(i32 %2)
%9 = icmp eq i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @bzero(i8* %8, i32 %2)
br label %12
12: ; preds = %7, %10, %3
%13 = phi i8* [ %8, %10 ], [ null, %7 ], [ null, %3 ]
br label %14
14: ; preds = %17, %12
%15 = call i32 @read(i32 %0, i32* %4, i32 4)
%16 = icmp eq i32 %15, 4
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = tail call i32 @bread(i8* %13, i32 %2)
%19 = call i32 @write(i32 %1, i32* %4, i32 4)
%20 = icmp eq i32 %19, 4
br i1 %20, label %14, label %21
21: ; preds = %17, %14
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%24 = tail call i32 @exit(i32 0)
unreachable
}