#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*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
void reader(FILE *stream) {
  char buffer[1024];
  while (!feof(stream) && !ferror(stream) &&
         fgets(buffer, sizeof(buffer), stream) != NULL) {
    fputs(buffer, stdout);
  }
}


x86 assembly (clang, -O0):
<reader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x411(%rbp)
jne    11a9 <reader+0x69>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x411(%rbp)
jne    11a9 <reader+0x69>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x411(%rbp)
mov    -0x411(%rbp),%al
test   $0x1,%al
jne    11bc <reader+0x7c>
jmp    11d6 <reader+0x96>
lea    -0x410(%rbp),%rdi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
jmp    114f <reader+0xf>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reader>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rbx
call   1060 <feof@plt>
test   %eax,%eax
je     1165 <reader+0x25>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rsp,%r14
mov    0x2e71(%rip),%r15
nop
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %eax,%eax
jne    1158 <reader+0x18>
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1158 <reader+0x18>
mov    (%r15),%esi
mov    %r14,%rdi
call   1040 <fputs@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     1170 <reader+0x30>
jmp    1158 <reader+0x18>

LLVM IR (-O0):
@stdout = global i32 0
define void @reader(i32* %0) {
%2 = alloca i32*
%3 = alloca [1024 x i8]
store i32* %0, i32** %2
br label %4
4: ; preds = %19, %1
%5 = load i32*, i32** %2
%6 = call i32 @feof(i32* %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %17, label %8
8: ; preds = %4
%9 = load i32*, i32** %2
%10 = call i32 @ferror(i32* %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %8
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%14 = load i32*, i32** %2
%15 = call i32* @fgets(i8* %13, i32 1024, i32* %14)
%16 = icmp ne i32* %15, null
br label %17
17: ; preds = %12, %8, %4
%18 = phi i1 [ false, %8 ], [ false, %4 ], [ %16, %12 ]
br i1 %18, label %19, label %23
19: ; preds = %17
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%21 = load i32, i32* @stdout
%22 = call i32 @fputs(i8* %20, i32 %21)
br label %4
23: ; preds = %17
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
define void @reader(i32* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @feof(i32* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %17
6: ; preds = %1, %12
%7 = call i32 @ferror(i32* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = call i32* @fgets(i8* %3, i32 1024, i32* %0)
%11 = icmp eq i32* %10, null
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = load i32, i32* @stdout
%14 = call i32 @fputs(i8* %3, i32 %13)
%15 = call i32 @feof(i32* %0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %6, label %17
17: ; preds = %9, %6, %12, %1
ret void
}