#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;
  int revents;
};

/* Variables and functions */
int POLLIN;
int /*<<< orphan*/ poll(struct pollfd *, int, int);
int socketCanRead(int sock) {
  if (sock < 0) {
    return 0;
  }
  struct pollfd PFD;
  PFD.fd = sock;
  PFD.events = POLLIN;
  PFD.revents = 0;
  poll(&PFD, 1, 5);
  if ((PFD.revents & POLLIN) == POLLIN) {
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<socketCanRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1131 <socketCanRead+0x21>
movl   $0x0,-0x4(%rbp)
jmp    118b <socketCanRead+0x7b>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2eaa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
mov    $0x5,%edx
call   1030 <poll@plt>
mov    -0x10(%rbp),%eax
mov    0x2e81(%rip),%rcx
and    (%rcx),%eax
mov    0x2e78(%rip),%rcx
cmp    (%rcx),%eax
jne    1184 <socketCanRead+0x74>
movl   $0x1,-0x4(%rbp)
jmp    118b <socketCanRead+0x7b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socketCanRead>:
test   %edi,%edi
js     1156 <socketCanRead+0x46>
push   %rbx
sub    $0x10,%rsp
mov    %edi,(%rsp)
mov    0x2ec5(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x4(%rsp)
movl   $0x0,0x8(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x5,%edx
call   1030 <poll@plt>
mov    0x8(%rsp),%ecx
not    %ecx
xor    %eax,%eax
and    (%rbx),%ecx
sete   %al
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32 }
@POLLIN = global i32 0
define i32 @socketCanRead(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.pollfd
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 0, i32* %2
br label %23
8: ; preds = %1
%9 = load i32, i32* %3
%10 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* @POLLIN
%12 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 1
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 2
store i32 0, i32* %13
%14 = call i32 @poll(%struct.pollfd* %4, i32 1, i32 5)
%15 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 2
%16 = load i32, i32* %15
%17 = load i32, i32* @POLLIN
%18 = and i32 %16, %17
%19 = load i32, i32* @POLLIN
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %8
store i32 1, i32* %2
br label %23
22: ; preds = %8
store i32 0, i32* %2
br label %23
23: ; preds = %22, %21, %7
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
@POLLIN = global i32 0
define i32 @socketCanRead(i32 %0) {
%2 = alloca %struct.pollfd
%3 = icmp slt i32 %0, 0
br i1 %3, label %16, label %4
4: ; preds = %1
%5 = bitcast %struct.pollfd* %2 to i8*
%6 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i64 0, i32 0
store i32 %0, i32* %6
%7 = load i32, i32* @POLLIN
%8 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i64 0, i32 1
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i64 0, i32 2
store i32 0, i32* %9
%10 = call i32 @poll(%struct.pollfd* %2, i32 1, i32 5)
%11 = load i32, i32* %9
%12 = load i32, i32* @POLLIN
%13 = and i32 %12, %11
%14 = icmp eq i32 %13, %12
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %1, %4
%17 = phi i32 [ %15, %4 ], [ 0, %1 ]
ret i32 %17
}