#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 rtattr {
  int rta_type;
};
struct nlmsghdr {
  int nlmsg_len;
};
struct ifinfomsg {
  int /*<<< orphan*/ ifi_index;
};
typedef int /*<<< orphan*/ ssize_t;

/* Variables and functions */
#define IFLA_IFNAME 128
int IF_NAMESIZE;
int /*<<< orphan*/ LOG_INFO;
int NLMSG_ALIGN(int);
scalar_t__ NLMSG_DATA(struct nlmsghdr *);
int NLMSG_PAYLOAD(struct nlmsghdr *, int);
char *RTA_DATA(struct rtattr *);
struct rtattr *RTA_NEXT(struct rtattr *, int);
scalar_t__ RTA_OK(struct rtattr *, int);
int RTA_PAYLOAD(struct rtattr *);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char const *, char *,
                          int /*<<< orphan*/);
void handle_link(struct nlmsghdr *header, ssize_t bytes, const char *name) {
  struct rtattr *rta;
  struct ifinfomsg *ifi;
  int len;
  char ifname[IF_NAMESIZE + 1];
  len = header->nlmsg_len - sizeof *header;
  ifi = (struct ifinfomsg *)NLMSG_DATA(header);
  rta = (struct rtattr *)((char *)ifi + NLMSG_ALIGN(sizeof(*ifi)));
  len = NLMSG_PAYLOAD(header, sizeof *ifi);
  ifname[0] = 0;
  for (; RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) {
    int namelen;
    const char *np;
    switch (rta->rta_type) {
    case IFLA_IFNAME:
      namelen = RTA_PAYLOAD(rta);
      if (namelen > IF_NAMESIZE)
        namelen = IF_NAMESIZE;
      np = RTA_DATA(rta);
      memcpy(ifname, np, namelen);
      ifname[namelen] = 0;
    }
  }
  syslog(LOG_INFO, "%s: %s index %d\n", name, ifname, ifi->ifi_index);
}


