#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*/ die(char *);
int /*<<< orphan*/ isalnum(char);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ strlen(char *);
char toupper(char);
void genname(const char *fname, char *name) {
  char str[256], *c;
  strcpy(str, fname);
  c = strchr(str, '.');
  if ((c - str) > 8)
    c[8] = 0;
  else
    *c = 0;
  c = str - 1;
  do {
    c++;
    *c = toupper(*c);
    if (!isalnum(*c))
      *c = 0;
  } while (*c != 0);
  if (!strlen(str))
    die("A valid variable name could not be generated!\n");
  strcpy(name, str);
}


x86 assembly (clang, -O0):
<genname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strchr@plt>
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rax
lea    -0x110(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x8,%rax
jle    11c6 <genname+0x66>
mov    -0x118(%rbp),%rax
movb   $0x0,0x8(%rax)
jmp    11d0 <genname+0x70>
mov    -0x118(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x110(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
mov    %al,%cl
mov    -0x118(%rbp),%rax
mov    %cl,(%rax)
mov    -0x118(%rbp),%rax
movsbl (%rax),%edi
call   1070 <isalnum@plt>
cmp    $0x0,%eax
jne    1230 <genname+0xd0>
mov    -0x118(%rbp),%rax
movb   $0x0,(%rax)
jmp    1235 <genname+0xd5>
mov    -0x118(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11e2 <genname+0x82>
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%eax
jne    1269 <genname+0x109>
lea    0xd9c(%rip),%rdi
call   1080 <die@plt>
mov    -0x10(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genname>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1060 <strchr@plt>
mov    %rax,%rcx
sub    %rbx,%rcx
xor    %edx,%edx
cmp    $0x9,%rcx
setge  %dl
movb   $0x0,(%rax,%rdx,8)
nopl   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1040 <toupper@plt>
mov    %al,(%rbx)
movsbl %al,%edi
call   1070 <isalnum@plt>
test   %eax,%eax
je     11c1 <genname+0x61>
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
jne    11a0 <genname+0x40>
jmp    11c4 <genname+0x64>
movb   $0x0,(%rbx)
mov    %rsp,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jne    11dc <genname+0x7c>
lea    0xe29(%rip),%rdi
call   1080 <die@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [47 x i8] c"A valid variable name could not be generated!\0A\00"
define void @genname(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [256 x i8]
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = call i32 @strcpy(i8* %7, i8* %8)
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%11 = call i8* @strchr(i8* %10, i8 signext 46)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%14 = ptrtoint i8* %12 to i64
%15 = ptrtoint i8* %13 to i64
%16 = sub i64 %14, %15
%17 = icmp sgt i64 %16, 8
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i64 8
store i8 0, i8* %20
br label %23
21: ; preds = %2
%22 = load i8*, i8** %6
store i8 0, i8* %22
br label %23
23: ; preds = %21, %18
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%25 = getelementptr inbounds i8, i8* %24, i64 -1
store i8* %25, i8** %6
br label %26
26: ; preds = %40, %23
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %6
%29 = load i8*, i8** %6
%30 = load i8, i8* %29
%31 = call signext i8 @toupper(i8 signext %30)
%32 = load i8*, i8** %6
store i8 %31, i8* %32
%33 = load i8*, i8** %6
%34 = load i8, i8* %33
%35 = call i32 @isalnum(i8 signext %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %26
%38 = load i8*, i8** %6
store i8 0, i8* %38
br label %39
39: ; preds = %37, %26
br label %40
40: ; preds = %39
%41 = load i8*, i8** %6
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 0
br i1 %44, label %26, label %45
45: ; preds = %40
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
%48 = icmp ne i32 %47, 0
br i1 %48, label %51, label %49
49: ; preds = %45
%50 = call i32 @die(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %51
51: ; preds = %49, %45
%52 = load i8*, i8** %4
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%54 = call i32 @strcpy(i8* %52, i8* %53)
ret void
}

LLVM IR (-O2):
@.str = [47 x i8] c"A valid variable name could not be generated!\0A\00"
define void @genname(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* %0)
%6 = call i8* @strchr(i8* %4, i8 signext 46)
%7 = ptrtoint i8* %6 to i64
%8 = ptrtoint [256 x i8]* %3 to i64
%9 = sub i64 %7, %8
%10 = icmp sgt i64 %9, 8
%11 = select i1 %10, i64 8, i64 0
%12 = getelementptr i8, i8* %6, i64 %11
store i8 0, i8* %12
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 -1
br label %14
14: ; preds = %22, %2
%15 = phi i8* [ %13, %2 ], [ %16, %22 ]
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %16
%18 = call signext i8 @toupper(i8 signext %17)
store i8 %18, i8* %16
%19 = call i32 @isalnum(i8 signext %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %14
store i8 0, i8* %16
br label %25
22: ; preds = %14
%23 = load i8, i8* %16
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %14
25: ; preds = %22, %21
%26 = call i32 @strlen(i8* %4)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @die(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
%31 = call i32 @strcpy(i8* %1, i8* %4)
ret void
}