#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 IsResourceInFile(char *);
scalar_t__ isupper(char);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strrchr(char *, char);
char tolower(char);
int LoadResourceMap(char *filename) {
  char *spt, *pt, *dpt;
  char buffer[1400];
  if (IsResourceInFile(filename))
    return (1);
  strcpy(buffer, filename);
  spt = strrchr(buffer, '/');
  if (spt == NULL) {
    spt = buffer;
    pt = filename;
  } else {
    ++spt;
    pt = filename + (spt - buffer);
  }
  strcpy(spt, "resource.frk/");
  strcat(spt, pt);
  if (IsResourceInFile(buffer))
    return (1);
  spt = strrchr(buffer, '/') + 1;
  for (pt = spt; *pt; ++pt)
    if (isupper(*pt))
      *pt = tolower(*pt);
  dpt = strchr(spt, '.');
  if (dpt == NULL)
    dpt = spt + strlen(spt);
  if (dpt - spt > 8 || strlen(dpt) > 4) {
    char exten[8];
    strncpy(exten, dpt, 7);
    exten[4] = '\0';
    if (dpt - spt > 6)
      dpt = spt + 6;
    *dpt++ = '~';
    *dpt++ = '1';
    strcpy(dpt, exten);
  }
  return (IsResourceInFile(buffer));
}


