#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;
int /*<<< orphan*/ exit(int);
scalar_t__ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char const *argv[]) {
  char buf[1024];
  while (fgets(buf, 1024, stdin) != NULL) {
    if (fputs(buf, stdout) == EOF) {
      fprintf(stderr, "output error\n");
      exit(1);
    }
  }
  if (ferror(stdin)) {
    fprintf(stderr, "input error\n");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11d6 <main+0x86>
lea    -0x410(%rbp),%rdi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2e37(%rip),%rcx
cmp    (%rcx),%rax
jne    11d1 <main+0x81>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1169 <main+0x19>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     120d <main+0xbd>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    0x2e83(%rip),%r14
mov    %rsp,%rbx
mov    0x2e59(%rip),%r15
mov    0x2e6a(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11c5 <main+0x75>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1040 <fputs@plt>
cmp    (%r12),%rax
jne    1180 <main+0x30>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    (%r14),%edi
call   1030 <ferror@plt>
test   %rax,%rax
jne    11e3 <main+0x93>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
jmp    11b6 <main+0x66>

LLVM IR (-O0):
@stdin = global i32 0
@stdout = global i32 0
@EOF = global i64 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 [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %7
7: ; preds = %22, %2
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32* @fgets(i8* %8, i32 1024, i32 %9)
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %23
12: ; preds = %7
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%14 = load i32, i32* @stdout
%15 = call i64 @fputs(i8* %13, i32 %14)
%16 = load i64, i64* @EOF
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %22
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))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %12
br label %7
23: ; preds = %7
%24 = load i32, i32* @stdin
%25 = call i64 @ferror(i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %23
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@stdout = global i32 0
@EOF = global i64 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) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %9, %2
%6 = load i32, i32* @stdin
%7 = call i32* @fgets(i8* %4, i32 1024, i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %18, label %9
9: ; preds = %5
%10 = load i32, i32* @stdout
%11 = call i64 @fputs(i8* %4, i32 %10)
%12 = load i64, i64* @EOF
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %5
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %5
%19 = load i32, i32* @stdin
%20 = call i64 @ferror(i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %18
ret i32 0
}