#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 */
typedef int uint32_t;
struct rtattr {
  scalar_t__ rta_type;
};
struct nlmsghdr {
  int dummy;
};
struct ifaddrmsg {
  int /*<<< orphan*/ ifa_index;
};

/* Variables and functions */
scalar_t__ IFA_LOCAL;
int IFA_PAYLOAD(struct nlmsghdr *);
struct rtattr *IFA_RTA(struct ifaddrmsg *);
int IFNAMSIZ;
scalar_t__ NLMSG_DATA(struct nlmsghdr *);
scalar_t__ RTA_DATA(struct rtattr *);
struct rtattr *RTA_NEXT(struct rtattr *, int);
scalar_t__ RTA_OK(struct rtattr *, int);
int htonl(int);
int /*<<< orphan*/ if_indextoname(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char *, int, int, int, int);
void print_rtm_newaddr(struct nlmsghdr *h) {
  struct ifaddrmsg *ifa = (struct ifaddrmsg *)NLMSG_DATA(h);
  struct rtattr *rth = IFA_RTA(ifa);
  int rtl = IFA_PAYLOAD(h);
  while (rtl && RTA_OK(rth, rtl)) {
    ;
    if (rth->rta_type == IFA_LOCAL) {
      uint32_t ipaddr = htonl(*((uint32_t *)RTA_DATA(rth)));
      char name[IFNAMSIZ];
      if_indextoname(ifa->ifa_index, name);
      printf("%s is %d.%d.%d.%d\n", name, (ipaddr >> 24) & 0xff,
             (ipaddr >> 16) & 0xff, (ipaddr >> 8) & 0xff, ipaddr & 0xff);
    }
    rth = RTA_NEXT(rth, rtl);
  }
}


