#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  char **gl_pathv;
};
typedef TYPE_1__ glob_t;

/* Variables and functions */
int /*<<< orphan*/ GLOB_ERR;
int getNumberOfExecutables(char *);
int /*<<< orphan*/ glob(char *, int /*<<< orphan*/, int /*<<< orphan*/ *,
                        TYPE_1__ *);
int /*<<< orphan*/ globfree(TYPE_1__ *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void getExecutables(char *dir, char **list) {
  char pattern[260];
  strcpy(pattern, dir);
  strcat(pattern, "Lesson*");
  glob_t result;
  glob(pattern, GLOB_ERR, NULL, &result);
  for (int i = 0; i < getNumberOfExecutables(dir); i++)
    strcpy(list[i], result.gl_pathv[i]);
  globfree(&result);
}


x86 assembly (clang, -O0):
<getExecutables>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x120(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1050 <strcat@plt>
lea    -0x120(%rbp),%rdi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x128(%rbp),%rcx
call   1060 <glob@plt>
movl   $0x0,-0x12c(%rbp)
mov    -0x12c(%rbp),%eax
mov    %eax,-0x130(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <getNumberOfExecutables@plt>
mov    %eax,%ecx
mov    -0x130(%rbp),%eax
cmp    %ecx,%eax
jge    120f <getExecutables+0xbf>
mov    -0x10(%rbp),%rax
movslq -0x12c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x128(%rbp),%rax
movslq -0x12c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcpy@plt>
mov    -0x12c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x12c(%rbp)
jmp    11b0 <getExecutables+0x60>
lea    -0x128(%rbp),%rdi
call   1030 <globfree@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getExecutables>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
lea    0xe85(%rip),%rsi
mov    %r15,%rdi
call   1050 <strcat@plt>
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rcx
mov    %r15,%rdi
xor    %edx,%edx
call   1060 <glob@plt>
mov    %r12,%rdi
call   1070 <getNumberOfExecutables@plt>
test   %eax,%eax
jle    11d5 <getExecutables+0x85>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r14,%rbx,8),%rdi
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,8),%rsi
call   1040 <strcpy@plt>
add    $0x1,%rbx
mov    %r12,%rdi
call   1070 <getNumberOfExecutables@plt>
cltq
cmp    %rax,%rbx
jl     11b0 <getExecutables+0x60>
lea    0x8(%rsp),%rdi
call   1030 <globfree@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i8** }
@.str = [8 x i8] c"Lesson*\00"
@GLOB_ERR = global i32 0
define void @getExecutables(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca [260 x i8]
%6 = alloca %struct.TYPE_4__
%7 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
%8 = getelementptr inbounds [260 x i8], [260 x i8]* %5, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = call i32 @strcpy(i8* %8, i8* %9)
%11 = getelementptr inbounds [260 x i8], [260 x i8]* %5, i64 0, i64 0
%12 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds [260 x i8], [260 x i8]* %5, i64 0, i64 0
%14 = load i32, i32* @GLOB_ERR
%15 = call i32 @glob(i8* %13, i32 %14, i32* null, %struct.TYPE_4__* %6)
store i32 0, i32* %7
br label %16
16: ; preds = %34, %2
%17 = load i32, i32* %7
%18 = load i8*, i8** %3
%19 = call i32 @getNumberOfExecutables(i8* %18)
%20 = icmp slt i32 %17, %19
br i1 %20, label %21, label %37
21: ; preds = %16
%22 = load i8**, i8*** %4
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 0
%28 = load i8**, i8*** %27
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 @strcpy(i8* %26, i8* %32)
br label %34
34: ; preds = %21
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %16
37: ; preds = %16
%38 = call i32 @globfree(%struct.TYPE_4__* %6)
ret void
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i8** }
@.str = [8 x i8] c"Lesson*\00"
@GLOB_ERR = global i32 0
define void @getExecutables(i8* %0, i8** nocapture %1) {
%3 = alloca [260 x i8]
%4 = alloca %struct.TYPE_4__
%5 = getelementptr inbounds [260 x i8], [260 x i8]* %3, i64 0, i64 0
%6 = call i32 @strcpy(i8* %5, i8* %0)
%7 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = bitcast %struct.TYPE_4__* %4 to i8*
%9 = load i32, i32* @GLOB_ERR
%10 = call i32 @glob(i8* %5, i32 %9, i32* null, %struct.TYPE_4__* %4)
%11 = call i32 @getNumberOfExecutables(i8* %0)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %4, i64 0, i32 0
br label %17
15: ; preds = %17, %2
%16 = call i32 @globfree(%struct.TYPE_4__* %4)
ret void
17: ; preds = %13, %17
%18 = phi i64 [ 0, %13 ], [ %25, %17 ]
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %14
%22 = getelementptr inbounds i8*, i8** %21, i64 %18
%23 = load i8*, i8** %22
%24 = call i32 @strcpy(i8* %20, i8* %23)
%25 = add nuw nsw i64 %18, 1
%26 = call i32 @getNumberOfExecutables(i8* %0)
%27 = sext i32 %26 to i64
%28 = icmp slt i64 %25, %27
br i1 %28, label %17, label %15
}