#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 */
int /*<<< orphan*/ atoi(char *);
unsigned int ip_mkip(char *);
unsigned int ip_mkmask(int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, char *, unsigned int);
int ip_parsecidr(char *input, unsigned int *ip, unsigned int *mask) {
  char temp[16];
  unsigned int i;
  i = 0;
  while (*(input + i) && *(input + i) != '/')
    i++;
  if (i > sizeof(temp))
    return 1;
  strncpy(temp, input, i);
  temp[i] = '\0';
  *ip = ip_mkip(temp);
  *mask = ip_mkmask(atoi(input + i + 1));
  if (*mask == 0)
    *mask = 32;
  return 0;
}


x86 assembly (clang, -O0):
<ip_parsecidr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x35(%rbp)
je     1188 <ip_parsecidr+0x48>
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    1198 <ip_parsecidr+0x58>
jmp    11a6 <ip_parsecidr+0x66>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    115b <ip_parsecidr+0x1b>
mov    -0x34(%rbp),%eax
cmp    $0x10,%rax
jbe    11bf <ip_parsecidr+0x7f>
movl   $0x1,-0x4(%rbp)
jmp    1228 <ip_parsecidr+0xe8>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x34(%rbp),%eax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rdi
call   1040 <ip_mkip@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x34(%rbp),%eax
add    %rax,%rdi
add    $0x1,%rdi
call   1060 <atoi@plt>
mov    %eax,%edi
call   1050 <ip_mkmask@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1221 <ip_parsecidr+0xe1>
mov    -0x20(%rbp),%rax
movl   $0x20,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip_parsecidr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r13
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
mov    %edx,%ebx
movzbl 0x0(%r13,%rbx,1),%eax
test   %al,%al
je     1175 <ip_parsecidr+0x35>
cmp    $0x2f,%al
je     1175 <ip_parsecidr+0x35>
add    $0x1,%edx
jmp    1160 <ip_parsecidr+0x20>
mov    $0x1,%eax
cmp    $0x10,%edx
ja     11bf <ip_parsecidr+0x7f>
mov    %rsp,%r12
mov    %r12,%rdi
mov    %r13,%rsi
call   1030 <strncpy@plt>
movb   $0x0,(%rsp,%rbx,1)
mov    %r12,%rdi
call   1040 <ip_mkip@plt>
mov    %eax,(%r15)
lea    (%rbx,%r13,1),%rdi
add    $0x1,%rdi
call   1060 <atoi@plt>
mov    %eax,%edi
call   1050 <ip_mkmask@plt>
test   %eax,%eax
mov    $0x20,%ecx
cmovne %eax,%ecx
mov    %ecx,(%r14)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @ip_parsecidr(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
br label %6
6: ; preds = %11, %3
%7 = phi i32 [ 0, %3 ], [ %12, %11 ]
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
switch i8 %10, label %11 [
i8 0, label %13
i8 47, label %13
]
11: ; preds = %6
%12 = add i32 %7, 1
br label %6
13: ; preds = %6, %6
%14 = zext i32 %7 to i64
%15 = icmp ugt i32 %7, 16
br i1 %15, label %26, label %16
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %0, i64 %14
%18 = call i32 @strncpy(i8* %5, i8* %0, i32 %7)
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 %14
store i8 0, i8* %19
%20 = call i32 @ip_mkip(i8* %5)
store i32 %20, i32* %1
%21 = getelementptr inbounds i8, i8* %17, i64 1
%22 = call i32 @atoi(i8* %21)
%23 = call i32 @ip_mkmask(i32 %22)
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i32 32, i32 %23
store i32 %25, i32* %2
br label %26
26: ; preds = %13, %16
%27 = phi i32 [ 0, %16 ], [ 1, %13 ]
ret i32 %27
}