#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*/ isalnum(char);
int /*<<< orphan*/ isalpha(char);
scalar_t__ isspace(char);
int is_valid_name(const char *str) {
  char ch;
  if ((ch = *str++) == '\0')
    return 0;
  if (!isalpha(ch) || isspace(ch))
    return 0;
  while ((ch = *str++) != '\0')
    if (!isalnum(ch) || isspace(ch))
      return 0;
  return 1;
}


x86 assembly (clang, -O0):
<is_valid_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
jne    1168 <is_valid_name+0x38>
movl   $0x0,-0x4(%rbp)
jmp    11fb <is_valid_name+0xcb>
movsbl -0x11(%rbp),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%eax
je     118d <is_valid_name+0x5d>
movsbl -0x11(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1199 <is_valid_name+0x69>
movl   $0x0,-0x4(%rbp)
jmp    11fb <is_valid_name+0xcb>
jmp    119e <is_valid_name+0x6e>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     11f4 <is_valid_name+0xc4>
movsbl -0x11(%rbp),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%eax
je     11e3 <is_valid_name+0xb3>
movsbl -0x11(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11ef <is_valid_name+0xbf>
movl   $0x0,-0x4(%rbp)
jmp    11fb <is_valid_name+0xcb>
jmp    119e <is_valid_name+0x6e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_valid_name>:
push   %rbp
push   %r14
push   %rbx
mov    (%rdi),%al
xor    %r14d,%r14d
test   %al,%al
je     115a <is_valid_name+0x2a>
mov    %rdi,%rbx
movsbl %al,%ebp
mov    %ebp,%edi
call   1050 <isalpha@plt>
test   %eax,%eax
je     115a <is_valid_name+0x2a>
mov    %ebp,%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     1162 <is_valid_name+0x32>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
movzbl (%rbx),%eax
test   %al,%al
je     1197 <is_valid_name+0x67>
movsbl %al,%ebp
mov    %ebp,%edi
call   1030 <isalnum@plt>
test   %eax,%eax
je     115a <is_valid_name+0x2a>
mov    %ebp,%edi
call   1040 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
je     1170 <is_valid_name+0x40>
jmp    115a <is_valid_name+0x2a>
mov    $0x1,%r14d
jmp    115a <is_valid_name+0x2a>

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

LLVM IR (-O2):
define i32 @is_valid_name(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %21, label %4
4: ; preds = %1
%5 = tail call i32 @isalpha(i8 signext %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %21, label %7
7: ; preds = %4
%8 = tail call i64 @isspace(i8 signext %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %7, %18
%11 = phi i8* [ %12, %18 ], [ %0, %7 ]
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %10
%16 = tail call i32 @isalnum(i8 signext %13)
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = tail call i64 @isspace(i8 signext %13)
%20 = icmp eq i64 %19, 0
br i1 %20, label %10, label %21
21: ; preds = %10, %15, %18, %4, %7, %1
%22 = phi i32 [ 0, %1 ], [ 0, %7 ], [ 0, %4 ], [ 1, %10 ], [ 0, %15 ], [ 0, %18 ]
ret i32 %22
}