#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 /*<<< orphan*/ nlmsg_len;
};

/* Variables and functions */
int NLMSG_ALIGN(int);
struct rtattr *RTA_NEXT(struct rtattr *, int /*<<< orphan*/);
int /*<<< orphan*/ RTA_OK(struct rtattr *, int /*<<< orphan*/);
__attribute__((visibility("hidden"))) struct rtattr *
rta_get(struct nlmsghdr *m, struct rtattr *p, int offset) {
  struct rtattr *rta;
  if (p) {
    rta = RTA_NEXT(p, m->nlmsg_len);
    if (!RTA_OK(rta, m->nlmsg_len))
      return NULL;
  } else {
    rta = (void *)m + NLMSG_ALIGN(offset);
  }
  return rta;
}


x86 assembly (clang, -O0):
<rta_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118b <rta_get+0x5b>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1030 <RTA_NEXT@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1040 <RTA_OK@plt>
cmp    $0x0,%eax
jne    1186 <rta_get+0x56>
movq   $0x0,-0x8(%rbp)
jmp    11b3 <rta_get+0x83>
jmp    11ab <rta_get+0x7b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <NLMSG_ALIGN@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rta_get>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
test   %rsi,%rsi
je     115e <rta_get+0x2e>
mov    (%rbx),%eax
mov    %rsi,%rdi
mov    %eax,%esi
call   1030 <RTA_NEXT@plt>
mov    %rax,%r14
mov    (%rbx),%esi
mov    %rax,%rdi
call   1040 <RTA_OK@plt>
test   %eax,%eax
jne    116d <rta_get+0x3d>
xor    %r14d,%r14d
jmp    116d <rta_get+0x3d>
mov    %edx,%edi
call   1050 <NLMSG_ALIGN@plt>
cltq
add    %rax,%rbx
mov    %rbx,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.nlmsghdr = type { i32 }
%struct.rtattr = type { i32 }
define hidden %struct.rtattr* @rta_get(%struct.nlmsghdr* %0, %struct.rtattr* %1, i32 %2) {
%4 = alloca %struct.rtattr*
%5 = alloca %struct.nlmsghdr*
%6 = alloca %struct.rtattr*
%7 = alloca i32
%8 = alloca %struct.rtattr*
store %struct.nlmsghdr* %0, %struct.nlmsghdr** %5
store %struct.rtattr* %1, %struct.rtattr** %6
store i32 %2, i32* %7
%9 = load %struct.rtattr*, %struct.rtattr** %6
%10 = icmp ne %struct.rtattr* %9, null
br i1 %10, label %11, label %25
11: ; preds = %3
%12 = load %struct.rtattr*, %struct.rtattr** %6
%13 = load %struct.nlmsghdr*, %struct.nlmsghdr** %5
%14 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call %struct.rtattr* @RTA_NEXT(%struct.rtattr* %12, i32 %15)
store %struct.rtattr* %16, %struct.rtattr** %8
%17 = load %struct.rtattr*, %struct.rtattr** %8
%18 = load %struct.nlmsghdr*, %struct.nlmsghdr** %5
%19 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @RTA_OK(%struct.rtattr* %17, i32 %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %11
store %struct.rtattr* null, %struct.rtattr** %4
br label %35
24: ; preds = %11
br label %33
25: ; preds = %3
%26 = load %struct.nlmsghdr*, %struct.nlmsghdr** %5
%27 = bitcast %struct.nlmsghdr* %26 to i8*
%28 = load i32, i32* %7
%29 = call i32 @NLMSG_ALIGN(i32 %28)
%30 = sext i32 %29 to i64
%31 = getelementptr i8, i8* %27, i64 %30
%32 = bitcast i8* %31 to %struct.rtattr*
store %struct.rtattr* %32, %struct.rtattr** %8
br label %33
33: ; preds = %25, %24
%34 = load %struct.rtattr*, %struct.rtattr** %8
store %struct.rtattr* %34, %struct.rtattr** %4
br label %35
35: ; preds = %33, %23
%36 = load %struct.rtattr*, %struct.rtattr** %4
ret %struct.rtattr* %36
}

LLVM IR (-O2):
%struct.nlmsghdr = type { i32 }
%struct.rtattr = type { i32 }
define hidden %struct.rtattr* @rta_get(%struct.nlmsghdr* %0, %struct.rtattr* %1, i32 %2) {
%4 = icmp eq %struct.rtattr* %1, null
br i1 %4, label %12, label %5
5: ; preds = %3
%6 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %0, i64 0, i32 0
%7 = load i32, i32* %6
%8 = tail call %struct.rtattr* @RTA_NEXT(%struct.rtattr* %1, i32 %7)
%9 = load i32, i32* %6
%10 = tail call i32 @RTA_OK(%struct.rtattr* %8, i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %20, label %18
12: ; preds = %3
%13 = bitcast %struct.nlmsghdr* %0 to i8*
%14 = tail call i32 @NLMSG_ALIGN(i32 %2)
%15 = sext i32 %14 to i64
%16 = getelementptr i8, i8* %13, i64 %15
%17 = bitcast i8* %16 to %struct.rtattr*
br label %18
18: ; preds = %5, %12
%19 = phi %struct.rtattr* [ %8, %5 ], [ %17, %12 ]
br label %20
20: ; preds = %5, %18
%21 = phi %struct.rtattr* [ %19, %18 ], [ null, %5 ]
ret %struct.rtattr* %21
}