#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 scalar_t__ u_int32_t;

/* Variables and functions */
int /*<<< orphan*/ addtoaml(scalar_t__, scalar_t__);
scalar_t__ aspectou32(char *, int);
scalar_t__ mspectou32(char *);
int /*<<< orphan*/ rangetoaml(scalar_t__, scalar_t__);
char *strchr(char *, char);
int spectoaml(char *addrspec, int dns) {
  char *sep;
  u_int32_t addr;
  if ((sep = strchr(addrspec, ':')) != NULL) {
    u_int32_t addr2;
    *sep++ = '\0';
    addr = aspectou32(addrspec, dns);
    if (*sep == '+') {
      sep++;
      addr2 = addr;
    } else
      addr2 = 0;
    addr2 += aspectou32(sep, dns);
    rangetoaml(addr, addr2);
  } else if ((sep = strchr(addrspec, '/')) != NULL) {
    u_int32_t mask;
    *sep++ = '\0';
    addr = aspectou32(addrspec, dns);
    mask = mspectou32(sep);
    addtoaml(addr, mask);
  } else {
    addr = aspectou32(addrspec, dns);
    addtoaml(addr, ~0);
  }
  return (0);
}


x86 assembly (clang, -O0):
<spectoaml>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11f4 <spectoaml+0xa4>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <aspectou32@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    11c6 <spectoaml+0x76>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11ce <spectoaml+0x7e>
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <aspectou32@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <rangetoaml@plt>
jmp    1276 <spectoaml+0x126>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1251 <spectoaml+0x101>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <aspectou32@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <mspectou32@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <addtoaml@plt>
jmp    1271 <spectoaml+0x121>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <aspectou32@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0xffffffffffffffff,%rsi
call   1030 <addtoaml@plt>
jmp    1276 <spectoaml+0x126>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spectoaml>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11b2 <spectoaml+0x62>
mov    %rax,%rbp
lea    0x1(%rax),%r12
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <aspectou32@plt>
mov    %rax,%r15
mov    %rbp,%rdi
add    $0x2,%rdi
xor    %ebx,%ebx
cmpb   $0x2b,0x1(%rbp)
cmove  %rax,%rbx
cmovne %r12,%rdi
mov    %r14d,%esi
call   1050 <aspectou32@plt>
add    %rax,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <rangetoaml@plt>
jmp    1206 <spectoaml+0xb6>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11ec <spectoaml+0x9c>
mov    %rax,%rbp
add    $0x1,%rbp
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <aspectou32@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1070 <mspectou32@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
jmp    1201 <spectoaml+0xb1>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <aspectou32@plt>
mov    %rax,%rdi
mov    $0xffffffffffffffff,%rsi
call   1030 <addtoaml@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @spectoaml(i8* %0, i32 %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%4 = icmp eq i8* %3, null
br i1 %4, label %16, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 1
store i8 0, i8* %3
%7 = tail call i64 @aspectou32(i8* %0, i32 %1)
%8 = load i8, i8* %6
%9 = icmp eq i8 %8, 43
%10 = getelementptr inbounds i8, i8* %3, i64 2
%11 = select i1 %9, i64 %7, i64 0
%12 = select i1 %9, i8* %10, i8* %6
%13 = tail call i64 @aspectou32(i8* %12, i32 %1)
%14 = add nsw i64 %11, %13
%15 = tail call i32 @rangetoaml(i64 %7, i64 %14)
br label %27
16: ; preds = %2
%17 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%18 = icmp eq i8* %17, null
br i1 %18, label %24, label %19
19: ; preds = %16
%20 = getelementptr inbounds i8, i8* %17, i64 1
store i8 0, i8* %17
%21 = tail call i64 @aspectou32(i8* %0, i32 %1)
%22 = tail call i64 @mspectou32(i8* %20)
%23 = tail call i32 @addtoaml(i64 %21, i64 %22)
br label %27
24: ; preds = %16
%25 = tail call i64 @aspectou32(i8* %0, i32 %1)
%26 = tail call i32 @addtoaml(i64 %25, i64 -1)
br label %27
27: ; preds = %19, %24, %5
ret i32 0
}