#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 EOF;
int /*<<< orphan*/ clearerr(int /*<<< orphan*/);
scalar_t__ ferror(int /*<<< orphan*/);
int getchar();
int putchar(int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdin;
int keep_reading() {
  int c;
  for (;;) {
    sleep(1);
    clearerr(stdin);
    while ((c = getchar()) != EOF) {
      if (putchar(c) == EOF)
        return 1;
    }
    if (ferror(stdin))
      return 1;
  }
}


x86 assembly (clang, -O0):
<keep_reading>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
call   1060 <clearerr@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e5f(%rip),%rcx
cmp    (%rcx),%eax
je     11b1 <keep_reading+0x61>
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
mov    0x2e48(%rip),%rcx
cmp    (%rcx),%eax
jne    11ac <keep_reading+0x5c>
movl   $0x1,-0x4(%rbp)
jmp    11da <keep_reading+0x8a>
jmp    1170 <keep_reading+0x20>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     11d5 <keep_reading+0x85>
movl   $0x1,-0x4(%rbp)
jmp    11da <keep_reading+0x8a>
jmp    1158 <keep_reading+0x8>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<keep_reading>:
push   %r14
push   %rbx
push   %rax
mov    0x2e8d(%rip),%r14
mov    0x2e7e(%rip),%rbx
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    (%r14),%edi
call   1060 <clearerr@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%rbx),%eax
je     11a0 <keep_reading+0x50>
mov    %eax,%edi
call   1030 <putchar@plt>
cmp    (%rbx),%eax
jne    1180 <keep_reading+0x30>
jmp    11ad <keep_reading+0x5d>
nopl   0x0(%rax,%rax,1)
mov    (%r14),%edi
call   1040 <ferror@plt>
test   %rax,%rax
je     1162 <keep_reading+0x12>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdin = global i32 0
@EOF = global i32 0
define i32 @keep_reading() {
%1 = alloca i32
%2 = alloca i32
br label %3
3: ; preds = %23, %0
%4 = call i32 @sleep(i32 1)
%5 = load i32, i32* @stdin
%6 = call i32 @clearerr(i32 %5)
br label %7
7: ; preds = %17, %3
%8 = call i32 (...) @getchar()
store i32 %8, i32* %2
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %18
11: ; preds = %7
%12 = load i32, i32* %2
%13 = call i32 @putchar(i32 %12)
%14 = load i32, i32* @EOF
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 1, i32* %1
br label %24
17: ; preds = %11
br label %7
18: ; preds = %7
%19 = load i32, i32* @stdin
%20 = call i64 @ferror(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 1, i32* %1
br label %24
23: ; preds = %18
br label %3
24: ; preds = %22, %16
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i32 0
define i32 @keep_reading() {
br label %1
1: ; preds = %13, %0
%2 = tail call i32 @sleep(i32 1)
%3 = load i32, i32* @stdin
%4 = tail call i32 @clearerr(i32 %3)
br label %5
5: ; preds = %9, %1
%6 = tail call i32 (...) @getchar()
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = tail call i32 @putchar(i32 %6)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %17, label %5
13: ; preds = %5
%14 = load i32, i32* @stdin
%15 = tail call i64 @ferror(i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %1, label %17
17: ; preds = %13, %9
ret i32 1
}