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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
lea    -0x2020(%rbp),%rsi
mov    $0x2000,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    11a1 <main+0x71>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    -0x2020(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <write@plt>
cmp    -0x14(%rbp),%eax
je     119c <main+0x6c>
lea    0xe69(%rip),%rdi
call   1030 <err_sys@plt>
jmp    1149 <main+0x19>
cmpl   $0x0,-0x14(%rbp)
jge    11b7 <main+0x87>
lea    0xe60(%rip),%rdi
call   1030 <err_sys@plt>
xor    %eax,%eax
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2000,%rsp
mov    0x2e92(%rip),%r15
mov    (%r15),%edi
mov    %rsp,%rsi
mov    $0x2000,%edx
call   1050 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11a2 <main+0x72>
mov    0x2e8d(%rip),%r12
mov    %rsp,%rbx
lea    0xe93(%rip),%r14
jmp    1186 <main+0x56>
nop
mov    (%r15),%edi
mov    %rbx,%rsi
mov    $0x2000,%edx
call   1050 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11a2 <main+0x72>
mov    (%r12),%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
cmp    %ebp,%eax
je     1170 <main+0x40>
mov    %r14,%rdi
call   1030 <err_sys@plt>
jmp    1170 <main+0x40>
test   %ebp,%ebp
jns    11b2 <main+0x82>
lea    0xe65(%rip),%rdi
call   1030 <err_sys@plt>
xor    %eax,%eax
add    $0x2000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@.str = [18 x i8] c"error while write\00"
@.str.1 = [20 x i8] c"error while reading\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [8192 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %8
8: ; preds = %22, %2
%9 = load i32, i32* @STDIN_FILENO
%10 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%11 = call i32 @read(i32 %9, i8* %10, i32 8192)
store i32 %11, i32* %6
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %8
%14 = load i32, i32* @STDOUT_FILENO
%15 = getelementptr inbounds [8192 x i8], [8192 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 %22
20: ; preds = %13
%21 = call i32 @err_sys(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %13
br label %8
23: ; preds = %8
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @err_sys(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %26, %23
ret i32 0
}

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