#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 EOF;
scalar_t__ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getc(int /*<<< orphan*/);
int putc(int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int ch;
  while ((ch = getc(stdin)) != EOF) {
    if (putc(ch, stdout) == EOF) {
      fprintf(stderr, "output error\n");
      return 0;
    }
  }
  if (ferror(stdin)) {
    fprintf(stderr, "input error\n");
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
call   1060 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e72(%rip),%rcx
cmp    (%rcx),%eax
je     11bc <main+0x7c>
mov    -0x14(%rbp),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
call   1040 <putc@plt>
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%eax
jne    11b7 <main+0x77>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fc <main+0xbc>
jmp    1156 <main+0x16>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11f5 <main+0xb5>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fc <main+0xbc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2e99(%rip),%r15
mov    0x2e8a(%rip),%rbx
mov    0x2e6b(%rip),%r12
lea    0xe9c(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15),%edi
call   1060 <getc@plt>
cmp    (%rbx),%eax
je     118d <main+0x4d>
mov    (%r12),%esi
mov    %eax,%edi
call   1040 <putc@plt>
cmp    (%rbx),%eax
jne    1170 <main+0x30>
jmp    11a1 <main+0x61>
mov    (%r15),%edi
call   1030 <ferror@plt>
test   %rax,%rax
je     11b2 <main+0x72>
lea    0xe6d(%rip),%r14
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str = [14 x i8] c"output error\0A\00"
@.str.1 = [13 x i8] c"input error\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %8, %2
%4 = load i32, i32* @stdin
%5 = tail call i32 @getc(i32 %4)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %13, label %8
8: ; preds = %3
%9 = load i32, i32* @stdout
%10 = tail call i32 @putc(i32 %5, i32 %9)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %17, label %3
13: ; preds = %3
%14 = load i32, i32* @stdin
%15 = tail call i64 @ferror(i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %8, %13
%18 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %13 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %8 ]
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* %18)
br label %21
21: ; preds = %17, %13
ret i32 0
}