#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 */
scalar_t__ EAGAIN;
int LOG_CONS;
int /*<<< orphan*/ LOG_INFO;
int LOG_PID;
int /*<<< orphan*/ LOG_USER;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ closelog();
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ openlog(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *);
scalar_t__ umount2(char *, int);
int /*<<< orphan*/ usage(char const *);
int main(int argc, const char *argv[]) {
  DIR *rootdir;
  struct dirent *mp;
  char *dirname;
  if (argc != 2)
    usage(argv[0]);
  openlog("timount", LOG_CONS | LOG_PID, LOG_USER);
  if (!(rootdir = opendir(argv[1]))) {
    perror("could not open specified path");
    exit(1);
  }
  while ((mp = readdir(rootdir))) {
    dirname = malloc(strlen(argv[1]) + strlen(mp->d_name) + 2);
    sprintf(dirname, "%s/%s", argv[1], mp->d_name);
    if (mp->d_name[0] != '.' && mp->d_name[0] != '_') {
      if (umount2(dirname, 4)) {
        if (errno == EAGAIN)
          syslog(LOG_INFO, "marked %s for expiry\n", mp->d_name);
      } else {
        syslog(LOG_INFO, "unmounted %s\n", mp->d_name);
      }
    }
    free(dirname);
  }
  closedir(rootdir);
  closelog();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     120c <main+0x2c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <usage@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
mov    0x2dbc(%rip),%rax
or     (%rax),%esi
mov    0x2dc3(%rip),%rax
mov    (%rax),%edx
lea    0xdd2(%rip),%rdi
call   10e0 <openlog@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1264 <main+0x84>
lea    0xdb3(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    1269 <main+0x89>
mov    -0x18(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1378 <main+0x198>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1070 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
lea    0xd5b(%rip),%rsi
call   10f0 <sprintf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     136a <main+0x18a>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
je     136a <main+0x18a>
mov    -0x28(%rbp),%rdi
mov    $0x4,%esi
call   1050 <umount2@plt>
cmp    $0x0,%rax
je     1349 <main+0x169>
mov    0x2cbb(%rip),%rax
mov    (%rax),%rax
mov    0x2c91(%rip),%rcx
cmp    (%rcx),%rax
jne    1344 <main+0x164>
mov    0x2c91(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
lea    0xced(%rip),%rsi
call   10b0 <syslog@plt>
jmp    1365 <main+0x185>
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
lea    0xce2(%rip),%rsi
call   10b0 <syslog@plt>
jmp    136a <main+0x18a>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    1269 <main+0x89>
mov    -0x18(%rbp),%rdi
call   1080 <closedir@plt>
mov    $0x0,%al
call   1040 <closelog@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
je     11fb <main+0x1b>
mov    (%rbx),%rdi
call   10c0 <usage@plt>
mov    0x2dc6(%rip),%rax
mov    0x2dcf(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dd4(%rip),%rax
mov    (%rax),%edx
lea    0xde3(%rip),%rdi
call   10e0 <openlog@plt>
mov    0x8(%rbx),%rdi
call   1060 <opendir@plt>
test   %rax,%rax
je     1341 <main+0x161>
mov    %rax,%r12
mov    %rax,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     1321 <main+0x141>
mov    %rax,%r15
mov    %rbx,(%rsp)
jmp    1291 <main+0xb1>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
call   10b0 <syslog@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1090 <readdir@plt>
mov    %rax,%r15
test   %rax,%rax
mov    (%rsp),%rbx
je     1321 <main+0x141>
mov    0x8(%rbx),%rbp
mov    %rbp,%rdi
call   1070 <strlen@plt>
mov    %rax,%rbx
mov    (%r15),%r14
mov    %r14,%rdi
call   1070 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   10a0 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
lea    0xd61(%rip),%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
call   10f0 <sprintf@plt>
mov    (%r15),%rax
movzbl (%rax),%eax
cmp    $0x2e,%al
je     1271 <main+0x91>
cmp    $0x5f,%al
je     1271 <main+0x91>
mov    %r13,%rdi
mov    $0x4,%esi
call   1050 <umount2@plt>
lea    0xd50(%rip),%rsi
test   %rax,%rax
je     1260 <main+0x80>
mov    0x2cce(%rip),%rax
mov    (%rax),%rax
lea    0xd20(%rip),%rsi
mov    0x2c9d(%rip),%rcx
cmp    (%rcx),%rax
je     1260 <main+0x80>
jmp    1271 <main+0x91>
mov    %r12,%rdi
call   1080 <closedir@plt>
xor    %eax,%eax
call   1040 <closelog@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcc0(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [8 x i8] c"timount\00"
@LOG_CONS = global i32 0
@LOG_PID = global i32 0
@LOG_USER = global i32 0
@.str.1 = [30 x i8] c"could not open specified path\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@errno = global i64 0
@EAGAIN = global i64 0
@LOG_INFO = global i32 0
@.str.3 = [22 x i8] c"marked %s for expiry\0A\00"
@.str.4 = [14 x i8] c"unmounted %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.dirent*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @usage(i8* %14)
br label %16
16: ; preds = %11, %2
%17 = load i32, i32* @LOG_CONS
%18 = load i32, i32* @LOG_PID
%19 = or i32 %17, %18
%20 = load i32, i32* @LOG_USER
%21 = call i32 @openlog(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %20)
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32* @opendir(i8* %24)
store i32* %25, i32** %6
%26 = icmp ne i32* %25, null
br i1 %26, label %30, label %27
27: ; preds = %16
%28 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %16
br label %31
31: ; preds = %92, %30
%32 = load i32*, i32** %6
%33 = call %struct.dirent* @readdir(i32* %32)
store %struct.dirent* %33, %struct.dirent** %7
%34 = icmp ne %struct.dirent* %33, null
br i1 %34, label %35, label %95
35: ; preds = %31
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i64 @strlen(i8* %38)
%40 = load %struct.dirent*, %struct.dirent** %7
%41 = getelementptr inbounds %struct.dirent, %struct.dirent* %40, i32 0, i32 0
%42 = load i8*, i8** %41
%43 = call i64 @strlen(i8* %42)
%44 = add nsw i64 %39, %43
%45 = add nsw i64 %44, 2
%46 = call i8* @malloc(i64 %45)
store i8* %46, i8** %8
%47 = load i8*, i8** %8
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = load %struct.dirent*, %struct.dirent** %7
%52 = getelementptr inbounds %struct.dirent, %struct.dirent* %51, i32 0, i32 0
%53 = load i8*, i8** %52
%54 = call i32 @sprintf(i8* %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %50, i8* %53)
%55 = load %struct.dirent*, %struct.dirent** %7
%56 = getelementptr inbounds %struct.dirent, %struct.dirent* %55, i32 0, i32 0
%57 = load i8*, i8** %56
%58 = getelementptr inbounds i8, i8* %57, i64 0
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp ne i32 %60, 46
br i1 %61, label %62, label %92
62: ; preds = %35
%63 = load %struct.dirent*, %struct.dirent** %7
%64 = getelementptr inbounds %struct.dirent, %struct.dirent* %63, i32 0, i32 0
%65 = load i8*, i8** %64
%66 = getelementptr inbounds i8, i8* %65, i64 0
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp ne i32 %68, 95
br i1 %69, label %70, label %92
70: ; preds = %62
%71 = load i8*, i8** %8
%72 = call i64 @umount2(i8* %71, i32 4)
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %85
74: ; preds = %70
%75 = load i64, i64* @errno
%76 = load i64, i64* @EAGAIN
%77 = icmp eq i64 %75, %76
br i1 %77, label %78, label %84
78: ; preds = %74
%79 = load i32, i32* @LOG_INFO
%80 = load %struct.dirent*, %struct.dirent** %7
%81 = getelementptr inbounds %struct.dirent, %struct.dirent* %80, i32 0, i32 0
%82 = load i8*, i8** %81
%83 = call i32 @syslog(i32 %79, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %82)
br label %84
84: ; preds = %78, %74
br label %91
85: ; preds = %70
%86 = load i32, i32* @LOG_INFO
%87 = load %struct.dirent*, %struct.dirent** %7
%88 = getelementptr inbounds %struct.dirent, %struct.dirent* %87, i32 0, i32 0
%89 = load i8*, i8** %88
%90 = call i32 @syslog(i32 %86, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %89)
br label %91
91: ; preds = %85, %84
br label %92
92: ; preds = %91, %62, %35
%93 = load i8*, i8** %8
%94 = call i32 @free(i8* %93)
br label %31
95: ; preds = %31
%96 = load i32*, i32** %6
%97 = call i32 @closedir(i32* %96)
%98 = call i32 (...) @closelog()
ret i32 0
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [8 x i8] c"timount\00"
@LOG_CONS = global i32 0
@LOG_PID = global i32 0
@LOG_USER = global i32 0
@.str.1 = [30 x i8] c"could not open specified path\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@errno = global i64 0
@EAGAIN = global i64 0
@LOG_INFO = global i32 0
@.str.3 = [22 x i8] c"marked %s for expiry\0A\00"
@.str.4 = [14 x i8] c"unmounted %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @usage(i8* %5)
br label %7
7: ; preds = %4, %2
%8 = load i32, i32* @LOG_CONS
%9 = load i32, i32* @LOG_PID
%10 = or i32 %9, %8
%11 = load i32, i32* @LOG_USER
%12 = tail call i32 @openlog(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32* @opendir(i8* %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %7
%18 = tail call %struct.dirent* @readdir(i32* %15)
%19 = icmp eq %struct.dirent* %18, null
br i1 %19, label %52, label %23
20: ; preds = %7
%21 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %17, %48
%24 = phi %struct.dirent* [ %50, %48 ], [ %18, %17 ]
%25 = load i8*, i8** %13
%26 = tail call i64 @strlen(i8* dereferenceable(1) %25)
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i64 0, i32 0
%28 = load i8*, i8** %27
%29 = tail call i64 @strlen(i8* dereferenceable(1) %28)
%30 = add i64 %26, 2
%31 = add i64 %30, %29
%32 = tail call i8* @malloc(i64 %31)
%33 = tail call i32 @sprintf(i8* dereferenceable(1) %32, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %25, i8* %28)
%34 = load i8*, i8** %27
%35 = load i8, i8* %34
switch i8 %35, label %36 [
i8 46, label %48
i8 95, label %48
]
36: ; preds = %23
%37 = tail call i64 @umount2(i8* %32, i32 4)
%38 = icmp eq i64 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %36
%40 = load i64, i64* @errno
%41 = load i64, i64* @EAGAIN
%42 = icmp eq i64 %40, %41
br i1 %42, label %43, label %48
43: ; preds = %36, %39
%44 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), %39 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), %36 ]
%45 = load i32, i32* @LOG_INFO
%46 = load i8*, i8** %27
%47 = tail call i32 @syslog(i32 %45, i8* %44, i8* %46)
br label %48
48: ; preds = %43, %23, %23, %39
%49 = tail call i32 @free(i8* %32)
%50 = tail call %struct.dirent* @readdir(i32* %15)
%51 = icmp eq %struct.dirent* %50, null
br i1 %51, label %52, label %23
52: ; preds = %48, %17
%53 = tail call i32 @closedir(i32* %15)
%54 = tail call i32 (...) @closelog()
ret i32 0
}