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

/* Variables and functions */
int /*<<< orphan*/ S_ISVTX;
int /*<<< orphan*/ cleanup_dir(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ udev_get_run_path(struct udev *);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ util_strscpyl(char *, int, int /*<<< orphan*/, char *,
                                 int /*<<< orphan*/ *);
void cleanup_db(struct udev *udev) {
  char filename[1024];
  DIR *dir;
  util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev),
                "/queue.bin", NULL);
  unlink(filename);
  util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data",
                NULL);
  dir = opendir(filename);
  if (dir != NULL) {
    cleanup_dir(dir, S_ISVTX, 1);
    closedir(dir);
  }
  util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/links",
                NULL);
  dir = opendir(filename);
  if (dir != NULL) {
    cleanup_dir(dir, 0, 2);
    closedir(dir);
  }
  util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/tags",
                NULL);
  dir = opendir(filename);
  if (dir != NULL) {
    cleanup_dir(dir, 0, 2);
    closedir(dir);
  }
  util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/watch",
                NULL);
  dir = opendir(filename);
  if (dir != NULL) {
    cleanup_dir(dir, 0, 1);
    closedir(dir);
  }
  util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev),
                "/firmware-missing", NULL);
  dir = opendir(filename);
  if (dir != NULL) {
    cleanup_dir(dir, 0, 1);
    closedir(dir);
  }
}


