#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 /*<<< orphan*/ uint32_t;
struct nlmsghdr {
  scalar_t__ nlmsg_type;
};
struct ifinfomsg {
  int ifi_index;
};
typedef int int32_t;

/* Variables and functions */
scalar_t__ IsIfInfoMsg(struct nlmsghdr *);
scalar_t__ NLMSG_DATA(struct nlmsghdr *);
scalar_t__ NLMSG_DONE;
struct nlmsghdr *NLMSG_NEXT(struct nlmsghdr *, int);
scalar_t__ NLMSG_OK(struct nlmsghdr *, int /*<<< orphan*/);
scalar_t__ NLMSG_PAYLOAD(struct nlmsghdr *, int);
int /*<<< orphan*/ assert(int);
bool NlGetIfInfoByIndex(int32_t nl_len, struct nlmsghdr *nl_msg,
                        int32_t if_index, int32_t *rt_len,
                        struct ifinfomsg **rt_msg) {
  assert(0 <= nl_len && nl_len < (1 << 16));
  assert(nl_msg != NULL);
  assert(rt_len != NULL);
  assert(rt_msg != NULL);
  for (struct nlmsghdr *nh = nl_msg;
       NLMSG_OK(nh, (uint32_t)nl_len) && nh->nlmsg_type != NLMSG_DONE;
       nh = NLMSG_NEXT(nh, nl_len)) {
    if (IsIfInfoMsg(nh)) {
      *rt_len = (int32_t)NLMSG_PAYLOAD(nh, sizeof(struct ifinfomsg));
      *rt_msg = (struct ifinfomsg *)NLMSG_DATA(nh);
      if ((*rt_msg)->ifi_index == if_index) {
        return true;
      }
    }
  }
  return false;
}


