#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 */
char *realloc(char *, int);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strrchr(char *, char);
char toupper(char);
void localFilenameToC64(const char *original, char *c64) {
  static char *buf = NULL;
  static int buflen = 0;
  int len, elen;
  char *exten;
  int i;
  len = strlen(original);
  if (len + 1 > buflen) {
    buflen = ((len + 35) / 32) * 32;
    buf = realloc(buf, buflen);
  }
  strcpy(buf, original);
  for (i = 0; i < len; i++)
    buf[i] = toupper(buf[i]);
  if (!(exten = strrchr(buf, '.'))) {
    elen = len;
    exten = "USR";
  } else {
    elen = exten - buf;
    exten++;
    if (!strcmp(exten, "TXT"))
      strcpy(exten, "SEQ");
    if (strcmp(exten, "SEQ") && strcmp(exten, "USR") && strcmp(exten, "PRG")) {
      elen = len;
      exten = "USR";
    }
  }
  if (elen > 16) {
    elen = 14;
    buf[elen] = '#';
    buf[elen + 1] = '1';
  }
  buf[elen] = '.';
  strncpy(c64, buf, elen);
  c64[elen] = '.';
  c64[elen + 1] = 0;
  strcat(c64, exten);
  return;
}


x86 assembly (clang, -O0):
<localFilenameToC64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cmp    0x2ec8(%rip),%eax
jle    11de <localFilenameToC64+0x5e>
mov    -0x14(%rbp),%eax
add    $0x23,%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
shl    $0x5,%eax
mov    %eax,0x2eab(%rip)
mov    0x2e9c(%rip),%rdi
mov    0x2e9e(%rip),%esi
call   1090 <realloc@plt>
mov    %rax,0x2e8a(%rip)
mov    0x2e83(%rip),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1233 <localFilenameToC64+0xb3>
mov    0x2e60(%rip),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <toupper@plt>
mov    %al,%dl
mov    0x2e4a(%rip),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11f5 <localFilenameToC64+0x75>
mov    0x2e2e(%rip),%rdi
mov    $0x2e,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1268 <localFilenameToC64+0xe8>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    0xda1(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1313 <localFilenameToC64+0x193>
mov    -0x20(%rbp),%rax
mov    0x2df5(%rip),%rcx
sub    %rcx,%rax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xd74(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12af <localFilenameToC64+0x12f>
mov    -0x20(%rbp),%rdi
lea    0xd5e(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xd4e(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     130e <localFilenameToC64+0x18e>
mov    -0x20(%rbp),%rdi
lea    0xd2c(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     130e <localFilenameToC64+0x18e>
mov    -0x20(%rbp),%rdi
lea    0xd1e(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     130e <localFilenameToC64+0x18e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    0xcf6(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1313 <localFilenameToC64+0x193>
cmpl   $0x10,-0x18(%rbp)
jle    1347 <localFilenameToC64+0x1c7>
movl   $0xe,-0x18(%rbp)
mov    0x2d3d(%rip),%rax
movslq -0x18(%rbp),%rcx
movb   $0x23,(%rax,%rcx,1)
mov    0x2d2e(%rip),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x31,(%rax,%rcx,1)
mov    0x2d1a(%rip),%rax
movslq -0x18(%rbp),%rcx
movb   $0x2e,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    0x2d07(%rip),%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x2e,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10a0 <strcat@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<localFilenameToC64>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <strlen@plt>
mov    %eax,%r15d
cmp    0x2ed4(%rip),%eax
jge    11a7 <localFilenameToC64+0x27>
mov    0x2ec3(%rip),%rdi
jmp    11d3 <localFilenameToC64+0x53>
lea    0x23(%r15),%eax
lea    0x42(%r15),%esi
test   %eax,%eax
cmovns %eax,%esi
and    $0xffffffe0,%esi
mov    %esi,0x2eb3(%rip)
mov    0x2ea4(%rip),%rdi
call   1090 <realloc@plt>
mov    %rax,%rdi
mov    %rax,0x2e95(%rip)
mov    %rbx,%rsi
call   1040 <strcpy@plt>
test   %r15d,%r15d
jle    120e <localFilenameToC64+0x8e>
mov    %r15d,%r12d
mov    0x2e7e(%rip),%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
movsbl (%rbx,%rbp,1),%edi
call   1050 <toupper@plt>
mov    0x2e68(%rip),%rbx
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r12
jne    11f0 <localFilenameToC64+0x70>
jmp    1215 <localFilenameToC64+0x95>
mov    0x2e53(%rip),%rbx
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1070 <strrchr@plt>
test   %rax,%rax
je     129d <localFilenameToC64+0x11d>
mov    %rax,%r12
mov    %r12d,%ebp
add    $0x1,%r12
lea    0xdcc(%rip),%rsi
mov    %r12,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1254 <localFilenameToC64+0xd4>
lea    0xdbc(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcpy@plt>
sub    %ebx,%ebp
lea    0xdab(%rip),%rsi
mov    %r12,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12a7 <localFilenameToC64+0x127>
lea    0xd8f(%rip),%rbx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12a7 <localFilenameToC64+0x127>
lea    0xd84(%rip),%rsi
mov    %r12,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
cmove  %ebp,%r15d
cmovne %rbx,%r12
jmp    12a4 <localFilenameToC64+0x124>
lea    0xd5c(%rip),%r12
mov    %r15d,%ebp
mov    0x2dba(%rip),%rsi
cmp    $0x11,%ebp
jl     12be <localFilenameToC64+0x13e>
movw   $0x3123,0xe(%rsi)
mov    $0xe,%ebp
movslq %ebp,%rbx
movb   $0x2e,(%rsi,%rbx,1)
mov    %r14,%rdi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movw   $0x2e,(%r14,%rbx,1)
mov    %r14,%rdi
mov    %r12,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <strcat@plt>

LLVM IR (-O0):
@localFilenameToC64.buf = internal global i8* null
@localFilenameToC64.buflen = internal global i32 0
@.str = [4 x i8] c"USR\00"
@.str.1 = [4 x i8] c"TXT\00"
@.str.2 = [4 x i8] c"SEQ\00"
@.str.3 = [4 x i8] c"PRG\00"
define void @localFilenameToC64(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = add nsw i32 %11, 1
%13 = load i32, i32* @localFilenameToC64.buflen
%14 = icmp sgt i32 %12, %13
br i1 %14, label %15, label %23
15: ; preds = %2
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 35
%18 = sdiv i32 %17, 32
%19 = mul nsw i32 %18, 32
store i32 %19, i32* @localFilenameToC64.buflen
%20 = load i8*, i8** @localFilenameToC64.buf
%21 = load i32, i32* @localFilenameToC64.buflen
%22 = call i8* @realloc(i8* %20, i32 %21)
store i8* %22, i8** @localFilenameToC64.buf
br label %23
23: ; preds = %15, %2
%24 = load i8*, i8** @localFilenameToC64.buf
%25 = load i8*, i8** %3
%26 = call i32 @strcpy(i8* %24, i8* %25)
store i32 0, i32* %8
br label %27
27: ; preds = %42, %23
%28 = load i32, i32* %8
%29 = load i32, i32* %5
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %45
31: ; preds = %27
%32 = load i8*, i8** @localFilenameToC64.buf
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = call signext i8 @toupper(i8 signext %36)
%38 = load i8*, i8** @localFilenameToC64.buf
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 %37, i8* %41
br label %42
42: ; preds = %31
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %27
45: ; preds = %27
%46 = load i8*, i8** @localFilenameToC64.buf
%47 = call i8* @strrchr(i8* %46, i8 signext 46)
store i8* %47, i8** %7
%48 = icmp ne i8* %47, null
br i1 %48, label %51, label %49
49: ; preds = %45
%50 = load i32, i32* %5
store i32 %50, i32* %6
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %7
br label %81
51: ; preds = %45
%52 = load i8*, i8** %7
%53 = load i8*, i8** @localFilenameToC64.buf
%54 = ptrtoint i8* %52 to i64
%55 = ptrtoint i8* %53 to i64
%56 = sub i64 %54, %55
%57 = trunc i64 %56 to i32
store i32 %57, i32* %6
%58 = load i8*, i8** %7
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %7
%60 = load i8*, i8** %7
%61 = call i64 @strcmp(i8* %60, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%62 = icmp ne i64 %61, 0
br i1 %62, label %66, label %63
63: ; preds = %51
%64 = load i8*, i8** %7
%65 = call i32 @strcpy(i8* %64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %66
66: ; preds = %63, %51
%67 = load i8*, i8** %7
%68 = call i64 @strcmp(i8* %67, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %80
70: ; preds = %66
%71 = load i8*, i8** %7
%72 = call i64 @strcmp(i8* %71, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %80
74: ; preds = %70
%75 = load i8*, i8** %7
%76 = call i64 @strcmp(i8* %75, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %74
%79 = load i32, i32* %5
store i32 %79, i32* %6
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %7
br label %80
80: ; preds = %78, %74, %70, %66
br label %81
81: ; preds = %80, %49
%82 = load i32, i32* %6
%83 = icmp sgt i32 %82, 16
br i1 %83, label %84, label %94
84: ; preds = %81
store i32 14, i32* %6
%85 = load i8*, i8** @localFilenameToC64.buf
%86 = load i32, i32* %6
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8, i8* %85, i64 %87
store i8 35, i8* %88
%89 = load i8*, i8** @localFilenameToC64.buf
%90 = load i32, i32* %6
%91 = add nsw i32 %90, 1
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %89, i64 %92
store i8 49, i8* %93
br label %94
94: ; preds = %84, %81
%95 = load i8*, i8** @localFilenameToC64.buf
%96 = load i32, i32* %6
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8, i8* %95, i64 %97
store i8 46, i8* %98
%99 = load i8*, i8** %4
%100 = load i8*, i8** @localFilenameToC64.buf
%101 = load i32, i32* %6
%102 = call i32 @strncpy(i8* %99, i8* %100, i32 %101)
%103 = load i8*, i8** %4
%104 = load i32, i32* %6
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i8, i8* %103, i64 %105
store i8 46, i8* %106
%107 = load i8*, i8** %4
%108 = load i32, i32* %6
%109 = add nsw i32 %108, 1
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i8, i8* %107, i64 %110
store i8 0, i8* %111
%112 = load i8*, i8** %4
%113 = load i8*, i8** %7
%114 = call i32 @strcat(i8* %112, i8* %113)
ret void
}

LLVM IR (-O2):
@localFilenameToC64.buf = internal unnamed_addr global i8* null
@localFilenameToC64.buflen = internal unnamed_addr global i32 0
@.str = [4 x i8] c"USR\00"
@.str.1 = [4 x i8] c"TXT\00"
@.str.2 = [4 x i8] c"SEQ\00"
@.str.3 = [4 x i8] c"PRG\00"
define void @localFilenameToC64(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = load i32, i32* @localFilenameToC64.buflen
%5 = icmp slt i32 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = load i8*, i8** @localFilenameToC64.buf
br label %14
8: ; preds = %2
%9 = add nsw i32 %3, 35
%10 = sdiv i32 %9, 32
%11 = shl nsw i32 %10, 5
store i32 %11, i32* @localFilenameToC64.buflen
%12 = load i8*, i8** @localFilenameToC64.buf
%13 = tail call i8* @realloc(i8* %12, i32 %11)
store i8* %13, i8** @localFilenameToC64.buf
br label %14
14: ; preds = %6, %8
%15 = phi i8* [ %7, %6 ], [ %13, %8 ]
%16 = tail call i32 @strcpy(i8* %15, i8* %0)
%17 = icmp sgt i32 %3, 0
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = load i8*, i8** @localFilenameToC64.buf
br label %33
20: ; preds = %14
%21 = zext i32 %3 to i64
%22 = load i8*, i8** @localFilenameToC64.buf
br label %23
23: ; preds = %20, %23
%24 = phi i8* [ %22, %20 ], [ %29, %23 ]
%25 = phi i64 [ 0, %20 ], [ %31, %23 ]
%26 = getelementptr inbounds i8, i8* %24, i64 %25
%27 = load i8, i8* %26
%28 = tail call signext i8 @toupper(i8 signext %27)
%29 = load i8*, i8** @localFilenameToC64.buf
%30 = getelementptr inbounds i8, i8* %29, i64 %25
store i8 %28, i8* %30
%31 = add nuw nsw i64 %25, 1
%32 = icmp eq i64 %31, %21
br i1 %32, label %33, label %23
33: ; preds = %23, %18
%34 = phi i8* [ %19, %18 ], [ %29, %23 ]
%35 = tail call i8* @strrchr(i8* dereferenceable(1) %34, i8 signext 46)
%36 = icmp eq i8* %35, null
br i1 %36, label %58, label %37
37: ; preds = %33
%38 = ptrtoint i8* %35 to i64
%39 = ptrtoint i8* %34 to i64
%40 = sub i64 %38, %39
%41 = trunc i64 %40 to i32
%42 = getelementptr inbounds i8, i8* %35, i64 1
%43 = tail call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %37
%46 = tail call i32 @strcpy(i8* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %47
47: ; preds = %45, %37
%48 = tail call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %58, label %50
50: ; preds = %47
%51 = tail call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %58, label %53
53: ; preds = %50
%54 = tail call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
%56 = select i1 %55, i32 %41, i32 %3
%57 = select i1 %55, i8* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0)
br label %58
58: ; preds = %53, %33, %47, %50
%59 = phi i32 [ %41, %50 ], [ %41, %47 ], [ %3, %33 ], [ %56, %53 ]
%60 = phi i8* [ %42, %50 ], [ %42, %47 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %33 ], [ %57, %53 ]
%61 = icmp sgt i32 %59, 16
%62 = load i8*, i8** @localFilenameToC64.buf
br i1 %61, label %63, label %66
63: ; preds = %58
%64 = getelementptr inbounds i8, i8* %62, i64 14
store i8 35, i8* %64
%65 = getelementptr inbounds i8, i8* %62, i64 15
store i8 49, i8* %65
br label %66
66: ; preds = %58, %63
%67 = phi i32 [ 14, %63 ], [ %59, %58 ]
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %62, i64 %68
store i8 46, i8* %69
%70 = tail call i32 @strncpy(i8* %1, i8* %62, i32 %67)
%71 = getelementptr inbounds i8, i8* %1, i64 %68
store i8 46, i8* %71
%72 = add nsw i32 %67, 1
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %1, i64 %73
store i8 0, i8* %74
%75 = tail call i32 @strcat(i8* %1, i8* %60)
ret void
}