#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*/ errno;
int /*<<< orphan*/ printf(char *, char *);
int read(int /*<<< orphan*/, char *, int);
char *strerror(int /*<<< orphan*/);
scalar_t__ write(int, char *, int);
int main(void) {
  int n;
  char buf[4096];
  while ((n = read(0, buf, 4096)) > 0) {
    if (write(1, buf, n) < 0) {
      printf("read error: %s\n", strerror(errno));
      return -1;
    }
  }
  if (n < 0) {
    printf("read error: %s\n", strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x1010(%rbp),%rsi
xor    %edi,%edi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11bd <main+0x7d>
lea    -0x1010(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11b8 <main+0x78>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <main+0xb7>
jmp    1152 <main+0x12>
cmpl   $0x0,-0x8(%rbp)
jge    11f0 <main+0xb0>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe21(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <main+0xb7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x1000,%rsp
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    1179 <main+0x39>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %rax,%rax
jns    1150 <main+0x10>
jmp    117f <main+0x3f>
xor    %ecx,%ecx
test   %eax,%eax
jns    11a1 <main+0x61>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe6c(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%ecx
mov    %ecx,%eax
add    $0x1000,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [16 x i8] c"read error: %s\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca [4096 x i8]
%2 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %6, %0
%4 = call i32 @read(i32 0, i8* %2, i32 4096)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = call i64 @write(i32 1, i8* %2, i32 %4)
%8 = icmp slt i64 %7, 0
br i1 %8, label %11, label %3
9: ; preds = %3
%10 = icmp slt i32 %4, 0
br i1 %10, label %11, label %15
11: ; preds = %6, %9
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %11, %9
%16 = phi i32 [ 0, %9 ], [ -1, %11 ]
ret i32 %16
}