#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_storage {
  scalar_t__ ss_family;
};
struct sockaddr_in6 {
  scalar_t__ sin6_port;
  int /*<<< orphan*/ sin6_addr;
};
struct TYPE_2__ {
  scalar_t__ s_addr;
};
struct sockaddr_in {
  scalar_t__ sin_port;
  TYPE_1__ sin_addr;
};

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
scalar_t__ __ip6_addr_equal(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int sockstorage_equal(const struct sockaddr_storage *s1,
                      const struct sockaddr_storage *s2) {
  if (s1->ss_family != s2->ss_family)
    return 0;
  if (s1->ss_family == AF_INET6) {
    struct sockaddr_in6 *a1 = (struct sockaddr_in6 *)s1;
    struct sockaddr_in6 *a2 = (struct sockaddr_in6 *)s2;
    if (__ip6_addr_equal(&a1->sin6_addr, &a2->sin6_addr) &&
        (a1->sin6_port == a2->sin6_port))
      return 1;
  } else if (s1->ss_family == AF_INET) {
    struct sockaddr_in *a1 = (struct sockaddr_in *)s1;
    struct sockaddr_in *a2 = (struct sockaddr_in *)s2;
    if ((a1->sin_addr.s_addr == a1->sin_addr.s_addr) &&
        (a1->sin_port == a2->sin_port))
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<sockstorage_equal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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 <sockstorage_equal+0x30>
movl   $0x0,-0x4(%rbp)
jmp    1219 <sockstorage_equal+0x109>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e92(%rip),%rcx
cmp    (%rcx),%rax
jne    11ab <sockstorage_equal+0x9b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x8,%rdi
mov    -0x28(%rbp),%rsi
add    $0x8,%rsi
call   1030 <__ip6_addr_equal@plt>
cmp    $0x0,%rax
je     11a6 <sockstorage_equal+0x96>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x28(%rbp),%rcx
cmp    (%rcx),%rax
jne    11a6 <sockstorage_equal+0x96>
movl   $0x1,-0x4(%rbp)
jmp    1219 <sockstorage_equal+0x109>
jmp    1212 <sockstorage_equal+0x102>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e2f(%rip),%rcx
cmp    (%rcx),%rax
jne    120d <sockstorage_equal+0xfd>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x30(%rbp),%rcx
cmp    0x8(%rcx),%rax
jne    1208 <sockstorage_equal+0xf8>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    -0x38(%rbp),%rcx
cmp    (%rcx),%rax
jne    1208 <sockstorage_equal+0xf8>
movl   $0x1,-0x4(%rbp)
jmp    1219 <sockstorage_equal+0x109>
jmp    120d <sockstorage_equal+0xfd>
jmp    1212 <sockstorage_equal+0x102>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sockstorage_equal>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%rcx
xor    %eax,%eax
cmp    (%rsi),%rcx
jne    1164 <sockstorage_equal+0x54>
mov    0x2ebb(%rip),%rax
cmp    (%rax),%rcx
jne    1151 <sockstorage_equal+0x41>
mov    %rsi,%r14
mov    %rdi,%rbx
add    $0x8,%rdi
add    $0x8,%rsi
call   1030 <__ip6_addr_equal@plt>
test   %rax,%rax
je     1162 <sockstorage_equal+0x52>
mov    (%rbx),%rcx
mov    $0x1,%eax
cmp    (%r14),%rcx
jne    1162 <sockstorage_equal+0x52>
jmp    1164 <sockstorage_equal+0x54>
mov    0x2e90(%rip),%rdx
mov    $0x1,%eax
cmp    (%rdx),%rcx
je     1164 <sockstorage_equal+0x54>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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