#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 v6masktonum(char *, int *, struct sip_in6_addr *);
int getsplitnumv6(char *buf, struct sip_in6_addr *splitmask, int *v6splitnum) {
  int x, y;
  if (strlen(buf) < 1)
    return -1;
  if (strlen(buf) > 4)
    return -1;
  if (buf[0] == '/')
    buf++;
  y = atoi(buf);
  if (y < 1 || y > 128)
    return -1;
  *v6splitnum = y;
  x = v6masktonum(buf, &y, 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    11ef <getsplitnumv6+0xbf>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
jle    1180 <getsplitnumv6+0x50>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ef <getsplitnumv6+0xbf>
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,-0x28(%rbp)
cmpl   $0x1,-0x28(%rbp)
jl     11bf <getsplitnumv6+0x8f>
cmpl   $0x80,-0x28(%rbp)
jle    11cb <getsplitnumv6+0x9b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ef <getsplitnumv6+0xbf>
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    -0x28(%rbp),%rsi
call   1030 <v6masktonum@plt>
mov    %eax,-0x24(%rbp)
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
%9 = alloca i32
store i8* %0, i8** %5
store %struct.sip_in6_addr* %1, %struct.sip_in6_addr** %6
store i32* %2, i32** %7
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %43
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
%17 = icmp sgt i32 %16, 4
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 -1, i32* %4
br label %43
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 47
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %5
br label %28
28: ; preds = %25, %19
%29 = load i8*, i8** %5
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %9
%31 = load i32, i32* %9
%32 = icmp slt i32 %31, 1
br i1 %32, label %36, label %33
33: ; preds = %28
%34 = load i32, i32* %9
%35 = icmp sgt i32 %34, 128
br i1 %35, label %36, label %37
36: ; preds = %33, %28
store i32 -1, i32* %4
br label %43
37: ; preds = %33
%38 = load i32, i32* %9
%39 = load i32*, i32** %7
store i32 %38, i32* %39
%40 = load i8*, i8** %5
%41 = load %struct.sip_in6_addr*, %struct.sip_in6_addr** %6
%42 = call i32 @v6masktonum(i8* %40, i32* %9, %struct.sip_in6_addr* %41)
store i32 %42, i32* %8
store i32 0, i32* %4
br label %43
43: ; preds = %37, %36, %18, %13
%44 = load i32, i32* %4
ret i32 %44
}

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
}