#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 */
int /*<<< orphan*/ AF_INET;
int addressOK(unsigned char *a, int bits, int family) {
  int byte;
  int nbits;
  int maxbits;
  int maxbytes;
  unsigned char mask;
  if (family == (AF_INET + 0)) {
    maxbits = 32;
    maxbytes = 4;
  } else {
    maxbits = 128;
    maxbytes = 16;
  }
  if (bits >= maxbits)
    return 1;
  byte = bits / 8;
  nbits = bits % 8;
  mask = 0xff;
  if (bits != 0)
    mask >>= nbits;
  while (byte < maxbytes) {
    if ((a[byte] & mask) != 0)
      return 0;
    mask = 0xff;
    byte++;
  }
  return 1;
}


x86 assembly (clang, -O0):
<addressOK>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2ed0(%rip),%rcx
mov    (%rcx),%ecx
add    $0x0,%ecx
cmp    %ecx,%eax
jne    1138 <addressOK+0x38>
movl   $0x20,-0x24(%rbp)
movl   $0x4,-0x28(%rbp)
jmp    1146 <addressOK+0x46>
movl   $0x80,-0x24(%rbp)
movl   $0x10,-0x28(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
jl     115e <addressOK+0x5e>
movl   $0x1,-0x4(%rbp)
jmp    11e5 <addressOK+0xe5>
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
movb   $0xff,-0x29(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1194 <addressOK+0x94>
mov    -0x20(%rbp),%ecx
movzbl -0x29(%rbp),%eax
sar    %cl,%eax
mov    %al,-0x29(%rbp)
jmp    1199 <addressOK+0x99>
mov    -0x1c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11de <addressOK+0xde>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
movzbl -0x29(%rbp),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11cc <addressOK+0xcc>
movl   $0x0,-0x4(%rbp)
jmp    11e5 <addressOK+0xe5>
movb   $0xff,-0x29(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1199 <addressOK+0x99>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<addressOK>:
mov    0x2ee1(%rip),%rax
cmp    %edx,(%rax)
mov    $0x20,%eax
mov    $0x80,%ecx
cmove  %eax,%ecx
mov    $0x4,%eax
mov    $0x10,%r8d
cmove  %eax,%r8d
mov    $0x1,%eax
cmp    %esi,%ecx
jle    1176 <addressOK+0x76>
lea    0x7(%rsi),%r9d
test   %esi,%esi
cmovns %esi,%r9d
sar    $0x3,%r9d
cmp    %r8d,%r9d
jge    1176 <addressOK+0x76>
mov    %esi,%ecx
and    $0x7,%cl
mov    $0xff,%r10d
mov    $0xff,%edx
shr    %cl,%edx
test   %esi,%esi
cmove  %r10d,%edx
movslq %r9d,%rcx
mov    %r8d,%r8d
nop
movzbl (%rdi,%rcx,1),%esi
test   %esi,%edx
jne    1177 <addressOK+0x77>
add    $0x1,%rcx
mov    $0xff,%edx
cmp    %rcx,%r8
jne    1160 <addressOK+0x60>
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
@AF_INET = global i32 0
define i32 @addressOK(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%13 = load i32, i32* %7
%14 = load i32, i32* @AF_INET
%15 = add nsw i32 %14, 0
%16 = icmp eq i32 %13, %15
br i1 %16, label %17, label %18
17: ; preds = %3
store i32 32, i32* %10
store i32 4, i32* %11
br label %19
18: ; preds = %3
store i32 128, i32* %10
store i32 16, i32* %11
br label %19
19: ; preds = %18, %17
%20 = load i32, i32* %6
%21 = load i32, i32* %10
%22 = icmp sge i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 1, i32* %4
br label %58
24: ; preds = %19
%25 = load i32, i32* %6
%26 = sdiv i32 %25, 8
store i32 %26, i32* %8
%27 = load i32, i32* %6
%28 = srem i32 %27, 8
store i32 %28, i32* %9
store i8 -1, i8* %12
%29 = load i32, i32* %6
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %24
%32 = load i32, i32* %9
%33 = load i8, i8* %12
%34 = zext i8 %33 to i32
%35 = ashr i32 %34, %32
%36 = trunc i32 %35 to i8
store i8 %36, i8* %12
br label %37
37: ; preds = %31, %24
br label %38
38: ; preds = %54, %37
%39 = load i32, i32* %8
%40 = load i32, i32* %11
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %57
42: ; preds = %38
%43 = load i8*, i8** %5
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = load i8, i8* %12
%50 = zext i8 %49 to i32
%51 = and i32 %48, %50
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %42
store i32 0, i32* %4
br label %58
54: ; preds = %42
store i8 -1, i8* %12
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
store i32 %56, i32* %8
br label %38
57: ; preds = %38
store i32 1, i32* %4
br label %58
58: ; preds = %57, %53, %23
%59 = load i32, i32* %4
ret i32 %59
}

LLVM IR (-O2):
@AF_INET = global i32 0
define i32 @addressOK(i8* nocapture %0, i32 %1, i32 %2) {
%4 = load i32, i32* @AF_INET
%5 = icmp eq i32 %4, %2
%6 = select i1 %5, i32 32, i32 128
%7 = select i1 %5, i32 4, i32 16
%8 = icmp sgt i32 %6, %1
br i1 %8, label %9, label %30
9: ; preds = %3
%10 = sdiv i32 %1, 8
%11 = icmp slt i32 %10, %7
br i1 %11, label %12, label %30
12: ; preds = %9
%13 = icmp eq i32 %1, 0
%14 = and i32 %1, 7
%15 = lshr i32 255, %14
%16 = select i1 %13, i32 255, i32 %15
%17 = sext i32 %10 to i64
%18 = zext i32 %7 to i64
br label %21
19: ; preds = %21
%20 = icmp eq i64 %29, %18
br i1 %20, label %30, label %21
21: ; preds = %12, %19
%22 = phi i64 [ %17, %12 ], [ %29, %19 ]
%23 = phi i32 [ %16, %12 ], [ 255, %19 ]
%24 = getelementptr inbounds i8, i8* %0, i64 %22
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = and i32 %23, %26
%28 = icmp eq i32 %27, 0
%29 = add nsw i64 %22, 1
br i1 %28, label %19, label %30
30: ; preds = %21, %19, %9, %3
%31 = phi i32 [ 1, %3 ], [ 1, %9 ], [ 0, %21 ], [ 1, %19 ]
ret i32 %31
}