#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct nlmsghdr {
  int nlmsg_flags;
  scalar_t__ nlmsg_len;
};
struct TYPE_2__ {
  int nlmsg_type;
  int nlmsg_seq;
  int nlmsg_pid;
};
struct nlmsgerr {
  TYPE_1__ msg;
  int /*<<< orphan*/ error;
};

/* Variables and functions */
scalar_t__ NLMSG_DATA(struct nlmsghdr *);
scalar_t__ NLMSG_LENGTH(int);
int NLM_F_MULTI;
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int /*<<< orphan*/);
int sk_netlink_err(struct nlmsghdr *h) {
  struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(h);
  if (err->error == 0) {
    printf("ACK: type=%u, seq=%u, pid=%d\n", err->msg.nlmsg_type,
           err->msg.nlmsg_seq, err->msg.nlmsg_pid);
    return (!(h->nlmsg_flags & NLM_F_MULTI)) ? 0 : 1;
  }
  if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr)))
    printf("Error: message truncated\n");
  else {
    printf("Error: %s, type=%u, seq=%u, pid=%d\n", strerror(-err->error),
           err->msg.nlmsg_type, err->msg.nlmsg_seq, err->msg.nlmsg_pid);
  }
  return -1;
}


x86 assembly (clang, -O0):
<sk_netlink_err>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <NLMSG_DATA@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0x0,0xc(%rax)
jne    11b6 <sk_netlink_err+0x76>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%ecx
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    0x2e52(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
setne  %dl
xor    $0xff,%dl
mov    $0x1,%eax
xor    %ecx,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    122a <sk_netlink_err+0xea>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    $0x10,%edi
call   1030 <NLMSG_LENGTH@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jge    11ef <sk_netlink_err+0xaf>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1223 <sk_netlink_err+0xe3>
mov    -0x18(%rbp),%rax
xor    %edi,%edi
sub    0xc(%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r8d
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sk_netlink_err>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1060 <NLMSG_DATA@plt>
mov    %rax,%rbx
cmpl   $0x0,0xc(%rax)
je     1186 <sk_netlink_err+0x36>
mov    0x8(%r14),%r14
mov    $0x10,%edi
call   1040 <NLMSG_LENGTH@plt>
cmp    %rax,%r14
jge    11af <sk_netlink_err+0x5f>
lea    0xec3(%rip),%rdi
call   1030 <puts@plt>
jmp    11d3 <sk_netlink_err+0x83>
mov    (%rbx),%esi
mov    0x4(%rbx),%edx
mov    0x8(%rbx),%ecx
lea    0xe6b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%ecx
xor    %eax,%eax
test   %ecx,(%r14)
setne  %al
jmp    11d8 <sk_netlink_err+0x88>
xor    %edi,%edi
sub    0xc(%rbx),%edi
call   1070 <strerror@plt>
mov    (%rbx),%edx
mov    0x4(%rbx),%ecx
mov    0x8(%rbx),%r8d
lea    0xe55(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.nlmsghdr = type { i32, i64 }
%struct.nlmsgerr = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32, i32, i32 }
@.str = [30 x i8] c"ACK: type=%u, seq=%u, pid=%d\0A\00"
@NLM_F_MULTI = global i32 0
@.str.1 = [26 x i8] c"Error: message truncated\0A\00"
@.str.2 = [36 x i8] c"Error: %s, type=%u, seq=%u, pid=%d\0A\00"
define i32 @sk_netlink_err(%struct.nlmsghdr* %0) {
%2 = alloca i32
%3 = alloca %struct.nlmsghdr*
%4 = alloca %struct.nlmsgerr*
store %struct.nlmsghdr* %0, %struct.nlmsghdr** %3
%5 = load %struct.nlmsghdr*, %struct.nlmsghdr** %3
%6 = call i64 @NLMSG_DATA(%struct.nlmsghdr* %5)
%7 = inttoptr i64 %6 to %struct.nlmsgerr*
store %struct.nlmsgerr* %7, %struct.nlmsgerr** %4
%8 = load %struct.nlmsgerr*, %struct.nlmsgerr** %4
%9 = getelementptr inbounds %struct.nlmsgerr, %struct.nlmsgerr* %8, i32 0, i32 1
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %35
12: ; preds = %1
%13 = load %struct.nlmsgerr*, %struct.nlmsgerr** %4
%14 = getelementptr inbounds %struct.nlmsgerr, %struct.nlmsgerr* %13, i32 0, i32 0
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = load %struct.nlmsgerr*, %struct.nlmsgerr** %4
%18 = getelementptr inbounds %struct.nlmsgerr, %struct.nlmsgerr* %17, i32 0, i32 0
%19 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %18, i32 0, i32 1
%20 = load i32, i32* %19
%21 = load %struct.nlmsgerr*, %struct.nlmsgerr** %4
%22 = getelementptr inbounds %struct.nlmsgerr, %struct.nlmsgerr* %21, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i32 0, i32 2
%24 = load i32, i32* %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %20, i32 %24)
%26 = load %struct.nlmsghdr*, %struct.nlmsghdr** %3
%27 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = load i32, i32* @NLM_F_MULTI
%30 = and i32 %28, %29
%31 = icmp ne i32 %30, 0
%32 = xor i1 %31, true
%33 = zext i1 %32 to i64
%34 = select i1 %32, i32 0, i32 1
store i32 %34, i32* %2
br label %63
35: ; preds = %1
%36 = load %struct.nlmsghdr*, %struct.nlmsghdr** %3
%37 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %36, i32 0, i32 1
%38 = load i64, i64* %37
%39 = call i64 @NLMSG_LENGTH(i32 16)
%40 = icmp slt i64 %38, %39
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %62
43: ; preds = %35
%44 = load %struct.nlmsgerr*, %struct.nlmsgerr** %4
%45 = getelementptr inbounds %struct.nlmsgerr, %struct.nlmsgerr* %44, i32 0, i32 1
%46 = load i32, i32* %45
%47 = sub nsw i32 0, %46
%48 = call i8* @strerror(i32 %47)
%49 = load %struct.nlmsgerr*, %struct.nlmsgerr** %4
%50 = getelementptr inbounds %struct.nlmsgerr, %struct.nlmsgerr* %49, i32 0, i32 0
%51 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = load %struct.nlmsgerr*, %struct.nlmsgerr** %4
%54 = getelementptr inbounds %struct.nlmsgerr, %struct.nlmsgerr* %53, i32 0, i32 0
%55 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %54, i32 0, i32 1
%56 = load i32, i32* %55
%57 = load %struct.nlmsgerr*, %struct.nlmsgerr** %4
%58 = getelementptr inbounds %struct.nlmsgerr, %struct.nlmsgerr* %57, i32 0, i32 0
%59 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %58, i32 0, i32 2
%60 = load i32, i32* %59
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %48, i32 %52, i32 %56, i32 %60)
br label %62
62: ; preds = %43, %41
store i32 -1, i32* %2
br label %63
63: ; preds = %62, %12
%64 = load i32, i32* %2
ret i32 %64
}

