#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 *s6_addr;
};

/* 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_MULTICAST(struct in6_addr const *);
scalar_t__ IN6_IS_ADDR_SITELOCAL(struct in6_addr const *);
int scopeof(const struct in6_addr *a) {
  if (IN6_IS_ADDR_MULTICAST(a))
    return a->s6_addr[1] & 15;
  if (IN6_IS_ADDR_LINKLOCAL(a))
    return 2;
  if (IN6_IS_ADDR_LOOPBACK(a))
    return 2;
  if (IN6_IS_ADDR_SITELOCAL(a))
    return 5;
  return 14;
}


x86 assembly (clang, -O0):
<scopeof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <IN6_IS_ADDR_MULTICAST@plt>
cmp    $0x0,%rax
je     1174 <scopeof+0x34>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x4(%rax),%eax
and    $0xf,%eax
mov    %eax,-0x4(%rbp)
jmp    11d8 <scopeof+0x98>
mov    -0x10(%rbp),%rdi
call   1060 <IN6_IS_ADDR_LINKLOCAL@plt>
cmp    $0x0,%rax
je     1193 <scopeof+0x53>
movl   $0x2,-0x4(%rbp)
jmp    11d8 <scopeof+0x98>
mov    -0x10(%rbp),%rdi
call   1040 <IN6_IS_ADDR_LOOPBACK@plt>
cmp    $0x0,%rax
je     11b2 <scopeof+0x72>
movl   $0x2,-0x4(%rbp)
jmp    11d8 <scopeof+0x98>
mov    -0x10(%rbp),%rdi
call   1030 <IN6_IS_ADDR_SITELOCAL@plt>
cmp    $0x0,%rax
je     11d1 <scopeof+0x91>
movl   $0x5,-0x4(%rbp)
jmp    11d8 <scopeof+0x98>
movl   $0xe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scopeof>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <IN6_IS_ADDR_MULTICAST@plt>
test   %rax,%rax
je     115b <scopeof+0x1b>
mov    (%rbx),%rax
mov    0x4(%rax),%ebp
and    $0xf,%ebp
jmp    1190 <scopeof+0x50>
mov    %rbx,%rdi
call   1060 <IN6_IS_ADDR_LINKLOCAL@plt>
mov    $0x2,%ebp
test   %rax,%rax
jne    1190 <scopeof+0x50>
mov    %rbx,%rdi
call   1040 <IN6_IS_ADDR_LOOPBACK@plt>
test   %rax,%rax
jne    1190 <scopeof+0x50>
mov    %rbx,%rdi
call   1030 <IN6_IS_ADDR_SITELOCAL@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    (%rcx,%rcx,8),%ebp
add    $0x5,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.in6_addr = type { i32* }
define i32 @scopeof(%struct.in6_addr* %0) {
%2 = alloca i32
%3 = alloca %struct.in6_addr*
store %struct.in6_addr* %0, %struct.in6_addr** %3
%4 = load %struct.in6_addr*, %struct.in6_addr** %3
%5 = call i64 @IN6_IS_ADDR_MULTICAST(%struct.in6_addr* %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %1
%8 = load %struct.in6_addr*, %struct.in6_addr** %3
%9 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %8, i32 0, i32 0
%10 = load i32*, i32** %9
%11 = getelementptr inbounds i32, i32* %10, i64 1
%12 = load i32, i32* %11
%13 = and i32 %12, 15
store i32 %13, i32* %2
br label %30
14: ; preds = %1
%15 = load %struct.in6_addr*, %struct.in6_addr** %3
%16 = call i64 @IN6_IS_ADDR_LINKLOCAL(%struct.in6_addr* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 2, i32* %2
br label %30
19: ; preds = %14
%20 = load %struct.in6_addr*, %struct.in6_addr** %3
%21 = call i64 @IN6_IS_ADDR_LOOPBACK(%struct.in6_addr* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 2, i32* %2
br label %30
24: ; preds = %19
%25 = load %struct.in6_addr*, %struct.in6_addr** %3
%26 = call i64 @IN6_IS_ADDR_SITELOCAL(%struct.in6_addr* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 5, i32* %2
br label %30
29: ; preds = %24
store i32 14, i32* %2
br label %30
30: ; preds = %29, %28, %23, %18, %7
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
%struct.in6_addr = type { i32* }
define i32 @scopeof(%struct.in6_addr* %0) {
%2 = tail call i64 @IN6_IS_ADDR_MULTICAST(%struct.in6_addr* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %0, i64 0, i32 0
%6 = load i32*, i32** %5
%7 = getelementptr inbounds i32, i32* %6, i64 1
%8 = load i32, i32* %7
%9 = and i32 %8, 15
br label %20
10: ; preds = %1
%11 = tail call i64 @IN6_IS_ADDR_LINKLOCAL(%struct.in6_addr* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = tail call i64 @IN6_IS_ADDR_LOOPBACK(%struct.in6_addr* %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = tail call i64 @IN6_IS_ADDR_SITELOCAL(%struct.in6_addr* %0)
%18 = icmp eq i64 %17, 0
%19 = select i1 %18, i32 14, i32 5
br label %20
20: ; preds = %16, %13, %10, %4
%21 = phi i32 [ %9, %4 ], [ 2, %10 ], [ 2, %13 ], [ %19, %16 ]
ret i32 %21
}