#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 POLLPRI;
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ sigio(int);
int do_socket(int sock) {
  struct pollfd plist;
  plist.fd = sock;
  plist.events = POLLIN | POLLPRI;
  while (1) {
    if (poll(&plist, 1, -1) != -1) {
      if ((plist.revents & POLLIN) == POLLIN ||
          (plist.revents & POLLPRI) == POLLPRI) {
        sigio(sock);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<do_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%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
mov    $0xffffffff,%edx
call   1040 <poll@plt>
cmp    $0xffffffff,%eax
je     11a5 <do_socket+0x85>
mov    -0x8(%rbp),%eax
mov    0x2e74(%rip),%rcx
and    (%rcx),%eax
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%eax
je     1198 <do_socket+0x78>
mov    -0x8(%rbp),%eax
mov    0x2e69(%rip),%rcx
and    (%rcx),%eax
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%eax
jne    11a0 <do_socket+0x80>
mov    -0x4(%rbp),%edi
call   1030 <sigio@plt>
jmp    11a5 <do_socket+0x85>
jmp    1146 <do_socket+0x26>

x86 assembly (clang, -O2):
<do_socket>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
mov    %edi,0x8(%rsp)
mov    0x2ea9(%rip),%r14
mov    0x2eb2(%rip),%r15
mov    (%r15),%eax
or     (%r14),%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rbx
jmp    1157 <do_socket+0x37>
nop
mov    %ebp,%edi
call   1030 <sigio@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1040 <poll@plt>
cmp    $0xffffffff,%eax
je     1157 <do_socket+0x37>
mov    0x10(%rsp),%eax
not    %eax
test   %eax,(%r14)
je     1150 <do_socket+0x30>
test   %eax,(%r15)
jne    1157 <do_socket+0x37>
jmp    1150 <do_socket+0x30>

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

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
@POLLIN = global i32 0
@POLLPRI = global i32 0
define i32 @do_socket(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 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i64 0, i32 2
br label %10
10: ; preds = %22, %1
%11 = call i32 @poll(%struct.pollfd* %2, i32 1, i32 -1)
%12 = icmp eq i32 %11, -1
br i1 %12, label %22, label %13
13: ; preds = %10
%14 = load i32, i32* %9
%15 = load i32, i32* @POLLIN
%16 = and i32 %15, %14
%17 = icmp eq i32 %16, %15
br i1 %17, label %23, label %18
18: ; preds = %13
%19 = load i32, i32* @POLLPRI
%20 = and i32 %19, %14
%21 = icmp eq i32 %20, %19
br i1 %21, label %23, label %22
22: ; preds = %18, %23, %10
br label %10
23: ; preds = %18, %13
%24 = call i32 @sigio(i32 %0)
br label %22
}