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

/* Variables and functions */
int DT_BLK;
int DT_CHR;
int DT_DIR;
int DT_FIFO;
int DT_LNK;
int DT_REG;
int DT_SOCK;
int DT_UNKNOWN;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
void foreach_dir(char *path, int depth) {
  DIR *Dir;
  struct stat statbuf;
  char whole_path[1024];
  struct dirent *Entry = NULL;
  snprintf(whole_path, sizeof(whole_path), "%s", path);
  Dir = opendir(whole_path);
  if (!Dir) {
    fprintf(stderr, "Cannot Open Directory \"%s\"\n", path);
    return;
  }
  while (NULL != (Entry = readdir(Dir))) {
    if (0 == strcmp(".", Entry->d_name) || 0 == strcmp("..", Entry->d_name)) {
      continue;
    } else {
      char sub_path[1024];
      snprintf(sub_path, sizeof(sub_path), "%s/%s", whole_path, Entry->d_name);
      if (Entry->d_type & DT_DIR) {
        printf("Folder: \"%s\"\r\n", sub_path);
        if (0 == depth || depth > 1) {
          foreach_dir(sub_path, depth > 1 ? depth - 1 : depth);
        }
      } else if (Entry->d_type & DT_BLK) {
        printf("Block Device: \"%s\"\r\n", sub_path);
      } else if (Entry->d_type & DT_CHR) {
        printf("Character Device: \"%s\"\r\n", sub_path);
      } else if (Entry->d_type & DT_FIFO) {
        printf("Named PIPE: \"%s\"\r\n", sub_path);
      } else if (Entry->d_type & DT_LNK) {
        printf("Symbolic Link: \"%s\"\r\n", sub_path);
      } else if (Entry->d_type & DT_REG) {
        printf("Regular File: \"%s\"\r\n", sub_path);
      } else if (Entry->d_type & DT_SOCK) {
        printf("UNIX Domain Socket: \"%s\"\r\n", sub_path);
      } else if (Entry->d_type & DT_UNKNOWN) {
        printf("Unknow File: \"%s\"\r\n", sub_path);
      }
    }
  }
  closedir(Dir);
}


