#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 sin6_equals(struct sockaddr_in6 *, struct sockaddr_in6 *);
int sin_equals(struct sockaddr_in *, struct sockaddr_in *);
int sockaddr_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 sin_equals((struct sockaddr_in *)a, (struct sockaddr_in *)b);
  else if (a->sa_family == AF_INET6)
    return sin6_equals((struct sockaddr_in6 *)a, (struct sockaddr_in6 *)b);
  return 0;
}


x86 assembly (clang, -O0):
<sockaddr_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     1150 <sockaddr_equals+0x30>
movl   $0x0,-0x4(%rbp)
jmp    11b4 <sockaddr_equals+0x94>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e8a(%rip),%rcx
cmp    (%rcx),%rax
jne    117c <sockaddr_equals+0x5c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <sin_equals@plt>
mov    %eax,-0x4(%rbp)
jmp    11b4 <sockaddr_equals+0x94>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e56(%rip),%rcx
cmp    (%rcx),%rax
jne    11a8 <sockaddr_equals+0x88>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <sin6_equals@plt>
mov    %eax,-0x4(%rbp)
jmp    11b4 <sockaddr_equals+0x94>
jmp    11ad <sockaddr_equals+0x8d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sockaddr_equals>:
mov    (%rdi),%rax
cmp    (%rsi),%rax
jne    114a <sockaddr_equals+0x2a>
mov    0x2eb9(%rip),%rcx
cmp    (%rcx),%rax
jne    1139 <sockaddr_equals+0x19>
jmp    1030 <sin_equals@plt>
mov    0x2ea0(%rip),%rcx
cmp    (%rcx),%rax
jne    114a <sockaddr_equals+0x2a>
jmp    1040 <sin6_equals@plt>
xor    %eax,%eax
ret

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 @sockaddr_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 %40
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 %26
20: ; preds = %14
%21 = load %struct.sockaddr*, %struct.sockaddr** %4
%22 = bitcast %struct.sockaddr* %21 to %struct.sockaddr_in*
%23 = load %struct.sockaddr*, %struct.sockaddr** %5
%24 = bitcast %struct.sockaddr* %23 to %struct.sockaddr_in*
%25 = call i32 @sin_equals(%struct.sockaddr_in* %22, %struct.sockaddr_in* %24)
store i32 %25, i32* %3
br label %40
26: ; preds = %14
%27 = load %struct.sockaddr*, %struct.sockaddr** %4
%28 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %27, i32 0, i32 0
%29 = load i64, i64* %28
%30 = load i64, i64* @AF_INET6
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %38
32: ; preds = %26
%33 = load %struct.sockaddr*, %struct.sockaddr** %4
%34 = bitcast %struct.sockaddr* %33 to %struct.sockaddr_in6*
%35 = load %struct.sockaddr*, %struct.sockaddr** %5
%36 = bitcast %struct.sockaddr* %35 to %struct.sockaddr_in6*
%37 = call i32 @sin6_equals(%struct.sockaddr_in6* %34, %struct.sockaddr_in6* %36)
store i32 %37, i32* %3
br label %40
38: ; preds = %26
br label %39
39: ; preds = %38
store i32 0, i32* %3
br label %40
40: ; preds = %39, %32, %20, %13
%41 = load i32, i32* %3
ret i32 %41
}

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 @sockaddr_equals(%struct.sockaddr* %0, %struct.sockaddr* %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 eq i64 %4, %6
br i1 %7, label %8, label %22
8: ; preds = %2
%9 = load i64, i64* @AF_INET
%10 = icmp eq i64 %4, %9
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = bitcast %struct.sockaddr* %0 to %struct.sockaddr_in*
%13 = bitcast %struct.sockaddr* %1 to %struct.sockaddr_in*
%14 = tail call i32 @sin_equals(%struct.sockaddr_in* %12, %struct.sockaddr_in* %13)
br label %22
15: ; preds = %8
%16 = load i64, i64* @AF_INET6
%17 = icmp eq i64 %4, %16
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = bitcast %struct.sockaddr* %0 to %struct.sockaddr_in6*
%20 = bitcast %struct.sockaddr* %1 to %struct.sockaddr_in6*
%21 = tail call i32 @sin6_equals(%struct.sockaddr_in6* %19, %struct.sockaddr_in6* %20)
br label %22
22: ; preds = %15, %2, %18, %11
%23 = phi i32 [ %14, %11 ], [ %21, %18 ], [ 0, %2 ], [ 0, %15 ]
ret i32 %23
}