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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ ident(char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int adddat_dir(char *fn) {
  DIR *dir;
  struct dirent *ent;
  char path[256], path2[256];
  sprintf(path, "%s\\*.*", fn);
  if ((dir = opendir(path)) != NULL) {
    while ((ent = readdir(dir)) != NULL) {
      sprintf(path2, "%s\\%s", fn, ent->d_name);
      ident(path2);
    }
    closedir(dir);
  } else {
    printf("Could not open directory %s/*.*", path);
    return -1;
  }
}


x86 assembly (clang, -O0):
<adddat_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe7f(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0x120(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11fd <adddat_dir+0x9d>
jmp    11a7 <adddat_dir+0x47>
mov    -0x18(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11ef <adddat_dir+0x8f>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0x220(%rbp),%rdi
call   1070 <ident@plt>
jmp    11a7 <adddat_dir+0x47>
mov    -0x18(%rbp),%rdi
call   1050 <closedir@plt>
jmp    1217 <adddat_dir+0xb7>
lea    -0x120(%rbp),%rsi
lea    0xe02(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adddat_dir>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%r14
lea    0xe88(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     11f2 <adddat_dir+0x92>
mov    %rax,%r12
mov    %rax,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11e8 <adddat_dir+0x88>
lea    0xe5b(%rip),%r15
lea    0x100(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rax),%rcx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <ident@plt>
mov    %r12,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
jne    11c0 <adddat_dir+0x60>
mov    %r12,%rdi
call   1050 <closedir@plt>
jmp    1201 <adddat_dir+0xa1>
lea    0xe14(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [7 x i8] c"%s\\*.*\00"
@.str.1 = [6 x i8] c"%s\\%s\00"
@.str.2 = [32 x i8] c"Could not open directory %s/*.*\00"
define i32 @adddat_dir(i8* %0) {
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32* @opendir(i8* %4)
%8 = icmp eq i32* %7, null
br i1 %8, label %22, label %9
9: ; preds = %1
%10 = call %struct.dirent* @readdir(i32* %7)
%11 = icmp eq %struct.dirent* %10, null
br i1 %11, label %20, label %12
12: ; preds = %9, %12
%13 = phi %struct.dirent* [ %18, %12 ], [ %10, %9 ]
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %13, i64 0, i32 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %15)
%17 = call i32 @ident(i8* %5)
%18 = call %struct.dirent* @readdir(i32* %7)
%19 = icmp eq %struct.dirent* %18, null
br i1 %19, label %20, label %12
20: ; preds = %12, %9
%21 = call i32 @closedir(i32* %7)
br label %24
22: ; preds = %1
%23 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %24
24: ; preds = %20, %22
ret i32 -1
}