#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 */
struct timeval {
  int tv_usec;
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int read(int /*<<< orphan*/, char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
void lp_internal_flush_stdin() {
  fd_set rfds;
  struct timeval tv;
  int retval;
  FD_ZERO(&rfds);
  FD_SET(0, &rfds);
  do {
    tv.tv_sec = 0;
    tv.tv_usec = 1;
    retval = select(1, &rfds, NULL, NULL, &tv);
    if (retval) {
      char buf[256];
      int r = read(0, buf, 256);
      if (r < 256)
        break;
    }
  } while (retval);
}


x86 assembly (clang, -O0):
<lp_internal_flush_stdin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
lea    -0x4(%rbp),%rdi
call   1040 <FD_ZERO@plt>
xor    %edi,%edi
lea    -0x4(%rbp),%rsi
call   1060 <FD_SET@plt>
movq   $0x0,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
mov    $0x1,%edi
lea    -0x4(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rdx
call   1050 <select@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11c7 <lp_internal_flush_stdin+0x87>
lea    -0x120(%rbp),%rsi
xor    %edi,%edi
mov    $0x100,%edx
call   1030 <read@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x100,-0x124(%rbp)
jge    11c2 <lp_internal_flush_stdin+0x82>
jmp    11d6 <lp_internal_flush_stdin+0x96>
jmp    11c7 <lp_internal_flush_stdin+0x87>
jmp    11cc <lp_internal_flush_stdin+0x8c>
cmpl   $0x0,-0x1c(%rbp)
jne    115f <lp_internal_flush_stdin+0x1f>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lp_internal_flush_stdin>:
push   %r15
push   %r14
push   %rbx
sub    $0x120,%rsp
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1040 <FD_ZERO@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1060 <FD_SET@plt>
lea    0x10(%rsp),%rbx
lea    0x20(%rsp),%r15
nopl   (%rax)
movq   $0x0,0x18(%rsp)
movl   $0x1,0x10(%rsp)
mov    $0x1,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
call   1050 <select@plt>
test   %eax,%eax
je     11af <lp_internal_flush_stdin+0x6f>
xor    %edi,%edi
mov    %r15,%rsi
mov    $0x100,%edx
call   1030 <read@plt>
cmp    $0xff,%eax
jg     1170 <lp_internal_flush_stdin+0x30>
add    $0x120,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
define void @lp_internal_flush_stdin() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = alloca i32
%6 = call i32 @FD_ZERO(i32* %1)
%7 = call i32 @FD_SET(i32 0, i32* %1)
br label %8
8: ; preds = %22, %0
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
store i64 0, i64* %9
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
store i32 1, i32* %10
%11 = call i32 @select(i32 1, i32* %1, i32* null, i32* null, %struct.timeval* %2)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %8
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%16 = call i32 @read(i32 0, i8* %15, i32 256)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = icmp slt i32 %17, 256
br i1 %18, label %19, label %20
19: ; preds = %14
br label %25
20: ; preds = %14
br label %21
21: ; preds = %20, %8
br label %22
22: ; preds = %21
%23 = load i32, i32* %3
%24 = icmp ne i32 %23, 0
br i1 %24, label %8, label %25
25: ; preds = %22, %19
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define void @lp_internal_flush_stdin() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca [256 x i8]
%4 = bitcast i32* %1 to i8*
%5 = bitcast %struct.timeval* %2 to i8*
%6 = call i32 @FD_ZERO(i32* %1)
%7 = call i32 @FD_SET(i32 0, i32* %1)
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
br label %11
11: ; preds = %14, %0
store i64 0, i64* %9
store i32 1, i32* %10
%12 = call i32 @select(i32 1, i32* %1, i32* null, i32* null, %struct.timeval* %2)
%13 = icmp eq i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = call i32 @read(i32 0, i8* %8, i32 256)
%16 = icmp slt i32 %15, 256
br i1 %16, label %17, label %11
17: ; preds = %11, %14
ret void
}