x86 assembly (clang, -O0):
<foreach_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x400,%esi
lea    0xe6e(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x420(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f4 <foreach_dir+0x74>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe16(%rip),%rsi
call   1090 <fprintf@plt>
jmp    14b9 <foreach_dir+0x339>
jmp    11f9 <foreach_dir+0x79>
mov    -0x18(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,%rcx
mov    %rcx,-0x428(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     14b0 <foreach_dir+0x330>
mov    -0x428(%rbp),%rax
mov    (%rax),%rsi
lea    0xdf5(%rip),%rdi
call   1080 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     125f <foreach_dir+0xdf>
mov    -0x428(%rbp),%rax
mov    (%rax),%rsi
lea    0xdd0(%rip),%rdi
call   1080 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1264 <foreach_dir+0xe4>
jmp    11f9 <foreach_dir+0x79>
lea    -0x830(%rbp),%rdi
lea    -0x420(%rbp),%rcx
mov    -0x428(%rbp),%rax
mov    (%rax),%r8
mov    $0x400,%esi
lea    0xd97(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    -0x428(%rbp),%rax
mov    0x8(%rax),%eax
mov    0x2d28(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     131c <foreach_dir+0x19c>
lea    -0x830(%rbp),%rsi
lea    0xd6c(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
je     12d3 <foreach_dir+0x153>
cmpl   $0x1,-0xc(%rbp)
jle    1317 <foreach_dir+0x197>
lea    -0x830(%rbp),%rax
mov    %rax,-0x838(%rbp)
cmpl   $0x1,-0xc(%rbp)
jle    12fc <foreach_dir+0x17c>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x83c(%rbp)
jmp    1305 <foreach_dir+0x185>
mov    -0xc(%rbp),%eax
mov    %eax,-0x83c(%rbp)
mov    -0x838(%rbp),%rdi
mov    -0x83c(%rbp),%esi
call   1030 <foreach_dir@plt>
jmp    14a6 <foreach_dir+0x326>
mov    -0x428(%rbp),%rax
mov    0x8(%rax),%eax
mov    0x2c93(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1350 <foreach_dir+0x1d0>
lea    -0x830(%rbp),%rsi
lea    0xcee(%rip),%rdi
call   1050 <printf@plt>
jmp    14a1 <foreach_dir+0x321>
mov    -0x428(%rbp),%rax
mov    0x8(%rax),%eax
mov    0x2c57(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1384 <foreach_dir+0x204>
lea    -0x830(%rbp),%rsi
lea    0xccf(%rip),%rdi
call   1050 <printf@plt>
jmp    149c <foreach_dir+0x31c>
mov    -0x428(%rbp),%rax
mov    0x8(%rax),%eax
mov    0x2c0b(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     13b8 <foreach_dir+0x238>
lea    -0x830(%rbp),%rsi
lea    0xcb4(%rip),%rdi
call   1050 <printf@plt>
jmp    1497 <foreach_dir+0x317>
mov    -0x428(%rbp),%rax
mov    0x8(%rax),%eax
mov    0x2be7(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     13ec <foreach_dir+0x26c>
lea    -0x830(%rbp),%rsi
lea    0xc93(%rip),%rdi
call   1050 <printf@plt>
jmp    1492 <foreach_dir+0x312>
mov    -0x428(%rbp),%rax
mov    0x8(%rax),%eax
mov    0x2bdb(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1420 <foreach_dir+0x2a0>
lea    -0x830(%rbp),%rsi
lea    0xc75(%rip),%rdi
call   1050 <printf@plt>
jmp    148d <foreach_dir+0x30d>
mov    -0x428(%rbp),%rax
mov    0x8(%rax),%eax
mov    0x2b67(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1454 <foreach_dir+0x2d4>
lea    -0x830(%rbp),%rsi
lea    0xc56(%rip),%rdi
call   1050 <printf@plt>
jmp    1488 <foreach_dir+0x308>
mov    -0x428(%rbp),%rax
mov    0x8(%rax),%eax
mov    0x2b83(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1483 <foreach_dir+0x303>
lea    -0x830(%rbp),%rsi
lea    0xc3d(%rip),%rdi
call   1050 <printf@plt>
jmp    1488 <foreach_dir+0x308>
jmp    148d <foreach_dir+0x30d>
jmp    1492 <foreach_dir+0x312>
jmp    1497 <foreach_dir+0x317>
jmp    149c <foreach_dir+0x31c>
jmp    14a1 <foreach_dir+0x321>
jmp    14a6 <foreach_dir+0x326>
jmp    14ab <foreach_dir+0x32b>
jmp    11f9 <foreach_dir+0x79>
mov    -0x18(%rbp),%rdi
call   1070 <closedir@plt>
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foreach_dir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %esi,%r14d
mov    %rdi,%rbp
lea    0xe84(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %rbp,%rcx
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     1356 <foreach_dir+0x1d6>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     134c <foreach_dir+0x1cc>
mov    %rax,%r12
mov    %r14d,%ecx
test   %r14d,%r14d
sete   %r14b
xor    %eax,%eax
cmp    $0x2,%ecx
setge  %al
or     %al,%r14b
sub    %eax,%ecx
mov    %ecx,0xc(%rsp)
lea    0xe1e(%rip),%rbp
lea    0xe16(%rip),%r15
lea    0x410(%rsp),%r13
jmp    1244 <foreach_dir+0xc4>
mov    0x2da9(%rip),%rcx
test   %eax,(%rcx)
je     12be <foreach_dir+0x13e>
lea    0xe0e(%rip),%rdi
mov    %r13,%rsi
call   1050 <printf@plt>
xchg   %ax,%ax
mov    %rbx,%rdi
call   10a0 <readdir@plt>
mov    %rax,%r12
test   %rax,%rax
je     134c <foreach_dir+0x1cc>
mov    (%r12),%rsi
mov    %rbp,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1230 <foreach_dir+0xb0>
mov    (%r12),%rsi
mov    %r15,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1230 <foreach_dir+0xb0>
mov    (%r12),%r8
mov    %r13,%rdi
mov    $0x400,%esi
lea    0xda6(%rip),%rdx
lea    0x10(%rsp),%rcx
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    0x8(%r12),%eax
mov    0x2d37(%rip),%rcx
test   %eax,(%rcx)
je     1210 <foreach_dir+0x90>
lea    0xd85(%rip),%rdi
mov    %r13,%rsi
call   1050 <printf@plt>
test   %r14b,%r14b
je     1230 <foreach_dir+0xb0>
mov    %r13,%rdi
mov    0xc(%rsp),%esi
call   1030 <foreach_dir@plt>
jmp    1230 <foreach_dir+0xb0>
mov    0x2cf3(%rip),%rcx
test   %eax,(%rcx)
je     12d5 <foreach_dir+0x155>
lea    0xd79(%rip),%rdi
jmp    1226 <foreach_dir+0xa6>
mov    0x2cc4(%rip),%rcx
test   %eax,(%rcx)
je     12ec <foreach_dir+0x16c>
lea    0xd7b(%rip),%rdi
jmp    1226 <foreach_dir+0xa6>
mov    0x2cbd(%rip),%rcx
test   %eax,(%rcx)
je     1303 <foreach_dir+0x183>
lea    0xd77(%rip),%rdi
jmp    1226 <foreach_dir+0xa6>
mov    0x2cce(%rip),%rcx
test   %eax,(%rcx)
je     131a <foreach_dir+0x19a>
lea    0xd76(%rip),%rdi
jmp    1226 <foreach_dir+0xa6>
mov    0x2c77(%rip),%rcx
test   %eax,(%rcx)
je     1331 <foreach_dir+0x1b1>
lea    0xd74(%rip),%rdi
jmp    1226 <foreach_dir+0xa6>
mov    0x2cb0(%rip),%rcx
test   %eax,(%rcx)
je     1230 <foreach_dir+0xb0>
lea    0xd74(%rip),%rdi
jmp    1226 <foreach_dir+0xa6>
mov    %rbx,%rdi
call   1070 <closedir@plt>
jmp    136e <foreach_dir+0x1ee>
mov    0x2c73(%rip),%rax
mov    (%rax),%edi
lea    0xc9a(%rip),%rsi
mov    %rbp,%rdx
call   1090 <fprintf@plt>
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.dirent = type { i8*, i32 }
@.str = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"Cannot Open Directory \22%s\22\0A\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [6 x i8] c"%s/%s\00"
@DT_DIR = global i32 0
@.str.5 = [15 x i8] c"Folder: \22%s\22\0D\0A\00"
@DT_BLK = global i32 0
@.str.6 = [21 x i8] c"Block Device: \22%s\22\0D\0A\00"
@DT_CHR = global i32 0
@.str.7 = [25 x i8] c"Character Device: \22%s\22\0D\0A\00"
@DT_FIFO = global i32 0
@.str.8 = [19 x i8] c"Named PIPE: \22%s\22\0D\0A\00"
@DT_LNK = global i32 0
@.str.9 = [22 x i8] c"Symbolic Link: \22%s\22\0D\0A\00"
@DT_REG = global i32 0
@.str.10 = [21 x i8] c"Regular File: \22%s\22\0D\0A\00"
@DT_SOCK = global i32 0
@.str.11 = [27 x i8] c"UNIX Domain Socket: \22%s\22\0D\0A\00"
@DT_UNKNOWN = global i32 0
@.str.12 = [20 x i8] c"Unknow File: \22%s\22\0D\0A\00"
define void @foreach_dir(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca %struct.stat
%7 = alloca [1024 x i8]
%8 = alloca %struct.dirent*
%9 = alloca [1024 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
store %struct.dirent* null, %struct.dirent** %8
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%11 = load i8*, i8** %3
%12 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %10, i32 1024, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%14 = call i32* @opendir(i8* %13)
store i32* %14, i32** %5
%15 = load i32*, i32** %5
%16 = icmp ne i32* %15, null
br i1 %16, label %21, label %17
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %3
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %154
21: ; preds = %2
br label %22
22: ; preds = %150, %38, %21
%23 = load i32*, i32** %5
%24 = call %struct.dirent* @readdir(i32* %23)
store %struct.dirent* %24, %struct.dirent** %8
%25 = icmp ne %struct.dirent* null, %24
br i1 %25, label %26, label %151
26: ; preds = %22
%27 = load %struct.dirent*, %struct.dirent** %8
%28 = getelementptr inbounds %struct.dirent, %struct.dirent* %27, i32 0, i32 0
%29 = load i8*, i8** %28
%30 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = icmp eq i64 0, %30
br i1 %31, label %38, label %32
32: ; preds = %26
%33 = load %struct.dirent*, %struct.dirent** %8
%34 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i32 0, i32 0
%35 = load i8*, i8** %34
%36 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %35)
%37 = icmp eq i64 0, %36
br i1 %37, label %38, label %39
38: ; preds = %32, %26
br label %22
39: ; preds = %32
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%42 = load %struct.dirent*, %struct.dirent** %8
%43 = getelementptr inbounds %struct.dirent, %struct.dirent* %42, i32 0, i32 0
%44 = load i8*, i8** %43
%45 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %40, i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %41, i8* %44)
%46 = load %struct.dirent*, %struct.dirent** %8
%47 = getelementptr inbounds %struct.dirent, %struct.dirent* %46, i32 0, i32 1
%48 = load i32, i32* %47
%49 = load i32, i32* @DT_DIR
%50 = and i32 %48, %49
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %72
52: ; preds = %39
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%54 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %53)
%55 = load i32, i32* %4
%56 = icmp eq i32 0, %55
br i1 %56, label %60, label %57
57: ; preds = %52
%58 = load i32, i32* %4
%59 = icmp sgt i32 %58, 1
br i1 %59, label %60, label %71
60: ; preds = %57, %52
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%62 = load i32, i32* %4
%63 = icmp sgt i32 %62, 1
br i1 %63, label %64, label %67
64: ; preds = %60
%65 = load i32, i32* %4
%66 = sub nsw i32 %65, 1
br label %69
67: ; preds = %60
%68 = load i32, i32* %4
br label %69
69: ; preds = %67, %64
%70 = phi i32 [ %66, %64 ], [ %68, %67 ]
br label %71
71: ; preds = %69, %57
br label %149
72: ; preds = %39
%73 = load %struct.dirent*, %struct.dirent** %8
%74 = getelementptr inbounds %struct.dirent, %struct.dirent* %73, i32 0, i32 1
%75 = load i32, i32* %74
%76 = load i32, i32* @DT_BLK
%77 = and i32 %75, %76
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %82
79: ; preds = %72
%80 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%81 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %80)
br label %148
82: ; preds = %72
%83 = load %struct.dirent*, %struct.dirent** %8
%84 = getelementptr inbounds %struct.dirent, %struct.dirent* %83, i32 0, i32 1
%85 = load i32, i32* %84
%86 = load i32, i32* @DT_CHR
%87 = and i32 %85, %86
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %92
89: ; preds = %82
%90 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%91 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %90)
br label %147
92: ; preds = %82
%93 = load %struct.dirent*, %struct.dirent** %8
%94 = getelementptr inbounds %struct.dirent, %struct.dirent* %93, i32 0, i32 1
%95 = load i32, i32* %94
%96 = load i32, i32* @DT_FIFO
%97 = and i32 %95, %96
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %102
99: ; preds = %92
%100 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%101 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %100)
br label %146
102: ; preds = %92
%103 = load %struct.dirent*, %struct.dirent** %8
%104 = getelementptr inbounds %struct.dirent, %struct.dirent* %103, i32 0, i32 1
%105 = load i32, i32* %104
%106 = load i32, i32* @DT_LNK
%107 = and i32 %105, %106
%108 = icmp ne i32 %107, 0
br i1 %108, label %109, label %112
109: ; preds = %102
%110 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%111 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* %110)
br label %145
112: ; preds = %102
%113 = load %struct.dirent*, %struct.dirent** %8
%114 = getelementptr inbounds %struct.dirent, %struct.dirent* %113, i32 0, i32 1
%115 = load i32, i32* %114
%116 = load i32, i32* @DT_REG
%117 = and i32 %115, %116
%118 = icmp ne i32 %117, 0
br i1 %118, label %119, label %122
119: ; preds = %112
%120 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%121 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0), i8* %120)
br label %144
122: ; preds = %112
%123 = load %struct.dirent*, %struct.dirent** %8
%124 = getelementptr inbounds %struct.dirent, %struct.dirent* %123, i32 0, i32 1
%125 = load i32, i32* %124
%126 = load i32, i32* @DT_SOCK
%127 = and i32 %125, %126
%128 = icmp ne i32 %127, 0
br i1 %128, label %129, label %132
129: ; preds = %122
%130 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%131 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0), i8* %130)
br label %143
132: ; preds = %122
%133 = load %struct.dirent*, %struct.dirent** %8
%134 = getelementptr inbounds %struct.dirent, %struct.dirent* %133, i32 0, i32 1
%135 = load i32, i32* %134
%136 = load i32, i32* @DT_UNKNOWN
%137 = and i32 %135, %136
%138 = icmp ne i32 %137, 0
br i1 %138, label %139, label %142
139: ; preds = %132
%140 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%141 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0), i8* %140)
br label %142
142: ; preds = %139, %132
br label %143
143: ; preds = %142, %129
br label %144
144: ; preds = %143, %119
br label %145
145: ; preds = %144, %109
br label %146
146: ; preds = %145, %99
br label %147
147: ; preds = %146, %89
br label %148
148: ; preds = %147, %79
br label %149
149: ; preds = %148, %71
br label %150
150: ; preds = %149
br label %22
151: ; preds = %22
%152 = load i32*, i32** %5
%153 = call i32 @closedir(i32* %152)
br label %154
154: ; preds = %151, %17
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8*, i32 }
@.str = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"Cannot Open Directory \22%s\22\0A\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [6 x i8] c"%s/%s\00"
@DT_DIR = global i32 0
@.str.5 = [15 x i8] c"Folder: \22%s\22\0D\0A\00"
@DT_BLK = global i32 0
@.str.6 = [21 x i8] c"Block Device: \22%s\22\0D\0A\00"
@DT_CHR = global i32 0
@.str.7 = [25 x i8] c"Character Device: \22%s\22\0D\0A\00"
@DT_FIFO = global i32 0
@.str.8 = [19 x i8] c"Named PIPE: \22%s\22\0D\0A\00"
@DT_LNK = global i32 0
@.str.9 = [22 x i8] c"Symbolic Link: \22%s\22\0D\0A\00"
@DT_REG = global i32 0
@.str.10 = [21 x i8] c"Regular File: \22%s\22\0D\0A\00"
@DT_SOCK = global i32 0
@.str.11 = [27 x i8] c"UNIX Domain Socket: \22%s\22\0D\0A\00"
@DT_UNKNOWN = global i32 0
@.str.12 = [20 x i8] c"Unknow File: \22%s\22\0D\0A\00"
define void @foreach_dir(i8* %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %5, i32 1024, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32* @opendir(i8* %5)
%8 = icmp eq i32* %7, null
br i1 %8, label %19, label %9
9: ; preds = %2
%10 = call %struct.dirent* @readdir(i32* %7)
%11 = icmp eq %struct.dirent* %10, null
br i1 %11, label %89, label %12
12: ; preds = %9
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%14 = icmp eq i32 %1, 0
%15 = icmp sgt i32 %1, 1
%16 = or i1 %14, %15
%17 = sext i1 %15 to i32
%18 = add nsw i32 %17, %1
br label %22
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %91
22: ; preds = %12, %32
%23 = phi %struct.dirent* [ %10, %12 ], [ %33, %32 ]
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i64 0, i32 0
%25 = load i8*, i8** %24
%26 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %22
%29 = load i8*, i8** %24
%30 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %22, %28, %88
%33 = call %struct.dirent* @readdir(i32* %7)
%34 = icmp eq %struct.dirent* %33, null
br i1 %34, label %89, label %22
35: ; preds = %28
%36 = load i8*, i8** %24
%37 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %13, i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %5, i8* %36)
%38 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i64 0, i32 1
%39 = load i32, i32* %38
%40 = load i32, i32* @DT_DIR
%41 = and i32 %40, %39
%42 = icmp eq i32 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %35
%44 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %13)
br i1 %16, label %45, label %88
45: ; preds = %43
br label %88
46: ; preds = %35
%47 = load i32, i32* @DT_BLK
%48 = and i32 %47, %39
%49 = icmp eq i32 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %46
%51 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %13)
br label %88
52: ; preds = %46
%53 = load i32, i32* @DT_CHR
%54 = and i32 %53, %39
%55 = icmp eq i32 %54, 0
br i1 %55, label %58, label %56
56: ; preds = %52
%57 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %13)
br label %88
58: ; preds = %52
%59 = load i32, i32* @DT_FIFO
%60 = and i32 %59, %39
%61 = icmp eq i32 %60, 0
br i1 %61, label %64, label %62
62: ; preds = %58
%63 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %13)
br label %88
64: ; preds = %58
%65 = load i32, i32* @DT_LNK
%66 = and i32 %65, %39
%67 = icmp eq i32 %66, 0
br i1 %67, label %70, label %68
68: ; preds = %64
%69 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* %13)
br label %88
70: ; preds = %64
%71 = load i32, i32* @DT_REG
%72 = and i32 %71, %39
%73 = icmp eq i32 %72, 0
br i1 %73, label %76, label %74
74: ; preds = %70
%75 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0), i8* %13)
br label %88
76: ; preds = %70
%77 = load i32, i32* @DT_SOCK
%78 = and i32 %77, %39
%79 = icmp eq i32 %78, 0
br i1 %79, label %82, label %80
80: ; preds = %76
%81 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0), i8* %13)
br label %88
82: ; preds = %76
%83 = load i32, i32* @DT_UNKNOWN
%84 = and i32 %83, %39
%85 = icmp eq i32 %84, 0
br i1 %85, label %88, label %86
86: ; preds = %82
%87 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0), i8* %13)
br label %88
88: ; preds = %50, %62, %74, %82, %86, %80, %68, %56, %45, %43
br label %32
89: ; preds = %32, %9
%90 = call i32 @closedir(i32* %7)
br label %91
91: ; preds = %89, %19
ret void
}