#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 scalar_t__ uint32_t;
typedef int /*<<< orphan*/ regex_t;

/* Variables and functions */
int REG_EXTENDED;
int REG_NOSUB;
scalar_t__ addr_to_bin(char *);
int /*<<< orphan*/ free(char *);
char *malloc(size_t const);
int /*<<< orphan*/ regcomp(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ regexec(int /*<<< orphan*/ *, char const *, size_t,
                           int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ split_range(char const *, char **, char **);
int strlen(char const *);
scalar_t__ validate_addr(char *);
bool parse_range(const char *range, uint32_t *ip1, uint32_t *ip2) {
  regex_t myregex;
  bool status = false;
  regcomp(&myregex, "^([0-9\\.]){7,15}-([0-9\\.]){7,15}$",
          REG_EXTENDED | REG_NOSUB);
  if (!regexec(&myregex, range, (size_t)0, NULL, 0)) {
    const size_t size = (strlen(range) + 1) * sizeof(char);
    char *a = malloc(size);
    char *b = malloc(size);
    split_range(range, &a, &b);
    if (validate_addr(a) && validate_addr(b)) {
      *ip1 = addr_to_bin(a);
      *ip2 = addr_to_bin(b);
      status = true;
    }
    free(a);
    free(b);
  } else {
    *ip1 = 0;
    *ip2 = 0;
  }
  regfree(&myregex);
  return status;
}


x86 assembly (clang, -O0):
<parse_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
mov    0x2e25(%rip),%rax
or     (%rax),%edx
lea    -0x1c(%rbp),%rdi
lea    0xe38(%rip),%rsi
call   1060 <regcomp@plt>
mov    -0x8(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
mov    %rcx,%rdx
call   1090 <regexec@plt>
cmp    $0x0,%eax
jne    1298 <parse_range+0x108>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1070 <split_range@plt>
mov    -0x30(%rbp),%rdi
call   10b0 <validate_addr@plt>
cmp    $0x0,%rax
je     1281 <parse_range+0xf1>
mov    -0x38(%rbp),%rdi
call   10b0 <validate_addr@plt>
cmp    $0x0,%rax
je     1281 <parse_range+0xf1>
mov    -0x30(%rbp),%rdi
call   10a0 <addr_to_bin@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rdi
call   10a0 <addr_to_bin@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    12ae <parse_range+0x11e>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
lea    -0x1c(%rbp),%rdi
call   1040 <regfree@plt>
mov    -0x20(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_range>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r13
mov    0x2e2b(%rip),%rax
mov    0x2e2c(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe41(%rip),%rsi
lea    0x1c(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <regcomp@plt>
xor    %r12d,%r12d
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1090 <regexec@plt>
test   %eax,%eax
je     11f8 <parse_range+0x68>
movq   $0x0,(%r15)
movq   $0x0,(%r14)
jmp    1287 <parse_range+0xf7>
mov    %r13,%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rbx
mov    %rbx,%rdi
call   1080 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    %rbx,%rdi
call   1080 <malloc@plt>
mov    %rax,0x8(%rsp)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %r13,%rdi
call   1070 <split_range@plt>
mov    0x10(%rsp),%rdi
call   10b0 <validate_addr@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     1273 <parse_range+0xe3>
mov    0x8(%rsp),%rdi
call   10b0 <validate_addr@plt>
test   %rax,%rax
je     1273 <parse_range+0xe3>
mov    0x10(%rsp),%rdi
call   10a0 <addr_to_bin@plt>
mov    %rax,(%r15)
mov    0x8(%rsp),%rdi
call   10a0 <addr_to_bin@plt>
mov    %rax,(%r14)
mov    $0x1,%r12d
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
lea    0x1c(%rsp),%rdi
call   1040 <regfree@plt>
mov    %r12d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [34 x i8] c"^([0-9\\.]){7,15}-([0-9\\.]){7,15}$\00"
@REG_EXTENDED = global i32 0
@REG_NOSUB = global i32 0
define i32 @parse_range(i8* %0, i64* %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %4
store i64* %1, i64** %5
store i64* %2, i64** %6
store i32 0, i32* %8
%12 = load i32, i32* @REG_EXTENDED
%13 = load i32, i32* @REG_NOSUB
%14 = or i32 %12, %13
%15 = call i32 @regcomp(i32* %7, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i8*, i8** %4
%17 = call i32 @regexec(i32* %7, i8* %16, i64 0, i32* null, i32 0)
%18 = icmp ne i32 %17, 0
br i1 %18, label %50, label %19
19: ; preds = %3
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 1
store i64 %24, i64* %9
%25 = load i64, i64* %9
%26 = call i8* @malloc(i64 %25)
store i8* %26, i8** %10
%27 = load i64, i64* %9
%28 = call i8* @malloc(i64 %27)
store i8* %28, i8** %11
%29 = load i8*, i8** %4
%30 = call i32 @split_range(i8* %29, i8** %10, i8** %11)
%31 = load i8*, i8** %10
%32 = call i64 @validate_addr(i8* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %45
34: ; preds = %19
%35 = load i8*, i8** %11
%36 = call i64 @validate_addr(i8* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %34
%39 = load i8*, i8** %10
%40 = call i64 @addr_to_bin(i8* %39)
%41 = load i64*, i64** %5
store i64 %40, i64* %41
%42 = load i8*, i8** %11
%43 = call i64 @addr_to_bin(i8* %42)
%44 = load i64*, i64** %6
store i64 %43, i64* %44
store i32 1, i32* %8
br label %45
45: ; preds = %38, %34, %19
%46 = load i8*, i8** %10
%47 = call i32 @free(i8* %46)
%48 = load i8*, i8** %11
%49 = call i32 @free(i8* %48)
br label %53
50: ; preds = %3
%51 = load i64*, i64** %5
store i64 0, i64* %51
%52 = load i64*, i64** %6
store i64 0, i64* %52
br label %53
53: ; preds = %50, %45
%54 = call i32 @regfree(i32* %7)
%55 = load i32, i32* %8
ret i32 %55
}

LLVM IR (-O2):
@.str = [34 x i8] c"^([0-9\\.]){7,15}-([0-9\\.]){7,15}$\00"
@REG_EXTENDED = global i32 0
@REG_NOSUB = global i32 0
define i32 @parse_range(i8* %0, i64* nocapture writeonly %1, i64* nocapture writeonly %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = bitcast i32* %4 to i8*
%8 = load i32, i32* @REG_EXTENDED
%9 = load i32, i32* @REG_NOSUB
%10 = or i32 %9, %8
%11 = call i32 @regcomp(i32* %4, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i32 @regexec(i32* %4, i8* %0, i64 0, i32* null, i32 0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %41
14: ; preds = %3
%15 = call i32 @strlen(i8* %0)
%16 = add nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = bitcast i8** %5 to i8*
%19 = call i8* @malloc(i64 %17)
store i8* %19, i8** %5
%20 = bitcast i8** %6 to i8*
%21 = call i8* @malloc(i64 %17)
store i8* %21, i8** %6
%22 = call i32 @split_range(i8* %0, i8** %5, i8** %6)
%23 = load i8*, i8** %5
%24 = call i64 @validate_addr(i8* %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %35, label %26
26: ; preds = %14
%27 = load i8*, i8** %6
%28 = call i64 @validate_addr(i8* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %26
%31 = load i8*, i8** %5
%32 = call i64 @addr_to_bin(i8* %31)
store i64 %32, i64* %1
%33 = load i8*, i8** %6
%34 = call i64 @addr_to_bin(i8* %33)
store i64 %34, i64* %2
br label %35
35: ; preds = %30, %26, %14
%36 = phi i32 [ 1, %30 ], [ 0, %26 ], [ 0, %14 ]
%37 = load i8*, i8** %5
%38 = call i32 @free(i8* %37)
%39 = load i8*, i8** %6
%40 = call i32 @free(i8* %39)
br label %42
41: ; preds = %3
store i64 0, i64* %1
store i64 0, i64* %2
br label %42
42: ; preds = %41, %35
%43 = phi i32 [ 0, %41 ], [ %36, %35 ]
%44 = call i32 @regfree(i32* %4)
ret i32 %43
}