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

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int _ensure(int, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int start_upstream(int up) {
  int ret = _ensure(95, fork());
  if (ret == 0) {
    char buf[1024];
    while (1) {
      char *bufptr = buf;
      int size = _ensure(100, read(STDIN_FILENO, bufptr, sizeof(buf)));
      if (size == 0)
        break;
      while (size > 0) {
        int rc = _ensure(103, write(up, bufptr, size));
        bufptr += rc;
        size -= rc;
      }
    }
    exit(0);
  }
  return ret;
}


x86 assembly (clang, -O0):
<start_upstream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,%esi
mov    $0x5f,%edi
call   1060 <_ensure@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1247 <start_upstream+0xf7>
jmp    1183 <start_upstream+0x33>
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
mov    -0x418(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,%esi
mov    $0x64,%edi
call   1060 <_ensure@plt>
mov    %eax,-0x41c(%rbp)
cmpl   $0x0,-0x41c(%rbp)
jne    11cf <start_upstream+0x7f>
jmp    1240 <start_upstream+0xf0>
jmp    11d4 <start_upstream+0x84>
cmpl   $0x0,-0x41c(%rbp)
jle    123b <start_upstream+0xeb>
mov    -0x4(%rbp),%edi
mov    -0x418(%rbp),%rsi
mov    -0x41c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,%esi
mov    $0x67,%edi
call   1060 <_ensure@plt>
mov    %eax,-0x420(%rbp)
mov    -0x420(%rbp),%ecx
mov    -0x418(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x418(%rbp)
mov    -0x420(%rbp),%ecx
mov    -0x41c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x41c(%rbp)
jmp    11d4 <start_upstream+0x84>
jmp    1183 <start_upstream+0x33>
xor    %edi,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_upstream>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %edi,%r15d
xor    %eax,%eax
call   1070 <fork@plt>
mov    $0x5f,%edi
mov    %eax,%esi
call   1060 <_ensure@plt>
test   %eax,%eax
je     1189 <start_upstream+0x39>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e50(%rip),%r12
mov    (%r12),%edi
mov    %rsp,%r14
mov    %r14,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    $0x64,%edi
mov    %eax,%esi
call   1060 <_ensure@plt>
test   %eax,%eax
jne    11bb <start_upstream+0x6b>
xor    %edi,%edi
call   1050 <exit@plt>
mov    %eax,%ebp
jmp    11e3 <start_upstream+0x93>
nop
mov    (%r12),%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    $0x64,%edi
mov    %eax,%esi
call   1060 <_ensure@plt>
mov    %eax,%ebp
test   %eax,%eax
je     11b4 <start_upstream+0x64>
test   %ebp,%ebp
jle    11c0 <start_upstream+0x70>
mov    %r14,%rbx
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
mov    $0x67,%edi
mov    %eax,%esi
call   1060 <_ensure@plt>
cltq
add    %rax,%rbx
sub    %eax,%ebp
jg     11f0 <start_upstream+0xa0>
jmp    11c0 <start_upstream+0x70>

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
define i32 @start_upstream(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
%8 = call i32 (...) @fork()
%9 = call i32 @_ensure(i32 95, i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %42
12: ; preds = %1
br label %13
13: ; preds = %12, %39
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
store i8* %14, i8** %5
%15 = load i32, i32* @STDIN_FILENO
%16 = load i8*, i8** %5
%17 = call i32 @read(i32 %15, i8* %16, i32 1024)
%18 = call i32 @_ensure(i32 100, i32 %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %13
br label %40
22: ; preds = %13
br label %23
23: ; preds = %26, %22
%24 = load i32, i32* %6
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %39
26: ; preds = %23
%27 = load i32, i32* %2
%28 = load i8*, i8** %5
%29 = load i32, i32* %6
%30 = call i32 @write(i32 %27, i8* %28, i32 %29)
%31 = call i32 @_ensure(i32 103, i32 %30)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = load i8*, i8** %5
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8* %35, i8** %5
%36 = load i32, i32* %7
%37 = load i32, i32* %6
%38 = sub nsw i32 %37, %36
store i32 %38, i32* %6
br label %23
39: ; preds = %23
br label %13
40: ; preds = %21
%41 = call i32 @exit(i32 0)
unreachable
42: ; preds = %1
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
define i32 @start_upstream(i32 %0) {
%2 = alloca [1024 x i8]
%3 = tail call i32 (...) @fork()
%4 = tail call i32 @_ensure(i32 95, i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %31
6: ; preds = %1
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%8 = load i32, i32* @STDIN_FILENO
%9 = call i32 @read(i32 %8, i8* %7, i32 1024)
%10 = tail call i32 @_ensure(i32 100, i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %29, label %17
12: ; preds = %20, %17
%13 = load i32, i32* @STDIN_FILENO
%14 = call i32 @read(i32 %13, i8* %7, i32 1024)
%15 = tail call i32 @_ensure(i32 100, i32 %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %29, label %17
17: ; preds = %6, %12
%18 = phi i32 [ %15, %12 ], [ %10, %6 ]
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %12
20: ; preds = %17, %20
%21 = phi i8* [ %26, %20 ], [ %7, %17 ]
%22 = phi i32 [ %27, %20 ], [ %18, %17 ]
%23 = call i32 @write(i32 %0, i8* %21, i32 %22)
%24 = tail call i32 @_ensure(i32 103, i32 %23)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %21, i64 %25
%27 = sub nsw i32 %22, %24
%28 = icmp sgt i32 %27, 0
br i1 %28, label %20, label %12
29: ; preds = %12, %6
%30 = tail call i32 @exit(i32 0)
unreachable
31: ; preds = %1
ret i32 %4
}