#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);
int rtnl_parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta,
                      int len) {
  memset(tb, 0, sizeof(struct rtattr *) * max);
  while (RTA_OK(rta, len)) {
    if (rta->rta_type <= max)
      tb[rta->rta_type] = rta;
    rta = RTA_NEXT(rta, len);
  }
  if (len)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<rtnl_parse_rtattr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1040 <RTA_OK@plt>
cmp    $0x0,%rax
je     11a8 <rtnl_parse_rtattr+0x78>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
cmp    -0x14(%rbp),%eax
jg     1193 <rtnl_parse_rtattr+0x63>
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq (%rcx),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <RTA_NEXT@plt>
mov    %rax,-0x20(%rbp)
jmp    115b <rtnl_parse_rtattr+0x2b>
cmpl   $0x0,-0x24(%rbp)
je     11be <rtnl_parse_rtattr+0x8e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c5 <rtnl_parse_rtattr+0x95>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
%struct.rtattr = type { i32 }
define i32 @rtnl_parse_rtattr(%struct.rtattr** %0, i32 %1, %struct.rtattr* %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.rtattr**
%7 = alloca i32
%8 = alloca %struct.rtattr*
%9 = alloca i32
store %struct.rtattr** %0, %struct.rtattr*** %6
store i32 %1, i32* %7
store %struct.rtattr* %2, %struct.rtattr** %8
store i32 %3, i32* %9
%10 = load %struct.rtattr**, %struct.rtattr*** %6
%11 = load i32, i32* %7
%12 = sext i32 %11 to i64
%13 = mul i64 8, %12
%14 = trunc i64 %13 to i32
%15 = call i32 @memset(%struct.rtattr** %10, i32 0, i32 %14)
br label %16
16: ; preds = %35, %4
%17 = load %struct.rtattr*, %struct.rtattr** %8
%18 = load i32, i32* %9
%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** %8
%23 = getelementptr inbounds %struct.rtattr, %struct.rtattr* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = load i32, i32* %7
%26 = icmp sle i32 %24, %25
br i1 %26, label %27, label %35
27: ; preds = %21
%28 = load %struct.rtattr*, %struct.rtattr** %8
%29 = load %struct.rtattr**, %struct.rtattr*** %6
%30 = load %struct.rtattr*, %struct.rtattr** %8
%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** %8
%37 = load i32, i32* %9
%38 = call %struct.rtattr* @RTA_NEXT(%struct.rtattr* %36, i32 %37)
store %struct.rtattr* %38, %struct.rtattr** %8
br label %16
39: ; preds = %16
%40 = load i32, i32* %9
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %39
store i32 -1, i32* %5
br label %44
43: ; preds = %39
store i32 0, i32* %5
br label %44
44: ; preds = %43, %42
%45 = load i32, i32* %5
ret i32 %45
}

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