#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 const *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ analysis_file(char *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ is_dir(char *);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ perror(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ skip_some_entries(char const *);
char *strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
void loop_dir(const char *name) {
  DIR *p_dir;
  if ((p_dir = opendir(name)) == NULL) {
    perror("opendir");
    exit(EXIT_FAILURE);
  }
  struct dirent *p_dirent;
  while ((p_dirent = readdir(p_dir)) != NULL) {
    if (skip_some_entries(p_dirent->d_name))
      continue;
    size_t fullnamelen = strlen(name) + 1 + strlen(p_dirent->d_name) + 1;
    char fullname[fullnamelen];
    strcpy(fullname, name);
    strcat(strcat(fullname, "/"), p_dirent->d_name);
    if (is_dir(fullname)) {
      loop_dir(fullname);
    } else
      analysis_file(fullname);
  }
  closedir(p_dir);
}


x86 assembly (clang, -O0):
<loop_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11fd <loop_dir+0x3d>
lea    0xe16(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
jmp    1202 <loop_dir+0x42>
mov    -0x10(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12e4 <loop_dir+0x124>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1060 <skip_some_entries@plt>
cmp    $0x0,%rax
je     1234 <loop_dir+0x74>
jmp    1202 <loop_dir+0x42>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    -0x3c(%rbp),%ecx
mov    %eax,%edx
mov    %ecx,%eax
mov    %edx,%ecx
lea    0x2(%rax,%rcx,1),%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x38(%rbp),%rdi
lea    0xd6e(%rip),%rsi
call   10d0 <strcat@plt>
mov    %rax,%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   10d0 <strcat@plt>
mov    -0x38(%rbp),%rdi
call   1070 <is_dir@plt>
cmp    $0x0,%rax
je     12cf <loop_dir+0x10f>
mov    -0x38(%rbp),%rdi
call   10a0 <loop_dir@plt>
jmp    12d8 <loop_dir+0x118>
mov    -0x38(%rbp),%rdi
call   1090 <analysis_file@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
jmp    1202 <loop_dir+0x42>
mov    -0x10(%rbp),%rdi
call   1080 <closedir@plt>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loop_dir>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <opendir@plt>
test   %rax,%rax
je     12ae <loop_dir+0xee>
mov    %rax,%r15
mov    %rax,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     1297 <loop_dir+0xd7>
mov    %rax,%rbx
jmp    1218 <loop_dir+0x58>
nopl   0x0(%rax,%rax,1)
call   10a0 <loop_dir@plt>
mov    %r13,%rsp
mov    %r15,%rdi
call   10b0 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1297 <loop_dir+0xd7>
mov    (%rbx),%rdi
call   1060 <skip_some_entries@plt>
test   %rax,%rax
jne    1208 <loop_dir+0x48>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
mov    (%rbx),%rdi
call   1050 <strlen@plt>
mov    %rsp,%r13
add    %r12d,%eax
add    $0x2,%eax
cltq
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
mov    %r12,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
movw   $0x2f,(%rax,%r12,1)
mov    (%rbx),%rsi
mov    %r12,%rdi
call   10d0 <strcat@plt>
mov    %r12,%rdi
call   1070 <is_dir@plt>
mov    %r12,%rdi
test   %rax,%rax
jne    1200 <loop_dir+0x40>
call   1090 <analysis_file@plt>
jmp    1205 <loop_dir+0x45>
mov    %r15,%rdi
call   1080 <closedir@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd4b(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [8 x i8] c"opendir\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"/\00"
define void @loop_dir(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32* @opendir(i8* %8)
store i32* %9, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
br label %16
16: ; preds = %53, %26, %15
%17 = load i32*, i32** %3
%18 = call %struct.dirent* @readdir(i32* %17)
store %struct.dirent* %18, %struct.dirent** %4
%19 = icmp ne %struct.dirent* %18, null
br i1 %19, label %20, label %55
20: ; preds = %16
%21 = load %struct.dirent*, %struct.dirent** %4
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = call i64 @skip_some_entries(i8* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %20
br label %16
27: ; preds = %20
%28 = load i8*, i8** %2
%29 = call i32 @strlen(i8* %28)
%30 = add nsw i32 %29, 1
%31 = load %struct.dirent*, %struct.dirent** %4
%32 = getelementptr inbounds %struct.dirent, %struct.dirent* %31, i32 0, i32 0
%33 = load i8*, i8** %32
%34 = call i32 @strlen(i8* %33)
%35 = add nsw i32 %30, %34
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
store i64 %37, i64* %5
%38 = load i64, i64* %5
%39 = call i8* @llvm.stacksave()
store i8* %39, i8** %6
%40 = alloca i8, i64 %38
store i64 %38, i64* %7
%41 = load i8*, i8** %2
%42 = call i32 @strcpy(i8* %40, i8* %41)
%43 = call i8* @strcat(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%44 = load %struct.dirent*, %struct.dirent** %4
%45 = getelementptr inbounds %struct.dirent, %struct.dirent* %44, i32 0, i32 0
%46 = load i8*, i8** %45
%47 = call i8* @strcat(i8* %43, i8* %46)
%48 = call i64 @is_dir(i8* %40)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %27
br label %53
51: ; preds = %27
%52 = call i32 @analysis_file(i8* %40)
br label %53
53: ; preds = %51, %50
%54 = load i8*, i8** %6
br label %16
55: ; preds = %16
%56 = load i32*, i32** %3
%57 = call i32 @closedir(i32* %56)
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [8 x i8] c"opendir\00"
@EXIT_FAILURE = global i32 0
define void @loop_dir(i8* %0) {
%2 = tail call i32* @opendir(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = call %struct.dirent* @readdir(i32* %2)
%6 = icmp eq %struct.dirent* %5, null
br i1 %6, label %41, label %11
7: ; preds = %1
%8 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %4, %38
%12 = phi %struct.dirent* [ %39, %38 ], [ %5, %4 ]
%13 = getelementptr inbounds %struct.dirent, %struct.dirent* %12, i64 0, i32 0
%14 = load i8*, i8** %13
%15 = call i64 @skip_some_entries(i8* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %38
17: ; preds = %11
%18 = call i32 @strlen(i8* %0)
%19 = load i8*, i8** %13
%20 = call i32 @strlen(i8* %19)
%21 = add i32 %18, 2
%22 = add i32 %21, %20
%23 = sext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
%25 = alloca i8, i64 %23
%26 = call i32 @strcpy(i8* %25, i8* %0)
%27 = call i64 bitcast (i32 (i8*)* @strlen to i64 (i8*)*)(i8* %25)
%28 = getelementptr i8, i8* %25, i64 %27
%29 = bitcast i8* %28 to i16*
store i16 47, i16* %29
%30 = load i8*, i8** %13
%31 = call i8* @strcat(i8* %25, i8* dereferenceable(1) %30)
%32 = call i64 @is_dir(i8* %25)
%33 = icmp eq i64 %32, 0
br i1 %33, label %35, label %34
34: ; preds = %17
br label %37
35: ; preds = %17
%36 = call i32 @analysis_file(i8* %25)
br label %37
37: ; preds = %35, %34
br label %38
38: ; preds = %37, %11
%39 = call %struct.dirent* @readdir(i32* %2)
%40 = icmp eq %struct.dirent* %39, null
br i1 %40, label %41, label %11
41: ; preds = %38, %4
%42 = call i32 @closedir(i32* %2)
ret void
}