#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 */

/* Variables and functions */
scalar_t__ dot_quad_addr(char *, unsigned long *);
int /*<<< orphan*/ tcpd_warn(char *, char *, char *);
int masked_match4(char *net_tok, char *mask_tok, char *string) {
  unsigned long net;
  unsigned long mask;
  unsigned long addr;
  if (dot_quad_addr(string, &addr) != 0)
    return (0);
  if (dot_quad_addr(net_tok, &net) != 0 ||
      dot_quad_addr(mask_tok, &mask) != 0) {
    tcpd_warn("bad net/mask expression: %s/%s", net_tok, mask_tok);
    return (0);
  }
  if ((net & ~mask) != 0)
    tcpd_warn("host bits not all zero in %s/%s", net_tok, mask_tok);
  return ((addr & mask) == net);
}


x86 assembly (clang, -O0):
<masked_match4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1040 <dot_quad_addr@plt>
cmp    $0x0,%rax
je     1157 <masked_match4+0x37>
movl   $0x0,-0x4(%rbp)
jmp    11e9 <masked_match4+0xc9>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <dot_quad_addr@plt>
cmp    $0x0,%rax
jne    1185 <masked_match4+0x65>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <dot_quad_addr@plt>
cmp    $0x0,%rax
je     11a5 <masked_match4+0x85>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe6c(%rip),%rdi
call   1030 <tcpd_warn@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e9 <masked_match4+0xc9>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
xor    $0xffffffffffffffff,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
je     11d2 <masked_match4+0xb2>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe52(%rip),%rdi
call   1030 <tcpd_warn@plt>
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_match4>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x18(%rsp),%rsi
mov    %rdx,%rdi
call   1040 <dot_quad_addr@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    1178 <masked_match4+0x58>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <dot_quad_addr@plt>
test   %rax,%rax
jne    1166 <masked_match4+0x46>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1040 <dot_quad_addr@plt>
test   %rax,%rax
je     1183 <masked_match4+0x63>
lea    0xe93(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <tcpd_warn@plt>
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x10(%rsp),%rax
mov    0x8(%rsp),%rcx
mov    %rcx,%rdx
not    %rdx
test   %rdx,%rax
je     11b4 <masked_match4+0x94>
lea    0xe80(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <tcpd_warn@plt>
mov    0x8(%rsp),%rcx
mov    0x10(%rsp),%rax
and    0x18(%rsp),%rcx
xor    %ebp,%ebp
cmp    %rax,%rcx
sete   %bpl
jmp    1178 <masked_match4+0x58>

LLVM IR (-O0):
@.str = [31 x i8] c"bad net/mask expression: %s/%s\00"
@.str.1 = [32 x i8] c"host bits not all zero in %s/%s\00"
define i32 @masked_match4(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 i64 @dot_quad_addr(i8* %11, i64* %10)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 0, i32* %4
br label %44
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = call i64 @dot_quad_addr(i8* %16, i64* %8)
%18 = icmp ne i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = load i8*, i8** %6
%21 = call i64 @dot_quad_addr(i8* %20, i64* %9)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19, %15
%24 = load i8*, i8** %5
%25 = load i8*, i8** %6
%26 = call i32 @tcpd_warn(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %24, i8* %25)
store i32 0, i32* %4
br label %44
27: ; preds = %19
%28 = load i64, i64* %8
%29 = load i64, i64* %9
%30 = xor i64 %29, -1
%31 = and i64 %28, %30
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %27
%34 = load i8*, i8** %5
%35 = load i8*, i8** %6
%36 = call i32 @tcpd_warn(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %34, i8* %35)
br label %37
37: ; preds = %33, %27
%38 = load i64, i64* %10
%39 = load i64, i64* %9
%40 = and i64 %38, %39
%41 = load i64, i64* %8
%42 = icmp eq i64 %40, %41
%43 = zext i1 %42 to i32
store i32 %43, i32* %4
br label %44
44: ; preds = %37, %23, %14
%45 = load i32, i32* %4
ret i32 %45
}

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