#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_un {
  int dummy;
};
struct sockaddr_storage {
  int dummy;
};
struct sockaddr_in6 {
  int dummy;
};
struct sockaddr_in {
  int dummy;
};
typedef int sa_family_t;

/* Variables and functions */
#define AF_INET 130
#define AF_INET6 129
#define AF_UNIX 128
size_t SUN_LEN(struct sockaddr_un *);
size_t get_sock_addr_len(sa_family_t family,
                         struct sockaddr_storage *sock_addr) {
  switch (family) {
  case AF_INET:
    return sizeof(struct sockaddr_in);
  case AF_INET6:
    return sizeof(struct sockaddr_in6);
  case AF_UNIX:
    return SUN_LEN((struct sockaddr_un *)sock_addr);
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_sock_addr_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x80,%eax
je     1175 <get_sock_addr_len+0x65>
jmp    1135 <get_sock_addr_len+0x25>
mov    -0x1c(%rbp),%eax
sub    $0x81,%eax
je     1168 <get_sock_addr_len+0x58>
jmp    1148 <get_sock_addr_len+0x38>
mov    -0x1c(%rbp),%eax
sub    $0x82,%eax
jne    1187 <get_sock_addr_len+0x77>
jmp    115b <get_sock_addr_len+0x4b>
movq   $0x4,-0x8(%rbp)
jmp    118f <get_sock_addr_len+0x7f>
movq   $0x4,-0x8(%rbp)
jmp    118f <get_sock_addr_len+0x7f>
mov    -0x18(%rbp),%rdi
call   1030 <SUN_LEN@plt>
mov    %rax,-0x8(%rbp)
jmp    118f <get_sock_addr_len+0x7f>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sock_addr_len>:
mov    $0x4,%eax
lea    -0x81(%rdi),%ecx
cmp    $0x2,%ecx
jb     1132 <get_sock_addr_len+0x22>
cmp    $0x80,%edi
jne    1130 <get_sock_addr_len+0x20>
mov    %rsi,%rdi
jmp    1030 <SUN_LEN@plt>
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr_un = type { i32 }
define i64 @get_sock_addr_len(i32 %0, %struct.sockaddr_storage* %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca %struct.sockaddr_storage*
store i32 %0, i32* %4
store %struct.sockaddr_storage* %1, %struct.sockaddr_storage** %5
%6 = load i32, i32* %4
switch i32 %6, label %13 [
i32 130, label %7
i32 129, label %8
i32 128, label %9
]
7: ; preds = %2
store i64 4, i64* %3
br label %14
8: ; preds = %2
store i64 4, i64* %3
br label %14
9: ; preds = %2
%10 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %5
%11 = bitcast %struct.sockaddr_storage* %10 to %struct.sockaddr_un*
%12 = call i64 @SUN_LEN(%struct.sockaddr_un* %11)
store i64 %12, i64* %3
br label %14
13: ; preds = %2
store i64 0, i64* %3
br label %14
14: ; preds = %13, %9, %8, %7
%15 = load i64, i64* %3
ret i64 %15
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr_un = type { i32 }
define i64 @get_sock_addr_len(i32 %0, %struct.sockaddr_storage* %1) {
switch i32 %0, label %6 [
i32 130, label %7
i32 129, label %7
i32 128, label %3
]
3: ; preds = %2
%4 = bitcast %struct.sockaddr_storage* %1 to %struct.sockaddr_un*
%5 = tail call i64 @SUN_LEN(%struct.sockaddr_un* %4)
br label %7
6: ; preds = %2
br label %7
7: ; preds = %2, %2, %6, %3
%8 = phi i64 [ 0, %6 ], [ %5, %3 ], [ 4, %2 ], [ 4, %2 ]
ret i64 %8
}