#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;
  for (i = 0; i < strlen(str); 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)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    11f9 <validname+0xb9>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isuscoreoralpha@plt>
cmp    $0x0,%eax
jne    11a9 <validname+0x69>
mov    -0x8(%rbp),%rsi
lea    0xe6a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11f9 <validname+0xb9>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isuscoreoralnum@plt>
cmp    $0x0,%eax
jne    11e1 <validname+0xa1>
mov    -0x8(%rbp),%rsi
lea    0xe53(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11f9 <validname+0xb9>
jmp    11e6 <validname+0xa6>
jmp    11eb <validname+0xab>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115a <validname+0x1a>
cmpl   $0x0,-0x10(%rbp)
jne    1213 <validname+0xd3>
mov    -0x8(%rbp),%rsi
lea    0xe39(%rip),%rdi
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validname>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    118e <validname+0x4e>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl (%r14),%edi
call   1060 <isuscoreoralpha@plt>
test   %eax,%eax
je     1197 <validname+0x57>
movsbl (%r14,%rbx,1),%edi
call   1040 <isuscoreoralnum@plt>
test   %eax,%eax
je     11a0 <validname+0x60>
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1160 <validname+0x20>
lea    0xeb2(%rip),%rdi
jmp    11a7 <validname+0x67>
lea    0xe62(%rip),%rdi
jmp    11a7 <validname+0x67>
lea    0xe7a(%rip),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
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
store i8* %0, i8** %2
store i32 0, i32* %4
store i32 0, i32* %3
br label %5
5: ; preds = %36, %1
%6 = load i32, i32* %3
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = icmp slt i32 %6, %8
br i1 %9, label %10, label %39
10: ; preds = %5
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = call i32 @isuscoreoralpha(i8 signext %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %10
%17 = load i8*, i8** %2
%18 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %39
21: ; preds = %10
%22 = load i8*, i8** %2
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @isuscoreoralnum(i8 signext %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %21
%30 = load i8*, i8** %2
%31 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %39
34: ; preds = %21
br label %35
35: ; preds = %34
br label %36
36: ; preds = %35
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
br label %5
39: ; preds = %29, %16, %5
%40 = load i32, i32* %4
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i8*, i8** %2
%44 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %42, %39
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 %8, label %23
4: ; preds = %15
%5 = tail call i32 @strlen(i8* %0)
%6 = sext i32 %5 to i64
%7 = icmp slt i64 %20, %6
br i1 %7, label %8, label %23
8: ; preds = %1, %4
%9 = phi i64 [ %20, %4 ], [ 0, %1 ]
%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 %4
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 = %4, %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
}