#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int errno;
int /*<<< orphan*/ printf(char *, int, char *);
int read(int /*<<< orphan*/, char *, int);
char *strerror(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 (n != (write(STDOUT_FILENO, buf, n)))
      printf("write error[%d][%s].\n", errno, strerror(errno));
  }
  if (n < 0) {
    printf("read error[%d][%s]\n", errno, strerror(errno));
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    -0x2020(%rbp),%rsi
mov    $0x2000,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    11e7 <main+0xa7>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2024(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    -0x2020(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    -0x2024(%rbp),%eax
cmp    %ecx,%eax
je     11e2 <main+0xa2>
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2028(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x2028(%rbp),%esi
mov    %rax,%rdx
lea    0xe23(%rip),%rdi
call   1040 <printf@plt>
jmp    1159 <main+0x19>
cmpl   $0x0,-0x14(%rbp)
jge    1234 <main+0xf4>
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x202c(%rbp)
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x202c(%rbp),%esi
mov    %rax,%rdx
lea    0xdf8(%rip),%rdi
call   1040 <printf@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1240 <main+0x100>
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2008,%rsp
mov    0x2e68(%rip),%r15
mov    (%r15),%edi
mov    %rsp,%rsi
mov    $0x2000,%edx
call   1050 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11d2 <main+0x92>
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    $0x2000,%edx
call   1050 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11d2 <main+0x92>
mov    (%r12),%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
cmp    %eax,%ebp
je     1190 <main+0x50>
mov    0x0(%r13),%ebp
mov    %ebp,%edi
call   1060 <strerror@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   1040 <printf@plt>
jmp    1190 <main+0x50>
test   %ebp,%ebp
js     11df <main+0x9f>
mov    0x2deb(%rip),%rax
jmp    1207 <main+0xc7>
mov    0x2df2(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1060 <strerror@plt>
lea    0xe20(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    0x2dc9(%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
@.str = [22 x i8] c"write error[%d][%s].\0A\00"
@errno = global i32 0
@.str.1 = [20 x i8] c"read error[%d][%s]\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
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 = %25, %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 %26
13: ; preds = %8
%14 = load i32, i32* %6
%15 = load i32, i32* @STDOUT_FILENO
%16 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%17 = load i32, i32* %6
%18 = call i32 @write(i32 %15, i8* %16, i32 %17)
%19 = icmp ne i32 %14, %18
br i1 %19, label %20, label %25
20: ; preds = %13
%21 = load i32, i32* @errno
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %21, i8* %23)
br label %25
25: ; preds = %20, %13
br label %8
26: ; preds = %8
%27 = load i32, i32* %6
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = load i32, i32* @errno
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %30, i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
store i32 %34, i32* %3
br label %37
35: ; preds = %26
%36 = load i32, i32* @EXIT_SUCCESS
store i32 %36, i32* %3
br label %37
37: ; preds = %35, %29
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@.str = [22 x i8] c"write error[%d][%s].\0A\00"
@errno = global i32 0
@.str.1 = [20 x i8] c"read error[%d][%s]\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
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 %21
8: ; preds = %2, %17
%9 = phi i32 [ %19, %17 ], [ %6, %2 ]
%10 = load i32, i32* @STDOUT_FILENO
%11 = call i32 @write(i32 %10, i8* %4, i32 %9)
%12 = icmp eq i32 %9, %11
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %14, i8* %15)
br label %17
17: ; preds = %13, %8
%18 = load i32, i32* @STDIN_FILENO
%19 = call i32 @read(i32 %18, i8* %4, i32 8192)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %8, label %21
21: ; preds = %17, %2
%22 = phi i32 [ %6, %2 ], [ %19, %17 ]
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* @errno
%26 = tail call i8* @strerror(i32 %25)
%27 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %25, i8* %26)
br label %28
28: ; preds = %21, %24
%29 = phi i32* [ @EXIT_FAILURE, %24 ], [ @EXIT_SUCCESS, %21 ]
%30 = load i32, i32* %29
ret i32 %30
}