#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__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, struct timeval *);
int waitForWrite(int sockFd, struct timeval *timeout) {
  fd_set set;
  FD_ZERO(&set);
  FD_SET(sockFd, &set);
  int maxFd = sockFd + 1;
  select(maxFd, NULL, &set, NULL, timeout);
  if (FD_ISSET(sockFd, &set)) {
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<waitForWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1060 <FD_SET@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%r8
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x14(%rbp),%rdx
mov    %rcx,%rsi
call   1050 <select@plt>
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     11a6 <waitForWrite+0x66>
movl   $0x1,-0x4(%rbp)
jmp    11ad <waitForWrite+0x6d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitForWrite>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xc(%rsp),%r15
mov    %r15,%rdi
call   1040 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1060 <FD_SET@plt>
lea    0x1(%rbx),%edi
xor    %esi,%esi
mov    %r15,%rdx
xor    %ecx,%ecx
mov    %r14,%r8
call   1050 <select@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1030 <FD_ISSET@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32 }
define i32 @waitForWrite(i32 %0, %struct.timeval* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @FD_ZERO(i32* %3)
%6 = call i32 @FD_SET(i32 %0, i32* %3)
%7 = add nsw i32 %0, 1
%8 = call i32 @select(i32 %7, i32* null, i32* %3, i32* null, %struct.timeval* %1)
%9 = call i64 @FD_ISSET(i32 %0, i32* %3)
%10 = icmp ne i64 %9, 0
%11 = zext i1 %10 to i32
ret i32 %11
}