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

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ textgfx_end();
int inpselect(int n, fd_set *set, struct timeval *tmout) {
  n = select(n, set, NULL, NULL, tmout);
  if (n == -1 && errno != EINTR) {
    textgfx_end();
    perror("Error waiting for input");
    exit(1);
  }
  return n;
}


x86 assembly (clang, -O0):
<inpselect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%r8
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1030 <select@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    11ae <inpselect+0x6e>
mov    0x2e62(%rip),%rax
mov    (%rax),%rax
mov    0x2e50(%rip),%rcx
cmp    (%rcx),%rax
je     11ae <inpselect+0x6e>
mov    $0x0,%al
call   1050 <textgfx_end@plt>
lea    0xe61(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inpselect>:
push   %rax
mov    %rdx,%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <select@plt>
cmp    $0xffffffff,%eax
jne    1168 <inpselect+0x28>
mov    0x2e87(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e75(%rip),%rdx
cmp    (%rdx),%rcx
jne    116a <inpselect+0x2a>
pop    %rcx
ret
xor    %eax,%eax
call   1050 <textgfx_end@plt>
lea    0xe88(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [24 x i8] c"Error waiting for input\00"
define i32 @inpselect(i32 %0, i32* %1, %struct.timeval* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca %struct.timeval*
store i32 %0, i32* %4
store i32* %1, i32** %5
store %struct.timeval* %2, %struct.timeval** %6
%7 = load i32, i32* %4
%8 = load i32*, i32** %5
%9 = load %struct.timeval*, %struct.timeval** %6
%10 = call i32 @select(i32 %7, i32* %8, i32* null, i32* null, %struct.timeval* %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %21
13: ; preds = %3
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINTR
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = call i32 (...) @textgfx_end()
%19 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %13, %3
%22 = load i32, i32* %4
ret i32 %22
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [24 x i8] c"Error waiting for input\00"
define i32 @inpselect(i32 %0, i32* %1, %struct.timeval* %2) {
%4 = tail call i32 @select(i32 %0, i32* %1, i32* null, i32* null, %struct.timeval* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %14
6: ; preds = %3
%7 = load i64, i64* @errno
%8 = load i64, i64* @EINTR
%9 = icmp eq i64 %7, %8
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = tail call i32 (...) @textgfx_end()
%12 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %6, %3
ret i32 %4
}