x86 assembly (clang, -O0):
<cleanup_db>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x428(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <udev_get_run_path@plt>
mov    -0x428(%rbp),%rdi
mov    %eax,%edx
mov    $0x400,%esi
lea    0xe65(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <util_strscpyl@plt>
lea    -0x410(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x410(%rbp),%rax
mov    %rax,-0x420(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <udev_get_run_path@plt>
mov    -0x420(%rbp),%rdi
mov    %eax,%edx
mov    $0x400,%esi
lea    0xe2e(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <util_strscpyl@plt>
lea    -0x410(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     122e <cleanup_db+0xce>
mov    -0x418(%rbp),%rdi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
call   1080 <cleanup_dir@plt>
mov    -0x418(%rbp),%rdi
call   1050 <closedir@plt>
lea    -0x410(%rbp),%rax
mov    %rax,-0x430(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <udev_get_run_path@plt>
mov    -0x430(%rbp),%rdi
mov    %eax,%edx
mov    $0x400,%esi
lea    0xdb7(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <util_strscpyl@plt>
lea    -0x410(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     12a4 <cleanup_db+0x144>
mov    -0x418(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1080 <cleanup_dir@plt>
mov    -0x418(%rbp),%rdi
call   1050 <closedir@plt>
lea    -0x410(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <udev_get_run_path@plt>
mov    -0x438(%rbp),%rdi
mov    %eax,%edx
mov    $0x400,%esi
lea    0xd48(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <util_strscpyl@plt>
lea    -0x410(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     131a <cleanup_db+0x1ba>
mov    -0x418(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1080 <cleanup_dir@plt>
mov    -0x418(%rbp),%rdi
call   1050 <closedir@plt>
lea    -0x410(%rbp),%rax
mov    %rax,-0x440(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <udev_get_run_path@plt>
mov    -0x440(%rbp),%rdi
mov    %eax,%edx
mov    $0x400,%esi
lea    0xcd8(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <util_strscpyl@plt>
lea    -0x410(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     1390 <cleanup_db+0x230>
mov    -0x418(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1080 <cleanup_dir@plt>
mov    -0x418(%rbp),%rdi
call   1050 <closedir@plt>
lea    -0x410(%rbp),%rax
mov    %rax,-0x448(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <udev_get_run_path@plt>
mov    -0x448(%rbp),%rdi
mov    %eax,%edx
mov    $0x400,%esi
lea    0xc69(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <util_strscpyl@plt>
lea    -0x410(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     1406 <cleanup_db+0x2a6>
mov    -0x418(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1080 <cleanup_dir@plt>
mov    -0x418(%rbp),%rdi
call   1050 <closedir@plt>
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cleanup_db>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%r14
call   1070 <udev_get_run_path@plt>
lea    0xe87(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %eax,%edx
xor    %r8d,%r8d
call   1060 <util_strscpyl@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %r14,%rdi
call   1070 <udev_get_run_path@plt>
lea    0xe66(%rip),%rcx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %eax,%edx
xor    %r8d,%r8d
call   1060 <util_strscpyl@plt>
mov    %rbx,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     11e5 <cleanup_db+0x85>
mov    %rax,%rbx
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1080 <cleanup_dir@plt>
mov    %rbx,%rdi
call   1050 <closedir@plt>
mov    %r14,%rdi
call   1070 <udev_get_run_path@plt>
lea    0xe1d(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %eax,%edx
xor    %r8d,%r8d
call   1060 <util_strscpyl@plt>
mov    %rbx,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     1230 <cleanup_db+0xd0>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1080 <cleanup_dir@plt>
mov    %rbx,%rdi
call   1050 <closedir@plt>
mov    %r14,%rdi
call   1070 <udev_get_run_path@plt>
lea    0xdd9(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %eax,%edx
xor    %r8d,%r8d
call   1060 <util_strscpyl@plt>
mov    %rbx,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     127b <cleanup_db+0x11b>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1080 <cleanup_dir@plt>
mov    %rbx,%rdi
call   1050 <closedir@plt>
mov    %r14,%rdi
call   1070 <udev_get_run_path@plt>
lea    0xd94(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %eax,%edx
xor    %r8d,%r8d
call   1060 <util_strscpyl@plt>
mov    %rbx,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     12c6 <cleanup_db+0x166>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1080 <cleanup_dir@plt>
mov    %rbx,%rdi
call   1050 <closedir@plt>
mov    %r14,%rdi
call   1070 <udev_get_run_path@plt>
lea    0xd50(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %eax,%edx
xor    %r8d,%r8d
call   1060 <util_strscpyl@plt>
mov    %rbx,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     1311 <cleanup_db+0x1b1>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1080 <cleanup_dir@plt>
mov    %rbx,%rdi
call   1050 <closedir@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.udev = type { i32 }
@.str = [11 x i8] c"/queue.bin\00"
@.str.1 = [6 x i8] c"/data\00"
@S_ISVTX = global i32 0
@.str.2 = [7 x i8] c"/links\00"
@.str.3 = [6 x i8] c"/tags\00"
@.str.4 = [7 x i8] c"/watch\00"
@.str.5 = [18 x i8] c"/firmware-missing\00"
define void @cleanup_db(%struct.udev* %0) {
%2 = alloca %struct.udev*
%3 = alloca [1024 x i8]
%4 = alloca i32*
store %struct.udev* %0, %struct.udev** %2
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = load %struct.udev*, %struct.udev** %2
%7 = call i32 @udev_get_run_path(%struct.udev* %6)
%8 = call i32 @util_strscpyl(i8* %5, i32 1024, i32 %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* null)
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = call i32 @unlink(i8* %9)
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%12 = load %struct.udev*, %struct.udev** %2
%13 = call i32 @udev_get_run_path(%struct.udev* %12)
%14 = call i32 @util_strscpyl(i8* %11, i32 1024, i32 %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* null)
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%16 = call i32* @opendir(i8* %15)
store i32* %16, i32** %4
%17 = load i32*, i32** %4
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %25
19: ; preds = %1
%20 = load i32*, i32** %4
%21 = load i32, i32* @S_ISVTX
%22 = call i32 @cleanup_dir(i32* %20, i32 %21, i32 1)
%23 = load i32*, i32** %4
%24 = call i32 @closedir(i32* %23)
br label %25
25: ; preds = %19, %1
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%27 = load %struct.udev*, %struct.udev** %2
%28 = call i32 @udev_get_run_path(%struct.udev* %27)
%29 = call i32 @util_strscpyl(i8* %26, i32 1024, i32 %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32* null)
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%31 = call i32* @opendir(i8* %30)
store i32* %31, i32** %4
%32 = load i32*, i32** %4
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %39
34: ; preds = %25
%35 = load i32*, i32** %4
%36 = call i32 @cleanup_dir(i32* %35, i32 0, i32 2)
%37 = load i32*, i32** %4
%38 = call i32 @closedir(i32* %37)
br label %39
39: ; preds = %34, %25
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%41 = load %struct.udev*, %struct.udev** %2
%42 = call i32 @udev_get_run_path(%struct.udev* %41)
%43 = call i32 @util_strscpyl(i8* %40, i32 1024, i32 %42, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* null)
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%45 = call i32* @opendir(i8* %44)
store i32* %45, i32** %4
%46 = load i32*, i32** %4
%47 = icmp ne i32* %46, null
br i1 %47, label %48, label %53
48: ; preds = %39
%49 = load i32*, i32** %4
%50 = call i32 @cleanup_dir(i32* %49, i32 0, i32 2)
%51 = load i32*, i32** %4
%52 = call i32 @closedir(i32* %51)
br label %53
53: ; preds = %48, %39
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%55 = load %struct.udev*, %struct.udev** %2
%56 = call i32 @udev_get_run_path(%struct.udev* %55)
%57 = call i32 @util_strscpyl(i8* %54, i32 1024, i32 %56, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* null)
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%59 = call i32* @opendir(i8* %58)
store i32* %59, i32** %4
%60 = load i32*, i32** %4
%61 = icmp ne i32* %60, null
br i1 %61, label %62, label %67
62: ; preds = %53
%63 = load i32*, i32** %4
%64 = call i32 @cleanup_dir(i32* %63, i32 0, i32 1)
%65 = load i32*, i32** %4
%66 = call i32 @closedir(i32* %65)
br label %67
67: ; preds = %62, %53
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%69 = load %struct.udev*, %struct.udev** %2
%70 = call i32 @udev_get_run_path(%struct.udev* %69)
%71 = call i32 @util_strscpyl(i8* %68, i32 1024, i32 %70, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32* null)
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%73 = call i32* @opendir(i8* %72)
store i32* %73, i32** %4
%74 = load i32*, i32** %4
%75 = icmp ne i32* %74, null
br i1 %75, label %76, label %81
76: ; preds = %67
%77 = load i32*, i32** %4
%78 = call i32 @cleanup_dir(i32* %77, i32 0, i32 1)
%79 = load i32*, i32** %4
%80 = call i32 @closedir(i32* %79)
br label %81
81: ; preds = %76, %67
ret void
}

LLVM IR (-O2):
%struct.udev = type { i32 }
@.str = [11 x i8] c"/queue.bin\00"
@.str.1 = [6 x i8] c"/data\00"
@S_ISVTX = global i32 0
@.str.2 = [7 x i8] c"/links\00"
@.str.3 = [6 x i8] c"/tags\00"
@.str.4 = [7 x i8] c"/watch\00"
@.str.5 = [18 x i8] c"/firmware-missing\00"
define void @cleanup_db(%struct.udev* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @udev_get_run_path(%struct.udev* %0)
%5 = call i32 @util_strscpyl(i8* %3, i32 1024, i32 %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* null)
%6 = call i32 @unlink(i8* %3)
%7 = call i32 @udev_get_run_path(%struct.udev* %0)
%8 = call i32 @util_strscpyl(i8* %3, i32 1024, i32 %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* null)
%9 = call i32* @opendir(i8* %3)
%10 = icmp eq i32* %9, null
br i1 %10, label %15, label %11
11: ; preds = %1
%12 = load i32, i32* @S_ISVTX
%13 = call i32 @cleanup_dir(i32* %9, i32 %12, i32 1)
%14 = call i32 @closedir(i32* %9)
br label %15
15: ; preds = %11, %1
%16 = call i32 @udev_get_run_path(%struct.udev* %0)
%17 = call i32 @util_strscpyl(i8* %3, i32 1024, i32 %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32* null)
%18 = call i32* @opendir(i8* %3)
%19 = icmp eq i32* %18, null
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = call i32 @cleanup_dir(i32* %18, i32 0, i32 2)
%22 = call i32 @closedir(i32* %18)
br label %23
23: ; preds = %20, %15
%24 = call i32 @udev_get_run_path(%struct.udev* %0)
%25 = call i32 @util_strscpyl(i8* %3, i32 1024, i32 %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* null)
%26 = call i32* @opendir(i8* %3)
%27 = icmp eq i32* %26, null
br i1 %27, label %31, label %28
28: ; preds = %23
%29 = call i32 @cleanup_dir(i32* %26, i32 0, i32 2)
%30 = call i32 @closedir(i32* %26)
br label %31
31: ; preds = %28, %23
%32 = call i32 @udev_get_run_path(%struct.udev* %0)
%33 = call i32 @util_strscpyl(i8* %3, i32 1024, i32 %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* null)
%34 = call i32* @opendir(i8* %3)
%35 = icmp eq i32* %34, null
br i1 %35, label %39, label %36
36: ; preds = %31
%37 = call i32 @cleanup_dir(i32* %34, i32 0, i32 1)
%38 = call i32 @closedir(i32* %34)
br label %39
39: ; preds = %36, %31
%40 = call i32 @udev_get_run_path(%struct.udev* %0)
%41 = call i32 @util_strscpyl(i8* %3, i32 1024, i32 %40, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32* null)
%42 = call i32* @opendir(i8* %3)
%43 = icmp eq i32* %42, null
br i1 %43, label %47, label %44
44: ; preds = %39
%45 = call i32 @cleanup_dir(i32* %42, i32 0, i32 1)
%46 = call i32 @closedir(i32* %42)
br label %47
47: ; preds = %44, %39
ret void
}