x86 assembly (clang, -O0):
<LoadResourceMap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5b0,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <IsResourceInFile@plt>
cmp    $0x0,%eax
je     11bd <LoadResourceMap+0x2d>
movl   $0x1,-0x4(%rbp)
jmp    13c1 <LoadResourceMap+0x231>
lea    -0x5a0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x5a0(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1205 <LoadResourceMap+0x75>
lea    -0x5a0(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    122a <LoadResourceMap+0x9a>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
lea    -0x5a0(%rbp),%rdx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdcb(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10b0 <strcat@plt>
lea    -0x5a0(%rbp),%rdi
call   1080 <IsResourceInFile@plt>
cmp    $0x0,%eax
je     1268 <LoadResourceMap+0xd8>
movl   $0x1,-0x4(%rbp)
jmp    13c1 <LoadResourceMap+0x231>
lea    -0x5a0(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     12d6 <LoadResourceMap+0x146>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   10a0 <isupper@plt>
cmp    $0x0,%rax
je     12c0 <LoadResourceMap+0x130>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1090 <tolower@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
jmp    12c5 <LoadResourceMap+0x135>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1289 <LoadResourceMap+0xf9>
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    131a <LoadResourceMap+0x18a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x5b0(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x5b0(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x8,%rax
jg     1341 <LoadResourceMap+0x1b1>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x4,%eax
jle    13b2 <LoadResourceMap+0x222>
lea    -0x5a8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x7,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x5a4(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x6,%rax
jle    137e <LoadResourceMap+0x1ee>
mov    -0x18(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x7e,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x31,(%rax)
mov    -0x28(%rbp),%rdi
lea    -0x5a8(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x5a0(%rbp),%rdi
call   1080 <IsResourceInFile@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x5b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LoadResourceMap>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x590,%rsp
mov    %rdi,%r12
call   1080 <IsResourceInFile@plt>
mov    $0x1,%r15d
test   %eax,%eax
jne    12ea <LoadResourceMap+0x15a>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
lea    0x1(%rax),%rbx
mov    %rbx,%rbp
sub    %r14,%rbp
test   %rax,%rax
cmove  %r14,%rbx
cmove  %rax,%rbp
add    %r12,%rbp
lea    0xe0f(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10b0 <strcat@plt>
mov    %r14,%rdi
call   1080 <IsResourceInFile@plt>
test   %eax,%eax
jne    12ea <LoadResourceMap+0x15a>
lea    0x10(%rsp),%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rax,%r15
lea    0x1(%rax),%r14
mov    0x1(%rax),%al
test   %al,%al
je     1266 <LoadResourceMap+0xd6>
lea    0x2(%r15),%rbx
jmp    124b <LoadResourceMap+0xbb>
nopw   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1266 <LoadResourceMap+0xd6>
movsbl %al,%edi
call   10a0 <isupper@plt>
test   %rax,%rax
je     1240 <LoadResourceMap+0xb0>
movsbl -0x1(%rbx),%edi
call   1090 <tolower@plt>
mov    %al,-0x1(%rbx)
jmp    1240 <LoadResourceMap+0xb0>
mov    %r14,%rdi
mov    $0x2e,%esi
call   1060 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1289 <LoadResourceMap+0xf9>
mov    %r14,%rdi
call   1050 <strlen@plt>
movslq %eax,%rbx
add    %r14,%rbx
mov    %rbx,%rbp
sub    %r14,%rbp
cmp    $0x8,%rbp
jg     12a2 <LoadResourceMap+0x112>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x5,%eax
jl     12dd <LoadResourceMap+0x14d>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x7,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xc(%rsp)
add    $0x7,%r15
cmp    $0x7,%rbp
cmovl  %rbx,%r15
movw   $0x317e,(%r15)
add    $0x2,%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0x10(%rsp),%rdi
call   1080 <IsResourceInFile@plt>
mov    %eax,%r15d
mov    %r15d,%eax
add    $0x590,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [14 x i8] c"resource.frk/\00"
define i32 @LoadResourceMap(i8* %0) {
%2 = alloca [1400 x i8]
%3 = alloca [8 x i8]
%4 = getelementptr inbounds [1400 x i8], [1400 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @IsResourceInFile(i8* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %67
7: ; preds = %1
%8 = call i32 @strcpy(i8* %4, i8* %0)
%9 = call i8* @strrchr(i8* %4, i8 signext 47)
%10 = icmp eq i8* %9, null
%11 = getelementptr inbounds i8, i8* %9, i64 1
%12 = ptrtoint i8* %11 to i64
%13 = ptrtoint [1400 x i8]* %2 to i64
%14 = sub i64 %12, %13
%15 = select i1 %10, i8* %4, i8* %11
%16 = select i1 %10, i64 0, i64 %14
%17 = getelementptr i8, i8* %0, i64 %16
%18 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @strcat(i8* %15, i8* %17)
%20 = call i32 @IsResourceInFile(i8* %4)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %67
22: ; preds = %7
%23 = call i8* @strrchr(i8* %4, i8 signext 47)
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %39, label %27
27: ; preds = %22, %35
%28 = phi i8 [ %37, %35 ], [ %25, %22 ]
%29 = phi i8* [ %36, %35 ], [ %24, %22 ]
%30 = call i64 @isupper(i8 signext %28)
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %27
%33 = load i8, i8* %29
%34 = call signext i8 @tolower(i8 signext %33)
store i8 %34, i8* %29
br label %35
35: ; preds = %27, %32
%36 = getelementptr inbounds i8, i8* %29, i64 1
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 0
br i1 %38, label %39, label %27
39: ; preds = %35, %22
%40 = call i8* @strchr(i8* %24, i8 signext 46)
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %46
42: ; preds = %39
%43 = call i32 @strlen(i8* %24)
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %24, i64 %44
br label %46
46: ; preds = %42, %39
%47 = phi i8* [ %45, %42 ], [ %40, %39 ]
%48 = ptrtoint i8* %47 to i64
%49 = ptrtoint i8* %24 to i64
%50 = sub i64 %48, %49
%51 = icmp sgt i64 %50, 8
br i1 %51, label %55, label %52
52: ; preds = %46
%53 = call i32 @strlen(i8* %47)
%54 = icmp sgt i32 %53, 4
br i1 %54, label %55, label %65
55: ; preds = %52, %46
%56 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%57 = call i32 @strncpy(i8* %56, i8* %47, i32 7)
%58 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 4
store i8 0, i8* %58
%59 = icmp sgt i64 %50, 6
%60 = getelementptr inbounds i8, i8* %23, i64 7
%61 = select i1 %59, i8* %60, i8* %47
%62 = getelementptr inbounds i8, i8* %61, i64 1
store i8 126, i8* %61
%63 = getelementptr inbounds i8, i8* %61, i64 2
store i8 49, i8* %62
%64 = call i32 @strcpy(i8* %63, i8* %56)
br label %65
65: ; preds = %55, %52
%66 = call i32 @IsResourceInFile(i8* %4)
br label %67
67: ; preds = %7, %1, %65
%68 = phi i32 [ %66, %65 ], [ 1, %1 ], [ 1, %7 ]
ret i32 %68
}