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

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int lstat(char *, struct stat *);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ printf(char *, char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char *);
int /*<<< orphan*/ stderr;
int store_st(struct DEDUPE_STORE_CONTEXT *, struct stat, char *);
scalar_t__ strcmp(char *, char *);
int store_dir(struct DEDUPE_STORE_CONTEXT *context, struct stat st,
              const char *d) {
  printf("%s\n", d);
  DIR *dp = opendir(d);
  if (d == NULL) {
    fprintf(stderr, "Error opening directory: %s\n", d);
    return 1;
  }
  struct dirent *ep;
  char full_path[PATH_MAX];
  while (ep = readdir(dp)) {
    if (strcmp(ep->d_name, ".") == 0)
      continue;
    if (strcmp(ep->d_name, "..") == 0)
      continue;
    struct stat cst;
    int ret;
    sprintf(full_path, "%s/%s", d, ep->d_name);
    if (0 != (ret = lstat(full_path, &cst))) {
      fprintf(stderr, "Error opening: %s\n", ep->d_name);
      closedir(dp);
      return ret;
    }
    if (ret = store_st(context, cst, full_path))
      return ret;
  }
  closedir(dp);
  return 0;
}


x86 assembly (clang, -O0):
<store_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %esi,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe87(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f0 <store_dir+0x60>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe21(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1336 <store_dir+0x1a6>
mov    0x2df9(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1318 <store_dir+0x188>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xddd(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1255 <store_dir+0xc5>
jmp    121c <store_dir+0x8c>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xdba(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1277 <store_dir+0xe7>
jmp    121c <store_dir+0x8c>
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
lea    0xd93(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x50(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1070 <lstat@plt>
mov    %eax,%ecx
mov    %ecx,-0x44(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
je     12e5 <store_dir+0x155>
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rax
mov    (%rax),%rdx
lea    0xd61(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <closedir@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    132f <store_dir+0x19f>
mov    -0x50(%rbp),%rdx
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%esi
call   1030 <store_st@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
je     1313 <store_dir+0x183>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    132f <store_dir+0x19f>
jmp    121c <store_dir+0x8c>
mov    -0x20(%rbp),%rdi
call   1060 <closedir@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<store_dir>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rdi,-0x40(%rbp)
lea    0xe86(%rip),%rdi
mov    %rdx,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <opendir@plt>
test   %r14,%r14
je     1289 <store_dir+0xf9>
mov    %rax,%r12
mov    %rsp,-0x30(%rbp)
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r12,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     1275 <store_dir+0xe5>
mov    %rax,%r15
jmp    1210 <store_dir+0x80>
nop
mov    %r12,%rdi
call   10a0 <readdir@plt>
mov    %rax,%r15
test   %rax,%rax
je     1275 <store_dir+0xe5>
mov    (%r15),%rdi
lea    0xe04(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1200 <store_dir+0x70>
mov    (%r15),%rdi
lea    0xdef(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1200 <store_dir+0x70>
mov    (%r15),%rcx
mov    %rbx,%rdi
lea    0xddb(%rip),%rsi
mov    %r14,%rdx
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
lea    -0x38(%rbp),%rsi
call   1070 <lstat@plt>
test   %eax,%eax
jne    12b8 <store_dir+0x128>
mov    -0x38(%rbp),%esi
mov    -0x40(%rbp),%rdi
mov    %rbx,%rdx
call   1030 <store_st@plt>
test   %eax,%eax
je     1200 <store_dir+0x70>
mov    %eax,%r13d
jmp    1280 <store_dir+0xf0>
mov    %r12,%rdi
call   1060 <closedir@plt>
xor    %r13d,%r13d
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
jmp    12a6 <store_dir+0x116>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
lea    0xd67(%rip),%rsi
xor    %edx,%edx
call   1090 <fprintf@plt>
mov    $0x1,%r13d
mov    %r13d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r13d
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xd58(%rip),%rsi
call   1090 <fprintf@plt>
mov    %r12,%rdi
call   1060 <closedir@plt>
jmp    1280 <store_dir+0xf0>

LLVM IR (-O0):
%struct.DEDUPE_STORE_CONTEXT = type { i32 }
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [4 x i8] c"%s\0A\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Error opening directory: %s\0A\00"
@PATH_MAX = global i32 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [19 x i8] c"Error opening: %s\0A\00"
define i32 @store_dir(%struct.DEDUPE_STORE_CONTEXT* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.stat
%6 = alloca %struct.DEDUPE_STORE_CONTEXT*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca %struct.dirent*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca %struct.stat
%13 = alloca i32
%14 = alloca i32
%15 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
store i32 %1, i32* %15
store %struct.DEDUPE_STORE_CONTEXT* %0, %struct.DEDUPE_STORE_CONTEXT** %6
store i8* %2, i8** %7
%16 = load i8*, i8** %7
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %7
%19 = call i32* @opendir(i8* %18)
store i32* %19, i32** %8
%20 = load i8*, i8** %7
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %26
22: ; preds = %3
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %7
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %24)
store i32 1, i32* %4
br label %80
26: ; preds = %3
%27 = load i32, i32* @PATH_MAX
%28 = zext i32 %27 to i64
%29 = call i8* @llvm.stacksave()
store i8* %29, i8** %10
%30 = alloca i8, i64 %28
store i64 %28, i64* %11
br label %31
31: ; preds = %74, %48, %41, %26
%32 = load i32*, i32** %8
%33 = call %struct.dirent* @readdir(i32* %32)
store %struct.dirent* %33, %struct.dirent** %9
%34 = icmp ne %struct.dirent* %33, null
br i1 %34, label %35, label %75
35: ; preds = %31
%36 = load %struct.dirent*, %struct.dirent** %9
%37 = getelementptr inbounds %struct.dirent, %struct.dirent* %36, i32 0, i32 0
%38 = load i8*, i8** %37
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %35
br label %31
42: ; preds = %35
%43 = load %struct.dirent*, %struct.dirent** %9
%44 = getelementptr inbounds %struct.dirent, %struct.dirent* %43, i32 0, i32 0
%45 = load i8*, i8** %44
%46 = call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %42
br label %31
49: ; preds = %42
%50 = load i8*, i8** %7
%51 = load %struct.dirent*, %struct.dirent** %9
%52 = getelementptr inbounds %struct.dirent, %struct.dirent* %51, i32 0, i32 0
%53 = load i8*, i8** %52
%54 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %50, i8* %53)
%55 = call i32 @lstat(i8* %30, %struct.stat* %12)
store i32 %55, i32* %13
%56 = icmp ne i32 0, %55
br i1 %56, label %57, label %66
57: ; preds = %49
%58 = load i32, i32* @stderr
%59 = load %struct.dirent*, %struct.dirent** %9
%60 = getelementptr inbounds %struct.dirent, %struct.dirent* %59, i32 0, i32 0
%61 = load i8*, i8** %60
%62 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %61)
%63 = load i32*, i32** %8
%64 = call i32 @closedir(i32* %63)
%65 = load i32, i32* %13
store i32 %65, i32* %4
store i32 1, i32* %14
br label %78
66: ; preds = %49
%67 = load %struct.DEDUPE_STORE_CONTEXT*, %struct.DEDUPE_STORE_CONTEXT** %6
%68 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%69 = load i32, i32* %68
%70 = call i32 @store_st(%struct.DEDUPE_STORE_CONTEXT* %67, i32 %69, i8* %30)
store i32 %70, i32* %13
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %66
%73 = load i32, i32* %13
store i32 %73, i32* %4
store i32 1, i32* %14
br label %78
74: ; preds = %66
br label %31
75: ; preds = %31
%76 = load i32*, i32** %8
%77 = call i32 @closedir(i32* %76)
store i32 0, i32* %4
store i32 1, i32* %14
br label %78
78: ; preds = %75, %72, %57
%79 = load i8*, i8** %10
br label %80
80: ; preds = %78, %22
%81 = load i32, i32* %4
ret i32 %81
}

LLVM IR (-O2):
%struct.DEDUPE_STORE_CONTEXT = type { i32 }
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [4 x i8] c"%s\0A\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Error opening directory: %s\0A\00"
@PATH_MAX = global i32 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [19 x i8] c"Error opening: %s\0A\00"
define i32 @store_dir(%struct.DEDUPE_STORE_CONTEXT* %0, i32 %1, i8* %2) {
%4 = alloca %struct.stat
%5 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
%6 = tail call i32* @opendir(i8* %2)
%7 = icmp eq i8* %2, null
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* null)
br label %52
11: ; preds = %3
%12 = load i32, i32* @PATH_MAX
%13 = zext i32 %12 to i64
%14 = tail call i8* @llvm.stacksave()
%15 = alloca i8, i64 %13
%16 = call %struct.dirent* @readdir(i32* %6)
%17 = icmp eq %struct.dirent* %16, null
br i1 %17, label %48, label %18
18: ; preds = %11
%19 = bitcast %struct.stat* %4 to i8*
%20 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
br label %21
21: ; preds = %18, %27
%22 = phi %struct.dirent* [ %16, %18 ], [ %28, %27 ]
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i64 0, i32 0
%24 = load i8*, i8** %23
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %21, %30, %44
%28 = call %struct.dirent* @readdir(i32* %6)
%29 = icmp eq %struct.dirent* %28, null
br i1 %29, label %48, label %21
30: ; preds = %21
%31 = load i8*, i8** %23
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %27, label %34
34: ; preds = %30
%35 = load i8*, i8** %23
%36 = call i32 @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %2, i8* %35)
%37 = call i32 @lstat(i8* %15, %struct.stat* %4)
%38 = icmp eq i32 %37, 0
br i1 %38, label %44, label %39
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %23
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %41)
%43 = call i32 @closedir(i32* %6)
br label %50
44: ; preds = %34
%45 = load i32, i32* %20
%46 = call i32 @store_st(%struct.DEDUPE_STORE_CONTEXT* %0, i32 %45, i8* %15)
%47 = icmp eq i32 %46, 0
br i1 %47, label %27, label %50
48: ; preds = %27, %11
%49 = call i32 @closedir(i32* %6)
br label %50
50: ; preds = %44, %39, %48
%51 = phi i32 [ 0, %48 ], [ %37, %39 ], [ %46, %44 ]
br label %52
52: ; preds = %50, %8
%53 = phi i32 [ 1, %8 ], [ %51, %50 ]
ret i32 %53
}