#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;
};

/* Variables and functions */
struct rtattr *RTA_NEXT(struct rtattr *, int);
scalar_t__ RTA_OK(struct rtattr *, int);
int /*<<< orphan*/ memset(struct rtattr **, int /*<<< orphan*/, int);
void rtnl_parse(struct rtattr *tb[], int max, struct rtattr *rta, int len) {
  memset(tb, 0, sizeof(struct rtattr *) * (max + 1));
  while (RTA_OK(rta, len)) {
    if (rta->rta_type <= max)
      tb[rta->rta_type] = rta;
    rta = RTA_NEXT(rta, len);
  }
}


x86 assembly (clang, -O0):
<rtnl_parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <RTA_OK@plt>
cmp    $0x0,%rax
je     11ac <rtnl_parse+0x7c>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0xc(%rbp),%eax
jg     1197 <rtnl_parse+0x67>
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <RTA_NEXT@plt>
mov    %rax,-0x18(%rbp)
jmp    115f <rtnl_parse+0x2f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtnl_parse>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x8(,%r14,8),%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    %rbx,%rdi
jmp    1170 <rtnl_parse+0x40>
cs nopw 0x0(%rax,%rax,1)
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
je     118a <rtnl_parse+0x5a>
movslq (%rbx),%rax
cmp    %r14d,%eax
jg     1160 <rtnl_parse+0x30>
mov    %rbx,(%r15,%rax,8)
jmp    1160 <rtnl_parse+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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