#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*/ p;

/* Variables and functions */
int /*<<< orphan*/ cull(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ read(int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ redirect(int, int *);
int /*<<< orphan*/ stdout;
void sink(void) {
  int pd[2], p;
  for (;;) {
    read(0, &p, sizeof(p));
    printf("%d\n", p);
    fflush(stdout);
    pipe(pd);
    if (fork()) {
      redirect(0, pd);
      continue;
    } else {
      redirect(1, pd);
      cull(p);
    }
  }
}


x86 assembly (clang, -O0):
<sink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %edi,%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    -0xc(%rbp),%esi
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    -0x8(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%rax
je     11cf <sink+0x5f>
lea    -0x8(%rbp),%rsi
xor    %edi,%edi
call   1030 <redirect@plt>
jmp    1178 <sink+0x8>
lea    -0x8(%rbp),%rsi
mov    $0x1,%edi
call   1030 <redirect@plt>
mov    -0xc(%rbp),%edi
call   1080 <cull@plt>
jmp    1178 <sink+0x8>

x86 assembly (clang, -O2):
<sink>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0x4(%rsp),%r14
lea    0xe78(%rip),%r15
mov    0x2e51(%rip),%r12
lea    0x8(%rsp),%rbx
jmp    11aa <sink+0x3a>
cs nopw 0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %rbx,%rsi
call   1030 <redirect@plt>
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    0x4(%rsp),%ebp
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    (%r12),%edi
call   1070 <fflush@plt>
mov    %rbx,%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
jne    11a0 <sink+0x30>
mov    $0x1,%edi
mov    %rbx,%rsi
call   1030 <redirect@plt>
mov    %ebp,%edi
call   1080 <cull@plt>
jmp    11aa <sink+0x3a>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@stdout = global i32 0
define void @sink() {
%1 = alloca [2 x i32]
%2 = alloca i32
br label %3
3: ; preds = %21, %13, %0
%4 = call i32 @read(i32 0, i32* %2, i32 4)
%5 = load i32, i32* %2
%6 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @stdout
%8 = call i32 @fflush(i32 %7)
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
%11 = call i64 (...) @fork()
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%15 = call i32 @redirect(i32 0, i32* %14)
br label %3
16: ; preds = %3
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%18 = call i32 @redirect(i32 1, i32* %17)
%19 = load i32, i32* %2
%20 = call i32 @cull(i32 %19)
br label %21
21: ; preds = %16
br label %3
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@stdout = global i32 0
define void @sink() {
%1 = alloca [2 x i32]
%2 = alloca i32
%3 = bitcast [2 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
br label %6
6: ; preds = %17, %0
%7 = call i32 @read(i32 0, i32* %2, i32 4)
%8 = load i32, i32* %2
%9 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @stdout
%11 = call i32 @fflush(i32 %10)
%12 = call i32 @pipe(i32* %5)
%13 = call i64 (...) @fork()
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %6
%16 = call i32 @redirect(i32 0, i32* %5)
br label %17
17: ; preds = %15, %18
br label %6
18: ; preds = %6
%19 = call i32 @redirect(i32 1, i32* %5)
%20 = call i32 @cull(i32 %8)
br label %17
}