#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*/ bitch(char *, char *);
int inet_pton(int /*<<< orphan*/, char *, struct in6_addr *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ isspace(char);
char *skip_white_space(char *);
int extract_ipv6(char **input, char *what, struct in6_addr *addr) {
  char *s = *input;
  char c;
  while (isdigit(*s) || *s == ':' || *s == '.' || (*s >= 'a' && *s <= 'f') ||
         (*s >= 'A' && *s <= 'F')) {
    s++;
  }
  if (s == *input) {
    bitch("%s is not valid", what);
    return -1;
  }
  if (*s && !isspace(*s) && *s != ';' && *s != ')') {
    bitch("%s is not valid", what);
    return -1;
  }
  c = *s;
  *s = 0;
  if (inet_pton(AF_INET6, *input, addr) != 1) {
    *s = c;
    bitch("cannot parse %s", what);
    return -1;
  }
  *s = c;
  *input = skip_white_space(s);
  if (!*input) {
    return -1;
  }
  return 1;
}


x86 assembly (clang, -O0):
<extract_ipv6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x2a(%rbp)
jne    1207 <extract_ipv6+0xb7>
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x3a,%ecx
mov    %al,-0x2a(%rbp)
je     1207 <extract_ipv6+0xb7>
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x2e,%ecx
mov    %al,-0x2a(%rbp)
je     1207 <extract_ipv6+0xb7>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x61,%eax
jl     11dc <extract_ipv6+0x8c>
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x66,%ecx
mov    %al,-0x2a(%rbp)
jle    1207 <extract_ipv6+0xb7>
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x41,%ecx
mov    %al,-0x2b(%rbp)
jl     1201 <extract_ipv6+0xb1>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x46,%eax
setle  %al
mov    %al,-0x2b(%rbp)
mov    -0x2b(%rbp),%al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
test   $0x1,%al
jne    1217 <extract_ipv6+0xc7>
jmp    1228 <extract_ipv6+0xd8>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    116f <extract_ipv6+0x1f>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jne    1255 <extract_ipv6+0x105>
mov    -0x18(%rbp),%rsi
lea    0xdbc(%rip),%rdi
call   1040 <bitch@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    134a <extract_ipv6+0x1fa>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12b6 <extract_ipv6+0x166>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%eax
jne    12b6 <extract_ipv6+0x166>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
je     12b6 <extract_ipv6+0x166>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x29,%eax
je     12b6 <extract_ipv6+0x166>
mov    -0x18(%rbp),%rsi
lea    0xd5b(%rip),%rdi
call   1040 <bitch@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    134a <extract_ipv6+0x1fa>
mov    -0x28(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x29(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rdx
call   1070 <inet_pton@plt>
cmp    $0x1,%eax
je     130d <extract_ipv6+0x1bd>
mov    -0x29(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rsi
lea    0xd14(%rip),%rdi
call   1040 <bitch@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    134a <extract_ipv6+0x1fa>
mov    -0x29(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rdi
call   1060 <skip_white_space@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1343 <extract_ipv6+0x1f3>
movl   $0xffffffff,-0x4(%rbp)
jmp    134a <extract_ipv6+0x1fa>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_ipv6>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rbx
movabs $0x1f8000001f81001,%rbp
jmp    1174 <extract_ipv6+0x24>
add    $0x1,%rbx
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1170 <extract_ipv6+0x20>
movzbl (%rbx),%eax
lea    -0x2e(%rax),%ecx
cmp    $0x38,%cl
ja     1195 <extract_ipv6+0x45>
movzbl %cl,%ecx
bt     %rcx,%rbp
jb     1170 <extract_ipv6+0x20>
cmp    (%r15),%rbx
je     11b9 <extract_ipv6+0x69>
test   %al,%al
je     11c2 <extract_ipv6+0x72>
movsbl %al,%edi
call   1050 <isspace@plt>
mov    (%rbx),%bpl
test   %eax,%eax
jne    11c4 <extract_ipv6+0x74>
cmp    $0x29,%bpl
je     11c4 <extract_ipv6+0x74>
cmp    $0x3b,%bpl
je     11c4 <extract_ipv6+0x74>
lea    0xe40(%rip),%rdi
jmp    1200 <extract_ipv6+0xb0>
xor    %ebp,%ebp
movb   $0x0,(%rbx)
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rsi
mov    %r12,%rdx
call   1070 <inet_pton@plt>
mov    %bpl,(%rbx)
cmp    $0x1,%eax
jne    11f9 <extract_ipv6+0xa9>
mov    %rbx,%rdi
call   1060 <skip_white_space@plt>
mov    %rax,(%r15)
cmp    $0x1,%rax
sbb    %eax,%eax
or     $0x1,%eax
jmp    120d <extract_ipv6+0xbd>
lea    0xe10(%rip),%rdi
mov    %r14,%rsi
call   1040 <bitch@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in6_addr = type { i32 }
@.str = [16 x i8] c"%s is not valid\00"
@AF_INET6 = global i32 0
@.str.1 = [16 x i8] c"cannot parse %s\00"
define i32 @extract_ipv6(i8** %0, i8* %1, %struct.in6_addr* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca %struct.in6_addr*
%8 = alloca i8*
%9 = alloca i8
store i8** %0, i8*** %5
store i8* %1, i8** %6
store %struct.in6_addr* %2, %struct.in6_addr** %7
%10 = load i8**, i8*** %5
%11 = load i8*, i8** %10
store i8* %11, i8** %8
br label %12
12: ; preds = %51, %3
%13 = load i8*, i8** %8
%14 = load i8, i8* %13
%15 = call i64 @isdigit(i8 signext %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %49, label %17
17: ; preds = %12
%18 = load i8*, i8** %8
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 58
br i1 %21, label %49, label %22
22: ; preds = %17
%23 = load i8*, i8** %8
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 46
br i1 %26, label %49, label %27
27: ; preds = %22
%28 = load i8*, i8** %8
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp sge i32 %30, 97
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i8*, i8** %8
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp sle i32 %35, 102
br i1 %36, label %49, label %37
37: ; preds = %32, %27
%38 = load i8*, i8** %8
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp sge i32 %40, 65
br i1 %41, label %42, label %47
42: ; preds = %37
%43 = load i8*, i8** %8
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp sle i32 %45, 70
br label %47
47: ; preds = %42, %37
%48 = phi i1 [ false, %37 ], [ %46, %42 ]
br label %49
49: ; preds = %47, %32, %22, %17, %12
%50 = phi i1 [ true, %32 ], [ true, %22 ], [ true, %17 ], [ true, %12 ], [ %48, %47 ]
br i1 %50, label %51, label %54
51: ; preds = %49
%52 = load i8*, i8** %8
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %8
br label %12
54: ; preds = %49
%55 = load i8*, i8** %8
%56 = load i8**, i8*** %5
%57 = load i8*, i8** %56
%58 = icmp eq i8* %55, %57
br i1 %58, label %59, label %62
59: ; preds = %54
%60 = load i8*, i8** %6
%61 = call i32 @bitch(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %60)
store i32 -1, i32* %4
br label %111
62: ; preds = %54
%63 = load i8*, i8** %8
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %85
67: ; preds = %62
%68 = load i8*, i8** %8
%69 = load i8, i8* %68
%70 = call i32 @isspace(i8 signext %69)
%71 = icmp ne i32 %70, 0
br i1 %71, label %85, label %72
72: ; preds = %67
%73 = load i8*, i8** %8
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = icmp ne i32 %75, 59
br i1 %76, label %77, label %85
77: ; preds = %72
%78 = load i8*, i8** %8
%79 = load i8, i8* %78
%80 = sext i8 %79 to i32
%81 = icmp ne i32 %80, 41
br i1 %81, label %82, label %85
82: ; preds = %77
%83 = load i8*, i8** %6
%84 = call i32 @bitch(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %83)
store i32 -1, i32* %4
br label %111
85: ; preds = %77, %72, %67, %62
%86 = load i8*, i8** %8
%87 = load i8, i8* %86
store i8 %87, i8* %9
%88 = load i8*, i8** %8
store i8 0, i8* %88
%89 = load i32, i32* @AF_INET6
%90 = load i8**, i8*** %5
%91 = load i8*, i8** %90
%92 = load %struct.in6_addr*, %struct.in6_addr** %7
%93 = call i32 @inet_pton(i32 %89, i8* %91, %struct.in6_addr* %92)
%94 = icmp ne i32 %93, 1
br i1 %94, label %95, label %100
95: ; preds = %85
%96 = load i8, i8* %9
%97 = load i8*, i8** %8
store i8 %96, i8* %97
%98 = load i8*, i8** %6
%99 = call i32 @bitch(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %98)
store i32 -1, i32* %4
br label %111
100: ; preds = %85
%101 = load i8, i8* %9
%102 = load i8*, i8** %8
store i8 %101, i8* %102
%103 = load i8*, i8** %8
%104 = call i8* @skip_white_space(i8* %103)
%105 = load i8**, i8*** %5
store i8* %104, i8** %105
%106 = load i8**, i8*** %5
%107 = load i8*, i8** %106
%108 = icmp ne i8* %107, null
br i1 %108, label %110, label %109
109: ; preds = %100
store i32 -1, i32* %4
br label %111
110: ; preds = %100
store i32 1, i32* %4
br label %111
111: ; preds = %110, %109, %95, %82, %59
%112 = load i32, i32* %4
ret i32 %112
}

LLVM IR (-O2):
%struct.in6_addr = type { i32 }
@.str = [16 x i8] c"%s is not valid\00"
@AF_INET6 = global i32 0
@.str.1 = [16 x i8] c"cannot parse %s\00"
define i32 @extract_ipv6(i8** nocapture %0, i8* %1, %struct.in6_addr* %2) {
%4 = load i8*, i8** %0
br label %5
5: ; preds = %12, %3
%6 = phi i8* [ %4, %3 ], [ %13, %12 ]
%7 = load i8, i8* %6
%8 = tail call i64 @isdigit(i8 signext %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = load i8, i8* %6
switch i8 %11, label %14 [
i8 58, label %12
i8 46, label %12
i8 102, label %12
i8 101, label %12
i8 100, label %12
i8 99, label %12
i8 98, label %12
i8 97, label %12
i8 70, label %12
i8 69, label %12
i8 68, label %12
i8 67, label %12
i8 66, label %12
i8 65, label %12
]
12: ; preds = %10, %10, %10, %10, %10, %10, %10, %10, %10, %10, %10, %10, %10, %10, %5
%13 = getelementptr inbounds i8, i8* %6, i64 1
br label %5
14: ; preds = %10
%15 = load i8*, i8** %0
%16 = icmp eq i8* %6, %15
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @bitch(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %40
19: ; preds = %14
%20 = icmp eq i8 %11, 0
br i1 %20, label %28, label %21
21: ; preds = %19
%22 = tail call i32 @isspace(i8 signext %11)
%23 = icmp eq i32 %22, 0
%24 = load i8, i8* %6
br i1 %23, label %25, label %28
25: ; preds = %21
switch i8 %24, label %26 [
i8 59, label %28
i8 41, label %28
]
26: ; preds = %25
%27 = tail call i32 @bitch(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %40
28: ; preds = %21, %25, %25, %19
%29 = phi i8 [ %24, %25 ], [ %24, %25 ], [ 0, %19 ], [ %24, %21 ]
store i8 0, i8* %6
%30 = load i32, i32* @AF_INET6
%31 = load i8*, i8** %0
%32 = tail call i32 @inet_pton(i32 %30, i8* %31, %struct.in6_addr* %2)
%33 = icmp eq i32 %32, 1
store i8 %29, i8* %6
br i1 %33, label %36, label %34
34: ; preds = %28
%35 = tail call i32 @bitch(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %40
36: ; preds = %28
%37 = tail call i8* @skip_white_space(i8* %6)
store i8* %37, i8** %0
%38 = icmp eq i8* %37, null
%39 = select i1 %38, i32 -1, i32 1
br label %40
40: ; preds = %36, %34, %26, %17
%41 = phi i32 [ -1, %17 ], [ -1, %34 ], [ -1, %26 ], [ %39, %36 ]
ret i32 %41
}