#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 uint32_t;
struct in_addr {
  int dummy;
};

/* Variables and functions */
int htonl(int);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ memcpy(struct in_addr *, int *, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ re_match(char *, char *);
int sscanf(char *, char *, unsigned int *, unsigned int *, unsigned int *,
           unsigned int *, unsigned int *, unsigned int *, unsigned int *,
           unsigned int *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ validateType(char *, char *, int);
int check_address(char *addr) {
  if (re_match(addr, "^[^-]+-[^-]+")) {
    if (!validateType("ipv4range", addr, 1)) {
      printf("Error: [%s] is not a valid IPv4 address range\n", addr);
      return 0;
    }
    unsigned int a1[4], a2[4];
    uint32_t addr1 = 0;
    uint32_t addr2 = 0;
    uint32_t mask = 0xffffff00;
    if (sscanf(addr, "%u.%u.%u.%u-%u.%u.%u.%u", &a1[0], &a1[1], &a1[2], &a1[3],
               &a2[0], &a2[1], &a2[2], &a2[3]) != 8)
      return 0;
    int i;
    for (i = 0; i < 4; ++i) {
      addr1 <<= 8;
      addr1 |= a1[i];
      addr2 <<= 8;
      addr2 |= a2[i];
    }
    addr1 = addr1 & mask;
    addr2 = addr2 & mask;
    struct in_addr in;
    if (addr1 != addr2) {
      addr1 = htonl(addr1);
      memcpy(&in, &addr1, sizeof(struct in_addr));
      printf("Error: address range must be within %s/24\n", inet_ntoa(in));
      return 0;
    }
    return 1;
  }
  if (strcmp(addr, "0.0.0.0") == 0) {
    printf("Error: zero IP address not valid in address-group");
    return 0;
  }
  if (!validateType("ipv4", addr, 1)) {
    printf("Error: [%s] isn't valid IPv4 address\n", addr);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<check_address>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x78,%rsp
mov    %rdi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1040 <re_match@plt>
cmp    $0x0,%rax
je     1321 <check_address+0x1a1>
mov    -0x18(%rbp),%rsi
lea    0xe5b(%rip),%rdi
mov    $0x1,%edx
call   1030 <validateType@plt>
cmp    $0x0,%eax
jne    11e3 <check_address+0x63>
mov    -0x18(%rbp),%rsi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0xc(%rbp)
jmp    1398 <check_address+0x218>
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0xffffff00,-0x4c(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    -0x30(%rbp),%rcx
add    $0x4,%rcx
lea    -0x30(%rbp),%r8
add    $0x8,%r8
lea    -0x30(%rbp),%r9
add    $0xc,%r9
lea    -0x40(%rbp),%rbx
lea    -0x40(%rbp),%r11
add    $0x4,%r11
lea    -0x40(%rbp),%r10
add    $0x8,%r10
lea    -0x40(%rbp),%rax
add    $0xc,%rax
lea    0xe0b(%rip),%rsi
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   10a0 <sscanf@plt>
cmp    $0x8,%eax
je     1268 <check_address+0xe8>
movl   $0x0,-0xc(%rbp)
jmp    1398 <check_address+0x218>
movl   $0x0,-0x50(%rbp)
cmpl   $0x4,-0x50(%rbp)
jge    12b5 <check_address+0x135>
mov    -0x44(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x44(%rbp)
movslq -0x50(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
or     -0x44(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x48(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x48(%rbp)
movslq -0x50(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
or     -0x48(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    126f <check_address+0xef>
mov    -0x44(%rbp),%eax
and    -0x4c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x48(%rbp),%eax
and    -0x4c(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x48(%rbp),%eax
je     1315 <check_address+0x195>
mov    -0x44(%rbp),%edi
call   1070 <htonl@plt>
mov    %eax,-0x44(%rbp)
lea    -0x58(%rbp),%rdi
lea    -0x44(%rbp),%rsi
mov    $0x4,%edx
call   1090 <memcpy@plt>
mov    -0x58(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0xc(%rbp)
jmp    1398 <check_address+0x218>
movl   $0x1,-0xc(%rbp)
jmp    1398 <check_address+0x218>
mov    -0x18(%rbp),%rdi
lea    0xd5d(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1355 <check_address+0x1d5>
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0xc(%rbp)
jmp    1398 <check_address+0x218>
mov    -0x18(%rbp),%rsi
lea    0xd63(%rip),%rdi
mov    $0x1,%edx
call   1030 <validateType@plt>
cmp    $0x0,%eax
jne    1391 <check_address+0x211>
mov    -0x18(%rbp),%rsi
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0xc(%rbp)
jmp    1398 <check_address+0x218>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x78,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_address>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
lea    0xe70(%rip),%rsi
call   1040 <re_match@plt>
test   %rax,%rax
je     1285 <check_address+0x105>
lea    0xe68(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <validateType@plt>
test   %eax,%eax
je     12bf <check_address+0x13f>
lea    0x14(%rsp),%rcx
lea    0x18(%rsp),%r8
lea    0x1c(%rsp),%r9
lea    0x4(%rsp),%r10
lea    0x8(%rsp),%rbp
lea    0xc(%rsp),%rax
mov    %rsp,%r11
lea    0xe64(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
push   %rax
push   %rbp
push   %r10
push   %r11
call   10a0 <sscanf@plt>
add    $0x20,%rsp
xor    %ebp,%ebp
cmp    $0x8,%eax
jne    12e4 <check_address+0x164>
mov    0x10(%rsp),%eax
mov    0x14(%rsp),%ecx
mov    (%rsp),%edx
mov    0x4(%rsp),%esi
shl    $0x10,%eax
shl    $0x8,%ecx
or     %eax,%ecx
or     0x18(%rsp),%ecx
shl    $0x10,%edx
shl    $0x8,%esi
or     %edx,%esi
or     0x8(%rsp),%esi
shl    $0x8,%ecx
shl    $0x8,%esi
mov    $0xffffff00,%eax
mov    0x1c(%rsp),%edi
and    %eax,%edi
and    0xc(%rsp),%eax
or     %ecx,%edi
or     %esi,%eax
mov    $0x1,%ebp
cmp    %eax,%edi
je     12e4 <check_address+0x164>
call   1070 <htonl@plt>
mov    %eax,0x24(%rsp)
lea    0x20(%rsp),%rdi
lea    0x24(%rsp),%rsi
mov    $0x4,%edx
call   1090 <memcpy@plt>
mov    0x20(%rsp),%edi
call   1050 <inet_ntoa@plt>
lea    0xde0(%rip),%rdi
xor    %ebp,%ebp
mov    %rax,%rsi
jmp    12cb <check_address+0x14b>
lea    0xdfd(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12d4 <check_address+0x154>
lea    0xe23(%rip),%rdi
mov    $0x1,%ebp
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <validateType@plt>
test   %eax,%eax
jne    12e4 <check_address+0x164>
lea    0xe0b(%rip),%rdi
jmp    12c6 <check_address+0x146>
lea    0xd51(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12e4 <check_address+0x164>
lea    0xdb6(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [13 x i8] c"^[^-]+-[^-]+\00"
@.str.1 = [10 x i8] c"ipv4range\00"
@.str.2 = [47 x i8] c"Error: [%s] is not a valid IPv4 address range\0A\00"
@.str.3 = [24 x i8] c"%u.%u.%u.%u-%u.%u.%u.%u\00"
@.str.4 = [43 x i8] c"Error: address range must be within %s/24\0A\00"
@.str.5 = [8 x i8] c"0.0.0.0\00"
@.str.6 = [50 x i8] c"Error: zero IP address not valid in address-group\00"
@.str.7 = [5 x i8] c"ipv4\00"
@.str.8 = [38 x i8] c"Error: [%s] isn't valid IPv4 address\0A\00"
define i32 @check_address(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [4 x i32]
%5 = alloca [4 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.in_addr
store i8* %0, i8** %3
%11 = load i8*, i8** %3
%12 = call i64 @re_match(i8* %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %77
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = call i32 @validateType(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %15, i32 1)
%17 = icmp ne i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %19)
store i32 0, i32* %2
br label %91
21: ; preds = %14
store i32 0, i32* %6
store i32 0, i32* %7
store i32 -256, i32* %8
%22 = load i8*, i8** %3
%23 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%24 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%25 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%27 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
%28 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 1
%29 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 2
%30 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 3
%31 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32* %23, i32* %24, i32* %25, i32* %26, i32* %27, i32* %28, i32* %29, i32* %30)
%32 = icmp ne i32 %31, 8
br i1 %32, label %33, label %34
33: ; preds = %21
store i32 0, i32* %2
br label %91
34: ; preds = %21
store i32 0, i32* %9
br label %35
35: ; preds = %55, %34
%36 = load i32, i32* %9
%37 = icmp slt i32 %36, 4
br i1 %37, label %38, label %58
38: ; preds = %35
%39 = load i32, i32* %6
%40 = shl i32 %39, 8
store i32 %40, i32* %6
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = load i32, i32* %6
%46 = or i32 %45, %44
store i32 %46, i32* %6
%47 = load i32, i32* %7
%48 = shl i32 %47, 8
store i32 %48, i32* %7
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 %50
%52 = load i32, i32* %51
%53 = load i32, i32* %7
%54 = or i32 %53, %52
store i32 %54, i32* %7
br label %55
55: ; preds = %38
%56 = load i32, i32* %9
%57 = add nsw i32 %56, 1
store i32 %57, i32* %9
br label %35
58: ; preds = %35
%59 = load i32, i32* %6
%60 = load i32, i32* %8
%61 = and i32 %59, %60
store i32 %61, i32* %6
%62 = load i32, i32* %7
%63 = load i32, i32* %8
%64 = and i32 %62, %63
store i32 %64, i32* %7
%65 = load i32, i32* %6
%66 = load i32, i32* %7
%67 = icmp ne i32 %65, %66
br i1 %67, label %68, label %76
68: ; preds = %58
%69 = load i32, i32* %6
%70 = call i32 @htonl(i32 %69)
store i32 %70, i32* %6
%71 = call i32 @memcpy(%struct.in_addr* %10, i32* %6, i32 4)
%72 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %10, i32 0, i32 0
%73 = load i32, i32* %72
%74 = call i8* @inet_ntoa(i32 %73)
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %74)
store i32 0, i32* %2
br label %91
76: ; preds = %58
store i32 1, i32* %2
br label %91
77: ; preds = %1
%78 = load i8*, i8** %3
%79 = call i64 @strcmp(i8* %78, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%80 = icmp eq i64 %79, 0
br i1 %80, label %81, label %83
81: ; preds = %77
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %2
br label %91
83: ; preds = %77
%84 = load i8*, i8** %3
%85 = call i32 @validateType(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %84, i32 1)
%86 = icmp ne i32 %85, 0
br i1 %86, label %90, label %87
87: ; preds = %83
%88 = load i8*, i8** %3
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i8* %88)
store i32 0, i32* %2
br label %91
90: ; preds = %83
store i32 1, i32* %2
br label %91
91: ; preds = %90, %87, %81, %76, %68, %33, %18
%92 = load i32, i32* %2
ret i32 %92
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@.str = [13 x i8] c"^[^-]+-[^-]+\00"
@.str.1 = [10 x i8] c"ipv4range\00"
@.str.2 = [47 x i8] c"Error: [%s] is not a valid IPv4 address range\0A\00"
@.str.3 = [24 x i8] c"%u.%u.%u.%u-%u.%u.%u.%u\00"
@.str.4 = [43 x i8] c"Error: address range must be within %s/24\0A\00"
@.str.5 = [8 x i8] c"0.0.0.0\00"
@.str.6 = [50 x i8] c"Error: zero IP address not valid in address-group\00"
@.str.7 = [5 x i8] c"ipv4\00"
@.str.8 = [38 x i8] c"Error: [%s] isn't valid IPv4 address\0A\00"
define i32 @check_address(i8* %0) {
%2 = alloca [4 x i32]
%3 = alloca [4 x i32]
%4 = alloca i32
%5 = alloca %struct.in_addr
%6 = tail call i64 @re_match(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %63, label %8
8: ; preds = %1
%9 = tail call i32 @validateType(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %73
13: ; preds = %8
%14 = bitcast [4 x i32]* %2 to i8*
%15 = bitcast [4 x i32]* %3 to i8*
%16 = bitcast i32* %4 to i8*
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
%21 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%23 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%24 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%25 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32* %17, i32* %18, i32* %19, i32* %20, i32* %21, i32* %22, i32* %23, i32* %24)
%26 = icmp eq i32 %25, 8
br i1 %26, label %27, label %61
27: ; preds = %13
%28 = load i32, i32* %17
%29 = load i32, i32* %21
%30 = load i32, i32* %18
%31 = load i32, i32* %22
%32 = shl i32 %28, 16
%33 = shl i32 %30, 8
%34 = or i32 %32, %33
%35 = load i32, i32* %19
%36 = or i32 %35, %34
%37 = shl i32 %29, 16
%38 = shl i32 %31, 8
%39 = or i32 %37, %38
%40 = load i32, i32* %23
%41 = or i32 %40, %39
%42 = shl i32 %36, 8
%43 = load i32, i32* %20
%44 = shl i32 %41, 8
%45 = load i32, i32* %24
%46 = and i32 %43, -256
%47 = or i32 %46, %42
%48 = and i32 %45, -256
%49 = or i32 %48, %44
%50 = bitcast %struct.in_addr* %5 to i8*
%51 = icmp eq i32 %47, %49
br i1 %51, label %59, label %52
52: ; preds = %27
%53 = call i32 @htonl(i32 %47)
store i32 %53, i32* %4
%54 = call i32 @memcpy(%struct.in_addr* %5, i32* %4, i32 4)
%55 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %5, i64 0, i32 0
%56 = load i32, i32* %55
%57 = call i8* @inet_ntoa(i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %57)
br label %59
59: ; preds = %27, %52
%60 = phi i32 [ 0, %52 ], [ 1, %27 ]
br label %61
61: ; preds = %13, %59
%62 = phi i32 [ %60, %59 ], [ 0, %13 ]
br label %73
63: ; preds = %1
%64 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %63
%67 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0))
br label %73
68: ; preds = %63
%69 = tail call i32 @validateType(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %0, i32 1)
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i8* %0)
br label %73
73: ; preds = %68, %71, %66, %61, %11
%74 = phi i32 [ %62, %61 ], [ 0, %11 ], [ 0, %66 ], [ 0, %71 ], [ 1, %68 ]
ret i32 %74
}