#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 */
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
char *getFileExtension(char *);
char *getFilename(char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ removeExtension(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcasecmp(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int doConvert(char *dirName, char *fileNameOut) {
  char *ext;
  DIR *dirInput;
  struct dirent *dirEntry;
  FILE *fileOutput;
  if (!fileNameOut[0])
    strcpy(fileNameOut, "converted.res");
  dirInput = opendir(dirName);
  if (!dirInput) {
    printf("Couldn't open input directory %s\n", dirName);
    return 1;
  }
  fileOutput = fopen(fileNameOut, "w");
  if (!fileOutput) {
    closedir(dirInput);
    printf("Couldn't open output file %s\n", fileNameOut);
    return 1;
  }
  fprintf(fileOutput, "# Generated with rescomp\n");
  fprintf(fileOutput, "\n");
  while ((dirEntry = readdir(dirInput))) {
    char filename[2048];
    char *name;
    char *id;
    name = dirEntry->d_name;
    if (!strcmp(name, "."))
      continue;
    if (!strcmp(name, ".."))
      continue;
    sprintf(filename, "\"%s\"", name);
    ext = getFileExtension(name);
    id = getFilename(name);
    removeExtension(id);
    if (!strcasecmp(ext, "bmp")) {
      fprintf(fileOutput, "BITMAP %s %s\n", id, filename);
    } else if (!strcasecmp(ext, "wav")) {
      fprintf(fileOutput, "WAV %s %s 0 16000\n", id, filename);
    } else if (!strcasecmp(ext, "wavpcm")) {
      fprintf(fileOutput, "WAV %s %s 1\n", id, name);
    } else if (!strcasecmp(ext, "pcm")) {
      fprintf(fileOutput, "PCM %s %s 1\n", id, filename);
    } else if (!strcasecmp(ext, "tfd")) {
      fprintf(fileOutput, "TFM %s %s 1\n", id, filename);
    } else if (!strcasecmp(ext, "tfc")) {
      fprintf(fileOutput, "TFM %s %s 1\n", id, filename);
    } else if (!strcasecmp(ext, "mvs")) {
      fprintf(fileOutput, "BIN %s %s 256\n", id, filename);
    } else if (!strcasecmp(ext, "vgm")) {
      fprintf(fileOutput, "VGM %s %s\n", id, filename);
    } else if (!strcasecmp(ext, "eif")) {
      fprintf(fileOutput, "BIN %s %s 256\n", id, filename);
    } else if (!strcasecmp(ext, "esf")) {
      fprintf(fileOutput, "BIN %s %s 32768\n", id, filename);
    } else if (!strcasecmp(ext, "dat")) {
      fprintf(fileOutput, "BIN %s %s 256 256\n", id, filename);
    } else if (!strcasecmp(ext, "raw")) {
      fprintf(fileOutput, "BIN %s %s 256 256\n", id, filename);
    }
  }
  fprintf(fileOutput, "\n");
  closedir(dirInput);
  fclose(fileOutput);
  return 0;
}


x86 assembly (clang, -O0):
<doConvert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1210 <doConvert+0x30>
mov    -0x18(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1244 <doConvert+0x64>
mov    -0x10(%rbp),%rsi
lea    0xddb(%rip),%rdi
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16a6 <doConvert+0x4c6>
mov    -0x18(%rbp),%rdi
lea    0xed4(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1288 <doConvert+0xa8>
mov    -0x28(%rbp),%rdi
call   10a0 <closedir@plt>
mov    -0x18(%rbp),%rsi
lea    0xdb9(%rip),%rdi
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16a6 <doConvert+0x4c6>
mov    -0x38(%rbp),%rdi
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xdf2(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   10d0 <readdir@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     167b <doConvert+0x49b>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x848(%rbp)
mov    -0x848(%rbp),%rdi
lea    0xd8a(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%eax
jne    12f2 <doConvert+0x112>
jmp    12ac <doConvert+0xcc>
mov    -0x848(%rbp),%rdi
lea    0xd68(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%eax
jne    1313 <doConvert+0x133>
jmp    12ac <doConvert+0xcc>
lea    -0x840(%rbp),%rdi
mov    -0x848(%rbp),%rdx
lea    0xd43(%rip),%rsi
call   10f0 <sprintf@plt>
mov    -0x848(%rbp),%rdi
call   1070 <getFileExtension@plt>
mov    %rax,-0x20(%rbp)
mov    -0x848(%rbp),%rdi
call   1100 <getFilename@plt>
mov    %rax,-0x850(%rbp)
mov    -0x850(%rbp),%rdi
call   1090 <removeExtension@plt>
mov    -0x20(%rbp),%rdi
lea    0xd09(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    139a <doConvert+0x1ba>
mov    -0x38(%rbp),%rdi
mov    -0x850(%rbp),%rdx
lea    -0x840(%rbp),%rcx
lea    0xce6(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
jmp    1676 <doConvert+0x496>
mov    -0x20(%rbp),%rdi
lea    0xcdd(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    13d8 <doConvert+0x1f8>
mov    -0x38(%rbp),%rdi
mov    -0x850(%rbp),%rdx
lea    -0x840(%rbp),%rcx
lea    0xcba(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
jmp    1671 <doConvert+0x491>
mov    -0x20(%rbp),%rdi
lea    0xcb6(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1416 <doConvert+0x236>
mov    -0x38(%rbp),%rdi
mov    -0x850(%rbp),%rdx
mov    -0x848(%rbp),%rcx
lea    0xc96(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
jmp    166c <doConvert+0x48c>
mov    -0x20(%rbp),%rdi
lea    0xc7b(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1454 <doConvert+0x274>
mov    -0x38(%rbp),%rdi
mov    -0x850(%rbp),%rdx
lea    -0x840(%rbp),%rcx
lea    0xc65(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
jmp    1667 <doConvert+0x487>
mov    -0x20(%rbp),%rdi
lea    0xc5b(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1492 <doConvert+0x2b2>
mov    -0x38(%rbp),%rdi
mov    -0x850(%rbp),%rdx
lea    -0x840(%rbp),%rcx
lea    0xc38(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
jmp    1662 <doConvert+0x482>
mov    -0x20(%rbp),%rdi
lea    0xc2e(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    14d0 <doConvert+0x2f0>
mov    -0x38(%rbp),%rdi
mov    -0x850(%rbp),%rdx
lea    -0x840(%rbp),%rcx
lea    0xbfa(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
jmp    165d <doConvert+0x47d>
mov    -0x20(%rbp),%rdi
lea    0xbf4(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    150e <doConvert+0x32e>
mov    -0x38(%rbp),%rdi
mov    -0x850(%rbp),%rdx
lea    -0x840(%rbp),%rcx
lea    0xbd1(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
jmp    1658 <doConvert+0x478>
mov    -0x20(%rbp),%rdi
lea    0xbc9(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    154c <doConvert+0x36c>
mov    -0x38(%rbp),%rdi
mov    -0x850(%rbp),%rdx
lea    -0x840(%rbp),%rcx
lea    0xba6(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
jmp    1653 <doConvert+0x473>
mov    -0x20(%rbp),%rdi
lea    0xb9a(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    158a <doConvert+0x3aa>
mov    -0x38(%rbp),%rdi
mov    -0x850(%rbp),%rdx
lea    -0x840(%rbp),%rcx
lea    0xb55(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
jmp    164e <doConvert+0x46e>
mov    -0x20(%rbp),%rdi
lea    0xb60(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    15c8 <doConvert+0x3e8>
mov    -0x38(%rbp),%rdi
mov    -0x850(%rbp),%rdx
lea    -0x840(%rbp),%rcx
lea    0xb3d(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
jmp    1649 <doConvert+0x469>
mov    -0x20(%rbp),%rdi
lea    0xb37(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1606 <doConvert+0x426>
mov    -0x38(%rbp),%rdi
mov    -0x850(%rbp),%rdx
lea    -0x840(%rbp),%rcx
lea    0xb14(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
jmp    1644 <doConvert+0x464>
mov    -0x20(%rbp),%rdi
lea    0xb10(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    163f <doConvert+0x45f>
mov    -0x38(%rbp),%rdi
mov    -0x850(%rbp),%rdx
lea    -0x840(%rbp),%rcx
lea    0xad6(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
jmp    1644 <doConvert+0x464>
jmp    1649 <doConvert+0x469>
jmp    164e <doConvert+0x46e>
jmp    1653 <doConvert+0x473>
jmp    1658 <doConvert+0x478>
jmp    165d <doConvert+0x47d>
jmp    1662 <doConvert+0x482>
jmp    1667 <doConvert+0x487>
jmp    166c <doConvert+0x48c>
jmp    1671 <doConvert+0x491>
jmp    1676 <doConvert+0x496>
jmp    12ac <doConvert+0xcc>
mov    -0x38(%rbp),%rdi
lea    0xa11(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   10a0 <closedir@plt>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doConvert>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rsi,%rbp
mov    %rdi,%rbx
cmpb   $0x0,(%rsi)
jne    122b <doConvert+0x2b>
lea    0xddd(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <opendir@plt>
test   %rax,%rax
je     1509 <doConvert+0x309>
mov    %rax,%r15
lea    0xedd(%rip),%rsi
mov    %rbp,%rdi
call   10f0 <fopen@plt>
test   %rax,%rax
je     1515 <doConvert+0x315>
mov    %rax,%rbx
lea    0xded(%rip),%rdi
mov    $0x19,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1110 <fwrite@plt>
mov    $0xa,%edi
mov    %rbx,0x8(%rsp)
mov    %rbx,%rsi
call   10b0 <fputc@plt>
mov    %r15,%rdi
call   10e0 <readdir@plt>
test   %rax,%rax
je     14e3 <doConvert+0x2e3>
lea    0xdcc(%rip),%r14
lea    0x10(%rsp),%r12
jmp    12d1 <doConvert+0xd1>
mov    0x8(%rsp),%rdi
lea    0xdc4(%rip),%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    %rbx,%r12
mov    %r15,%rdi
call   10e0 <readdir@plt>
test   %rax,%rax
je     14e3 <doConvert+0x2e3>
mov    (%rax),%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
call   10c0 <strcmp@plt>
test   %eax,%eax
je     12c0 <doConvert+0xc0>
mov    %rbp,%rdi
lea    0xd7b(%rip),%rsi
call   10c0 <strcmp@plt>
test   %eax,%eax
je     12c0 <doConvert+0xc0>
mov    %r12,%rdi
lea    0xd6b(%rip),%rsi
mov    %rbp,%rdx
call   1100 <sprintf@plt>
mov    %rbp,%rdi
call   1070 <getFileExtension@plt>
mov    %r12,%rbx
mov    %rax,%r12
mov    %rbp,%rdi
call   1120 <getFilename@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1090 <removeExtension@plt>
mov    %r12,%rdi
lea    0xd3d(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     12a4 <doConvert+0xa4>
mov    %r12,%rdi
lea    0xd38(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     1457 <doConvert+0x257>
mov    %r12,%rdi
lea    0xd38(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     1465 <doConvert+0x265>
mov    %r12,%rdi
lea    0xd24(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     148a <doConvert+0x28a>
mov    %r12,%rdi
lea    0xd2b(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     147c <doConvert+0x27c>
mov    %r12,%rdi
lea    0xd25(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     147c <doConvert+0x27c>
mov    %r12,%rdi
lea    0xd12(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     1498 <doConvert+0x298>
mov    %r12,%rdi
lea    0xd0e(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     14a6 <doConvert+0x2a6>
mov    %r12,%rdi
lea    0xd06(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     1498 <doConvert+0x298>
mov    %r12,%rdi
lea    0xcf3(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     14b4 <doConvert+0x2b4>
mov    %r12,%rdi
lea    0xcf1(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     14c2 <doConvert+0x2c2>
mov    %r12,%rdi
lea    0xcf1(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
mov    %rbx,%r12
jne    12c0 <doConvert+0xc0>
mov    0x8(%rsp),%rdi
lea    0xcc2(%rip),%rsi
mov    %r13,%rdx
mov    %r12,%rcx
jmp    14d7 <doConvert+0x2d7>
mov    0x8(%rsp),%rdi
lea    0xc23(%rip),%rsi
jmp    14ce <doConvert+0x2ce>
mov    0x8(%rsp),%rdi
lea    0xc2f(%rip),%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
jmp    12b6 <doConvert+0xb6>
mov    0x8(%rsp),%rdi
lea    0xc36(%rip),%rsi
jmp    14ce <doConvert+0x2ce>
mov    0x8(%rsp),%rdi
lea    0xc17(%rip),%rsi
jmp    14ce <doConvert+0x2ce>
mov    0x8(%rsp),%rdi
lea    0xc2f(%rip),%rsi
jmp    14ce <doConvert+0x2ce>
mov    0x8(%rsp),%rdi
lea    0xc34(%rip),%rsi
jmp    14ce <doConvert+0x2ce>
mov    0x8(%rsp),%rdi
lea    0xc39(%rip),%rsi
jmp    14ce <doConvert+0x2ce>
mov    0x8(%rsp),%rdi
lea    0xc40(%rip),%rsi
mov    %r13,%rdx
mov    %rbx,%r12
mov    %rbx,%rcx
xor    %eax,%eax
call   10d0 <fprintf@plt>
jmp    12c0 <doConvert+0xc0>
mov    $0xa,%edi
mov    0x8(%rsp),%rbx
mov    %rbx,%rsi
call   10b0 <fputc@plt>
mov    %r15,%rdi
call   10a0 <closedir@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    1531 <doConvert+0x331>
lea    0xafe(%rip),%rdi
mov    %rbx,%rsi
jmp    1527 <doConvert+0x327>
mov    %r15,%rdi
call   10a0 <closedir@plt>
lea    0xb0c(%rip),%rdi
mov    %rbp,%rsi
call   1080 <printf@plt>
mov    $0x1,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [14 x i8] c"converted.res\00"
@.str.1 = [34 x i8] c"Couldn't open input directory %s\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [30 x i8] c"Couldn't open output file %s\0A\00"
@.str.4 = [26 x i8] c"# Generated with rescomp\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [2 x i8] c".\00"
@.str.7 = [3 x i8] c"..\00"
@.str.8 = [5 x i8] c"\22%s\22\00"
@.str.9 = [4 x i8] c"bmp\00"
@.str.10 = [14 x i8] c"BITMAP %s %s\0A\00"
@.str.11 = [4 x i8] c"wav\00"
@.str.12 = [19 x i8] c"WAV %s %s 0 16000\0A\00"
@.str.13 = [7 x i8] c"wavpcm\00"
@.str.14 = [13 x i8] c"WAV %s %s 1\0A\00"
@.str.15 = [4 x i8] c"pcm\00"
@.str.16 = [13 x i8] c"PCM %s %s 1\0A\00"
@.str.17 = [4 x i8] c"tfd\00"
@.str.18 = [13 x i8] c"TFM %s %s 1\0A\00"
@.str.19 = [4 x i8] c"tfc\00"
@.str.20 = [4 x i8] c"mvs\00"
@.str.21 = [15 x i8] c"BIN %s %s 256\0A\00"
@.str.22 = [4 x i8] c"vgm\00"
@.str.23 = [11 x i8] c"VGM %s %s\0A\00"
@.str.24 = [4 x i8] c"eif\00"
@.str.25 = [4 x i8] c"esf\00"
@.str.26 = [17 x i8] c"BIN %s %s 32768\0A\00"
@.str.27 = [4 x i8] c"dat\00"
@.str.28 = [19 x i8] c"BIN %s %s 256 256\0A\00"
@.str.29 = [4 x i8] c"raw\00"
define i32 @doConvert(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca %struct.dirent*
%9 = alloca i32*
%10 = alloca [2048 x i8]
%11 = alloca i8*
%12 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %2
%18 = load i8*, i8** %5
%19 = call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %17, %2
%21 = load i8*, i8** %4
%22 = call i32* @opendir(i8* %21)
store i32* %22, i32** %7
%23 = load i32*, i32** %7
%24 = icmp ne i32* %23, null
br i1 %24, label %28, label %25
25: ; preds = %20
%26 = load i8*, i8** %4
%27 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %26)
store i32 1, i32* %3
br label %196
28: ; preds = %20
%29 = load i8*, i8** %5
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %30, i32** %9
%31 = load i32*, i32** %9
%32 = icmp ne i32* %31, null
br i1 %32, label %38, label %33
33: ; preds = %28
%34 = load i32*, i32** %7
%35 = call i32 @closedir(i32* %34)
%36 = load i8*, i8** %5
%37 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %36)
store i32 1, i32* %3
br label %196
38: ; preds = %28
%39 = load i32*, i32** %9
%40 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%41 = load i32*, i32** %9
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %43
43: ; preds = %188, %59, %54, %38
%44 = load i32*, i32** %7
%45 = call %struct.dirent* @readdir(i32* %44)
store %struct.dirent* %45, %struct.dirent** %8
%46 = icmp ne %struct.dirent* %45, null
br i1 %46, label %47, label %189
47: ; preds = %43
%48 = load %struct.dirent*, %struct.dirent** %8
%49 = getelementptr inbounds %struct.dirent, %struct.dirent* %48, i32 0, i32 0
%50 = load i8*, i8** %49
store i8* %50, i8** %11
%51 = load i8*, i8** %11
%52 = call i32 @strcmp(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%53 = icmp ne i32 %52, 0
br i1 %53, label %55, label %54
54: ; preds = %47
br label %43
55: ; preds = %47
%56 = load i8*, i8** %11
%57 = call i32 @strcmp(i8* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%58 = icmp ne i32 %57, 0
br i1 %58, label %60, label %59
59: ; preds = %55
br label %43
60: ; preds = %55
%61 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%62 = load i8*, i8** %11
%63 = call i32 @sprintf(i8* %61, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* %62)
%64 = load i8*, i8** %11
%65 = call i8* @getFileExtension(i8* %64)
store i8* %65, i8** %6
%66 = load i8*, i8** %11
%67 = call i8* @getFilename(i8* %66)
store i8* %67, i8** %12
%68 = load i8*, i8** %12
%69 = call i32 @removeExtension(i8* %68)
%70 = load i8*, i8** %6
%71 = call i32 @strcasecmp(i8* %70, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%72 = icmp ne i32 %71, 0
br i1 %72, label %78, label %73
73: ; preds = %60
%74 = load i32*, i32** %9
%75 = load i8*, i8** %12
%76 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%77 = call i32 (i32*, i8*, ...) @fprintf(i32* %74, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i8* %75, i8* %76)
br label %188
78: ; preds = %60
%79 = load i8*, i8** %6
%80 = call i32 @strcasecmp(i8* %79, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0))
%81 = icmp ne i32 %80, 0
br i1 %81, label %87, label %82
82: ; preds = %78
%83 = load i32*, i32** %9
%84 = load i8*, i8** %12
%85 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%86 = call i32 (i32*, i8*, ...) @fprintf(i32* %83, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0), i8* %84, i8* %85)
br label %187
87: ; preds = %78
%88 = load i8*, i8** %6
%89 = call i32 @strcasecmp(i8* %88, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0))
%90 = icmp ne i32 %89, 0
br i1 %90, label %96, label %91
91: ; preds = %87
%92 = load i32*, i32** %9
%93 = load i8*, i8** %12
%94 = load i8*, i8** %11
%95 = call i32 (i32*, i8*, ...) @fprintf(i32* %92, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i64 0, i64 0), i8* %93, i8* %94)
br label %186
96: ; preds = %87
%97 = load i8*, i8** %6
%98 = call i32 @strcasecmp(i8* %97, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0))
%99 = icmp ne i32 %98, 0
br i1 %99, label %105, label %100
100: ; preds = %96
%101 = load i32*, i32** %9
%102 = load i8*, i8** %12
%103 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%104 = call i32 (i32*, i8*, ...) @fprintf(i32* %101, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.16, i64 0, i64 0), i8* %102, i8* %103)
br label %185
105: ; preds = %96
%106 = load i8*, i8** %6
%107 = call i32 @strcasecmp(i8* %106, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.17, i64 0, i64 0))
%108 = icmp ne i32 %107, 0
br i1 %108, label %114, label %109
109: ; preds = %105
%110 = load i32*, i32** %9
%111 = load i8*, i8** %12
%112 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%113 = call i32 (i32*, i8*, ...) @fprintf(i32* %110, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.18, i64 0, i64 0), i8* %111, i8* %112)
br label %184
114: ; preds = %105
%115 = load i8*, i8** %6
%116 = call i32 @strcasecmp(i8* %115, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.19, i64 0, i64 0))
%117 = icmp ne i32 %116, 0
br i1 %117, label %123, label %118
118: ; preds = %114
%119 = load i32*, i32** %9
%120 = load i8*, i8** %12
%121 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%122 = call i32 (i32*, i8*, ...) @fprintf(i32* %119, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.18, i64 0, i64 0), i8* %120, i8* %121)
br label %183
123: ; preds = %114
%124 = load i8*, i8** %6
%125 = call i32 @strcasecmp(i8* %124, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.20, i64 0, i64 0))
%126 = icmp ne i32 %125, 0
br i1 %126, label %132, label %127
127: ; preds = %123
%128 = load i32*, i32** %9
%129 = load i8*, i8** %12
%130 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%131 = call i32 (i32*, i8*, ...) @fprintf(i32* %128, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.21, i64 0, i64 0), i8* %129, i8* %130)
br label %182
132: ; preds = %123
%133 = load i8*, i8** %6
%134 = call i32 @strcasecmp(i8* %133, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.22, i64 0, i64 0))
%135 = icmp ne i32 %134, 0
br i1 %135, label %141, label %136
136: ; preds = %132
%137 = load i32*, i32** %9
%138 = load i8*, i8** %12
%139 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%140 = call i32 (i32*, i8*, ...) @fprintf(i32* %137, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.23, i64 0, i64 0), i8* %138, i8* %139)
br label %181
141: ; preds = %132
%142 = load i8*, i8** %6
%143 = call i32 @strcasecmp(i8* %142, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.24, i64 0, i64 0))
%144 = icmp ne i32 %143, 0
br i1 %144, label %150, label %145
145: ; preds = %141
%146 = load i32*, i32** %9
%147 = load i8*, i8** %12
%148 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%149 = call i32 (i32*, i8*, ...) @fprintf(i32* %146, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.21, i64 0, i64 0), i8* %147, i8* %148)
br label %180
150: ; preds = %141
%151 = load i8*, i8** %6
%152 = call i32 @strcasecmp(i8* %151, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.25, i64 0, i64 0))
%153 = icmp ne i32 %152, 0
br i1 %153, label %159, label %154
154: ; preds = %150
%155 = load i32*, i32** %9
%156 = load i8*, i8** %12
%157 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%158 = call i32 (i32*, i8*, ...) @fprintf(i32* %155, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.26, i64 0, i64 0), i8* %156, i8* %157)
br label %179
159: ; preds = %150
%160 = load i8*, i8** %6
%161 = call i32 @strcasecmp(i8* %160, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.27, i64 0, i64 0))
%162 = icmp ne i32 %161, 0
br i1 %162, label %168, label %163
163: ; preds = %159
%164 = load i32*, i32** %9
%165 = load i8*, i8** %12
%166 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%167 = call i32 (i32*, i8*, ...) @fprintf(i32* %164, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.28, i64 0, i64 0), i8* %165, i8* %166)
br label %178
168: ; preds = %159
%169 = load i8*, i8** %6
%170 = call i32 @strcasecmp(i8* %169, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.29, i64 0, i64 0))
%171 = icmp ne i32 %170, 0
br i1 %171, label %177, label %172
172: ; preds = %168
%173 = load i32*, i32** %9
%174 = load i8*, i8** %12
%175 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%176 = call i32 (i32*, i8*, ...) @fprintf(i32* %173, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.28, i64 0, i64 0), i8* %174, i8* %175)
br label %177
177: ; preds = %172, %168
br label %178
178: ; preds = %177, %163
br label %179
179: ; preds = %178, %154
br label %180
180: ; preds = %179, %145
br label %181
181: ; preds = %180, %136
br label %182
182: ; preds = %181, %127
br label %183
183: ; preds = %182, %118
br label %184
184: ; preds = %183, %109
br label %185
185: ; preds = %184, %100
br label %186
186: ; preds = %185, %91
br label %187
187: ; preds = %186, %82
br label %188
188: ; preds = %187, %73
br label %43
189: ; preds = %43
%190 = load i32*, i32** %9
%191 = call i32 (i32*, i8*, ...) @fprintf(i32* %190, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%192 = load i32*, i32** %7
%193 = call i32 @closedir(i32* %192)
%194 = load i32*, i32** %9
%195 = call i32 @fclose(i32* %194)
store i32 0, i32* %3
br label %196
196: ; preds = %189, %33, %25
%197 = load i32, i32* %3
ret i32 %197
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [14 x i8] c"converted.res\00"
@.str.1 = [34 x i8] c"Couldn't open input directory %s\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [30 x i8] c"Couldn't open output file %s\0A\00"
@.str.4 = [26 x i8] c"# Generated with rescomp\0A\00"
@.str.6 = [2 x i8] c".\00"
@.str.7 = [3 x i8] c"..\00"
@.str.8 = [5 x i8] c"\22%s\22\00"
@.str.9 = [4 x i8] c"bmp\00"
@.str.10 = [14 x i8] c"BITMAP %s %s\0A\00"
@.str.11 = [4 x i8] c"wav\00"
@.str.12 = [19 x i8] c"WAV %s %s 0 16000\0A\00"
@.str.13 = [7 x i8] c"wavpcm\00"
@.str.14 = [13 x i8] c"WAV %s %s 1\0A\00"
@.str.15 = [4 x i8] c"pcm\00"
@.str.16 = [13 x i8] c"PCM %s %s 1\0A\00"
@.str.17 = [4 x i8] c"tfd\00"
@.str.18 = [13 x i8] c"TFM %s %s 1\0A\00"
@.str.19 = [4 x i8] c"tfc\00"
@.str.20 = [4 x i8] c"mvs\00"
@.str.21 = [15 x i8] c"BIN %s %s 256\0A\00"
@.str.22 = [4 x i8] c"vgm\00"
@.str.23 = [11 x i8] c"VGM %s %s\0A\00"
@.str.24 = [4 x i8] c"eif\00"
@.str.25 = [4 x i8] c"esf\00"
@.str.26 = [17 x i8] c"BIN %s %s 32768\0A\00"
@.str.27 = [4 x i8] c"dat\00"
@.str.28 = [19 x i8] c"BIN %s %s 256 256\0A\00"
@.str.29 = [4 x i8] c"raw\00"
define i32 @doConvert(i8* %0, i8* %1) {
%3 = alloca [2048 x i8]
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = tail call i32* @opendir(i8* %0)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %106
13: ; preds = %8
%14 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = tail call i32 @closedir(i32* %9)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %1)
br label %106
19: ; preds = %13
%20 = tail call i64 @fwrite(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i64 25, i64 1, i32* %14)
%21 = tail call i32 @fputc(i32 10, i32* %14)
%22 = call %struct.dirent* @readdir(i32* %9)
%23 = icmp eq %struct.dirent* %22, null
br i1 %23, label %102, label %24
24: ; preds = %19
%25 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
br label %26
26: ; preds = %24, %99
%27 = phi %struct.dirent* [ %22, %24 ], [ %100, %99 ]
%28 = getelementptr inbounds %struct.dirent, %struct.dirent* %27, i64 0, i32 0
%29 = load i8*, i8** %28
%30 = call i32 @strcmp(i8* dereferenceable(1) %29, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%31 = icmp eq i32 %30, 0
br i1 %31, label %99, label %32
32: ; preds = %26
%33 = call i32 @strcmp(i8* dereferenceable(1) %29, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%34 = icmp eq i32 %33, 0
br i1 %34, label %99, label %35
35: ; preds = %32
%36 = call i32 @sprintf(i8* %25, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* %29)
%37 = call i8* @getFileExtension(i8* %29)
%38 = call i8* @getFilename(i8* %29)
%39 = call i32 @removeExtension(i8* %38)
%40 = call i32 @strcasecmp(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %35
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i8* %38, i8* %25)
br label %99
44: ; preds = %35
%45 = call i32 @strcasecmp(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0))
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0), i8* %38, i8* %25)
br label %99
49: ; preds = %44
%50 = call i32 @strcasecmp(i8* %37, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0))
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %49
%53 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i64 0, i64 0), i8* %38, i8* %29)
br label %99
54: ; preds = %49
%55 = call i32 @strcasecmp(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0))
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %54
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.16, i64 0, i64 0), i8* %38, i8* %25)
br label %99
59: ; preds = %54
%60 = call i32 @strcasecmp(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.17, i64 0, i64 0))
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %59
%63 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.18, i64 0, i64 0), i8* %38, i8* %25)
br label %99
64: ; preds = %59
%65 = call i32 @strcasecmp(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.19, i64 0, i64 0))
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %64
%68 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.18, i64 0, i64 0), i8* %38, i8* %25)
br label %99
69: ; preds = %64
%70 = call i32 @strcasecmp(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.20, i64 0, i64 0))
%71 = icmp eq i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %69
%73 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.21, i64 0, i64 0), i8* %38, i8* %25)
br label %99
74: ; preds = %69
%75 = call i32 @strcasecmp(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.22, i64 0, i64 0))
%76 = icmp eq i32 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %74
%78 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.23, i64 0, i64 0), i8* %38, i8* %25)
br label %99
79: ; preds = %74
%80 = call i32 @strcasecmp(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.24, i64 0, i64 0))
%81 = icmp eq i32 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %79
%83 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.21, i64 0, i64 0), i8* %38, i8* %25)
br label %99
84: ; preds = %79
%85 = call i32 @strcasecmp(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.25, i64 0, i64 0))
%86 = icmp eq i32 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %84
%88 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.26, i64 0, i64 0), i8* %38, i8* %25)
br label %99
89: ; preds = %84
%90 = call i32 @strcasecmp(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.27, i64 0, i64 0))
%91 = icmp eq i32 %90, 0
br i1 %91, label %92, label %94
92: ; preds = %89
%93 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.28, i64 0, i64 0), i8* %38, i8* %25)
br label %99
94: ; preds = %89
%95 = call i32 @strcasecmp(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.29, i64 0, i64 0))
%96 = icmp eq i32 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %94
%98 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.28, i64 0, i64 0), i8* %38, i8* %25)
br label %99
99: ; preds = %42, %52, %62, %72, %82, %92, %97, %94, %87, %77, %67, %57, %47, %32, %26
%100 = call %struct.dirent* @readdir(i32* %9)
%101 = icmp eq %struct.dirent* %100, null
br i1 %101, label %102, label %26
102: ; preds = %99, %19
%103 = call i32 @fputc(i32 10, i32* %14)
%104 = call i32 @closedir(i32* %9)
%105 = call i32 @fclose(i32* %14)
br label %106
106: ; preds = %102, %16, %11
%107 = phi i32 [ 0, %102 ], [ 1, %16 ], [ 1, %11 ]
ret i32 %107
}