#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);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int write(int /*<<< orphan*/, char *, int);
int main(int argc, char **argv) {
  int n;
  char buf[32768];
  while ((n = read(STDIN_FILENO, buf, 32768)) > 0) {
    if (write(STDOUT_FILENO, buf, n) != n) {
      fprintf(stderr, "write error\n");
      exit(1);
    }
  }
  if (n < 0) {
    fprintf(stderr, "read error\n");
    exit(1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    -0x8020(%rbp),%rsi
mov    $0x8000,%edx
call   1040 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    11c4 <main+0x84>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    -0x8020(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
cmp    -0x14(%rbp),%eax
je     11bf <main+0x7f>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1159 <main+0x19>
cmpl   $0x0,-0x14(%rbp)
jge    11ed <main+0xad>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %eax,%eax
add    $0x8020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x8008,%rsp
mov    0x2e7c(%rip),%r14
mov    %rsp,%rbx
mov    0x2e92(%rip),%r15
xchg   %ax,%ax
mov    (%r14),%edi
mov    %rbx,%rsi
mov    $0x8000,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    11a6 <main+0x66>
mov    %eax,%ebp
mov    (%r15),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    %ebp,%eax
je     1160 <main+0x20>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
js     11b8 <main+0x78>
xor    %eax,%eax
add    $0x8008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
jmp    1197 <main+0x57>

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

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