#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 int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ err_sys(char *);
scalar_t__ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
scalar_t__ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  char buf[4];
  while (fgets(buf, sizeof(buf), stdin) != NULL) {
    if (fputs(buf, stdout) == EOF) {
      err_sys("fputs error");
    }
  }
  if (ferror(stdin)) {
    err_sys("stdin error");
  }
  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)
lea    -0x14(%rbp),%rdi
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     11aa <main+0x6a>
lea    -0x14(%rbp),%rdi
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
mov    0x2e50(%rip),%rcx
cmp    (%rcx),%rax
jne    11a5 <main+0x65>
lea    0xe60(%rip),%rdi
call   1040 <err_sys@plt>
jmp    1156 <main+0x16>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11ce <main+0x8e>
lea    0xe43(%rip),%rdi
call   1040 <err_sys@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e94(%rip),%r15
mov    (%r15),%edx
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     11c1 <main+0x81>
mov    0x2e5e(%rip),%r12
lea    0xc(%rsp),%rbx
mov    0x2e62(%rip),%r13
lea    0xe7b(%rip),%r14
jmp    11a5 <main+0x65>
nopw   0x0(%rax,%rax,1)
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x4,%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 <err_sys@plt>
jmp    1190 <main+0x50>
mov    (%r15),%edi
call   1030 <ferror@plt>
test   %rax,%rax
je     11da <main+0x9a>
lea    0xe37(%rip),%rdi
call   1040 <err_sys@plt>
xor    %eax,%eax
add    $0x10,%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 = [12 x i8] c"fputs error\00"
@.str.1 = [12 x i8] c"stdin error\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %7
7: ; preds = %20, %2
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32* @fgets(i8* %8, i32 4, i32 %9)
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %21
12: ; preds = %7
%13 = getelementptr inbounds [4 x i8], [4 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 %20
18: ; preds = %12
%19 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %12
br label %7
21: ; preds = %7
%22 = load i32, i32* @stdin
%23 = call i64 @ferror(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
ret i32 0
}

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