#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*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ assert(long *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ is_my_file(char const *);
long *malloc(int);
long number_from_filename(char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
long *__ls_my_files(DIR *dir, long start_at, long end_at, int *pcount,
                    int *pindex) {
  struct dirent *entry;
  const char *filename;
  long number, *ret;
  int my_index;
  entry = readdir(dir);
  if (!entry) {
    ret = malloc(sizeof(long) * (*pcount + 1));
    assert(ret);
    *pindex = *pcount - 1;
    ret[*pcount] = -1;
    closedir(dir);
    return ret;
  }
  filename = entry->d_name;
  if (!is_my_file(filename))
    return __ls_my_files(dir, start_at, end_at, pcount, pindex);
  number = number_from_filename(filename);
  if (number < start_at || end_at < number)
    return __ls_my_files(dir, start_at, end_at, pcount, pindex);
  (*pcount)++;
  ret = __ls_my_files(dir, start_at, end_at, pcount, &my_index);
  ret[my_index] = number;
  *pindex = my_index - 1;
  return ret;
}


x86 assembly (clang, -O0):
<__ls_my_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11ff <__ls_my_files+0x8f>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
sub    $0x1,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x50(%rbp),%rax
mov    -0x28(%rbp),%rcx
movslq (%rcx),%rcx
movq   $0xffffffffffffffff,(%rax,%rcx,8)
ff
mov    -0x10(%rbp),%rdi
call   1040 <closedir@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12d5 <__ls_my_files+0x165>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <is_my_file@plt>
cmp    $0x0,%eax
jne    123e <__ls_my_files+0xce>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1080 <__ls_my_files@plt>
mov    %rax,-0x8(%rbp)
jmp    12d5 <__ls_my_files+0x165>
mov    -0x40(%rbp),%rdi
call   1090 <number_from_filename@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x18(%rbp),%rax
jl     1267 <__ls_my_files+0xf7>
mov    -0x20(%rbp),%rax
cmp    -0x48(%rbp),%rax
jge    1289 <__ls_my_files+0x119>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1080 <__ls_my_files@plt>
mov    %rax,-0x8(%rbp)
jmp    12d5 <__ls_my_files+0x165>
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    -0x54(%rbp),%r8
call   1080 <__ls_my_files@plt>
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rdx
mov    -0x50(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x54(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__ls_my_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbp
call   1060 <readdir@plt>
test   %rax,%rax
je     11fe <__ls_my_files+0x8e>
mov    (%rax),%rbx
mov    %rbx,%rdi
call   1030 <is_my_file@plt>
test   %eax,%eax
je     1246 <__ls_my_files+0xd6>
mov    %r14,0x10(%rsp)
mov    %rbx,%rdi
call   1090 <number_from_filename@plt>
cmp    %r13,%rax
jl     1257 <__ls_my_files+0xe7>
mov    %rax,%r14
cmp    %r12,%rax
jg     1257 <__ls_my_files+0xe7>
addl   $0x1,(%r15)
lea    0xc(%rsp),%r8
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
call   1080 <__ls_my_files@plt>
mov    %rax,%rbx
movslq 0xc(%rsp),%rax
mov    %r14,(%rbx,%rax,8)
add    $0xffffffff,%eax
mov    0x10(%rsp),%rcx
mov    %eax,(%rcx)
jmp    1234 <__ls_my_files+0xc4>
mov    (%r15),%eax
lea    0x8(,%rax,8),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <assert@plt>
mov    (%r15),%eax
add    $0xffffffff,%eax
mov    %eax,(%r14)
movslq (%r15),%rax
movq   $0xffffffffffffffff,(%rbx,%rax,8)
ff
mov    %rbp,%rdi
call   1040 <closedir@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
jmp    1268 <__ls_my_files+0xf8>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    0x10(%rsp),%r8
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <__ls_my_files@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
define i64* @__ls_my_files(i32* %0, i64 %1, i64 %2, i32* %3, i32* %4) {
%6 = alloca i64*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca %struct.dirent*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i64*
%16 = alloca i32
store i32* %0, i32** %7
store i64 %1, i64* %8
store i64 %2, i64* %9
store i32* %3, i32** %10
store i32* %4, i32** %11
%17 = load i32*, i32** %7
%18 = call %struct.dirent* @readdir(i32* %17)
store %struct.dirent* %18, %struct.dirent** %12
%19 = load %struct.dirent*, %struct.dirent** %12
%20 = icmp ne %struct.dirent* %19, null
br i1 %20, label %43, label %21
21: ; preds = %5
%22 = load i32*, i32** %10
%23 = load i32, i32* %22
%24 = add nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = mul i64 8, %25
%27 = trunc i64 %26 to i32
%28 = call i64* @malloc(i32 %27)
store i64* %28, i64** %15
%29 = load i64*, i64** %15
%30 = call i32 @assert(i64* %29)
%31 = load i32*, i32** %10
%32 = load i32, i32* %31
%33 = sub nsw i32 %32, 1
%34 = load i32*, i32** %11
store i32 %33, i32* %34
%35 = load i64*, i64** %15
%36 = load i32*, i32** %10
%37 = load i32, i32* %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i64, i64* %35, i64 %38
store i64 -1, i64* %39
%40 = load i32*, i32** %7
%41 = call i32 @closedir(i32* %40)
%42 = load i64*, i64** %15
store i64* %42, i64** %6
br label %92
43: ; preds = %5
%44 = load %struct.dirent*, %struct.dirent** %12
%45 = getelementptr inbounds %struct.dirent, %struct.dirent* %44, i32 0, i32 0
%46 = load i8*, i8** %45
store i8* %46, i8** %13
%47 = load i8*, i8** %13
%48 = call i32 @is_my_file(i8* %47)
%49 = icmp ne i32 %48, 0
br i1 %49, label %57, label %50
50: ; preds = %43
%51 = load i32*, i32** %7
%52 = load i64, i64* %8
%53 = load i64, i64* %9
%54 = load i32*, i32** %10
%55 = load i32*, i32** %11
%56 = call i64* @__ls_my_files(i32* %51, i64 %52, i64 %53, i32* %54, i32* %55)
store i64* %56, i64** %6
br label %92
57: ; preds = %43
%58 = load i8*, i8** %13
%59 = call i64 @number_from_filename(i8* %58)
store i64 %59, i64* %14
%60 = load i64, i64* %14
%61 = load i64, i64* %8
%62 = icmp slt i64 %60, %61
br i1 %62, label %67, label %63
63: ; preds = %57
%64 = load i64, i64* %9
%65 = load i64, i64* %14
%66 = icmp slt i64 %64, %65
br i1 %66, label %67, label %74
67: ; preds = %63, %57
%68 = load i32*, i32** %7
%69 = load i64, i64* %8
%70 = load i64, i64* %9
%71 = load i32*, i32** %10
%72 = load i32*, i32** %11
%73 = call i64* @__ls_my_files(i32* %68, i64 %69, i64 %70, i32* %71, i32* %72)
store i64* %73, i64** %6
br label %92
74: ; preds = %63
%75 = load i32*, i32** %10
%76 = load i32, i32* %75
%77 = add nsw i32 %76, 1
store i32 %77, i32* %75
%78 = load i32*, i32** %7
%79 = load i64, i64* %8
%80 = load i64, i64* %9
%81 = load i32*, i32** %10
%82 = call i64* @__ls_my_files(i32* %78, i64 %79, i64 %80, i32* %81, i32* %16)
store i64* %82, i64** %15
%83 = load i64, i64* %14
%84 = load i64*, i64** %15
%85 = load i32, i32* %16
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i64, i64* %84, i64 %86
store i64 %83, i64* %87
%88 = load i32, i32* %16
%89 = sub nsw i32 %88, 1
%90 = load i32*, i32** %11
store i32 %89, i32* %90
%91 = load i64*, i64** %15
store i64* %91, i64** %6
br label %92
92: ; preds = %74, %67, %50, %21
%93 = load i64*, i64** %6
ret i64* %93
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
define i64* @__ls_my_files(i32* %0, i64 %1, i64 %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = tail call %struct.dirent* @readdir(i32* %0)
%9 = icmp eq %struct.dirent* %8, null
br i1 %9, label %10, label %22
10: ; preds = %5
%11 = load i32, i32* %3
%12 = shl i32 %11, 3
%13 = add i32 %12, 8
%14 = tail call i64* @malloc(i32 %13)
%15 = tail call i32 @assert(i64* %14)
%16 = load i32, i32* %3
%17 = add nsw i32 %16, -1
store i32 %17, i32* %4
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i64, i64* %14, i64 %19
store i64 -1, i64* %20
%21 = tail call i32 @closedir(i32* %0)
br label %44
22: ; preds = %5
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i64 0, i32 0
%24 = load i8*, i8** %23
%25 = tail call i32 @is_my_file(i8* %24)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = tail call i64* @__ls_my_files(i32* %0, i64 %1, i64 %2, i32* %3, i32* %4)
br label %44
29: ; preds = %22
%30 = tail call i64 @number_from_filename(i8* %24)
%31 = icmp slt i64 %30, %1
%32 = icmp sgt i64 %30, %2
%33 = or i1 %31, %32
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = tail call i64* @__ls_my_files(i32* %0, i64 %1, i64 %2, i32* %3, i32* %4)
br label %44
36: ; preds = %29
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
%39 = call i64* @__ls_my_files(i32* %0, i64 %1, i64 %2, i32* %3, i32* %6)
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i64, i64* %39, i64 %41
store i64 %30, i64* %42
%43 = add nsw i32 %40, -1
store i32 %43, i32* %4
br label %44
44: ; preds = %36, %34, %27, %10
%45 = phi i64* [ %35, %34 ], [ %39, %36 ], [ %28, %27 ], [ %14, %10 ]
ret i64* %45
}