#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__ isdigit(char const);
size_t strlen(char const *);
int /*<<< orphan*/ valid_name_char(char const);
int validate_name(const char *name) {
  size_t len = strlen(name);
  const char *p = name;
  if (!p || *p == '\0' || isdigit(*p))
    return 0;
  do {
    if (!valid_name_char(*p))
      return 0;
  } while ((size_t)(++p - name) < len);
  return 1;
}


x86 assembly (clang, -O0):
<validate_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1182 <validate_name+0x52>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1182 <validate_name+0x52>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     118e <validate_name+0x5e>
movl   $0x0,-0x4(%rbp)
jmp    11dd <validate_name+0xad>
jmp    1193 <validate_name+0x63>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1050 <valid_name_char@plt>
cmp    $0x0,%eax
jne    11b4 <validate_name+0x84>
movl   $0x0,-0x4(%rbp)
jmp    11dd <validate_name+0xad>
jmp    11b9 <validate_name+0x89>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
cmp    -0x18(%rbp),%rax
jb     1193 <validate_name+0x63>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_name>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
call   1040 <strlen@plt>
xor    %r14d,%r14d
test   %r12,%r12
je     118d <validate_name+0x5d>
mov    %rax,%r15
mov    (%r12),%al
test   %al,%al
je     118d <validate_name+0x5d>
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    118d <validate_name+0x5d>
xor    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%r12,%rbx,1),%edi
call   1050 <valid_name_char@plt>
test   %eax,%eax
je     118d <validate_name+0x5d>
add    $0x1,%rbx
cmp    %r15,%rbx
jb     1170 <validate_name+0x40>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @validate_name(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %4
%8 = load i8*, i8** %3
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %21
11: ; preds = %1
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %11
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = call i64 @isdigit(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16, %11, %1
store i32 0, i32* %2
br label %40
22: ; preds = %16
br label %23
23: ; preds = %30, %22
%24 = load i8*, i8** %5
%25 = load i8, i8* %24
%26 = call i32 @valid_name_char(i8 signext %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %23
store i32 0, i32* %2
br label %40
29: ; preds = %23
br label %30
30: ; preds = %29
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %5
%33 = load i8*, i8** %3
%34 = ptrtoint i8* %32 to i64
%35 = ptrtoint i8* %33 to i64
%36 = sub i64 %34, %35
%37 = load i64, i64* %4
%38 = icmp ult i64 %36, %37
br i1 %38, label %23, label %39
39: ; preds = %30
store i32 1, i32* %2
br label %40
40: ; preds = %39, %28, %21
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
define i32 @validate_name(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp eq i8* %0, null
br i1 %3, label %22, label %4
4: ; preds = %1
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %22, label %7
7: ; preds = %4
%8 = tail call i64 @isdigit(i8 signext %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %22
10: ; preds = %7
%11 = ptrtoint i8* %0 to i64
br label %12
12: ; preds = %10, %17
%13 = phi i8* [ %18, %17 ], [ %0, %10 ]
%14 = load i8, i8* %13
%15 = tail call i32 @valid_name_char(i8 signext %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %12
%18 = getelementptr inbounds i8, i8* %13, i64 1
%19 = ptrtoint i8* %18 to i64
%20 = sub i64 %19, %11
%21 = icmp ult i64 %20, %2
br i1 %21, label %12, label %22
22: ; preds = %17, %12, %1, %4, %7
%23 = phi i32 [ 0, %7 ], [ 0, %4 ], [ 0, %1 ], [ 1, %17 ], [ 0, %12 ]
ret i32 %23
}