#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 {
  scalar_t__ sa_family;
};

/* Variables and functions */
int memcmp(void *, void *, int);
void *sockaddr2addr(struct sockaddr const *, int *);
int is_addr_equal(const struct sockaddr *a, const struct sockaddr *b) {
  void *a0, *a1;
  int len;
  if (a->sa_family != b->sa_family)
    return (-1);
  a0 = sockaddr2addr(a, &len);
  a1 = sockaddr2addr(b, NULL);
  return (memcmp(a0, a1, len));
}


x86 assembly (clang, -O0):
<is_addr_equal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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 <is_addr_equal+0x30>
movl   $0xffffffff,-0x4(%rbp)
jmp    1185 <is_addr_equal+0x65>
mov    -0x10(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1040 <sockaddr2addr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <sockaddr2addr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <memcmp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_addr_equal>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%rcx
mov    $0xffffffff,%eax
cmp    (%rsi),%rcx
jne    115a <is_addr_equal+0x3a>
mov    %rsi,%rbx
lea    0x4(%rsp),%rsi
call   1040 <sockaddr2addr@plt>
mov    %rax,%r14
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <sockaddr2addr@plt>
mov    0x4(%rsp),%edx
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <memcmp@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr = type { i64 }
define i32 @is_addr_equal(%struct.sockaddr* %0, %struct.sockaddr* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr*
%5 = alloca %struct.sockaddr*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store %struct.sockaddr* %0, %struct.sockaddr** %4
store %struct.sockaddr* %1, %struct.sockaddr** %5
%9 = load %struct.sockaddr*, %struct.sockaddr** %4
%10 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %9, i32 0, i32 0
%11 = load i64, i64* %10
%12 = load %struct.sockaddr*, %struct.sockaddr** %5
%13 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %12, i32 0, i32 0
%14 = load i64, i64* %13
%15 = icmp ne i64 %11, %14
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 -1, i32* %3
br label %26
17: ; preds = %2
%18 = load %struct.sockaddr*, %struct.sockaddr** %4
%19 = call i8* @sockaddr2addr(%struct.sockaddr* %18, i32* %8)
store i8* %19, i8** %6
%20 = load %struct.sockaddr*, %struct.sockaddr** %5
%21 = call i8* @sockaddr2addr(%struct.sockaddr* %20, i32* null)
store i8* %21, i8** %7
%22 = load i8*, i8** %6
%23 = load i8*, i8** %7
%24 = load i32, i32* %8
%25 = call i32 @memcmp(i8* %22, i8* %23, i32 %24)
store i32 %25, i32* %3
br label %26
26: ; preds = %17, %16
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.sockaddr = type { i64 }
define i32 @is_addr_equal(%struct.sockaddr* %0, %struct.sockaddr* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%6 = load i64, i64* %5
%7 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 0
%8 = load i64, i64* %7
%9 = icmp eq i64 %6, %8
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = call i8* @sockaddr2addr(%struct.sockaddr* %0, i32* %3)
%12 = call i8* @sockaddr2addr(%struct.sockaddr* %1, i32* null)
%13 = load i32, i32* %3
%14 = call i32 @memcmp(i8* %11, i8* %12, i32 %13)
br label %15
15: ; preds = %2, %10
%16 = phi i32 [ %14, %10 ], [ -1, %2 ]
ret i32 %16
}