#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 {
  int /*<<< orphan*/ d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ IsDirectory(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ plintf(char *, char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int strlen(int /*<<< orphan*/);
scalar_t__ wild_match(int /*<<< orphan*/, char const *);
int fil_count(const char *direct, int *ndir, int *nfil, const char *wild,
              int *mld, int *mlf) {
  DIR *dirp;
  int l;
  struct dirent *dp;
  *mld = 0;
  *mlf = 0;
  dirp = opendir(direct);
  if (dirp == NULL) {
    plintf(" % is not a directory \n", direct);
    return 0;
  }
  dp = readdir(dirp);
  *ndir = 0;
  *nfil = 0;
  while (dp != NULL) {
    if (IsDirectory(direct, dp->d_name)) {
      *ndir = *ndir + 1;
      l = strlen(dp->d_name);
      if (l > *mld)
        *mld = l;
    } else {
      if (wild_match(dp->d_name, wild)) {
        *nfil = *nfil + 1;
        l = strlen(dp->d_name);
        if (l > *mlf)
          *mlf = l;
      }
    }
    dp = readdir(dirp);
  }
  closedir(dirp);
  return 1;
}


x86 assembly (clang, -O0):
<fil_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x38(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11d8 <fil_count+0x68>
mov    -0x10(%rbp),%rsi
lea    0xe39(%rip),%rdi
call   1090 <plintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d1 <fil_count+0x161>
mov    -0x40(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
cmpq   $0x0,-0x50(%rbp)
je     12c1 <fil_count+0x151>
mov    -0x10(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    (%rax),%esi
call   1080 <IsDirectory@plt>
cmp    $0x0,%rax
je     1257 <fil_count+0xe7>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x50(%rbp),%rax
mov    (%rax),%edi
call   1040 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    -0x30(%rbp),%rcx
cmp    (%rcx),%eax
jle    1252 <fil_count+0xe2>
mov    -0x44(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
jmp    12af <fil_count+0x13f>
mov    -0x50(%rbp),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rsi
call   1050 <wild_match@plt>
cmp    $0x0,%rax
je     12aa <fil_count+0x13a>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x50(%rbp),%rax
mov    (%rax),%edi
call   1040 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    -0x38(%rbp),%rcx
cmp    (%rcx),%eax
jle    12a5 <fil_count+0x135>
mov    -0x44(%rbp),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
jmp    12aa <fil_count+0x13a>
jmp    12af <fil_count+0x13f>
mov    -0x40(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x50(%rbp)
jmp    11f9 <fil_count+0x89>
mov    -0x40(%rbp),%rdi
call   1060 <closedir@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fil_count>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,0x10(%rsp)
mov    %rdx,%r12
mov    %rsi,%rbp
mov    %rdi,%rbx
movl   $0x0,(%r8)
movl   $0x0,(%r9)
call   1030 <opendir@plt>
test   %rax,%rax
je     125d <fil_count+0xed>
mov    %rax,%r13
mov    %rax,%rdi
call   1070 <readdir@plt>
mov    %r12,%rcx
movl   $0x0,0x0(%rbp)
mov    %r12,0x8(%rsp)
movl   $0x0,(%r12)
test   %rax,%rax
je     124e <fil_count+0xde>
mov    %rax,%r12
jmp    11f0 <fil_count+0x80>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1070 <readdir@plt>
mov    %rax,%r12
test   %rax,%rax
je     124e <fil_count+0xde>
mov    (%r12),%esi
mov    %rbx,%rdi
call   1080 <IsDirectory@plt>
test   %rax,%rax
je     1220 <fil_count+0xb0>
addl   $0x1,0x0(%rbp)
mov    (%r12),%edi
call   1040 <strlen@plt>
cmp    (%r15),%eax
jle    11e0 <fil_count+0x70>
mov    %eax,(%r15)
jmp    11e0 <fil_count+0x70>
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    0x10(%rsp),%rsi
call   1050 <wild_match@plt>
test   %rax,%rax
je     11e0 <fil_count+0x70>
mov    0x8(%rsp),%rax
addl   $0x1,(%rax)
mov    (%r12),%edi
call   1040 <strlen@plt>
cmp    (%r14),%eax
jle    11e0 <fil_count+0x70>
mov    %eax,(%r14)
jmp    11e0 <fil_count+0x70>
mov    %r13,%rdi
call   1060 <closedir@plt>
mov    $0x1,%eax
jmp    126e <fil_count+0xfe>
lea    0xd9c(%rip),%rdi
mov    %rbx,%rsi
call   1090 <plintf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [24 x i8] c" % is not a directory \0A\00"
define i32 @fil_count(i8* %0, i32* %1, i32* %2, i8* %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32
%16 = alloca %struct.dirent*
store i8* %0, i8** %8
store i32* %1, i32** %9
store i32* %2, i32** %10
store i8* %3, i8** %11
store i32* %4, i32** %12
store i32* %5, i32** %13
%17 = load i32*, i32** %12
store i32 0, i32* %17
%18 = load i32*, i32** %13
store i32 0, i32* %18
%19 = load i8*, i8** %8
%20 = call i32* @opendir(i8* %19)
store i32* %20, i32** %14
%21 = load i32*, i32** %14
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %6
%24 = load i8*, i8** %8
%25 = call i32 @plintf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %24)
store i32 0, i32* %7
br label %89
26: ; preds = %6
%27 = load i32*, i32** %14
%28 = call %struct.dirent* @readdir(i32* %27)
store %struct.dirent* %28, %struct.dirent** %16
%29 = load i32*, i32** %9
store i32 0, i32* %29
%30 = load i32*, i32** %10
store i32 0, i32* %30
br label %31
31: ; preds = %83, %26
%32 = load %struct.dirent*, %struct.dirent** %16
%33 = icmp ne %struct.dirent* %32, null
br i1 %33, label %34, label %86
34: ; preds = %31
%35 = load i8*, i8** %8
%36 = load %struct.dirent*, %struct.dirent** %16
%37 = getelementptr inbounds %struct.dirent, %struct.dirent* %36, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i64 @IsDirectory(i8* %35, i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %58
41: ; preds = %34
%42 = load i32*, i32** %9
%43 = load i32, i32* %42
%44 = add nsw i32 %43, 1
%45 = load i32*, i32** %9
store i32 %44, i32* %45
%46 = load %struct.dirent*, %struct.dirent** %16
%47 = getelementptr inbounds %struct.dirent, %struct.dirent* %46, i32 0, i32 0
%48 = load i32, i32* %47
%49 = call i32 @strlen(i32 %48)
store i32 %49, i32* %15
%50 = load i32, i32* %15
%51 = load i32*, i32** %12
%52 = load i32, i32* %51
%53 = icmp sgt i32 %50, %52
br i1 %53, label %54, label %57
54: ; preds = %41
%55 = load i32, i32* %15
%56 = load i32*, i32** %12
store i32 %55, i32* %56
br label %57
57: ; preds = %54, %41
br label %83
58: ; preds = %34
%59 = load %struct.dirent*, %struct.dirent** %16
%60 = getelementptr inbounds %struct.dirent, %struct.dirent* %59, i32 0, i32 0
%61 = load i32, i32* %60
%62 = load i8*, i8** %11
%63 = call i64 @wild_match(i32 %61, i8* %62)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %82
65: ; preds = %58
%66 = load i32*, i32** %10
%67 = load i32, i32* %66
%68 = add nsw i32 %67, 1
%69 = load i32*, i32** %10
store i32 %68, i32* %69
%70 = load %struct.dirent*, %struct.dirent** %16
%71 = getelementptr inbounds %struct.dirent, %struct.dirent* %70, i32 0, i32 0
%72 = load i32, i32* %71
%73 = call i32 @strlen(i32 %72)
store i32 %73, i32* %15
%74 = load i32, i32* %15
%75 = load i32*, i32** %13
%76 = load i32, i32* %75
%77 = icmp sgt i32 %74, %76
br i1 %77, label %78, label %81
78: ; preds = %65
%79 = load i32, i32* %15
%80 = load i32*, i32** %13
store i32 %79, i32* %80
br label %81
81: ; preds = %78, %65
br label %82
82: ; preds = %81, %58
br label %83
83: ; preds = %82, %57
%84 = load i32*, i32** %14
%85 = call %struct.dirent* @readdir(i32* %84)
store %struct.dirent* %85, %struct.dirent** %16
br label %31
86: ; preds = %31
%87 = load i32*, i32** %14
%88 = call i32 @closedir(i32* %87)
store i32 1, i32* %7
br label %89
89: ; preds = %86, %23
%90 = load i32, i32* %7
ret i32 %90
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [24 x i8] c" % is not a directory \0A\00"
define i32 @fil_count(i8* %0, i32* nocapture %1, i32* nocapture %2, i8* %3, i32* nocapture %4, i32* nocapture %5) {
store i32 0, i32* %4
store i32 0, i32* %5
%7 = tail call i32* @opendir(i8* %0)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @plintf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %45
11: ; preds = %6
%12 = tail call %struct.dirent* @readdir(i32* %7)
store i32 0, i32* %1
store i32 0, i32* %2
%13 = icmp eq %struct.dirent* %12, null
br i1 %13, label %43, label %14
14: ; preds = %11, %40
%15 = phi %struct.dirent* [ %41, %40 ], [ %12, %11 ]
%16 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i64 0, i32 0
%17 = load i32, i32* %16
%18 = tail call i64 @IsDirectory(i8* %0, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %28, label %20
20: ; preds = %14
%21 = load i32, i32* %1
%22 = add nsw i32 %21, 1
store i32 %22, i32* %1
%23 = load i32, i32* %16
%24 = tail call i32 @strlen(i32 %23)
%25 = load i32, i32* %4
%26 = icmp sgt i32 %24, %25
br i1 %26, label %27, label %40
27: ; preds = %20
store i32 %24, i32* %4
br label %40
28: ; preds = %14
%29 = load i32, i32* %16
%30 = tail call i64 @wild_match(i32 %29, i8* %3)
%31 = icmp eq i64 %30, 0
br i1 %31, label %40, label %32
32: ; preds = %28
%33 = load i32, i32* %2
%34 = add nsw i32 %33, 1
store i32 %34, i32* %2
%35 = load i32, i32* %16
%36 = tail call i32 @strlen(i32 %35)
%37 = load i32, i32* %5
%38 = icmp sgt i32 %36, %37
br i1 %38, label %39, label %40
39: ; preds = %32
store i32 %36, i32* %5
br label %40
40: ; preds = %28, %39, %32, %20, %27
%41 = tail call %struct.dirent* @readdir(i32* %7)
%42 = icmp eq %struct.dirent* %41, null
br i1 %42, label %43, label %14
43: ; preds = %40, %11
%44 = tail call i32 @closedir(i32* %7)
br label %45
45: ; preds = %43, %9
%46 = phi i32 [ 0, %9 ], [ 1, %43 ]
ret i32 %46
}