#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*/ *opendir(char const *);
int /*<<< orphan*/ process_file(int /*<<< orphan*/, char const *, int);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strncmp(int /*<<< orphan*/, char *, int);
void populate_desktop_and_directory_lists(const char *path, int isdir) {
  struct dirent *entry;
  DIR *dp;
  dp = opendir(path);
  if (!dp)
    goto close_dir;
  while ((entry = readdir(dp))) {
    if (!strncmp(entry->d_name, ".", 1) || !strncmp(entry->d_name, "..", 2))
      continue;
    process_file(entry->d_name, path, isdir);
  }
close_dir:
  closedir(dp);
}


x86 assembly (clang, -O0):
<populate_desktop_and_directory_lists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117c <populate_desktop_and_directory_lists+0x2c>
jmp    11f9 <populate_desktop_and_directory_lists+0xa9>
jmp    1181 <populate_desktop_and_directory_lists+0x31>
mov    -0x20(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11f4 <populate_desktop_and_directory_lists+0xa4>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
je     11d8 <populate_desktop_and_directory_lists+0x88>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11dd <populate_desktop_and_directory_lists+0x8d>
jmp    1181 <populate_desktop_and_directory_lists+0x31>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <process_file@plt>
jmp    1181 <populate_desktop_and_directory_lists+0x31>
jmp    11f9 <populate_desktop_and_directory_lists+0xa9>
mov    -0x20(%rbp),%rdi
call   1060 <closedir@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<populate_desktop_and_directory_lists>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
call   1040 <opendir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11d5 <populate_desktop_and_directory_lists+0x85>
mov    %rbp,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11d5 <populate_desktop_and_directory_lists+0x85>
mov    %rax,%rbx
lea    0xe7c(%rip),%r13
lea    0xe74(%rip),%r12
jmp    11a0 <populate_desktop_and_directory_lists+0x50>
xchg   %ax,%ax
mov    %rbp,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11d5 <populate_desktop_and_directory_lists+0x85>
mov    (%rbx),%edi
mov    %r13,%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1190 <populate_desktop_and_directory_lists+0x40>
mov    (%rbx),%edi
mov    %r12,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1190 <populate_desktop_and_directory_lists+0x40>
mov    (%rbx),%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1050 <process_file@plt>
jmp    1190 <populate_desktop_and_directory_lists+0x40>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <closedir@plt>

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

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
define void @populate_desktop_and_directory_lists(i8* %0, i32 %1) {
%3 = tail call i32* @opendir(i8* %0)
%4 = icmp eq i32* %3, null
br i1 %4, label %24, label %5
5: ; preds = %2
%6 = tail call %struct.dirent* @readdir(i32* %3)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %24, label %8
8: ; preds = %5, %18
%9 = phi %struct.dirent* [ %19, %18 ], [ %6, %5 ]
%10 = getelementptr inbounds %struct.dirent, %struct.dirent* %9, i64 0, i32 0
%11 = load i32, i32* %10
%12 = tail call i32 @strncmp(i32 %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %8
%15 = load i32, i32* %10
%16 = tail call i32 @strncmp(i32 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %8, %14, %21
%19 = tail call %struct.dirent* @readdir(i32* %3)
%20 = icmp eq %struct.dirent* %19, null
br i1 %20, label %24, label %8
21: ; preds = %14
%22 = load i32, i32* %10
%23 = tail call i32 @process_file(i32 %22, i8* %0, i32 %1)
br label %18
24: ; preds = %18, %5, %2
%25 = tail call i32 @closedir(i32* %3)
ret void
}