#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 */
scalar_t__ EOF;
scalar_t__ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
scalar_t__ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(void) {
  char buf[4096];
  while (fgets(buf, 4096, stdin) != NULL)
    if (fputs(buf, stdout) == EOF)
      printf("output error");
  if (ferror(stdin))
    printf("input error");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x1010(%rbp),%rdi
mov    0x2e88(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     11ac <main+0x6c>
lea    -0x1010(%rbp),%rdi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%rax
jne    11a7 <main+0x67>
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
jmp    1152 <main+0x12>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11d0 <main+0x90>
lea    0xe42(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1000,%rsp
mov    0x2e91(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rdi
mov    $0x1000,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     11c1 <main+0x81>
mov    0x2e5d(%rip),%r12
mov    %rsp,%rbx
mov    0x2e63(%rip),%r13
lea    0xe7c(%rip),%r14
jmp    11a5 <main+0x65>
cs nopw 0x0(%rax,%rax,1)
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     11c1 <main+0x81>
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <fputs@plt>
cmp    0x0(%r13),%rax
jne    1190 <main+0x50>
mov    %r14,%rdi
call   1040 <printf@plt>
jmp    1190 <main+0x50>
mov    (%r15),%edi
call   1030 <ferror@plt>
test   %rax,%rax
je     11da <main+0x9a>
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@stdin = global i32 0
@stdout = global i32 0
@EOF = global i64 0
@.str = [13 x i8] c"output error\00"
@.str.1 = [12 x i8] c"input error\00"
define i32 @main() {
%1 = alloca [4096 x i8]
%2 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32* @fgets(i8* %2, i32 4096, i32 %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %17, label %6
6: ; preds = %0, %13
%7 = load i32, i32* @stdout
%8 = call i64 @fputs(i8* %2, i32 %7)
%9 = load i64, i64* @EOF
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %6
%14 = load i32, i32* @stdin
%15 = call i32* @fgets(i8* %2, i32 4096, i32 %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %6
17: ; preds = %13, %0
%18 = load i32, i32* @stdin
%19 = call i64 @ferror(i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
ret i32 0
}