#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 cr_select(int, unsigned int, int);
int recv(int, char *, int, int /*<<< orphan*/);
int cr_receivedata(int fd, unsigned int msecs, char *buf, int size) {
  int rc = cr_select(fd, msecs, 1);
  if (rc > 0)
    return recv(fd, buf, size, 0);
  else if (rc == 0)
    return -2;
  else
    return -1;
}


x86 assembly (clang, -O0):
<cr_receivedata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x1,%edx
call   1040 <cr_select@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    116b <cr_receivedata+0x4b>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x4(%rbp)
jmp    1188 <cr_receivedata+0x68>
cmpl   $0x0,-0x20(%rbp)
jne    1181 <cr_receivedata+0x61>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1188 <cr_receivedata+0x68>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cr_receivedata>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %edi,%ebp
mov    $0x1,%edx
call   1040 <cr_select@plt>
test   %eax,%eax
jle    114d <cr_receivedata+0x2d>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <recv@plt>
sete   %al
movzbl %al,%eax
not    %eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @cr_receivedata(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = tail call i32 @cr_select(i32 %0, i32 %1, i32 1)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @recv(i32 %0, i8* %2, i32 %3, i32 0)
br label %12
9: ; preds = %4
%10 = icmp eq i32 %5, 0
%11 = select i1 %10, i32 -2, i32 -1
br label %12
12: ; preds = %9, %7
%13 = phi i32 [ %8, %7 ], [ %11, %9 ]
ret i32 %13
}