#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 strlen(char const *);
int validname(const char *str) {
  int i;
  int err = 0;
  int len = strlen(str);
  for (i = 0; i < len; i++) {
    if (!isuscoreoralpha(str[0])) {
      err += 1;
      break;
    } else if (!isuscoreoralnum(str[i])) {
      err += 1;
      break;
    }
  }
  if (err == 0)
    return 1;
  else
    return -1;
}


x86 assembly (clang, -O0):
<validname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11c5 <validname+0x95>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isuscoreoralpha@plt>
cmp    $0x0,%eax
jne    1185 <validname+0x55>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c5 <validname+0x95>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isuscoreoralnum@plt>
cmp    $0x0,%eax
jne    11ad <validname+0x7d>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c5 <validname+0x95>
jmp    11b2 <validname+0x82>
jmp    11b7 <validname+0x87>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1156 <validname+0x26>
cmpl   $0x0,-0x18(%rbp)
jne    11db <validname+0xab>
movl   $0x1,-0x4(%rbp)
jmp    11e2 <validname+0xb2>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validname>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %eax,%eax
jle    1174 <validname+0x44>
mov    %eax,%r14d
xor    %ebx,%ebx
mov    $0xffffffff,%ebp
nopl   (%rax)
movsbl (%r15),%edi
call   1050 <isuscoreoralpha@plt>
test   %eax,%eax
je     1179 <validname+0x49>
movsbl (%r15,%rbx,1),%edi
call   1040 <isuscoreoralnum@plt>
test   %eax,%eax
je     1179 <validname+0x49>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <validname+0x20>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @validname(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %19
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %8
6: ; preds = %13
%7 = icmp eq i64 %18, %5
br i1 %7, label %19, label %8
8: ; preds = %4, %6
%9 = phi i64 [ 0, %4 ], [ %18, %6 ]
%10 = load i8, i8* %0
%11 = tail call i32 @isuscoreoralpha(i8 signext %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %8
%14 = getelementptr inbounds i8, i8* %0, i64 %9
%15 = load i8, i8* %14
%16 = tail call i32 @isuscoreoralnum(i8 signext %15)
%17 = icmp eq i32 %16, 0
%18 = add nuw nsw i64 %9, 1
br i1 %17, label %19, label %6
19: ; preds = %6, %8, %13, %1
%20 = phi i32 [ 1, %1 ], [ -1, %13 ], [ -1, %8 ], [ 1, %6 ]
ret i32 %20
}