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

/* Variables and functions */
int /*<<< orphan*/ atoh(char *);
int atoi(char *);
int /*<<< orphan*/ netmask(int);
char *strchr(char *, char);
void parsecidr(in_addr_t *addr, in_addr_t *mask, char *str) {
  char *p;
  int prefix;
  prefix = 32;
  p = strchr(str, '/');
  if (p != NULL) {
    *p = '\0';
    prefix = atoi(p + 1);
    if (prefix < 0)
      prefix = 0;
    if (prefix > 32)
      prefix = 32;
  }
  *addr = atoh(str);
  *mask = netmask(prefix);
}


x86 assembly (clang, -O0):
<parsecidr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x20,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b6 <parsecidr+0x76>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1060 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11a0 <parsecidr+0x60>
movl   $0x0,-0x24(%rbp)
cmpl   $0x20,-0x24(%rbp)
jle    11b1 <parsecidr+0x71>
movl   $0x20,-0x24(%rbp)
jmp    11b6 <parsecidr+0x76>
mov    -0x18(%rbp),%rdi
call   1030 <atoh@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x24(%rbp),%edi
call   1040 <netmask@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsecidr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1185 <parsecidr+0x45>
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,%rdi
call   1060 <atoi@plt>
xor    %ecx,%ecx
test   %eax,%eax
cmovns %eax,%ecx
cmp    $0x20,%ecx
mov    $0x20,%ebp
cmovb  %ecx,%ebp
jmp    118a <parsecidr+0x4a>
mov    $0x20,%ebp
mov    %rbx,%rdi
call   1030 <atoh@plt>
mov    %eax,(%r15)
mov    %ebp,%edi
call   1040 <netmask@plt>
mov    %eax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @parsecidr(i32* %0, i32* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
store i32 32, i32* %8
%9 = load i8*, i8** %6
%10 = call i8* @strchr(i8* %9, i8 signext 47)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %26
13: ; preds = %3
%14 = load i8*, i8** %7
store i8 0, i8* %14
%15 = load i8*, i8** %7
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %13
store i32 0, i32* %8
br label %21
21: ; preds = %20, %13
%22 = load i32, i32* %8
%23 = icmp sgt i32 %22, 32
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 32, i32* %8
br label %25
25: ; preds = %24, %21
br label %26
26: ; preds = %25, %3
%27 = load i8*, i8** %6
%28 = call i32 @atoh(i8* %27)
%29 = load i32*, i32** %4
store i32 %28, i32* %29
%30 = load i32, i32* %8
%31 = call i32 @netmask(i32 %30)
%32 = load i32*, i32** %5
store i32 %31, i32* %32
ret void
}

LLVM IR (-O2):
define void @parsecidr(i32* nocapture writeonly %0, i32* nocapture writeonly %1, i8* %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %2, i8 signext 47)
%5 = icmp eq i8* %4, null
br i1 %5, label %13, label %6
6: ; preds = %3
store i8 0, i8* %4
%7 = getelementptr inbounds i8, i8* %4, i64 1
%8 = tail call i32 @atoi(i8* %7)
%9 = icmp sgt i32 %8, 0
%10 = select i1 %9, i32 %8, i32 0
%11 = icmp ult i32 %10, 32
%12 = select i1 %11, i32 %10, i32 32
br label %13
13: ; preds = %6, %3
%14 = phi i32 [ %12, %6 ], [ 32, %3 ]
%15 = tail call i32 @atoh(i8* %2)
store i32 %15, i32* %0
%16 = tail call i32 @netmask(i32 %14)
store i32 %16, i32* %1
ret void
}