#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*/ atoi(char *);
int /*<<< orphan*/ free_regexp_matches(char **);
int ipv4_check_ip(char *);
int ipv4_check_prefixlen(int /*<<< orphan*/);
int /*<<< orphan*/ regexp_match_grab(char const *, char const *, int, char **);
short int ipv4_check_prefix(const char *prefix) {
  char *matches[1 + 2];
  const char *pattern = "^("
                        "[1-2]?[0-9]?[0-9]"
                        "\\."
                        "[1-2]?[0-9]?[0-9]"
                        "\\."
                        "[1-2]?[0-9]?[0-9]"
                        "\\."
                        "[1-2]?[0-9]?[0-9]"
                        ")"
                        "/("
                        "[1-3]?[0-9]"
                        ")$";
  int err = 0;
  if (!regexp_match_grab(prefix, pattern, 1, matches))
    return -1;
  err = ipv4_check_ip(matches[0]);
  err &= ipv4_check_prefixlen(atoi(matches[1]));
  free_regexp_matches(matches);
  return err;
}


x86 assembly (clang, -O0):
<ipv4_check_prefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe9d(%rip),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
lea    -0x30(%rbp),%rcx
mov    $0x1,%edx
call   1030 <regexp_match_grab@plt>
cmp    $0x0,%eax
jne    1198 <ipv4_check_prefix+0x48>
movw   $0xffff,-0x2(%rbp)
jmp    11ca <ipv4_check_prefix+0x7a>
mov    -0x30(%rbp),%rdi
call   1040 <ipv4_check_ip@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,%edi
call   1050 <ipv4_check_prefixlen@plt>
and    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
lea    -0x30(%rbp),%rdi
call   1070 <free_regexp_matches@plt>
mov    -0x3c(%rbp),%eax
mov    %ax,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipv4_check_prefix>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xea3(%rip),%rsi
mov    %rsp,%rcx
mov    $0x1,%edx
call   1030 <regexp_match_grab@plt>
test   %eax,%eax
je     1198 <ipv4_check_prefix+0x48>
mov    (%rsp),%rdi
call   1040 <ipv4_check_ip@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rdi
call   1060 <atoi@plt>
mov    %eax,%edi
call   1050 <ipv4_check_prefixlen@plt>
mov    %eax,%ebx
and    %ebp,%ebx
mov    %rsp,%rdi
call   1070 <free_regexp_matches@plt>
jmp    119c <ipv4_check_prefix+0x4c>
mov    $0xffff,%bx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [93 x i8] c"^([1-2]?[0-9]?[0-9]\\.[1-2]?[0-9]?[0-9]\\.[1-2]?[0-9]?[0-9]\\.[1-2]?[0-9]?[0-9])/([1-3]?[0-9])$\00"
define signext i16 @ipv4_check_prefix(i8* %0) {
%2 = alloca i16
%3 = alloca i8*
%4 = alloca [3 x i8*]
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str, i64 0, i64 0), i8** %5
store i32 0, i32* %6
%7 = load i8*, i8** %3
%8 = load i8*, i8** %5
%9 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%10 = call i32 @regexp_match_grab(i8* %7, i8* %8, i32 1, i8** %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %1
store i16 -1, i16* %2
br label %27
13: ; preds = %1
%14 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @ipv4_check_ip(i8* %15)
store i32 %16, i32* %6
%17 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
%20 = call i32 @ipv4_check_prefixlen(i32 %19)
%21 = load i32, i32* %6
%22 = and i32 %21, %20
store i32 %22, i32* %6
%23 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%24 = call i32 @free_regexp_matches(i8** %23)
%25 = load i32, i32* %6
%26 = trunc i32 %25 to i16
store i16 %26, i16* %2
br label %27
27: ; preds = %13, %12
%28 = load i16, i16* %2
ret i16 %28
}

LLVM IR (-O2):
@.str = [93 x i8] c"^([1-2]?[0-9]?[0-9]\\.[1-2]?[0-9]?[0-9]\\.[1-2]?[0-9]?[0-9]\\.[1-2]?[0-9]?[0-9])/([1-3]?[0-9])$\00"
define signext i16 @ipv4_check_prefix(i8* %0) {
%2 = alloca [3 x i8*]
%3 = bitcast [3 x i8*]* %2 to i8*
%4 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
%5 = call i32 @regexp_match_grab(i8* %0, i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str, i64 0, i64 0), i32 1, i8** %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %1
%8 = load i8*, i8** %4
%9 = call i32 @ipv4_check_ip(i8* %8)
%10 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @atoi(i8* %11)
%13 = call i32 @ipv4_check_prefixlen(i32 %12)
%14 = and i32 %13, %9
%15 = call i32 @free_regexp_matches(i8** %4)
%16 = trunc i32 %14 to i16
br label %17
17: ; preds = %1, %7
%18 = phi i16 [ %16, %7 ], [ -1, %1 ]
ret i16 %18
}