#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;
};
struct nlmsghdr {
  int dummy;
};
struct msghdr {
  int msg_iovlen;
  struct iovec *msg_iov;
};
struct iovec {
  char *iov_base;
  int iov_len;
};
typedef int /*<<< orphan*/ msg;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ POLLIN;
scalar_t__ TEMP_FAILURE_RETRY(int /*<<< orphan*/);
int /*<<< orphan*/ ifup_scan_event(struct nlmsghdr *, int, int *);
int /*<<< orphan*/ memset(struct msghdr *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ poll(struct pollfd *, int, int);
int recvmsg(int, struct msghdr *, int /*<<< orphan*/);
int ifup_read_event(int fd, int *seen_flags) {
  struct pollfd fds;
  int len;
  char buf[4096];
  struct iovec iov;
  struct msghdr msg;
  iov.iov_base = buf;
  iov.iov_len = sizeof(buf);
  fds.fd = fd;
  fds.events = POLLIN;
  if (TEMP_FAILURE_RETRY(poll(&fds, 1, -1)) < 0) {
    perror("poll");
    return 0;
  }
  memset(&msg, 0, sizeof(msg));
  msg.msg_iov = &iov;
  msg.msg_iovlen = 1;
  len = recvmsg(fd, &msg, 0);
  if (len < 0) {
    perror("recvmsg");
    return 0;
  }
  if (seen_flags)
    ifup_scan_event((struct nlmsghdr *)buf, len, seen_flags);
  return 1;
}


x86 assembly (clang, -O0):
<ifup_read_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1030(%rbp)
movl   $0x1000,-0x1028(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1050 <poll@plt>
mov    %eax,%edi
call   1080 <TEMP_FAILURE_RETRY@plt>
cmp    $0x0,%rax
jge    11d8 <ifup_read_event+0x78>
lea    0xe39(%rip),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    125e <ifup_read_event+0xfe>
lea    -0x1040(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
lea    -0x1030(%rbp),%rax
mov    %rax,-0x1038(%rbp)
movl   $0x1,-0x1040(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x1040(%rbp),%rsi
xor    %edx,%edx
call   1040 <recvmsg@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1239 <ifup_read_event+0xd9>
lea    0xddd(%rip),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    125e <ifup_read_event+0xfe>
cmpq   $0x0,-0x10(%rbp)
je     1257 <ifup_read_event+0xf7>
lea    -0x1020(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1070 <ifup_scan_event@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ifup_read_event>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1038,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0x30(%rsp),%rax
mov    %rax,0x20(%rsp)
movl   $0x1000,0x28(%rsp)
mov    %edi,0x8(%rsp)
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1050 <poll@plt>
mov    %eax,%edi
call   1080 <TEMP_FAILURE_RETRY@plt>
test   %rax,%rax
js     1216 <ifup_read_event+0xb6>
lea    0x10(%rsp),%r15
xor    %ebp,%ebp
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
lea    0x20(%rsp),%rax
mov    %rax,0x18(%rsp)
movl   $0x1,0x10(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
xor    %edx,%edx
call   1040 <recvmsg@plt>
test   %eax,%eax
js     1226 <ifup_read_event+0xc6>
mov    $0x1,%ebp
test   %r14,%r14
je     1206 <ifup_read_event+0xa6>
lea    0x30(%rsp),%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   1070 <ifup_scan_event@plt>
mov    %ebp,%eax
add    $0x1038,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde3(%rip),%rdi
call   1060 <perror@plt>
xor    %ebp,%ebp
jmp    1206 <ifup_read_event+0xa6>
lea    0xdd8(%rip),%rdi
call   1060 <perror@plt>
jmp    1206 <ifup_read_event+0xa6>

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

LLVM IR (-O2):
%struct.pollfd = type { i32, i32 }
%struct.iovec = type { i8*, i32 }
%struct.msghdr = type { i32, %struct.iovec* }
%struct.nlmsghdr = type { i32 }
@POLLIN = global i32 0
@.str = [5 x i8] c"poll\00"
@.str.1 = [8 x i8] c"recvmsg\00"
define i32 @ifup_read_event(i32 %0, i32* %1) {
%3 = alloca %struct.pollfd
%4 = alloca [4096 x i8]
%5 = alloca %struct.iovec
%6 = alloca %struct.msghdr
%7 = bitcast %struct.pollfd* %3 to i8*
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%9 = bitcast %struct.iovec* %5 to i8*
%10 = bitcast %struct.msghdr* %6 to i8*
%11 = getelementptr inbounds %struct.iovec, %struct.iovec* %5, i64 0, i32 0
store i8* %8, i8** %11
%12 = getelementptr inbounds %struct.iovec, %struct.iovec* %5, i64 0, i32 1
store i32 4096, i32* %12
%13 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %3, i64 0, i32 0
store i32 %0, i32* %13
%14 = load i32, i32* @POLLIN
%15 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %3, i64 0, i32 1
store i32 %14, i32* %15
%16 = call i32 @poll(%struct.pollfd* %3, i32 1, i32 -1)
%17 = call i64 @TEMP_FAILURE_RETRY(i32 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %34
21: ; preds = %2
%22 = call i32 @memset(%struct.msghdr* %6, i32 0, i32 16)
%23 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i64 0, i32 1
store %struct.iovec* %5, %struct.iovec** %23
%24 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i64 0, i32 0
store i32 1, i32* %24
%25 = call i32 @recvmsg(i32 %0, %struct.msghdr* %6, i32 0)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %34
29: ; preds = %21
%30 = icmp eq i32* %1, null
br i1 %30, label %34, label %31
31: ; preds = %29
%32 = bitcast [4096 x i8]* %4 to %struct.nlmsghdr*
%33 = call i32 @ifup_scan_event(%struct.nlmsghdr* %32, i32 %25, i32* %1)
br label %34
34: ; preds = %29, %31, %27, %19
%35 = phi i32 [ 0, %19 ], [ 0, %27 ], [ 1, %31 ], [ 1, %29 ]
ret i32 %35
}