#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;
  scalar_t__ revents;
  void *events;
};
typedef int /*<<< orphan*/ pollfd;

/* Variables and functions */
scalar_t__ EINTR;
void *POLLIN;
scalar_t__ errno;
int /*<<< orphan*/ error(int, scalar_t__, char *);
int /*<<< orphan*/ memset(struct pollfd **, int /*<<< orphan*/, int);
int poll(struct pollfd *, int, int);
int nflog_wait(int fd) {
  struct pollfd pollfd[2];
  int len;
  do {
    memset(&pollfd, 0, sizeof(pollfd));
    pollfd[0].events = POLLIN;
    pollfd[0].fd = 0;
    pollfd[1].events = POLLIN;
    pollfd[1].fd = fd;
    len = poll(pollfd, 2, 50);
    if (len == -1) {
      if (errno == EINTR)
        continue;
      error(1, errno, "poll");
    }
    if (len && pollfd[0].revents)
      return 0;
  } while (!len);
  return 1;
}


x86 assembly (clang, -O0):
<nflog_wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
mov    0x2e96(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x40(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x2,%esi
mov    $0x32,%edx
call   1040 <poll@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    11ce <nflog_wait+0x9e>
mov    0x2e3d(%rip),%rax
mov    (%rax),%rax
mov    0x2e2b(%rip),%rcx
cmp    (%rcx),%rax
jne    11b3 <nflog_wait+0x83>
jmp    11f4 <nflog_wait+0xc4>
mov    0x2e1e(%rip),%rax
mov    (%rax),%rsi
mov    $0x1,%edi
lea    0xe37(%rip),%rdx
call   1050 <error@plt>
cmpl   $0x0,-0x44(%rbp)
je     11ef <nflog_wait+0xbf>
cmpq   $0x0,-0x38(%rbp)
je     11ef <nflog_wait+0xbf>
movl   $0x0,-0x4(%rbp)
jmp    120c <nflog_wait+0xdc>
jmp    11f4 <nflog_wait+0xc4>
cmpl   $0x0,-0x44(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    113b <nflog_wait+0xb>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nflog_wait>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
mov    0x2ea3(%rip),%r15
jmp    1154 <nflog_wait+0x24>
nopw   0x0(%rax,%rax,1)
test   %eax,%eax
jne    11a2 <nflog_wait+0x72>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
mov    (%r15),%rax
mov    %rax,0x10(%rsp)
movl   $0x0,(%rsp)
mov    %rax,0x28(%rsp)
mov    %ebx,0x18(%rsp)
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x32,%edx
call   1040 <poll@plt>
cmp    $0xffffffff,%eax
je     11a9 <nflog_wait+0x79>
test   %eax,%eax
je     1150 <nflog_wait+0x20>
cmpq   $0x0,0x8(%rsp)
je     1150 <nflog_wait+0x20>
xor    %eax,%eax
jmp    11e0 <nflog_wait+0xb0>
mov    $0x1,%eax
jmp    11e0 <nflog_wait+0xb0>
mov    0x2e28(%rip),%rax
mov    (%rax),%rsi
mov    0x2e16(%rip),%rcx
mov    $0x1,%eax
cmp    (%rcx),%rsi
je     11e0 <nflog_wait+0xb0>
lea    0xe35(%rip),%rdx
mov    $0x1,%edi
call   1050 <error@plt>
xor    %eax,%eax
cmpq   $0x0,0x8(%rsp)
sete   %al
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i64, i8* }
@POLLIN = global i8* null
@errno = global i64 0
@EINTR = global i64 0
@.str = [5 x i8] c"poll\00"
define i32 @nflog_wait(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x %struct.pollfd]
%5 = alloca i32
store i32 %0, i32* %3
br label %6
6: ; preds = %42, %1
%7 = bitcast [2 x %struct.pollfd]* %4 to %struct.pollfd**
%8 = call i32 @memset(%struct.pollfd** %7, i32 0, i32 48)
%9 = load i8*, i8** @POLLIN
%10 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0
%11 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %10, i32 0, i32 2
store i8* %9, i8** %11
%12 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0
%13 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %12, i32 0, i32 0
store i32 0, i32* %13
%14 = load i8*, i8** @POLLIN
%15 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1
%16 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %15, i32 0, i32 2
store i8* %14, i8** %16
%17 = load i32, i32* %3
%18 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1
%19 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %18, i32 0, i32 0
store i32 %17, i32* %19
%20 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0
%21 = call i32 @poll(%struct.pollfd* %20, i32 2, i32 50)
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %32
24: ; preds = %6
%25 = load i64, i64* @errno
%26 = load i64, i64* @EINTR
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24
br label %42
29: ; preds = %24
%30 = load i64, i64* @errno
%31 = call i32 @error(i32 1, i64 %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %29, %6
%33 = load i32, i32* %5
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %32
%36 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0
%37 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %36, i32 0, i32 1
%38 = load i64, i64* %37
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %35
store i32 0, i32* %2
br label %47
41: ; preds = %35, %32
br label %42
42: ; preds = %41, %28
%43 = load i32, i32* %5
%44 = icmp ne i32 %43, 0
%45 = xor i1 %44, true
br i1 %45, label %6, label %46
46: ; preds = %42
store i32 1, i32* %2
br label %47
47: ; preds = %46, %40
%48 = load i32, i32* %2
ret i32 %48
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i64, i8* }
@POLLIN = global i8* null
@errno = global i64 0
@EINTR = global i64 0
@.str = [5 x i8] c"poll\00"
define i32 @nflog_wait(i32 %0) {
%2 = alloca [2 x %struct.pollfd]
%3 = bitcast [2 x %struct.pollfd]* %2 to i8*
%4 = bitcast [2 x %struct.pollfd]* %2 to %struct.pollfd**
%5 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %2, i64 0, i64 0
%6 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %2, i64 0, i64 0, i32 2
%7 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %2, i64 0, i64 0, i32 0
%8 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %2, i64 0, i64 1, i32 2
%9 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %2, i64 0, i64 1, i32 0
%10 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %2, i64 0, i64 0, i32 1
br label %11
11: ; preds = %30, %1
%12 = call i32 @memset(%struct.pollfd** %4, i32 0, i32 48)
%13 = load i8*, i8** @POLLIN
store i8* %13, i8** %6
store i32 0, i32* %7
store i8* %13, i8** %8
store i32 %0, i32* %9
%14 = call i32 @poll(%struct.pollfd* %5, i32 2, i32 50)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i64, i64* @errno
%18 = load i64, i64* @EINTR
%19 = icmp eq i64 %17, %18
br i1 %19, label %32, label %25
20: ; preds = %11
%21 = icmp ne i32 %14, 0
%22 = load i64, i64* %10
%23 = icmp ne i64 %22, 0
%24 = select i1 %21, i1 %23, i1 false
br i1 %24, label %32, label %30
25: ; preds = %16
%26 = call i32 @error(i32 1, i64 %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%27 = load i64, i64* %10
%28 = icmp eq i64 %27, 0
%29 = zext i1 %28 to i32
br label %32
30: ; preds = %20
%31 = icmp eq i32 %14, 0
br i1 %31, label %11, label %32
32: ; preds = %30, %20, %25, %16
%33 = phi i32 [ 1, %16 ], [ %29, %25 ], [ 1, %30 ], [ 0, %20 ]
ret i32 %33
}