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

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ read_byte(int);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, struct timeval *);
void flush_bytes(int fd) {
  fd_set s;
  struct timeval tv;
  FD_ZERO(&s);
  FD_SET(fd, &s);
  tv.tv_sec = tv.tv_usec = 0;
  while (select(fd + 1, &s, NULL, NULL, &tv) > 0)
    read_byte(fd);
}


x86 assembly (clang, -O0):
<flush_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1060 <FD_SET@plt>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rdx
call   1050 <select@plt>
cmp    $0x0,%rax
jle    11a1 <flush_bytes+0x61>
mov    -0x4(%rbp),%edi
call   1030 <read_byte@plt>
jmp    1170 <flush_bytes+0x30>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flush_bytes>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebx
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1040 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <FD_SET@plt>
lea    0x1(%rbx),%ebp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%r8
mov    %ebp,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
test   %rax,%rax
jle    11ad <flush_bytes+0x6d>
lea    0xc(%rsp),%r14
lea    0x10(%rsp),%r15
mov    %ebx,%edi
call   1030 <read_byte@plt>
mov    %ebp,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1050 <select@plt>
test   %rax,%rax
jg     1190 <flush_bytes+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @flush_bytes(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = bitcast i32* %2 to i8*
%5 = bitcast %struct.timeval* %3 to i8*
%6 = call i32 @FD_ZERO(i32* %2)
%7 = call i32 @FD_SET(i32 %0, i32* %2)
%8 = add nsw i32 %0, 1
%9 = bitcast %struct.timeval* %3 to i8*
%10 = call i64 @select(i32 %8, i32* %2, i32* null, i32* null, %struct.timeval* %3)
%11 = icmp sgt i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %1, %12
%13 = call i32 @read_byte(i32 %0)
%14 = call i64 @select(i32 %8, i32* %2, i32* null, i32* null, %struct.timeval* %3)
%15 = icmp sgt i64 %14, 0
br i1 %15, label %12, label %16
16: ; preds = %12, %1
ret void
}