#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 in6_addr {
  int dummy;
};

/* Variables and functions */
scalar_t__ IN6_IS_ADDR_LINKLOCAL(struct in6_addr const *);
scalar_t__ IN6_IS_ADDR_LOOPBACK(struct in6_addr const *);
scalar_t__ IN6_IS_ADDR_SITELOCAL(struct in6_addr const *);
scalar_t__ IN6_IS_ADDR_UNSPECIFIED(struct in6_addr const *);
scalar_t__ IN6_IS_ADDR_V4COMPAT(struct in6_addr const *);
scalar_t__ IN6_IS_ADDR_V4MAPPED(struct in6_addr const *);
int filter_ipv6addr(const struct in6_addr *ifaddr, unsigned int flags) {
  if (IN6_IS_ADDR_UNSPECIFIED(ifaddr) || IN6_IS_ADDR_LOOPBACK(ifaddr)) {
    return 1;
  } else if (IN6_IS_ADDR_V4COMPAT(ifaddr) || IN6_IS_ADDR_V4MAPPED(ifaddr)) {
    return !(flags & 0x0400);
  } else if (IN6_IS_ADDR_LINKLOCAL(ifaddr)) {
    return !(flags & 0x0800);
  } else if (IN6_IS_ADDR_SITELOCAL(ifaddr)) {
    return !(flags & 0x1000);
  }
  return !(flags & 0x2000);
}


x86 assembly (clang, -O0):
<filter_ipv6addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <IN6_IS_ADDR_UNSPECIFIED@plt>
cmp    $0x0,%rax
jne    1195 <filter_ipv6addr+0x35>
mov    -0x10(%rbp),%rdi
call   1050 <IN6_IS_ADDR_LOOPBACK@plt>
cmp    $0x0,%rax
je     11a1 <filter_ipv6addr+0x41>
movl   $0x1,-0x4(%rbp)
jmp    126b <filter_ipv6addr+0x10b>
mov    -0x10(%rbp),%rdi
call   1060 <IN6_IS_ADDR_V4COMPAT@plt>
cmp    $0x0,%rax
jne    11c7 <filter_ipv6addr+0x67>
mov    -0x10(%rbp),%rdi
call   1030 <IN6_IS_ADDR_V4MAPPED@plt>
cmp    $0x0,%rax
je     11e4 <filter_ipv6addr+0x84>
mov    -0x14(%rbp),%eax
and    $0x400,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    126b <filter_ipv6addr+0x10b>
mov    -0x10(%rbp),%rdi
call   1070 <IN6_IS_ADDR_LINKLOCAL@plt>
cmp    $0x0,%rax
je     1214 <filter_ipv6addr+0xb4>
mov    -0x14(%rbp),%eax
and    $0x800,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    126b <filter_ipv6addr+0x10b>
mov    -0x10(%rbp),%rdi
call   1040 <IN6_IS_ADDR_SITELOCAL@plt>
cmp    $0x0,%rax
je     1244 <filter_ipv6addr+0xe4>
mov    -0x14(%rbp),%eax
and    $0x1000,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    126b <filter_ipv6addr+0x10b>
jmp    1249 <filter_ipv6addr+0xe9>
jmp    124e <filter_ipv6addr+0xee>
jmp    1253 <filter_ipv6addr+0xf3>
mov    -0x14(%rbp),%eax
and    $0x2000,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter_ipv6addr>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
call   1080 <IN6_IS_ADDR_UNSPECIFIED@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    11ad <filter_ipv6addr+0x4d>
mov    %rbx,%rdi
call   1050 <IN6_IS_ADDR_LOOPBACK@plt>
test   %rax,%rax
jne    11ad <filter_ipv6addr+0x4d>
mov    %rbx,%rdi
call   1060 <IN6_IS_ADDR_V4COMPAT@plt>
test   %rax,%rax
jne    11a0 <filter_ipv6addr+0x40>
mov    %rbx,%rdi
call   1030 <IN6_IS_ADDR_V4MAPPED@plt>
test   %rax,%rax
je     11b4 <filter_ipv6addr+0x54>
xor    %ebp,%ebp
test   $0x400,%r14d
sete   %bpl
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rbx,%rdi
call   1070 <IN6_IS_ADDR_LINKLOCAL@plt>
test   %rax,%rax
je     11cc <filter_ipv6addr+0x6c>
xor    %ebp,%ebp
test   $0x800,%r14d
jmp    11a9 <filter_ipv6addr+0x49>
mov    %rbx,%rdi
call   1040 <IN6_IS_ADDR_SITELOCAL@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11e4 <filter_ipv6addr+0x84>
test   $0x1000,%r14d
jmp    11a9 <filter_ipv6addr+0x49>
test   $0x2000,%r14d
jmp    11a9 <filter_ipv6addr+0x49>

