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

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int write(int /*<<< orphan*/, char *, int);
int main(void) {
  int n;
  char buf[4096];
  while ((n = read(STDIN_FILENO, buf, 4096)) > 0) {
    if (write(STDOUT_FILENO, buf, n) != n) {
      fprintf(stderr, "write error");
    }
  }
  if (n < 0) {
    fprintf(stderr, "read error");
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   1040 <read@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11b3 <main+0x73>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    -0x1010(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <write@plt>
cmp    -0x8(%rbp),%eax
je     11ae <main+0x6e>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1152 <main+0x12>
cmpl   $0x0,-0x8(%rbp)
jge    11d2 <main+0x92>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    0x2e78(%rip),%r15
mov    (%r15),%edi
mov    %rsp,%rsi
mov    $0x1000,%edx
call   1040 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11c6 <main+0x86>
mov    0x2e7b(%rip),%r12
mov    %rsp,%rbx
mov    0x2e59(%rip),%r13
lea    0xe7a(%rip),%r14
jmp    11a6 <main+0x66>
nopl   0x0(%rax,%rax,1)
mov    (%r15),%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1040 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11c6 <main+0x86>
mov    (%r12),%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
cmp    %ebp,%eax
je     1190 <main+0x50>
mov    0x0(%r13),%edi
mov    %r14,%rsi
call   1050 <fprintf@plt>
jmp    1190 <main+0x50>
test   %ebp,%ebp
jns    11df <main+0x9f>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@stderr = global i32 0
@.str = [12 x i8] c"write error\00"
@.str.1 = [11 x i8] c"read error\00"
define i32 @main() {
%1 = alloca [4096 x i8]
%2 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @STDIN_FILENO
%4 = call i32 @read(i32 %3, i8* %2, i32 4096)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %18
6: ; preds = %0, %14
%7 = phi i32 [ %16, %14 ], [ %4, %0 ]
%8 = load i32, i32* @STDOUT_FILENO
%9 = call i32 @write(i32 %8, i8* %2, i32 %7)
%10 = icmp eq i32 %9, %7
br i1 %10, label %14, label %11
11: ; preds = %6
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(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 i32 @read(i32 %15, i8* %2, i32 4096)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %6, label %18
18: ; preds = %14, %0
%19 = phi i32 [ %4, %0 ], [ %16, %14 ]
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %21, %18
%25 = tail call i32 @exit(i32 0)
unreachable
}