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

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ stdin;
void clear_input_buffer(void) {
  struct timeval tv;
  fd_set fds;
  char buf;
  tv.tv_usec = 0;
  tv.tv_sec = 0;
  FD_ZERO(&fds);
  FD_SET(fileno(stdin), &fds);
  fflush(stdin);
  while (select(1, &fds, NULL, NULL, &tv) != 0)
    read(fileno(stdin), &buf, 1);
}


x86 assembly (clang, -O0):
<clear_input_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1050 <FD_ZERO@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
call   1040 <fileno@plt>
mov    %eax,%edi
lea    -0x14(%rbp),%rsi
call   1080 <FD_SET@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    $0x1,%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x10(%rbp),%r8
mov    %rcx,%rdx
call   1060 <select@plt>
cmp    $0x0,%rax
je     11ee <clear_input_buffer+0x8e>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1040 <fileno@plt>
mov    %eax,%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
jmp    11a8 <clear_input_buffer+0x48>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clear_input_buffer>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <FD_ZERO@plt>
mov    0x2e61(%rip),%r12
mov    (%r12),%edi
call   1040 <fileno@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1080 <FD_SET@plt>
mov    (%r12),%edi
call   1070 <fflush@plt>
lea    0x10(%rsp),%r8
mov    $0x1,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <select@plt>
test   %rax,%rax
je     1201 <clear_input_buffer+0xa1>
lea    0xb(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0x10(%rsp),%rbx
nopl   (%rax)
mov    (%r12),%edi
call   1040 <fileno@plt>
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    $0x1,%edi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
call   1060 <select@plt>
test   %rax,%rax
jne    11d0 <clear_input_buffer+0x70>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@stdin = global i32 0
define void @clear_input_buffer() {
%1 = alloca %struct.timeval
%2 = alloca i32
%3 = alloca i8
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
store i64 0, i64* %4
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
store i64 0, i64* %5
%6 = call i32 @FD_ZERO(i32* %2)
%7 = load i32, i32* @stdin
%8 = call i32 @fileno(i32 %7)
%9 = call i32 @FD_SET(i32 %8, i32* %2)
%10 = load i32, i32* @stdin
%11 = call i32 @fflush(i32 %10)
br label %12
12: ; preds = %15, %0
%13 = call i64 @select(i32 1, i32* %2, i32* null, i32* null, %struct.timeval* %1)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32, i32* @stdin
%17 = call i32 @fileno(i32 %16)
%18 = call i32 @read(i32 %17, i8* %3, i32 1)
br label %12
19: ; preds = %12
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@stdin = global i32 0
define void @clear_input_buffer() {
%1 = alloca %struct.timeval
%2 = alloca i32
%3 = alloca i8
%4 = bitcast %struct.timeval* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast %struct.timeval* %1 to i8*
%7 = call i32 @FD_ZERO(i32* %2)
%8 = load i32, i32* @stdin
%9 = call i32 @fileno(i32 %8)
%10 = call i32 @FD_SET(i32 %9, i32* %2)
%11 = load i32, i32* @stdin
%12 = call i32 @fflush(i32 %11)
%13 = call i64 @select(i32 1, i32* %2, i32* null, i32* null, %struct.timeval* %1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %0, %15
%16 = load i32, i32* @stdin
%17 = call i32 @fileno(i32 %16)
%18 = call i32 @read(i32 %17, i8* %3, i32 1)
%19 = call i64 @select(i32 1, i32* %2, i32* null, i32* null, %struct.timeval* %1)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %15
21: ; preds = %15, %0
ret void
}