#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 /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int sa_family;
};

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int IN6_ARE_ADDR_EQUAL(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ err(int, char *);
int af_sockaddr_eq(const struct sockaddr *sa1, const struct sockaddr *sa2) {
  int res;
  res = 0;
  if (sa1->sa_family == sa2->sa_family) {
    switch (sa1->sa_family) {
    case AF_INET:
      res = (((struct sockaddr_in *)sa1)->sin_addr.s_addr ==
             ((struct sockaddr_in *)sa2)->sin_addr.s_addr);
      break;
    case AF_INET6:
      res = IN6_ARE_ADDR_EQUAL(&((struct sockaddr_in6 *)sa1)->sin6_addr,
                               &((struct sockaddr_in6 *)sa2)->sin6_addr);
      break;
    default:
      err(1, "Unknown sockaddr family");
      break;
    }
  }
  return (res);
}


x86 assembly (clang, -O0):
<af_sockaddr_eq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jne    11bc <af_sockaddr_eq+0x9c>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
sub    $0x80,%eax
je     1191 <af_sockaddr_eq+0x71>
jmp    1162 <af_sockaddr_eq+0x42>
mov    -0x18(%rbp),%eax
sub    $0x81,%eax
jne    11a6 <af_sockaddr_eq+0x86>
jmp    1175 <af_sockaddr_eq+0x55>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
jmp    11b7 <af_sockaddr_eq+0x97>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <IN6_ARE_ADDR_EQUAL@plt>
mov    %eax,-0x14(%rbp)
jmp    11b7 <af_sockaddr_eq+0x97>
mov    $0x1,%edi
lea    0xe4e(%rip),%rsi
call   1040 <err@plt>
jmp    11bc <af_sockaddr_eq+0x9c>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<af_sockaddr_eq>:
push   %rbx
mov    (%rdi),%eax
xor    %ebx,%ebx
cmp    (%rsi),%eax
jne    1155 <af_sockaddr_eq+0x35>
cmp    $0x81,%eax
je     113d <af_sockaddr_eq+0x1d>
cmp    $0x80,%eax
jne    1144 <af_sockaddr_eq+0x24>
pop    %rbx
jmp    1030 <IN6_ARE_ADDR_EQUAL@plt>
mov    $0x1,%ebx
jmp    1155 <af_sockaddr_eq+0x35>
lea    0xeb5(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@.str = [24 x i8] c"Unknown sockaddr family\00"
define i32 @af_sockaddr_eq(%struct.sockaddr* %0, %struct.sockaddr* %1) {
%3 = alloca %struct.sockaddr*
%4 = alloca %struct.sockaddr*
%5 = alloca i32
store %struct.sockaddr* %0, %struct.sockaddr** %3
store %struct.sockaddr* %1, %struct.sockaddr** %4
store i32 0, i32* %5
%6 = load %struct.sockaddr*, %struct.sockaddr** %3
%7 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = load %struct.sockaddr*, %struct.sockaddr** %4
%10 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = icmp eq i32 %8, %11
br i1 %12, label %13, label %41
13: ; preds = %2
%14 = load %struct.sockaddr*, %struct.sockaddr** %3
%15 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %14, i32 0, i32 0
%16 = load i32, i32* %15
switch i32 %16, label %38 [
i32 129, label %17
i32 128, label %30
]
17: ; preds = %13
%18 = load %struct.sockaddr*, %struct.sockaddr** %3
%19 = bitcast %struct.sockaddr* %18 to %struct.sockaddr_in*
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 0
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = load %struct.sockaddr*, %struct.sockaddr** %4
%24 = bitcast %struct.sockaddr* %23 to %struct.sockaddr_in*
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %24, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
%27 = load i32, i32* %26
%28 = icmp eq i32 %22, %27
%29 = zext i1 %28 to i32
store i32 %29, i32* %5
br label %40
30: ; preds = %13
%31 = load %struct.sockaddr*, %struct.sockaddr** %3
%32 = bitcast %struct.sockaddr* %31 to %struct.sockaddr_in6*
%33 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %32, i32 0, i32 0
%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 = call i32 @IN6_ARE_ADDR_EQUAL(i32* %33, i32* %36)
store i32 %37, i32* %5
br label %40
38: ; preds = %13
%39 = call i32 @err(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %40
40: ; preds = %38, %30, %17
br label %41
41: ; preds = %40, %2
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [24 x i8] c"Unknown sockaddr family\00"
define i32 @af_sockaddr_eq(%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
br i1 %7, label %8, label %13
8: ; preds = %2
switch i32 %4, label %11 [
i32 129, label %13
i32 128, label %9
]
9: ; preds = %8
%10 = tail call i32 @IN6_ARE_ADDR_EQUAL(i32* %3, i32* %5)
br label %13
11: ; preds = %8
%12 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %8, %9, %11, %2
%14 = phi i32 [ 0, %11 ], [ %10, %9 ], [ 0, %2 ], [ 1, %8 ]
ret i32 %14
}