#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 AF_INET;
int AF_INET6;
int inet_pton(int, char *, void *);
int /*<<< orphan*/ print_error();
int /*<<< orphan*/ print_usage();
char *strchr(char *, char);
unsigned long strtoul(char *, int /*<<< orphan*/ *, int);
void parse_str(int af, char *str, void *addr, unsigned long *mask) {
  int ret;
  char *slash;
  if ((slash = strchr(str, '/')) == NULL)
    print_usage();
  *slash = '\0';
  if ((ret = inet_pton(af, str, addr)) != 1) {
    if (ret == 0)
      print_usage();
    else
      print_error();
  }
  *mask = strtoul(slash + 1, NULL, 10);
  if ((af == AF_INET && *mask > 32) || (af == AF_INET6 && *mask > 128))
    print_usage();
}


x86 assembly (clang, -O0):
<parse_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    118a <parse_str+0x3a>
mov    $0x0,%al
call   1070 <print_usage@plt>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <inet_pton@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x1,%eax
je     11cf <parse_str+0x7f>
cmpl   $0x0,-0x24(%rbp)
jne    11c3 <parse_str+0x73>
mov    $0x0,%al
call   1070 <print_usage@plt>
jmp    11ca <parse_str+0x7a>
mov    $0x0,%al
call   1030 <print_error@plt>
jmp    11cf <parse_str+0x7f>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x4(%rbp),%eax
mov    0x2def(%rip),%rcx
cmp    (%rcx),%eax
jne    120f <parse_str+0xbf>
mov    -0x20(%rbp),%rax
cmpq   $0x20,(%rax)
ja     1232 <parse_str+0xe2>
mov    -0x4(%rbp),%eax
mov    0x2dc7(%rip),%rcx
cmp    (%rcx),%eax
jne    1239 <parse_str+0xe9>
mov    -0x20(%rbp),%rax
cmpq   $0x80,(%rax)
jbe    1239 <parse_str+0xe9>
mov    $0x0,%al
call   1070 <print_usage@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_str>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%rbp
mov    %edi,%r15d
mov    %rsi,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1180 <parse_str+0x30>
xor    %eax,%eax
call   1070 <print_usage@plt>
movb   $0x0,(%rbx)
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1050 <inet_pton@plt>
cmp    $0x1,%eax
je     11aa <parse_str+0x5a>
test   %eax,%eax
jne    11a3 <parse_str+0x53>
xor    %eax,%eax
call   1070 <print_usage@plt>
jmp    11aa <parse_str+0x5a>
xor    %eax,%eax
call   1030 <print_error@plt>
add    $0x1,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %rax,(%r14)
mov    0x2e21(%rip),%rcx
cmp    %r15d,(%rcx)
jne    11d2 <parse_str+0x82>
cmp    $0x20,%rax
ja     11e6 <parse_str+0x96>
mov    0x2e07(%rip),%rcx
cmp    %r15d,(%rcx)
jne    11f5 <parse_str+0xa5>
cmp    $0x81,%rax
jb     11f5 <parse_str+0xa5>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <print_usage@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@AF_INET = global i32 0
@AF_INET6 = global i32 0
define void @parse_str(i32 %0, i8* %1, i8* %2, i64* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64*
%9 = alloca i32
%10 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i64* %3, i64** %8
%11 = load i8*, i8** %6
%12 = call i8* @strchr(i8* %11, i8 signext 47)
store i8* %12, i8** %10
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = call i32 (...) @print_usage()
br label %16
16: ; preds = %14, %4
%17 = load i8*, i8** %10
store i8 0, i8* %17
%18 = load i32, i32* %5
%19 = load i8*, i8** %6
%20 = load i8*, i8** %7
%21 = call i32 @inet_pton(i32 %18, i8* %19, i8* %20)
store i32 %21, i32* %9
%22 = icmp ne i32 %21, 1
br i1 %22, label %23, label %31
23: ; preds = %16
%24 = load i32, i32* %9
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 (...) @print_usage()
br label %30
28: ; preds = %23
%29 = call i32 (...) @print_error()
br label %30
30: ; preds = %28, %26
br label %31
31: ; preds = %30, %16
%32 = load i8*, i8** %10
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = call i64 @strtoul(i8* %33, i32* null, i32 10)
%35 = load i64*, i64** %8
store i64 %34, i64* %35
%36 = load i32, i32* %5
%37 = load i32, i32* @AF_INET
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %43
39: ; preds = %31
%40 = load i64*, i64** %8
%41 = load i64, i64* %40
%42 = icmp ugt i64 %41, 32
br i1 %42, label %51, label %43
43: ; preds = %39, %31
%44 = load i32, i32* %5
%45 = load i32, i32* @AF_INET6
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %53
47: ; preds = %43
%48 = load i64*, i64** %8
%49 = load i64, i64* %48
%50 = icmp ugt i64 %49, 128
br i1 %50, label %51, label %53
51: ; preds = %47, %39
%52 = call i32 (...) @print_usage()
br label %53
53: ; preds = %51, %47, %43
ret void
}

LLVM IR (-O2):
@AF_INET = global i32 0
@AF_INET6 = global i32 0
define void @parse_str(i32 %0, i8* %1, i8* %2, i64* nocapture %3) {
%5 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 47)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 (...) @print_usage()
br label %9
9: ; preds = %7, %4
store i8 0, i8* %5
%10 = tail call i32 @inet_pton(i32 %0, i8* %1, i8* %2)
switch i32 %10, label %13 [
i32 1, label %15
i32 0, label %11
]
11: ; preds = %9
%12 = tail call i32 (...) @print_usage()
br label %15
13: ; preds = %9
%14 = tail call i32 (...) @print_error()
br label %15
15: ; preds = %9, %11, %13
%16 = getelementptr inbounds i8, i8* %5, i64 1
%17 = tail call i64 @strtoul(i8* nocapture %16, i32* null, i32 10)
store i64 %17, i64* %3
%18 = load i32, i32* @AF_INET
%19 = icmp eq i32 %18, %0
%20 = icmp ugt i64 %17, 32
%21 = select i1 %19, i1 %20, i1 false
br i1 %21, label %27, label %22
22: ; preds = %15
%23 = load i32, i32* @AF_INET6
%24 = icmp eq i32 %23, %0
%25 = icmp ugt i64 %17, 128
%26 = select i1 %24, i1 %25, i1 false
br i1 %26, label %27, label %29
27: ; preds = %22, %15
%28 = tail call i32 (...) @print_usage()
br label %29
29: ; preds = %27, %22
ret void
}