#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*/ memset(char *, int /*<<< orphan*/, int);
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char *, int);
unsigned int strtoul(char *, char **, int);
void cidr_split_address(char *cidr_addr, char *addresspart,
                        unsigned int *maskbits) {
  char maskpart[4];
  char *endptr;
  char *slashptr;
  char address_buffer[80];
  if (strchr(cidr_addr, '/') == NULL) {
    strncpy(addresspart, cidr_addr, 80);
    *maskbits = 255;
    return;
  }
  memset(address_buffer, 0, 80);
  memset(addresspart, 0, 80);
  memset(maskpart, 0, 4);
  strncpy(address_buffer, cidr_addr, 80);
  slashptr = strchr(address_buffer, '/');
  *slashptr = '\0';
  slashptr++;
  strncpy(addresspart, address_buffer, 80);
  strncpy(maskpart, slashptr, 4);
  if (maskpart[0] != '\0') {
    *maskbits = strtoul(maskpart, &endptr, 10);
    if (*endptr != '\0')
      *maskbits = 255;
  } else
    *maskbits = 255;
  return;
}


x86 assembly (clang, -O0):
<cidr_split_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    1190 <cidr_split_address+0x50>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movl   $0xff,(%rax)
jmp    1270 <cidr_split_address+0x130>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
lea    -0x1c(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
lea    -0x80(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
lea    -0x1c(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movsbl -0x1c(%rbp),%eax
cmp    $0x0,%eax
je     1261 <cidr_split_address+0x121>
lea    -0x1c(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     125c <cidr_split_address+0x11c>
mov    -0x18(%rbp),%rax
movl   $0xff,(%rax)
jmp    126b <cidr_split_address+0x12b>
mov    -0x18(%rbp),%rax
movl   $0xff,(%rax)
jmp    1270 <cidr_split_address+0x130>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cidr_split_address>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x60,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1214 <cidr_split_address+0xd4>
lea    0x10(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
lea    0x4(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
mov    %r12,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
lea    0x1(%rax),%rbx
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
cmpb   $0x0,0x4(%rsp)
je     1224 <cidr_split_address+0xe4>
lea    0x4(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %eax,(%r14)
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
mov    $0xff,%ecx
cmove  %eax,%ecx
jmp    1229 <cidr_split_address+0xe9>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
mov    $0xff,%ecx
mov    %ecx,(%r14)
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @cidr_split_address(i8* %0, i8* %1, i32* nocapture writeonly %2) {
%4 = alloca [4 x i8]
%5 = alloca i8*
%6 = alloca [80 x i8]
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%8 = bitcast i8** %5 to i8*
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%10 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = tail call i32 @strncpy(i8* %1, i8* %0, i32 80)
br label %31
14: ; preds = %3
%15 = call i32 @memset(i8* %9, i32 0, i32 80)
%16 = call i32 @memset(i8* %1, i32 0, i32 80)
%17 = call i32 @memset(i8* %7, i32 0, i32 4)
%18 = call i32 @strncpy(i8* %9, i8* %0, i32 80)
%19 = call i8* @strchr(i8* %9, i8 signext 47)
store i8 0, i8* %19
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = call i32 @strncpy(i8* %1, i8* %9, i32 80)
%22 = call i32 @strncpy(i8* %7, i8* %20, i32 4)
%23 = load i8, i8* %7
%24 = icmp eq i8 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %14
%26 = call i32 @strtoul(i8* %7, i8** %5, i32 10)
store i32 %26, i32* %2
%27 = load i8*, i8** %5
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 0
%30 = select i1 %29, i32 %26, i32 255
br label %31
31: ; preds = %14, %25, %12
%32 = phi i32 [ %30, %25 ], [ 255, %12 ], [ 255, %14 ]
store i32 %32, i32* %2
ret void
}