#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_in6 {
  int dummy;
};
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  scalar_t__ sa_family;
};

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
int /*<<< orphan*/ assert(int);
int sockutil_a4_eq(struct sockaddr_in *, struct sockaddr_in *, unsigned int);
int sockutil_a6_eq(struct sockaddr_in6 *, struct sockaddr_in6 *, unsigned int);
int sockutil_addr_eq(struct sockaddr *a, struct sockaddr *b, unsigned ignore) {
  assert(a->sa_family == AF_INET || a->sa_family == AF_INET6);
  assert(b->sa_family == AF_INET || b->sa_family == AF_INET6);
  if (a->sa_family != b->sa_family) {
    return 0;
  }
  return (a->sa_family == AF_INET)
             ? sockutil_a4_eq((struct sockaddr_in *)a, (struct sockaddr_in *)b,
                              ignore)
             : sockutil_a6_eq((struct sockaddr_in6 *)a,
                              (struct sockaddr_in6 *)b, ignore);
}


x86 assembly (clang, -O0):
<sockutil_addr_eq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    $0x1,%al
mov    0x2e95(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x1d(%rbp)
je     1176 <sockutil_addr_eq+0x46>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
mov    $0x1,%al
mov    0x2e55(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x1e(%rbp)
je     11b6 <sockutil_addr_eq+0x86>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e33(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%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     11e3 <sockutil_addr_eq+0xb3>
movl   $0x0,-0x4(%rbp)
jmp    122b <sockutil_addr_eq+0xfb>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2df7(%rip),%rcx
cmp    (%rcx),%rax
jne    1212 <sockutil_addr_eq+0xe2>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <sockutil_a4_eq@plt>
mov    %eax,-0x24(%rbp)
jmp    1225 <sockutil_addr_eq+0xf5>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <sockutil_a6_eq@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sockutil_addr_eq>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%rax
mov    0x2ea3(%rip),%r15
cmp    (%r15),%rax
sete   %cl
mov    0x2e8e(%rip),%r12
cmp    (%r12),%rax
mov    %edx,%r14d
mov    %rsi,%rbp
sete   %al
or     %cl,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x0(%rbp),%rax
cmp    (%r15),%rax
sete   %cl
cmp    (%r12),%rax
sete   %al
or     %cl,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    (%rbx),%rax
cmp    0x0(%rbp),%rax
jne    11a8 <sockutil_addr_eq+0x78>
cmp    (%r15),%rax
jne    11b3 <sockutil_addr_eq+0x83>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <sockutil_a4_eq@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <sockutil_a6_eq@plt>

LLVM IR (-O0):
%struct.sockaddr = type { i64 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@AF_INET = global i64 0
@AF_INET6 = global i64 0
define i32 @sockutil_addr_eq(%struct.sockaddr* %0, %struct.sockaddr* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr*
%6 = alloca %struct.sockaddr*
%7 = alloca i32
store %struct.sockaddr* %0, %struct.sockaddr** %5
store %struct.sockaddr* %1, %struct.sockaddr** %6
store i32 %2, i32* %7
%8 = load %struct.sockaddr*, %struct.sockaddr** %5
%9 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %8, i32 0, i32 0
%10 = load i64, i64* %9
%11 = load i64, i64* @AF_INET
%12 = icmp eq i64 %10, %11
br i1 %12, label %19, label %13
13: ; preds = %3
%14 = load %struct.sockaddr*, %struct.sockaddr** %5
%15 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %14, i32 0, i32 0
%16 = load i64, i64* %15
%17 = load i64, i64* @AF_INET6
%18 = icmp eq i64 %16, %17
br label %19
19: ; preds = %13, %3
%20 = phi i1 [ true, %3 ], [ %18, %13 ]
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load %struct.sockaddr*, %struct.sockaddr** %6
%24 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %23, i32 0, i32 0
%25 = load i64, i64* %24
%26 = load i64, i64* @AF_INET
%27 = icmp eq i64 %25, %26
br i1 %27, label %34, label %28
28: ; preds = %19
%29 = load %struct.sockaddr*, %struct.sockaddr** %6
%30 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %29, i32 0, i32 0
%31 = load i64, i64* %30
%32 = load i64, i64* @AF_INET6
%33 = icmp eq i64 %31, %32
br label %34
34: ; preds = %28, %19
%35 = phi i1 [ true, %19 ], [ %33, %28 ]
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = load %struct.sockaddr*, %struct.sockaddr** %5
%39 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %38, i32 0, i32 0
%40 = load i64, i64* %39
%41 = load %struct.sockaddr*, %struct.sockaddr** %6
%42 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %41, i32 0, i32 0
%43 = load i64, i64* %42
%44 = icmp ne i64 %40, %43
br i1 %44, label %45, label %46
45: ; preds = %34
store i32 0, i32* %4
br label %68
46: ; preds = %34
%47 = load %struct.sockaddr*, %struct.sockaddr** %5
%48 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %47, i32 0, i32 0
%49 = load i64, i64* %48
%50 = load i64, i64* @AF_INET
%51 = icmp eq i64 %49, %50
br i1 %51, label %52, label %59
52: ; preds = %46
%53 = load %struct.sockaddr*, %struct.sockaddr** %5
%54 = bitcast %struct.sockaddr* %53 to %struct.sockaddr_in*
%55 = load %struct.sockaddr*, %struct.sockaddr** %6
%56 = bitcast %struct.sockaddr* %55 to %struct.sockaddr_in*
%57 = load i32, i32* %7
%58 = call i32 @sockutil_a4_eq(%struct.sockaddr_in* %54, %struct.sockaddr_in* %56, i32 %57)
br label %66
59: ; preds = %46
%60 = load %struct.sockaddr*, %struct.sockaddr** %5
%61 = bitcast %struct.sockaddr* %60 to %struct.sockaddr_in6*
%62 = load %struct.sockaddr*, %struct.sockaddr** %6
%63 = bitcast %struct.sockaddr* %62 to %struct.sockaddr_in6*
%64 = load i32, i32* %7
%65 = call i32 @sockutil_a6_eq(%struct.sockaddr_in6* %61, %struct.sockaddr_in6* %63, i32 %64)
br label %66
66: ; preds = %59, %52
%67 = phi i32 [ %58, %52 ], [ %65, %59 ]
store i32 %67, i32* %4
br label %68
68: ; preds = %66, %45
%69 = load i32, i32* %4
ret i32 %69
}

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