#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 */
typedef int /*<<< orphan*/ cmd;

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ RB_AUTOBOOT;
int WEXITSTATUS(int /*<<< orphan*/);
char *get_lv_fstype(char const *);
int /*<<< orphan*/ logprintf(char *, ...);
int /*<<< orphan*/ reboot(int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int /*<<< orphan*/ sync();
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ umount_lv(char const *);
void check_lv(const char *lv) {
  int code;
  char cmd[PATH_MAX], *type;
  logprintf("0checking filesystem on volume %s", lv);
  umount_lv(lv);
  type = get_lv_fstype(lv);
  if (!strcmp(type, "none") || !strcmp(type, "swap"))
    return;
  else if (!strncmp(type, "ext", 3))
    snprintf(cmd, sizeof(cmd), "e2fsck -fy /dev/store/%s", lv);
  else if (!strcmp(type, "vfat") || !strcmp(type, "msdos"))
    snprintf(cmd, sizeof(cmd), "dosfsck -aw /dev/store/%s", lv);
  else {
    logprintf("2error: unknown fstype %s", type);
    return;
  }
  code = WEXITSTATUS(system(cmd));
  if (code > 7) {
    logprintf("2error: fsck quit with abnormal code %d", code);
    return;
  }
  if (code & 1)
    logprintf("2%s", "warning: errors were fixed");
  if (code & 4)
    logprintf("2%s", "warning: errors were left unfixed");
  if (code & 2) {
    logprintf("2%s", "system restart was requested, will reboot in 5s");
    sleep(3);
    sync();
    reboot(RB_AUTOBOOT);
  }
}


x86 assembly (clang, -O0):
<check_lv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   10d0 <logprintf@plt>
mov    -0x8(%rbp),%rdi
call   10a0 <umount_lv@plt>
mov    -0x8(%rbp),%rdi
call   1050 <get_lv_fstype@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     1246 <check_lv+0x96>
mov    -0x28(%rbp),%rdi
lea    0xdef(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1252 <check_lv+0xa2>
movl   $0x1,-0x2c(%rbp)
jmp    13d4 <check_lv+0x224>
mov    -0x28(%rbp),%rdi
lea    0xdcf(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    128f <check_lv+0xdf>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
lea    0xdab(%rip),%rdx
call   1060 <snprintf@plt>
jmp    1303 <check_lv+0x153>
mov    -0x28(%rbp),%rdi
lea    0xdaf(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     12c1 <check_lv+0x111>
mov    -0x28(%rbp),%rdi
lea    0xd9b(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    12e0 <check_lv+0x130>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
lea    0xd7e(%rip),%rdx
call   1060 <snprintf@plt>
jmp    12fe <check_lv+0x14e>
mov    -0x28(%rbp),%rsi
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   10d0 <logprintf@plt>
movl   $0x1,-0x2c(%rbp)
jmp    13d4 <check_lv+0x224>
jmp    1303 <check_lv+0x153>
jmp    1308 <check_lv+0x158>
mov    -0x38(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,%edi
call   1090 <WEXITSTATUS@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x7,-0xc(%rbp)
jle    1342 <check_lv+0x192>
mov    -0xc(%rbp),%esi
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   10d0 <logprintf@plt>
movl   $0x1,-0x2c(%rbp)
jmp    13d4 <check_lv+0x224>
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1366 <check_lv+0x1b6>
lea    0xd58(%rip),%rdi
lea    0xd55(%rip),%rsi
mov    $0x0,%al
call   10d0 <logprintf@plt>
mov    -0xc(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     138a <check_lv+0x1da>
lea    0xd34(%rip),%rdi
lea    0xd4c(%rip),%rsi
mov    $0x0,%al
call   10d0 <logprintf@plt>
mov    -0xc(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     13cd <check_lv+0x21d>
lea    0xd10(%rip),%rdi
lea    0xd4a(%rip),%rsi
mov    $0x0,%al
call   10d0 <logprintf@plt>
mov    $0x3,%edi
call   10c0 <sleep@plt>
mov    $0x0,%al
call   1080 <sync@plt>
mov    0x2c12(%rip),%rax
mov    (%rax),%edi
call   10b0 <reboot@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_lv>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    0x2e28(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r12
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe1d(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   10d0 <logprintf@plt>
mov    %r15,%rdi
call   10a0 <umount_lv@plt>
mov    %r15,%rdi
call   1050 <get_lv_fstype@plt>
mov    %rax,%rbx
lea    0xe1b(%rip),%rsi
mov    %rax,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1315 <check_lv+0x165>
lea    0xe09(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1315 <check_lv+0x165>
lea    0xdf7(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1292 <check_lv+0xe2>
lea    0xdfc(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
lea    0xdf8(%rip),%r13
test   %eax,%eax
je     1299 <check_lv+0xe9>
lea    0xde7(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1299 <check_lv+0xe9>
lea    0xdf4(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10d0 <logprintf@plt>
lea    0xd97(%rip),%r13
mov    %r12,%rdi
mov    %r14d,%esi
mov    %r13,%rdx
mov    %r15,%rcx
call   1060 <snprintf@plt>
mov    %r12,%rdi
call   1040 <system@plt>
mov    %eax,%edi
call   1090 <WEXITSTATUS@plt>
mov    %eax,%ebx
cmp    $0x8,%eax
jl     12d2 <check_lv+0x122>
lea    0xdc1(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   10d0 <logprintf@plt>
jmp    1315 <check_lv+0x165>
test   $0x1,%bl
jne    1324 <check_lv+0x174>
test   $0x4,%bl
jne    133e <check_lv+0x18e>
test   $0x2,%bl
je     1315 <check_lv+0x165>
lea    0xdc8(%rip),%rdi
lea    0xe02(%rip),%rsi
xor    %eax,%eax
call   10d0 <logprintf@plt>
mov    $0x3,%edi
call   10c0 <sleep@plt>
xor    %eax,%eax
call   1080 <sync@plt>
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
call   10b0 <reboot@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd85(%rip),%rdi
lea    0xd82(%rip),%rsi
xor    %eax,%eax
call   10d0 <logprintf@plt>
test   $0x4,%bl
je     12dc <check_lv+0x12c>
lea    0xd6b(%rip),%rdi
lea    0xd83(%rip),%rsi
xor    %eax,%eax
call   10d0 <logprintf@plt>
test   $0x2,%bl
jne    12e1 <check_lv+0x131>
jmp    1315 <check_lv+0x165>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [34 x i8] c"0checking filesystem on volume %s\00"
@.str.1 = [5 x i8] c"none\00"
@.str.2 = [5 x i8] c"swap\00"
@.str.3 = [4 x i8] c"ext\00"
@.str.4 = [25 x i8] c"e2fsck -fy /dev/store/%s\00"
@.str.5 = [5 x i8] c"vfat\00"
@.str.6 = [6 x i8] c"msdos\00"
@.str.7 = [26 x i8] c"dosfsck -aw /dev/store/%s\00"
@.str.8 = [26 x i8] c"2error: unknown fstype %s\00"
@.str.9 = [40 x i8] c"2error: fsck quit with abnormal code %d\00"
@.str.10 = [4 x i8] c"2%s\00"
@.str.11 = [27 x i8] c"warning: errors were fixed\00"
@.str.12 = [34 x i8] c"warning: errors were left unfixed\00"
@.str.13 = [48 x i8] c"system restart was requested, will reboot in 5s\00"
@RB_AUTOBOOT = global i32 0
define void @check_lv(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i32, i32* @PATH_MAX
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %4
%11 = alloca i8, i64 %9
store i64 %9, i64* %5
%12 = load i8*, i8** %2
%13 = call i32 (i8*, ...) @logprintf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %2
%15 = call i32 @umount_lv(i8* %14)
%16 = load i8*, i8** %2
%17 = call i8* @get_lv_fstype(i8* %16)
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = call i32 @strcmp(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %1
%22 = load i8*, i8** %6
%23 = call i32 @strcmp(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp ne i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %21, %1
store i32 1, i32* %7
br label %82
26: ; preds = %21
%27 = load i8*, i8** %6
%28 = call i32 @strncmp(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%29 = icmp ne i32 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = trunc i64 %9 to i32
%32 = load i8*, i8** %2
%33 = call i32 @snprintf(i8* %11, i32 %31, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %32)
br label %50
34: ; preds = %26
%35 = load i8*, i8** %6
%36 = call i32 @strcmp(i8* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i8*, i8** %6
%40 = call i32 @strcmp(i8* %39, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%41 = icmp ne i32 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %38, %34
%43 = trunc i64 %9 to i32
%44 = load i8*, i8** %2
%45 = call i32 @snprintf(i8* %11, i32 %43, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %44)
br label %49
46: ; preds = %38
%47 = load i8*, i8** %6
%48 = call i32 (i8*, ...) @logprintf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i8* %47)
store i32 1, i32* %7
br label %82
49: ; preds = %42
br label %50
50: ; preds = %49, %30
br label %51
51: ; preds = %50
%52 = call i32 @system(i8* %11)
%53 = call i32 @WEXITSTATUS(i32 %52)
store i32 %53, i32* %3
%54 = load i32, i32* %3
%55 = icmp sgt i32 %54, 7
br i1 %55, label %56, label %59
56: ; preds = %51
%57 = load i32, i32* %3
%58 = call i32 (i8*, ...) @logprintf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0), i32 %57)
store i32 1, i32* %7
br label %82
59: ; preds = %51
%60 = load i32, i32* %3
%61 = and i32 %60, 1
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %59
%64 = call i32 (i8*, ...) @logprintf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
br label %65
65: ; preds = %63, %59
%66 = load i32, i32* %3
%67 = and i32 %66, 4
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %65
%70 = call i32 (i8*, ...) @logprintf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.12, i64 0, i64 0))
br label %71
71: ; preds = %69, %65
%72 = load i32, i32* %3
%73 = and i32 %72, 2
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %81
75: ; preds = %71
%76 = call i32 (i8*, ...) @logprintf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.13, i64 0, i64 0))
%77 = call i32 @sleep(i32 3)
%78 = call i32 (...) @sync()
%79 = load i32, i32* @RB_AUTOBOOT
%80 = call i32 @reboot(i32 %79)
br label %81
81: ; preds = %75, %71
store i32 0, i32* %7
br label %82
82: ; preds = %81, %56, %46, %25
%83 = load i8*, i8** %4
%84 = load i32, i32* %7
switch i32 %84, label %86 [
i32 0, label %85
i32 1, label %85
]
85: ; preds = %82, %82
ret void
86: ; preds = %82
unreachable
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [34 x i8] c"0checking filesystem on volume %s\00"
@.str.1 = [5 x i8] c"none\00"
@.str.2 = [5 x i8] c"swap\00"
@.str.3 = [4 x i8] c"ext\00"
@.str.4 = [25 x i8] c"e2fsck -fy /dev/store/%s\00"
@.str.5 = [5 x i8] c"vfat\00"
@.str.6 = [6 x i8] c"msdos\00"
@.str.7 = [26 x i8] c"dosfsck -aw /dev/store/%s\00"
@.str.8 = [26 x i8] c"2error: unknown fstype %s\00"
@.str.9 = [40 x i8] c"2error: fsck quit with abnormal code %d\00"
@.str.10 = [4 x i8] c"2%s\00"
@.str.11 = [27 x i8] c"warning: errors were fixed\00"
@.str.12 = [34 x i8] c"warning: errors were left unfixed\00"
@.str.13 = [48 x i8] c"system restart was requested, will reboot in 5s\00"
@RB_AUTOBOOT = global i32 0
define void @check_lv(i8* %0) {
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = tail call i32 (i8*, ...) @logprintf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = tail call i32 @umount_lv(i8* %0)
%7 = tail call i8* @get_lv_fstype(i8* %0)
%8 = tail call i32 @strcmp(i8* dereferenceable(1) %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %51, label %10
10: ; preds = %1
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %51, label %13
13: ; preds = %10
%14 = tail call i32 @strncmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %24, label %16
16: ; preds = %13
%17 = tail call i32 @strcmp(i8* dereferenceable(1) %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %16
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %7, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = tail call i32 (i8*, ...) @logprintf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i8* %7)
br label %51
24: ; preds = %16, %19, %13
%25 = phi i8* [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), %13 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), %19 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), %16 ]
%26 = call i32 @snprintf(i8* %4, i32 %2, i8* %25, i8* %0)
%27 = call i32 @system(i8* %4)
%28 = call i32 @WEXITSTATUS(i32 %27)
%29 = icmp sgt i32 %28, 7
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 (i8*, ...) @logprintf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0), i32 %28)
br label %51
32: ; preds = %24
%33 = and i32 %28, 1
%34 = icmp eq i32 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = call i32 (i8*, ...) @logprintf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
br label %37
37: ; preds = %35, %32
%38 = and i32 %28, 4
%39 = icmp eq i32 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %37
%41 = call i32 (i8*, ...) @logprintf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.12, i64 0, i64 0))
br label %42
42: ; preds = %40, %37
%43 = and i32 %28, 2
%44 = icmp eq i32 %43, 0
br i1 %44, label %51, label %45
45: ; preds = %42
%46 = call i32 (i8*, ...) @logprintf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.13, i64 0, i64 0))
%47 = call i32 @sleep(i32 3)
%48 = call i32 (...) @sync()
%49 = load i32, i32* @RB_AUTOBOOT
%50 = call i32 @reboot(i32 %49)
br label %51
51: ; preds = %42, %45, %1, %10, %30, %22
ret void
}