#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 */

/* Variables and functions */
int read(int, char *, int);
int tcpSelect(int, int /*<<< orphan*/, int);
int tcpRecv(int fd, char *buffer, int size, int timeout) {
  int ret;
  ret = tcpSelect(fd, 0, timeout);
  if (ret == (-1))
    return -2;
  if (ret == 0)
    return -3;
  ret = read(fd, buffer, size);
  if (ret < 0) {
    return -4;
  }
  return ret;
}


x86 assembly (clang, -O0):
<tcpRecv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%edx
xor    %esi,%esi
call   1040 <tcpSelect@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    115b <tcpRecv+0x3b>
movl   $0xfffffffe,-0x4(%rbp)
jmp    119f <tcpRecv+0x7f>
cmpl   $0x0,-0x1c(%rbp)
jne    1171 <tcpRecv+0x51>
movl   $0xfffffffd,-0x4(%rbp)
jmp    119f <tcpRecv+0x7f>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1199 <tcpRecv+0x79>
movl   $0xfffffffc,-0x4(%rbp)
jmp    119f <tcpRecv+0x7f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcpRecv>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %esi,%esi
mov    %ecx,%edx
call   1040 <tcpSelect@plt>
cmp    $0xffffffff,%eax
je     1145 <tcpRecv+0x25>
test   %eax,%eax
jne    114c <tcpRecv+0x2c>
mov    $0xfffffffd,%eax
jmp    1165 <tcpRecv+0x45>
mov    $0xfffffffe,%eax
jmp    1165 <tcpRecv+0x45>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <read@plt>
mov    %eax,%ecx
test   %eax,%eax
mov    $0xfffffffc,%eax
cmovns %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @tcpRecv(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load i32, i32* %6
%12 = load i32, i32* %9
%13 = call i32 @tcpSelect(i32 %11, i32 0, i32 %12)
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 -2, i32* %5
br label %31
17: ; preds = %4
%18 = load i32, i32* %10
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 -3, i32* %5
br label %31
21: ; preds = %17
%22 = load i32, i32* %6
%23 = load i8*, i8** %7
%24 = load i32, i32* %8
%25 = call i32 @read(i32 %22, i8* %23, i32 %24)
store i32 %25, i32* %10
%26 = load i32, i32* %10
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %21
store i32 -4, i32* %5
br label %31
29: ; preds = %21
%30 = load i32, i32* %10
store i32 %30, i32* %5
br label %31
31: ; preds = %29, %28, %20, %16
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
define i32 @tcpRecv(i32 %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = tail call i32 @tcpSelect(i32 %0, i32 0, i32 %3)
switch i32 %5, label %7 [
i32 -1, label %11
i32 0, label %6
]
6: ; preds = %4
br label %11
7: ; preds = %4
%8 = tail call i32 @read(i32 %0, i8* %1, i32 %2)
%9 = icmp slt i32 %8, 0
%10 = select i1 %9, i32 -4, i32 %8
br label %11
11: ; preds = %7, %4, %6
%12 = phi i32 [ -3, %6 ], [ -2, %4 ], [ %10, %7 ]
ret i32 %12
}