x86 assembly (clang, -O0):
<handle_link>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
movslq (%rax),%rax
sub    $0x4,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <NLMSG_DATA@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    $0x4,%edi
call   1060 <NLMSG_ALIGN@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x4,%esi
call   1070 <NLMSG_PAYLOAD@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
mov    %ecx,-0x2c(%rbp)
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1050 <RTA_OK@plt>
cmp    $0x0,%rax
je     12c2 <handle_link+0x132>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
sub    $0x80,%eax
jne    12a8 <handle_link+0x118>
jmp    1255 <handle_link+0xc5>
mov    -0x20(%rbp),%rdi
call   1040 <RTA_PAYLOAD@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    0x2d7d(%rip),%rcx
cmp    (%rcx),%eax
jle    127f <handle_link+0xef>
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rdi
call   10b0 <RTA_DATA@plt>
mov    -0x58(%rbp),%rdi
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rsi
mov    -0x44(%rbp),%edx
call   1080 <memcpy@plt>
mov    -0x58(%rbp),%rax
movslq -0x44(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    12ad <handle_link+0x11d>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1030 <RTA_NEXT@plt>
mov    %rax,-0x20(%rbp)
jmp    1229 <handle_link+0x99>
mov    -0x58(%rbp),%rcx
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    (%rax),%r8d
lea    0xd1f(%rip),%rsi
call   10a0 <syslog@plt>
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_link>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,-0x40(%rbp)
mov    %rdi,-0x30(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%r14d
add    $0x1,%r14d
mov    %rsp,%r15
add    $0xf,%r14
and    $0xfffffffffffffff0,%r14
mov    %r15,%r12
sub    %r14,%r12
mov    %r12,%rsp
neg    %r14
call   1090 <NLMSG_DATA@plt>
mov    %rax,%r13
mov    $0x4,%edi
call   1060 <NLMSG_ALIGN@plt>
movslq %eax,%rbx
mov    %r13,-0x38(%rbp)
add    %r13,%rbx
mov    -0x30(%rbp),%rdi
mov    $0x4,%esi
call   1070 <NLMSG_PAYLOAD@plt>
mov    %eax,%r13d
movb   $0x0,(%r15,%r14,1)
mov    %rbx,%rdi
mov    %eax,%esi
jmp    1224 <handle_link+0x94>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r13d,%esi
call   1030 <RTA_NEXT@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13d,%esi
call   1050 <RTA_OK@plt>
test   %rax,%rax
je     1271 <handle_link+0xe1>
cmpl   $0x80,(%rbx)
jne    1210 <handle_link+0x80>
mov    %rbx,%rdi
call   1040 <RTA_PAYLOAD@plt>
mov    %eax,%r14d
mov    0x2da0(%rip),%rax
mov    (%rax),%eax
cmp    %eax,%r14d
cmovg  %eax,%r14d
mov    %rbx,%rdi
call   10b0 <RTA_DATA@plt>
mov    %r12,%rdi
mov    %rax,%rsi
mov    %r14d,%edx
call   1080 <memcpy@plt>
movslq %r14d,%rax
movb   $0x0,(%r12,%rax,1)
jmp    1210 <handle_link+0x80>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rax
mov    (%rax),%r8d
lea    0xd78(%rip),%rsi
mov    -0x40(%rbp),%rdx
mov    %r12,%rcx
call   10a0 <syslog@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.nlmsghdr = type { i32 }
%struct.rtattr = type { i32 }
%struct.ifinfomsg = type { i32 }
@IF_NAMESIZE = global i32 0
@LOG_INFO = global i32 0
@.str = [17 x i8] c"%s: %s index %d\0A\00"
define void @handle_link(%struct.nlmsghdr* %0, i32 %1, i8* %2) {
%4 = alloca %struct.nlmsghdr*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.rtattr*
%8 = alloca %struct.ifinfomsg*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i8*
store %struct.nlmsghdr* %0, %struct.nlmsghdr** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%14 = load i32, i32* @IF_NAMESIZE
%15 = add nsw i32 %14, 1
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %10
%18 = alloca i8, i64 %16
store i64 %16, i64* %11
%19 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%20 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = sext i32 %21 to i64
%23 = sub i64 %22, 4
%24 = trunc i64 %23 to i32
store i32 %24, i32* %9
%25 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%26 = call i64 @NLMSG_DATA(%struct.nlmsghdr* %25)
%27 = inttoptr i64 %26 to %struct.ifinfomsg*
store %struct.ifinfomsg* %27, %struct.ifinfomsg** %8
%28 = load %struct.ifinfomsg*, %struct.ifinfomsg** %8
%29 = bitcast %struct.ifinfomsg* %28 to i8*
%30 = call i32 @NLMSG_ALIGN(i32 4)
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = bitcast i8* %32 to %struct.rtattr*
store %struct.rtattr* %33, %struct.rtattr** %7
%34 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%35 = call i32 @NLMSG_PAYLOAD(%struct.nlmsghdr* %34, i32 4)
store i32 %35, i32* %9
%36 = getelementptr inbounds i8, i8* %18, i64 0
store i8 0, i8* %36
br label %37
37: ; preds = %64, %3
%38 = load %struct.rtattr*, %struct.rtattr** %7
%39 = load i32, i32* %9
%40 = call i64 @RTA_OK(%struct.rtattr* %38, i32 %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %68
42: ; preds = %37
%43 = load %struct.rtattr*, %struct.rtattr** %7
%44 = getelementptr inbounds %struct.rtattr, %struct.rtattr* %43, i32 0, i32 0
%45 = load i32, i32* %44
switch i32 %45, label %63 [
i32 128, label %46
]
46: ; preds = %42
%47 = load %struct.rtattr*, %struct.rtattr** %7
%48 = call i32 @RTA_PAYLOAD(%struct.rtattr* %47)
store i32 %48, i32* %12
%49 = load i32, i32* %12
%50 = load i32, i32* @IF_NAMESIZE
%51 = icmp sgt i32 %49, %50
br i1 %51, label %52, label %54
52: ; preds = %46
%53 = load i32, i32* @IF_NAMESIZE
store i32 %53, i32* %12
br label %54
54: ; preds = %52, %46
%55 = load %struct.rtattr*, %struct.rtattr** %7
%56 = call i8* @RTA_DATA(%struct.rtattr* %55)
store i8* %56, i8** %13
%57 = load i8*, i8** %13
%58 = load i32, i32* %12
%59 = call i32 @memcpy(i8* %18, i8* %57, i32 %58)
%60 = load i32, i32* %12
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %18, i64 %61
store i8 0, i8* %62
br label %63
63: ; preds = %54, %42
br label %64
64: ; preds = %63
%65 = load %struct.rtattr*, %struct.rtattr** %7
%66 = load i32, i32* %9
%67 = call %struct.rtattr* @RTA_NEXT(%struct.rtattr* %65, i32 %66)
store %struct.rtattr* %67, %struct.rtattr** %7
br label %37
68: ; preds = %37
%69 = load i32, i32* @LOG_INFO
%70 = load i8*, i8** %6
%71 = load %struct.ifinfomsg*, %struct.ifinfomsg** %8
%72 = getelementptr inbounds %struct.ifinfomsg, %struct.ifinfomsg* %71, i32 0, i32 0
%73 = load i32, i32* %72
%74 = call i32 @syslog(i32 %69, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %70, i8* %18, i32 %73)
%75 = load i8*, i8** %10
ret void
}

LLVM IR (-O2):
%struct.nlmsghdr = type { i32 }
%struct.rtattr = type { i32 }
%struct.ifinfomsg = type { i32 }
@IF_NAMESIZE = global i32 0
@LOG_INFO = global i32 0
@.str = [17 x i8] c"%s: %s index %d\0A\00"
define void @handle_link(%struct.nlmsghdr* %0, i32 %1, i8* %2) {
%4 = load i32, i32* @IF_NAMESIZE
%5 = add nsw i32 %4, 1
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = tail call i64 @NLMSG_DATA(%struct.nlmsghdr* %0)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @NLMSG_ALIGN(i32 4)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = bitcast i8* %12 to %struct.rtattr*
%14 = tail call i32 @NLMSG_PAYLOAD(%struct.nlmsghdr* %0, i32 4)
store i8 0, i8* %7
%15 = call i64 @RTA_OK(%struct.rtattr* %13, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %35, label %17
17: ; preds = %3, %31
%18 = phi %struct.rtattr* [ %32, %31 ], [ %13, %3 ]
%19 = getelementptr inbounds %struct.rtattr, %struct.rtattr* %18, i64 0, i32 0
%20 = load i32, i32* %19
%21 = icmp eq i32 %20, 128
br i1 %21, label %22, label %31
22: ; preds = %17
%23 = call i32 @RTA_PAYLOAD(%struct.rtattr* %18)
%24 = load i32, i32* @IF_NAMESIZE
%25 = icmp sgt i32 %23, %24
%26 = select i1 %25, i32 %24, i32 %23
%27 = call i8* @RTA_DATA(%struct.rtattr* %18)
%28 = call i32 @memcpy(i8* %7, i8* %27, i32 %26)
%29 = sext i32 %26 to i64
%30 = getelementptr inbounds i8, i8* %7, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %17, %22
%32 = call %struct.rtattr* @RTA_NEXT(%struct.rtattr* %18, i32 %14)
%33 = call i64 @RTA_OK(%struct.rtattr* %32, i32 %14)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %17
35: ; preds = %31, %3
%36 = inttoptr i64 %8 to %struct.ifinfomsg*
%37 = load i32, i32* @LOG_INFO
%38 = getelementptr inbounds %struct.ifinfomsg, %struct.ifinfomsg* %36, i64 0, i32 0
%39 = load i32, i32* %38
%40 = call i32 @syslog(i32 %37, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %7, i32 %39)
ret void
}