#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 */

/* Variables and functions */
scalar_t__ strchr(char *, char const);
scalar_t__ strlen(char const *);
scalar_t__ strspn(char const *, char *);
int validate_label(const char *label) {
  return (*label) &&
         (strspn(label, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
                        "_"
                        "0123456789") == strlen(label)) &&
         strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
                "_",
                *label);
}


x86 assembly (clang, -O0):
<validate_label>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x9(%rbp)
je     11a0 <validate_label+0x70>
mov    -0x8(%rbp),%rdi
lea    0xea4(%rip),%rsi
call   1050 <strspn@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x9(%rbp)
jne    11a0 <validate_label+0x70>
mov    -0x8(%rbp),%rax
lea    0xeb2(%rip),%rdi
movsbl (%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_label>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%r15b
xor    %ebp,%ebp
test   %r15b,%r15b
je     1179 <validate_label+0x49>
mov    %rdi,%rbx
lea    0xeb5(%rip),%rsi
call   1050 <strspn@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %rax,%r14
jne    1179 <validate_label+0x49>
movsbl %r15b,%esi
lea    0xed5(%rip),%rdi
call   1040 <strchr@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [64 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789\00"
@.str.1 = [54 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_\00"
define i32 @validate_label(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = load i8, i8* %3
%5 = sext i8 %4 to i32
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %18
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = call i64 @strspn(i8* %8, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
%10 = load i8*, i8** %2
%11 = call i64 @strlen(i8* %10)
%12 = icmp eq i64 %9, %11
br i1 %12, label %13, label %18
13: ; preds = %7
%14 = load i8*, i8** %2
%15 = load i8, i8* %14
%16 = call i64 @strchr(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8 signext %15)
%17 = icmp ne i64 %16, 0
br label %18
18: ; preds = %13, %7, %1
%19 = phi i1 [ false, %7 ], [ false, %1 ], [ %17, %13 ]
%20 = zext i1 %19 to i32
ret i32 %20
}

LLVM IR (-O2):
@.str = [64 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789\00"
@.str.1 = [54 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_\00"
define i32 @validate_label(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i64 @strspn(i8* %0, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
%6 = tail call i64 @strlen(i8* %0)
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = tail call i64 @strchr(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8 signext %2)
%10 = icmp ne i64 %9, 0
%11 = zext i1 %10 to i32
br label %12
12: ; preds = %8, %4, %1
%13 = phi i32 [ 0, %4 ], [ 0, %1 ], [ %11, %8 ]
ret i32 %13
}