#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 */
struct sip_in6_addr {
  int dummy;
};

/* Variables and functions */
int atoi(char *);
int strlen(char *);
int /*<<< orphan*/ v6masktonum(char *, int *, struct sip_in6_addr *);
int getsplitnumv6(char *buf, struct sip_in6_addr *splitmask, int *v6splitnum) {
  int i;
  if (strlen(buf) < 1)
    return -1;
  if (strlen(buf) > 4)
    return -1;
  if (buf[0] == '/')
    buf++;
  i = atoi(buf);
  if (i < 1 || i > 128)
    return -1;
  *v6splitnum = i;
  v6masktonum(buf, &i, splitmask);
  return 0;
}


x86 assembly (clang, -O0):
<getsplitnumv6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jge    1162 <getsplitnumv6+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <getsplitnumv6+0xbc>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
jle    1180 <getsplitnumv6+0x50>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <getsplitnumv6+0xbc>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    119c <getsplitnumv6+0x6c>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jl     11bf <getsplitnumv6+0x8f>
cmpl   $0x80,-0x24(%rbp)
jle    11cb <getsplitnumv6+0x9b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <getsplitnumv6+0xbc>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    -0x24(%rbp),%rsi
call   1030 <v6masktonum@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getsplitnumv6>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbp
call   1040 <strlen@plt>
mov    $0xffffffff,%r12d
test   %eax,%eax
jle    119a <getsplitnumv6+0x6a>
mov    %rbp,%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
jg     119a <getsplitnumv6+0x6a>
xor    %ebx,%ebx
cmpb   $0x2f,0x0(%rbp)
sete   %bl
add    %rbp,%rbx
mov    %rbx,%rdi
call   1050 <atoi@plt>
mov    %eax,0xc(%rsp)
lea    -0x81(%rax),%ecx
cmp    $0xffffff80,%ecx
jb     119a <getsplitnumv6+0x6a>
mov    %eax,(%r15)
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <v6masktonum@plt>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sip_in6_addr = type { i32 }
define i32 @getsplitnumv6(i8* %0, %struct.sip_in6_addr* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.sip_in6_addr*
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %5
store %struct.sip_in6_addr* %1, %struct.sip_in6_addr** %6
store i32* %2, i32** %7
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
%11 = icmp slt i32 %10, 1
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %42
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = call i32 @strlen(i8* %14)
%16 = icmp sgt i32 %15, 4
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 -1, i32* %4
br label %42
18: ; preds = %13
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 47
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %5
br label %27
27: ; preds = %24, %18
%28 = load i8*, i8** %5
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp slt i32 %30, 1
br i1 %31, label %35, label %32
32: ; preds = %27
%33 = load i32, i32* %8
%34 = icmp sgt i32 %33, 128
br i1 %34, label %35, label %36
35: ; preds = %32, %27
store i32 -1, i32* %4
br label %42
36: ; preds = %32
%37 = load i32, i32* %8
%38 = load i32*, i32** %7
store i32 %37, i32* %38
%39 = load i8*, i8** %5
%40 = load %struct.sip_in6_addr*, %struct.sip_in6_addr** %6
%41 = call i32 @v6masktonum(i8* %39, i32* %8, %struct.sip_in6_addr* %40)
store i32 0, i32* %4
br label %42
42: ; preds = %36, %35, %17, %12
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
%struct.sip_in6_addr = type { i32 }
define i32 @getsplitnumv6(i8* %0, %struct.sip_in6_addr* %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp slt i32 %6, 1
br i1 %7, label %21, label %8
8: ; preds = %3
%9 = tail call i32 @strlen(i8* %0)
%10 = icmp sgt i32 %9, 4
br i1 %10, label %21, label %11
11: ; preds = %8
%12 = load i8, i8* %0
%13 = icmp eq i8 %12, 47
%14 = zext i1 %13 to i64
%15 = getelementptr i8, i8* %0, i64 %14
%16 = tail call i32 @atoi(i8* %15)
store i32 %16, i32* %4
%17 = add i32 %16, -129
%18 = icmp ult i32 %17, -128
br i1 %18, label %21, label %19
19: ; preds = %11
store i32 %16, i32* %2
%20 = call i32 @v6masktonum(i8* %15, i32* %4, %struct.sip_in6_addr* %1)
br label %21
21: ; preds = %11, %8, %3, %19
%22 = phi i32 [ 0, %19 ], [ -1, %3 ], [ -1, %8 ], [ -1, %11 ]
ret i32 %22
}