#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 msghdr {
  char *msg_control;
  int msg_controllen;
  int msg_flags;
  struct iovec *msg_iov;
  int /*<<< orphan*/ member_0;
};
struct iovec {
  int /*<<< orphan*/ member_0;
};
struct cfg {
  int dummy;
};
typedef int /*<<< orphan*/ control;

/* Variables and functions */
int MSG_CTRUNC;
int /*<<< orphan*/ MSG_ERRQUEUE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ parse_errqueue(struct msghdr *, struct cfg *);
int recvmsg(int, struct msghdr *, int /*<<< orphan*/);
void recv_errqueue(int fd, struct cfg *cfg) {
  struct msghdr msg = {0};
  struct iovec iov = {0};
  char control[1000];
  int ret;
  msg.msg_iov = &iov;
  msg.msg_control = control;
  msg.msg_controllen = sizeof(control);
  ret = recvmsg(fd, &msg, MSG_ERRQUEUE);
  if (ret == -1)
    error(1, errno, "recv err");
  if (msg.msg_flags & MSG_CTRUNC)
    error(1, errno, "recv err: control truncated");
  parse_errqueue(&msg, cfg);
}


x86 assembly (clang, -O0):
<recv_errqueue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
lea    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x3e8,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rsi
call   1040 <recvmsg@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0xffffffff,-0x424(%rbp)
jne    11ce <recv_errqueue+0x8e>
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe37(%rip),%rdx
call   1050 <error@plt>
mov    -0x24(%rbp),%eax
mov    0x2e00(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11fd <recv_errqueue+0xbd>
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe11(%rip),%rdx
call   1050 <error@plt>
mov    -0x10(%rbp),%rsi
lea    -0x30(%rbp),%rdi
call   1060 <parse_errqueue@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_errqueue>:
push   %rbx
sub    $0x420,%rsp
mov    %rsi,%rbx
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
movq   $0x0,0x28(%rsp)
movl   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rax
mov    %rax,0x20(%rsp)
lea    0x30(%rsp),%rax
mov    %rax,0x10(%rsp)
movl   $0x3e8,0x18(%rsp)
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rsi
call   1030 <recvmsg@plt>
cmp    $0xffffffff,%eax
jne    11a2 <recv_errqueue+0x72>
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
lea    0xe68(%rip),%rdx
mov    $0x1,%edi
call   1040 <error@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
test   %eax,0x1c(%rsp)
je     11cb <recv_errqueue+0x9b>
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
lea    0xe48(%rip),%rdx
mov    $0x1,%edi
call   1040 <error@plt>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1050 <parse_errqueue@plt>
add    $0x420,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.cfg = type { i32 }
%struct.msghdr = type { i8*, i32, i32, %struct.iovec*, i32 }
%struct.iovec = type { i32 }
@MSG_ERRQUEUE = global i32 0
@errno = global i32 0
@.str = [9 x i8] c"recv err\00"
@MSG_CTRUNC = global i32 0
@.str.1 = [28 x i8] c"recv err: control truncated\00"
define void @recv_errqueue(i32 %0, %struct.cfg* %1) {
%3 = alloca i32
%4 = alloca %struct.cfg*
%5 = alloca %struct.msghdr
%6 = alloca %struct.iovec
%7 = alloca [1000 x i8]
%8 = alloca i32
store i32 %0, i32* %3
store %struct.cfg* %1, %struct.cfg** %4
%9 = bitcast %struct.msghdr* %5 to i8*
%10 = bitcast %struct.iovec* %6 to i8*
%11 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 3
store %struct.iovec* %6, %struct.iovec** %11
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 0
store i8* %12, i8** %13
%14 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 1
store i32 1000, i32* %14
%15 = load i32, i32* %3
%16 = load i32, i32* @MSG_ERRQUEUE
%17 = call i32 @recvmsg(i32 %15, %struct.msghdr* %5, i32 %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = load i32, i32* @errno
%22 = call i32 @error(i32 1, i32 %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %20, %2
%24 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 2
%25 = load i32, i32* %24
%26 = load i32, i32* @MSG_CTRUNC
%27 = and i32 %25, %26
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = load i32, i32* @errno
%31 = call i32 @error(i32 1, i32 %30, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %29, %23
%33 = load %struct.cfg*, %struct.cfg** %4
%34 = call i32 @parse_errqueue(%struct.msghdr* %5, %struct.cfg* %33)
ret void
}

LLVM IR (-O2):
%struct.cfg = type { i32 }
%struct.msghdr = type { i8*, i32, i32, %struct.iovec*, i32 }
%struct.iovec = type { i32 }
@MSG_ERRQUEUE = global i32 0
@errno = global i32 0
@.str = [9 x i8] c"recv err\00"
@MSG_CTRUNC = global i32 0
@.str.1 = [28 x i8] c"recv err: control truncated\00"
define void @recv_errqueue(i32 %0, %struct.cfg* %1) {
%3 = alloca %struct.msghdr
%4 = alloca %struct.iovec
%5 = alloca [1000 x i8]
%6 = bitcast %struct.msghdr* %3 to i8*
%7 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %3, i64 0, i32 1
%8 = bitcast i32* %7 to i8*
%9 = bitcast %struct.iovec* %4 to i8*
%10 = getelementptr inbounds %struct.iovec, %struct.iovec* %4, i64 0, i32 0
store i32 0, i32* %10
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %3, i64 0, i32 3
store %struct.iovec* %4, %struct.iovec** %12
%13 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %3, i64 0, i32 0
store i8* %11, i8** %13
%14 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %3, i64 0, i32 1
store i32 1000, i32* %14
%15 = load i32, i32* @MSG_ERRQUEUE
%16 = call i32 @recvmsg(i32 %0, %struct.msghdr* %3, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i32, i32* @errno
%20 = call i32 @error(i32 1, i32 %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %18, %2
%22 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %3, i64 0, i32 2
%23 = load i32, i32* %22
%24 = load i32, i32* @MSG_CTRUNC
%25 = and i32 %24, %23
%26 = icmp eq i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %21
%28 = load i32, i32* @errno
%29 = call i32 @error(i32 1, i32 %28, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %27, %21
%31 = call i32 @parse_errqueue(%struct.msghdr* %3, %struct.cfg* %1)
ret void
}