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

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ read(int, char *, int);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/,
                  int /*<<< orphan*/, struct timeval *);
void detect_enter(int time_out) {
  int fd_console = 0;
  fd_set fdset;
  struct timeval timeout;
  char c;
  FD_ZERO(&fdset);
  FD_SET(fd_console, &fdset);
  timeout.tv_sec = time_out;
  timeout.tv_usec = 0;
  if (select(fd_console + 1, &fdset, 0, 0, &timeout) > 0) {
    do {
      read(fd_console, &c, 1);
    } while (c != 10);
  }
}


x86 assembly (clang, -O0):
<detect_enter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
call   1060 <FD_SET@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
add    $0x1,%edi
lea    -0xc(%rbp),%rsi
xor    %ecx,%ecx
lea    -0x20(%rbp),%r8
mov    %ecx,%edx
call   1050 <select@plt>
cmp    $0x0,%rax
jle    11be <detect_enter+0x7e>
jmp    119b <detect_enter+0x5b>
mov    -0x8(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
movsbl -0x21(%rbp),%eax
cmp    $0xa,%eax
jne    119b <detect_enter+0x5b>
jmp    11be <detect_enter+0x7e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detect_enter>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1040 <FD_ZERO@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1060 <FD_SET@plt>
mov    %ebx,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%r8
mov    $0x1,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
test   %rax,%rax
jle    11a6 <detect_enter+0x66>
lea    0x3(%rsp),%rbx
nopl   (%rax)
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmpb   $0xa,0x3(%rsp)
jne    1190 <detect_enter+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

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