#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_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    1322 <vss_operate+0x1b2>
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    1322 <vss_operate+0x1b2>
jmp    1236 <vss_operate+0xc6>
mov    -0x20(%rbp),%rdi
call   1080 <getmntent@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     12f0 <vss_operate+0x180>
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    0x8(%rax),%rdi
lea    0xd4e(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12d1 <vss_operate+0x161>
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     131c <vss_operate+0x1ac>
mov    -0x2c(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xcf3(%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    12be <vss_operate+0x14e>
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     12be <vss_operate+0x14e>
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     1292 <vss_operate+0x122>
mov    %rax,%r14
jmp    1230 <vss_operate+0xc0>
xchg   %ax,%ax
mov    %rbp,%rdi
call   1080 <getmntent@plt>
mov    %rax,%r14
test   %rax,%rax
je     1292 <vss_operate+0x122>
mov    0x10(%r14),%r15d
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1220 <vss_operate+0xb0>
mov    (%r14),%rdi
mov    %r13,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1220 <vss_operate+0xb0>
mov    0x8(%r14),%rdi
lea    0xd9b(%rip),%rsi
call   1070 <strcmp@plt>
mov    $0x1,%ecx
test   %rax,%rax
je     1209 <vss_operate+0x99>
mov    0x8(%r14),%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     12bb <vss_operate+0x14b>
lea    0xd5e(%rip),%rdi
mov    0x4(%rsp),%esi
mov    0x10(%rsp),%rdx
call   1060 <vss_do_freeze@plt>
mov    (%rsp),%ebx
or     %eax,%ebx
jmp    12be <vss_operate+0x14e>
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 = [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 %74
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 %74
23: ; preds = %18
br label %24
24: ; preds = %52, %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 %61
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 1
%48 = load i8*, i8** %47
%49 = call i64 @strcmp(i8* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %45
store i32 1, i32* %10
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 = load i32, i32* %8
%57 = load i8*, i8** %4
%58 = call i32 @vss_do_freeze(i8* %55, i32 %56, i8* %57)
%59 = load i32, i32* %9
%60 = or i32 %59, %58
store i32 %60, i32* %9
br label %24
61: ; preds = %24
%62 = load i32*, i32** %6
%63 = call i32 @endmntent(i32* %62)
%64 = load i32, i32* %10
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %72
66: ; preds = %61
%67 = load i32, i32* %8
%68 = load i8*, i8** %4
%69 = call i32 @vss_do_freeze(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 %67, i8* %68)
%70 = load i32, i32* %9
%71 = or i32 %70, %69
store i32 %71, i32* %9
br label %72
72: ; preds = %66, %61
%73 = load i32, i32* %9
store i32 %73, i32* %2
br label %74
74: ; preds = %72, %22, %17
%75 = load i32, i32* %2
ret i32 %75
}

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 = [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 %49 [
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 %49, label %11
11: ; preds = %5, %38
%12 = phi i32 [ %42, %38 ], [ 0, %5 ]
%13 = phi i32 [ %15, %38 ], [ 0, %5 ]
br label %14
14: ; preds = %11, %33
%15 = phi i32 [ %13, %11 ], [ 1, %33 ]
%16 = call %struct.mntent* @getmntent(i32* %9)
%17 = icmp eq %struct.mntent* %16, null
br i1 %17, label %43, 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
%26 = call %struct.mntent* @getmntent(i32* %9)
%27 = icmp eq %struct.mntent* %26, null
br i1 %27, label %43, 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 = getelementptr inbounds %struct.mntent, %struct.mntent* %19, i64 0, i32 1
%35 = load i8*, i8** %34
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %14, label %38
38: ; preds = %33
%39 = getelementptr inbounds %struct.mntent, %struct.mntent* %19, i64 0, i32 1
%40 = load i8*, i8** %39
%41 = call i32 @vss_do_freeze(i8* %40, i32 %8, i8* %6)
%42 = or i32 %41, %12
br label %11
43: ; preds = %14, %25
%44 = call i32 @endmntent(i32* %9)
%45 = icmp eq i32 %15, 0
br i1 %45, label %49, label %46
46: ; preds = %43
%47 = call i32 @vss_do_freeze(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 %8, i8* %6)
%48 = or i32 %47, %12
br label %49
49: ; preds = %43, %46, %5, %1
%50 = phi i32 [ -1, %1 ], [ -1, %5 ], [ %48, %46 ], [ %12, %43 ]
ret i32 %50
}