#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__ isalnum(char);
int /*<<< orphan*/ isalpha(char);
int /*<<< orphan*/ strncpy(char *, char *, int);
char toupper(char);
char *get_sane_name(char *name) {
  static char str[32];
  char *cp;
  if (!isalpha(*name))
    return 0;
  for (cp = name; *cp && (isalnum(*cp) || (*cp == ' ' && isalnum(*(cp + 1))));
       cp++)
    ;
  if (*cp)
    return 0;
  strncpy(str, name, 32 - 1);
  str[32 - 1] = '\0';
  *str = toupper(*str);
  return str;
}


x86 assembly (clang, -O0):
<get_sane_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isalpha@plt>
cmp    $0x0,%eax
jne    116e <get_sane_name+0x2e>
movq   $0x0,-0x8(%rbp)
jmp    125a <get_sane_name+0x11a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     11e1 <get_sane_name+0xa1>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isalnum@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x1a(%rbp)
jne    11db <get_sane_name+0x9b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x20,%ecx
mov    %al,-0x1b(%rbp)
jne    11d5 <get_sane_name+0x95>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1050 <isalnum@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x1b(%rbp)
mov    -0x1b(%rbp),%al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11f1 <get_sane_name+0xb1>
jmp    1207 <get_sane_name+0xc7>
jmp    11f6 <get_sane_name+0xb6>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1176 <get_sane_name+0x36>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1221 <get_sane_name+0xe1>
movq   $0x0,-0x8(%rbp)
jmp    125a <get_sane_name+0x11a>
mov    -0x10(%rbp),%rsi
lea    0x2e24(%rip),%rdi
mov    $0x1f,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x2e32(%rip)
movsbl 0x2e0c(%rip),%edi
call   1040 <toupper@plt>
mov    %al,0x2e01(%rip)
lea    0x2dfa(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sane_name>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movsbl (%rdi),%edi
call   1060 <isalpha@plt>
test   %eax,%eax
je     1194 <get_sane_name+0x54>
mov    (%r14),%al
test   %al,%al
je     1198 <get_sane_name+0x58>
lea    0x1(%r14),%rbx
jmp    116b <get_sane_name+0x2b>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1198 <get_sane_name+0x58>
movsbl %al,%edi
call   1050 <isalnum@plt>
test   %rax,%rax
jne    1160 <get_sane_name+0x20>
movzbl -0x1(%rbx),%eax
cmp    $0x20,%al
jne    1190 <get_sane_name+0x50>
movsbl (%rbx),%edi
call   1050 <isalnum@plt>
test   %rax,%rax
jne    1160 <get_sane_name+0x20>
mov    -0x1(%rbx),%al
test   %al,%al
je     1198 <get_sane_name+0x58>
xor    %ebx,%ebx
jmp    11c8 <get_sane_name+0x88>
lea    0x2eb1(%rip),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1f,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x2eb9(%rip)
movsbl 0x2e93(%rip),%edi
call   1040 <toupper@plt>
mov    %al,0x2e88(%rip)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@get_sane_name.str = internal global [32 x i8] zeroinitializer
define i8* @get_sane_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i8, i8* %5
%7 = call i32 @isalpha(i8 signext %6)
%8 = icmp ne i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %1
store i8* null, i8** %2
br label %53
10: ; preds = %1
%11 = load i8*, i8** %3
store i8* %11, i8** %4
br label %12
12: ; preds = %40, %10
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %37
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = call i64 @isalnum(i8 signext %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %35, label %22
22: ; preds = %17
%23 = load i8*, i8** %4
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 32
br i1 %26, label %27, label %33
27: ; preds = %22
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i8, i8* %29
%31 = call i64 @isalnum(i8 signext %30)
%32 = icmp ne i64 %31, 0
br label %33
33: ; preds = %27, %22
%34 = phi i1 [ false, %22 ], [ %32, %27 ]
br label %35
35: ; preds = %33, %17
%36 = phi i1 [ true, %17 ], [ %34, %33 ]
br label %37
37: ; preds = %35, %12
%38 = phi i1 [ false, %12 ], [ %36, %35 ]
br i1 %38, label %39, label %43
39: ; preds = %37
br label %40
40: ; preds = %39
%41 = load i8*, i8** %4
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %4
br label %12
43: ; preds = %37
%44 = load i8*, i8** %4
%45 = load i8, i8* %44
%46 = icmp ne i8 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %43
store i8* null, i8** %2
br label %53
48: ; preds = %43
%49 = load i8*, i8** %3
%50 = call i32 @strncpy(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_sane_name.str, i64 0, i64 0), i8* %49, i32 31)
store i8 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_sane_name.str, i64 0, i64 31)
%51 = load i8, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_sane_name.str, i64 0, i64 0)
%52 = call signext i8 @toupper(i8 signext %51)
store i8 %52, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_sane_name.str, i64 0, i64 0)
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_sane_name.str, i64 0, i64 0), i8** %2
br label %53
53: ; preds = %48, %47, %9
%54 = load i8*, i8** %2
ret i8* %54
}

LLVM IR (-O2):
@get_sane_name.str = internal global [32 x i8] zeroinitializer
define i8* @get_sane_name(i8* %0) {
%2 = load i8, i8* %0
%3 = tail call i32 @isalpha(i8 signext %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %34, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %30, label %8
8: ; preds = %5, %21
%9 = phi i8 [ %23, %21 ], [ %6, %5 ]
%10 = phi i8* [ %22, %21 ], [ %0, %5 ]
%11 = tail call i64 @isalnum(i8 signext %9)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %8
%14 = load i8, i8* %10
%15 = icmp eq i8 %14, 32
br i1 %15, label %16, label %27
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %10, i64 1
%18 = load i8, i8* %17
%19 = tail call i64 @isalnum(i8 signext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %8, %16
%22 = getelementptr inbounds i8, i8* %10, i64 1
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %30, label %8
25: ; preds = %16
%26 = load i8, i8* %10
br label %27
27: ; preds = %13, %25
%28 = phi i8 [ %26, %25 ], [ %14, %13 ]
%29 = icmp eq i8 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %21, %5, %27
%31 = tail call i32 @strncpy(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_sane_name.str, i64 0, i64 0), i8* %0, i32 31)
store i8 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_sane_name.str, i64 0, i64 31)
%32 = load i8, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_sane_name.str, i64 0, i64 0)
%33 = tail call signext i8 @toupper(i8 signext %32)
store i8 %33, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_sane_name.str, i64 0, i64 0)
br label %34
34: ; preds = %27, %1, %30
%35 = phi i8* [ getelementptr inbounds ([32 x i8], [32 x i8]* @get_sane_name.str, i64 0, i64 0), %30 ], [ null, %1 ], [ null, %27 ]
ret i8* %35
}