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

/* Variables and functions */
unsigned int FIFREEZE;
unsigned int FITHAW;
#define VSS_OP_FREEZE 129
#define VSS_OP_THAW 128
int /*<<< orphan*/ endmntent(int /*<<< orphan*/ *);
struct mntent *getmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ *setmntent(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int vss_do_freeze(char *, unsigned int, char *);
int vss_operate(int operation) {
  char *fs_op;
  char match[] = "/dev/";
  FILE *mounts;
  struct mntent *ent;
  unsigned int cmd;
  int error = 0, root_seen = 0;
  switch (operation) {
  case VSS_OP_FREEZE:
    cmd = FIFREEZE;
    fs_op = "freeze";
    break;
  case VSS_OP_THAW:
    cmd = FITHAW;
    fs_op = "thaw";
    break;
  default:
    return -1;
  }
  mounts = setmntent("/proc/mounts", "r");
  if (mounts == NULL)
    return -1;
  while ((ent = getmntent(mounts))) {
    if (strncmp(ent->mnt_fsname, match, strlen(match)))
      continue;
    if (strcmp(ent->mnt_type, "iso9660") == 0)
      continue;
    if (strcmp(ent->mnt_type, "vfat") == 0)
      continue;
    if (strcmp(ent->mnt_dir, "/") == 0) {
      root_seen = 1;
      continue;
    }
    error |= vss_do_freeze(ent->mnt_dir, cmd, fs_op);
  }
  endmntent(mounts);
  if (root_seen) {
    error |= vss_do_freeze("/", cmd, fs_op);
  }
  return error;
}


x86 assembly (clang, -O0):
<vss_operate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
movw   $0x2f,-0x14(%rbp)
movl   $0x7665642f,-0x18(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0x80,%eax
je     11db <vss_operate+0x6b>
jmp    11ac <vss_operate+0x3c>
mov    -0x38(%rbp),%eax
sub    $0x81,%eax
jne    11f7 <vss_operate+0x87>
jmp    11bf <vss_operate+0x4f>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
lea    0xe34(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1203 <vss_operate+0x93>
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
lea    0xe1f(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1203 <vss_operate+0x93>
movl   $0xffffffff,-0x4(%rbp)
jmp    1344 <vss_operate+0x1d4>
lea    0xe08(%rip),%rdi
lea    0xe0e(%rip),%rsi
call   1090 <setmntent@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1231 <vss_operate+0xc1>
movl   $0xffffffff,-0x4(%rbp)
jmp    1344 <vss_operate+0x1d4>
jmp    1236 <vss_operate+0xc6>
mov    -0x20(%rbp),%rdi
call   1080 <getmntent@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1312 <vss_operate+0x1a2>
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%eax
mov    %eax,-0x44(%rbp)
lea    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1285 <vss_operate+0x115>
jmp    1236 <vss_operate+0xc6>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xd8e(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12a7 <vss_operate+0x137>
jmp    1236 <vss_operate+0xc6>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xd74(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12c9 <vss_operate+0x159>
jmp    1236 <vss_operate+0xc6>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd2c(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12f3 <vss_operate+0x183>
movl   $0x1,-0x34(%rbp)
jmp    1236 <vss_operate+0xc6>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1060 <vss_do_freeze@plt>
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    1236 <vss_operate+0xc6>
mov    -0x20(%rbp),%rdi
call   1030 <endmntent@plt>
cmpl   $0x0,-0x34(%rbp)
je     133e <vss_operate+0x1ce>
mov    -0x2c(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xcd1(%rip),%rdi
call   1060 <vss_do_freeze@plt>
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vss_operate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movw   $0x2f,0xc(%rsp)
movl   $0x7665642f,0x8(%rsp)
76
mov    $0xffffffff,%ebx
cmp    $0x81,%edi
je     11b6 <vss_operate+0x46>
cmp    $0x80,%edi
jne    12e6 <vss_operate+0x176>
mov    0x2e23(%rip),%rax
lea    0xe59(%rip),%r14
jmp    11c4 <vss_operate+0x54>
mov    0x2e2b(%rip),%rax
lea    0xe42(%rip),%r14
mov    (%rax),%r15d
lea    0xe44(%rip),%rdi
lea    0xe4a(%rip),%rsi
call   1090 <setmntent@plt>
test   %rax,%rax
je     12e6 <vss_operate+0x176>
mov    %rax,%rbp
mov    %r15d,0x4(%rsp)
mov    %r14,0x10(%rsp)
movl   $0x0,(%rsp)
lea    0x8(%rsp),%rbx
lea    0xe1e(%rip),%r13
xor    %r12d,%r12d
mov    %r12d,%ecx
mov    %ecx,%r12d
mov    %rbp,%rdi
call   1080 <getmntent@plt>
test   %rax,%rax
je     12ba <vss_operate+0x14a>
mov    %rax,%r15
jmp    1240 <vss_operate+0xd0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1080 <getmntent@plt>
mov    %rax,%r15
test   %rax,%rax
je     12ba <vss_operate+0x14a>
mov    0x10(%r15),%r14d
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1230 <vss_operate+0xc0>
mov    (%r15),%rdi
mov    %r13,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1230 <vss_operate+0xc0>
mov    (%r15),%rdi
lea    0xdb1(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1230 <vss_operate+0xc0>
mov    0x8(%r15),%rdi
lea    0xd77(%rip),%rsi
call   1070 <strcmp@plt>
mov    $0x1,%ecx
test   %rax,%rax
je     1209 <vss_operate+0x99>
mov    0x8(%r15),%rdi
mov    0x4(%rsp),%esi
mov    0x10(%rsp),%rdx
call   1060 <vss_do_freeze@plt>
or     %eax,(%rsp)
jmp    1206 <vss_operate+0x96>
mov    %rbp,%rdi
call   1030 <endmntent@plt>
test   %r12d,%r12d
je     12e3 <vss_operate+0x173>
lea    0xd36(%rip),%rdi
mov    0x4(%rsp),%esi
mov    0x10(%rsp),%rdx
call   1060 <vss_do_freeze@plt>
mov    (%rsp),%ebx
or     %eax,%ebx
jmp    12e6 <vss_operate+0x176>
mov    (%rsp),%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mntent = type { i8*, i8*, i32 }
@__const.vss_operate.match = [6 x i8] c"/dev/\00"
@FIFREEZE = global i32 0
@.str = [7 x i8] c"freeze\00"
@FITHAW = global i32 0
@.str.1 = [5 x i8] c"thaw\00"
@.str.2 = [13 x i8] c"/proc/mounts\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [8 x i8] c"iso9660\00"
@.str.5 = [5 x i8] c"vfat\00"
@.str.6 = [2 x i8] c"/\00"
define i32 @vss_operate(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [6 x i8]
%6 = alloca i32*
%7 = alloca %struct.mntent*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %3
%11 = bitcast [6 x i8]* %5 to i8*
store i32 0, i32* %9
store i32 0, i32* %10
%12 = load i32, i32* %3
switch i32 %12, label %17 [
i32 129, label %13
i32 128, label %15
]
13: ; preds = %1
%14 = load i32, i32* @FIFREEZE
store i32 %14, i32* %8
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %4
br label %18
15: ; preds = %1
%16 = load i32, i32* @FITHAW
store i32 %16, i32* %8
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %18
17: ; preds = %1
store i32 -1, i32* %2
br label %81
18: ; preds = %15, %13
%19 = call i32* @setmntent(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 -1, i32* %2
br label %81
23: ; preds = %18
br label %24
24: ; preds = %59, %58, %51, %44, %37, %23
%25 = load i32*, i32** %6
%26 = call %struct.mntent* @getmntent(i32* %25)
store %struct.mntent* %26, %struct.mntent** %7
%27 = icmp ne %struct.mntent* %26, null
br i1 %27, label %28, label %68
28: ; preds = %24
%29 = load %struct.mntent*, %struct.mntent** %7
%30 = getelementptr inbounds %struct.mntent, %struct.mntent* %29, i32 0, i32 2
%31 = load i32, i32* %30
%32 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%33 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = call i64 @strncmp(i32 %31, i8* %32, i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %28
br label %24
38: ; preds = %28
%39 = load %struct.mntent*, %struct.mntent** %7
%40 = getelementptr inbounds %struct.mntent, %struct.mntent* %39, i32 0, i32 0
%41 = load i8*, i8** %40
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %38
br label %24
45: ; preds = %38
%46 = load %struct.mntent*, %struct.mntent** %7
%47 = getelementptr inbounds %struct.mntent, %struct.mntent* %46, i32 0, i32 0
%48 = load i8*, i8** %47
%49 = call i64 @strcmp(i8* %48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %45
br label %24
52: ; preds = %45
%53 = load %struct.mntent*, %struct.mntent** %7
%54 = getelementptr inbounds %struct.mntent, %struct.mntent* %53, i32 0, i32 1
%55 = load i8*, i8** %54
%56 = call i64 @strcmp(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %52
store i32 1, i32* %10
br label %24
59: ; preds = %52
%60 = load %struct.mntent*, %struct.mntent** %7
%61 = getelementptr inbounds %struct.mntent, %struct.mntent* %60, i32 0, i32 1
%62 = load i8*, i8** %61
%63 = load i32, i32* %8
%64 = load i8*, i8** %4
%65 = call i32 @vss_do_freeze(i8* %62, i32 %63, i8* %64)
%66 = load i32, i32* %9
%67 = or i32 %66, %65
store i32 %67, i32* %9
br label %24
68: ; preds = %24
%69 = load i32*, i32** %6
%70 = call i32 @endmntent(i32* %69)
%71 = load i32, i32* %10
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %79
73: ; preds = %68
%74 = load i32, i32* %8
%75 = load i8*, i8** %4
%76 = call i32 @vss_do_freeze(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 %74, i8* %75)
%77 = load i32, i32* %9
%78 = or i32 %77, %76
store i32 %78, i32* %9
br label %79
79: ; preds = %73, %68
%80 = load i32, i32* %9
store i32 %80, i32* %2
br label %81
81: ; preds = %79, %22, %17
%82 = load i32, i32* %2
ret i32 %82
}

LLVM IR (-O2):
%struct.mntent = type { i8*, i8*, i32 }
@__const.vss_operate.match = [6 x i8] c"/dev/\00"
@FIFREEZE = global i32 0
@.str = [7 x i8] c"freeze\00"
@FITHAW = global i32 0
@.str.1 = [5 x i8] c"thaw\00"
@.str.2 = [13 x i8] c"/proc/mounts\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [8 x i8] c"iso9660\00"
@.str.5 = [5 x i8] c"vfat\00"
@.str.6 = [2 x i8] c"/\00"
define i32 @vss_operate(i32 %0) {
%2 = alloca [6 x i8]
%3 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
switch i32 %0, label %53 [
i32 129, label %5
i32 128, label %4
]
4: ; preds = %1
br label %5
5: ; preds = %1, %4
%6 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %1 ]
%7 = phi i32* [ @FITHAW, %4 ], [ @FIFREEZE, %1 ]
%8 = load i32, i32* %7
%9 = tail call i32* @setmntent(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %53, label %11
11: ; preds = %5, %42
%12 = phi i32 [ %46, %42 ], [ 0, %5 ]
%13 = phi i32 [ %15, %42 ], [ 0, %5 ]
br label %14
14: ; preds = %11, %37
%15 = phi i32 [ %13, %11 ], [ 1, %37 ]
%16 = call %struct.mntent* @getmntent(i32* %9)
%17 = icmp eq %struct.mntent* %16, null
br i1 %17, label %47, label %18
18: ; preds = %14, %25
%19 = phi %struct.mntent* [ %26, %25 ], [ %16, %14 ]
%20 = getelementptr inbounds %struct.mntent, %struct.mntent* %19, i64 0, i32 2
%21 = load i32, i32* %20
%22 = call i32 @strlen(i8* %3)
%23 = call i64 @strncmp(i32 %21, i8* %3, i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %18, %28, %33
%26 = call %struct.mntent* @getmntent(i32* %9)
%27 = icmp eq %struct.mntent* %26, null
br i1 %27, label %47, label %18
28: ; preds = %18
%29 = getelementptr inbounds %struct.mntent, %struct.mntent* %19, i64 0, i32 0
%30 = load i8*, i8** %29
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %25, label %33
33: ; preds = %28
%34 = load i8*, i8** %29
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %25, label %37
37: ; preds = %33
%38 = getelementptr inbounds %struct.mntent, %struct.mntent* %19, i64 0, i32 1
%39 = load i8*, i8** %38
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %14, label %42
42: ; preds = %37
%43 = getelementptr inbounds %struct.mntent, %struct.mntent* %19, i64 0, i32 1
%44 = load i8*, i8** %43
%45 = call i32 @vss_do_freeze(i8* %44, i32 %8, i8* %6)
%46 = or i32 %45, %12
br label %11
47: ; preds = %14, %25
%48 = call i32 @endmntent(i32* %9)
%49 = icmp eq i32 %15, 0
br i1 %49, label %53, label %50
50: ; preds = %47
%51 = call i32 @vss_do_freeze(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 %8, i8* %6)
%52 = or i32 %51, %12
br label %53
53: ; preds = %47, %50, %5, %1
%54 = phi i32 [ -1, %1 ], [ -1, %5 ], [ %52, %50 ], [ %12, %47 ]
ret i32 %54
}