#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 */
typedef int uint32_t;
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*/ *);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, struct timeval *);
uint32_t v3timeout(uint32_t sock, uint32_t secs) {
  struct timeval tout;
  fd_set fd_read;
  tout.tv_sec = secs;
  tout.tv_usec = 0;
  FD_ZERO(&fd_read);
  FD_SET(sock, &fd_read);
  if (select(sock + 1, &fd_read, NULL, NULL, &tout) <= 0)
    return (-1);
  return (0);
}


x86 assembly (clang, -O0):
<v3timeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x24(%rbp),%rdi
call   1030 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0x24(%rbp),%rsi
call   1050 <FD_SET@plt>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
lea    -0x24(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1040 <select@plt>
cmp    $0x0,%rax
jg     1191 <v3timeout+0x61>
movl   $0xffffffff,-0x4(%rbp)
jmp    1198 <v3timeout+0x68>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<v3timeout>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
mov    %esi,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1030 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <FD_SET@plt>
add    $0x1,%ebx
lea    0x8(%rsp),%r8
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <select@plt>
xor    %ecx,%ecx
test   %rax,%rax
setle  %cl
neg    %ecx
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define i32 @v3timeout(i32 %0, i32 %1) {
%3 = alloca %struct.timeval
%4 = alloca i32
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
store i32 %1, i32* %7
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
store i64 0, i64* %8
%9 = call i32 @FD_ZERO(i32* %4)
%10 = call i32 @FD_SET(i32 %0, i32* %4)
%11 = add nsw i32 %0, 1
%12 = call i64 @select(i32 %11, i32* %4, i32* null, i32* null, %struct.timeval* %3)
%13 = icmp slt i64 %12, 1
%14 = sext i1 %13 to i32
ret i32 %14
}