#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_storage {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ addr_get_raw(struct sockaddr_storage *);
int /*<<< orphan*/ addr_len(struct sockaddr_storage *);
int /*<<< orphan*/ addr_mask(struct sockaddr_storage *, size_t);
scalar_t__ memcmp(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int addr_match(struct sockaddr_storage *addr, struct sockaddr_storage *network,
               size_t mask) {
  struct sockaddr_storage addr_masked = *addr;
  addr_mask(&addr_masked, mask);
  return memcmp(addr_get_raw(&addr_masked), addr_get_raw(network),
                addr_len(network)) == 0;
}


x86 assembly (clang, -O0):
<addr_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdi
call   1040 <addr_mask@plt>
lea    -0x20(%rbp),%rdi
call   1060 <addr_get_raw@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <addr_get_raw@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <addr_len@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    %eax,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addr_match>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    (%rdi),%eax
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    %rdx,%rsi
call   1040 <addr_mask@plt>
mov    %r14,%rdi
call   1060 <addr_get_raw@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1060 <addr_get_raw@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <addr_len@plt>
mov    %r14d,%edi
mov    %ebp,%esi
mov    %eax,%edx
call   1030 <memcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
define i32 @addr_match(%struct.sockaddr_storage* %0, %struct.sockaddr_storage* %1, i64 %2) {
%4 = alloca %struct.sockaddr_storage*
%5 = alloca %struct.sockaddr_storage*
%6 = alloca i64
%7 = alloca %struct.sockaddr_storage
store %struct.sockaddr_storage* %0, %struct.sockaddr_storage** %4
store %struct.sockaddr_storage* %1, %struct.sockaddr_storage** %5
store i64 %2, i64* %6
%8 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%9 = bitcast %struct.sockaddr_storage* %7 to i8*
%10 = bitcast %struct.sockaddr_storage* %8 to i8*
%11 = load i64, i64* %6
%12 = call i32 @addr_mask(%struct.sockaddr_storage* %7, i64 %11)
%13 = call i32 @addr_get_raw(%struct.sockaddr_storage* %7)
%14 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %5
%15 = call i32 @addr_get_raw(%struct.sockaddr_storage* %14)
%16 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %5
%17 = call i32 @addr_len(%struct.sockaddr_storage* %16)
%18 = call i64 @memcmp(i32 %13, i32 %15, i32 %17)
%19 = icmp eq i64 %18, 0
%20 = zext i1 %19 to i32
ret i32 %20
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
define i32 @addr_match(%struct.sockaddr_storage* nocapture %0, %struct.sockaddr_storage* %1, i64 %2) {
%4 = alloca %struct.sockaddr_storage
%5 = bitcast %struct.sockaddr_storage* %4 to i8*
%6 = getelementptr %struct.sockaddr_storage, %struct.sockaddr_storage* %0, i64 0, i32 0
%7 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %4, i64 0, i32 0
%8 = load i32, i32* %6
store i32 %8, i32* %7
%9 = call i32 @addr_mask(%struct.sockaddr_storage* %4, i64 %2)
%10 = call i32 @addr_get_raw(%struct.sockaddr_storage* %4)
%11 = call i32 @addr_get_raw(%struct.sockaddr_storage* %1)
%12 = call i32 @addr_len(%struct.sockaddr_storage* %1)
%13 = call i64 @memcmp(i32 %10, i32 %11, i32 %12)
%14 = icmp eq i64 %13, 0
%15 = zext i1 %14 to i32
ret i32 %15
}