#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 dummy;
};
struct nlmsghdr {
  int nlmsg_type;
};

/* Variables and functions */
size_t IFLA_IFNAME;
int /*<<< orphan*/ IFNAMSIZ;
#define RTM_NEWLINK 128
int __IFLA_MAX;
int /*<<< orphan*/ parse_ifinfo(struct rtattr **, struct nlmsghdr *);
int /*<<< orphan*/ strncpy(char *, void *, int /*<<< orphan*/);
int rtnl_getlinkname_handler(struct nlmsghdr *nh, void *arg) {
  char *name = arg;
  struct rtattr *ifla[__IFLA_MAX];
  switch (nh->nlmsg_type) {
  case RTM_NEWLINK:
    parse_ifinfo(ifla, nh);
    strncpy(name,
            ((void *)(((char *)(ifla[IFLA_IFNAME])) +
                      ((((sizeof(struct rtattr)) + 4 - 1) & ~(4 - 1)) + (0)))),
            IFNAMSIZ);
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<rtnl_getlinkname_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sub    $0x80,%eax
jne    11c3 <rtnl_getlinkname_handler+0xa3>
jmp    117b <rtnl_getlinkname_handler+0x5b>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <parse_ifinfo@plt>
mov    -0x40(%rbp),%rax
mov    -0x20(%rbp),%rdi
mov    0x2e51(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rsi
add    $0x4,%rsi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    11d1 <rtnl_getlinkname_handler+0xb1>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtnl_getlinkname_handler>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    0x2eb2(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    $0xffffffff,%eax
cmpl   $0x80,(%rdi)
jne    1185 <rtnl_getlinkname_handler+0x65>
mov    %rsi,%r14
mov    %rdi,%rsi
mov    %rbx,%rdi
call   1040 <parse_ifinfo@plt>
mov    0x2e81(%rip),%rax
mov    (%rax),%rax
mov    (%rbx,%rax,8),%rsi
add    $0x4,%rsi
mov    0x2e57(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
call   1030 <strncpy@plt>
xor    %eax,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.nlmsghdr = type { i32 }
%struct.rtattr = type { i32 }
@__IFLA_MAX = global i32 0
@IFLA_IFNAME = global i64 0
@IFNAMSIZ = global i32 0
define i32 @rtnl_getlinkname_handler(%struct.nlmsghdr* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.nlmsghdr*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store %struct.nlmsghdr* %0, %struct.nlmsghdr** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %5
store i8* %10, i8** %6
%11 = load i32, i32* @__IFLA_MAX
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %7
%14 = alloca %struct.rtattr*, i64 %12
store i64 %12, i64* %8
%15 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%16 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %15, i32 0, i32 0
%17 = load i32, i32* %16
switch i32 %17, label %29 [
i32 128, label %18
]
18: ; preds = %2
%19 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%20 = call i32 @parse_ifinfo(%struct.rtattr** %14, %struct.nlmsghdr* %19)
%21 = load i8*, i8** %6
%22 = load i64, i64* @IFLA_IFNAME
%23 = getelementptr inbounds %struct.rtattr*, %struct.rtattr** %14, i64 %22
%24 = load %struct.rtattr*, %struct.rtattr** %23
%25 = bitcast %struct.rtattr* %24 to i8*
%26 = getelementptr inbounds i8, i8* %25, i64 4
%27 = load i32, i32* @IFNAMSIZ
%28 = call i32 @strncpy(i8* %21, i8* %26, i32 %27)
store i32 0, i32* %3
store i32 1, i32* %9
br label %30
29: ; preds = %2
store i32 -1, i32* %3
store i32 1, i32* %9
br label %30
30: ; preds = %29, %18
%31 = load i8*, i8** %7
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
%struct.nlmsghdr = type { i32 }
%struct.rtattr = type { i32 }
@__IFLA_MAX = global i32 0
@IFLA_IFNAME = global i64 0
@IFNAMSIZ = global i32 0
define i32 @rtnl_getlinkname_handler(%struct.nlmsghdr* %0, i8* %1) {
%3 = load i32, i32* @__IFLA_MAX
%4 = zext i32 %3 to i64
%5 = alloca %struct.rtattr*, i64 %4
%6 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %0, i64 0, i32 0
%7 = load i32, i32* %6
%8 = icmp eq i32 %7, 128
br i1 %8, label %9, label %18
9: ; preds = %2
%10 = call i32 @parse_ifinfo(%struct.rtattr** %5, %struct.nlmsghdr* %0)
%11 = load i64, i64* @IFLA_IFNAME
%12 = getelementptr inbounds %struct.rtattr*, %struct.rtattr** %5, i64 %11
%13 = bitcast %struct.rtattr** %12 to i8**
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8, i8* %14, i64 4
%16 = load i32, i32* @IFNAMSIZ
%17 = call i32 @strncpy(i8* %1, i8* %15, i32 %16)
br label %18
18: ; preds = %2, %9
%19 = phi i32 [ 0, %9 ], [ -1, %2 ]
ret i32 %19
}