#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 {
  unsigned short rta_type;
};

/* Variables and functions */
scalar_t__ EINVAL;
scalar_t__ ESRCH;
struct rtattr *RTA_NEXT(struct rtattr *, unsigned int);
scalar_t__ RTA_OK(struct rtattr *, unsigned int);
scalar_t__ errno;
struct rtattr *rtnetlink_get_attr(struct rtattr *attr, unsigned int bounds,
                                  unsigned short rta_type) {
  errno = 0;
  if (!attr) {
    errno = EINVAL;
    return NULL;
  }
  while (RTA_OK(attr, bounds)) {
    if (attr->rta_type == rta_type)
      return attr;
    attr = RTA_NEXT(attr, bounds);
  }
  errno = ESRCH;
  return NULL;
}


x86 assembly (clang, -O0):
<rtnetlink_get_attr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dx,%ax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %ax,-0x16(%rbp)
mov    0x2ea3(%rip),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x10(%rbp)
jne    1170 <rtnetlink_get_attr+0x50>
mov    0x2e82(%rip),%rax
mov    (%rax),%rcx
mov    0x2e80(%rip),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11dc <rtnetlink_get_attr+0xbc>
jmp    1175 <rtnetlink_get_attr+0x55>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <RTA_OK@plt>
cmp    $0x0,%rax
je     11c0 <rtnetlink_get_attr+0xa0>
mov    -0x10(%rbp),%rax
movzwl (%rax),%eax
movzwl -0x16(%rbp),%ecx
cmp    %ecx,%eax
jne    11ab <rtnetlink_get_attr+0x8b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11dc <rtnetlink_get_attr+0xbc>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <RTA_NEXT@plt>
mov    %rax,-0x10(%rbp)
jmp    1175 <rtnetlink_get_attr+0x55>
mov    0x2e01(%rip),%rax
mov    (%rax),%rcx
mov    0x2e0f(%rip),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtnetlink_get_attr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2eb1(%rip),%r15
movq   $0x0,(%r15)
test   %rdi,%rdi
je     1184 <rtnetlink_get_attr+0x64>
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <RTA_OK@plt>
mov    0x2e79(%rip),%r12
test   %rax,%rax
je     118b <rtnetlink_get_attr+0x6b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    %r14w,(%rbx)
je     1194 <rtnetlink_get_attr+0x74>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <RTA_NEXT@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
call   1040 <RTA_OK@plt>
test   %rax,%rax
jne    1160 <rtnetlink_get_attr+0x40>
jmp    118b <rtnetlink_get_attr+0x6b>
mov    0x2e4d(%rip),%r12
mov    (%r12),%rax
mov    %rax,(%r15)
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.rtattr = type { i16 }
@errno = global i64 0
@EINVAL = global i64 0
@ESRCH = global i64 0
define %struct.rtattr* @rtnetlink_get_attr(%struct.rtattr* %0, i32 %1, i16 zeroext %2) {
store i64 0, i64* @errno
%4 = icmp eq %struct.rtattr* %0, null
br i1 %4, label %17, label %5
5: ; preds = %3
%6 = tail call i64 @RTA_OK(%struct.rtattr* %0, i32 %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %17, label %8
8: ; preds = %5, %13
%9 = phi %struct.rtattr* [ %14, %13 ], [ %0, %5 ]
%10 = getelementptr inbounds %struct.rtattr, %struct.rtattr* %9, i64 0, i32 0
%11 = load i16, i16* %10
%12 = icmp eq i16 %11, %2
br i1 %12, label %20, label %13
13: ; preds = %8
%14 = tail call %struct.rtattr* @RTA_NEXT(%struct.rtattr* %9, i32 %1)
%15 = tail call i64 @RTA_OK(%struct.rtattr* %14, i32 %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %8
17: ; preds = %13, %5, %3
%18 = phi i64* [ @EINVAL, %3 ], [ @ESRCH, %5 ], [ @ESRCH, %13 ]
%19 = load i64, i64* %18
store i64 %19, i64* @errno
br label %20
20: ; preds = %8, %17
%21 = phi %struct.rtattr* [ null, %17 ], [ %9, %8 ]
ret %struct.rtattr* %21
}