#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 /*<<< orphan*/ *sun_path;
};
struct sockaddr_storage {
  int ss_family;
};
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
  int /*<<< orphan*/ sin6_port;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
};

/* Variables and functions */
#define AF_INET 130
#define AF_INET6 129
#define AF_UNIX 128
int /*<<< orphan*/ abort();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
unsigned int hash_bytes(int /*<<< orphan*/ *, int, unsigned int);
int /*<<< orphan*/ stderr;
int strlen(int /*<<< orphan*/ *);
unsigned int addrhash(const struct sockaddr_storage *ss) {
  unsigned int r = 5381;
  switch (ss->ss_family) {
  case AF_INET: {
    const struct sockaddr_in *s = (const struct sockaddr_in *)ss;
    r = hash_bytes(&s->sin_port, 2, r);
    return hash_bytes(&s->sin_addr, 4, r);
  }
  case AF_INET6: {
    const struct sockaddr_in6 *s = (const struct sockaddr_in6 *)ss;
    r = hash_bytes(&s->sin6_port, 2, r);
    return hash_bytes(&s->sin6_addr, 16, r);
  }
  case AF_UNIX: {
    const struct sockaddr_un *s = (const struct sockaddr_un *)ss;
    return hash_bytes(s->sun_path, strlen(s->sun_path), r);
  }
  }
  fprintf(stderr, "addrhash: unknown address family %d\n", ss->ss_family);
  abort();
}


