#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 {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
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 *);
int /*<<< orphan*/ write(int, char *, int);
void writeMessage(int fd, char *buf, int buflen) {
  struct timeval zero_timeout;
  fd_set wfds, efds;
  FD_ZERO(&wfds);
  FD_SET(fd, &wfds);
  FD_ZERO(&efds);
  FD_SET(fd, &efds);
  zero_timeout.tv_sec = 0;
  zero_timeout.tv_usec = 0;
  if (select(fd + 1, NULL, &wfds, &efds, &zero_timeout) > 0) {
    write(fd, buf, buflen);
  }
}


x86 assembly (clang, -O0):
<writeMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x2c(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x2c(%rbp),%rsi
call   1060 <FD_SET@plt>
lea    -0x30(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1060 <FD_SET@plt>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x2c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x28(%rbp),%r8
call   1050 <select@plt>
cmp    $0x0,%rax
jle    11c0 <writeMessage+0x80>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeMessage>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %edi,%ebp
lea    0xc(%rsp),%r12
mov    %r12,%rdi
call   1040 <FD_ZERO@plt>
mov    %ebp,%edi
mov    %r12,%rsi
call   1060 <FD_SET@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <FD_ZERO@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <FD_SET@plt>
lea    0x1(%rbp),%edi
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%r8
xor    %esi,%esi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1050 <select@plt>
test   %rax,%rax
jle    11b1 <writeMessage+0x71>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <write@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @writeMessage(i32 %0, i8* nocapture %1, i32 %2) {
%4 = alloca %struct.timeval
%5 = alloca i32
%6 = alloca i32
%7 = bitcast %struct.timeval* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = bitcast i32* %6 to i8*
%10 = call i32 @FD_ZERO(i32* %5)
%11 = call i32 @FD_SET(i32 %0, i32* %5)
%12 = call i32 @FD_ZERO(i32* %6)
%13 = call i32 @FD_SET(i32 %0, i32* %6)
%14 = add nsw i32 %0, 1
%15 = bitcast %struct.timeval* %4 to i8*
%16 = call i64 @select(i32 %14, i32* null, i32* %5, i32* %6, %struct.timeval* %4)
%17 = icmp sgt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = call i32 @write(i32 %0, i8* %1, i32 %2)
br label %20
20: ; preds = %18, %3
ret void
}