#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_un {
  int /*<<< orphan*/ sun_path;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int sa_family;
};
struct in_addr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
#define AF_INET 129
#define AF_UNIX 128
int memcmp(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int strcmp(int /*<<< orphan*/, int /*<<< orphan*/);
int sock_cmp_addr(const struct sockaddr *sa1, const struct sockaddr *sa2,
                  socklen_t salen) {
  if (sa1->sa_family != sa2->sa_family)
    return (-1);
  switch (sa1->sa_family) {
  case AF_INET: {
    return (memcmp(&((struct sockaddr_in *)sa1)->sin_addr,
                   &((struct sockaddr_in *)sa2)->sin_addr,
                   sizeof(struct in_addr)));
  }
  case AF_UNIX: {
    return (strcmp(((struct sockaddr_un *)sa1)->sun_path,
                   ((struct sockaddr_un *)sa2)->sun_path));
  }
  }
  return -1;
}


x86 assembly (clang, -O0):
<sock_cmp_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
je     1151 <sock_cmp_addr+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <sock_cmp_addr+0x97>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
sub    $0x80,%eax
je     1197 <sock_cmp_addr+0x77>
jmp    116a <sock_cmp_addr+0x4a>
mov    -0x20(%rbp),%eax
sub    $0x81,%eax
jne    11b0 <sock_cmp_addr+0x90>
jmp    117d <sock_cmp_addr+0x5d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
mov    %eax,-0x4(%rbp)
jmp    11b7 <sock_cmp_addr+0x97>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1040 <strcmp@plt>
mov    %eax,-0x4(%rbp)
jmp    11b7 <sock_cmp_addr+0x97>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_cmp_addr>:
mov    (%rdi),%eax
cmp    (%rsi),%eax
jne    113e <sock_cmp_addr+0x1e>
cmp    $0x80,%eax
je     1144 <sock_cmp_addr+0x24>
cmp    $0x81,%eax
jne    113e <sock_cmp_addr+0x1e>
mov    $0x4,%edx
jmp    1030 <memcmp@plt>
mov    $0xffffffff,%eax
ret
mov    $0x80,%edi
mov    $0x80,%esi
jmp    1040 <strcmp@plt>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_un = type { i32 }
define i32 @sock_cmp_addr(%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 i32, i32* %9
%11 = load %struct.sockaddr*, %struct.sockaddr** %6
%12 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = icmp ne i32 %10, %13
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %39
16: ; preds = %3
%17 = load %struct.sockaddr*, %struct.sockaddr** %5
%18 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %17, i32 0, i32 0
%19 = load i32, i32* %18
switch i32 %19, label %38 [
i32 129, label %20
i32 128, label %28
]
20: ; preds = %16
%21 = load %struct.sockaddr*, %struct.sockaddr** %5
%22 = bitcast %struct.sockaddr* %21 to %struct.sockaddr_in*
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %22, i32 0, i32 0
%24 = load %struct.sockaddr*, %struct.sockaddr** %6
%25 = bitcast %struct.sockaddr* %24 to %struct.sockaddr_in*
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %25, i32 0, i32 0
%27 = call i32 @memcmp(i32* %23, i32* %26, i32 4)
store i32 %27, i32* %4
br label %39
28: ; preds = %16
%29 = load %struct.sockaddr*, %struct.sockaddr** %5
%30 = bitcast %struct.sockaddr* %29 to %struct.sockaddr_un*
%31 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = load %struct.sockaddr*, %struct.sockaddr** %6
%34 = bitcast %struct.sockaddr* %33 to %struct.sockaddr_un*
%35 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i32 @strcmp(i32 %32, i32 %36)
store i32 %37, i32* %4
br label %39
38: ; preds = %16
store i32 -1, i32* %4
br label %39
39: ; preds = %38, %28, %20, %15
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
define i32 @sock_cmp_addr(%struct.sockaddr* %0, %struct.sockaddr* %1, i32 %2) {
%4 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%5 = load i32, i32* %4
%6 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 0
%7 = load i32, i32* %6
%8 = icmp eq i32 %5, %7
br i1 %8, label %9, label %14
9: ; preds = %3
switch i32 %5, label %14 [
i32 129, label %10
i32 128, label %12
]
10: ; preds = %9
%11 = tail call i32 @memcmp(i32* %4, i32* %6, i32 4)
br label %14
12: ; preds = %9
%13 = tail call i32 @strcmp(i32 128, i32 128)
br label %14
14: ; preds = %9, %3, %12, %10
%15 = phi i32 [ %13, %12 ], [ %11, %10 ], [ -1, %3 ], [ -1, %9 ]
ret i32 %15
}