#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_storage {
  scalar_t__ ss_family;
};
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};

/* Variables and functions */
scalar_t__ AF_INET6;
int /*<<< orphan*/ memcmp(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int equal_addr(const struct sockaddr_storage *a,
               const struct sockaddr_storage *b) {
  if (!a->ss_family)
    return 0;
  if (a->ss_family != b->ss_family)
    return 0;
  if (a->ss_family == AF_INET6)
    return !memcmp(&((struct sockaddr_in6 *)a)->sin6_addr,
                   &((struct sockaddr_in6 *)b)->sin6_addr,
                   sizeof(((struct sockaddr_in6 *)a)->sin6_addr));
  else
    return !memcmp(&((struct sockaddr_in *)a)->sin_addr,
                   &((struct sockaddr_in *)b)->sin_addr,
                   sizeof(((struct sockaddr_in *)a)->sin_addr));
  return 0;
}


x86 assembly (clang, -O0):
<equal_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    113a <equal_addr+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    11ba <equal_addr+0xaa>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
je     115a <equal_addr+0x4a>
movl   $0x0,-0x4(%rbp)
jmp    11ba <equal_addr+0xaa>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e80(%rip),%rcx
cmp    (%rcx),%rax
jne    1198 <equal_addr+0x88>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    11ba <equal_addr+0xaa>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<equal_addr>:
push   %rax
mov    (%rdi),%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     1133 <equal_addr+0x23>
cmp    (%rsi),%rcx
jne    1133 <equal_addr+0x23>
mov    $0x4,%edx
call   1030 <memcmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
pop    %rcx
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i64 }
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr_in = type { i32 }
@AF_INET6 = global i64 0
define i32 @equal_addr(%struct.sockaddr_storage* %0, %struct.sockaddr_storage* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_storage*
%5 = alloca %struct.sockaddr_storage*
store %struct.sockaddr_storage* %0, %struct.sockaddr_storage** %4
store %struct.sockaddr_storage* %1, %struct.sockaddr_storage** %5
%6 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%7 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %6, i32 0, i32 0
%8 = load i64, i64* %7
%9 = icmp ne i64 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %2
store i32 0, i32* %3
br label %48
11: ; preds = %2
%12 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%13 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %12, i32 0, i32 0
%14 = load i64, i64* %13
%15 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %5
%16 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %15, i32 0, i32 0
%17 = load i64, i64* %16
%18 = icmp ne i64 %14, %17
br i1 %18, label %19, label %20
19: ; preds = %11
store i32 0, i32* %3
br label %48
20: ; preds = %11
%21 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%22 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %21, i32 0, i32 0
%23 = load i64, i64* %22
%24 = load i64, i64* @AF_INET6
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %37
26: ; preds = %20
%27 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%28 = bitcast %struct.sockaddr_storage* %27 to %struct.sockaddr_in6*
%29 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %28, i32 0, i32 0
%30 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %5
%31 = bitcast %struct.sockaddr_storage* %30 to %struct.sockaddr_in6*
%32 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %31, i32 0, i32 0
%33 = call i32 @memcmp(i32* %29, i32* %32, i32 4)
%34 = icmp ne i32 %33, 0
%35 = xor i1 %34, true
%36 = zext i1 %35 to i32
store i32 %36, i32* %3
br label %48
37: ; preds = %20
%38 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%39 = bitcast %struct.sockaddr_storage* %38 to %struct.sockaddr_in*
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %39, i32 0, i32 0
%41 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %5
%42 = bitcast %struct.sockaddr_storage* %41 to %struct.sockaddr_in*
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %42, i32 0, i32 0
%44 = call i32 @memcmp(i32* %40, i32* %43, i32 4)
%45 = icmp ne i32 %44, 0
%46 = xor i1 %45, true
%47 = zext i1 %46 to i32
store i32 %47, i32* %3
br label %48
48: ; preds = %37, %26, %19, %10
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i64 }
@AF_INET6 = global i64 0
define i32 @equal_addr(%struct.sockaddr_storage* %0, %struct.sockaddr_storage* %1) {
%3 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %0, i64 0, i32 0
%4 = load i64, i64* %3
%5 = icmp eq i64 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %1, i64 0, i32 0
%8 = load i64, i64* %7
%9 = icmp eq i64 %4, %8
br i1 %9, label %10, label %16
10: ; preds = %6
%11 = bitcast %struct.sockaddr_storage* %0 to i32*
%12 = bitcast %struct.sockaddr_storage* %1 to i32*
%13 = tail call i32 @memcmp(i32* %11, i32* %12, i32 4)
%14 = icmp eq i32 %13, 0
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %10, %6, %2
%17 = phi i32 [ 0, %2 ], [ 0, %6 ], [ %15, %10 ]
ret i32 %17
}