LLVM IR (-O0):
%struct.in6_addr = type { i32 }
define i32 @filter_ipv6addr(%struct.in6_addr* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.in6_addr*
%5 = alloca i32
store %struct.in6_addr* %0, %struct.in6_addr** %4
store i32 %1, i32* %5
%6 = load %struct.in6_addr*, %struct.in6_addr** %4
%7 = call i64 @IN6_IS_ADDR_UNSPECIFIED(%struct.in6_addr* %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load %struct.in6_addr*, %struct.in6_addr** %4
%11 = call i64 @IN6_IS_ADDR_LOOPBACK(%struct.in6_addr* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9, %2
store i32 1, i32* %3
br label %57
14: ; preds = %9
%15 = load %struct.in6_addr*, %struct.in6_addr** %4
%16 = call i64 @IN6_IS_ADDR_V4COMPAT(%struct.in6_addr* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load %struct.in6_addr*, %struct.in6_addr** %4
%20 = call i64 @IN6_IS_ADDR_V4MAPPED(%struct.in6_addr* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %18, %14
%23 = load i32, i32* %5
%24 = and i32 %23, 1024
%25 = icmp ne i32 %24, 0
%26 = xor i1 %25, true
%27 = zext i1 %26 to i32
store i32 %27, i32* %3
br label %57
28: ; preds = %18
%29 = load %struct.in6_addr*, %struct.in6_addr** %4
%30 = call i64 @IN6_IS_ADDR_LINKLOCAL(%struct.in6_addr* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %28
%33 = load i32, i32* %5
%34 = and i32 %33, 2048
%35 = icmp ne i32 %34, 0
%36 = xor i1 %35, true
%37 = zext i1 %36 to i32
store i32 %37, i32* %3
br label %57
38: ; preds = %28
%39 = load %struct.in6_addr*, %struct.in6_addr** %4
%40 = call i64 @IN6_IS_ADDR_SITELOCAL(%struct.in6_addr* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %38
%43 = load i32, i32* %5
%44 = and i32 %43, 4096
%45 = icmp ne i32 %44, 0
%46 = xor i1 %45, true
%47 = zext i1 %46 to i32
store i32 %47, i32* %3
br label %57
48: ; preds = %38
br label %49
49: ; preds = %48
br label %50
50: ; preds = %49
br label %51
51: ; preds = %50
%52 = load i32, i32* %5
%53 = and i32 %52, 8192
%54 = icmp ne i32 %53, 0
%55 = xor i1 %54, true
%56 = zext i1 %55 to i32
store i32 %56, i32* %3
br label %57
57: ; preds = %51, %42, %32, %22, %13
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
%struct.in6_addr = type { i32 }
define i32 @filter_ipv6addr(%struct.in6_addr* %0, i32 %1) {
%3 = tail call i64 @IN6_IS_ADDR_UNSPECIFIED(%struct.in6_addr* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %36
5: ; preds = %2
%6 = tail call i64 @IN6_IS_ADDR_LOOPBACK(%struct.in6_addr* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %36
8: ; preds = %5
%9 = tail call i64 @IN6_IS_ADDR_V4COMPAT(%struct.in6_addr* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i64 @IN6_IS_ADDR_V4MAPPED(%struct.in6_addr* %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %11, %8
%15 = lshr i32 %1, 10
%16 = and i32 %15, 1
%17 = xor i32 %16, 1
br label %36
18: ; preds = %11
%19 = tail call i64 @IN6_IS_ADDR_LINKLOCAL(%struct.in6_addr* %0)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = lshr i32 %1, 11
%23 = and i32 %22, 1
%24 = xor i32 %23, 1
br label %36
25: ; preds = %18
%26 = tail call i64 @IN6_IS_ADDR_SITELOCAL(%struct.in6_addr* %0)
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %25
%29 = lshr i32 %1, 12
%30 = and i32 %29, 1
%31 = xor i32 %30, 1
br label %36
32: ; preds = %25
%33 = lshr i32 %1, 13
%34 = and i32 %33, 1
%35 = xor i32 %34, 1
br label %36
36: ; preds = %2, %5, %32, %28, %21, %14
%37 = phi i32 [ %17, %14 ], [ %24, %21 ], [ %31, %28 ], [ %35, %32 ], [ 1, %5 ], [ 1, %2 ]
ret i32 %37
}