LLVM IR (-O2):
%struct.nlmsghdr = type { i32, i64 }
%struct.nlmsgerr = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32, i32, i32 }
@.str = [30 x i8] c"ACK: type=%u, seq=%u, pid=%d\0A\00"
@NLM_F_MULTI = global i32 0
@.str.2 = [36 x i8] c"Error: %s, type=%u, seq=%u, pid=%d\0A\00"
@str = [25 x i8] c"Error: message truncated\00"
define i32 @sk_netlink_err(%struct.nlmsghdr* %0) {
%2 = tail call i64 @NLMSG_DATA(%struct.nlmsghdr* %0)
%3 = inttoptr i64 %2 to %struct.nlmsgerr*
%4 = getelementptr inbounds %struct.nlmsgerr, %struct.nlmsgerr* %3, i64 0, i32 1
%5 = load i32, i32* %4
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %21
7: ; preds = %1
%8 = getelementptr inbounds %struct.nlmsgerr, %struct.nlmsgerr* %3, i64 0, i32 0, i32 0
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.nlmsgerr, %struct.nlmsgerr* %3, i64 0, i32 0, i32 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.nlmsgerr, %struct.nlmsgerr* %3, i64 0, i32 0, i32 2
%13 = load i32, i32* %12
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %11, i32 %13)
%15 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %0, i64 0, i32 0
%16 = load i32, i32* %15
%17 = load i32, i32* @NLM_F_MULTI
%18 = and i32 %17, %16
%19 = icmp ne i32 %18, 0
%20 = zext i1 %19 to i32
br label %39
21: ; preds = %1
%22 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %0, i64 0, i32 1
%23 = load i64, i64* %22
%24 = tail call i64 @NLMSG_LENGTH(i32 16)
%25 = icmp slt i64 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %39
28: ; preds = %21
%29 = load i32, i32* %4
%30 = sub nsw i32 0, %29
%31 = tail call i8* @strerror(i32 %30)
%32 = getelementptr inbounds %struct.nlmsgerr, %struct.nlmsgerr* %3, i64 0, i32 0, i32 0
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.nlmsgerr, %struct.nlmsgerr* %3, i64 0, i32 0, i32 1
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.nlmsgerr, %struct.nlmsgerr* %3, i64 0, i32 0, i32 2
%37 = load i32, i32* %36
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %31, i32 %33, i32 %35, i32 %37)
br label %39
39: ; preds = %26, %28, %7
%40 = phi i32 [ %20, %7 ], [ -1, %28 ], [ -1, %26 ]
ret i32 %40
}