#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__ {
  int gl_pathc;
  int /*<<< orphan*/ **gl_pathv;
};
typedef TYPE_1__ glob_t;

/* Variables and functions */
int /*<<< orphan*/ GLOB_ERR;
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 *);
int getNumberOfExecutables(char *dir) {
  char pattern[260];
  strcpy(pattern, dir);
  strcat(pattern, "Lesson*");
  glob_t result;
  glob(pattern, GLOB_ERR, NULL, &result);
  int number = 0;
  for (int i = 0; i < result.gl_pathc; i++)
    if (result.gl_pathv[i] != NULL)
      number++;
  globfree(&result);
  return number;
}


x86 assembly (clang, -O0):
<getNumberOfExecutables>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x110(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1050 <strcat@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x120(%rbp),%rcx
call   1060 <glob@plt>
movl   $0x0,-0x124(%rbp)
movl   $0x0,-0x128(%rbp)
mov    -0x128(%rbp),%eax
cmp    -0x120(%rbp),%eax
jge    11f9 <getNumberOfExecutables+0xb9>
mov    -0x118(%rbp),%rax
movslq -0x128(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11e0 <getNumberOfExecutables+0xa0>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    11e5 <getNumberOfExecutables+0xa5>
mov    -0x128(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x128(%rbp)
jmp    11a6 <getNumberOfExecutables+0x66>
lea    -0x120(%rbp),%rdi
call   1030 <globfree@plt>
mov    -0x124(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNumberOfExecutables>:
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1040 <strcpy@plt>
lea    0xe9f(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcat@plt>
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
mov    %rsp,%rcx
mov    %r14,%rdi
xor    %edx,%edx
call   1060 <glob@plt>
mov    (%rsp),%edx
test   %edx,%edx
jle    1201 <getNumberOfExecutables+0xc1>
mov    0x8(%rsp),%rcx
lea    -0x1(%rdx),%rsi
mov    %edx,%eax
and    $0x3,%eax
cmp    $0x3,%rsi
jae    11a2 <getNumberOfExecutables+0x62>
xor    %esi,%esi
xor    %ebx,%ebx
jmp    11dc <getNumberOfExecutables+0x9c>
and    $0xfffffffc,%edx
xor    %esi,%esi
xor    %ebx,%ebx
nopl   0x0(%rax)
cmpq   $0x1,(%rcx,%rsi,8)
sbb    $0xffffffff,%ebx
cmpq   $0x1,0x8(%rcx,%rsi,8)
sbb    $0xffffffff,%ebx
cmpq   $0x1,0x10(%rcx,%rsi,8)
sbb    $0xffffffff,%ebx
cmpq   $0x1,0x18(%rcx,%rsi,8)
sbb    $0xffffffff,%ebx
add    $0x4,%rsi
cmp    %rsi,%rdx
jne    11b0 <getNumberOfExecutables+0x70>
test   %rax,%rax
je     1201 <getNumberOfExecutables+0xc1>
lea    (%rcx,%rsi,8),%rcx
xor    %edx,%edx
nopw   0x0(%rax,%rax,1)
cmpq   $0x1,(%rcx,%rdx,8)
sbb    $0xffffffff,%ebx
add    $0x1,%rdx
cmp    %rdx,%rax
jne    11f0 <getNumberOfExecutables+0xb0>
mov    %rsp,%rdi
call   1030 <globfree@plt>
mov    %ebx,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32** }
@.str = [8 x i8] c"Lesson*\00"
@GLOB_ERR = global i32 0
define i32 @getNumberOfExecutables(i8* %0) {
%2 = alloca [260 x i8]
%3 = alloca %struct.TYPE_4__
%4 = getelementptr inbounds [260 x i8], [260 x i8]* %2, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* %0)
%6 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%7 = bitcast %struct.TYPE_4__* %3 to i8*
%8 = load i32, i32* @GLOB_ERR
%9 = call i32 @glob(i8* %4, i32 %8, i32* null, %struct.TYPE_4__* %3)
%10 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0
%11 = load i32, i32* %10
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %39
13: ; preds = %1
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 1
%15 = load i32**, i32*** %14
%16 = zext i32 %11 to i64
%17 = add nsw i64 %16, -1
%18 = and i64 %16, 3
%19 = icmp ult i64 %17, 3
br i1 %19, label %22, label %20
20: ; preds = %13
%21 = and i64 %16, 4294967292
br label %42
22: ; preds = %42, %13
%23 = phi i32 [ undef, %13 ], [ %68, %42 ]
%24 = phi i64 [ 0, %13 ], [ %69, %42 ]
%25 = phi i32 [ 0, %13 ], [ %68, %42 ]
%26 = icmp eq i64 %18, 0
br i1 %26, label %39, label %27
27: ; preds = %22, %27
%28 = phi i64 [ %36, %27 ], [ %24, %22 ]
%29 = phi i32 [ %35, %27 ], [ %25, %22 ]
%30 = phi i64 [ %37, %27 ], [ 0, %22 ]
%31 = getelementptr inbounds i32*, i32** %15, i64 %28
%32 = load i32*, i32** %31
%33 = icmp ne i32* %32, null
%34 = zext i1 %33 to i32
%35 = add nuw nsw i32 %29, %34
%36 = add nuw nsw i64 %28, 1
%37 = add i64 %30, 1
%38 = icmp eq i64 %37, %18
br i1 %38, label %39, label %27
39: ; preds = %22, %27, %1
%40 = phi i32 [ 0, %1 ], [ %23, %22 ], [ %35, %27 ]
%41 = call i32 @globfree(%struct.TYPE_4__* %3)
ret i32 %40
42: ; preds = %42, %20
%43 = phi i64 [ 0, %20 ], [ %69, %42 ]
%44 = phi i32 [ 0, %20 ], [ %68, %42 ]
%45 = phi i64 [ 0, %20 ], [ %70, %42 ]
%46 = getelementptr inbounds i32*, i32** %15, i64 %43
%47 = load i32*, i32** %46
%48 = icmp ne i32* %47, null
%49 = zext i1 %48 to i32
%50 = add nuw nsw i32 %44, %49
%51 = or i64 %43, 1
%52 = getelementptr inbounds i32*, i32** %15, i64 %51
%53 = load i32*, i32** %52
%54 = icmp ne i32* %53, null
%55 = zext i1 %54 to i32
%56 = add nuw nsw i32 %50, %55
%57 = or i64 %43, 2
%58 = getelementptr inbounds i32*, i32** %15, i64 %57
%59 = load i32*, i32** %58
%60 = icmp ne i32* %59, null
%61 = zext i1 %60 to i32
%62 = add nuw nsw i32 %56, %61
%63 = or i64 %43, 3
%64 = getelementptr inbounds i32*, i32** %15, i64 %63
%65 = load i32*, i32** %64
%66 = icmp ne i32* %65, null
%67 = zext i1 %66 to i32
%68 = add nuw nsw i32 %62, %67
%69 = add nuw nsw i64 %43, 4
%70 = add i64 %45, 4
%71 = icmp eq i64 %70, %21
br i1 %71, label %22, label %42
}