#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*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  char line[4 + 1];
  char *ptr;
  int len = 0;
  while (fgets(line, 4, stdin) != NULL) {
    if (fputs(line, stdout) == EOF) {
      perror("fputs");
      return -1;
    }
  }
  if (ferror(stdin))
    printf("input error\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x15(%rbp),%rdi
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     11cd <main+0x7d>
lea    -0x15(%rbp),%rdi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
mov    0x2e39(%rip),%rcx
cmp    (%rcx),%rax
jne    11c8 <main+0x78>
lea    0xe49(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f8 <main+0xa8>
jmp    116d <main+0x1d>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11f1 <main+0xa1>
lea    0xe1a(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2e89(%rip),%r14
lea    0x3(%rsp),%rbx
mov    0x2e65(%rip),%r15
mov    0x2e6e(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     11b9 <main+0x69>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1050 <fputs@plt>
cmp    (%r12),%rax
jne    1180 <main+0x30>
lea    0xe53(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%ebx
jmp    11d4 <main+0x84>
mov    (%r14),%edi
call   1040 <ferror@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11d4 <main+0x84>
lea    0xe37(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@stdin = global i32 0
@stdout = global i32 0
@EOF = global i64 0
@.str = [6 x i8] c"fputs\00"
@str = [12 x i8] c"input error\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [5 x i8]
%4 = getelementptr inbounds [5 x i8], [5 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 4, i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %16, 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 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %22
16: ; preds = %5
%17 = load i32, i32* @stdin
%18 = call i64 @ferror(i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %22
22: ; preds = %16, %20, %14
%23 = phi i32 [ -1, %14 ], [ 0, %20 ], [ 0, %16 ]
ret i32 %23
}