#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 tms {
  int dummy;
};
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ fd_set;
typedef scalar_t__ clock_t;

/* Variables and functions */
int /*<<< orphan*/ EINTR;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ _SC_CLK_TCK;
char *dump(char *, char *, char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ logIT(int /*<<< orphan*/, char *, ...);
int read(int, char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ setblock(int);
int /*<<< orphan*/ setnonblock(int);
unsigned long sysconf(int /*<<< orphan*/);
scalar_t__ times(struct tms *);
int receive_nb(int fd, char *r_buf, int r_len, unsigned long *etime) {
  int i;
  ssize_t len;
  char string[100];
  fd_set rfds;
  struct timeval tv;
  int retval;
  struct tms tms_t;
  clock_t start, end, mid, mid1;
  unsigned long clktck;
  clktck = sysconf(_SC_CLK_TCK);
  start = times(&tms_t);
  mid1 = start;
  i = 0;
  while (i < r_len) {
    setnonblock(fd);
    FD_ZERO(&rfds);
    FD_SET(fd, &rfds);
    tv.tv_sec = 5;
    tv.tv_usec = 0;
    retval = select(fd + 1, &rfds, NULL, NULL, &tv);
    if (retval == 0) {
      logIT(LOG_ERR, "<RECV: read timeout");
      setblock(fd);
      logIT(LOG_INFO, dump(string, "<RECV: received", r_buf, i));
      return (-1);
    } else if (retval < 0) {
      if (errno == EINTR) {
        logIT(LOG_INFO, "<RECV: select interrupted - redo");
        continue;
      } else {
        logIT(LOG_ERR, "<RECV: select error %d", retval);
        setblock(fd);
        logIT(LOG_INFO, dump(string, "<RECV: received", r_buf, i));
        return (-1);
      }
    } else if (FD_ISSET(fd, &rfds)) {
      len = read(fd, &r_buf[i], r_len - i);
      if (len == 0) {
        logIT(LOG_ERR, "<RECV: read eof");
        setblock(fd);
        logIT(LOG_INFO, dump(string, "<RECV: received", r_buf, i));
        return (-1);
      } else if (len < 0) {
        if (errno == EINTR) {
          logIT(LOG_INFO, "<RECV: read interrupted - redo");
          continue;
        } else {
          logIT(LOG_ERR, "<RECV: read error %d", errno);
          setblock(fd);
          logIT(LOG_INFO, dump(string, "<RECV: received", r_buf, i));
          return (-1);
        }
      } else {
        unsigned char byte = r_buf[i] & 255;
        mid = times(&tms_t);
        logIT(LOG_INFO, "<RECV: len=%zd %02X (%0.1f ms)", len, byte,
              ((float)(mid - mid1) / clktck) * 1000);
        mid1 = mid;
        i += len;
      }
    } else {
      continue;
    }
  }
  end = times(&tms_t);
  *etime = ((float)(end - start) / clktck) * 1000;
  setblock(fd);
  logIT(LOG_INFO, dump(string, "<RECV: received", r_buf, i));
  return i;
}


x86 assembly (clang, -O0):
<receive_nb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   10b0 <sysconf@plt>
mov    %rax,-0xd8(%rbp)
lea    -0xb0(%rbp),%rdi
call   10a0 <times@plt>
mov    %rax,-0xb8(%rbp)
mov    -0xb8(%rbp),%rax
mov    %rax,-0xd0(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1606 <receive_nb+0x456>
mov    -0x8(%rbp),%edi
call   1090 <setnonblock@plt>
lea    -0x94(%rbp),%rdi
call   1070 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0x94(%rbp),%rsi
call   10d0 <FD_SET@plt>
movl   $0x5,-0xa8(%rbp)
movq   $0x0,-0xa0(%rbp)
mov    -0x8(%rbp),%edi
add    $0x1,%edi
lea    -0x94(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0xa8(%rbp),%r8
mov    %rcx,%rdx
call   1080 <select@plt>
mov    %eax,-0xac(%rbp)
cmpl   $0x0,-0xac(%rbp)
jne    12e1 <receive_nb+0x131>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
lea    0xd7b(%rip),%rsi
mov    $0x0,%al
call   10c0 <logIT@plt>
mov    -0x8(%rbp),%edi
call   1030 <setblock@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xe0(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xd5c(%rip),%rsi
call   1050 <dump@plt>
mov    -0xe0(%rbp),%edi
mov    %rax,%rsi
mov    $0x0,%al
call   10c0 <logIT@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1717 <receive_nb+0x567>
cmpl   $0x0,-0xac(%rbp)
jge    138c <receive_nb+0x1dc>
mov    0x2ce3(%rip),%rax
mov    (%rax),%eax
mov    0x2cd2(%rip),%rcx
cmp    (%rcx),%eax
jne    1322 <receive_nb+0x172>
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
lea    0xd16(%rip),%rsi
mov    $0x0,%al
call   10c0 <logIT@plt>
jmp    1206 <receive_nb+0x56>
mov    0x2c8f(%rip),%rax
mov    (%rax),%edi
mov    -0xac(%rbp),%edx
lea    0xd15(%rip),%rsi
mov    $0x0,%al
call   10c0 <logIT@plt>
mov    -0x8(%rbp),%edi
call   1030 <setblock@plt>
mov    0x2c7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xe4(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xcb1(%rip),%rsi
call   1050 <dump@plt>
mov    -0xe4(%rbp),%edi
mov    %rax,%rsi
mov    $0x0,%al
call   10c0 <logIT@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1717 <receive_nb+0x567>
mov    -0x8(%rbp),%edi
lea    -0x94(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     15f2 <receive_nb+0x442>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
sub    -0x24(%rbp),%edx
call   1060 <read@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    142f <receive_nb+0x27f>
mov    0x2be6(%rip),%rax
mov    (%rax),%edi
lea    0xc89(%rip),%rsi
mov    $0x0,%al
call   10c0 <logIT@plt>
mov    -0x8(%rbp),%edi
call   1030 <setblock@plt>
mov    0x2bd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xe8(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xc0e(%rip),%rsi
call   1050 <dump@plt>
mov    -0xe8(%rbp),%edi
mov    %rax,%rsi
mov    $0x0,%al
call   10c0 <logIT@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1717 <receive_nb+0x567>
cmpl   $0x0,-0x28(%rbp)
jge    14da <receive_nb+0x32a>
mov    0x2b98(%rip),%rax
mov    (%rax),%eax
mov    0x2b87(%rip),%rcx
cmp    (%rcx),%eax
jne    146d <receive_nb+0x2bd>
mov    0x2b70(%rip),%rax
mov    (%rax),%edi
lea    0xc13(%rip),%rsi
mov    $0x0,%al
call   10c0 <logIT@plt>
jmp    1206 <receive_nb+0x56>
mov    0x2b44(%rip),%rax
mov    (%rax),%edi
mov    0x2b5b(%rip),%rax
mov    (%rax),%edx
lea    0xc0d(%rip),%rsi
mov    $0x0,%al
call   10c0 <logIT@plt>
mov    -0x8(%rbp),%edi
call   1030 <setblock@plt>
mov    0x2b2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xec(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xb63(%rip),%rsi
call   1050 <dump@plt>
mov    -0xec(%rbp),%edi
mov    %rax,%rsi
mov    $0x0,%al
call   10c0 <logIT@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1717 <receive_nb+0x567>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0xd9(%rbp)
lea    -0xb0(%rbp),%rdi
call   10a0 <times@plt>
mov    %rax,-0xc8(%rbp)
mov    0x2ac3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x104(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x100(%rbp)
movzbl -0xd9(%rbp),%eax
mov    %eax,-0xfc(%rbp)
mov    -0xc8(%rbp),%rax
mov    -0xd0(%rbp),%rcx
sub    %rcx,%rax
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0xf8(%rbp)
ff
mov    -0xd8(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0xf4(%rbp)
ff
test   %rax,%rax
movss  %xmm0,-0xf0(%rbp)
ff
js     158d <receive_nb+0x3dd>
movss  -0xf4(%rbp),%xmm0
ff
movss  %xmm0,-0xf0(%rbp)
ff
mov    -0xfc(%rbp),%ecx
mov    -0x100(%rbp),%edx
mov    -0x104(%rbp),%edi
movss  -0xf8(%rbp),%xmm0
ff
movss  -0xf0(%rbp),%xmm1
ff
divss  %xmm1,%xmm0
movss  0xa45(%rip),%xmm1
mulss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xade(%rip),%rsi
mov    $0x1,%al
call   10c0 <logIT@plt>
mov    -0xc8(%rbp),%rax
mov    %rax,-0xd0(%rbp)
mov    -0x28(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    15ed <receive_nb+0x43d>
jmp    15f7 <receive_nb+0x447>
jmp    1206 <receive_nb+0x56>
jmp    15fc <receive_nb+0x44c>
jmp    1601 <receive_nb+0x451>
jmp    1206 <receive_nb+0x56>
lea    -0xb0(%rbp),%rdi
call   10a0 <times@plt>
mov    %rax,-0xc0(%rbp)
mov    -0xc0(%rbp),%rax
mov    -0xb8(%rbp),%rcx
sub    %rcx,%rax
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x110(%rbp)
ff
mov    -0xd8(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x10c(%rbp)
ff
test   %rax,%rax
movss  %xmm0,-0x108(%rbp)
ff
js     1683 <receive_nb+0x4d3>
movss  -0x10c(%rbp),%xmm0
ff
movss  %xmm0,-0x108(%rbp)
ff
movss  -0x110(%rbp),%xmm0
ff
movss  -0x108(%rbp),%xmm1
ff
divss  %xmm1,%xmm0
movss  0x961(%rip),%xmm1
mulss  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttss2si %xmm1,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
movss  0x94a(%rip),%xmm1
subss  %xmm1,%xmm0
cvttss2si %xmm0,%rax
and    %rdx,%rax
or     %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%edi
call   1030 <setblock@plt>
mov    0x28e9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x114(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0x920(%rip),%rsi
call   1050 <dump@plt>
mov    -0x114(%rbp),%edi
mov    %rax,%rsi
mov    $0x0,%al
call   10c0 <logIT@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receive_nb>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%r12
mov    %edi,%ebx
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   10b0 <sysconf@plt>
mov    %rax,%rbp
lea    0x10(%rsp),%rdi
call   10a0 <times@plt>
mov    %rax,%r13
mov    %r15d,0x14(%rsp)
test   %r15d,%r15d
jle    1205 <receive_nb+0x55>
test   %rbp,%rbp
mov    %r14,0x28(%rsp)
js     1218 <receive_nb+0x68>
cvtsi2ss %rbp,%xmm0
jmp    122d <receive_nb+0x7d>
test   %rbp,%rbp
js     13bc <receive_nb+0x20c>
cvtsi2ss %rbp,%xmm0
jmp    13d1 <receive_nb+0x221>
mov    %rbp,%rax
shr    %rax
and    $0x1,%ebp
or     %rax,%rbp
cvtsi2ss %rbp,%xmm0
addss  %xmm0,%xmm0
movss  %xmm0,0x4(%rsp)
lea    0x1(%rbx),%r15d
lea    0x4c(%rsp),%r14
xor    %ebp,%ebp
mov    %r13,0x20(%rsp)
mov    %r12,0x8(%rsp)
mov    %r13,0x30(%rsp)
mov    %ebp,(%rsp)
movslq %ebp,%rax
lea    (%r12,%rax,1),%rcx
mov    %rcx,0x18(%rsp)
mov    0x14(%rsp),%r13d
sub    %eax,%r13d
lea    0x38(%rsp),%rbp
jmp    129f <receive_nb+0xef>
nopl   0x0(%rax,%rax,1)
mov    0x2d61(%rip),%rcx
mov    (%rcx),%ecx
lea    0xdac(%rip),%rsi
mov    0x2d49(%rip),%rdx
cmp    (%rdx),%ecx
jne    143c <receive_nb+0x28c>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
call   10c0 <logIT@plt>
mov    %ebx,%edi
call   1090 <setnonblock@plt>
mov    %r14,%rdi
call   1070 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   10d0 <FD_SET@plt>
movl   $0x5,0x38(%rsp)
movq   $0x0,0x40(%rsp)
mov    %r15d,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %rbp,%r8
call   1080 <select@plt>
test   %eax,%eax
je     13aa <receive_nb+0x1fa>
js     1270 <receive_nb+0xc0>
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     129f <receive_nb+0xef>
mov    %ebx,%edi
mov    0x18(%rsp),%rsi
mov    %r13d,%edx
call   1060 <read@plt>
test   %eax,%eax
je     1423 <receive_nb+0x273>
jns    1336 <receive_nb+0x186>
mov    0x2cc4(%rip),%rax
mov    (%rax),%edx
lea    0xd57(%rip),%rsi
mov    0x2cac(%rip),%rax
cmp    (%rax),%edx
lea    0x38(%rsp),%rbp
je     128f <receive_nb+0xdf>
jmp    1450 <receive_nb+0x2a0>
mov    %eax,%r12d
mov    0x18(%rsp),%rax
movzbl (%rax),%ebp
lea    0x10(%rsp),%rdi
call   10a0 <times@plt>
mov    %rax,%r13
sub    0x30(%rsp),%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
mov    0x2c66(%rip),%rax
mov    (%rax),%edi
divss  0x4(%rsp),%xmm0
mulss  0xc8e(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd2b(%rip),%rsi
mov    %r12d,%edx
mov    %ebp,%ecx
mov    $0x1,%al
call   10c0 <logIT@plt>
mov    (%rsp),%ebp
add    %r12d,%ebp
cmp    0x14(%rsp),%ebp
mov    0x8(%rsp),%r12
jl     1248 <receive_nb+0x98>
mov    0x28(%rsp),%r14
mov    0x20(%rsp),%r13
jmp    13d9 <receive_nb+0x229>
mov    0x2c07(%rip),%rax
mov    (%rax),%edi
lea    0xc4e(%rip),%rsi
jmp    1433 <receive_nb+0x283>
mov    %rbp,%rax
shr    %rax
and    $0x1,%ebp
or     %rax,%rbp
cvtsi2ss %rbp,%xmm0
addss  %xmm0,%xmm0
movss  %xmm0,0x4(%rsp)
xor    %ebp,%ebp
lea    0x10(%rsp),%rdi
call   10a0 <times@plt>
sub    %r13,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
divss  0x4(%rsp),%xmm0
mulss  0xc04(%rip),%xmm0
cvttss2si %xmm0,%rax
mov    %rax,%rcx
subss  0xbf8(%rip),%xmm0
cvttss2si %xmm0,%rdx
sar    $0x3f,%rcx
and    %rcx,%rdx
or     %rax,%rdx
mov    %rdx,(%r14)
mov    %ebp,%r14d
jmp    1475 <receive_nb+0x2c5>
mov    0x2b8e(%rip),%rax
mov    (%rax),%edi
lea    0xc31(%rip),%rsi
xor    %eax,%eax
call   10c0 <logIT@plt>
jmp    1467 <receive_nb+0x2b7>
mov    0x2b75(%rip),%rcx
mov    (%rcx),%edi
lea    0xc01(%rip),%rsi
mov    %eax,%edx
jmp    1460 <receive_nb+0x2b0>
mov    0x2b61(%rip),%rax
mov    (%rax),%edi
lea    0xc33(%rip),%rsi
xor    %eax,%eax
call   10c0 <logIT@plt>
mov    $0xffffffff,%r14d
mov    0x8(%rsp),%r12
mov    (%rsp),%ebp
mov    %ebx,%edi
call   1030 <setblock@plt>
mov    0x2b45(%rip),%rax
mov    (%rax),%ebx
lea    0xb90(%rip),%rsi
lea    0x50(%rsp),%rdi
mov    %r12,%rdx
mov    %ebp,%ecx
call   1050 <dump@plt>
mov    %ebx,%edi
mov    %rax,%rsi
xor    %eax,%eax
call   10c0 <logIT@plt>
mov    %r14d,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
%struct.tms = type { i32 }
@_SC_CLK_TCK = global i32 0
@LOG_ERR = global i32 0
@.str = [20 x i8] c"<RECV: read timeout\00"
@LOG_INFO = global i32 0
@.str.1 = [16 x i8] c"<RECV: received\00"
@errno = global i32 0
@EINTR = global i32 0
@.str.2 = [33 x i8] c"<RECV: select interrupted - redo\00"
@.str.3 = [23 x i8] c"<RECV: select error %d\00"
@.str.4 = [16 x i8] c"<RECV: read eof\00"
@.str.5 = [31 x i8] c"<RECV: read interrupted - redo\00"
@.str.6 = [21 x i8] c"<RECV: read error %d\00"
@.str.7 = [31 x i8] c"<RECV: len=%zd %02X (%0.1f ms)\00"
define i32 @receive_nb(i32 %0, i8* %1, i32 %2, i64* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64*
%10 = alloca i32
%11 = alloca i32
%12 = alloca [100 x i8]
%13 = alloca i32
%14 = alloca %struct.timeval
%15 = alloca i32
%16 = alloca %struct.tms
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64
%20 = alloca i64
%21 = alloca i64
%22 = alloca i8
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i64* %3, i64** %9
%23 = load i32, i32* @_SC_CLK_TCK
%24 = call i64 @sysconf(i32 %23)
store i64 %24, i64* %21
%25 = call i64 @times(%struct.tms* %16)
store i64 %25, i64* %17
%26 = load i64, i64* %17
store i64 %26, i64* %20
store i32 0, i32* %10
br label %27
27: ; preds = %159, %156, %111, %62, %4
%28 = load i32, i32* %10
%29 = load i32, i32* %8
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %160
31: ; preds = %27
%32 = load i32, i32* %6
%33 = call i32 @setnonblock(i32 %32)
%34 = call i32 @FD_ZERO(i32* %13)
%35 = load i32, i32* %6
%36 = call i32 @FD_SET(i32 %35, i32* %13)
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
store i32 5, i32* %37
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
store i64 0, i64* %38
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
%41 = call i32 @select(i32 %40, i32* %13, i32* null, i32* null, %struct.timeval* %14)
store i32 %41, i32* %15
%42 = load i32, i32* %15
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %55
44: ; preds = %31
%45 = load i32, i32* @LOG_ERR
%46 = call i32 (i32, i8*, ...) @logIT(i32 %45, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%47 = load i32, i32* %6
%48 = call i32 @setblock(i32 %47)
%49 = load i32, i32* @LOG_INFO
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%51 = load i8*, i8** %7
%52 = load i32, i32* %10
%53 = call i8* @dump(i8* %50, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %51, i32 %52)
%54 = call i32 (i32, i8*, ...) @logIT(i32 %49, i8* %53)
store i32 -1, i32* %5
br label %181
55: ; preds = %31
%56 = load i32, i32* %15
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %77
58: ; preds = %55
%59 = load i32, i32* @errno
%60 = load i32, i32* @EINTR
%61 = icmp eq i32 %59, %60
br i1 %61, label %62, label %65
62: ; preds = %58
%63 = load i32, i32* @LOG_INFO
%64 = call i32 (i32, i8*, ...) @logIT(i32 %63, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %27
65: ; preds = %58
%66 = load i32, i32* @LOG_ERR
%67 = load i32, i32* %15
%68 = call i32 (i32, i8*, ...) @logIT(i32 %66, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %67)
%69 = load i32, i32* %6
%70 = call i32 @setblock(i32 %69)
%71 = load i32, i32* @LOG_INFO
%72 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%73 = load i8*, i8** %7
%74 = load i32, i32* %10
%75 = call i8* @dump(i8* %72, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %73, i32 %74)
%76 = call i32 (i32, i8*, ...) @logIT(i32 %71, i8* %75)
store i32 -1, i32* %5
br label %181
77: ; preds = %55
%78 = load i32, i32* %6
%79 = call i64 @FD_ISSET(i32 %78, i32* %13)
%80 = icmp ne i64 %79, 0
br i1 %80, label %81, label %156
81: ; preds = %77
%82 = load i32, i32* %6
%83 = load i8*, i8** %7
%84 = load i32, i32* %10
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %83, i64 %85
%87 = load i32, i32* %8
%88 = load i32, i32* %10
%89 = sub nsw i32 %87, %88
%90 = call i32 @read(i32 %82, i8* %86, i32 %89)
store i32 %90, i32* %11
%91 = load i32, i32* %11
%92 = icmp eq i32 %91, 0
br i1 %92, label %93, label %104
93: ; preds = %81
%94 = load i32, i32* @LOG_ERR
%95 = call i32 (i32, i8*, ...) @logIT(i32 %94, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%96 = load i32, i32* %6
%97 = call i32 @setblock(i32 %96)
%98 = load i32, i32* @LOG_INFO
%99 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%100 = load i8*, i8** %7
%101 = load i32, i32* %10
%102 = call i8* @dump(i8* %99, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %100, i32 %101)
%103 = call i32 (i32, i8*, ...) @logIT(i32 %98, i8* %102)
store i32 -1, i32* %5
br label %181
104: ; preds = %81
%105 = load i32, i32* %11
%106 = icmp slt i32 %105, 0
br i1 %106, label %107, label %126
107: ; preds = %104
%108 = load i32, i32* @errno
%109 = load i32, i32* @EINTR
%110 = icmp eq i32 %108, %109
br i1 %110, label %111, label %114
111: ; preds = %107
%112 = load i32, i32* @LOG_INFO
%113 = call i32 (i32, i8*, ...) @logIT(i32 %112, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
br label %27
114: ; preds = %107
%115 = load i32, i32* @LOG_ERR
%116 = load i32, i32* @errno
%117 = call i32 (i32, i8*, ...) @logIT(i32 %115, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %116)
%118 = load i32, i32* %6
%119 = call i32 @setblock(i32 %118)
%120 = load i32, i32* @LOG_INFO
%121 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%122 = load i8*, i8** %7
%123 = load i32, i32* %10
%124 = call i8* @dump(i8* %121, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %122, i32 %123)
%125 = call i32 (i32, i8*, ...) @logIT(i32 %120, i8* %124)
store i32 -1, i32* %5
br label %181
126: ; preds = %104
%127 = load i8*, i8** %7
%128 = load i32, i32* %10
%129 = sext i32 %128 to i64
%130 = getelementptr inbounds i8, i8* %127, i64 %129
%131 = load i8, i8* %130
%132 = sext i8 %131 to i32
%133 = and i32 %132, 255
%134 = trunc i32 %133 to i8
store i8 %134, i8* %22
%135 = call i64 @times(%struct.tms* %16)
store i64 %135, i64* %19
%136 = load i32, i32* @LOG_INFO
%137 = load i32, i32* %11
%138 = load i8, i8* %22
%139 = zext i8 %138 to i32
%140 = load i64, i64* %19
%141 = load i64, i64* %20
%142 = sub nsw i64 %140, %141
%143 = sitofp i64 %142 to float
%144 = load i64, i64* %21
%145 = uitofp i64 %144 to float
%146 = fdiv float %143, %145
%147 = fmul float %146, 1.000000e+03
%148 = fpext float %147 to double
%149 = call i32 (i32, i8*, ...) @logIT(i32 %136, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %137, i32 %139, double %148)
%150 = load i64, i64* %19
store i64 %150, i64* %20
%151 = load i32, i32* %11
%152 = load i32, i32* %10
%153 = add nsw i32 %152, %151
store i32 %153, i32* %10
br label %154
154: ; preds = %126
br label %155
155: ; preds = %154
br label %157
156: ; preds = %77
br label %27
157: ; preds = %155
br label %158
158: ; preds = %157
br label %159
159: ; preds = %158
br label %27
160: ; preds = %27
%161 = call i64 @times(%struct.tms* %16)
store i64 %161, i64* %18
%162 = load i64, i64* %18
%163 = load i64, i64* %17
%164 = sub nsw i64 %162, %163
%165 = sitofp i64 %164 to float
%166 = load i64, i64* %21
%167 = uitofp i64 %166 to float
%168 = fdiv float %165, %167
%169 = fmul float %168, 1.000000e+03
%170 = fptoui float %169 to i64
%171 = load i64*, i64** %9
store i64 %170, i64* %171
%172 = load i32, i32* %6
%173 = call i32 @setblock(i32 %172)
%174 = load i32, i32* @LOG_INFO
%175 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%176 = load i8*, i8** %7
%177 = load i32, i32* %10
%178 = call i8* @dump(i8* %175, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %176, i32 %177)
%179 = call i32 (i32, i8*, ...) @logIT(i32 %174, i8* %178)
%180 = load i32, i32* %10
store i32 %180, i32* %5
br label %181
181: ; preds = %160, %114, %93, %65, %44
%182 = load i32, i32* %5
ret i32 %182
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
%struct.tms = type { i32 }
@_SC_CLK_TCK = global i32 0
@LOG_ERR = global i32 0
@.str = [20 x i8] c"<RECV: read timeout\00"
@LOG_INFO = global i32 0
@.str.1 = [16 x i8] c"<RECV: received\00"
@errno = global i32 0
@EINTR = global i32 0
@.str.2 = [33 x i8] c"<RECV: select interrupted - redo\00"
@.str.3 = [23 x i8] c"<RECV: select error %d\00"
@.str.4 = [16 x i8] c"<RECV: read eof\00"
@.str.5 = [31 x i8] c"<RECV: read interrupted - redo\00"
@.str.6 = [21 x i8] c"<RECV: read error %d\00"
@.str.7 = [31 x i8] c"<RECV: len=%zd %02X (%0.1f ms)\00"
define i32 @receive_nb(i32 %0, i8* %1, i32 %2, i64* nocapture writeonly %3) {
%5 = alloca [100 x i8]
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = alloca %struct.tms
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%10 = bitcast i32* %6 to i8*
%11 = bitcast %struct.timeval* %7 to i8*
%12 = bitcast %struct.tms* %8 to i8*
%13 = load i32, i32* @_SC_CLK_TCK
%14 = tail call i64 @sysconf(i32 %13)
%15 = call i64 @times(%struct.tms* %8)
%16 = icmp sgt i32 %2, 0
br i1 %16, label %19, label %17
17: ; preds = %4
%18 = uitofp i64 %14 to float
br label %84
19: ; preds = %4
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
%22 = add nsw i32 %0, 1
%23 = uitofp i64 %14 to float
br label %24
24: ; preds = %19, %71
%25 = phi i32 [ 0, %19 ], [ %82, %71 ]
%26 = phi i64 [ %15, %19 ], [ %73, %71 ]
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds i8, i8* %1, i64 %27
%29 = sub nsw i32 %2, %25
br label %30
30: ; preds = %49, %24
%31 = call i32 @setnonblock(i32 %0)
%32 = call i32 @FD_ZERO(i32* %6)
%33 = call i32 @FD_SET(i32 %0, i32* %6)
store i32 5, i32* %20
store i64 0, i64* %21
%34 = call i32 @select(i32 %22, i32* %6, i32* null, i32* null, %struct.timeval* %7)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %30
%37 = load i32, i32* @LOG_ERR
%38 = call i32 (i32, i8*, ...) @logIT(i32 %37, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %93
39: ; preds = %30
%40 = icmp slt i32 %34, 0
br i1 %40, label %41, label %53
41: ; preds = %39
%42 = load i32, i32* @errno
%43 = load i32, i32* @EINTR
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %50
45: ; preds = %41, %64
%46 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), %64 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), %41 ]
%47 = load i32, i32* @LOG_INFO
%48 = call i32 (i32, i8*, ...) @logIT(i32 %47, i8* %46)
br label %49
49: ; preds = %45, %53
br label %30
50: ; preds = %41
%51 = load i32, i32* @LOG_ERR
%52 = call i32 (i32, i8*, ...) @logIT(i32 %51, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %34)
br label %93
53: ; preds = %39
%54 = call i64 @FD_ISSET(i32 %0, i32* %6)
%55 = icmp eq i64 %54, 0
br i1 %55, label %49, label %56
56: ; preds = %53
%57 = call i32 @read(i32 %0, i8* %28, i32 %29)
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i32, i32* @LOG_ERR
%61 = call i32 (i32, i8*, ...) @logIT(i32 %60, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %93
62: ; preds = %56
%63 = icmp slt i32 %57, 0
br i1 %63, label %64, label %71
64: ; preds = %62
%65 = load i32, i32* @errno
%66 = load i32, i32* @EINTR
%67 = icmp eq i32 %65, %66
br i1 %67, label %45, label %68
68: ; preds = %64
%69 = load i32, i32* @LOG_ERR
%70 = call i32 (i32, i8*, ...) @logIT(i32 %69, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %65)
br label %93
71: ; preds = %62
%72 = load i8, i8* %28
%73 = call i64 @times(%struct.tms* %8)
%74 = load i32, i32* @LOG_INFO
%75 = zext i8 %72 to i32
%76 = sub nsw i64 %73, %26
%77 = sitofp i64 %76 to float
%78 = fdiv float %77, %23
%79 = fmul float %78, 1.000000e+03
%80 = fpext float %79 to double
%81 = call i32 (i32, i8*, ...) @logIT(i32 %74, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %57, i32 %75, double %80)
%82 = add nsw i32 %57, %25
%83 = icmp slt i32 %82, %2
br i1 %83, label %24, label %84
84: ; preds = %71, %17
%85 = phi float [ %18, %17 ], [ %23, %71 ]
%86 = phi i32 [ 0, %17 ], [ %82, %71 ]
%87 = call i64 @times(%struct.tms* %8)
%88 = sub nsw i64 %87, %15
%89 = sitofp i64 %88 to float
%90 = fdiv float %89, %85
%91 = fmul float %90, 1.000000e+03
%92 = fptoui float %91 to i64
store i64 %92, i64* %3
br label %93
93: ; preds = %84, %68, %59, %50, %36
%94 = phi i32 [ %86, %84 ], [ %25, %68 ], [ %25, %59 ], [ %25, %50 ], [ %25, %36 ]
%95 = phi i32 [ %86, %84 ], [ -1, %68 ], [ -1, %59 ], [ -1, %50 ], [ -1, %36 ]
%96 = call i32 @setblock(i32 %0)
%97 = load i32, i32* @LOG_INFO
%98 = call i8* @dump(i8* %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %94)
%99 = call i32 (i32, i8*, ...) @logIT(i32 %97, i8* %98)
ret i32 %95
}