#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 in_addr {
  scalar_t__ s_addr;
};
struct in6_addr {
  int dummy;
};
typedef scalar_t__ sa_family_t;

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
scalar_t__ __ip6_addr_equal(struct in6_addr *, struct in6_addr *);
int inaddr_equal(sa_family_t family, void *addr1, void *addr2) {
  if (family == AF_INET6) {
    struct in6_addr *a1 = (struct in6_addr *)addr1;
    struct in6_addr *a2 = (struct in6_addr *)addr2;
    if (__ip6_addr_equal(a1, a2))
      return 1;
  } else if (family == AF_INET) {
    struct in_addr *a1 = (struct in_addr *)addr1;
    struct in_addr *a2 = (struct in_addr *)addr2;
    if (a1->s_addr == a2->s_addr)
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<inaddr_equal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2eb1(%rip),%rcx
cmp    (%rcx),%rax
jne    1170 <inaddr_equal+0x60>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <__ip6_addr_equal@plt>
cmp    $0x0,%rax
je     116b <inaddr_equal+0x5b>
movl   $0x1,-0x4(%rbp)
jmp    11c5 <inaddr_equal+0xb5>
jmp    11be <inaddr_equal+0xae>
mov    -0x10(%rbp),%rax
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%rax
jne    11b9 <inaddr_equal+0xa9>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    -0x40(%rbp),%rcx
cmp    (%rcx),%rax
jne    11b4 <inaddr_equal+0xa4>
movl   $0x1,-0x4(%rbp)
jmp    11c5 <inaddr_equal+0xb5>
jmp    11b9 <inaddr_equal+0xa9>
jmp    11be <inaddr_equal+0xae>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inaddr_equal>:
push   %rax
mov    0x2ec8(%rip),%rax
cmp    %rdi,(%rax)
jne    1137 <inaddr_equal+0x27>
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1030 <__ip6_addr_equal@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
je     1150 <inaddr_equal+0x40>
pop    %rcx
ret
mov    0x2eaa(%rip),%rax
cmp    %rdi,(%rax)
jne    1150 <inaddr_equal+0x40>
mov    (%rsi),%rcx
mov    $0x1,%eax
cmp    (%rdx),%rcx
je     1135 <inaddr_equal+0x25>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
%struct.in6_addr = type { i32 }
@AF_INET6 = global i64 0
@AF_INET = global i64 0
define i32 @inaddr_equal(i64 %0, i8* %1, i8* %2) {
%4 = load i64, i64* @AF_INET6
%5 = icmp eq i64 %4, %0
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = bitcast i8* %1 to %struct.in6_addr*
%8 = bitcast i8* %2 to %struct.in6_addr*
%9 = tail call i64 @__ip6_addr_equal(%struct.in6_addr* %7, %struct.in6_addr* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %20, label %21
11: ; preds = %3
%12 = load i64, i64* @AF_INET
%13 = icmp eq i64 %12, %0
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = bitcast i8* %1 to i64*
%16 = load i64, i64* %15
%17 = bitcast i8* %2 to i64*
%18 = load i64, i64* %17
%19 = icmp eq i64 %16, %18
br i1 %19, label %21, label %20
20: ; preds = %14, %6, %11
br label %21
21: ; preds = %14, %6, %20
%22 = phi i32 [ 1, %6 ], [ 0, %20 ], [ 1, %14 ]
ret i32 %22
}