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

/* Variables and functions */
int POLLIN;
int POLLPRI;
int /*<<< orphan*/ poll(struct pollfd *, int, int /*<<< orphan*/);
char *sk_recv(int, int);
char *srv_poll(int sock, int ssl) {
  struct pollfd sock_p;
  sock_p.fd = sock;
  sock_p.events = POLLIN | POLLPRI;
  sock_p.revents = 0;
  poll(&sock_p, 1, 0);
  if (sock_p.revents) {
    return sk_recv(sock, ssl);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<srv_poll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
mov    0x2eac(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1040 <poll@plt>
cmpq   $0x0,-0x18(%rbp)
je     1180 <srv_poll+0x60>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <sk_recv@plt>
mov    %rax,-0x8(%rbp)
jmp    1188 <srv_poll+0x68>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<srv_poll>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
mov    %edi,(%rsp)
mov    0x2ea9(%rip),%rax
mov    0x2eb2(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,0x4(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rdi
xor    %ebx,%ebx
mov    $0x1,%esi
xor    %edx,%edx
call   1040 <poll@plt>
cmpq   $0x0,0x8(%rsp)
je     1175 <srv_poll+0x55>
mov    %ebp,%edi
mov    %r14d,%esi
call   1030 <sk_recv@plt>
mov    %rax,%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i64 }
@POLLIN = global i32 0
@POLLPRI = global i32 0
define i8* @srv_poll(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 = load i32, i32* @POLLPRI
%8 = or i32 %7, %6
%9 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %3, i64 0, i32 1
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %3, i64 0, i32 2
store i64 0, i64* %10
%11 = call i32 @poll(%struct.pollfd* %3, i32 1, i32 0)
%12 = load i64, i64* %10
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = call i8* @sk_recv(i32 %0, i32 %1)
br label %16
16: ; preds = %2, %14
%17 = phi i8* [ %15, %14 ], [ null, %2 ]
ret i8* %17
}