#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

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

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ memcmp(int /*<<< orphan*/, int /*<<< orphan*/, int);
int ip_addr_equals(const struct sockaddr *a, const struct sockaddr *b) {
  if (a->sa_family != b->sa_family)
    return 0;
  if (a->sa_family == AF_INET) {
    return ((struct sockaddr_in *)a)->sin_addr.s_addr !=
           ((struct sockaddr_in *)b)->sin_addr.s_addr;
  } else {
    return !memcmp(((struct sockaddr_in6 *)a)->sin6_addr.s6_addr,
                   ((struct sockaddr_in6 *)b)->sin6_addr.s6_addr, 16);
  }
}


x86 assembly (clang, -O0):
<ip_addr_equals>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
je     1140 <ip_addr_equals+0x30>
movl   $0x0,-0x4(%rbp)
jmp    119b <ip_addr_equals+0x8b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e9a(%rip),%rcx
cmp    (%rcx),%rax
jne    1175 <ip_addr_equals+0x65>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    119b <ip_addr_equals+0x8b>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    $0x10,%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):
<ip_addr_equals>:
push   %rax
mov    (%rdi),%rdi
mov    (%rsi),%rsi
xor    %eax,%eax
cmp    %rsi,%rdi
jne    113d <ip_addr_equals+0x2d>
mov    0x2ec3(%rip),%rcx
cmp    (%rcx),%rdi
je     113d <ip_addr_equals+0x2d>
mov    $0x10,%edx
call   1030 <memcmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
pop    %rcx
ret

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

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