#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 pollfd {
  int fd;
  int events;
};

/* Variables and functions */
int POLLIN;
int POLLPRI;
int /*<<< orphan*/ perror(char *);
int poll(struct pollfd *, int, int /*<<< orphan*/);
bool isDataReady(int sock) {
  struct pollfd ufds;
  ufds.fd = sock;
  ufds.events = POLLIN | POLLPRI;
  int rv = poll(&ufds, 1, 0);
  if (rv == -1) {
    perror("error in poll??");
    return false;
  } else if (rv == 0) {
    return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<isDataReady>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2ea8(%rip),%rax
mov    (%rax),%eax
mov    0x2eaf(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <poll@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    117b <isDataReady+0x5b>
lea    0xe96(%rip),%rdi
call   1040 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    119d <isDataReady+0x7d>
cmpl   $0x0,-0x14(%rbp)
jne    1191 <isDataReady+0x71>
movl   $0x0,-0x4(%rbp)
jmp    119d <isDataReady+0x7d>
jmp    1196 <isDataReady+0x76>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isDataReady>:
push   %rax
mov    %edi,(%rsp)
mov    0x2eb5(%rip),%rax
mov    0x2ebe(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,0x4(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <poll@plt>
test   %eax,%eax
je     1157 <isDataReady+0x37>
cmp    $0xffffffff,%eax
je     1159 <isDataReady+0x39>
mov    $0x1,%eax
pop    %rcx
ret
lea    0xea0(%rip),%rdi
call   1040 <perror@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32 }
@POLLIN = global i32 0
@POLLPRI = global i32 0
@.str = [16 x i8] c"error in poll??\00"
define i32 @isDataReady(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.pollfd
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 0
store i32 %6, i32* %7
%8 = load i32, i32* @POLLIN
%9 = load i32, i32* @POLLPRI
%10 = or i32 %8, %9
%11 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 1
store i32 %10, i32* %11
%12 = call i32 @poll(%struct.pollfd* %4, i32 1, i32 0)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %23
17: ; preds = %1
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 0, i32* %2
br label %23
21: ; preds = %17
br label %22
22: ; preds = %21
store i32 1, i32* %2
br label %23
23: ; preds = %22, %20, %15
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32 }
@POLLIN = global i32 0
@POLLPRI = global i32 0
@.str = [16 x i8] c"error in poll??\00"
define i32 @isDataReady(i32 %0) {
%2 = alloca %struct.pollfd
%3 = bitcast %struct.pollfd* %2 to i8*
%4 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i64 0, i32 0
store i32 %0, i32* %4
%5 = load i32, i32* @POLLIN
%6 = load i32, i32* @POLLPRI
%7 = or i32 %6, %5
%8 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i64 0, i32 1
store i32 %7, i32* %8
%9 = call i32 @poll(%struct.pollfd* %2, i32 1, i32 0)
switch i32 %9, label %12 [
i32 -1, label %10
i32 0, label %13
]
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %13
12: ; preds = %1
br label %13
13: ; preds = %1, %12, %10
%14 = phi i32 [ 0, %10 ], [ 1, %12 ], [ %9, %1 ]
ret i32 %14
}