#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 */
typedef int uint16_t;
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int sa_family;
};
struct in_addr {
  int dummy;
};
struct in6_addr {
  int dummy;
};

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int memcmp(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int sockaddrcmp(struct sockaddr *s1, struct sockaddr *s2) {
  uint16_t family = s1->sa_family;
  if (s1->sa_family == s2->sa_family) {
    switch (family) {
    case AF_INET:
      return memcmp(&((struct sockaddr_in *)s1)->sin_addr,
                    &((struct sockaddr_in *)s2)->sin_addr,
                    sizeof(struct in_addr));
    case AF_INET6:
      return memcmp(&((struct sockaddr_in6 *)s1)->sin6_addr,
                    &((struct sockaddr_in6 *)s2)->sin6_addr,
                    sizeof(struct in6_addr));
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<sockaddrcmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jne    119d <sockaddrcmp+0x8d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x80,%eax
je     117e <sockaddrcmp+0x6e>
jmp    1151 <sockaddrcmp+0x41>
mov    -0x20(%rbp),%eax
sub    $0x81,%eax
jne    1198 <sockaddrcmp+0x88>
jmp    1164 <sockaddrcmp+0x54>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
mov    %eax,-0x4(%rbp)
jmp    11a4 <sockaddrcmp+0x94>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
mov    %eax,-0x4(%rbp)
jmp    11a4 <sockaddrcmp+0x94>
jmp    119d <sockaddrcmp+0x8d>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sockaddrcmp>:
mov    (%rdi),%eax
cmp    (%rsi),%eax
jne    112a <sockaddrcmp+0x1a>
and    $0xfffffffe,%eax
cmp    $0x80,%eax
jne    112a <sockaddrcmp+0x1a>
mov    $0x4,%edx
jmp    1030 <memcmp@plt>
mov    $0x1,%eax
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
define i32 @sockaddrcmp(%struct.sockaddr* %0, %struct.sockaddr* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr*
%5 = alloca %struct.sockaddr*
%6 = alloca i32
store %struct.sockaddr* %0, %struct.sockaddr** %4
store %struct.sockaddr* %1, %struct.sockaddr** %5
%7 = load %struct.sockaddr*, %struct.sockaddr** %4
%8 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %7, i32 0, i32 0
%9 = load i32, i32* %8
store i32 %9, i32* %6
%10 = load %struct.sockaddr*, %struct.sockaddr** %4
%11 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = load %struct.sockaddr*, %struct.sockaddr** %5
%14 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = icmp eq i32 %12, %15
br i1 %16, label %17, label %36
17: ; preds = %2
%18 = load i32, i32* %6
switch i32 %18, label %35 [
i32 129, label %19
i32 128, label %27
]
19: ; preds = %17
%20 = load %struct.sockaddr*, %struct.sockaddr** %4
%21 = bitcast %struct.sockaddr* %20 to %struct.sockaddr_in*
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %21, i32 0, i32 0
%23 = load %struct.sockaddr*, %struct.sockaddr** %5
%24 = bitcast %struct.sockaddr* %23 to %struct.sockaddr_in*
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %24, i32 0, i32 0
%26 = call i32 @memcmp(i32* %22, i32* %25, i32 4)
store i32 %26, i32* %3
br label %37
27: ; preds = %17
%28 = load %struct.sockaddr*, %struct.sockaddr** %4
%29 = bitcast %struct.sockaddr* %28 to %struct.sockaddr_in6*
%30 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %29, i32 0, i32 0
%31 = load %struct.sockaddr*, %struct.sockaddr** %5
%32 = bitcast %struct.sockaddr* %31 to %struct.sockaddr_in6*
%33 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %32, i32 0, i32 0
%34 = call i32 @memcmp(i32* %30, i32* %33, i32 4)
store i32 %34, i32* %3
br label %37
35: ; preds = %17
br label %36
36: ; preds = %35, %2
store i32 1, i32* %3
br label %37
37: ; preds = %36, %27, %19
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
define i32 @sockaddrcmp(%struct.sockaddr* %0, %struct.sockaddr* %1) {
%3 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 0
%6 = load i32, i32* %5
%7 = icmp eq i32 %4, %6
%8 = and i32 %4, -2
%9 = icmp eq i32 %8, 128
%10 = and i1 %7, %9
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @memcmp(i32* %3, i32* %5, i32 4)
br label %13
13: ; preds = %11, %2
%14 = phi i32 [ 1, %2 ], [ %12, %11 ]
ret i32 %14
}