#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 */
typedef int /*<<< orphan*/ IPAddressOrRanges;

/* Variables and functions */
int /*<<< orphan*/ extract_min_max(int /*<<< orphan*/, unsigned char *,
                                   unsigned char *, int);
scalar_t__ memcmp(unsigned char *, unsigned char *, int);
int sk_IPAddressOrRange_num(int /*<<< orphan*/ *);
int /*<<< orphan*/ sk_IPAddressOrRange_value(int /*<<< orphan*/ *, int);
int addr_contains(IPAddressOrRanges *parent, IPAddressOrRanges *child,
                  int length) {
  unsigned char p_min[16], p_max[16];
  unsigned char c_min[16], c_max[16];
  int p, c;
  if (child == NULL || parent == child)
    return 1;
  if (parent == NULL)
    return 0;
  p = 0;
  for (c = 0; c < sk_IPAddressOrRange_num(child); c++) {
    if (!extract_min_max(sk_IPAddressOrRange_value(child, c), c_min, c_max,
                         length))
      return -1;
    for (;; p++) {
      if (p >= sk_IPAddressOrRange_num(parent))
        return 0;
      if (!extract_min_max(sk_IPAddressOrRange_value(parent, p), p_min, p_max,
                           length))
        return 0;
      if (memcmp(p_max, c_max, length) < 0)
        continue;
      if (memcmp(p_min, c_min, length) > 0)
        return 0;
      break;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<addr_contains>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     116c <addr_contains+0x2c>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    1178 <addr_contains+0x38>
movl   $0x1,-0x4(%rbp)
jmp    12be <addr_contains+0x17e>
cmpq   $0x0,-0x10(%rbp)
jne    118f <addr_contains+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    12be <addr_contains+0x17e>
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <sk_IPAddressOrRange_num@plt>
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
cmp    %ecx,%eax
jge    12b7 <addr_contains+0x177>
mov    -0x18(%rbp),%rdi
mov    -0x68(%rbp),%esi
call   1050 <sk_IPAddressOrRange_value@plt>
mov    %eax,%edi
lea    -0x50(%rbp),%rsi
lea    -0x60(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <extract_min_max@plt>
cmp    $0x0,%eax
jne    11ec <addr_contains+0xac>
movl   $0xffffffff,-0x4(%rbp)
jmp    12be <addr_contains+0x17e>
jmp    11f1 <addr_contains+0xb1>
mov    -0x64(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <sk_IPAddressOrRange_num@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%eax
cmp    %ecx,%eax
jl     1219 <addr_contains+0xd9>
movl   $0x0,-0x4(%rbp)
jmp    12be <addr_contains+0x17e>
mov    -0x10(%rbp),%rdi
mov    -0x64(%rbp),%esi
call   1050 <sk_IPAddressOrRange_value@plt>
mov    %eax,%edi
lea    -0x30(%rbp),%rsi
lea    -0x40(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <extract_min_max@plt>
cmp    $0x0,%eax
jne    124c <addr_contains+0x10c>
movl   $0x0,-0x4(%rbp)
jmp    12be <addr_contains+0x17e>
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jge    126b <addr_contains+0x12b>
jmp    1296 <addr_contains+0x156>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jle    1291 <addr_contains+0x151>
movl   $0x0,-0x4(%rbp)
jmp    12be <addr_contains+0x17e>
jmp    12a4 <addr_contains+0x164>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11f1 <addr_contains+0xb1>
jmp    12a9 <addr_contains+0x169>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    119d <addr_contains+0x5d>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addr_contains>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
test   %rsi,%rsi
je     126d <addr_contains+0x12d>
mov    %rsi,%rbp
mov    %rdi,%rbx
cmp    %rsi,%rdi
je     126d <addr_contains+0x12d>
test   %rbx,%rbx
je     1275 <addr_contains+0x135>
mov    %edx,%r15d
mov    %rbp,%rdi
call   1060 <sk_IPAddressOrRange_num@plt>
test   %eax,%eax
jle    126d <addr_contains+0x12d>
xor    %r13d,%r13d
lea    0x10(%rsp),%r14
lea    0x30(%rsp),%rcx
xor    %r12d,%r12d
mov    %rbp,0x8(%rsp)
mov    %rbp,%rdi
mov    %r13d,%esi
mov    %rcx,%rbp
call   1050 <sk_IPAddressOrRange_value@plt>
mov    %eax,%edi
mov    %r14,%rsi
mov    %rbp,%r14
mov    %rbp,%rdx
mov    %r15d,%ecx
call   1030 <extract_min_max@plt>
test   %eax,%eax
je     128a <addr_contains+0x14a>
mov    %r13d,0x4(%rsp)
mov    %rbx,%rdi
call   1060 <sk_IPAddressOrRange_num@plt>
xor    %r13d,%r13d
cmp    %eax,%r12d
jge    1278 <addr_contains+0x138>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r12d,%esi
call   1050 <sk_IPAddressOrRange_value@plt>
mov    %eax,%edi
lea    0x20(%rsp),%rsi
lea    0x40(%rsp),%rbp
mov    %rbp,%rdx
mov    %r15d,%ecx
call   1030 <extract_min_max@plt>
test   %eax,%eax
je     1278 <addr_contains+0x138>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
jns    122c <addr_contains+0xec>
add    $0x1,%r12d
mov    %rbx,%rdi
call   1060 <sk_IPAddressOrRange_num@plt>
cmp    %eax,%r12d
jl     11e0 <addr_contains+0xa0>
jmp    1278 <addr_contains+0x138>
lea    0x20(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r15d,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
jg     1278 <addr_contains+0x138>
mov    0x4(%rsp),%r13d
add    $0x1,%r13d
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <sk_IPAddressOrRange_num@plt>
cmp    %eax,%r13d
lea    0x10(%rsp),%rax
mov    %r14,%rcx
mov    %rax,%r14
jl     1197 <addr_contains+0x57>
mov    $0x1,%r13d
jmp    1278 <addr_contains+0x138>
xor    %r13d,%r13d
mov    %r13d,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%r13d
jmp    1278 <addr_contains+0x138>

LLVM IR (-O0):
define i32 @addr_contains(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [16 x i8]
%9 = alloca [16 x i8]
%10 = alloca [16 x i8]
%11 = alloca [16 x i8]
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%14 = load i32*, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %20, label %16
16: ; preds = %3
%17 = load i32*, i32** %5
%18 = load i32*, i32** %6
%19 = icmp eq i32* %17, %18
br i1 %19, label %20, label %21
20: ; preds = %16, %3
store i32 1, i32* %4
br label %81
21: ; preds = %16
%22 = load i32*, i32** %5
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 0, i32* %4
br label %81
25: ; preds = %21
store i32 0, i32* %12
store i32 0, i32* %13
br label %26
26: ; preds = %77, %25
%27 = load i32, i32* %13
%28 = load i32*, i32** %6
%29 = call i32 @sk_IPAddressOrRange_num(i32* %28)
%30 = icmp slt i32 %27, %29
br i1 %30, label %31, label %80
31: ; preds = %26
%32 = load i32*, i32** %6
%33 = load i32, i32* %13
%34 = call i32 @sk_IPAddressOrRange_value(i32* %32, i32 %33)
%35 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%37 = load i32, i32* %7
%38 = call i32 @extract_min_max(i32 %34, i8* %35, i8* %36, i32 %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %31
store i32 -1, i32* %4
br label %81
41: ; preds = %31
br label %42
42: ; preds = %73, %41
%43 = load i32, i32* %12
%44 = load i32*, i32** %5
%45 = call i32 @sk_IPAddressOrRange_num(i32* %44)
%46 = icmp sge i32 %43, %45
br i1 %46, label %47, label %48
47: ; preds = %42
store i32 0, i32* %4
br label %81
48: ; preds = %42
%49 = load i32*, i32** %5
%50 = load i32, i32* %12
%51 = call i32 @sk_IPAddressOrRange_value(i32* %49, i32 %50)
%52 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%53 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%54 = load i32, i32* %7
%55 = call i32 @extract_min_max(i32 %51, i8* %52, i8* %53, i32 %54)
%56 = icmp ne i32 %55, 0
br i1 %56, label %58, label %57
57: ; preds = %48
store i32 0, i32* %4
br label %81
58: ; preds = %48
%59 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%60 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%61 = load i32, i32* %7
%62 = call i64 @memcmp(i8* %59, i8* %60, i32 %61)
%63 = icmp slt i64 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %58
br label %73
65: ; preds = %58
%66 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%67 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%68 = load i32, i32* %7
%69 = call i64 @memcmp(i8* %66, i8* %67, i32 %68)
%70 = icmp sgt i64 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %65
store i32 0, i32* %4
br label %81
72: ; preds = %65
br label %76
73: ; preds = %64
%74 = load i32, i32* %12
%75 = add nsw i32 %74, 1
store i32 %75, i32* %12
br label %42
76: ; preds = %72
br label %77
77: ; preds = %76
%78 = load i32, i32* %13
%79 = add nsw i32 %78, 1
store i32 %79, i32* %13
br label %26
80: ; preds = %26
store i32 1, i32* %4
br label %81
81: ; preds = %80, %71, %57, %47, %40, %24, %20
%82 = load i32, i32* %4
ret i32 %82
}

LLVM IR (-O2):
define i32 @addr_contains(i32* %0, i32* %1, i32 %2) {
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = alloca [16 x i8]
%7 = alloca [16 x i8]
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%12 = icmp eq i32* %1, null
%13 = icmp eq i32* %0, %1
%14 = or i1 %12, %13
br i1 %14, label %48, label %15
15: ; preds = %3
%16 = icmp eq i32* %0, null
br i1 %16, label %48, label %17
17: ; preds = %15
%18 = call i32 @sk_IPAddressOrRange_num(i32* %1)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %23, label %48
20: ; preds = %40
%21 = call i32 @sk_IPAddressOrRange_num(i32* %1)
%22 = icmp slt i32 %43, %21
br i1 %22, label %23, label %48
23: ; preds = %17, %20
%24 = phi i32 [ %43, %20 ], [ 0, %17 ]
%25 = phi i32 [ %33, %20 ], [ 0, %17 ]
%26 = call i32 @sk_IPAddressOrRange_value(i32* %1, i32 %24)
%27 = call i32 @extract_min_max(i32 %26, i8* %10, i8* %11, i32 %2)
%28 = icmp eq i32 %27, 0
br i1 %28, label %48, label %29
29: ; preds = %23
%30 = call i32 @sk_IPAddressOrRange_num(i32* %0)
%31 = icmp slt i32 %25, %30
br i1 %31, label %32, label %48
32: ; preds = %29, %44
%33 = phi i32 [ %45, %44 ], [ %25, %29 ]
%34 = call i32 @sk_IPAddressOrRange_value(i32* %0, i32 %33)
%35 = call i32 @extract_min_max(i32 %34, i8* %8, i8* %9, i32 %2)
%36 = icmp eq i32 %35, 0
br i1 %36, label %48, label %37
37: ; preds = %32
%38 = call i64 @memcmp(i8* %9, i8* %11, i32 %2)
%39 = icmp slt i64 %38, 0
br i1 %39, label %44, label %40
40: ; preds = %37
%41 = call i64 @memcmp(i8* %8, i8* %10, i32 %2)
%42 = icmp sgt i64 %41, 0
%43 = add nuw nsw i32 %24, 1
br i1 %42, label %48, label %20
44: ; preds = %37
%45 = add nsw i32 %33, 1
%46 = call i32 @sk_IPAddressOrRange_num(i32* %0)
%47 = icmp slt i32 %45, %46
br i1 %47, label %32, label %48
48: ; preds = %23, %40, %20, %29, %44, %32, %17, %15, %3
%49 = phi i32 [ 1, %3 ], [ 0, %15 ], [ 1, %17 ], [ 0, %32 ], [ 0, %44 ], [ 0, %29 ], [ -1, %23 ], [ 0, %40 ], [ 1, %20 ]
ret i32 %49
}