#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 {
  char *d_name;
  scalar_t__ d_type;
};
typedef int /*<<< orphan*/ full_path;
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ DT_DIR;
scalar_t__ DT_REG;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memcmp(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ process_file(int /*<<< orphan*/ *, char *, char const *,
                                char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char *);
char *strerror(int);
int /*<<< orphan*/ strlen(char *);
int process_dir(FILE *output, const char *path, const char *start_tag,
                const char *end_tag) {
  DIR *dir;
  struct dirent *dir_ent;
  printf("Processing %s ..\n", path);
  dir = opendir(path);
  if (!dir) {
    printf("ERROR: opendir() failed errno: %d (%s)\n", errno, strerror(errno));
    exit(1);
  }
  while ((dir_ent = readdir(dir))) {
    char full_path[1000];
    if (!(memcmp(dir_ent->d_name, ".", strlen("."))))
      continue;
    snprintf(full_path, sizeof(full_path), "%s/%s", path, dir_ent->d_name);
    if (dir_ent->d_type == DT_REG) {
      process_file(output, full_path, start_tag, end_tag);
    } else if (dir_ent->d_type == DT_DIR) {
      process_dir(output, full_path, start_tag, end_tag);
    } else {
    }
  }
  closedir(dir);
  return 0;
}


x86 assembly (clang, -O0):
<process_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1233 <process_dir+0x83>
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x424(%rbp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x424(%rbp),%esi
mov    %rax,%rdx
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    1238 <process_dir+0x88>
mov    -0x28(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1328 <process_dir+0x178>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x430(%rbp)
lea    0xdd6(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x430(%rbp),%rdi
mov    %eax,%edx
lea    0xdc1(%rip),%rsi
call   1090 <memcmp@plt>
cmp    $0x0,%eax
jne    128c <process_dir+0xdc>
jmp    1238 <process_dir+0x88>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    (%rax),%r8
mov    $0x3e8,%esi
lea    0xd92(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2d22(%rip),%rcx
cmp    (%rcx),%rax
jne    12e4 <process_dir+0x134>
mov    -0x8(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1050 <process_file@plt>
jmp    1323 <process_dir+0x173>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2ce5(%rip),%rcx
cmp    (%rcx),%rax
jne    1319 <process_dir+0x169>
mov    -0x8(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   10b0 <process_dir@plt>
jmp    131e <process_dir+0x16e>
jmp    131e <process_dir+0x16e>
jmp    1323 <process_dir+0x173>
jmp    1238 <process_dir+0x88>
mov    -0x28(%rbp),%rdi
call   1080 <closedir@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_dir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rcx,0x18(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rsi,%r13
mov    %rdi,0x8(%rsp)
lea    0xe26(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     12ce <process_dir+0x11e>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     12b2 <process_dir+0x102>
mov    %rax,%r15
lea    0xe2a(%rip),%rbp
lea    0x20(%rsp),%r14
jmp    1247 <process_dir+0x97>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    0x10(%rsp),%rdx
mov    0x18(%rsp),%rcx
call   1050 <process_file@plt>
mov    %rbx,%rdi
call   10a0 <readdir@plt>
mov    %rax,%r15
test   %rax,%rax
je     12b2 <process_dir+0x102>
mov    (%r15),%r12
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1090 <memcmp@plt>
test   %eax,%eax
je     1237 <process_dir+0x87>
mov    (%r15),%r8
mov    %r14,%rdi
mov    $0x3e8,%esi
lea    0xdc7(%rip),%rdx
mov    %r13,%rcx
call   1070 <snprintf@plt>
mov    0x8(%r15),%rax
mov    0x2d58(%rip),%rcx
cmp    (%rcx),%rax
je     1220 <process_dir+0x70>
mov    0x2d44(%rip),%rcx
cmp    (%rcx),%rax
jne    1237 <process_dir+0x87>
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    0x10(%rsp),%rdx
mov    0x18(%rsp),%rcx
call   10b0 <process_dir@plt>
jmp    1237 <process_dir+0x87>
mov    %rbx,%rdi
call   1080 <closedir@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cfb(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10d0 <strerror@plt>
lea    0xd2d(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8*, i64 }
@.str = [18 x i8] c"Processing %s ..\0A\00"
@.str.1 = [40 x i8] c"ERROR: opendir() failed errno: %d (%s)\0A\00"
@errno = global i32 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [6 x i8] c"%s/%s\00"
@DT_REG = global i64 0
@DT_DIR = global i64 0
define i32 @process_dir(i32* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca %struct.dirent*
%11 = alloca [1000 x i8]
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%12 = load i8*, i8** %6
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %6
%15 = call i32* @opendir(i8* %14)
store i32* %15, i32** %9
%16 = load i32*, i32** %9
%17 = icmp ne i32* %16, null
br i1 %17, label %24, label %18
18: ; preds = %4
%19 = load i32, i32* @errno
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %19, i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %4
br label %25
25: ; preds = %69, %36, %24
%26 = load i32*, i32** %9
%27 = call %struct.dirent* @readdir(i32* %26)
store %struct.dirent* %27, %struct.dirent** %10
%28 = icmp ne %struct.dirent* %27, null
br i1 %28, label %29, label %70
29: ; preds = %25
%30 = load %struct.dirent*, %struct.dirent** %10
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %30, i32 0, i32 0
%32 = load i8*, i8** %31
%33 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @memcmp(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %29
br label %25
37: ; preds = %29
%38 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%39 = load i8*, i8** %6
%40 = load %struct.dirent*, %struct.dirent** %10
%41 = getelementptr inbounds %struct.dirent, %struct.dirent* %40, i32 0, i32 0
%42 = load i8*, i8** %41
%43 = call i32 @snprintf(i8* %38, i32 1000, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %39, i8* %42)
%44 = load %struct.dirent*, %struct.dirent** %10
%45 = getelementptr inbounds %struct.dirent, %struct.dirent* %44, i32 0, i32 1
%46 = load i64, i64* %45
%47 = load i64, i64* @DT_REG
%48 = icmp eq i64 %46, %47
br i1 %48, label %49, label %55
49: ; preds = %37
%50 = load i32*, i32** %5
%51 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%52 = load i8*, i8** %7
%53 = load i8*, i8** %8
%54 = call i32 @process_file(i32* %50, i8* %51, i8* %52, i8* %53)
br label %69
55: ; preds = %37
%56 = load %struct.dirent*, %struct.dirent** %10
%57 = getelementptr inbounds %struct.dirent, %struct.dirent* %56, i32 0, i32 1
%58 = load i64, i64* %57
%59 = load i64, i64* @DT_DIR
%60 = icmp eq i64 %58, %59
br i1 %60, label %61, label %67
61: ; preds = %55
%62 = load i32*, i32** %5
%63 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%64 = load i8*, i8** %7
%65 = load i8*, i8** %8
%66 = call i32 @process_dir(i32* %62, i8* %63, i8* %64, i8* %65)
br label %68
67: ; preds = %55
br label %68
68: ; preds = %67, %61
br label %69
69: ; preds = %68, %49
br label %25
70: ; preds = %25
%71 = load i32*, i32** %9
%72 = call i32 @closedir(i32* %71)
ret i32 0
}

LLVM IR (-O2):
%struct.dirent = type { i8*, i64 }
@.str = [18 x i8] c"Processing %s ..\0A\00"
@.str.1 = [40 x i8] c"ERROR: opendir() failed errno: %d (%s)\0A\00"
@errno = global i32 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [6 x i8] c"%s/%s\00"
@DT_REG = global i64 0
@DT_DIR = global i64 0
define i32 @process_dir(i32* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca [1000 x i8]
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %1)
%7 = tail call i32* @opendir(i8* %1)
%8 = icmp eq i32* %7, null
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = call %struct.dirent* @readdir(i32* %7)
%11 = icmp eq %struct.dirent* %10, null
br i1 %11, label %43, label %12
12: ; preds = %9
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
br label %19
14: ; preds = %4
%15 = load i32, i32* @errno
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %15, i8* %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %12, %40
%20 = phi %struct.dirent* [ %10, %12 ], [ %41, %40 ]
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i64 0, i32 0
%22 = load i8*, i8** %21
%23 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @memcmp(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %40, label %26
26: ; preds = %19
%27 = load i8*, i8** %21
%28 = call i32 @snprintf(i8* %13, i32 1000, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %27)
%29 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i64 0, i32 1
%30 = load i64, i64* %29
%31 = load i64, i64* @DT_REG
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 @process_file(i32* %0, i8* %13, i8* %2, i8* %3)
br label %40
35: ; preds = %26
%36 = load i64, i64* @DT_DIR
%37 = icmp eq i64 %30, %36
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 @process_dir(i32* %0, i8* %13, i8* %2, i8* %3)
br label %40
40: ; preds = %33, %35, %38, %19
%41 = call %struct.dirent* @readdir(i32* %7)
%42 = icmp eq %struct.dirent* %41, null
br i1 %42, label %43, label %19
43: ; preds = %40, %9
%44 = call i32 @closedir(i32* %7)
ret i32 0
}