#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 /*<<< orphan*/ events;
};

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ POLLIN;
scalar_t__ errno;
int poll(struct pollfd *, int, int);
int pollIn(int sock_num, int timeout) {
  int rc;
  struct pollfd poll_sock;
  poll_sock.fd = sock_num;
  poll_sock.events = POLLIN;
  rc = poll(&poll_sock, 1, timeout);
  if (rc == 1)
    return 0;
  if ((rc == -1 && errno == EINTR) || rc == 0)
    return 1;
  else
    return -1;
}


x86 assembly (clang, -O0):
<pollIn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2ebd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edx
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1030 <poll@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    115a <pollIn+0x4a>
movl   $0x0,-0x4(%rbp)
jmp    119b <pollIn+0x8b>
cmpl   $0xffffffff,-0x10(%rbp)
jne    117e <pollIn+0x6e>
mov    0x2e6d(%rip),%rax
mov    (%rax),%rax
mov    0x2e5b(%rip),%rcx
cmp    (%rcx),%rax
je     1188 <pollIn+0x78>
cmpl   $0x0,-0x10(%rbp)
jne    1194 <pollIn+0x84>
movl   $0x1,-0x4(%rbp)
jmp    119b <pollIn+0x8b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pollIn>:
push   %rax
mov    %esi,%edx
mov    %edi,(%rsp)
mov    0x2ecb(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
call   1030 <poll@plt>
cmp    $0x1,%eax
je     1162 <pollIn+0x52>
test   %eax,%eax
je     1154 <pollIn+0x44>
cmp    $0xffffffff,%eax
jne    115b <pollIn+0x4b>
mov    0x2e93(%rip),%rax
mov    (%rax),%rax
mov    0x2e81(%rip),%rcx
cmp    (%rcx),%rax
jne    115b <pollIn+0x4b>
mov    $0x1,%eax
pop    %rcx
ret
mov    $0xffffffff,%eax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

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

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