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

/* Variables and functions */
int /*<<< orphan*/ build_path(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
scalar_t__ is_dir(struct stat *);
scalar_t__ is_file(struct stat *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ process_file(char *, struct stat *);
int /*<<< orphan*/ puts(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int stat(char *, struct stat *);
int /*<<< orphan*/ string_is_in_list(char const *, int /*<<< orphan*/);
void walk(char *path, const char *blacklist) {
  DIR *stream;
  struct dirent *item;
  struct stat info;
  stream = opendir(path);
  if (stream != NULL) {
    while ((item = readdir(stream))) {
      if (!string_is_in_list(blacklist, item->d_name)) {
        char full_path[1024];
        build_path(full_path, path, item->d_name);
        int got_info = stat(full_path, &info);
        int success = !got_info;
        if (success) {
          if (is_dir(&info)) {
            walk(full_path, blacklist);
          } else if (is_file(&info)) {
            process_file(full_path, &info);
          }
        } else {
          puts("Could not get any information on this file:");
          printf("%s\n", full_path);
          exit(1);
        }
      }
    }
  } else {
    puts("Could not open the following path:");
    printf("%s\n", path);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<walk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12fc <walk+0x13c>
jmp    11f0 <walk+0x30>
mov    -0x18(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     12f7 <walk+0x137>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1030 <string_is_in_list@plt>
cmp    $0x0,%eax
jne    12f2 <walk+0x132>
lea    -0x430(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   1040 <build_path@plt>
lea    -0x430(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10a0 <stat@plt>
mov    %eax,-0x434(%rbp)
cmpl   $0x0,-0x434(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x438(%rbp)
cmpl   $0x0,-0x438(%rbp)
je     12c4 <walk+0x104>
lea    -0x28(%rbp),%rdi
call   1090 <is_dir@plt>
cmp    $0x0,%rax
je     1297 <walk+0xd7>
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10e0 <walk@plt>
jmp    12bf <walk+0xff>
lea    -0x28(%rbp),%rdi
call   10c0 <is_file@plt>
cmp    $0x0,%rax
je     12ba <walk+0xfa>
lea    -0x430(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <process_file@plt>
jmp    12bf <walk+0xff>
jmp    12ed <walk+0x12d>
lea    0xd35(%rip),%rdi
call   1050 <puts@plt>
lea    -0x430(%rbp),%rsi
lea    0xd4e(%rip),%rdi
call   1080 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    12f2 <walk+0x132>
jmp    11f0 <walk+0x30>
jmp    1322 <walk+0x162>
lea    0xd2d(%rip),%rdi
call   1050 <puts@plt>
mov    -0x8(%rbp),%rsi
lea    0xd19(%rip),%rdi
call   1080 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<walk>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
call   1060 <opendir@plt>
test   %rax,%rax
je     12b7 <walk+0xf7>
mov    %rax,%r15
mov    %rax,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     127e <walk+0xbe>
mov    %rax,%rbp
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%r13
jmp    122b <walk+0x6b>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   10e0 <walk@plt>
mov    %r15,%rdi
call   10b0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     127e <walk+0xbe>
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1030 <string_is_in_list@plt>
test   %eax,%eax
jne    121b <walk+0x5b>
mov    0x0(%rbp),%edx
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <build_path@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   10a0 <stat@plt>
test   %eax,%eax
jne    1290 <walk+0xd0>
mov    %r13,%rdi
call   1090 <is_dir@plt>
test   %rax,%rax
jne    1210 <walk+0x50>
mov    %r13,%rdi
call   10c0 <is_file@plt>
test   %rax,%rax
je     121b <walk+0x5b>
mov    %r12,%rdi
mov    %r13,%rsi
call   1070 <process_file@plt>
jmp    121b <walk+0x5b>
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd69(%rip),%rdi
call   1050 <puts@plt>
lea    0xd89(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1080 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xd72(%rip),%rdi
call   1050 <puts@plt>
lea    0xd62(%rip),%rdi
mov    %r14,%rsi
jmp    12a8 <walk+0xe8>

LLVM IR (-O0):
%struct.dirent = type { i32 }
%struct.stat = type { i32 }
@.str = [44 x i8] c"Could not get any information on this file:\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [35 x i8] c"Could not open the following path:\00"
define void @walk(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca %struct.dirent*
%7 = alloca %struct.stat
%8 = alloca [1024 x i8]
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = load i8*, i8** %3
%12 = call i32* @opendir(i8* %11)
store i32* %12, i32** %5
%13 = load i32*, i32** %5
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %64
15: ; preds = %2
br label %16
16: ; preds = %62, %15
%17 = load i32*, i32** %5
%18 = call %struct.dirent* @readdir(i32* %17)
store %struct.dirent* %18, %struct.dirent** %6
%19 = icmp ne %struct.dirent* %18, null
br i1 %19, label %20, label %63
20: ; preds = %16
%21 = load i8*, i8** %4
%22 = load %struct.dirent*, %struct.dirent** %6
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @string_is_in_list(i8* %21, i32 %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %62, label %27
27: ; preds = %20
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%29 = load i8*, i8** %3
%30 = load %struct.dirent*, %struct.dirent** %6
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 @build_path(i8* %28, i8* %29, i32 %32)
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%35 = call i32 @stat(i8* %34, %struct.stat* %7)
store i32 %35, i32* %9
%36 = load i32, i32* %9
%37 = icmp ne i32 %36, 0
%38 = xor i1 %37, true
%39 = zext i1 %38 to i32
store i32 %39, i32* %10
%40 = load i32, i32* %10
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %56
42: ; preds = %27
%43 = call i64 @is_dir(%struct.stat* %7)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%47 = load i8*, i8** %4
br label %55
48: ; preds = %42
%49 = call i64 @is_file(%struct.stat* %7)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%53 = call i32 @process_file(i8* %52, %struct.stat* %7)
br label %54
54: ; preds = %51, %48
br label %55
55: ; preds = %54, %45
br label %61
56: ; preds = %27
%57 = call i32 @puts(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%59 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %58)
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %55
br label %62
62: ; preds = %61, %20
br label %16
63: ; preds = %16
br label %69
64: ; preds = %2
%65 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%66 = load i8*, i8** %3
%67 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %66)
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %63
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i32 }
@.str = [44 x i8] c"Could not get any information on this file:\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [35 x i8] c"Could not open the following path:\00"
define void @walk(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = alloca [1024 x i8]
%5 = bitcast %struct.stat* %3 to i8*
%6 = tail call i32* @opendir(i8* %0)
%7 = icmp eq i32* %6, null
br i1 %7, label %41, label %8
8: ; preds = %2
%9 = call %struct.dirent* @readdir(i32* %6)
%10 = icmp eq %struct.dirent* %9, null
br i1 %10, label %45, label %11
11: ; preds = %8
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
br label %13
13: ; preds = %11, %38
%14 = phi %struct.dirent* [ %9, %11 ], [ %39, %38 ]
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @string_is_in_list(i8* %1, i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %38
19: ; preds = %13
%20 = load i32, i32* %15
%21 = call i32 @build_path(i8* %12, i8* %0, i32 %20)
%22 = call i32 @stat(i8* %12, %struct.stat* %3)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %33
24: ; preds = %19
%25 = call i64 @is_dir(%struct.stat* %3)
%26 = icmp eq i64 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %24
br label %37
28: ; preds = %24
%29 = call i64 @is_file(%struct.stat* %3)
%30 = icmp eq i64 %29, 0
br i1 %30, label %37, label %31
31: ; preds = %28
%32 = call i32 @process_file(i8* %12, %struct.stat* %3)
br label %37
33: ; preds = %19
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %27, %31, %28
br label %38
38: ; preds = %37, %13
%39 = call %struct.dirent* @readdir(i32* %6)
%40 = icmp eq %struct.dirent* %39, null
br i1 %40, label %45, label %13
41: ; preds = %2
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%43 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %38, %8
ret void
}