x86 assembly (clang, -O0):
<addrhash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x1505,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
sub    $0x80,%eax
je     1204 <addrhash+0xc4>
jmp    116c <addrhash+0x2c>
mov    -0x34(%rbp),%eax
sub    $0x81,%eax
je     11cb <addrhash+0x8b>
jmp    117f <addrhash+0x3f>
mov    -0x34(%rbp),%eax
sub    $0x82,%eax
jne    1239 <addrhash+0xf9>
jmp    1192 <addrhash+0x52>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x4,%rdi
mov    -0x14(%rbp),%edx
mov    $0x2,%esi
call   1060 <hash_bytes@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x4,%esi
call   1060 <hash_bytes@plt>
mov    %eax,-0x4(%rbp)
jmp    125b <addrhash+0x11b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x4,%rdi
mov    -0x14(%rbp),%edx
mov    $0x2,%esi
call   1060 <hash_bytes@plt>
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x10,%esi
call   1060 <hash_bytes@plt>
mov    %eax,-0x4(%rbp)
jmp    125b <addrhash+0x11b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
mov    -0x14(%rbp),%edx
call   1060 <hash_bytes@plt>
mov    %eax,-0x4(%rbp)
jmp    125b <addrhash+0x11b>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xdb1(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addrhash>:
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%edx
cmp    $0x80,%edx
je     117b <addrhash+0x3b>
cmp    $0x81,%edx
je     1196 <addrhash+0x56>
cmp    $0x82,%edx
jne    11b9 <addrhash+0x79>
lea    0x4(%rbx),%rdi
mov    $0x2,%esi
mov    $0x1505,%edx
call   1060 <hash_bytes@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
jmp    11b1 <addrhash+0x71>
mov    (%rbx),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1505,%edx
pop    %rbx
jmp    1060 <hash_bytes@plt>
lea    0x4(%rbx),%rdi
mov    $0x2,%esi
mov    $0x1505,%edx
call   1060 <hash_bytes@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
mov    %eax,%edx
pop    %rbx
jmp    1060 <hash_bytes@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr_in6 = type { i32, i32 }
%struct.sockaddr_un = type { i32* }
@stderr = global i32 0
@.str = [37 x i8] c"addrhash: unknown address family %d\0A\00"
define i32 @addrhash(%struct.sockaddr_storage* %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_storage*
%4 = alloca i32
%5 = alloca %struct.sockaddr_in*
%6 = alloca %struct.sockaddr_in6*
%7 = alloca %struct.sockaddr_un*
store %struct.sockaddr_storage* %0, %struct.sockaddr_storage** %3
store i32 5381, i32* %4
%8 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %3
%9 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %8, i32 0, i32 0
%10 = load i32, i32* %9
switch i32 %10, label %45 [
i32 130, label %11
i32 129, label %22
i32 128, label %33
]
11: ; preds = %1
%12 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %3
%13 = bitcast %struct.sockaddr_storage* %12 to %struct.sockaddr_in*
store %struct.sockaddr_in* %13, %struct.sockaddr_in** %5
%14 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 1
%16 = load i32, i32* %4
%17 = call i32 @hash_bytes(i32* %15, i32 2, i32 %16)
store i32 %17, i32* %4
%18 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 0
%20 = load i32, i32* %4
%21 = call i32 @hash_bytes(i32* %19, i32 4, i32 %20)
store i32 %21, i32* %2
br label %52
22: ; preds = %1
%23 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %3
%24 = bitcast %struct.sockaddr_storage* %23 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %24, %struct.sockaddr_in6** %6
%25 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %6
%26 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %25, i32 0, i32 1
%27 = load i32, i32* %4
%28 = call i32 @hash_bytes(i32* %26, i32 2, i32 %27)
store i32 %28, i32* %4
%29 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %6
%30 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %29, i32 0, i32 0
%31 = load i32, i32* %4
%32 = call i32 @hash_bytes(i32* %30, i32 16, i32 %31)
store i32 %32, i32* %2
br label %52
33: ; preds = %1
%34 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %3
%35 = bitcast %struct.sockaddr_storage* %34 to %struct.sockaddr_un*
store %struct.sockaddr_un* %35, %struct.sockaddr_un** %7
%36 = load %struct.sockaddr_un*, %struct.sockaddr_un** %7
%37 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %36, i32 0, i32 0
%38 = load i32*, i32** %37
%39 = load %struct.sockaddr_un*, %struct.sockaddr_un** %7
%40 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %39, i32 0, i32 0
%41 = load i32*, i32** %40
%42 = call i32 @strlen(i32* %41)
%43 = load i32, i32* %4
%44 = call i32 @hash_bytes(i32* %38, i32 %42, i32 %43)
store i32 %44, i32* %2
br label %52
45: ; preds = %1
%46 = load i32, i32* @stderr
%47 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %3
%48 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %49)
%51 = call i32 (...) @abort()
unreachable
52: ; preds = %33, %22, %11
%53 = load i32, i32* %2
ret i32 %53
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
@stderr = global i32 0
@.str = [37 x i8] c"addrhash: unknown address family %d\0A\00"
define i32 @addrhash(%struct.sockaddr_storage* %0) {
%2 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %0, i64 0, i32 0
%3 = load i32, i32* %2
switch i32 %3, label %17 [
i32 130, label %4
i32 129, label %8
i32 128, label %12
]
4: ; preds = %1
%5 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %0, i64 1, i32 0
%6 = tail call i32 @hash_bytes(i32* %5, i32 2, i32 5381)
%7 = tail call i32 @hash_bytes(i32* %2, i32 4, i32 %6)
br label %21
8: ; preds = %1
%9 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %0, i64 1, i32 0
%10 = tail call i32 @hash_bytes(i32* %9, i32 2, i32 5381)
%11 = tail call i32 @hash_bytes(i32* %2, i32 16, i32 %10)
br label %21
12: ; preds = %1
%13 = bitcast %struct.sockaddr_storage* %0 to i32**
%14 = load i32*, i32** %13
%15 = tail call i32 @strlen(i32* %14)
%16 = tail call i32 @hash_bytes(i32* %14, i32 %15, i32 5381)
br label %21
17: ; preds = %1
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %3)
%20 = tail call i32 (...) @abort()
unreachable
21: ; preds = %12, %8, %4
%22 = phi i32 [ %16, %12 ], [ %11, %8 ], [ %7, %4 ]
ret i32 %22
}