#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 */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *do_opendir(char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int dirobjectcount(const char *path) {
  DIR *dp;
  struct dirent *de;
  int objcount = 0;
  dp = do_opendir(path);
  while ((de = readdir(dp))) {
    if (strcmp(de->d_name, ".") == 0)
      continue;
    if (strcmp(de->d_name, "..") == 0)
      continue;
    objcount++;
  }
  closedir(dp);
  return objcount;
}


x86 assembly (clang, -O0):
<dirobjectcount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <do_opendir@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11c7 <dirobjectcount+0x87>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1198 <dirobjectcount+0x58>
jmp    1160 <dirobjectcount+0x20>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11b9 <dirobjectcount+0x79>
jmp    1160 <dirobjectcount+0x20>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1160 <dirobjectcount+0x20>
mov    -0x10(%rbp),%rdi
call   1030 <closedir@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dirobjectcount>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
call   1050 <do_opendir@plt>
mov    %rax,%rbx
xor    %r14d,%r14d
lea    0xea7(%rip),%r12
lea    0xe9f(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11a4 <dirobjectcount+0x64>
mov    %rax,%rbp
mov    (%rax),%edi
mov    %r12,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1170 <dirobjectcount+0x30>
mov    0x0(%rbp),%edi
mov    %r15,%rsi
call   1040 <strcmp@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%r14d
jmp    1170 <dirobjectcount+0x30>
mov    %rbx,%rdi
call   1030 <closedir@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
define i32 @dirobjectcount(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %5
%6 = load i8*, i8** %2
%7 = call i32* @do_opendir(i8* %6)
store i32* %7, i32** %3
br label %8
8: ; preds = %26, %25, %18, %1
%9 = load i32*, i32** %3
%10 = call %struct.dirent* @readdir(i32* %9)
store %struct.dirent* %10, %struct.dirent** %4
%11 = icmp ne %struct.dirent* %10, null
br i1 %11, label %12, label %29
12: ; preds = %8
%13 = load %struct.dirent*, %struct.dirent** %4
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i64 @strcmp(i32 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %12
br label %8
19: ; preds = %12
%20 = load %struct.dirent*, %struct.dirent** %4
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i64 @strcmp(i32 %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %19
br label %8
26: ; preds = %19
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %8
29: ; preds = %8
%30 = load i32*, i32** %3
%31 = call i32 @closedir(i32* %30)
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
define i32 @dirobjectcount(i8* %0) {
%2 = tail call i32* @do_opendir(i8* %0)
br label %3
3: ; preds = %13, %1
%4 = phi i32 [ %19, %13 ], [ 0, %1 ]
br label %5
5: ; preds = %3, %8
%6 = tail call %struct.dirent* @readdir(i32* %2)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %20, label %8
8: ; preds = %5
%9 = getelementptr inbounds %struct.dirent, %struct.dirent* %6, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i64 @strcmp(i32 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %5, label %13
13: ; preds = %8
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %6, i64 0, i32 0
%15 = load i32, i32* %14
%16 = tail call i64 @strcmp(i32 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
%18 = zext i1 %17 to i32
%19 = add nuw nsw i32 %4, %18
br label %3
20: ; preds = %5
%21 = tail call i32 @closedir(i32* %2)
ret i32 %4
}