#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 */
typedef scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ printf(char *);
scalar_t__ read(int /*<<< orphan*/, char *, int);
scalar_t__ write(int /*<<< orphan*/, char *, scalar_t__);
int main(int argc, char *argv[]) {
  char buf[256];
  ssize_t bytes_read = 0;
  while ((bytes_read = read(STDIN_FILENO, buf, 256)) > 0) {
    ssize_t bytes_written = write(STDOUT_FILENO, buf, bytes_read);
    if (bytes_read != bytes_written) {
      printf("write error!");
      return 1;
    }
  }
  if (bytes_read < 0) {
    printf("read error!");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x118(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %rax,-0x118(%rbp)
cmp    $0x0,%rax
jle    11d3 <main+0xa3>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rsi
mov    -0x118(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x120(%rbp)
mov    -0x118(%rbp),%rax
cmp    -0x120(%rbp),%rax
je     11ce <main+0x9e>
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f4 <main+0xc4>
jmp    1154 <main+0x24>
cmpq   $0x0,-0x118(%rbp)
jge    11ed <main+0xbd>
lea    0xe25(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    0x2e92(%rip),%r12
mov    %rsp,%r15
mov    0x2ea0(%rip),%rbp
lea    0xea9(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    %r15,%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %rax,%rbx
test   %rax,%rax
jle    1193 <main+0x63>
mov    0x0(%rbp),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <write@plt>
cmp    %rax,%rbx
je     1160 <main+0x30>
mov    $0x1,%ebp
jmp    11a1 <main+0x71>
xor    %ebp,%ebp
test   %rbx,%rbx
jns    11a9 <main+0x79>
lea    0xe6c(%rip),%r14
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %ebp,%eax
add    $0x100,%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 = [13 x i8] c"write error!\00"
@.str.1 = [12 x i8] c"read error!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %7
br label %9
9: ; preds = %24, %2
%10 = load i32, i32* @STDIN_FILENO
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%12 = call i64 @read(i32 %10, i8* %11, i32 256)
store i64 %12, i64* %7
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %25
14: ; preds = %9
%15 = load i32, i32* @STDOUT_FILENO
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%17 = load i64, i64* %7
%18 = call i64 @write(i32 %15, i8* %16, i64 %17)
store i64 %18, i64* %8
%19 = load i64, i64* %7
%20 = load i64, i64* %8
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %31
24: ; preds = %14
br label %9
25: ; preds = %9
%26 = load i64, i64* %7
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
store i32 0, i32* %3
br label %31
31: ; preds = %30, %22
%32 = load i32, i32* %3
ret i32 %32
}

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