#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 in6_addr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ LOG_ERR;
scalar_t__ inet_pton(int /*<<< orphan*/, char *, struct in6_addr *);
char *strtok_r(char *, char *, char **);
unsigned int strtol(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ sys_err(int /*<<< orphan*/, char *, int, int /*<<< orphan*/,
                           char *);
int ippool_aton6(struct in6_addr *prefix, int *prefixlen, int *mask,
                 char *pool) {
  char *addr = NULL;
  char *ptr = NULL;
  unsigned int m = 0;
  addr = strtok_r(pool, "/", &ptr);
  m = strtol(ptr, NULL, 10);
  if (addr == NULL || ptr == NULL) {
    sys_err(LOG_ERR,
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/borellyc/cb-pepperspot/refs/heads/"
            "master/src/ippool.c",
            562, 0, "Invalid format for prefix");
    return -1;
  }
  if (inet_pton(AF_INET6, addr, prefix) < 0) {
    sys_err(LOG_ERR,
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/borellyc/cb-pepperspot/refs/heads/"
            "master/src/ippool.c",
            567, 0, "Invalid IPv6 prefix");
    return -1;
  }
  *prefixlen = m / 8;
  *mask = m;
  return 0;
}


x86 assembly (clang, -O0):
<ippool_aton6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe86(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1030 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x3c(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11b2 <ippool_aton6+0x72>
cmpq   $0x0,-0x38(%rbp)
jne    11e1 <ippool_aton6+0xa1>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
mov    $0x232,%edx
xor    %ecx,%ecx
lea    0xec2(%rip),%r8
call   1060 <sys_err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124c <ippool_aton6+0x10c>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <inet_pton@plt>
cmp    $0x0,%rax
jge    1230 <ippool_aton6+0xf0>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
mov    $0x237,%edx
xor    %ecx,%ecx
lea    0xe8d(%rip),%r8
call   1060 <sys_err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124c <ippool_aton6+0x10c>
mov    -0x3c(%rbp),%ecx
shr    $0x3,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x3c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ippool_aton6>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
movq   $0x0,0x8(%rsp)
lea    0xe9b(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rcx,%rdi
call   1030 <strtok_r@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
test   %rbx,%rbx
je     11bd <ippool_aton6+0x7d>
cmpq   $0x0,0x8(%rsp)
je     11bd <ippool_aton6+0x7d>
mov    %eax,%ebp
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1050 <inet_pton@plt>
test   %rax,%rax
js     11db <ippool_aton6+0x9b>
mov    %ebp,%eax
shr    $0x3,%eax
mov    %eax,(%r15)
mov    %ebp,(%r14)
xor    %eax,%eax
jmp    1203 <ippool_aton6+0xc3>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
lea    0xebe(%rip),%r8
mov    $0x232,%edx
jmp    11f7 <ippool_aton6+0xb7>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
lea    0xeba(%rip),%r8
mov    $0x237,%edx
xor    %ecx,%ecx
call   1060 <sys_err@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in6_addr = type { i32 }
@.str = [2 x i8] c"/\00"
@LOG_ERR = global i32 0
@.str.1 = [144 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/borellyc/cb-pepperspot/refs/heads/master/src/ippool.c\00"
@.str.2 = [26 x i8] c"Invalid format for prefix\00"
@AF_INET6 = global i32 0
@.str.3 = [20 x i8] c"Invalid IPv6 prefix\00"
define i32 @ippool_aton6(%struct.in6_addr* %0, i32* %1, i32* %2, i8* %3) {
%5 = alloca i32
%6 = alloca %struct.in6_addr*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store %struct.in6_addr* %0, %struct.in6_addr** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i8* %3, i8** %9
store i8* null, i8** %10
store i8* null, i8** %11
store i32 0, i32* %12
%13 = load i8*, i8** %9
%14 = call i8* @strtok_r(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %11)
store i8* %14, i8** %10
%15 = load i8*, i8** %11
%16 = call i32 @strtol(i8* %15, i32* null, i32 10)
store i32 %16, i32* %12
%17 = load i8*, i8** %10
%18 = icmp eq i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %4
%20 = load i8*, i8** %11
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19, %4
%23 = load i32, i32* @LOG_ERR
%24 = call i32 @sys_err(i32 %23, i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.1, i64 0, i64 0), i32 562, i32 0, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %5
br label %40
25: ; preds = %19
%26 = load i32, i32* @AF_INET6
%27 = load i8*, i8** %10
%28 = load %struct.in6_addr*, %struct.in6_addr** %6
%29 = call i64 @inet_pton(i32 %26, i8* %27, %struct.in6_addr* %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = load i32, i32* @LOG_ERR
%33 = call i32 @sys_err(i32 %32, i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.1, i64 0, i64 0), i32 567, i32 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %5
br label %40
34: ; preds = %25
%35 = load i32, i32* %12
%36 = udiv i32 %35, 8
%37 = load i32*, i32** %7
store i32 %36, i32* %37
%38 = load i32, i32* %12
%39 = load i32*, i32** %8
store i32 %38, i32* %39
store i32 0, i32* %5
br label %40
40: ; preds = %34, %31, %22
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
%struct.in6_addr = type { i32 }
@.str = [2 x i8] c"/\00"
@LOG_ERR = global i32 0
@.str.1 = [144 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/borellyc/cb-pepperspot/refs/heads/master/src/ippool.c\00"
@.str.2 = [26 x i8] c"Invalid format for prefix\00"
@AF_INET6 = global i32 0
@.str.3 = [20 x i8] c"Invalid IPv6 prefix\00"
define i32 @ippool_aton6(%struct.in6_addr* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i8* %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%7 = call i8* @strtok_r(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %5)
%8 = load i8*, i8** %5
%9 = call i32 @strtol(i8* nocapture %8, i32* null, i32 10)
%10 = icmp eq i8* %7, null
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = load i32, i32* @LOG_ERR
%16 = call i32 @sys_err(i32 %15, i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.1, i64 0, i64 0), i32 562, i32 0, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %26
17: ; preds = %4
%18 = load i32, i32* @AF_INET6
%19 = call i64 @inet_pton(i32 %18, i8* %7, %struct.in6_addr* %0)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* @LOG_ERR
%23 = call i32 @sys_err(i32 %22, i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.1, i64 0, i64 0), i32 567, i32 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %26
24: ; preds = %17
%25 = lshr i32 %9, 3
store i32 %25, i32* %1
store i32 %9, i32* %2
br label %26
26: ; preds = %24, %21, %14
%27 = phi i32 [ -1, %14 ], [ -1, %21 ], [ 0, %24 ]
ret i32 %27
}