#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;

/* Variables and functions */
int /*<<< orphan*/ re_match(char const *, char *);
int sscanf(char const *, char *, unsigned int *, unsigned int *, unsigned int *,
           unsigned int *, unsigned int *);
int validate_ipv4net(const char *str) {
  if (!str)
    return 0;
  unsigned int a[4], plen;
  uint32_t addr;
  if (!re_match(str, "^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+/[0-9]+$"))
    return 0;
  if (sscanf(str, "%u.%u.%u.%u/%u", &a[0], &a[1], &a[2], &a[3], &plen) != 5)
    return 0;
  addr = 0;
  int i;
  for (i = 0; i < 4; i++) {
    if (a[i] > 255)
      return 0;
    addr <<= 8;
    addr |= a[i];
  }
  if ((plen == 0 && addr != 0) || plen > 32)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<validate_ipv4net>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1143 <validate_ipv4net+0x23>
movl   $0x0,-0x4(%rbp)
jmp    123d <validate_ipv4net+0x11d>
mov    -0x10(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1030 <re_match@plt>
cmp    $0x0,%eax
jne    1168 <validate_ipv4net+0x48>
movl   $0x0,-0x4(%rbp)
jmp    123d <validate_ipv4net+0x11d>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    -0x20(%rbp),%rcx
add    $0x4,%rcx
lea    -0x20(%rbp),%r8
add    $0x8,%r8
lea    -0x20(%rbp),%r9
add    $0xc,%r9
lea    0xe99(%rip),%rsi
lea    -0x24(%rbp),%rax
mov    %rax,(%rsp)
call   1040 <sscanf@plt>
cmp    $0x5,%eax
je     11b1 <validate_ipv4net+0x91>
movl   $0x0,-0x4(%rbp)
jmp    123d <validate_ipv4net+0x11d>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x4,-0x2c(%rbp)
jge    120c <validate_ipv4net+0xec>
movslq -0x2c(%rbp),%rax
cmpl   $0xff,-0x20(%rbp,%rax,4)
jbe    11e7 <validate_ipv4net+0xc7>
movl   $0x0,-0x4(%rbp)
jmp    123d <validate_ipv4net+0x11d>
mov    -0x28(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x28(%rbp)
movslq -0x2c(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11bf <validate_ipv4net+0x9f>
cmpl   $0x0,-0x24(%rbp)
jne    1220 <validate_ipv4net+0x100>
cmpl   $0x0,-0x28(%rbp)
jne    122a <validate_ipv4net+0x10a>
cmpl   $0x20,-0x24(%rbp)
jbe    1236 <validate_ipv4net+0x116>
movl   $0x0,-0x4(%rbp)
jmp    123d <validate_ipv4net+0x11d>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_ipv4net>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
test   %rdi,%rdi
je     11d2 <validate_ipv4net+0xb2>
mov    %rdi,%rbx
lea    0xec7(%rip),%rsi
call   1030 <re_match@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     11d4 <validate_ipv4net+0xb4>
lea    0x14(%rsp),%rcx
lea    0x18(%rsp),%r8
lea    0x1c(%rsp),%r9
lea    0x24(%rsp),%rax
mov    %rax,(%rsp)
lea    0xec1(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <sscanf@plt>
cmp    $0x5,%eax
jne    11d4 <validate_ipv4net+0xb4>
mov    0x10(%rsp),%ecx
cmp    $0xff,%ecx
ja     11d4 <validate_ipv4net+0xb4>
mov    0x14(%rsp),%edx
cmp    $0xff,%edx
ja     11d4 <validate_ipv4net+0xb4>
mov    0x18(%rsp),%eax
cmp    $0xff,%eax
ja     11d4 <validate_ipv4net+0xb4>
mov    0x1c(%rsp),%esi
cmp    $0xff,%esi
ja     11d4 <validate_ipv4net+0xb4>
shl    $0x10,%ecx
shl    $0x8,%edx
or     %ecx,%edx
or     %edx,%eax
shl    $0x8,%eax
mov    0x24(%rsp),%ecx
test   %ecx,%ecx
setne  %dl
or     %eax,%esi
sete   %al
or     %dl,%al
cmp    $0x21,%ecx
setb   %cl
and    %al,%cl
movzbl %cl,%ebp
jmp    11d4 <validate_ipv4net+0xb4>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+/[0-9]+$\00"
@.str.1 = [15 x i8] c"%u.%u.%u.%u/%u\00"
define i32 @validate_ipv4net(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [4 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store i32 0, i32* %2
br label %59
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 @re_match(i8* %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %11
store i32 0, i32* %2
br label %59
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%21 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%22 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32* %18, i32* %19, i32* %20, i32* %21, i32* %5)
%23 = icmp ne i32 %22, 5
br i1 %23, label %24, label %25
24: ; preds = %16
store i32 0, i32* %2
br label %59
25: ; preds = %16
store i32 0, i32* %6
store i32 0, i32* %7
br label %26
26: ; preds = %45, %25
%27 = load i32, i32* %7
%28 = icmp slt i32 %27, 4
br i1 %28, label %29, label %48
29: ; preds = %26
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = icmp ugt i32 %33, 255
br i1 %34, label %35, label %36
35: ; preds = %29
store i32 0, i32* %2
br label %59
36: ; preds = %29
%37 = load i32, i32* %6
%38 = shl i32 %37, 8
store i32 %38, i32* %6
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = load i32, i32* %6
%44 = or i32 %43, %42
store i32 %44, i32* %6
br label %45
45: ; preds = %36
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %26
48: ; preds = %26
%49 = load i32, i32* %5
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i32, i32* %6
%53 = icmp ne i32 %52, 0
br i1 %53, label %57, label %54
54: ; preds = %51, %48
%55 = load i32, i32* %5
%56 = icmp ugt i32 %55, 32
br i1 %56, label %57, label %58
57: ; preds = %54, %51
store i32 0, i32* %2
br label %59
58: ; preds = %54
store i32 1, i32* %2
br label %59
59: ; preds = %58, %57, %35, %24, %15, %10
%60 = load i32, i32* %2
ret i32 %60
}

LLVM IR (-O2):
@.str = [40 x i8] c"^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+/[0-9]+$\00"
@.str.1 = [15 x i8] c"%u.%u.%u.%u/%u\00"
define i32 @validate_ipv4net(i8* %0) {
%2 = alloca [4 x i32]
%3 = alloca i32
%4 = icmp eq i8* %0, null
br i1 %4, label %46, label %5
5: ; preds = %1
%6 = bitcast [4 x i32]* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = tail call i32 @re_match(i8* %0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %44, label %10
10: ; preds = %5
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
%15 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32* %11, i32* %12, i32* %13, i32* %14, i32* %3)
%16 = icmp eq i32 %15, 5
br i1 %16, label %17, label %44
17: ; preds = %10
%18 = load i32, i32* %11
%19 = icmp ugt i32 %18, 255
br i1 %19, label %44, label %20
20: ; preds = %17
%21 = load i32, i32* %12
%22 = icmp ugt i32 %21, 255
br i1 %22, label %44, label %23
23: ; preds = %20
%24 = load i32, i32* %13
%25 = icmp ugt i32 %24, 255
br i1 %25, label %44, label %26
26: ; preds = %23
%27 = load i32, i32* %14
%28 = icmp ugt i32 %27, 255
br i1 %28, label %44, label %29
29: ; preds = %26
%30 = shl nuw nsw i32 %18, 16
%31 = shl nuw nsw i32 %21, 8
%32 = or i32 %30, %31
%33 = or i32 %24, %32
%34 = shl i32 %33, 8
%35 = or i32 %27, %34
%36 = load i32, i32* %3
%37 = icmp eq i32 %36, 0
%38 = icmp ne i32 %35, 0
%39 = select i1 %37, i1 %38, i1 false
%40 = icmp ugt i32 %36, 32
%41 = or i1 %40, %39
%42 = xor i1 %41, true
%43 = zext i1 %42 to i32
br label %44
44: ; preds = %17, %20, %23, %26, %29, %10, %5
%45 = phi i32 [ 0, %5 ], [ 0, %10 ], [ %43, %29 ], [ 0, %26 ], [ 0, %23 ], [ 0, %20 ], [ 0, %17 ]
br label %46
46: ; preds = %1, %44
%47 = phi i32 [ %45, %44 ], [ 0, %1 ]
ret i32 %47
}