#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 {
  scalar_t__ sin6_port;
  int /*<<< orphan*/ sin6_addr;
};
struct TYPE_2__ {
  scalar_t__ s_addr;
};
struct sockaddr_in {
  scalar_t__ sin_port;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  scalar_t__ sa_family;
};
struct in6_addr {
  int dummy;
};

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
scalar_t__ memcmp(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
bool SockAddrsEqual(const struct sockaddr *addr1,
                    const struct sockaddr *addr2) {
  if (addr1 == NULL || addr2 == NULL)
    return addr1 == addr2;
  else if (addr1->sa_family != addr2->sa_family)
    return false;
  else if (addr1->sa_family == AF_INET) {
    struct sockaddr_in *ipv4Addr1 = (struct sockaddr_in *)addr1;
    struct sockaddr_in *ipv4Addr2 = (struct sockaddr_in *)addr2;
    return ipv4Addr1->sin_addr.s_addr == ipv4Addr2->sin_addr.s_addr &&
           ipv4Addr1->sin_port == ipv4Addr2->sin_port;
  } else if (addr1->sa_family == AF_INET6) {
    struct sockaddr_in6 *ipv6Addr1 = (struct sockaddr_in6 *)addr1;
    struct sockaddr_in6 *ipv6Addr2 = (struct sockaddr_in6 *)addr2;
    return memcmp(&ipv6Addr1->sin6_addr, &ipv6Addr2->sin6_addr,
                  sizeof(struct in6_addr)) == 0 &&
           ipv6Addr1->sin6_port == ipv6Addr2->sin6_port;
  } else
    return false;
}


x86 assembly (clang, -O0):
<SockAddrsEqual>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1136 <SockAddrsEqual+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    114e <SockAddrsEqual+0x3e>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    1252 <SockAddrsEqual+0x142>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
je     116e <SockAddrsEqual+0x5e>
movl   $0x0,-0x4(%rbp)
jmp    1252 <SockAddrsEqual+0x142>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e6c(%rip),%rcx
cmp    (%rcx),%rax
jne    11d4 <SockAddrsEqual+0xc4>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x28(%rbp),%rdx
xor    %eax,%eax
cmp    0x8(%rdx),%rcx
mov    %al,-0x39(%rbp)
jne    11c4 <SockAddrsEqual+0xb4>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x28(%rbp),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    1252 <SockAddrsEqual+0x142>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2dfe(%rip),%rcx
cmp    (%rcx),%rax
jne    124b <SockAddrsEqual+0x13b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
add    $0x8,%rdi
mov    -0x38(%rbp),%rsi
add    $0x8,%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x3a(%rbp)
jne    123b <SockAddrsEqual+0x12b>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    -0x38(%rbp),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    1252 <SockAddrsEqual+0x142>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SockAddrsEqual>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
je     1142 <SockAddrsEqual+0x32>
test   %r14,%r14
je     1142 <SockAddrsEqual+0x32>
mov    (%rbx),%rax
cmp    (%r14),%rax
jne    116d <SockAddrsEqual+0x5d>
mov    0x2eb5(%rip),%rcx
cmp    (%rcx),%rax
jne    114a <SockAddrsEqual+0x3a>
mov    0x8(%rbx),%rax
cmp    0x8(%r14),%rax
jmp    1145 <SockAddrsEqual+0x35>
cmp    %r14,%rbx
sete   %al
jmp    116f <SockAddrsEqual+0x5f>
mov    0x2e8f(%rip),%rcx
cmp    (%rcx),%rax
jne    116d <SockAddrsEqual+0x5d>
lea    0x8(%rbx),%rdi
lea    0x8(%r14),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     117a <SockAddrsEqual+0x6a>
xor    %eax,%eax
movzbl %al,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    (%rbx),%rax
cmp    (%r14),%rax
jmp    1145 <SockAddrsEqual+0x35>

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

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