#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 */
typedef int /*<<< orphan*/ file;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ isdigit(char);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *, ...);
unsigned int strlen(char *);
char *generate_name(char *progname, char *file) {
  char *str;
  unsigned int i;
  str = malloc(sizeof(file) * sizeof(char));
  if (str == NULL) {
    printf("\x1B[31;1m%s: Malloc failed?!\x1B[37;0m\r\n", progname);
    exit(5);
  }
  if (isdigit(file[0])) {
    printf(
        "\x1B[31;1m%s: File must not begin with a number (%s)!\x1B[37;0m\r\n",
        progname, file);
    exit(6);
  }
  for (i = 0; i < strlen(file); i++) {
    str[i] = file[i];
    switch (str[i]) {
    case ' ':
    case '.':
    case '+':
    case '-':
    case '$':
    case '%':
    case '|':
    case '/':
    case '\\':
      str[i] = '_';
      break;
    }
  }
  return str;
}


x86 assembly (clang, -O0):
<generate_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1195 <generate_name+0x45>
mov    -0x8(%rbp),%rsi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x5,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11cb <generate_name+0x7b>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x6,%edi
call   1070 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jae    1294 <generate_name+0x144>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x24(%rbp)
sub    $0x20,%eax
je     1276 <generate_name+0x126>
jmp    121b <generate_name+0xcb>
mov    -0x24(%rbp),%eax
add    $0xffffffdc,%eax
sub    $0x2,%eax
jb     1276 <generate_name+0x126>
jmp    122f <generate_name+0xdf>
mov    -0x24(%rbp),%eax
sub    $0x2b,%eax
je     1276 <generate_name+0x126>
jmp    1240 <generate_name+0xf0>
mov    -0x24(%rbp),%eax
add    $0xffffffd3,%eax
sub    $0x3,%eax
jb     1276 <generate_name+0x126>
jmp    1254 <generate_name+0x104>
mov    -0x24(%rbp),%eax
sub    $0x5c,%eax
je     1276 <generate_name+0x126>
jmp    1265 <generate_name+0x115>
mov    -0x24(%rbp),%eax
sub    $0x7c,%eax
jne    1281 <generate_name+0x131>
jmp    1276 <generate_name+0x126>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movb   $0x5f,(%rax,%rcx,1)
jmp    1286 <generate_name+0x136>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d2 <generate_name+0x82>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_name>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x8,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11e5 <generate_name+0x95>
mov    %rax,%r12
movsbl (%r14),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1200 <generate_name+0xb0>
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     11d6 <generate_name+0x86>
xor    %ebx,%ebx
movabs $0x100000000000e831,%r15
jmp    11be <generate_name+0x6e>
nopl   0x0(%rax)
bt     %rcx,%r15
jae    11cf <generate_name+0x7f>
movb   $0x5f,(%r12,%rbx,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbx
jae    11d6 <generate_name+0x86>
movsbl (%r14,%rbx,1),%eax
mov    %al,(%r12,%rbx,1)
lea    -0x20(%rax),%ecx
cmp    $0x3c,%ecx
jbe    11a0 <generate_name+0x50>
cmp    $0x7c,%eax
je     11a6 <generate_name+0x56>
jmp    11ab <generate_name+0x5b>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe14(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x5,%edi
call   1070 <exit@plt>
lea    0xe1d(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x6,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"\1B[31;1m%s: Malloc failed?!\1B[37;0m\0D\0A\00"
@.str.1 = [60 x i8] c"\1B[31;1m%s: File must not begin with a number (%s)!\1B[37;0m\0D\0A\00"
define i8* @generate_name(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = call i8* @malloc(i32 8)
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = call i32 @exit(i32 5)
unreachable
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = call i64 @isdigit(i8 signext %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = load i8*, i8** %3
%22 = load i8*, i8** %4
%23 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %22)
%24 = call i32 @exit(i32 6)
unreachable
25: ; preds = %14
store i32 0, i32* %6
br label %26
26: ; preds = %53, %25
%27 = load i32, i32* %6
%28 = load i8*, i8** %4
%29 = call i32 @strlen(i8* %28)
%30 = icmp ult i32 %27, %29
br i1 %30, label %31, label %56
31: ; preds = %26
%32 = load i8*, i8** %4
%33 = load i32, i32* %6
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = load i8*, i8** %5
%38 = load i32, i32* %6
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 %36, i8* %40
%41 = load i8*, i8** %5
%42 = load i32, i32* %6
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
switch i32 %46, label %52 [
i32 32, label %47
i32 46, label %47
i32 43, label %47
i32 45, label %47
i32 36, label %47
i32 37, label %47
i32 124, label %47
i32 47, label %47
i32 92, label %47
]
47: ; preds = %31, %31, %31, %31, %31, %31, %31, %31, %31
%48 = load i8*, i8** %5
%49 = load i32, i32* %6
%50 = zext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 95, i8* %51
br label %52
52: ; preds = %31, %47
br label %53
53: ; preds = %52
%54 = load i32, i32* %6
%55 = add i32 %54, 1
store i32 %55, i32* %6
br label %26
56: ; preds = %26
%57 = load i8*, i8** %5
ret i8* %57
}

LLVM IR (-O2):
@.str = [36 x i8] c"\1B[31;1m%s: Malloc failed?!\1B[37;0m\0D\0A\00"
@.str.1 = [60 x i8] c"\1B[31;1m%s: File must not begin with a number (%s)!\1B[37;0m\0D\0A\00"
define noalias i8* @generate_name(i8* %0, i8* %1) {
%3 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = tail call i32 @exit(i32 5)
unreachable
8: ; preds = %2
%9 = load i8, i8* %1
%10 = tail call i64 @isdigit(i8 signext %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = tail call i32 @strlen(i8* %1)
%14 = icmp eq i32 %13, 0
br i1 %14, label %30, label %18
15: ; preds = %8
%16 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
%17 = tail call i32 @exit(i32 6)
unreachable
18: ; preds = %12, %25
%19 = phi i64 [ %26, %25 ], [ 0, %12 ]
%20 = getelementptr inbounds i8, i8* %1, i64 %19
%21 = load i8, i8* %20
%22 = getelementptr inbounds i8, i8* %3, i64 %19
store i8 %21, i8* %22
%23 = sext i8 %21 to i32
switch i32 %23, label %25 [
i32 32, label %24
i32 46, label %24
i32 43, label %24
i32 45, label %24
i32 36, label %24
i32 37, label %24
i32 124, label %24
i32 47, label %24
i32 92, label %24
]
24: ; preds = %18, %18, %18, %18, %18, %18, %18, %18, %18
store i8 95, i8* %22
br label %25
25: ; preds = %24, %18
%26 = add nuw nsw i64 %19, 1
%27 = tail call i32 @strlen(i8* %1)
%28 = zext i32 %27 to i64
%29 = icmp ult i64 %26, %28
br i1 %29, label %18, label %30
30: ; preds = %25, %12
ret i8* %3
}