#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct timeval {
  int tv_sec;
  int /*<<< orphan*/ member_0;
};
struct TYPE_4__ {
  int /*<<< orphan*/ member_0;
};
typedef TYPE_1__ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int /*<<< orphan*/, TYPE_1__ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int select(int, TYPE_1__ *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           struct timeval *);
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  while (1) {
    int selected;
    fd_set set = {0};
    struct timeval tm = {0};
    FD_SET(0, &set);
    tm.tv_sec = 3;
    selected = select(1, &set, NULL, NULL, &tm);
    if (selected > 0) {
      char msg[256] = {0};
      fgets(msg, 255, stdin);
      printf("Lido: %s\n", msg);
    } else {
      printf("Timeout!\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
xor    %edi,%edi
lea    -0x18(%rbp),%rsi
call   1070 <FD_SET@plt>
movl   $0x3,-0x20(%rbp)
mov    $0x1,%edi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1060 <select@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1208 <main+0xb8>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    0x2e06(%rip),%rax
mov    (%rax),%edx
mov    $0xff,%esi
call   1050 <fgets@plt>
lea    -0x120(%rbp),%rsi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1216 <main+0xc6>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1169 <main+0x19>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsp,%rbx
lea    0x8(%rsp),%r14
mov    0x2e78(%rip),%rbp
lea    0x10(%rsp),%r15
lea    0xe84(%rip),%r12
lea    0xe87(%rip),%r13
jmp    121b <main+0xcb>
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
mov    0x0(%rbp),%edx
mov    %r15,%rdi
mov    $0xff,%esi
call   1050 <fgets@plt>
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
xor    %edi,%edi
mov    %rbx,%rsi
call   1070 <FD_SET@plt>
movl   $0x3,0x8(%rsp)
mov    $0x1,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1060 <select@plt>
test   %eax,%eax
jg     1190 <main+0x40>
mov    %r13,%rdi
call   1030 <puts@plt>
jmp    121b <main+0xcb>

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32 }
%struct.timeval = type { i32, i32 }
@stdin = global i32 0
@.str = [10 x i8] c"Lido: %s\0A\00"
@.str.1 = [10 x i8] c"Timeout!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.TYPE_4__
%8 = alloca %struct.timeval
%9 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %10
10: ; preds = %2, %27
%11 = bitcast %struct.TYPE_4__* %7 to i8*
%12 = bitcast %struct.timeval* %8 to i8*
%13 = call i32 @FD_SET(i32 0, %struct.TYPE_4__* %7)
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
store i32 3, i32* %14
%15 = call i32 @select(i32 1, %struct.TYPE_4__* %7, i32* null, i32* null, %struct.timeval* %8)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %10
%19 = bitcast [256 x i8]* %9 to i8*
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%21 = load i32, i32* @stdin
%22 = call i32 @fgets(i8* %20, i32 255, i32 %21)
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %27
25: ; preds = %10
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %18
br label %10
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32 }
%struct.timeval = type { i32, i32 }
@stdin = global i32 0
@.str = [10 x i8] c"Lido: %s\0A\00"
@str = [9 x i8] c"Timeout!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.TYPE_4__
%4 = alloca i64
%5 = bitcast i64* %4 to %struct.timeval*
%6 = alloca [256 x i8]
%7 = bitcast %struct.TYPE_4__* %3 to i8*
%8 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0
%9 = bitcast i64* %4 to i8*
%10 = bitcast i64* %4 to i32*
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
br label %12
12: ; preds = %2, %22
store i32 0, i32* %8
store i64 0, i64* %4
%13 = call i32 @FD_SET(i32 0, %struct.TYPE_4__* %3)
store i32 3, i32* %10
%14 = call i32 @select(i32 1, %struct.TYPE_4__* %3, i32* null, i32* null, %struct.timeval* %5)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i32, i32* @stdin
%18 = call i32 @fgets(i8* %11, i32 255, i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %22
20: ; preds = %12
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
br label %12
}