#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__ EINTR;
int /*<<< orphan*/ STDIN_FILENO;
scalar_t__ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ monitor_args_execute();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pthread_exit(int *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ set_exit_flag(int);
int /*<<< orphan*/ stderr;
void flush_input(void) {
  int rv, n;
  char c;
  while ((n = read(STDIN_FILENO, &c, 1)) != 0) {
    if (n < 0) {
      if (errno == EINTR)
        continue;
      else {
        perror("read");
        fflush(stderr);
        set_exit_flag(1);
        monitor_args_execute();
        rv = 1;
        pthread_exit(&rv);
      }
    }
    if (c == '\n')
      break;
  }
}


x86 assembly (clang, -O0):
<flush_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     120b <flush_input+0xab>
cmpl   $0x0,-0x8(%rbp)
jge    11f4 <flush_input+0x94>
mov    0x2e3c(%rip),%rax
mov    (%rax),%rax
mov    0x2e2a(%rip),%rcx
cmp    (%rcx),%rax
jne    11b4 <flush_input+0x54>
jmp    1168 <flush_input+0x8>
lea    0xe45(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    $0x1,%edi
call   1030 <set_exit_flag@plt>
mov    $0x0,%al
call   1050 <monitor_args_execute@plt>
movl   $0x1,-0x4(%rbp)
lea    -0x4(%rbp),%rdi
call   1060 <pthread_exit@plt>
jmp    11f4 <flush_input+0x94>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
jne    1206 <flush_input+0xa6>
jmp    120b <flush_input+0xab>
jmp    1168 <flush_input+0x8>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flush_input>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e56(%rip),%r12
mov    (%r12),%edi
lea    0x3(%rsp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %eax,%eax
je     121c <flush_input+0xbc>
mov    0x2e44(%rip),%r13
mov    0x2e35(%rip),%rbp
mov    0x2e3e(%rip),%r14
lea    0x4(%rsp),%r15
lea    0x3(%rsp),%rbx
jmp    120c <flush_input+0xac>
lea    0xe4b(%rip),%rdi
call   1080 <perror@plt>
mov    (%r14),%edi
call   1070 <fflush@plt>
mov    $0x1,%edi
call   1030 <set_exit_flag@plt>
xor    %eax,%eax
call   1050 <monitor_args_execute@plt>
movl   $0x1,0x4(%rsp)
mov    %r15,%rdi
call   1060 <pthread_exit@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0xa,0x3(%rsp)
je     121c <flush_input+0xbc>
mov    (%r12),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %eax,%eax
je     121c <flush_input+0xbc>
test   %eax,%eax
jns    11f0 <flush_input+0x90>
mov    0x0(%r13),%rax
cmp    0x0(%rbp),%rax
je     11f7 <flush_input+0x97>
jmp    11ae <flush_input+0x4e>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@.str = [5 x i8] c"read\00"
@stderr = global i32 0
define void @flush_input() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
br label %4
4: ; preds = %29, %15, %0
%5 = load i32, i32* @STDIN_FILENO
%6 = call i32 @read(i32 %5, i8* %3, i32 1)
store i32 %6, i32* %2
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %30
8: ; preds = %4
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %8
%12 = load i64, i64* @errno
%13 = load i64, i64* @EINTR
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %11
br label %4
16: ; preds = %11
%17 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @stderr
%19 = call i32 @fflush(i32 %18)
%20 = call i32 @set_exit_flag(i32 1)
%21 = call i32 (...) @monitor_args_execute()
store i32 1, i32* %1
%22 = call i32 @pthread_exit(i32* %1)
br label %23
23: ; preds = %16
br label %24
24: ; preds = %23, %8
%25 = load i8, i8* %3
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %29
28: ; preds = %24
br label %30
29: ; preds = %24
br label %4
30: ; preds = %28, %4
ret void
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@.str = [5 x i8] c"read\00"
@stderr = global i32 0
define void @flush_input() {
%1 = alloca i32
%2 = alloca i8
%3 = bitcast i32* %1 to i8*
%4 = load i32, i32* @STDIN_FILENO
%5 = call i32 @read(i32 %4, i8* %2, i32 1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %28, label %7
7: ; preds = %0, %14
%8 = phi i32 [ %16, %14 ], [ %5, %0 ]
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %25
10: ; preds = %7
%11 = load i64, i64* @errno
%12 = load i64, i64* @EINTR
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %10, %25
%15 = load i32, i32* @STDIN_FILENO
%16 = call i32 @read(i32 %15, i8* %2, i32 1)
%17 = icmp eq i32 %16, 0
br i1 %17, label %28, label %7
18: ; preds = %10
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @stderr
%21 = call i32 @fflush(i32 %20)
%22 = call i32 @set_exit_flag(i32 1)
%23 = call i32 (...) @monitor_args_execute()
store i32 1, i32* %1
%24 = call i32 @pthread_exit(i32* %1)
br label %25
25: ; preds = %18, %7
%26 = load i8, i8* %2
%27 = icmp eq i8 %26, 10
br i1 %27, label %28, label %14
28: ; preds = %14, %25, %0
ret void
}