#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 {
  int dummy;
};
struct ifinfomsg {
  int /*<<< orphan*/ ifi_flags;
};
typedef int int32_t;

/* Variables and functions */
size_t NLMSG_ALIGNTO;
scalar_t__ NlGetIfInfoByIndex(int, struct nlmsghdr *, int, int *,
                              struct ifinfomsg **);
int /*<<< orphan*/ assert(int);
bool NetlinkGetInterfaceFlags(int32_t nl_len, void *nl_msg, int32_t if_index,
                              uint32_t *ifi_flags) {
  assert(0 <= nl_len && nl_len < (1 << 16));
  assert(nl_msg != NULL && (size_t)nl_msg % NLMSG_ALIGNTO == 0);
  assert(ifi_flags != NULL);
  struct nlmsghdr *nh = (struct nlmsghdr *)nl_msg;
  int32_t rt_len;
  struct ifinfomsg *rt_msg;
  if (NlGetIfInfoByIndex(nl_len, nh, if_index, &rt_len, &rt_msg)) {
    *ifi_flags = rt_msg->ifi_flags;
    return true;
  }
  return false;
}


x86 assembly (clang, -O0):
<NetlinkGetInterfaceFlags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
xor    %ecx,%ecx
cmp    -0x8(%rbp),%ecx
mov    %al,-0x39(%rbp)
jg     1153 <NetlinkGetInterfaceFlags+0x33>
cmpl   $0x10000,-0x8(%rbp)
setl   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x3a(%rbp)
je     118a <NetlinkGetInterfaceFlags+0x6a>
mov    -0x10(%rbp),%rax
mov    0x2e6d(%rip),%rcx
xor    %edx,%edx
divq   (%rcx)
cmp    $0x0,%rdx
sete   %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    -0x2c(%rbp),%rcx
lea    -0x38(%rbp),%r8
call   1040 <NlGetIfInfoByIndex@plt>
cmp    $0x0,%rax
je     11ea <NetlinkGetInterfaceFlags+0xca>
mov    -0x38(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11f1 <NetlinkGetInterfaceFlags+0xd1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NetlinkGetInterfaceFlags>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r15
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
cmp    $0x10000,%ebp
setb   %dil
call   1030 <assert@plt>
xor    %r12d,%r12d
mov    $0x0,%edi
test   %rbx,%rbx
je     1184 <NetlinkGetInterfaceFlags+0x64>
mov    0x2e8c(%rip),%rax
mov    (%rax),%rcx
mov    %rbx,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     1175 <NetlinkGetInterfaceFlags+0x55>
mov    %rbx,%rax
xor    %edx,%edx
div    %rcx
jmp    117b <NetlinkGetInterfaceFlags+0x5b>
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
xor    %edi,%edi
test   %rdx,%rdx
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1030 <assert@plt>
lea    0xc(%rsp),%rcx
mov    %rsp,%r8
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <NlGetIfInfoByIndex@plt>
test   %rax,%rax
je     11c0 <NetlinkGetInterfaceFlags+0xa0>
mov    (%rsp),%rax
mov    (%rax),%eax
mov    %eax,(%r15)
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.nlmsghdr = type { i32 }
%struct.ifinfomsg = type { i32 }
@NLMSG_ALIGNTO = global i64 0
define i32 @NetlinkGetInterfaceFlags(i32 %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca %struct.nlmsghdr*
%11 = alloca i32
%12 = alloca %struct.ifinfomsg*
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%13 = load i32, i32* %6
%14 = icmp sle i32 0, %13
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 65536
br label %18
18: ; preds = %15, %4
%19 = phi i1 [ false, %4 ], [ %17, %15 ]
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i8*, i8** %7
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %30
24: ; preds = %18
%25 = load i8*, i8** %7
%26 = ptrtoint i8* %25 to i64
%27 = load i64, i64* @NLMSG_ALIGNTO
%28 = urem i64 %26, %27
%29 = icmp eq i64 %28, 0
br label %30
30: ; preds = %24, %18
%31 = phi i1 [ false, %18 ], [ %29, %24 ]
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load i32*, i32** %9
%35 = icmp ne i32* %34, null
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = load i8*, i8** %7
%39 = bitcast i8* %38 to %struct.nlmsghdr*
store %struct.nlmsghdr* %39, %struct.nlmsghdr** %10
%40 = load i32, i32* %6
%41 = load %struct.nlmsghdr*, %struct.nlmsghdr** %10
%42 = load i32, i32* %8
%43 = call i64 @NlGetIfInfoByIndex(i32 %40, %struct.nlmsghdr* %41, i32 %42, i32* %11, %struct.ifinfomsg** %12)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %30
%46 = load %struct.ifinfomsg*, %struct.ifinfomsg** %12
%47 = getelementptr inbounds %struct.ifinfomsg, %struct.ifinfomsg* %46, i32 0, i32 0
%48 = load i32, i32* %47
%49 = load i32*, i32** %9
store i32 %48, i32* %49
store i32 1, i32* %5
br label %51
50: ; preds = %30
store i32 0, i32* %5
br label %51
51: ; preds = %50, %45
%52 = load i32, i32* %5
ret i32 %52
}

LLVM IR (-O2):
%struct.ifinfomsg = type { i32 }
%struct.nlmsghdr = type { i32 }
@NLMSG_ALIGNTO = global i64 0
define i32 @NetlinkGetInterfaceFlags(i32 %0, i8* %1, i32 %2, i32* writeonly %3) {
%5 = alloca i32
%6 = alloca %struct.ifinfomsg*
%7 = icmp ult i32 %0, 65536
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = icmp eq i8* %1, null
br i1 %10, label %17, label %11
11: ; preds = %4
%12 = ptrtoint i8* %1 to i64
%13 = load i64, i64* @NLMSG_ALIGNTO
%14 = urem i64 %12, %13
%15 = icmp eq i64 %14, 0
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %11, %4
%18 = phi i32 [ 0, %4 ], [ %16, %11 ]
%19 = tail call i32 @assert(i32 %18)
%20 = icmp ne i32* %3, null
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
%23 = bitcast i8* %1 to %struct.nlmsghdr*
%24 = bitcast i32* %5 to i8*
%25 = bitcast %struct.ifinfomsg** %6 to i8*
%26 = call i64 @NlGetIfInfoByIndex(i32 %0, %struct.nlmsghdr* %23, i32 %2, i32* %5, %struct.ifinfomsg** %6)
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %17
%29 = load %struct.ifinfomsg*, %struct.ifinfomsg** %6
%30 = getelementptr inbounds %struct.ifinfomsg, %struct.ifinfomsg* %29, i64 0, i32 0
%31 = load i32, i32* %30
store i32 %31, i32* %3
br label %32
32: ; preds = %17, %28
%33 = phi i32 [ 1, %28 ], [ 0, %17 ]
ret i32 %33
}