#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 {
  int st_mode;
};
struct dirent {
  char *d_name;
  int /*<<< orphan*/ d_ino;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int MAXPATHLEN;
int S_IFDIR;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
void get_dir_count(char *path, int *count, int *filelen) {
  struct dirent *dp;
  DIR *dir;
  char dirpath[MAXPATHLEN];
  char fullname[MAXPATHLEN];
  int len;
  struct stat buf;
  strcpy(dirpath, path);
  len = strlen(dirpath);
  if (dirpath[len - 1] != '/')
    strcat(dirpath, "/");
  if (!(dir = opendir(dirpath))) {
    fprintf(stderr, "Error: Cannot open directory [%s]\n", path);
    exit(-1);
  }
  while ((dp = readdir(dir))) {
    if (!dp->d_ino || *dp->d_name == '.' || !strncmp(dp->d_name, "Makefile", 8))
      continue;
    sprintf(fullname, "%s%s", dirpath, dp->d_name);
    if (!stat(fullname, &buf))
      if (buf.st_mode & S_IFDIR)
        continue;
    len = strlen(dp->d_name);
    if (dp->d_name[len - 1] == '~')
      continue;
    ++(*count);
    *filelen = (len > *filelen) ? len : *filelen;
  }
  closedir(dir);
  return;
}


x86 assembly (clang, -O0):
<get_dir_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x30(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rdi
sub    %rdx,%rdi
mov    %rdi,-0x50(%rbp)
mov    %rdi,%rsp
mov    %rcx,-0x38(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x50(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
mov    %ecx,-0x44(%rbp)
mov    -0x44(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     124f <get_dir_count+0x9f>
mov    -0x50(%rbp),%rdi
lea    0xdb6(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x50(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1289 <get_dir_count+0xd9>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd88(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
jmp    128e <get_dir_count+0xde>
mov    -0x28(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     13a9 <get_dir_count+0x1f9>
mov    -0x20(%rbp),%rax
cmpl   $0x0,0x8(%rax)
je     12e7 <get_dir_count+0x137>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     12e7 <get_dir_count+0x137>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xd51(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    12ec <get_dir_count+0x13c>
jmp    128e <get_dir_count+0xde>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
lea    0xd2c(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x58(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%eax
jne    133c <get_dir_count+0x18c>
mov    -0x48(%rbp),%eax
mov    0x2ca1(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1337 <get_dir_count+0x187>
jmp    128e <get_dir_count+0xde>
jmp    133c <get_dir_count+0x18c>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x44(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jne    136d <get_dir_count+0x1bd>
jmp    128e <get_dir_count+0xde>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x44(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jle    1392 <get_dir_count+0x1e2>
mov    -0x44(%rbp),%eax
mov    %eax,-0x5c(%rbp)
jmp    139b <get_dir_count+0x1eb>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    128e <get_dir_count+0xde>
mov    -0x28(%rbp),%rdi
call   1070 <closedir@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dir_count>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,-0x40(%rbp)
mov    %rsi,-0x38(%rbp)
mov    %rdi,%r14
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
mov    %r13,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%r13,1)
je     121b <get_dir_count+0x6b>
lea    0xded(%rip),%rsi
mov    %r13,%rdi
call   10b0 <strcat@plt>
mov    %r13,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     12f7 <get_dir_count+0x147>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     12e0 <get_dir_count+0x130>
mov    %rax,%r15
lea    0xddb(%rip),%r14
jmp    1270 <get_dir_count+0xc0>
mov    0x2d75(%rip),%rax
mov    (%rax),%eax
test   %eax,-0x30(%rbp)
je     12b5 <get_dir_count+0x105>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10a0 <readdir@plt>
mov    %rax,%r15
test   %rax,%rax
je     12e0 <get_dir_count+0x130>
cmpl   $0x0,0x8(%r15)
je     1260 <get_dir_count+0xb0>
mov    (%r15),%rdi
cmpb   $0x2e,(%rdi)
je     1260 <get_dir_count+0xb0>
mov    %r14,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1260 <get_dir_count+0xb0>
mov    (%r15),%rcx
mov    %r12,%rdi
lea    0xd91(%rip),%rsi
mov    %r13,%rdx
call   10c0 <sprintf@plt>
mov    %r12,%rdi
lea    -0x30(%rbp),%rsi
call   1090 <stat@plt>
test   %eax,%eax
je     124c <get_dir_count+0x9c>
mov    (%r15),%rdi
call   1060 <strlen@plt>
mov    (%r15),%rcx
movslq %eax,%rdx
cmpb   $0x7e,-0x1(%rdx,%rcx,1)
je     1260 <get_dir_count+0xb0>
mov    -0x38(%rbp),%rcx
addl   $0x1,(%rcx)
mov    -0x40(%rbp),%rdx
mov    (%rdx),%ecx
cmp    %ecx,%eax
cmovg  %eax,%ecx
mov    %ecx,(%rdx)
jmp    1260 <get_dir_count+0xb0>
mov    %rbx,%rdi
call   1070 <closedir@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
lea    0xcfb(%rip),%rsi
mov    %r14,%rdx
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8*, i32 }
%struct.stat = type { i32 }
@MAXPATHLEN = global i32 0
@.str = [2 x i8] c"/\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"Error: Cannot open directory [%s]\0A\00"
@.str.2 = [9 x i8] c"Makefile\00"
@.str.3 = [5 x i8] c"%s%s\00"
@S_IFDIR = global i32 0
define void @get_dir_count(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca %struct.dirent*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
%13 = alloca %struct.stat
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%14 = load i32, i32* @MAXPATHLEN
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %9
%17 = alloca i8, i64 %15
store i64 %15, i64* %10
%18 = load i32, i32* @MAXPATHLEN
%19 = zext i32 %18 to i64
%20 = alloca i8, i64 %19
store i64 %19, i64* %11
%21 = load i8*, i8** %4
%22 = call i32 @strcpy(i8* %17, i8* %21)
%23 = call i32 @strlen(i8* %17)
store i32 %23, i32* %12
%24 = load i32, i32* %12
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %17, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 47
br i1 %30, label %31, label %33
31: ; preds = %3
%32 = call i32 @strcat(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %31, %3
%34 = call i32* @opendir(i8* %17)
store i32* %34, i32** %8
%35 = icmp ne i32* %34, null
br i1 %35, label %41, label %36
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %4
%39 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %33
br label %42
42: ; preds = %109, %95, %78, %64, %41
%43 = load i32*, i32** %8
%44 = call %struct.dirent* @readdir(i32* %43)
store %struct.dirent* %44, %struct.dirent** %7
%45 = icmp ne %struct.dirent* %44, null
br i1 %45, label %46, label %112
46: ; preds = %42
%47 = load %struct.dirent*, %struct.dirent** %7
%48 = getelementptr inbounds %struct.dirent, %struct.dirent* %47, i32 0, i32 1
%49 = load i32, i32* %48
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %64
51: ; preds = %46
%52 = load %struct.dirent*, %struct.dirent** %7
%53 = getelementptr inbounds %struct.dirent, %struct.dirent* %52, i32 0, i32 0
%54 = load i8*, i8** %53
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 46
br i1 %57, label %64, label %58
58: ; preds = %51
%59 = load %struct.dirent*, %struct.dirent** %7
%60 = getelementptr inbounds %struct.dirent, %struct.dirent* %59, i32 0, i32 0
%61 = load i8*, i8** %60
%62 = call i32 @strncmp(i8* %61, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%63 = icmp ne i32 %62, 0
br i1 %63, label %65, label %64
64: ; preds = %58, %51, %46
br label %42
65: ; preds = %58
%66 = load %struct.dirent*, %struct.dirent** %7
%67 = getelementptr inbounds %struct.dirent, %struct.dirent* %66, i32 0, i32 0
%68 = load i8*, i8** %67
%69 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %17, i8* %68)
%70 = call i32 @stat(i8* %20, %struct.stat* %13)
%71 = icmp ne i32 %70, 0
br i1 %71, label %80, label %72
72: ; preds = %65
%73 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%74 = load i32, i32* %73
%75 = load i32, i32* @S_IFDIR
%76 = and i32 %74, %75
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %79
78: ; preds = %72
br label %42
79: ; preds = %72
br label %80
80: ; preds = %79, %65
%81 = load %struct.dirent*, %struct.dirent** %7
%82 = getelementptr inbounds %struct.dirent, %struct.dirent* %81, i32 0, i32 0
%83 = load i8*, i8** %82
%84 = call i32 @strlen(i8* %83)
store i32 %84, i32* %12
%85 = load %struct.dirent*, %struct.dirent** %7
%86 = getelementptr inbounds %struct.dirent, %struct.dirent* %85, i32 0, i32 0
%87 = load i8*, i8** %86
%88 = load i32, i32* %12
%89 = sub nsw i32 %88, 1
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i8, i8* %87, i64 %90
%92 = load i8, i8* %91
%93 = sext i8 %92 to i32
%94 = icmp eq i32 %93, 126
br i1 %94, label %95, label %96
95: ; preds = %80
br label %42
96: ; preds = %80
%97 = load i32*, i32** %5
%98 = load i32, i32* %97
%99 = add nsw i32 %98, 1
store i32 %99, i32* %97
%100 = load i32, i32* %12
%101 = load i32*, i32** %6
%102 = load i32, i32* %101
%103 = icmp sgt i32 %100, %102
br i1 %103, label %104, label %106
104: ; preds = %96
%105 = load i32, i32* %12
br label %109
106: ; preds = %96
%107 = load i32*, i32** %6
%108 = load i32, i32* %107
br label %109
109: ; preds = %106, %104
%110 = phi i32 [ %105, %104 ], [ %108, %106 ]
%111 = load i32*, i32** %6
store i32 %110, i32* %111
br label %42
112: ; preds = %42
%113 = load i32*, i32** %8
%114 = call i32 @closedir(i32* %113)
%115 = load i8*, i8** %9
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8*, i32 }
@MAXPATHLEN = global i32 0
@.str = [2 x i8] c"/\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"Error: Cannot open directory [%s]\0A\00"
@.str.2 = [9 x i8] c"Makefile\00"
@.str.3 = [5 x i8] c"%s%s\00"
@S_IFDIR = global i32 0
define void @get_dir_count(i8* %0, i32* nocapture %1, i32* nocapture %2) {
%4 = alloca %struct.stat
%5 = load i32, i32* @MAXPATHLEN
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = alloca i8, i64 %6
%9 = bitcast %struct.stat* %4 to i8*
%10 = call i32 @strcpy(i8* %7, i8* %0)
%11 = call i32 @strlen(i8* %7)
%12 = add nsw i32 %11, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %7, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 47
br i1 %16, label %19, label %17
17: ; preds = %3
%18 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %3
%20 = call i32* @opendir(i8* %7)
%21 = icmp eq i32* %20, null
br i1 %21, label %27, label %22
22: ; preds = %19
%23 = call %struct.dirent* @readdir(i32* %20)
%24 = icmp eq %struct.dirent* %23, null
br i1 %24, label %72, label %25
25: ; preds = %22
%26 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
br label %31
27: ; preds = %19
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%30 = call i32 @exit(i32 -1)
unreachable
31: ; preds = %25, %44
%32 = phi %struct.dirent* [ %23, %25 ], [ %45, %44 ]
%33 = getelementptr inbounds %struct.dirent, %struct.dirent* %32, i64 0, i32 1
%34 = load i32, i32* %33
%35 = icmp eq i32 %34, 0
br i1 %35, label %44, label %36
36: ; preds = %31
%37 = getelementptr inbounds %struct.dirent, %struct.dirent* %32, i64 0, i32 0
%38 = load i8*, i8** %37
%39 = load i8, i8* %38
%40 = icmp eq i8 %39, 46
br i1 %40, label %44, label %41
41: ; preds = %36
%42 = call i32 @strncmp(i8* %38, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %31, %36, %41, %66, %52, %57
%45 = call %struct.dirent* @readdir(i32* %20)
%46 = icmp eq %struct.dirent* %45, null
br i1 %46, label %72, label %31
47: ; preds = %41
%48 = load i8*, i8** %37
%49 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %7, i8* %48)
%50 = call i32 @stat(i8* %8, %struct.stat* %4)
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %47
%53 = load i32, i32* %26
%54 = load i32, i32* @S_IFDIR
%55 = and i32 %54, %53
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %44
57: ; preds = %52, %47
%58 = load i8*, i8** %37
%59 = call i32 @strlen(i8* %58)
%60 = load i8*, i8** %37
%61 = add nsw i32 %59, -1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = load i8, i8* %63
%65 = icmp eq i8 %64, 126
br i1 %65, label %44, label %66
66: ; preds = %57
%67 = load i32, i32* %1
%68 = add nsw i32 %67, 1
store i32 %68, i32* %1
%69 = load i32, i32* %2
%70 = icmp sgt i32 %59, %69
%71 = select i1 %70, i32 %59, i32 %69
store i32 %71, i32* %2
br label %44
72: ; preds = %44, %22
%73 = call i32 @closedir(i32* %20)
ret void
}