int masked_match(net_tok, mask_tok, string)
char *net_tok;
char *mask_tok;
char *string;
{
  unsigned long net;
  unsigned long mask;
  unsigned long addr;
  if ((addr = dot_quad_addr(string)) == (-1))
    return (0);
  if ((net = dot_quad_addr(net_tok)) == (-1) ||
      (mask = dot_quad_addr(mask_tok)) == (-1)) {
    tcpd_warn("bad net/mask expression: %s/%s", net_tok, mask_tok);
    return (0);
  }
  return ((addr & mask) == net);
}


x86 assembly (clang, -O0):
<masked_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1040 <dot_quad_addr@plt>
cltq
mov    %rax,-0x38(%rbp)
cmp    $0xffffffffffffffff,%rax
jne    115b <masked_match+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    11ca <masked_match+0xaa>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1040 <dot_quad_addr@plt>
cltq
mov    %rax,-0x28(%rbp)
cmp    $0xffffffffffffffff,%rax
je     1191 <masked_match+0x71>
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1040 <dot_quad_addr@plt>
cltq
mov    %rax,-0x30(%rbp)
cmp    $0xffffffffffffffff,%rax
jne    11b3 <masked_match+0x93>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <tcpd_warn@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ca <masked_match+0xaa>
mov    -0x38(%rbp),%rax
and    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<masked_match>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
mov    %rdx,%rdi
xor    %eax,%eax
call   1040 <dot_quad_addr@plt>
cmp    $0xffffffff,%eax
je     1184 <masked_match+0x64>
mov    %eax,%ebp
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <dot_quad_addr@plt>
cmp    $0xffffffff,%eax
je     1170 <masked_match+0x50>
mov    %eax,%r12d
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <dot_quad_addr@plt>
cmp    $0xffffffff,%eax
je     1170 <masked_match+0x50>
and    %ebp,%eax
xor    %ebx,%ebx
cmp    %r12d,%eax
sete   %bl
jmp    1184 <masked_match+0x64>
lea    0xe89(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <tcpd_warn@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"bad net/mask expression: %s/%s\00"
define i32 @masked_match(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %7
%12 = call i32 (i8*, ...) bitcast (i32 (...)* @dot_quad_addr to i32 (i8*, ...)*)(i8* %11)
%13 = sext i32 %12 to i64
store i64 %13, i64* %10
%14 = icmp eq i64 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 0, i32* %4
br label %37
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = call i32 (i8*, ...) bitcast (i32 (...)* @dot_quad_addr to i32 (i8*, ...)*)(i8* %17)
%19 = sext i32 %18 to i64
store i64 %19, i64* %8
%20 = icmp eq i64 %19, -1
br i1 %20, label %26, label %21
21: ; preds = %16
%22 = load i8*, i8** %6
%23 = call i32 (i8*, ...) bitcast (i32 (...)* @dot_quad_addr to i32 (i8*, ...)*)(i8* %22)
%24 = sext i32 %23 to i64
store i64 %24, i64* %9
%25 = icmp eq i64 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %21, %16
%27 = load i8*, i8** %5
%28 = load i8*, i8** %6
%29 = call i32 (i8*, i8*, i8*, ...) bitcast (i32 (...)* @tcpd_warn to i32 (i8*, i8*, i8*, ...)*)(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %27, i8* %28)
store i32 0, i32* %4
br label %37
30: ; preds = %21
%31 = load i64, i64* %10
%32 = load i64, i64* %9
%33 = and i64 %31, %32
%34 = load i64, i64* %8
%35 = icmp eq i64 %33, %34
%36 = zext i1 %35 to i32
store i32 %36, i32* %4
br label %37
37: ; preds = %30, %26, %15
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
@.str = [31 x i8] c"bad net/mask expression: %s/%s\00"
define i32 @masked_match(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 (i8*, ...) bitcast (i32 (...)* @dot_quad_addr to i32 (i8*, ...)*)(i8* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %18, label %6
6: ; preds = %3
%7 = tail call i32 (i8*, ...) bitcast (i32 (...)* @dot_quad_addr to i32 (i8*, ...)*)(i8* %0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call i32 (i8*, ...) bitcast (i32 (...)* @dot_quad_addr to i32 (i8*, ...)*)(i8* %1)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %9, %6
%13 = tail call i32 (i8*, i8*, i8*, ...) bitcast (i32 (...)* @tcpd_warn to i32 (i8*, i8*, i8*, ...)*)(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
br label %18
14: ; preds = %9
%15 = and i32 %10, %4
%16 = icmp eq i32 %15, %7
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %3, %14, %12
%19 = phi i32 [ 0, %12 ], [ %17, %14 ], [ 0, %3 ]
ret i32 %19
}