#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 */
int /*<<< orphan*/ isuscoreoralnum(char const);
int /*<<< orphan*/ isuscoreoralpha(char const);
int /*<<< orphan*/ printf(char *, char const *);
int strlen(char const *);
void validname(const char *str) {
  int i;
  int err = 0;
  int len = strlen(str);
  for (i = 0; i < len; i++) {
    if (!isuscoreoralpha(str[0])) {
      printf("%s has invalid first character.\n", str);
      err += 1;
      break;
    } else if (!isuscoreoralnum(str[i])) {
      printf("%s : Non-letter-or-underscore found.\n", str);
      err += 1;
      break;
    }
  }
  if (err == 0)
    printf("%s is a valid name.\n", str);
}


x86 assembly (clang, -O0):
<validname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f5 <validname+0xb5>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isuscoreoralpha@plt>
cmp    $0x0,%eax
jne    11a5 <validname+0x65>
mov    -0x8(%rbp),%rsi
lea    0xe6e(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11f5 <validname+0xb5>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isuscoreoralnum@plt>
cmp    $0x0,%eax
jne    11dd <validname+0x9d>
mov    -0x8(%rbp),%rsi
lea    0xe57(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11f5 <validname+0xb5>
jmp    11e2 <validname+0xa2>
jmp    11e7 <validname+0xa7>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1166 <validname+0x26>
cmpl   $0x0,-0x10(%rbp)
jne    120f <validname+0xcf>
mov    -0x8(%rbp),%rsi
lea    0xe3d(%rip),%rdi
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validname>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %eax,%eax
jle    1184 <validname+0x44>
mov    %eax,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movsbl (%r15),%edi
call   1060 <isuscoreoralpha@plt>
test   %eax,%eax
je     118d <validname+0x4d>
movsbl (%r15,%rbx,1),%edi
call   1040 <isuscoreoralnum@plt>
test   %eax,%eax
je     1196 <validname+0x56>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1160 <validname+0x20>
lea    0xebc(%rip),%rdi
jmp    119d <validname+0x5d>
lea    0xe6c(%rip),%rdi
jmp    119d <validname+0x5d>
lea    0xe84(%rip),%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"%s has invalid first character.\0A\00"
@.str.1 = [38 x i8] c"%s : Non-letter-or-underscore found.\0A\00"
@.str.2 = [21 x i8] c"%s is a valid name.\0A\00"
define void @validname(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
store i32 0, i32* %3
br label %8
8: ; preds = %38, %1
%9 = load i32, i32* %3
%10 = load i32, i32* %5
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %41
12: ; preds = %8
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = call i32 @isuscoreoralpha(i8 signext %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %12
%19 = load i8*, i8** %2
%20 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %41
23: ; preds = %12
%24 = load i8*, i8** %2
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = call i32 @isuscoreoralnum(i8 signext %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %23
%32 = load i8*, i8** %2
%33 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %41
36: ; preds = %23
br label %37
37: ; preds = %36
br label %38
38: ; preds = %37
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %3
br label %8
41: ; preds = %31, %18, %8
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i8*, i8** %2
%46 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %44, %41
ret void
}

LLVM IR (-O2):
@.str = [33 x i8] c"%s has invalid first character.\0A\00"
@.str.1 = [38 x i8] c"%s : Non-letter-or-underscore found.\0A\00"
@.str.2 = [21 x i8] c"%s is a valid name.\0A\00"
define void @validname(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %23
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %8
6: ; preds = %15
%7 = icmp eq i64 %20, %5
br i1 %7, label %23, label %8
8: ; preds = %4, %6
%9 = phi i64 [ 0, %4 ], [ %20, %6 ]
%10 = load i8, i8* %0
%11 = tail call i32 @isuscoreoralpha(i8 signext %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %25
15: ; preds = %8
%16 = getelementptr inbounds i8, i8* %0, i64 %9
%17 = load i8, i8* %16
%18 = tail call i32 @isuscoreoralnum(i8 signext %17)
%19 = icmp eq i32 %18, 0
%20 = add nuw nsw i64 %9, 1
br i1 %19, label %21, label %6
21: ; preds = %15
%22 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %25
23: ; preds = %6, %1
%24 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %25
25: ; preds = %13, %21, %23
ret void
}