#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 int ssize_t;

/* Variables and functions */
ssize_t parse_ipv6addr(const char *buffer, const char **error) {
  char const *p;
  for (p = buffer; *p; p++) {
    if (*p == ':')
      continue;
    if ((*p >= '0') && (*p <= '9'))
      continue;
    if ((*p >= 'a') && (*p <= 'f'))
      continue;
    if ((*p >= 'A') && (*p <= 'F'))
      continue;
    *error = "Invalid character in IPv6 address";
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<parse_ipv6addr>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d0 <parse_ipv6addr+0xd0>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1136 <parse_ipv6addr+0x36>
jmp    11bf <parse_ipv6addr+0xbf>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     115b <parse_ipv6addr+0x5b>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     115b <parse_ipv6addr+0x5b>
jmp    11bf <parse_ipv6addr+0xbf>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x61,%eax
jl     1180 <parse_ipv6addr+0x80>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x66,%eax
jg     1180 <parse_ipv6addr+0x80>
jmp    11bf <parse_ipv6addr+0xbf>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x41,%eax
jl     11a5 <parse_ipv6addr+0xa5>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x46,%eax
jg     11a5 <parse_ipv6addr+0xa5>
jmp    11bf <parse_ipv6addr+0xbf>
mov    -0x18(%rbp),%rax
lea    0xe50(%rip),%rcx
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11d7 <parse_ipv6addr+0xd7>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1114 <parse_ipv6addr+0x14>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_ipv6addr>:
movabs $0x3f0000003f,%rax
jmp    1114 <parse_ipv6addr+0x14>
nopl   0x0(%rax)
add    $0x1,%rdi
movzbl (%rdi),%ecx
cmp    $0x3a,%cl
je     1110 <parse_ipv6addr+0x10>
test   %cl,%cl
je     1146 <parse_ipv6addr+0x46>
lea    -0x30(%rcx),%edx
cmp    $0xa,%dl
jb     1110 <parse_ipv6addr+0x10>
add    $0xbf,%cl
cmp    $0x25,%cl
ja     1139 <parse_ipv6addr+0x39>
movzbl %cl,%ecx
bt     %rcx,%rax
jb     1110 <parse_ipv6addr+0x10>
lea    0xec0(%rip),%rax
mov    %rax,(%rsi)
xor    %eax,%eax
ret
mov    $0x1,%eax
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Invalid character in IPv6 address\00"
define i32 @parse_ipv6addr(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
%7 = load i8*, i8** %4
store i8* %7, i8** %6
br label %8
8: ; preds = %53, %2
%9 = load i8*, i8** %6
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %56
12: ; preds = %8
%13 = load i8*, i8** %6
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 58
br i1 %16, label %17, label %18
17: ; preds = %12
br label %53
18: ; preds = %12
%19 = load i8*, i8** %6
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp sge i32 %21, 48
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = load i8*, i8** %6
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp sle i32 %26, 57
br i1 %27, label %28, label %29
28: ; preds = %23
br label %53
29: ; preds = %23, %18
%30 = load i8*, i8** %6
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp sge i32 %32, 97
br i1 %33, label %34, label %40
34: ; preds = %29
%35 = load i8*, i8** %6
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp sle i32 %37, 102
br i1 %38, label %39, label %40
39: ; preds = %34
br label %53
40: ; preds = %34, %29
%41 = load i8*, i8** %6
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp sge i32 %43, 65
br i1 %44, label %45, label %51
45: ; preds = %40
%46 = load i8*, i8** %6
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp sle i32 %48, 70
br i1 %49, label %50, label %51
50: ; preds = %45
br label %53
51: ; preds = %45, %40
%52 = load i8**, i8*** %5
store i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8** %52
store i32 0, i32* %3
br label %57
53: ; preds = %50, %39, %28, %17
%54 = load i8*, i8** %6
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %6
br label %8
56: ; preds = %8
store i32 1, i32* %3
br label %57
57: ; preds = %56, %51
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str = [34 x i8] c"Invalid character in IPv6 address\00"
define i32 @parse_ipv6addr(i8* nocapture %0, i8** nocapture writeonly %1) {
br label %3
3: ; preds = %11, %2
%4 = phi i8* [ %0, %2 ], [ %12, %11 ]
%5 = load i8, i8* %4
switch i8 %5, label %6 [
i8 0, label %13
i8 58, label %11
]
6: ; preds = %3
%7 = add i8 %5, -48
%8 = icmp ult i8 %7, 10
br i1 %8, label %11, label %9
9: ; preds = %6
switch i8 %5, label %10 [
i8 102, label %11
i8 101, label %11
i8 100, label %11
i8 99, label %11
i8 98, label %11
i8 97, label %11
i8 70, label %11
i8 69, label %11
i8 68, label %11
i8 67, label %11
i8 66, label %11
i8 65, label %11
]
10: ; preds = %9
store i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8** %1
br label %13
11: ; preds = %9, %9, %9, %9, %9, %9, %9, %9, %9, %9, %9, %9, %6, %3
%12 = getelementptr inbounds i8, i8* %4, i64 1
br label %3
13: ; preds = %3, %10
%14 = phi i32 [ 0, %10 ], [ 1, %3 ]
ret i32 %14
}