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

/* Variables and functions */
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/,
                  int /*<<< orphan*/, struct timeval *);
int has_more_input(int sock) {
  fd_set set;
  struct timeval tmv = {0};
  FD_ZERO(&set);
  FD_SET(sock, &set);
  return select(sock + 1, &set, 0, 0, &tmv) == 0 && FD_ISSET(sock, &set);
}


x86 assembly (clang, -O0):
<has_more_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
lea    -0x8(%rbp),%rdi
call   1050 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1070 <FD_SET@plt>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
lea    -0x8(%rbp),%rsi
xor    %ecx,%ecx
lea    -0x10(%rbp),%r8
mov    %ecx,%edx
call   1060 <select@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x11(%rbp)
jne    11bf <has_more_input+0x6f>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<has_more_input>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x0,0x8(%rsp)
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),%edi
xor    %ebp,%ebp
lea    0x8(%rsp),%r8
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
test   %rax,%rax
jne    1199 <has_more_input+0x59>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
call   1030 <FD_ISSET@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
define i32 @has_more_input(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.timeval
store i32 %0, i32* %2
%5 = bitcast %struct.timeval* %4 to i8*
%6 = call i32 @FD_ZERO(i32* %3)
%7 = load i32, i32* %2
%8 = call i32 @FD_SET(i32 %7, i32* %3)
%9 = load i32, i32* %2
%10 = add nsw i32 %9, 1
%11 = call i64 @select(i32 %10, i32* %3, i32 0, i32 0, %struct.timeval* %4)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = load i32, i32* %2
%15 = call i64 @FD_ISSET(i32 %14, i32* %3)
%16 = icmp ne i64 %15, 0
br label %17
17: ; preds = %13, %1
%18 = phi i1 [ false, %1 ], [ %16, %13 ]
%19 = zext i1 %18 to i32
ret i32 %19
}

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