#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 sockaddr_nl {
  int /*<<< orphan*/ nl_family;
};
struct nlmsghdr {
  scalar_t__ nlmsg_type;
};
struct msghdr {
  void *msg_name;
  int msg_namelen;
  int msg_iovlen;
  int /*<<< orphan*/ msg_flags;
  int /*<<< orphan*/ msg_controllen;
  int /*<<< orphan*/ *msg_control;
  struct iovec *msg_iov;
};
struct iovec {
  char *iov_base;
  int iov_len;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ nladdr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_NETLINK;
scalar_t__ NLMSG_DONE;
scalar_t__ NLMSG_ERROR;
scalar_t__ NLMSG_OK(struct nlmsghdr *, scalar_t__);
int /*<<< orphan*/ memset(struct sockaddr_nl *, int /*<<< orphan*/, int);
scalar_t__ recvmsg(int const, struct msghdr *, int /*<<< orphan*/);
int check_responses(const int fd) {
  static char buf[8192];
  struct sockaddr_nl nladdr;
  struct iovec iov = {.iov_base = buf, .iov_len = sizeof(buf)};
  memset(&nladdr, 0, sizeof(nladdr));
  nladdr.nl_family = AF_NETLINK;
  struct msghdr msg = {.msg_name = (void *)&nladdr,
                       .msg_namelen = sizeof(nladdr),
                       .msg_iov = &iov,
                       .msg_iovlen = 1,
                       .msg_control = NULL,
                       .msg_controllen = 0,
                       .msg_flags = 0};
  ssize_t ret = recvmsg(fd, &msg, 0);
  if (ret <= 0)
    return 0;
  struct nlmsghdr *h = (struct nlmsghdr *)buf;
  return (NLMSG_OK(h, ret) && h->nlmsg_type != NLMSG_ERROR &&
          h->nlmsg_type != NLMSG_DONE)
             ? 1
             : 0;
}


x86 assembly (clang, -O0):
<check_responses>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2cb6(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2cb3(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0x4,-0x40(%rbp)
movl   $0x1,-0x3c(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x34(%rbp)
movq   $0x0,-0x30(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x48(%rbp),%rsi
xor    %edx,%edx
call   1050 <recvmsg@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jg     11ca <check_responses+0x9a>
movl   $0x0,-0x4(%rbp)
jmp    123a <check_responses+0x10a>
lea    0x2e7f(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   1030 <NLMSG_OK@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x59(%rbp)
je     1227 <check_responses+0xf7>
mov    -0x58(%rbp),%rax
mov    (%rax),%rcx
xor    %eax,%eax
mov    0x2de4(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x59(%rbp)
je     1227 <check_responses+0xf7>
mov    -0x58(%rbp),%rax
mov    (%rax),%rax
mov    0x2db2(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
mov    %al,-0x59(%rbp)
mov    -0x59(%rbp),%dl
xor    %eax,%eax
mov    $0x1,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_responses>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %edi,%ebp
movups 0x2cb7(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x8(%rsp),%rbx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %rbx,0x28(%rsp)
movabs $0x100000004,%rax
mov    %rax,0x30(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x38(%rsp)
lea    0x10(%rsp),%rax
mov    %rax,0x48(%rsp)
lea    0x28(%rsp),%rsi
mov    %ebp,%edi
xor    %edx,%edx
call   1050 <recvmsg@plt>
test   %rax,%rax
jle    11db <check_responses+0xab>
lea    0x2ea6(%rip),%rdi
mov    %rax,%rsi
call   1030 <NLMSG_OK@plt>
test   %rax,%rax
je     11db <check_responses+0xab>
mov    0x2e92(%rip),%rax
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%rax
je     11db <check_responses+0xab>
mov    0x2dff(%rip),%rcx
xor    %r14d,%r14d
cmp    (%rcx),%rax
setne  %r14b
mov    %r14d,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.iovec = type { i8*, i32 }
%struct.sockaddr_nl = type { i32 }
%struct.msghdr = type { i8*, i32, i32, i32, i32, i32*, %struct.iovec* }
%struct.nlmsghdr = type { i64 }
@check_responses.buf = internal global [8192 x i8] zeroinitializer
@__const.check_responses.iov = %struct.iovec { i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @check_responses.buf, i32 0, i32 0), i32 8192 }
@AF_NETLINK = global i32 0
@NLMSG_ERROR = global i64 0
@NLMSG_DONE = global i64 0
define i32 @check_responses(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_nl
%5 = alloca %struct.iovec
%6 = alloca %struct.msghdr
%7 = alloca i64
%8 = alloca %struct.nlmsghdr*
store i32 %0, i32* %3
%9 = bitcast %struct.iovec* %5 to i8*
%10 = call i32 @memset(%struct.sockaddr_nl* %4, i32 0, i32 4)
%11 = load i32, i32* @AF_NETLINK
%12 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %4, i32 0, i32 0
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i32 0, i32 0
%14 = bitcast %struct.sockaddr_nl* %4 to i8*
store i8* %14, i8** %13
%15 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i32 0, i32 1
store i32 4, i32* %15
%16 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i32 0, i32 2
store i32 1, i32* %16
%17 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i32 0, i32 3
store i32 0, i32* %17
%18 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i32 0, i32 4
store i32 0, i32* %18
%19 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i32 0, i32 5
store i32* null, i32** %19
%20 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i32 0, i32 6
store %struct.iovec* %5, %struct.iovec** %20
%21 = load i32, i32* %3
%22 = call i64 @recvmsg(i32 %21, %struct.msghdr* %6, i32 0)
store i64 %22, i64* %7
%23 = load i64, i64* %7
%24 = icmp sle i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %1
store i32 0, i32* %2
br label %47
26: ; preds = %1
store %struct.nlmsghdr* bitcast ([8192 x i8]* @check_responses.buf to %struct.nlmsghdr*), %struct.nlmsghdr** %8
%27 = load %struct.nlmsghdr*, %struct.nlmsghdr** %8
%28 = load i64, i64* %7
%29 = call i64 @NLMSG_OK(%struct.nlmsghdr* %27, i64 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %43
31: ; preds = %26
%32 = load %struct.nlmsghdr*, %struct.nlmsghdr** %8
%33 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %32, i32 0, i32 0
%34 = load i64, i64* %33
%35 = load i64, i64* @NLMSG_ERROR
%36 = icmp ne i64 %34, %35
br i1 %36, label %37, label %43
37: ; preds = %31
%38 = load %struct.nlmsghdr*, %struct.nlmsghdr** %8
%39 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %38, i32 0, i32 0
%40 = load i64, i64* %39
%41 = load i64, i64* @NLMSG_DONE
%42 = icmp ne i64 %40, %41
br label %43
43: ; preds = %37, %31, %26
%44 = phi i1 [ false, %31 ], [ false, %26 ], [ %42, %37 ]
%45 = zext i1 %44 to i64
%46 = select i1 %44, i32 1, i32 0
store i32 %46, i32* %2
br label %47
47: ; preds = %43, %25
%48 = load i32, i32* %2
ret i32 %48
}

LLVM IR (-O2):
%struct.iovec = type { i8*, i32 }
%struct.sockaddr_nl = type { i32 }
%struct.msghdr = type { i8*, i32, i32, i32, i32, i32*, %struct.iovec* }
%struct.nlmsghdr = type { i64 }
@check_responses.buf = internal global [8192 x i8] zeroinitializer
@__const.check_responses.iov = %struct.iovec { i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @check_responses.buf, i32 0, i32 0), i32 8192 }
@AF_NETLINK = global i32 0
@NLMSG_ERROR = global i64 0
@NLMSG_DONE = global i64 0
define i32 @check_responses(i32 %0) {
%2 = alloca %struct.sockaddr_nl
%3 = alloca %struct.iovec
%4 = alloca %struct.msghdr
%5 = bitcast %struct.sockaddr_nl* %2 to i8*
%6 = bitcast %struct.iovec* %3 to i8*
%7 = call i32 @memset(%struct.sockaddr_nl* %2, i32 0, i32 4)
%8 = load i32, i32* @AF_NETLINK
%9 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %2, i64 0, i32 0
store i32 %8, i32* %9
%10 = bitcast %struct.msghdr* %4 to i8*
%11 = bitcast %struct.msghdr* %4 to %struct.sockaddr_nl**
store %struct.sockaddr_nl* %2, %struct.sockaddr_nl** %11
%12 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 1
store i32 4, i32* %12
%13 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 2
store i32 1, i32* %13
%14 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 3
%15 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 6
%16 = bitcast i32* %14 to i8*
store %struct.iovec* %3, %struct.iovec** %15
%17 = call i64 @recvmsg(i32 %0, %struct.msghdr* %4, i32 0)
%18 = icmp slt i64 %17, 1
br i1 %18, label %30, label %19
19: ; preds = %1
%20 = call i64 @NLMSG_OK(%struct.nlmsghdr* bitcast ([8192 x i8]* @check_responses.buf to %struct.nlmsghdr*), i64 %17)
%21 = icmp eq i64 %20, 0
br i1 %21, label %30, label %22
22: ; preds = %19
%23 = load i64, i64* bitcast ([8192 x i8]* @check_responses.buf to i64*)
%24 = load i64, i64* @NLMSG_ERROR
%25 = icmp eq i64 %23, %24
br i1 %25, label %30, label %26
26: ; preds = %22
%27 = load i64, i64* @NLMSG_DONE
%28 = icmp ne i64 %23, %27
%29 = zext i1 %28 to i32
br label %30
30: ; preds = %19, %22, %26, %1
%31 = phi i32 [ 0, %1 ], [ 0, %22 ], [ 0, %19 ], [ %29, %26 ]
ret i32 %31
}