#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 nlmsghdr {
  int nlmsg_type;
};
struct ifinfomsg {
  int ifi_flags;
};

/* Variables and functions */
int IFF_RUNNING;
struct ifinfomsg *NLMSG_DATA(struct nlmsghdr *);
#define NLMSG_DONE 131
#define NLMSG_ERROR 130
struct nlmsghdr *NLMSG_NEXT(struct nlmsghdr *, int);
scalar_t__ NLMSG_OK(struct nlmsghdr *, int);
#define RTM_NEWADDR 129
#define RTM_NEWLINK 128
void ifup_scan_event(struct nlmsghdr *nh, int len, int *seen_flags) {
  struct ifinfomsg *ifi;
  for (; NLMSG_OK(nh, len); nh = NLMSG_NEXT(nh, len)) {
    switch (nh->nlmsg_type) {
    case NLMSG_DONE:
      return;
    case NLMSG_ERROR:
      return;
    case RTM_NEWLINK:
      ifi = NLMSG_DATA(nh);
      if (ifi->ifi_flags & IFF_RUNNING) {
        *seen_flags |= 1;
      }
      break;
    case RTM_NEWADDR:
      *seen_flags |= 2;
      break;
    }
  }
}


x86 assembly (clang, -O0):
<ifup_scan_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <NLMSG_OK@plt>
cmp    $0x0,%rax
je     11e9 <ifup_scan_event+0xb9>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x3,%eax
ja     11cf <ifup_scan_event+0x9f>
mov    -0x28(%rbp),%rax
lea    0xe84(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    11e9 <ifup_scan_event+0xb9>
jmp    11e9 <ifup_scan_event+0xb9>
mov    -0x8(%rbp),%rdi
call   1040 <NLMSG_DATA@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    0x2e3f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11bf <ifup_scan_event+0x8f>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
or     $0x1,%ecx
mov    %ecx,(%rax)
jmp    11cf <ifup_scan_event+0x9f>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
or     $0x2,%ecx
mov    %ecx,(%rax)
jmp    11d4 <ifup_scan_event+0xa4>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <NLMSG_NEXT@plt>
mov    %rax,-0x8(%rbp)
jmp    1143 <ifup_scan_event+0x13>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ifup_scan_event>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <NLMSG_OK@plt>
test   %rax,%rax
je     11b2 <ifup_scan_event+0x82>
mov    0x2e98(%rip),%r15
jmp    1193 <ifup_scan_event+0x63>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <NLMSG_DATA@plt>
mov    (%r15),%edx
mov    $0x1,%ecx
test   %edx,(%rax)
je     1177 <ifup_scan_event+0x47>
or     %ecx,(%r14)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <NLMSG_NEXT@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
call   1030 <NLMSG_OK@plt>
test   %rax,%rax
je     11b2 <ifup_scan_event+0x82>
mov    (%rbx),%eax
cmp    $0x80,%eax
je     1160 <ifup_scan_event+0x30>
mov    $0x2,%ecx
cmp    $0x81,%eax
je     1174 <ifup_scan_event+0x44>
add    $0xffffff7e,%eax
cmp    $0x2,%eax
jae    1177 <ifup_scan_event+0x47>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.nlmsghdr = type { i32 }
%struct.ifinfomsg = type { i32 }
@IFF_RUNNING = global i32 0
define void @ifup_scan_event(%struct.nlmsghdr* %0, i32 %1, i32* %2) {
%4 = alloca %struct.nlmsghdr*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca %struct.ifinfomsg*
store %struct.nlmsghdr* %0, %struct.nlmsghdr** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
br label %8
8: ; preds = %38, %3
%9 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%10 = load i32, i32* %5
%11 = call i64 @NLMSG_OK(%struct.nlmsghdr* %9, i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %42
13: ; preds = %8
%14 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%15 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %14, i32 0, i32 0
%16 = load i32, i32* %15
switch i32 %16, label %37 [
i32 131, label %17
i32 130, label %18
i32 128, label %19
i32 129, label %33
]
17: ; preds = %13
br label %42
18: ; preds = %13
br label %42
19: ; preds = %13
%20 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%21 = call %struct.ifinfomsg* @NLMSG_DATA(%struct.nlmsghdr* %20)
store %struct.ifinfomsg* %21, %struct.ifinfomsg** %7
%22 = load %struct.ifinfomsg*, %struct.ifinfomsg** %7
%23 = getelementptr inbounds %struct.ifinfomsg, %struct.ifinfomsg* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = load i32, i32* @IFF_RUNNING
%26 = and i32 %24, %25
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %19
%29 = load i32*, i32** %6
%30 = load i32, i32* %29
%31 = or i32 %30, 1
store i32 %31, i32* %29
br label %32
32: ; preds = %28, %19
br label %37
33: ; preds = %13
%34 = load i32*, i32** %6
%35 = load i32, i32* %34
%36 = or i32 %35, 2
store i32 %36, i32* %34
br label %37
37: ; preds = %13, %33, %32
br label %38
38: ; preds = %37
%39 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%40 = load i32, i32* %5
%41 = call %struct.nlmsghdr* @NLMSG_NEXT(%struct.nlmsghdr* %39, i32 %40)
store %struct.nlmsghdr* %41, %struct.nlmsghdr** %4
br label %8
42: ; preds = %17, %18, %8
ret void
}

LLVM IR (-O2):
%struct.nlmsghdr = type { i32 }
%struct.ifinfomsg = type { i32 }
@IFF_RUNNING = global i32 0
define void @ifup_scan_event(%struct.nlmsghdr* %0, i32 %1, i32* nocapture %2) {
%4 = tail call i64 @NLMSG_OK(%struct.nlmsghdr* %0, i32 %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %25, label %6
6: ; preds = %3, %21
%7 = phi %struct.nlmsghdr* [ %22, %21 ], [ %0, %3 ]
%8 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %7, i64 0, i32 0
%9 = load i32, i32* %8
switch i32 %9, label %21 [
i32 131, label %25
i32 130, label %25
i32 128, label %10
i32 129, label %17
]
10: ; preds = %6
%11 = tail call %struct.ifinfomsg* @NLMSG_DATA(%struct.nlmsghdr* %7)
%12 = getelementptr inbounds %struct.ifinfomsg, %struct.ifinfomsg* %11, i64 0, i32 0
%13 = load i32, i32* %12
%14 = load i32, i32* @IFF_RUNNING
%15 = and i32 %14, %13
%16 = icmp eq i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %6, %10
%18 = phi i32 [ 1, %10 ], [ 2, %6 ]
%19 = load i32, i32* %2
%20 = or i32 %19, %18
store i32 %20, i32* %2
br label %21
21: ; preds = %17, %6, %10
%22 = tail call %struct.nlmsghdr* @NLMSG_NEXT(%struct.nlmsghdr* %7, i32 %1)
%23 = tail call i64 @NLMSG_OK(%struct.nlmsghdr* %22, i32 %1)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %6
25: ; preds = %6, %6, %21, %3
ret void
}