#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 mntent {
  int /*<<< orphan*/ mnt_dir;
  int /*<<< orphan*/ mnt_fsname;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
struct mntent *getmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ *hasmntopt(struct mntent *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ *setmntent(char *, char *);
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, char *);
int strpref(char const *, int /*<<< orphan*/);
int mounted_noatime(const char *path) {
  struct mntent *mnt;
  int prefix_max = 0, prefix;
  int has_noatime;
  FILE *f;
  f = setmntent("/proc/mounts", "r");
  if (f == NULL) {
    printf("Couldn't mount /proc/mounts\n");
    return -1;
  }
  while ((mnt = getmntent(f))) {
    if (!strcmp(mnt->mnt_fsname, "rootfs"))
      continue;
    prefix = strpref(path, mnt->mnt_dir);
    if (prefix > prefix_max) {
      prefix_max = prefix;
      has_noatime = hasmntopt(mnt, "noatime") != NULL;
    }
  }
  return has_noatime;
}


x86 assembly (clang, -O0):
<mounted_noatime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe86(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1070 <setmntent@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11ad <mounted_noatime+0x4d>
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1238 <mounted_noatime+0xd8>
jmp    11b2 <mounted_noatime+0x52>
mov    -0x30(%rbp),%rdi
call   1060 <getmntent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1232 <mounted_noatime+0xd2>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
lea    0xe55(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11ea <mounted_noatime+0x8a>
jmp    11b2 <mounted_noatime+0x52>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1050 <strpref@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    122d <mounted_noatime+0xcd>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   1080 <hasmntopt@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
jmp    11b2 <mounted_noatime+0x52>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mounted_noatime>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,(%rsp)
lea    0xeaa(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1070 <setmntent@plt>
test   %rax,%rax
je     11f1 <mounted_noatime+0x91>
mov    %rax,%rbx
xor    %r14d,%r14d
lea    0xe6e(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1060 <getmntent@plt>
test   %rax,%rax
je     1203 <mounted_noatime+0xa3>
mov    %rax,%rbp
mov    0x4(%rax),%edi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11a0 <mounted_noatime+0x40>
mov    0x0(%rbp),%esi
mov    (%rsp),%rdi
call   1050 <strpref@plt>
cmp    %r14d,%eax
jle    11a0 <mounted_noatime+0x40>
mov    %eax,%r12d
mov    %rbp,%rdi
lea    0xe2c(%rip),%rsi
call   1080 <hasmntopt@plt>
xor    %r13d,%r13d
test   %rax,%rax
setne  %r13b
mov    %r12d,%r14d
jmp    11a0 <mounted_noatime+0x40>
lea    0xe19(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mntent = type { i32, i32 }
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"Couldn't mount /proc/mounts\0A\00"
@.str.3 = [7 x i8] c"rootfs\00"
@.str.4 = [8 x i8] c"noatime\00"
define i32 @mounted_noatime(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.mntent*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i8* %0, i8** %3
store i32 0, i32* %5
%9 = call i32* @setmntent(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %8
%10 = load i32*, i32** %8
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %44
14: ; preds = %1
br label %15
15: ; preds = %41, %25, %14
%16 = load i32*, i32** %8
%17 = call %struct.mntent* @getmntent(i32* %16)
store %struct.mntent* %17, %struct.mntent** %4
%18 = icmp ne %struct.mntent* %17, null
br i1 %18, label %19, label %42
19: ; preds = %15
%20 = load %struct.mntent*, %struct.mntent** %4
%21 = getelementptr inbounds %struct.mntent, %struct.mntent* %20, i32 0, i32 1
%22 = load i32, i32* %21
%23 = call i32 @strcmp(i32 %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp ne i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %19
br label %15
26: ; preds = %19
%27 = load i8*, i8** %3
%28 = load %struct.mntent*, %struct.mntent** %4
%29 = getelementptr inbounds %struct.mntent, %struct.mntent* %28, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 @strpref(i8* %27, i32 %30)
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = load i32, i32* %5
%34 = icmp sgt i32 %32, %33
br i1 %34, label %35, label %41
35: ; preds = %26
%36 = load i32, i32* %6
store i32 %36, i32* %5
%37 = load %struct.mntent*, %struct.mntent** %4
%38 = call i32* @hasmntopt(%struct.mntent* %37, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%39 = icmp ne i32* %38, null
%40 = zext i1 %39 to i32
store i32 %40, i32* %7
br label %41
41: ; preds = %35, %26
br label %15
42: ; preds = %15
%43 = load i32, i32* %7
store i32 %43, i32* %2
br label %44
44: ; preds = %42, %12
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
%struct.mntent = type { i32, i32 }
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [7 x i8] c"rootfs\00"
@.str.4 = [8 x i8] c"noatime\00"
@str = [28 x i8] c"Couldn't mount /proc/mounts\00"
define i32 @mounted_noatime(i8* %0) {
%2 = tail call i32* @setmntent(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %23
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %27
6: ; preds = %26, %9
%7 = tail call %struct.mntent* @getmntent(i32* %2)
%8 = icmp eq %struct.mntent* %7, null
br i1 %8, label %27, label %9
9: ; preds = %6
%10 = getelementptr inbounds %struct.mntent, %struct.mntent* %7, i64 0, i32 1
%11 = load i32, i32* %10
%12 = tail call i32 @strcmp(i32 %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %6, label %14
14: ; preds = %9
%15 = getelementptr inbounds %struct.mntent, %struct.mntent* %7, i64 0, i32 0
%16 = load i32, i32* %15
%17 = tail call i32 @strpref(i8* %0, i32 %16)
%18 = icmp sgt i32 %17, %24
br i1 %18, label %19, label %26
19: ; preds = %14
%20 = tail call i32* @hasmntopt(%struct.mntent* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp ne i32* %20, null
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %1, %19
%24 = phi i32 [ %17, %19 ], [ 0, %1 ]
%25 = phi i32 [ %22, %19 ], [ undef, %1 ]
br label %26
26: ; preds = %23, %14
br label %6
27: ; preds = %6, %4
%28 = phi i32 [ -1, %4 ], [ %25, %6 ]
ret i32 %28
}