#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 */
char EOF;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
char *get_suffix(char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewinddir(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
char toupper(char);
int listdir(char *dir, char *type) {
  struct dirent *entry;
  DIR *work, *subdir;
  char buffer[512], name[512], *suffix, ch, *end;
  FILE *ret_file, *curr_file;
  work = opendir(dir);
  if (work == NULL) {
    perror("opendir\n");
    return 0;
  }
  ret_file = fopen("svg_media.h", "w");
  if (ret_file == NULL) {
    perror("Failed to open return file\n");
    return 0;
  }
  strncpy(buffer, dir, 512);
  int n = strlen(buffer);
  if (n > 0 && (buffer[n - 1] != '/'))
    buffer[n++] = '/';
  fprintf(ret_file, "#ifndef _SVG_MEDIA\n#define _SVG_MEDIA\n\n");
  fprintf(ret_file, "enum {\n");
  while ((entry = readdir(work))) {
    strncpy(buffer + n, entry->d_name, 512 - n);
    subdir = opendir(buffer);
    if (subdir != NULL)
      closedir(subdir);
    else {
      suffix = get_suffix(entry->d_name);
      if (strcmp(type, suffix) == 0) {
        curr_file = fopen(buffer, "r");
        if (curr_file) {
          strncpy(name, entry->d_name, 512);
          end = strstr(name, suffix);
          *(end - 1) = 0;
          end = name;
          while (*end = toupper(*end))
            end++;
          fprintf(ret_file, "    SVG_%s,\n", name);
          fclose(curr_file);
        }
      }
    }
  }
  fprintf(ret_file, "    SVG_MEDIA_SIZE\n} svg_list;\n\n");
  fprintf(ret_file, "char * svg_data[] = {\n");
  rewinddir(work);
  while ((entry = readdir(work))) {
    strncpy(buffer + n, entry->d_name, 512 - n);
    subdir = opendir(buffer);
    if (subdir != NULL)
      closedir(subdir);
    else {
      suffix = get_suffix(entry->d_name);
      if (strcmp(type, suffix) == 0) {
        curr_file = fopen(buffer, "r");
        if (curr_file) {
          strncpy(name, entry->d_name, 512);
          end = strstr(name, suffix);
          *(end - 1) = 0;
          end = name;
          while (*end = toupper(*end))
            end++;
          fprintf(ret_file, "\t[SVG_%s] = (char[]){\"", name);
          while ((ch = fgetc(curr_file)) != EOF) {
            if (ch == '\"')
              fprintf(ret_file, "\\\"");
            else if (ch == '\n')
              fprintf(ret_file, "\"\n\t\"");
            else
              fputc(ch, ret_file);
          }
          fprintf(ret_file, "\"},\n\n");
          fclose(curr_file);
        }
      }
    }
  }
  fprintf(ret_file, "};\n#endif");
  fclose(ret_file);
  closedir(work);
  return 1;
}


x86 assembly (clang, -O0):
<listdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1243 <listdir+0x43>
lea    0xdce(%rip),%rdi
call   1110 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1717 <listdir+0x517>
lea    0xdbf(%rip),%rdi
lea    0xdc4(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x450(%rbp)
cmpq   $0x0,-0x450(%rbp)
jne    1283 <listdir+0x83>
lea    0xda5(%rip),%rdi
call   1110 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1717 <listdir+0x517>
lea    -0x230(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
lea    -0x230(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x45c(%rbp)
cmpl   $0x0,-0x45c(%rbp)
jle    12ee <listdir+0xee>
mov    -0x45c(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x230(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
je     12ee <listdir+0xee>
mov    -0x45c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x45c(%rbp)
cltq
movb   $0x2f,-0x230(%rbp,%rax,1)
2f
mov    -0x450(%rbp),%rdi
lea    0xd37(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x450(%rbp),%rdi
lea    0xd4a(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   10f0 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     148e <listdir+0x28e>
lea    -0x230(%rbp),%rdi
movslq -0x45c(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    $0x200,%edx
sub    -0x45c(%rbp),%edx
call   1030 <strncpy@plt>
lea    -0x230(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1380 <listdir+0x180>
mov    -0x30(%rbp),%rdi
call   10b0 <closedir@plt>
jmp    1489 <listdir+0x289>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1080 <get_suffix@plt>
mov    %rax,-0x438(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x438(%rbp),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    1484 <listdir+0x284>
lea    -0x230(%rbp),%rdi
lea    0xca8(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x458(%rbp)
cmpq   $0x0,-0x458(%rbp)
je     147f <listdir+0x27f>
lea    -0x430(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
lea    -0x430(%rbp),%rdi
mov    -0x438(%rbp),%rsi
call   1120 <strstr@plt>
mov    %rax,-0x448(%rbp)
mov    -0x448(%rbp),%rax
movb   $0x0,-0x1(%rax)
lea    -0x430(%rbp),%rax
mov    %rax,-0x448(%rbp)
mov    -0x448(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
mov    -0x448(%rbp),%rcx
mov    %al,(%rcx)
cmp    $0x0,%al
je     1457 <listdir+0x257>
mov    -0x448(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x448(%rbp)
jmp    1420 <listdir+0x220>
mov    -0x450(%rbp),%rdi
lea    -0x430(%rbp),%rdx
lea    0xbf9(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x458(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1484 <listdir+0x284>
jmp    1489 <listdir+0x289>
jmp    1318 <listdir+0x118>
mov    -0x450(%rbp),%rdi
lea    0xbd6(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x450(%rbp),%rdi
lea    0xbe2(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   10a0 <rewinddir@plt>
mov    -0x28(%rbp),%rdi
call   10f0 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     16e6 <listdir+0x4e6>
lea    -0x230(%rbp),%rdi
movslq -0x45c(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    $0x200,%edx
sub    -0x45c(%rbp),%edx
call   1030 <strncpy@plt>
lea    -0x230(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1529 <listdir+0x329>
mov    -0x30(%rbp),%rdi
call   10b0 <closedir@plt>
jmp    16e1 <listdir+0x4e1>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1080 <get_suffix@plt>
mov    %rax,-0x438(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x438(%rbp),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    16dc <listdir+0x4dc>
lea    -0x230(%rbp),%rdi
lea    0xaff(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x458(%rbp)
cmpq   $0x0,-0x458(%rbp)
je     16d7 <listdir+0x4d7>
lea    -0x430(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
lea    -0x430(%rbp),%rdi
mov    -0x438(%rbp),%rsi
call   1120 <strstr@plt>
mov    %rax,-0x448(%rbp)
mov    -0x448(%rbp),%rax
movb   $0x0,-0x1(%rax)
lea    -0x430(%rbp),%rax
mov    %rax,-0x448(%rbp)
mov    -0x448(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
mov    -0x448(%rbp),%rcx
mov    %al,(%rcx)
cmp    $0x0,%al
je     1600 <listdir+0x400>
mov    -0x448(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x448(%rbp)
jmp    15c9 <listdir+0x3c9>
mov    -0x450(%rbp),%rdi
lea    -0x430(%rbp),%rdx
lea    0xa95(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x458(%rbp),%rdi
call   1090 <fgetc@plt>
mov    %al,-0x439(%rbp)
movsbl %al,%eax
mov    0x29b0(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     16b6 <listdir+0x4b6>
movsbl -0x439(%rbp),%eax
cmp    $0x22,%eax
jne    166d <listdir+0x46d>
mov    -0x450(%rbp),%rdi
lea    0xa60(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
jmp    16b1 <listdir+0x4b1>
movsbl -0x439(%rbp),%eax
cmp    $0xa,%eax
jne    1697 <listdir+0x497>
mov    -0x450(%rbp),%rdi
lea    0xa39(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
jmp    16ac <listdir+0x4ac>
mov    -0x439(%rbp),%al
mov    -0x450(%rbp),%rsi
movsbl %al,%edi
call   10c0 <fputc@plt>
jmp    16b1 <listdir+0x4b1>
jmp    161c <listdir+0x41c>
mov    -0x450(%rbp),%rdi
lea    0xa05(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x458(%rbp),%rdi
call   1050 <fclose@plt>
jmp    16dc <listdir+0x4dc>
jmp    16e1 <listdir+0x4e1>
jmp    14c1 <listdir+0x2c1>
mov    -0x450(%rbp),%rdi
lea    0x9db(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x450(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   10b0 <closedir@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listdir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rsi,0x10(%rsp)
mov    %rdi,%rbx
call   1060 <opendir@plt>
test   %rax,%rax
je     1605 <listdir+0x3f5>
mov    %rax,%r14
lea    0xdc8(%rip),%rdi
lea    0xdcd(%rip),%rsi
call   1100 <fopen@plt>
test   %rax,%rax
je     160e <listdir+0x3fe>
mov    %rax,%rbp
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
mov    %r15,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1290 <listdir+0x80>
lea    -0x1(%rbx),%eax
cmpb   $0x2f,0x20(%rsp,%rax,1)
je     1290 <listdir+0x80>
mov    %ebx,%eax
add    $0x1,%ebx
movb   $0x2f,0x20(%rsp,%rax,1)
lea    0xd9c(%rip),%rdi
mov    $0x27,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1120 <fwrite@plt>
lea    0xdab(%rip),%rdi
mov    $0x7,%esi
mov    $0x1,%edx
mov    %rbp,(%rsp)
mov    %rbp,%rcx
call   1120 <fwrite@plt>
mov    %r14,%r12
mov    %r14,%rdi
call   10f0 <readdir@plt>
mov    %rax,%r13
movslq %ebx,%rax
mov    %rax,0x8(%rsp)
test   %r13,%r13
je     13e2 <listdir+0x1d2>
mov    0x8(%rsp),%rax
lea    (%rsp,%rax,1),%r14
add    $0x20,%r14
mov    $0x200,%ebx
sub    %eax,%ebx
lea    0x20(%rsp),%rbp
jmp    131c <listdir+0x10c>
mov    %rax,%rdi
call   10b0 <closedir@plt>
mov    %r12,%rdi
call   10f0 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     13e2 <listdir+0x1d2>
mov    0x0(%r13),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1030 <strncpy@plt>
mov    %rbp,%rdi
call   1060 <opendir@plt>
test   %rax,%rax
jne    1300 <listdir+0xf0>
mov    0x0(%r13),%rdi
call   1080 <get_suffix@plt>
mov    %rax,%r15
mov    0x10(%rsp),%rdi
mov    %rax,%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
jne    1308 <listdir+0xf8>
mov    %rbp,%rdi
lea    0xd04(%rip),%rsi
call   1100 <fopen@plt>
test   %rax,%rax
je     1308 <listdir+0xf8>
mov    %rax,0x18(%rsp)
mov    0x0(%r13),%rsi
lea    0x220(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x200,%edx
call   1030 <strncpy@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1130 <strstr@plt>
movb   $0x0,-0x1(%rax)
cs nopw 0x0(%rax,%rax,1)
movsbl 0x0(%rbp),%edi
call   1040 <toupper@plt>
mov    %al,0x0(%rbp)
add    $0x1,%rbp
test   %al,%al
jne    13a0 <listdir+0x190>
mov    (%rsp),%rdi
lea    0xca6(%rip),%rsi
lea    0x220(%rsp),%rdx
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    0x18(%rsp),%rdi
call   1050 <fclose@plt>
lea    0x20(%rsp),%rbp
jmp    1308 <listdir+0xf8>
lea    0xc89(%rip),%rdi
mov    $0x20,%esi
mov    $0x1,%edx
mov    (%rsp),%rbx
mov    %rbx,%rcx
call   1120 <fwrite@plt>
lea    0xc8d(%rip),%rdi
mov    $0x16,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1120 <fwrite@plt>
mov    %r12,%r14
mov    %r12,%rdi
call   10a0 <rewinddir@plt>
mov    %r12,%rdi
call   10f0 <readdir@plt>
test   %rax,%rax
je     15c1 <listdir+0x3b1>
mov    %rax,%r13
mov    0x8(%rsp),%rax
lea    (%rsp,%rax,1),%r12
add    $0x20,%r12
mov    $0x200,%r15d
sub    %eax,%r15d
jmp    146c <listdir+0x25c>
nop
mov    %rax,%rdi
call   10b0 <closedir@plt>
mov    %r14,%rdi
call   10f0 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     15c1 <listdir+0x3b1>
mov    0x0(%r13),%rsi
mov    %r12,%rdi
mov    %r15d,%edx
call   1030 <strncpy@plt>
lea    0x20(%rsp),%rdi
call   1060 <opendir@plt>
test   %rax,%rax
jne    1450 <listdir+0x240>
mov    0x0(%r13),%rdi
call   1080 <get_suffix@plt>
mov    %rax,%rbp
mov    0x10(%rsp),%rdi
mov    %rax,%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
jne    1458 <listdir+0x248>
lea    0x20(%rsp),%rdi
lea    0xbaf(%rip),%rsi
call   1100 <fopen@plt>
test   %rax,%rax
je     1458 <listdir+0x248>
mov    %rax,%rbx
mov    0x0(%r13),%rsi
lea    0x220(%rsp),%r13
mov    %r13,%rdi
mov    $0x200,%edx
call   1030 <strncpy@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1130 <strstr@plt>
movb   $0x0,-0x1(%rax)
nopl   0x0(%rax)
movsbl 0x0(%r13),%edi
call   1040 <toupper@plt>
mov    %al,0x0(%r13)
add    $0x1,%r13
test   %al,%al
jne    14f0 <listdir+0x2e0>
mov    (%rsp),%rbp
mov    %rbp,%rdi
lea    0xb96(%rip),%rsi
lea    0x220(%rsp),%rdx
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    %rbx,%rdi
call   1090 <fgetc@plt>
mov    0x2ab6(%rip),%r13
jmp    1553 <listdir+0x343>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl %al,%edi
mov    %rbp,%rsi
call   10c0 <fputc@plt>
mov    %rbx,%rdi
call   1090 <fgetc@plt>
cmp    0x0(%r13),%al
je     159b <listdir+0x38b>
cmp    $0xa,%al
je     1580 <listdir+0x370>
cmp    $0x22,%al
jne    1540 <listdir+0x330>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xb4f(%rip),%rdi
jmp    1591 <listdir+0x381>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x4,%esi
mov    $0x1,%edx
lea    0xb33(%rip),%rdi
mov    %rbp,%rcx
call   1120 <fwrite@plt>
jmp    154b <listdir+0x33b>
mov    $0x5,%esi
mov    $0x1,%edx
lea    0xb1d(%rip),%rdi
mov    %rbp,%rcx
call   1120 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    1458 <listdir+0x248>
lea    0xb07(%rip),%rdi
mov    $0x9,%esi
mov    $0x1,%edx
mov    (%rsp),%rbx
mov    %rbx,%rcx
call   1120 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   10b0 <closedir@plt>
mov    $0x1,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x9f4(%rip),%rdi
jmp    1615 <listdir+0x405>
lea    0xa02(%rip),%rdi
call   1110 <perror@plt>
xor    %eax,%eax
jmp    15f3 <listdir+0x3e3>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [9 x i8] c"opendir\0A\00"
@.str.1 = [12 x i8] c"svg_media.h\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [28 x i8] c"Failed to open return file\0A\00"
@.str.4 = [40 x i8] c"#ifndef _SVG_MEDIA\0A#define _SVG_MEDIA\0A\0A\00"
@.str.5 = [8 x i8] c"enum {\0A\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [13 x i8] c" SVG_%s,\0A\00"
@.str.8 = [33 x i8] c" SVG_MEDIA_SIZE\0A} svg_list;\0A\0A\00"
@.str.9 = [23 x i8] c"char * svg_data[] = {\0A\00"
@.str.10 = [23 x i8] c"\09[SVG_%s] = (char[]){\22\00"
@EOF = global i8 0
@.str.11 = [3 x i8] c"\\\22\00"
@.str.12 = [5 x i8] c"\22\0A\09\22\00"
@.str.13 = [6 x i8] c"\22},\0A\0A\00"
@.str.14 = [10 x i8] c"};\0A#endif\00"
define i32 @listdir(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.dirent*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca [512 x i8]
%10 = alloca [512 x i8]
%11 = alloca i8*
%12 = alloca i8
%13 = alloca i8*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%17 = load i8*, i8** %4
%18 = call i32* @opendir(i8* %17)
store i32* %18, i32** %7
%19 = load i32*, i32** %7
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %231
23: ; preds = %2
%24 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %24, i32** %14
%25 = load i32*, i32** %14
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %231
29: ; preds = %23
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%31 = load i8*, i8** %4
%32 = call i32 @strncpy(i8* %30, i8* %31, i32 512)
%33 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
store i32 %34, i32* %16
%35 = load i32, i32* %16
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %50
37: ; preds = %29
%38 = load i32, i32* %16
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 47
br i1 %44, label %45, label %50
45: ; preds = %37
%46 = load i32, i32* %16
%47 = add nsw i32 %46, 1
store i32 %47, i32* %16
%48 = sext i32 %46 to i64
%49 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 %48
store i8 47, i8* %49
br label %50
50: ; preds = %45, %37, %29
%51 = load i32*, i32** %14
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
%53 = load i32*, i32** %14
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %55
55: ; preds = %120, %50
%56 = load i32*, i32** %7
%57 = call %struct.dirent* @readdir(i32* %56)
store %struct.dirent* %57, %struct.dirent** %6
%58 = icmp ne %struct.dirent* %57, null
br i1 %58, label %59, label %121
59: ; preds = %55
%60 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%61 = load i32, i32* %16
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = load %struct.dirent*, %struct.dirent** %6
%65 = getelementptr inbounds %struct.dirent, %struct.dirent* %64, i32 0, i32 0
%66 = load i8*, i8** %65
%67 = load i32, i32* %16
%68 = sub nsw i32 512, %67
%69 = call i32 @strncpy(i8* %63, i8* %66, i32 %68)
%70 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%71 = call i32* @opendir(i8* %70)
store i32* %71, i32** %8
%72 = load i32*, i32** %8
%73 = icmp ne i32* %72, null
br i1 %73, label %74, label %77
74: ; preds = %59
%75 = load i32*, i32** %8
%76 = call i32 @closedir(i32* %75)
br label %120
77: ; preds = %59
%78 = load %struct.dirent*, %struct.dirent** %6
%79 = getelementptr inbounds %struct.dirent, %struct.dirent* %78, i32 0, i32 0
%80 = load i8*, i8** %79
%81 = call i8* @get_suffix(i8* %80)
store i8* %81, i8** %11
%82 = load i8*, i8** %5
%83 = load i8*, i8** %11
%84 = call i64 @strcmp(i8* %82, i8* %83)
%85 = icmp eq i64 %84, 0
br i1 %85, label %86, label %119
86: ; preds = %77
%87 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%88 = call i32* @fopen(i8* %87, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %88, i32** %15
%89 = load i32*, i32** %15
%90 = icmp ne i32* %89, null
br i1 %90, label %91, label %118
91: ; preds = %86
%92 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%93 = load %struct.dirent*, %struct.dirent** %6
%94 = getelementptr inbounds %struct.dirent, %struct.dirent* %93, i32 0, i32 0
%95 = load i8*, i8** %94
%96 = call i32 @strncpy(i8* %92, i8* %95, i32 512)
%97 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%98 = load i8*, i8** %11
%99 = call i8* @strstr(i8* %97, i8* %98)
store i8* %99, i8** %13
%100 = load i8*, i8** %13
%101 = getelementptr inbounds i8, i8* %100, i64 -1
store i8 0, i8* %101
%102 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
store i8* %102, i8** %13
br label %103
103: ; preds = %109, %91
%104 = load i8*, i8** %13
%105 = load i8, i8* %104
%106 = call signext i8 @toupper(i8 signext %105)
%107 = load i8*, i8** %13
store i8 %106, i8* %107
%108 = icmp ne i8 %106, 0
br i1 %108, label %109, label %112
109: ; preds = %103
%110 = load i8*, i8** %13
%111 = getelementptr inbounds i8, i8* %110, i32 1
store i8* %111, i8** %13
br label %103
112: ; preds = %103
%113 = load i32*, i32** %14
%114 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%115 = call i32 (i32*, i8*, ...) @fprintf(i32* %113, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %114)
%116 = load i32*, i32** %15
%117 = call i32 @fclose(i32* %116)
br label %118
118: ; preds = %112, %86
br label %119
119: ; preds = %118, %77
br label %120
120: ; preds = %119, %74
br label %55
121: ; preds = %55
%122 = load i32*, i32** %14
%123 = call i32 (i32*, i8*, ...) @fprintf(i32* %122, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
%124 = load i32*, i32** %14
%125 = call i32 (i32*, i8*, ...) @fprintf(i32* %124, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%126 = load i32*, i32** %7
%127 = call i32 @rewinddir(i32* %126)
br label %128
128: ; preds = %223, %121
%129 = load i32*, i32** %7
%130 = call %struct.dirent* @readdir(i32* %129)
store %struct.dirent* %130, %struct.dirent** %6
%131 = icmp ne %struct.dirent* %130, null
br i1 %131, label %132, label %224
132: ; preds = %128
%133 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%134 = load i32, i32* %16
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds i8, i8* %133, i64 %135
%137 = load %struct.dirent*, %struct.dirent** %6
%138 = getelementptr inbounds %struct.dirent, %struct.dirent* %137, i32 0, i32 0
%139 = load i8*, i8** %138
%140 = load i32, i32* %16
%141 = sub nsw i32 512, %140
%142 = call i32 @strncpy(i8* %136, i8* %139, i32 %141)
%143 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%144 = call i32* @opendir(i8* %143)
store i32* %144, i32** %8
%145 = load i32*, i32** %8
%146 = icmp ne i32* %145, null
br i1 %146, label %147, label %150
147: ; preds = %132
%148 = load i32*, i32** %8
%149 = call i32 @closedir(i32* %148)
br label %223
150: ; preds = %132
%151 = load %struct.dirent*, %struct.dirent** %6
%152 = getelementptr inbounds %struct.dirent, %struct.dirent* %151, i32 0, i32 0
%153 = load i8*, i8** %152
%154 = call i8* @get_suffix(i8* %153)
store i8* %154, i8** %11
%155 = load i8*, i8** %5
%156 = load i8*, i8** %11
%157 = call i64 @strcmp(i8* %155, i8* %156)
%158 = icmp eq i64 %157, 0
br i1 %158, label %159, label %222
159: ; preds = %150
%160 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%161 = call i32* @fopen(i8* %160, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %161, i32** %15
%162 = load i32*, i32** %15
%163 = icmp ne i32* %162, null
br i1 %163, label %164, label %221
164: ; preds = %159
%165 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%166 = load %struct.dirent*, %struct.dirent** %6
%167 = getelementptr inbounds %struct.dirent, %struct.dirent* %166, i32 0, i32 0
%168 = load i8*, i8** %167
%169 = call i32 @strncpy(i8* %165, i8* %168, i32 512)
%170 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%171 = load i8*, i8** %11
%172 = call i8* @strstr(i8* %170, i8* %171)
store i8* %172, i8** %13
%173 = load i8*, i8** %13
%174 = getelementptr inbounds i8, i8* %173, i64 -1
store i8 0, i8* %174
%175 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
store i8* %175, i8** %13
br label %176
176: ; preds = %182, %164
%177 = load i8*, i8** %13
%178 = load i8, i8* %177
%179 = call signext i8 @toupper(i8 signext %178)
%180 = load i8*, i8** %13
store i8 %179, i8* %180
%181 = icmp ne i8 %179, 0
br i1 %181, label %182, label %185
182: ; preds = %176
%183 = load i8*, i8** %13
%184 = getelementptr inbounds i8, i8* %183, i32 1
store i8* %184, i8** %13
br label %176
185: ; preds = %176
%186 = load i32*, i32** %14
%187 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%188 = call i32 (i32*, i8*, ...) @fprintf(i32* %186, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i8* %187)
br label %189
189: ; preds = %215, %185
%190 = load i32*, i32** %15
%191 = call signext i8 @fgetc(i32* %190)
store i8 %191, i8* %12
%192 = sext i8 %191 to i32
%193 = load i8, i8* @EOF
%194 = sext i8 %193 to i32
%195 = icmp ne i32 %192, %194
br i1 %195, label %196, label %216
196: ; preds = %189
%197 = load i8, i8* %12
%198 = sext i8 %197 to i32
%199 = icmp eq i32 %198, 34
br i1 %199, label %200, label %203
200: ; preds = %196
%201 = load i32*, i32** %14
%202 = call i32 (i32*, i8*, ...) @fprintf(i32* %201, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
br label %215
203: ; preds = %196
%204 = load i8, i8* %12
%205 = sext i8 %204 to i32
%206 = icmp eq i32 %205, 10
br i1 %206, label %207, label %210
207: ; preds = %203
%208 = load i32*, i32** %14
%209 = call i32 (i32*, i8*, ...) @fprintf(i32* %208, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
br label %214
210: ; preds = %203
%211 = load i8, i8* %12
%212 = load i32*, i32** %14
%213 = call i32 @fputc(i8 signext %211, i32* %212)
br label %214
214: ; preds = %210, %207
br label %215
215: ; preds = %214, %200
br label %189
216: ; preds = %189
%217 = load i32*, i32** %14
%218 = call i32 (i32*, i8*, ...) @fprintf(i32* %217, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.13, i64 0, i64 0))
%219 = load i32*, i32** %15
%220 = call i32 @fclose(i32* %219)
br label %221
221: ; preds = %216, %159
br label %222
222: ; preds = %221, %150
br label %223
223: ; preds = %222, %147
br label %128
224: ; preds = %128
%225 = load i32*, i32** %14
%226 = call i32 (i32*, i8*, ...) @fprintf(i32* %225, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0))
%227 = load i32*, i32** %14
%228 = call i32 @fclose(i32* %227)
%229 = load i32*, i32** %7
%230 = call i32 @closedir(i32* %229)
store i32 1, i32* %3
br label %231
231: ; preds = %224, %27, %21
%232 = load i32, i32* %3
ret i32 %232
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [9 x i8] c"opendir\0A\00"
@.str.1 = [12 x i8] c"svg_media.h\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [28 x i8] c"Failed to open return file\0A\00"
@.str.4 = [40 x i8] c"#ifndef _SVG_MEDIA\0A#define _SVG_MEDIA\0A\0A\00"
@.str.5 = [8 x i8] c"enum {\0A\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [13 x i8] c" SVG_%s,\0A\00"
@.str.8 = [33 x i8] c" SVG_MEDIA_SIZE\0A} svg_list;\0A\0A\00"
@.str.9 = [23 x i8] c"char * svg_data[] = {\0A\00"
@.str.10 = [23 x i8] c"\09[SVG_%s] = (char[]){\22\00"
@EOF = global i8 0
@.str.11 = [3 x i8] c"\\\22\00"
@.str.12 = [5 x i8] c"\22\0A\09\22\00"
@.str.13 = [6 x i8] c"\22},\0A\0A\00"
@.str.14 = [10 x i8] c"};\0A#endif\00"
define i32 @listdir(i8* %0, i8* %1) {
%3 = alloca [512 x i8]
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = tail call i32* @opendir(i8* %0)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %139
11: ; preds = %2
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %139
16: ; preds = %11
%17 = call i32 @strncpy(i8* %5, i8* %0, i32 512)
%18 = call i32 @strlen(i8* %5)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = add nsw i32 %18, -1
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 47
br i1 %25, label %30, label %26
26: ; preds = %20
%27 = add nuw nsw i32 %18, 1
%28 = zext i32 %18 to i64
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %28
store i8 47, i8* %29
br label %30
30: ; preds = %26, %20, %16
%31 = phi i32 [ %27, %26 ], [ %18, %20 ], [ %18, %16 ]
%32 = call i64 @fwrite(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i64 39, i64 1, i32* %12)
%33 = call i64 @fwrite(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i64 7, i64 1, i32* %12)
%34 = call %struct.dirent* @readdir(i32* %7)
%35 = icmp eq %struct.dirent* %34, null
br i1 %35, label %74, label %36
36: ; preds = %30
%37 = sext i32 %31 to i64
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %37
%39 = sub nsw i32 512, %31
br label %40
40: ; preds = %36, %71
%41 = phi %struct.dirent* [ %34, %36 ], [ %72, %71 ]
%42 = getelementptr inbounds %struct.dirent, %struct.dirent* %41, i64 0, i32 0
%43 = load i8*, i8** %42
%44 = call i32 @strncpy(i8* %38, i8* %43, i32 %39)
%45 = call i32* @opendir(i8* %5)
%46 = icmp eq i32* %45, null
br i1 %46, label %49, label %47
47: ; preds = %40
%48 = call i32 @closedir(i32* %45)
br label %71
49: ; preds = %40
%50 = load i8*, i8** %42
%51 = call i8* @get_suffix(i8* %50)
%52 = call i64 @strcmp(i8* %1, i8* %51)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %71
54: ; preds = %49
%55 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%56 = icmp eq i32* %55, null
br i1 %56, label %71, label %57
57: ; preds = %54
%58 = load i8*, i8** %42
%59 = call i32 @strncpy(i8* %6, i8* %58, i32 512)
%60 = call i8* @strstr(i8* %6, i8* dereferenceable(1) %51)
%61 = getelementptr inbounds i8, i8* %60, i64 -1
store i8 0, i8* %61
br label %62
62: ; preds = %62, %57
%63 = phi i8* [ %6, %57 ], [ %67, %62 ]
%64 = load i8, i8* %63
%65 = call signext i8 @toupper(i8 signext %64)
store i8 %65, i8* %63
%66 = icmp eq i8 %65, 0
%67 = getelementptr inbounds i8, i8* %63, i64 1
br i1 %66, label %68, label %62
68: ; preds = %62
%69 = call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %6)
%70 = call i32 @fclose(i32* %55)
br label %71
71: ; preds = %49, %68, %54, %47
%72 = call %struct.dirent* @readdir(i32* %7)
%73 = icmp eq %struct.dirent* %72, null
br i1 %73, label %74, label %40
74: ; preds = %71, %30
%75 = call i64 @fwrite(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i64 32, i64 1, i32* %12)
%76 = call i64 @fwrite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i64 22, i64 1, i32* %12)
%77 = call i32 @rewinddir(i32* %7)
%78 = call %struct.dirent* @readdir(i32* %7)
%79 = icmp eq %struct.dirent* %78, null
br i1 %79, label %135, label %80
80: ; preds = %74
%81 = sext i32 %31 to i64
%82 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %81
%83 = sub nsw i32 512, %31
br label %84
84: ; preds = %80, %132
%85 = phi %struct.dirent* [ %78, %80 ], [ %133, %132 ]
%86 = getelementptr inbounds %struct.dirent, %struct.dirent* %85, i64 0, i32 0
%87 = load i8*, i8** %86
%88 = call i32 @strncpy(i8* %82, i8* %87, i32 %83)
%89 = call i32* @opendir(i8* %5)
%90 = icmp eq i32* %89, null
br i1 %90, label %93, label %91
91: ; preds = %84
%92 = call i32 @closedir(i32* %89)
br label %132
93: ; preds = %84
%94 = load i8*, i8** %86
%95 = call i8* @get_suffix(i8* %94)
%96 = call i64 @strcmp(i8* %1, i8* %95)
%97 = icmp eq i64 %96, 0
br i1 %97, label %98, label %132
98: ; preds = %93
%99 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%100 = icmp eq i32* %99, null
br i1 %100, label %132, label %101
101: ; preds = %98
%102 = load i8*, i8** %86
%103 = call i32 @strncpy(i8* %6, i8* %102, i32 512)
%104 = call i8* @strstr(i8* %6, i8* dereferenceable(1) %95)
%105 = getelementptr inbounds i8, i8* %104, i64 -1
store i8 0, i8* %105
br label %106
106: ; preds = %106, %101
%107 = phi i8* [ %6, %101 ], [ %111, %106 ]
%108 = load i8, i8* %107
%109 = call signext i8 @toupper(i8 signext %108)
store i8 %109, i8* %107
%110 = icmp eq i8 %109, 0
%111 = getelementptr inbounds i8, i8* %107, i64 1
br i1 %110, label %112, label %106
112: ; preds = %106
%113 = call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i8* %6)
%114 = call signext i8 @fgetc(i32* %99)
%115 = load i8, i8* @EOF
%116 = icmp eq i8 %114, %115
br i1 %116, label %129, label %117
117: ; preds = %112, %125
%118 = phi i8 [ %126, %125 ], [ %114, %112 ]
switch i8 %118, label %123 [
i8 34, label %119
i8 10, label %121
]
119: ; preds = %117
%120 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i64 2, i64 1, i32* %12)
br label %125
121: ; preds = %117
%122 = call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i64 4, i64 1, i32* %12)
br label %125
123: ; preds = %117
%124 = call i32 @fputc(i8 signext %118, i32* %12)
br label %125
125: ; preds = %121, %123, %119
%126 = call signext i8 @fgetc(i32* %99)
%127 = load i8, i8* @EOF
%128 = icmp eq i8 %126, %127
br i1 %128, label %129, label %117
129: ; preds = %125, %112
%130 = call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.13, i64 0, i64 0), i64 5, i64 1, i32* %12)
%131 = call i32 @fclose(i32* %99)
br label %132
132: ; preds = %93, %129, %98, %91
%133 = call %struct.dirent* @readdir(i32* %7)
%134 = icmp eq %struct.dirent* %133, null
br i1 %134, label %135, label %84
135: ; preds = %132, %74
%136 = call i64 @fwrite(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i64 9, i64 1, i32* %12)
%137 = call i32 @fclose(i32* %12)
%138 = call i32 @closedir(i32* %7)
br label %139
139: ; preds = %135, %14, %9
%140 = phi i32 [ 0, %9 ], [ 0, %14 ], [ 1, %135 ]
ret i32 %140
}