#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 dummy;
};
struct ifinfomsg {
  int ifi_index;
};

/* Variables and functions */
#define IFLA_IFNAME 128
struct rtattr *IFLA_RTA(struct ifinfomsg *);
struct ifinfomsg *NLMSG_DATA(struct nlmsghdr *);
int NLMSG_LENGTH(int);
scalar_t__ RTA_DATA(struct rtattr *);
struct rtattr *RTA_NEXT(struct rtattr *, int);
scalar_t__ RTA_OK(struct rtattr *, int);
int /*<<< orphan*/ printf(char *, int, char *);
void rtnl_print_link(struct nlmsghdr *h) {
  struct ifinfomsg *iface;
  struct rtattr *attribute;
  int len;
  iface = NLMSG_DATA(h);
  len = NLMSG_LENGTH(sizeof(*iface));
  for (attribute = IFLA_RTA(iface); RTA_OK(attribute, len);
       attribute = RTA_NEXT(attribute, len)) {
    switch (attribute->rta_type) {
    case IFLA_IFNAME:
      printf("Interface %d : %s\n", iface->ifi_index,
             (char *)RTA_DATA(attribute));
      break;
    default:
      break;
    }
  }
}


x86 assembly (clang, -O0):
<rtnl_print_link>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <NLMSG_DATA@plt>
mov    %rax,-0x10(%rbp)
mov    $0x4,%edi
call   1040 <NLMSG_LENGTH@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <IFLA_RTA@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <RTA_OK@plt>
cmp    $0x0,%rax
je     1217 <rtnl_print_link+0xa7>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
sub    $0x80,%eax
jne    11f8 <rtnl_print_link+0x88>
jmp    11cf <rtnl_print_link+0x5f>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <RTA_DATA@plt>
mov    -0x20(%rbp),%esi
mov    %rax,%rdx
lea    0xe12(%rip),%rdi
call   1060 <printf@plt>
jmp    11fd <rtnl_print_link+0x8d>
jmp    11fd <rtnl_print_link+0x8d>
jmp    1202 <rtnl_print_link+0x92>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <RTA_NEXT@plt>
mov    %rax,-0x18(%rbp)
jmp    11a3 <rtnl_print_link+0x33>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtnl_print_link>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
call   1080 <NLMSG_DATA@plt>
mov    %rax,%r14
mov    $0x4,%edi
call   1040 <NLMSG_LENGTH@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1070 <IFLA_RTA@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12d,%esi
call   1050 <RTA_OK@plt>
test   %rax,%rax
je     1200 <rtnl_print_link+0x90>
lea    0xe51(%rip),%r15
jmp    11de <rtnl_print_link+0x6e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12d,%esi
call   1030 <RTA_NEXT@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12d,%esi
call   1050 <RTA_OK@plt>
test   %rax,%rax
je     1200 <rtnl_print_link+0x90>
cmpl   $0x80,(%rbx)
jne    11c0 <rtnl_print_link+0x50>
mov    (%r14),%ebp
mov    %rbx,%rdi
call   1090 <RTA_DATA@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   1060 <printf@plt>
jmp    11c0 <rtnl_print_link+0x50>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.nlmsghdr = type { i32 }
%struct.ifinfomsg = type { i32 }
%struct.rtattr = type { i32 }
@.str = [19 x i8] c"Interface %d : %s\0A\00"
define void @rtnl_print_link(%struct.nlmsghdr* %0) {
%2 = alloca %struct.nlmsghdr*
%3 = alloca %struct.ifinfomsg*
%4 = alloca %struct.rtattr*
%5 = alloca i32
store %struct.nlmsghdr* %0, %struct.nlmsghdr** %2
%6 = load %struct.nlmsghdr*, %struct.nlmsghdr** %2
%7 = call %struct.ifinfomsg* @NLMSG_DATA(%struct.nlmsghdr* %6)
store %struct.ifinfomsg* %7, %struct.ifinfomsg** %3
%8 = call i32 @NLMSG_LENGTH(i32 4)
store i32 %8, i32* %5
%9 = load %struct.ifinfomsg*, %struct.ifinfomsg** %3
%10 = call %struct.rtattr* @IFLA_RTA(%struct.ifinfomsg* %9)
store %struct.rtattr* %10, %struct.rtattr** %4
br label %11
11: ; preds = %30, %1
%12 = load %struct.rtattr*, %struct.rtattr** %4
%13 = load i32, i32* %5
%14 = call i64 @RTA_OK(%struct.rtattr* %12, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %34
16: ; preds = %11
%17 = load %struct.rtattr*, %struct.rtattr** %4
%18 = getelementptr inbounds %struct.rtattr, %struct.rtattr* %17, i32 0, i32 0
%19 = load i32, i32* %18
switch i32 %19, label %28 [
i32 128, label %20
]
20: ; preds = %16
%21 = load %struct.ifinfomsg*, %struct.ifinfomsg** %3
%22 = getelementptr inbounds %struct.ifinfomsg, %struct.ifinfomsg* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = load %struct.rtattr*, %struct.rtattr** %4
%25 = call i64 @RTA_DATA(%struct.rtattr* %24)
%26 = inttoptr i64 %25 to i8*
%27 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %23, i8* %26)
br label %29
28: ; preds = %16
br label %29
29: ; preds = %28, %20
br label %30
30: ; preds = %29
%31 = load %struct.rtattr*, %struct.rtattr** %4
%32 = load i32, i32* %5
%33 = call %struct.rtattr* @RTA_NEXT(%struct.rtattr* %31, i32 %32)
store %struct.rtattr* %33, %struct.rtattr** %4
br label %11
34: ; preds = %11
ret void
}

LLVM IR (-O2):
%struct.nlmsghdr = type { i32 }
%struct.ifinfomsg = type { i32 }
%struct.rtattr = type { i32 }
@.str = [19 x i8] c"Interface %d : %s\0A\00"
define void @rtnl_print_link(%struct.nlmsghdr* %0) {
%2 = tail call %struct.ifinfomsg* @NLMSG_DATA(%struct.nlmsghdr* %0)
%3 = tail call i32 @NLMSG_LENGTH(i32 4)
%4 = tail call %struct.rtattr* @IFLA_RTA(%struct.ifinfomsg* %2)
%5 = tail call i64 @RTA_OK(%struct.rtattr* %4, i32 %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %23, label %7
7: ; preds = %1
%8 = getelementptr inbounds %struct.ifinfomsg, %struct.ifinfomsg* %2, i64 0, i32 0
br label %9
9: ; preds = %7, %19
%10 = phi %struct.rtattr* [ %4, %7 ], [ %20, %19 ]
%11 = getelementptr inbounds %struct.rtattr, %struct.rtattr* %10, i64 0, i32 0
%12 = load i32, i32* %11
%13 = icmp eq i32 %12, 128
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = load i32, i32* %8
%16 = tail call i64 @RTA_DATA(%struct.rtattr* %10)
%17 = inttoptr i64 %16 to i8*
%18 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %17)
br label %19
19: ; preds = %14, %9
%20 = tail call %struct.rtattr* @RTA_NEXT(%struct.rtattr* %10, i32 %3)
%21 = tail call i64 @RTA_OK(%struct.rtattr* %20, i32 %3)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %9
23: ; preds = %19, %1
ret void
}