#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 sockaddr_ll {
  int /*<<< orphan*/ sll_addr;
};
struct sockaddr_in6 {
  int dummy;
};
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int /*<<< orphan*/ sa_data;
};
typedef int sa_family_t;

/* Variables and functions */
#define AF_INET 130
#define AF_INET6 129
#define AF_PACKET 128
size_t ifa_sa_len(sa_family_t family, int len) {
  size_t size;
  switch (family) {
  case AF_INET:
    size = sizeof(struct sockaddr_in);
    break;
  case AF_INET6:
    size = sizeof(struct sockaddr_in6);
    break;
  case AF_PACKET:
    size = (size_t)(((struct sockaddr_ll *)NULL)->sll_addr) + len;
    if (size < sizeof(struct sockaddr_ll))
      size = sizeof(struct sockaddr_ll);
    break;
  default:
    size = (size_t)(((struct sockaddr *)NULL)->sa_data) + len;
    if (size < sizeof(struct sockaddr))
      size = sizeof(struct sockaddr);
  }
  return size;
}


x86 assembly (clang, -O0):
<ifa_sa_len>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x80,%eax
je     1160 <ifa_sa_len+0x60>
jmp    1120 <ifa_sa_len+0x20>
mov    -0x14(%rbp),%eax
sub    $0x81,%eax
je     1153 <ifa_sa_len+0x53>
jmp    1133 <ifa_sa_len+0x33>
mov    -0x14(%rbp),%eax
sub    $0x82,%eax
jne    1188 <ifa_sa_len+0x88>
jmp    1146 <ifa_sa_len+0x46>
movq   $0x4,-0x10(%rbp)
jmp    11b0 <ifa_sa_len+0xb0>
movq   $0x4,-0x10(%rbp)
jmp    11b0 <ifa_sa_len+0xb0>
xor    %eax,%eax
movslq (%rax),%rax
movslq -0x8(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x4,-0x10(%rbp)
jae    1183 <ifa_sa_len+0x83>
movq   $0x4,-0x10(%rbp)
jmp    11b0 <ifa_sa_len+0xb0>
xor    %eax,%eax
movslq (%rax),%rax
movslq -0x8(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x4,-0x10(%rbp)
jae    11ab <ifa_sa_len+0xab>
movq   $0x4,-0x10(%rbp)
jmp    11b0 <ifa_sa_len+0xb0>
mov    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ifa_sa_len>:
mov    $0x4,%eax
lea    -0x81(%rdi),%ecx
cmp    $0x2,%ecx
jb     1126 <ifa_sa_len+0x26>
cmp    $0x80,%edi
movslq %esi,%rcx
cmp    $0x5,%rcx
mov    $0x4,%eax
cmovae %rcx,%rax
ret

LLVM IR (-O0):
define i64 @ifa_sa_len(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
switch i32 %6, label %19 [
i32 130, label %7
i32 129, label %8
i32 128, label %9
]
7: ; preds = %2
store i64 4, i64* %5
br label %29
8: ; preds = %2
store i64 4, i64* %5
br label %29
9: ; preds = %2
%10 = load i32, i32* null
%11 = sext i32 %10 to i64
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = add i64 %11, %13
store i64 %14, i64* %5
%15 = load i64, i64* %5
%16 = icmp ult i64 %15, 4
br i1 %16, label %17, label %18
17: ; preds = %9
store i64 4, i64* %5
br label %18
18: ; preds = %17, %9
br label %29
19: ; preds = %2
%20 = load i32, i32* null
%21 = sext i32 %20 to i64
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = add i64 %21, %23
store i64 %24, i64* %5
%25 = load i64, i64* %5
%26 = icmp ult i64 %25, 4
br i1 %26, label %27, label %28
27: ; preds = %19
store i64 4, i64* %5
br label %28
28: ; preds = %27, %19
br label %29
29: ; preds = %28, %18, %8, %7
%30 = load i64, i64* %5
ret i64 %30
}

LLVM IR (-O2):
define i64 @ifa_sa_len(i32 %0, i32 %1) {
switch i32 %0, label %7 [
i32 130, label %11
i32 129, label %11
i32 128, label %3
]
3: ; preds = %2
%4 = sext i32 %1 to i64
%5 = icmp ugt i64 %4, 4
%6 = select i1 %5, i64 %4, i64 4
br label %11
7: ; preds = %2
%8 = sext i32 %1 to i64
%9 = icmp ugt i64 %8, 4
%10 = select i1 %9, i64 %8, i64 4
br label %11
11: ; preds = %2, %2, %7, %3
%12 = phi i64 [ %10, %7 ], [ %6, %3 ], [ 4, %2 ], [ 4, %2 ]
ret i64 %12
}