#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct TYPE_2__ {
  int s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};
struct sockaddr {
  scalar_t__ sa_family;
};

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
int /*<<< orphan*/ assert(int);
int memcmp(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int chitcp_addr_cmp(struct sockaddr *addr1, struct sockaddr *addr2) {
  assert(addr1->sa_family == AF_INET || addr1->sa_family == AF_INET6);
  assert(addr2->sa_family == AF_INET || addr2->sa_family == AF_INET6);
  if (addr1->sa_family != addr2->sa_family) {
    return addr1->sa_family - addr2->sa_family;
  } else if (addr1->sa_family == AF_INET) {
    struct sockaddr_in *sin1 = (struct sockaddr_in *)addr1;
    struct sockaddr_in *sin2 = (struct sockaddr_in *)addr2;
    return sin1->sin_addr.s_addr - sin2->sin_addr.s_addr;
  } else if (addr1->sa_family == AF_INET6) {
    struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)addr1;
    struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)addr2;
    return memcmp(&sin1->sin6_addr, &sin2->sin6_addr, sizeof(sin1->sin6_addr));
  }
  return -1;
}


x86 assembly (clang, -O0):
<chitcp_addr_cmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    $0x1,%al
mov    0x2ea8(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x39(%rbp)
je     1163 <chitcp_addr_cmp+0x43>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e86(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
mov    $0x1,%al
mov    0x2e68(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x3a(%rbp)
je     11a3 <chitcp_addr_cmp+0x83>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e46(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
je     11da <chitcp_addr_cmp+0xba>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
sub    (%rcx),%rax
mov    %eax,-0x4(%rbp)
jmp    1267 <chitcp_addr_cmp+0x147>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e00(%rip),%rcx
cmp    (%rcx),%rax
jne    1215 <chitcp_addr_cmp+0xf5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    -0x28(%rbp),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1267 <chitcp_addr_cmp+0x147>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2dbd(%rip),%rcx
cmp    (%rcx),%rax
jne    1256 <chitcp_addr_cmp+0x136>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
mov    %eax,-0x4(%rbp)
jmp    1267 <chitcp_addr_cmp+0x147>
jmp    125b <chitcp_addr_cmp+0x13b>
jmp    1260 <chitcp_addr_cmp+0x140>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chitcp_addr_cmp>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%rax
mov    0x2eb3(%rip),%r12
cmp    (%r12),%rax
sete   %cl
mov    0x2e9d(%rip),%r15
cmp    (%r15),%rax
mov    %rsi,%rbx
sete   %al
or     %cl,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    (%rbx),%rax
cmp    (%r12),%rax
sete   %cl
cmp    (%r15),%rax
sete   %al
or     %cl,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    (%r14),%rcx
mov    (%rbx),%rax
cmp    %rax,%rcx
jne    1181 <chitcp_addr_cmp+0x61>
cmp    (%r12),%rcx
jne    1191 <chitcp_addr_cmp+0x71>
sub    %eax,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    $0xffffffff,%eax
cmp    (%r15),%rcx
jne    1185 <chitcp_addr_cmp+0x65>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <memcmp@plt>

LLVM IR (-O0):
%struct.sockaddr = type { i64 }
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@AF_INET = global i64 0
@AF_INET6 = global i64 0
define i32 @chitcp_addr_cmp(%struct.sockaddr* %0, %struct.sockaddr* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr*
%5 = alloca %struct.sockaddr*
%6 = alloca %struct.sockaddr_in*
%7 = alloca %struct.sockaddr_in*
%8 = alloca %struct.sockaddr_in6*
%9 = alloca %struct.sockaddr_in6*
store %struct.sockaddr* %0, %struct.sockaddr** %4
store %struct.sockaddr* %1, %struct.sockaddr** %5
%10 = load %struct.sockaddr*, %struct.sockaddr** %4
%11 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %10, i32 0, i32 0
%12 = load i64, i64* %11
%13 = load i64, i64* @AF_INET
%14 = icmp eq i64 %12, %13
br i1 %14, label %21, label %15
15: ; preds = %2
%16 = load %struct.sockaddr*, %struct.sockaddr** %4
%17 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %16, i32 0, i32 0
%18 = load i64, i64* %17
%19 = load i64, i64* @AF_INET6
%20 = icmp eq i64 %18, %19
br label %21
21: ; preds = %15, %2
%22 = phi i1 [ true, %2 ], [ %20, %15 ]
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load %struct.sockaddr*, %struct.sockaddr** %5
%26 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %25, i32 0, i32 0
%27 = load i64, i64* %26
%28 = load i64, i64* @AF_INET
%29 = icmp eq i64 %27, %28
br i1 %29, label %36, label %30
30: ; preds = %21
%31 = load %struct.sockaddr*, %struct.sockaddr** %5
%32 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %31, i32 0, i32 0
%33 = load i64, i64* %32
%34 = load i64, i64* @AF_INET6
%35 = icmp eq i64 %33, %34
br label %36
36: ; preds = %30, %21
%37 = phi i1 [ true, %21 ], [ %35, %30 ]
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = load %struct.sockaddr*, %struct.sockaddr** %4
%41 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %40, i32 0, i32 0
%42 = load i64, i64* %41
%43 = load %struct.sockaddr*, %struct.sockaddr** %5
%44 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %43, i32 0, i32 0
%45 = load i64, i64* %44
%46 = icmp ne i64 %42, %45
br i1 %46, label %47, label %56
47: ; preds = %36
%48 = load %struct.sockaddr*, %struct.sockaddr** %4
%49 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %48, i32 0, i32 0
%50 = load i64, i64* %49
%51 = load %struct.sockaddr*, %struct.sockaddr** %5
%52 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %51, i32 0, i32 0
%53 = load i64, i64* %52
%54 = sub nsw i64 %50, %53
%55 = trunc i64 %54 to i32
store i32 %55, i32* %3
br label %95
56: ; preds = %36
%57 = load %struct.sockaddr*, %struct.sockaddr** %4
%58 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %57, i32 0, i32 0
%59 = load i64, i64* %58
%60 = load i64, i64* @AF_INET
%61 = icmp eq i64 %59, %60
br i1 %61, label %62, label %76
62: ; preds = %56
%63 = load %struct.sockaddr*, %struct.sockaddr** %4
%64 = bitcast %struct.sockaddr* %63 to %struct.sockaddr_in*
store %struct.sockaddr_in* %64, %struct.sockaddr_in** %6
%65 = load %struct.sockaddr*, %struct.sockaddr** %5
%66 = bitcast %struct.sockaddr* %65 to %struct.sockaddr_in*
store %struct.sockaddr_in* %66, %struct.sockaddr_in** %7
%67 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%68 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %67, i32 0, i32 0
%69 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %68, i32 0, i32 0
%70 = load i32, i32* %69
%71 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%72 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %71, i32 0, i32 0
%73 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %72, i32 0, i32 0
%74 = load i32, i32* %73
%75 = sub nsw i32 %70, %74
store i32 %75, i32* %3
br label %95
76: ; preds = %56
%77 = load %struct.sockaddr*, %struct.sockaddr** %4
%78 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %77, i32 0, i32 0
%79 = load i64, i64* %78
%80 = load i64, i64* @AF_INET6
%81 = icmp eq i64 %79, %80
br i1 %81, label %82, label %92
82: ; preds = %76
%83 = load %struct.sockaddr*, %struct.sockaddr** %4
%84 = bitcast %struct.sockaddr* %83 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %84, %struct.sockaddr_in6** %8
%85 = load %struct.sockaddr*, %struct.sockaddr** %5
%86 = bitcast %struct.sockaddr* %85 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %86, %struct.sockaddr_in6** %9
%87 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %8
%88 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %87, i32 0, i32 0
%89 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %9
%90 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %89, i32 0, i32 0
%91 = call i32 @memcmp(i32* %88, i32* %90, i32 4)
store i32 %91, i32* %3
br label %95
92: ; preds = %76
br label %93
93: ; preds = %92
br label %94
94: ; preds = %93
store i32 -1, i32* %3
br label %95
95: ; preds = %94, %82, %62, %47
%96 = load i32, i32* %3
ret i32 %96
}

LLVM IR (-O2):
%struct.sockaddr = type { i64 }
@AF_INET = global i64 0
@AF_INET6 = global i64 0
define i32 @chitcp_addr_cmp(%struct.sockaddr* %0, %struct.sockaddr* %1) {
%3 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%4 = load i64, i64* %3
%5 = load i64, i64* @AF_INET
%6 = icmp eq i64 %4, %5
%7 = load i64, i64* @AF_INET6
%8 = icmp eq i64 %4, %7
%9 = select i1 %6, i1 true, i1 %8
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 0
%13 = load i64, i64* %12
%14 = load i64, i64* @AF_INET
%15 = icmp eq i64 %13, %14
%16 = load i64, i64* @AF_INET6
%17 = icmp eq i64 %13, %16
%18 = select i1 %15, i1 true, i1 %17
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = load i64, i64* %3
%22 = load i64, i64* %12
%23 = icmp eq i64 %21, %22
%24 = trunc i64 %21 to i32
%25 = trunc i64 %22 to i32
br i1 %23, label %29, label %26
26: ; preds = %2
%27 = sub nsw i64 %21, %22
%28 = trunc i64 %27 to i32
br label %41
29: ; preds = %2
%30 = load i64, i64* @AF_INET
%31 = icmp eq i64 %21, %30
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = sub nsw i32 %24, %25
br label %41
34: ; preds = %29
%35 = load i64, i64* @AF_INET6
%36 = icmp eq i64 %21, %35
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = bitcast %struct.sockaddr* %0 to i32*
%39 = bitcast %struct.sockaddr* %1 to i32*
%40 = tail call i32 @memcmp(i32* %38, i32* %39, i32 4)
br label %41
41: ; preds = %34, %37, %32, %26
%42 = phi i32 [ %28, %26 ], [ %33, %32 ], [ %40, %37 ], [ -1, %34 ]
ret i32 %42
}