#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*/ temp;

/* Variables and functions */
unsigned int atoi(char *);
int /*<<< orphan*/ free(unsigned int *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strstr(char const *, char *);
unsigned int *to_ipv4(char *);
unsigned int *to_ipv4_cidr(const char *range, unsigned int *cidr_range) {
  char temp[0xff];
  char *tp = NULL;
  unsigned int *ip = NULL;
  unsigned int mask = 0xffffffff;
  memset(temp, 0, sizeof(temp));
  strncpy(temp, range, sizeof(temp) - 1);
  tp = strstr(temp, "/");
  if (tp == NULL) {
    return NULL;
  }
  *tp = 0;
  ip = to_ipv4(temp);
  if (ip == NULL) {
    return NULL;
  }
  tp = strstr(range, "/");
  if (tp == NULL) {
    free(ip);
    return NULL;
  }
  strncpy(temp, tp + 1, sizeof(temp) - 1);
  if (cidr_range != NULL) {
    *cidr_range = atoi(temp);
  }
  mask = mask >> atoi(temp);
  *ip = (*ip | mask);
  return ip;
}


x86 assembly (clang, -O0):
<to_ipv4_cidr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x128(%rbp)
movq   $0x0,-0x130(%rbp)
movl   $0xffffffff,-0x134(%rbp)
ff ff ff
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1060 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xfe,%edx
call   1040 <strncpy@plt>
lea    -0x120(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    11f0 <to_ipv4_cidr+0x90>
movq   $0x0,-0x8(%rbp)
jmp    12ec <to_ipv4_cidr+0x18c>
mov    -0x128(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x120(%rbp),%rdi
call   1050 <to_ipv4@plt>
mov    %rax,-0x130(%rbp)
cmpq   $0x0,-0x130(%rbp)
jne    1228 <to_ipv4_cidr+0xc8>
movq   $0x0,-0x8(%rbp)
jmp    12ec <to_ipv4_cidr+0x18c>
mov    -0x10(%rbp),%rdi
lea    0xdcd(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    1266 <to_ipv4_cidr+0x106>
mov    -0x130(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12ec <to_ipv4_cidr+0x18c>
lea    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rsi
add    $0x1,%rsi
mov    $0xfe,%edx
call   1040 <strncpy@plt>
cmpq   $0x0,-0x18(%rbp)
je     12a1 <to_ipv4_cidr+0x141>
lea    -0x120(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x134(%rbp),%eax
mov    %eax,-0x138(%rbp)
lea    -0x120(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x138(%rbp),%eax
shr    %cl,%eax
mov    %eax,-0x134(%rbp)
mov    -0x130(%rbp),%rax
mov    (%rax),%ecx
or     -0x134(%rbp),%ecx
mov    -0x130(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x130(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_ipv4_cidr>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsp,%rbx
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1070 <memset@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0xfe,%edx
call   1040 <strncpy@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1215 <to_ipv4_cidr+0xb5>
movb   $0x0,(%rax)
mov    %rsp,%rdi
call   1050 <to_ipv4@plt>
test   %rax,%rax
je     1212 <to_ipv4_cidr+0xb2>
mov    %rax,%r15
mov    %r12,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     120a <to_ipv4_cidr+0xaa>
add    $0x1,%rax
mov    %rsp,%rdi
mov    %rax,%rsi
mov    $0xfe,%edx
call   1040 <strncpy@plt>
test   %r14,%r14
je     11f4 <to_ipv4_cidr+0x94>
mov    %rsp,%rdi
call   1080 <atoi@plt>
mov    %eax,(%r14)
mov    %rsp,%rdi
call   1080 <atoi@plt>
mov    $0xffffffff,%edx
mov    %eax,%ecx
shr    %cl,%edx
or     %edx,(%r15)
jmp    1215 <to_ipv4_cidr+0xb5>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32* @to_ipv4_cidr(i8* %0, i32* writeonly %1) {
%3 = alloca [255 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 255)
%6 = call i32 @strncpy(i8* %4, i8* %0, i32 254)
%7 = call i8* @strchr(i8* %4, i32 47)
%8 = icmp eq i8* %7, null
br i1 %8, label %28, label %9
9: ; preds = %2
store i8 0, i8* %7
%10 = call i32* @to_ipv4(i8* %4)
%11 = icmp eq i32* %10, null
br i1 %11, label %28, label %12
12: ; preds = %9
%13 = call i8* @strchr(i8* dereferenceable(1) %0, i32 47)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @free(i32* %10)
br label %28
17: ; preds = %12
%18 = getelementptr inbounds i8, i8* %13, i64 1
%19 = call i32 @strncpy(i8* %4, i8* %18, i32 254)
%20 = icmp eq i32* %1, null
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = call i32 @atoi(i8* %4)
store i32 %22, i32* %1
br label %23
23: ; preds = %21, %17
%24 = call i32 @atoi(i8* %4)
%25 = lshr i32 -1, %24
%26 = load i32, i32* %10
%27 = or i32 %26, %25
store i32 %27, i32* %10
br label %28
28: ; preds = %9, %2, %23, %15
%29 = phi i32* [ null, %15 ], [ %10, %23 ], [ null, %2 ], [ null, %9 ]
ret i32* %29
}