x86 assembly (clang, -O0):
<print_rtm_newaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <NLMSG_DATA@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <IFA_RTA@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   10b0 <IFA_PAYLOAD@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x31(%rbp)
je     11e7 <print_rtm_newaddr+0x57>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <RTA_OK@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11f7 <print_rtm_newaddr+0x67>
jmp    12b6 <print_rtm_newaddr+0x126>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2de3(%rip),%rcx
cmp    (%rcx),%rax
jne    12a1 <print_rtm_newaddr+0x111>
mov    -0x18(%rbp),%rdi
call   10a0 <RTA_DATA@plt>
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x20(%rbp)
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x40(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1080 <if_indextoname@plt>
mov    -0x40(%rbp),%rsi
mov    -0x20(%rbp),%edx
sar    $0x18,%edx
and    $0xff,%edx
mov    -0x20(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    -0x20(%rbp),%r8d
sar    $0x8,%r8d
and    $0xff,%r8d
mov    -0x20(%rbp),%r9d
and    $0xff,%r9d
lea    0xd6b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <RTA_NEXT@plt>
mov    %rax,-0x18(%rbp)
jmp    11c2 <print_rtm_newaddr+0x32>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_rtm_newaddr>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
call   1070 <NLMSG_DATA@plt>
mov    %rax,-0x30(%rbp)
mov    %rax,%rdi
call   1090 <IFA_RTA@plt>
mov    %rax,%r13
mov    %r15,%rdi
call   10b0 <IFA_PAYLOAD@plt>
test   %eax,%eax
je     128d <print_rtm_newaddr+0xfd>
mov    %eax,%r15d
mov    %r13,%rdi
mov    %eax,%esi
call   1040 <RTA_OK@plt>
test   %rax,%rax
je     128d <print_rtm_newaddr+0xfd>
mov    0x2e03(%rip),%r14
jmp    120e <print_rtm_newaddr+0x7e>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r15d,%esi
call   1030 <RTA_NEXT@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r15d,%esi
call   1040 <RTA_OK@plt>
test   %rax,%rax
je     128d <print_rtm_newaddr+0xfd>
mov    0x0(%r13),%rax
cmp    (%r14),%rax
jne    11f0 <print_rtm_newaddr+0x60>
mov    %r13,%rdi
call   10a0 <RTA_DATA@plt>
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,%r12d
mov    %rsp,-0x38(%rbp)
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1080 <if_indextoname@plt>
mov    %r12d,%ecx
mov    %r12d,%edx
shr    $0x18,%edx
mov    %r12d,%eax
shr    $0x10,%eax
movzbl %al,%r8d
movzbl %ch,%eax
movzbl %cl,%r9d
lea    0xd8a(%rip),%rdi
mov    %rbx,%rsi
mov    %r8d,%ecx
mov    %eax,%r8d
call   1050 <printf@plt>
mov    -0x38(%rbp),%rsp
jmp    11f0 <print_rtm_newaddr+0x60>
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.ifaddrmsg = type { i32 }
%struct.rtattr = type { i64 }
@IFA_LOCAL = global i64 0
@IFNAMSIZ = global i32 0
@.str = [19 x i8] c"%s is %d.%d.%d.%d\0A\00"
define void @print_rtm_newaddr(%struct.nlmsghdr* %0) {
%2 = alloca %struct.nlmsghdr*
%3 = alloca %struct.ifaddrmsg*
%4 = alloca %struct.rtattr*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store %struct.nlmsghdr* %0, %struct.nlmsghdr** %2
%9 = load %struct.nlmsghdr*, %struct.nlmsghdr** %2
%10 = call i64 @NLMSG_DATA(%struct.nlmsghdr* %9)
%11 = inttoptr i64 %10 to %struct.ifaddrmsg*
store %struct.ifaddrmsg* %11, %struct.ifaddrmsg** %3
%12 = load %struct.ifaddrmsg*, %struct.ifaddrmsg** %3
%13 = call %struct.rtattr* @IFA_RTA(%struct.ifaddrmsg* %12)
store %struct.rtattr* %13, %struct.rtattr** %4
%14 = load %struct.nlmsghdr*, %struct.nlmsghdr** %2
%15 = call i32 @IFA_PAYLOAD(%struct.nlmsghdr* %14)
store i32 %15, i32* %5
br label %16
16: ; preds = %59, %1
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load %struct.rtattr*, %struct.rtattr** %4
%21 = load i32, i32* %5
%22 = call i64 @RTA_OK(%struct.rtattr* %20, i32 %21)
%23 = icmp ne i64 %22, 0
br label %24
24: ; preds = %19, %16
%25 = phi i1 [ false, %16 ], [ %23, %19 ]
br i1 %25, label %26, label %63
26: ; preds = %24
%27 = load %struct.rtattr*, %struct.rtattr** %4
%28 = getelementptr inbounds %struct.rtattr, %struct.rtattr* %27, i32 0, i32 0
%29 = load i64, i64* %28
%30 = load i64, i64* @IFA_LOCAL
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %59
32: ; preds = %26
%33 = load %struct.rtattr*, %struct.rtattr** %4
%34 = call i64 @RTA_DATA(%struct.rtattr* %33)
%35 = inttoptr i64 %34 to i32*
%36 = load i32, i32* %35
%37 = call i32 @htonl(i32 %36)
store i32 %37, i32* %6
%38 = load i32, i32* @IFNAMSIZ
%39 = zext i32 %38 to i64
%40 = call i8* @llvm.stacksave()
store i8* %40, i8** %7
%41 = alloca i8, i64 %39
store i64 %39, i64* %8
%42 = load %struct.ifaddrmsg*, %struct.ifaddrmsg** %3
%43 = getelementptr inbounds %struct.ifaddrmsg, %struct.ifaddrmsg* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = call i32 @if_indextoname(i32 %44, i8* %41)
%46 = load i32, i32* %6
%47 = ashr i32 %46, 24
%48 = and i32 %47, 255
%49 = load i32, i32* %6
%50 = ashr i32 %49, 16
%51 = and i32 %50, 255
%52 = load i32, i32* %6
%53 = ashr i32 %52, 8
%54 = and i32 %53, 255
%55 = load i32, i32* %6
%56 = and i32 %55, 255
%57 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %41, i32 %48, i32 %51, i32 %54, i32 %56)
%58 = load i8*, i8** %7
br label %59
59: ; preds = %32, %26
%60 = load %struct.rtattr*, %struct.rtattr** %4
%61 = load i32, i32* %5
%62 = call %struct.rtattr* @RTA_NEXT(%struct.rtattr* %60, i32 %61)
store %struct.rtattr* %62, %struct.rtattr** %4
br label %16
63: ; preds = %24
ret void
}

LLVM IR (-O2):
%struct.nlmsghdr = type { i32 }
%struct.ifaddrmsg = type { i32 }
%struct.rtattr = type { i64 }
@IFA_LOCAL = global i64 0
@IFNAMSIZ = global i32 0
@.str = [19 x i8] c"%s is %d.%d.%d.%d\0A\00"
define void @print_rtm_newaddr(%struct.nlmsghdr* %0) {
%2 = tail call i64 @NLMSG_DATA(%struct.nlmsghdr* %0)
%3 = inttoptr i64 %2 to %struct.ifaddrmsg*
%4 = tail call %struct.rtattr* @IFA_RTA(%struct.ifaddrmsg* %3)
%5 = tail call i32 @IFA_PAYLOAD(%struct.nlmsghdr* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %39, label %7
7: ; preds = %1
%8 = getelementptr inbounds %struct.ifaddrmsg, %struct.ifaddrmsg* %3, i64 0, i32 0
%9 = call i64 @RTA_OK(%struct.rtattr* %4, i32 %5)
%10 = icmp eq i64 %9, 0
br i1 %10, label %39, label %11
11: ; preds = %7, %35
%12 = phi %struct.rtattr* [ %36, %35 ], [ %4, %7 ]
%13 = getelementptr inbounds %struct.rtattr, %struct.rtattr* %12, i64 0, i32 0
%14 = load i64, i64* %13
%15 = load i64, i64* @IFA_LOCAL
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %35
17: ; preds = %11
%18 = call i64 @RTA_DATA(%struct.rtattr* %12)
%19 = inttoptr i64 %18 to i32*
%20 = load i32, i32* %19
%21 = call i32 @htonl(i32 %20)
%22 = load i32, i32* @IFNAMSIZ
%23 = zext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
%25 = alloca i8, i64 %23
%26 = load i32, i32* %8
%27 = call i32 @if_indextoname(i32 %26, i8* %25)
%28 = lshr i32 %21, 24
%29 = lshr i32 %21, 16
%30 = and i32 %29, 255
%31 = lshr i32 %21, 8
%32 = and i32 %31, 255
%33 = and i32 %21, 255
%34 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %25, i32 %28, i32 %30, i32 %32, i32 %33)
br label %35
35: ; preds = %17, %11
%36 = call %struct.rtattr* @RTA_NEXT(%struct.rtattr* %12, i32 %5)
%37 = call i64 @RTA_OK(%struct.rtattr* %36, i32 %5)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %11
39: ; preds = %35, %7, %1
ret void
}