#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__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
scalar_t__ read(int /*<<< orphan*/, char *, size_t const);
scalar_t__ write(int /*<<< orphan*/, char *, scalar_t__);
int passthru(void) {
  char buf[8192];
  const size_t bufsize = sizeof buf;
  ssize_t nread;
  ssize_t nwrote;
  while ((nread = read(STDIN_FILENO, buf, bufsize)) > 0) {
    nwrote = write(STDOUT_FILENO, buf, nread);
    if (nwrote != nread)
      err(EXIT_FAILURE, "short write");
  }
  if (nread < 0)
    err(EXIT_FAILURE, "read");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<passthru>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
movq   $0x2000,-0x2008(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    -0x2000(%rbp),%rsi
mov    $0x2000,%edx
call   1040 <read@plt>
mov    %rax,-0x2010(%rbp)
cmp    $0x0,%rax
jle    11c2 <passthru+0x92>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    -0x2000(%rbp),%rsi
mov    -0x2010(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x2018(%rbp)
mov    -0x2018(%rbp),%rax
cmp    -0x2010(%rbp),%rax
je     11bd <passthru+0x8d>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
call   1050 <err@plt>
jmp    1146 <passthru+0x16>
cmpq   $0x0,-0x2010(%rbp)
jge    11e5 <passthru+0xb5>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
call   1050 <err@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<passthru>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2008,%rsp
mov    0x2e80(%rip),%r12
mov    (%r12),%edi
mov    %rsp,%rsi
mov    $0x2000,%edx
call   1040 <read@plt>
mov    %rax,%rbx
test   %rax,%rax
jle    11ba <passthru+0x8a>
mov    0x2e88(%rip),%r13
mov    %rsp,%r15
mov    0x2e66(%rip),%rbp
lea    0xe87(%rip),%r14
jmp    1199 <passthru+0x69>
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    $0x2000,%edx
mov    %r15,%rsi
call   1040 <read@plt>
mov    %rax,%rbx
test   %rax,%rax
jle    11ba <passthru+0x8a>
mov    0x0(%r13),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <write@plt>
cmp    %rbx,%rax
je     1180 <passthru+0x50>
mov    0x0(%rbp),%edi
mov    %r14,%rsi
call   1050 <err@plt>
jmp    1180 <passthru+0x50>
test   %rbx,%rbx
jns    11d4 <passthru+0xa4>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
call   1050 <err@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%eax
add    $0x2008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [12 x i8] c"short write\00"
@.str.1 = [5 x i8] c"read\00"
@EXIT_SUCCESS = global i32 0
define i32 @passthru() {
%1 = alloca [8192 x i8]
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 8192, i64* %2
br label %5
5: ; preds = %21, %0
%6 = load i32, i32* @STDIN_FILENO
%7 = getelementptr inbounds [8192 x i8], [8192 x i8]* %1, i64 0, i64 0
%8 = call i64 @read(i32 %6, i8* %7, i64 8192)
store i64 %8, i64* %3
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %22
10: ; preds = %5
%11 = load i32, i32* @STDOUT_FILENO
%12 = getelementptr inbounds [8192 x i8], [8192 x i8]* %1, i64 0, i64 0
%13 = load i64, i64* %3
%14 = call i64 @write(i32 %11, i8* %12, i64 %13)
store i64 %14, i64* %4
%15 = load i64, i64* %4
%16 = load i64, i64* %3
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @err(i32 %19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %18, %10
br label %5
22: ; preds = %5
%23 = load i64, i64* %3
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @err(i32 %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %25, %22
%29 = load i32, i32* @EXIT_SUCCESS
ret i32 %29
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [12 x i8] c"short write\00"
@.str.1 = [5 x i8] c"read\00"
@EXIT_SUCCESS = global i32 0
define i32 @passthru() {
%1 = alloca [8192 x i8]
%2 = getelementptr inbounds [8192 x i8], [8192 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @STDIN_FILENO
%4 = call i64 @read(i32 %3, i8* %2, i64 8192)
%5 = icmp sgt i64 %4, 0
br i1 %5, label %6, label %18
6: ; preds = %0, %14
%7 = phi i64 [ %16, %14 ], [ %4, %0 ]
%8 = load i32, i32* @STDOUT_FILENO
%9 = call i64 @write(i32 %8, i8* %2, i64 %7)
%10 = icmp eq i64 %9, %7
br i1 %10, label %14, label %11
11: ; preds = %6
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @err(i32 %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %11, %6
%15 = load i32, i32* @STDIN_FILENO
%16 = call i64 @read(i32 %15, i8* %2, i64 8192)
%17 = icmp sgt i64 %16, 0
br i1 %17, label %6, label %18
18: ; preds = %14, %0
%19 = phi i64 [ %4, %0 ], [ %16, %14 ]
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @err(i32 %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %21, %18
%25 = load i32, i32* @EXIT_SUCCESS
ret i32 %25
}