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

/* Variables and functions */
int DT_DIR;
int DT_LNK;
int /*<<< orphan*/ EXIT_FAILURE;
int PATH_MAX;
scalar_t__ closedir(int /*<<< orphan*/ *);
scalar_t__ ends_with(char const *, char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int snprintf(char *, int, char *, char const *, char const *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char const *, char *);
char *strerror(int /*<<< orphan*/);
void list_dir(const char *dir_name) {
  DIR *d;
  d = opendir(dir_name);
  if (!d) {
    fprintf(stderr, "Cannot open directory '%s': %s\n", dir_name,
            strerror(errno));
    return;
  }
  while (1) {
    struct dirent *entry;
    const char *d_name;
    entry = readdir(d);
    if (!entry) {
      break;
    }
    d_name = entry->d_name;
    char filepath[4096];
    sprintf(filepath, "%s/%s", dir_name, d_name);
    if (!(entry->d_type & DT_DIR) && strcmp(d_name, "..") != 0 &&
        strcmp(d_name, ".") != 0) {
      if (ends_with(d_name, ".tbi") || ends_with(d_name, ".bigwig") ||
          ends_with(d_name, ".bw") || ends_with(d_name, ".bai")) {
        char filename[300];
        sprintf(filename, "%s/%s", dir_name, d_name);
        struct stat st;
        stat(filename, &st);
        if (st.st_size > 0)
          printf("%s\n", filename);
      }
    }
    if (entry->d_type & DT_DIR || entry->d_type & DT_LNK) {
      if (strcmp(d_name, "..") != 0 && strcmp(d_name, ".") != 0) {
        int path_length;
        char path[PATH_MAX];
        path_length = snprintf(path, PATH_MAX, "%s/%s", dir_name, d_name);
        if (path_length >= PATH_MAX) {
          fprintf(stderr, "Path length has got too long.\n");
          exit(EXIT_FAILURE);
        }
        list_dir(path);
      }
    }
  }
  if (closedir(d)) {
    fprintf(stderr, "Could not close '%s': %s\n", dir_name, strerror(errno));
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<list_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x11a0,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1242 <list_dir+0x72>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x117c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x1178(%rbp)
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x117c(%rbp),%edi
mov    -0x1178(%rbp),%rdx
mov    %rax,%rcx
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1517 <list_dir+0x347>
jmp    1247 <list_dir+0x77>
mov    -0x10(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1264 <list_dir+0x94>
jmp    14b0 <list_dir+0x2e0>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xd9b(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%eax
mov    0x2d38(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1398 <list_dir+0x1c8>
mov    -0x20(%rbp),%rdi
lea    0xd78(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1398 <list_dir+0x1c8>
mov    -0x20(%rbp),%rdi
lea    0xd5f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1398 <list_dir+0x1c8>
mov    -0x20(%rbp),%rdi
lea    0xd47(%rip),%rsi
call   10c0 <ends_with@plt>
cmp    $0x0,%rax
jne    133f <list_dir+0x16f>
mov    -0x20(%rbp),%rdi
lea    0xd32(%rip),%rsi
call   10c0 <ends_with@plt>
cmp    $0x0,%rax
jne    133f <list_dir+0x16f>
mov    -0x20(%rbp),%rdi
lea    0xd20(%rip),%rsi
call   10c0 <ends_with@plt>
cmp    $0x0,%rax
jne    133f <list_dir+0x16f>
mov    -0x20(%rbp),%rdi
lea    0xd0a(%rip),%rsi
call   10c0 <ends_with@plt>
cmp    $0x0,%rax
je     1393 <list_dir+0x1c3>
lea    -0x1150(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xccb(%rip),%rsi
call   10d0 <sprintf@plt>
lea    -0x1150(%rbp),%rdi
lea    -0x1158(%rbp),%rsi
call   1090 <stat@plt>
cmpq   $0x0,-0x1158(%rbp)
jle    138e <list_dir+0x1be>
lea    -0x1150(%rbp),%rsi
lea    0xceb(%rip),%rdi
call   1040 <printf@plt>
jmp    1393 <list_dir+0x1c3>
jmp    1398 <list_dir+0x1c8>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%eax
mov    0x2c2a(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    13ca <list_dir+0x1fa>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%eax
mov    0x2bf9(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     14ab <list_dir+0x2db>
mov    -0x20(%rbp),%rdi
lea    0xc51(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     14a6 <list_dir+0x2d6>
mov    -0x20(%rbp),%rdi
lea    0xc38(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     14a6 <list_dir+0x2d6>
mov    0x2beb(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x1168(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x1188(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x1170(%rbp)
mov    0x2bb6(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xbd5(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,-0x115c(%rbp)
mov    -0x115c(%rbp),%eax
mov    0x2b8d(%rip),%rcx
cmp    (%rcx),%eax
jl     1490 <list_dir+0x2c0>
mov    0x2b66(%rip),%rax
mov    (%rax),%edi
lea    0xbc4(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2b37(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x1188(%rbp),%rdi
call   10b0 <list_dir@plt>
mov    -0x1168(%rbp),%rax
mov    %rax,%rsp
jmp    14ab <list_dir+0x2db>
jmp    1247 <list_dir+0x77>
mov    -0x10(%rbp),%rdi
call   1060 <closedir@plt>
cmp    $0x0,%rax
je     1517 <list_dir+0x347>
mov    0x2b0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1194(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x1190(%rbp)
mov    0x2ae4(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x1194(%rbp),%edi
mov    -0x1190(%rbp),%rdx
mov    %rax,%rcx
lea    0xb5c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2ab0(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_dir>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1148,%rsp
mov    %rdi,-0x30(%rbp)
call   1030 <opendir@plt>
test   %rax,%rax
je     13e8 <list_dir+0x218>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     13cc <list_dir+0x1fc>
mov    %rax,%r13
lea    0xe0c(%rip),%r14
mov    %rbx,-0x38(%rbp)
jmp    1234 <list_dir+0x64>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10a0 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     13cc <list_dir+0x1fc>
mov    0x0(%r13),%r12
lea    -0x1170(%rbp),%rdi
mov    %r14,%rsi
mov    -0x30(%rbp),%rdx
mov    %r12,%rcx
call   10d0 <sprintf@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
test   %eax,0x8(%r13)
je     1300 <list_dir+0x130>
mov    0x8(%r13),%eax
mov    0x2d64(%rip),%rcx
test   %eax,(%rcx)
jne    127b <list_dir+0xab>
mov    0x2d41(%rip),%rcx
test   %eax,(%rcx)
je     1220 <list_dir+0x50>
mov    %r12,%rdi
lea    0xda1(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1220 <list_dir+0x50>
mov    %r12,%rdi
lea    0xd8e(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1220 <list_dir+0x50>
mov    -0x30(%rbp),%rcx
mov    %rsp,%r13
mov    0x2d3b(%rip),%rdi
mov    (%rdi),%eax
mov    %r14,%rdx
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    (%rdi),%esi
mov    %rdi,%r15
mov    %rbx,%rdi
mov    %r12,%r8
call   1050 <snprintf@plt>
cmp    (%r15),%eax
jge    1424 <list_dir+0x254>
mov    %rbx,%rdi
call   10b0 <list_dir@plt>
mov    %r13,%rsp
mov    -0x38(%rbp),%rbx
jmp    1220 <list_dir+0x50>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
lea    0xd1c(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1261 <list_dir+0x91>
mov    %r12,%rdi
lea    0xd05(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1261 <list_dir+0x91>
mov    %r12,%rdi
lea    0xcef(%rip),%rsi
call   10c0 <ends_with@plt>
test   %rax,%rax
jne    1384 <list_dir+0x1b4>
mov    %r12,%rdi
lea    0xce0(%rip),%rsi
call   10c0 <ends_with@plt>
test   %rax,%rax
jne    1384 <list_dir+0x1b4>
mov    %r12,%rdi
lea    0xcd4(%rip),%rsi
call   10c0 <ends_with@plt>
test   %rax,%rax
jne    1384 <list_dir+0x1b4>
mov    %r12,%rdi
lea    0xcc4(%rip),%rsi
call   10c0 <ends_with@plt>
test   %rax,%rax
je     1261 <list_dir+0x91>
lea    -0x170(%rbp),%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    -0x30(%rbp),%rdx
mov    %r12,%rcx
call   10d0 <sprintf@plt>
mov    %r15,%rdi
lea    -0x40(%rbp),%rsi
call   1090 <stat@plt>
cmpq   $0x0,-0x40(%rbp)
jle    1261 <list_dir+0x91>
lea    0xcb9(%rip),%rdi
lea    -0x170(%rbp),%rsi
call   1040 <printf@plt>
jmp    1261 <list_dir+0x91>
mov    %rbx,%rdi
call   1060 <closedir@plt>
test   %rax,%rax
jne    1449 <list_dir+0x279>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2be9(%rip),%rax
mov    (%rax),%ebx
mov    0x2bd0(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xbfa(%rip),%rsi
mov    %ebx,%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <fprintf@plt>
mov    0x2bad(%rip),%rax
mov    (%rax),%edi
lea    0xc0b(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2b7e(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    0x2b88(%rip),%rax
mov    (%rax),%ebx
mov    0x2b6f(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xbf7(%rip),%rsi
mov    %ebx,%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    143b <list_dir+0x26b>

LLVM IR (-O0):
%struct.dirent = type { i8*, i32 }
%struct.stat = type { i64 }
@stderr = global i32 0
@.str = [32 x i8] c"Cannot open directory '%s': %s\0A\00"
@errno = global i32 0
@.str.1 = [6 x i8] c"%s/%s\00"
@DT_DIR = global i32 0
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [5 x i8] c".tbi\00"
@.str.5 = [8 x i8] c".bigwig\00"
@.str.6 = [4 x i8] c".bw\00"
@.str.7 = [5 x i8] c".bai\00"
@.str.8 = [4 x i8] c"%s\0A\00"
@DT_LNK = global i32 0
@PATH_MAX = global i32 0
@.str.9 = [31 x i8] c"Path length has got too long.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.10 = [26 x i8] c"Could not close '%s': %s\0A\00"
define void @list_dir(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca i8*
%6 = alloca [4096 x i8]
%7 = alloca [300 x i8]
%8 = alloca %struct.stat
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
store i8* %0, i8** %2
%12 = load i8*, i8** %2
%13 = call i32* @opendir(i8* %12)
store i32* %13, i32** %3
%14 = load i32*, i32** %3
%15 = icmp ne i32* %14, null
br i1 %15, label %22, label %16
16: ; preds = %1
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %2
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %20)
br label %137
22: ; preds = %1
br label %23
23: ; preds = %22, %124
%24 = load i32*, i32** %3
%25 = call %struct.dirent* @readdir(i32* %24)
store %struct.dirent* %25, %struct.dirent** %4
%26 = load %struct.dirent*, %struct.dirent** %4
%27 = icmp ne %struct.dirent* %26, null
br i1 %27, label %29, label %28
28: ; preds = %23
br label %125
29: ; preds = %23
%30 = load %struct.dirent*, %struct.dirent** %4
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %30, i32 0, i32 0
%32 = load i8*, i8** %31
store i8* %32, i8** %5
%33 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%34 = load i8*, i8** %2
%35 = load i8*, i8** %5
%36 = call i32 @sprintf(i8* %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %34, i8* %35)
%37 = load %struct.dirent*, %struct.dirent** %4
%38 = getelementptr inbounds %struct.dirent, %struct.dirent* %37, i32 0, i32 1
%39 = load i32, i32* %38
%40 = load i32, i32* @DT_DIR
%41 = and i32 %39, %40
%42 = icmp ne i32 %41, 0
br i1 %42, label %82, label %43
43: ; preds = %29
%44 = load i8*, i8** %5
%45 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %82
47: ; preds = %43
%48 = load i8*, i8** %5
%49 = call i64 @strcmp(i8* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %82
51: ; preds = %47
%52 = load i8*, i8** %5
%53 = call i64 @ends_with(i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%54 = icmp ne i64 %53, 0
br i1 %54, label %67, label %55
55: ; preds = %51
%56 = load i8*, i8** %5
%57 = call i64 @ends_with(i8* %56, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%58 = icmp ne i64 %57, 0
br i1 %58, label %67, label %59
59: ; preds = %55
%60 = load i8*, i8** %5
%61 = call i64 @ends_with(i8* %60, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%62 = icmp ne i64 %61, 0
br i1 %62, label %67, label %63
63: ; preds = %59
%64 = load i8*, i8** %5
%65 = call i64 @ends_with(i8* %64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %81
67: ; preds = %63, %59, %55, %51
%68 = getelementptr inbounds [300 x i8], [300 x i8]* %7, i64 0, i64 0
%69 = load i8*, i8** %2
%70 = load i8*, i8** %5
%71 = call i32 @sprintf(i8* %68, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %69, i8* %70)
%72 = getelementptr inbounds [300 x i8], [300 x i8]* %7, i64 0, i64 0
%73 = call i32 @stat(i8* %72, %struct.stat* %8)
%74 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%75 = load i64, i64* %74
%76 = icmp sgt i64 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %67
%78 = getelementptr inbounds [300 x i8], [300 x i8]* %7, i64 0, i64 0
%79 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %78)
br label %80
80: ; preds = %77, %67
br label %81
81: ; preds = %80, %63
br label %82
82: ; preds = %81, %47, %43, %29
%83 = load %struct.dirent*, %struct.dirent** %4
%84 = getelementptr inbounds %struct.dirent, %struct.dirent* %83, i32 0, i32 1
%85 = load i32, i32* %84
%86 = load i32, i32* @DT_DIR
%87 = and i32 %85, %86
%88 = icmp ne i32 %87, 0
br i1 %88, label %96, label %89
89: ; preds = %82
%90 = load %struct.dirent*, %struct.dirent** %4
%91 = getelementptr inbounds %struct.dirent, %struct.dirent* %90, i32 0, i32 1
%92 = load i32, i32* %91
%93 = load i32, i32* @DT_LNK
%94 = and i32 %92, %93
%95 = icmp ne i32 %94, 0
br i1 %95, label %96, label %124
96: ; preds = %89, %82
%97 = load i8*, i8** %5
%98 = call i64 @strcmp(i8* %97, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%99 = icmp ne i64 %98, 0
br i1 %99, label %100, label %123
100: ; preds = %96
%101 = load i8*, i8** %5
%102 = call i64 @strcmp(i8* %101, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%103 = icmp ne i64 %102, 0
br i1 %103, label %104, label %123
104: ; preds = %100
%105 = load i32, i32* @PATH_MAX
%106 = zext i32 %105 to i64
%107 = call i8* @llvm.stacksave()
store i8* %107, i8** %10
%108 = alloca i8, i64 %106
store i64 %106, i64* %11
%109 = load i32, i32* @PATH_MAX
%110 = load i8*, i8** %2
%111 = load i8*, i8** %5
%112 = call i32 @snprintf(i8* %108, i32 %109, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %110, i8* %111)
store i32 %112, i32* %9
%113 = load i32, i32* %9
%114 = load i32, i32* @PATH_MAX
%115 = icmp sge i32 %113, %114
br i1 %115, label %116, label %121
116: ; preds = %104
%117 = load i32, i32* @stderr
%118 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
%119 = load i32, i32* @EXIT_FAILURE
%120 = call i32 @exit(i32 %119)
unreachable
121: ; preds = %104
%122 = load i8*, i8** %10
br label %123
123: ; preds = %121, %100, %96
br label %124
124: ; preds = %123, %89
br label %23
125: ; preds = %28
%126 = load i32*, i32** %3
%127 = call i64 @closedir(i32* %126)
%128 = icmp ne i64 %127, 0
br i1 %128, label %129, label %137
129: ; preds = %125
%130 = load i32, i32* @stderr
%131 = load i8*, i8** %2
%132 = load i32, i32* @errno
%133 = call i8* @strerror(i32 %132)
%134 = call i32 (i32, i8*, ...) @fprintf(i32 %130, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i8* %131, i8* %133)
%135 = load i32, i32* @EXIT_FAILURE
%136 = call i32 @exit(i32 %135)
unreachable
137: ; preds = %16, %125
ret void
}

LLVM IR (-O2):
%struct.stat = type { i64 }
%struct.dirent = type { i8*, i32 }
@stderr = global i32 0
@.str = [32 x i8] c"Cannot open directory '%s': %s\0A\00"
@errno = global i32 0
@.str.1 = [6 x i8] c"%s/%s\00"
@DT_DIR = global i32 0
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [5 x i8] c".tbi\00"
@.str.5 = [8 x i8] c".bigwig\00"
@.str.6 = [4 x i8] c".bw\00"
@.str.7 = [5 x i8] c".bai\00"
@.str.8 = [4 x i8] c"%s\0A\00"
@DT_LNK = global i32 0
@PATH_MAX = global i32 0
@.str.9 = [31 x i8] c"Path length has got too long.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.10 = [26 x i8] c"Could not close '%s': %s\0A\00"
define void @list_dir(i8* %0) {
%2 = alloca [4096 x i8]
%3 = alloca [300 x i8]
%4 = alloca %struct.stat
%5 = tail call i32* @opendir(i8* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %15, label %7
7: ; preds = %1
%8 = call %struct.dirent* @readdir(i32* %5)
%9 = icmp eq %struct.dirent* %8, null
br i1 %9, label %89, label %10
10: ; preds = %7
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%12 = getelementptr inbounds [300 x i8], [300 x i8]* %3, i64 0, i64 0
%13 = bitcast %struct.stat* %4 to i8*
%14 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
br label %20
15: ; preds = %1
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %18)
br label %99
20: ; preds = %10, %86
%21 = phi %struct.dirent* [ %8, %10 ], [ %87, %86 ]
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i64 0, i32 0
%23 = load i8*, i8** %22
%24 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %23)
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i64 0, i32 1
%26 = load i32, i32* %25
%27 = load i32, i32* @DT_DIR
%28 = and i32 %27, %26
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %56
30: ; preds = %20
%31 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %56, label %33
33: ; preds = %30
%34 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %56, label %36
36: ; preds = %33
%37 = call i64 @ends_with(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %48
39: ; preds = %36
%40 = call i64 @ends_with(i8* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %39
%43 = call i64 @ends_with(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = call i64 @ends_with(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %56, label %48
48: ; preds = %45, %42, %39, %36
%49 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %23)
%50 = call i32 @stat(i8* %12, %struct.stat* %4)
%51 = load i64, i64* %14
%52 = icmp sgt i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %48
%54 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %12)
br label %55
55: ; preds = %53, %48
br label %56
56: ; preds = %45, %55, %33, %30, %20
%57 = load i32, i32* %25
%58 = load i32, i32* @DT_DIR
%59 = and i32 %58, %57
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %56
%62 = load i32, i32* @DT_LNK
%63 = and i32 %62, %57
%64 = icmp eq i32 %63, 0
br i1 %64, label %86, label %65
65: ; preds = %61, %56
%66 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%67 = icmp eq i64 %66, 0
br i1 %67, label %86, label %68
68: ; preds = %65
%69 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%70 = icmp eq i64 %69, 0
br i1 %70, label %86, label %71
71: ; preds = %68
%72 = load i32, i32* @PATH_MAX
%73 = zext i32 %72 to i64
%74 = call i8* @llvm.stacksave()
%75 = alloca i8, i64 %73
%76 = load i32, i32* @PATH_MAX
%77 = call i32 @snprintf(i8* %75, i32 %76, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %23)
%78 = load i32, i32* @PATH_MAX
%79 = icmp slt i32 %77, %78
br i1 %79, label %85, label %80
80: ; preds = %71
%81 = load i32, i32* @stderr
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
%83 = load i32, i32* @EXIT_FAILURE
%84 = call i32 @exit(i32 %83)
unreachable
85: ; preds = %71
br label %86
86: ; preds = %61, %85, %68, %65
%87 = call %struct.dirent* @readdir(i32* %5)
%88 = icmp eq %struct.dirent* %87, null
br i1 %88, label %89, label %20
89: ; preds = %86, %7
%90 = call i64 @closedir(i32* %5)
%91 = icmp eq i64 %90, 0
br i1 %91, label %99, label %92
92: ; preds = %89
%93 = load i32, i32* @stderr
%94 = load i32, i32* @errno
%95 = call i8* @strerror(i32 %94)
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i8* %0, i8* %95)
%97 = load i32, i32* @EXIT_FAILURE
%98 = call i32 @exit(i32 %97)
unreachable
99: ; preds = %89, %15
ret void
}