#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ feof(int /*<<< orphan*/);
scalar_t__ ferror(int /*<<< orphan*/);
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
void command(void) {
  char buf[4096];
  char *ret = fgets(buf, 4096, stdin);
  if (ret == NULL) {
    if (feof(stdin)) {
      exit(EXIT_SUCCESS);
    }
    if (ferror(stdin)) {
      perror("fgets");
      exit(EXIT_FAILURE);
    }
  }
  printf("%s", buf);
}


x86 assembly (clang, -O0):
<command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
lea    -0x1000(%rbp),%rdi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%esi
call   1050 <fgets@plt>
mov    %rax,-0x1008(%rbp)
cmpq   $0x0,-0x1008(%rbp)
jne    11f7 <command+0x97>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     11c0 <command+0x60>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11f2 <command+0x92>
lea    0xe21(%rip),%rdi
call   1070 <perror@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    11f7 <command+0x97>
lea    -0x1000(%rbp),%rsi
lea    0xe01(%rip),%rdi
call   1040 <printf@plt>
add    $0x1010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<command>:
push   %rbx
sub    $0x1000,%rsp
mov    0x2e79(%rip),%rbx
mov    (%rbx),%edx
mov    %rsp,%rdi
mov    $0x1000,%esi
call   1050 <fgets@plt>
test   %rax,%rax
jne    119b <command+0x3b>
mov    (%rbx),%edi
call   1060 <feof@plt>
test   %rax,%rax
jne    11b3 <command+0x53>
mov    (%rbx),%edi
call   1030 <ferror@plt>
test   %rax,%rax
jne    11c1 <command+0x61>
lea    0xe64(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
add    $0x1000,%rsp
pop    %rbx
ret
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xe38(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stdin = global i32 0
@EXIT_SUCCESS = global i32 0
@.str = [6 x i8] c"fgets\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define void @command() {
%1 = alloca [4096 x i8]
%2 = alloca i8*
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%4 = load i32, i32* @stdin
%5 = call i8* @fgets(i8* %3, i32 4096, i32 %4)
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %24
8: ; preds = %0
%9 = load i32, i32* @stdin
%10 = call i64 @feof(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* @EXIT_SUCCESS
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %8
%16 = load i32, i32* @stdin
%17 = call i64 @ferror(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %15
br label %24
24: ; preds = %23, %0
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%26 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %25)
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@EXIT_SUCCESS = global i32 0
@.str = [6 x i8] c"fgets\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define void @command() {
%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 i8* @fgets(i8* %2, i32 4096, i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %21
6: ; preds = %0
%7 = load i32, i32* @stdin
%8 = call i64 @feof(i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = load i32, i32* @EXIT_SUCCESS
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %6
%14 = load i32, i32* @stdin
%15 = call i64 @ferror(i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %13, %0
%22 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
ret void
}