x86 assembly (clang, -O0):
<NlGetIfInfoByIndex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
xor    %eax,%eax
xor    %ecx,%ecx
cmp    -0x8(%rbp),%ecx
mov    %al,-0x31(%rbp)
jg     1197 <NlGetIfInfoByIndex+0x37>
cmpl   $0x10000,-0x8(%rbp)
setl   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x28(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <NLMSG_OK@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x32(%rbp)
je     1217 <NlGetIfInfoByIndex+0xb7>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    0x2dd2(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
mov    %al,-0x32(%rbp)
mov    -0x32(%rbp),%al
test   $0x1,%al
jne    1227 <NlGetIfInfoByIndex+0xc7>
jmp    12a0 <NlGetIfInfoByIndex+0x140>
mov    -0x30(%rbp),%rdi
call   1080 <IsIfInfoMsg@plt>
cmp    $0x0,%rax
je     1286 <NlGetIfInfoByIndex+0x126>
mov    -0x30(%rbp),%rdi
mov    $0x4,%esi
call   1050 <NLMSG_PAYLOAD@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rdi
call   1060 <NLMSG_DATA@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
cmp    -0x14(%rbp),%eax
jne    1281 <NlGetIfInfoByIndex+0x121>
movl   $0x1,-0x4(%rbp)
jmp    12a7 <NlGetIfInfoByIndex+0x147>
jmp    1286 <NlGetIfInfoByIndex+0x126>
jmp    128b <NlGetIfInfoByIndex+0x12b>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1070 <NLMSG_NEXT@plt>
mov    %rax,-0x30(%rbp)
jmp    11e2 <NlGetIfInfoByIndex+0x82>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NlGetIfInfoByIndex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r12
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
cmp    $0x10000,%ebp
setb   %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %r12,%r12
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <NLMSG_OK@plt>
xor    %ecx,%ecx
test   %rax,%rax
je     122c <NlGetIfInfoByIndex+0xcc>
mov    0x2e14(%rip),%r13
jmp    11ec <NlGetIfInfoByIndex+0x8c>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <NLMSG_NEXT@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
call   1030 <NLMSG_OK@plt>
test   %rax,%rax
je     122a <NlGetIfInfoByIndex+0xca>
mov    (%rbx),%rax
cmp    0x0(%r13),%rax
je     122a <NlGetIfInfoByIndex+0xca>
mov    %rbx,%rdi
call   1080 <IsIfInfoMsg@plt>
test   %rax,%rax
je     11d0 <NlGetIfInfoByIndex+0x70>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1050 <NLMSG_PAYLOAD@plt>
mov    %eax,(%r12)
mov    %rbx,%rdi
call   1060 <NLMSG_DATA@plt>
mov    %rax,(%r14)
cmp    %r15d,(%rax)
jne    11d0 <NlGetIfInfoByIndex+0x70>
mov    $0x1,%ecx
jmp    122c <NlGetIfInfoByIndex+0xcc>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.nlmsghdr = type { i64 }
%struct.ifinfomsg = type { i32 }
@NLMSG_DONE = global i64 0
define i32 @NlGetIfInfoByIndex(i32 %0, %struct.nlmsghdr* %1, i32 %2, i32* %3, %struct.ifinfomsg** %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.nlmsghdr*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca %struct.ifinfomsg**
%12 = alloca %struct.nlmsghdr*
store i32 %0, i32* %7
store %struct.nlmsghdr* %1, %struct.nlmsghdr** %8
store i32 %2, i32* %9
store i32* %3, i32** %10
store %struct.ifinfomsg** %4, %struct.ifinfomsg*** %11
%13 = load i32, i32* %7
%14 = icmp sle i32 0, %13
br i1 %14, label %15, label %18
15: ; preds = %5
%16 = load i32, i32* %7
%17 = icmp slt i32 %16, 65536
br label %18
18: ; preds = %15, %5
%19 = phi i1 [ false, %5 ], [ %17, %15 ]
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load %struct.nlmsghdr*, %struct.nlmsghdr** %8
%23 = icmp ne %struct.nlmsghdr* %22, null
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i32*, i32** %10
%27 = icmp ne i32* %26, null
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load %struct.ifinfomsg**, %struct.ifinfomsg*** %11
%31 = icmp ne %struct.ifinfomsg** %30, null
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load %struct.nlmsghdr*, %struct.nlmsghdr** %8
store %struct.nlmsghdr* %34, %struct.nlmsghdr** %12
br label %35
35: ; preds = %70, %18
%36 = load %struct.nlmsghdr*, %struct.nlmsghdr** %12
%37 = load i32, i32* %7
%38 = call i64 @NLMSG_OK(%struct.nlmsghdr* %36, i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %35
%41 = load %struct.nlmsghdr*, %struct.nlmsghdr** %12
%42 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %41, i32 0, i32 0
%43 = load i64, i64* %42
%44 = load i64, i64* @NLMSG_DONE
%45 = icmp ne i64 %43, %44
br label %46
46: ; preds = %40, %35
%47 = phi i1 [ false, %35 ], [ %45, %40 ]
br i1 %47, label %48, label %74
48: ; preds = %46
%49 = load %struct.nlmsghdr*, %struct.nlmsghdr** %12
%50 = call i64 @IsIfInfoMsg(%struct.nlmsghdr* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %69
52: ; preds = %48
%53 = load %struct.nlmsghdr*, %struct.nlmsghdr** %12
%54 = call i64 @NLMSG_PAYLOAD(%struct.nlmsghdr* %53, i32 4)
%55 = trunc i64 %54 to i32
%56 = load i32*, i32** %10
store i32 %55, i32* %56
%57 = load %struct.nlmsghdr*, %struct.nlmsghdr** %12
%58 = call i64 @NLMSG_DATA(%struct.nlmsghdr* %57)
%59 = inttoptr i64 %58 to %struct.ifinfomsg*
%60 = load %struct.ifinfomsg**, %struct.ifinfomsg*** %11
store %struct.ifinfomsg* %59, %struct.ifinfomsg** %60
%61 = load %struct.ifinfomsg**, %struct.ifinfomsg*** %11
%62 = load %struct.ifinfomsg*, %struct.ifinfomsg** %61
%63 = getelementptr inbounds %struct.ifinfomsg, %struct.ifinfomsg* %62, i32 0, i32 0
%64 = load i32, i32* %63
%65 = load i32, i32* %9
%66 = icmp eq i32 %64, %65
br i1 %66, label %67, label %68
67: ; preds = %52
store i32 1, i32* %6
br label %75
68: ; preds = %52
br label %69
69: ; preds = %68, %48
br label %70
70: ; preds = %69
%71 = load %struct.nlmsghdr*, %struct.nlmsghdr** %12
%72 = load i32, i32* %7
%73 = call %struct.nlmsghdr* @NLMSG_NEXT(%struct.nlmsghdr* %71, i32 %72)
store %struct.nlmsghdr* %73, %struct.nlmsghdr** %12
br label %35
74: ; preds = %46
store i32 0, i32* %6
br label %75
75: ; preds = %74, %67
%76 = load i32, i32* %6
ret i32 %76
}

LLVM IR (-O2):
%struct.nlmsghdr = type { i64 }
%struct.ifinfomsg = type { i32 }
@NLMSG_DONE = global i64 0
define i32 @NlGetIfInfoByIndex(i32 %0, %struct.nlmsghdr* %1, i32 %2, i32* writeonly %3, %struct.ifinfomsg** writeonly %4) {
%6 = icmp ult i32 %0, 65536
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = icmp ne %struct.nlmsghdr* %1, null
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = icmp ne i32* %3, null
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = icmp ne %struct.ifinfomsg** %4, null
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = tail call i64 @NLMSG_OK(%struct.nlmsghdr* %1, i32 %0)
%19 = icmp eq i64 %18, 0
br i1 %19, label %41, label %20
20: ; preds = %5, %37
%21 = phi %struct.nlmsghdr* [ %38, %37 ], [ %1, %5 ]
%22 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %21, i64 0, i32 0
%23 = load i64, i64* %22
%24 = load i64, i64* @NLMSG_DONE
%25 = icmp eq i64 %23, %24
br i1 %25, label %41, label %26
26: ; preds = %20
%27 = tail call i64 @IsIfInfoMsg(%struct.nlmsghdr* %21)
%28 = icmp eq i64 %27, 0
br i1 %28, label %37, label %29
29: ; preds = %26
%30 = tail call i64 @NLMSG_PAYLOAD(%struct.nlmsghdr* %21, i32 4)
%31 = trunc i64 %30 to i32
store i32 %31, i32* %3
%32 = tail call i64 @NLMSG_DATA(%struct.nlmsghdr* %21)
%33 = inttoptr i64 %32 to %struct.ifinfomsg*
store %struct.ifinfomsg* %33, %struct.ifinfomsg** %4
%34 = getelementptr inbounds %struct.ifinfomsg, %struct.ifinfomsg* %33, i64 0, i32 0
%35 = load i32, i32* %34
%36 = icmp eq i32 %35, %2
br i1 %36, label %41, label %37
37: ; preds = %26, %29
%38 = tail call %struct.nlmsghdr* @NLMSG_NEXT(%struct.nlmsghdr* %21, i32 %0)
%39 = tail call i64 @NLMSG_OK(%struct.nlmsghdr* %38, i32 %0)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %20
41: ; preds = %37, %20, %29, %5
%42 = phi i32 [ 0, %5 ], [ 1, %29 ], [ 0, %20 ], [ 0, %37 ]
ret i32 %42
}