#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 char uint8_t;
struct in_addr {
  int dummy;
};

/* Variables and functions */
scalar_t__ inet_aton(char *, struct in_addr *);
int strspn(char *, char *);
bool parse_ip4_label(struct in_addr *out, const uint8_t label[8]) {
  char ip4addr[] = {
      '0',      'x',      label[0], label[1], label[2], label[3],
      label[4], label[5], label[6], label[7], 0,
  };
  if (strspn(ip4addr + 2, "0123456789abcdef") != 8)
    return false;
  return inet_aton(ip4addr, out) != 0;
}


x86 assembly (clang, -O0):
<parse_ip4_label>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movb   $0x30,-0x23(%rbp)
movb   $0x78,-0x22(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x21(%rbp)
mov    -0x18(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2(%rax),%al
mov    %al,-0x1f(%rbp)
mov    -0x18(%rbp),%rax
mov    0x3(%rax),%al
mov    %al,-0x1e(%rbp)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%al
mov    %al,-0x1d(%rbp)
mov    -0x18(%rbp),%rax
mov    0x5(%rax),%al
mov    %al,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    0x6(%rax),%al
mov    %al,-0x1b(%rbp)
mov    -0x18(%rbp),%rax
mov    0x7(%rax),%al
mov    %al,-0x1a(%rbp)
movb   $0x0,-0x19(%rbp)
lea    -0x23(%rbp),%rdi
add    $0x2,%rdi
lea    0xe66(%rip),%rsi
call   1030 <strspn@plt>
cmp    $0x8,%eax
je     11b4 <parse_ip4_label+0x94>
movl   $0x0,-0x4(%rbp)
jmp    11d0 <parse_ip4_label+0xb0>
lea    -0x23(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <inet_aton@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_ip4_label>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movw   $0x7830,0x5(%rsp)
lea    0x7(%rsp),%rdi
mov    (%rsi),%al
mov    %al,0x7(%rsp)
mov    0x1(%rsi),%al
mov    %al,0x8(%rsp)
mov    0x2(%rsi),%al
mov    %al,0x9(%rsp)
mov    0x3(%rsi),%al
mov    %al,0xa(%rsp)
mov    0x4(%rsi),%al
mov    %al,0xb(%rsp)
mov    0x5(%rsi),%al
mov    %al,0xc(%rsp)
mov    0x6(%rsi),%al
mov    %al,0xd(%rsp)
mov    0x7(%rsi),%al
mov    %al,0xe(%rsp)
movb   $0x0,0xf(%rsp)
lea    0xe89(%rip),%rsi
call   1030 <strspn@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x8,%ecx
jne    119d <parse_ip4_label+0x7d>
lea    0x5(%rsp),%rdi
mov    %rbx,%rsi
call   1040 <inet_aton@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [17 x i8] c"0123456789abcdef\00"
define i32 @parse_ip4_label(%struct.in_addr* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.in_addr*
%5 = alloca i8*
%6 = alloca [11 x i8]
store %struct.in_addr* %0, %struct.in_addr** %4
store i8* %1, i8** %5
%7 = getelementptr inbounds [11 x i8], [11 x i8]* %6, i64 0, i64 0
store i8 48, i8* %7
%8 = getelementptr inbounds i8, i8* %7, i64 1
store i8 120, i8* %8
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8*, i8** %5
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
store i8 %12, i8* %9
%13 = getelementptr inbounds i8, i8* %9, i64 1
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %15
store i8 %16, i8* %13
%17 = getelementptr inbounds i8, i8* %13, i64 1
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 2
%20 = load i8, i8* %19
store i8 %20, i8* %17
%21 = getelementptr inbounds i8, i8* %17, i64 1
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 3
%24 = load i8, i8* %23
store i8 %24, i8* %21
%25 = getelementptr inbounds i8, i8* %21, i64 1
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i64 4
%28 = load i8, i8* %27
store i8 %28, i8* %25
%29 = getelementptr inbounds i8, i8* %25, i64 1
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 5
%32 = load i8, i8* %31
store i8 %32, i8* %29
%33 = getelementptr inbounds i8, i8* %29, i64 1
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 6
%36 = load i8, i8* %35
store i8 %36, i8* %33
%37 = getelementptr inbounds i8, i8* %33, i64 1
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i64 7
%40 = load i8, i8* %39
store i8 %40, i8* %37
%41 = getelementptr inbounds i8, i8* %37, i64 1
store i8 0, i8* %41
%42 = getelementptr inbounds [11 x i8], [11 x i8]* %6, i64 0, i64 0
%43 = getelementptr inbounds i8, i8* %42, i64 2
%44 = call i32 @strspn(i8* %43, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%45 = icmp ne i32 %44, 8
br i1 %45, label %46, label %47
46: ; preds = %2
store i32 0, i32* %3
br label %53
47: ; preds = %2
%48 = getelementptr inbounds [11 x i8], [11 x i8]* %6, i64 0, i64 0
%49 = load %struct.in_addr*, %struct.in_addr** %4
%50 = call i64 @inet_aton(i8* %48, %struct.in_addr* %49)
%51 = icmp ne i64 %50, 0
%52 = zext i1 %51 to i32
store i32 %52, i32* %3
br label %53
53: ; preds = %47, %46
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@.str = [17 x i8] c"0123456789abcdef\00"
define i32 @parse_ip4_label(%struct.in_addr* %0, i8* nocapture %1) {
%3 = alloca [11 x i8]
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
store i8 48, i8* %4
%5 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 1
store i8 120, i8* %5
%6 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 2
%7 = load i8, i8* %1
store i8 %7, i8* %6
%8 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 3
%9 = getelementptr inbounds i8, i8* %1, i64 1
%10 = load i8, i8* %9
store i8 %10, i8* %8
%11 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 4
%12 = getelementptr inbounds i8, i8* %1, i64 2
%13 = load i8, i8* %12
store i8 %13, i8* %11
%14 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 5
%15 = getelementptr inbounds i8, i8* %1, i64 3
%16 = load i8, i8* %15
store i8 %16, i8* %14
%17 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 6
%18 = getelementptr inbounds i8, i8* %1, i64 4
%19 = load i8, i8* %18
store i8 %19, i8* %17
%20 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 7
%21 = getelementptr inbounds i8, i8* %1, i64 5
%22 = load i8, i8* %21
store i8 %22, i8* %20
%23 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 8
%24 = getelementptr inbounds i8, i8* %1, i64 6
%25 = load i8, i8* %24
store i8 %25, i8* %23
%26 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 9
%27 = getelementptr inbounds i8, i8* %1, i64 7
%28 = load i8, i8* %27
store i8 %28, i8* %26
%29 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 10
store i8 0, i8* %29
%30 = call i32 @strspn(i8* %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%31 = icmp eq i32 %30, 8
br i1 %31, label %32, label %36
32: ; preds = %2
%33 = call i64 @inet_aton(i8* %4, %struct.in_addr* %0)
%34 = icmp ne i64 %33, 0
%35 = zext i1 %34 to i32
br label %36
36: ; preds = %2, %32
%37 = phi i32 [ %35, %32 ], [ 0, %2 ]
ret i32 %37
}