#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*/ FILE;

/* Variables and functions */
int LINE_MAX;
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcmp(char *, char *);
void check_mounts(void) {
  FILE *file;
  char line[LINE_MAX], *s, *e;
  int tmp, proc, sys, dev;
  file = fopen("/proc/mounts", "r");
  if (!file)
    error("Failed to open /proc/mounts.\n");
  tmp = proc = sys = dev = 0;
  while (fgets(line, sizeof line, file)) {
    s = strchr(line, ' ');
    if (!s)
      continue;
    e = strchr(++s, ' ');
    if (!e)
      continue;
    *e = 0;
    if (!strcmp(s, "/usr/lib/fw32"
                   "/tmp"))
      tmp = 1;
    else if (!strcmp(s, "/usr/lib/fw32"
                        "/proc"))
      proc = 1;
    else if (!strcmp(s, "/usr/lib/fw32"
                        "/sys"))
      sys = 1;
    else if (!strcmp(s, "/usr/lib/fw32"
                        "/dev"))
      dev = 1;
  }
  if (!tmp || !proc || !sys || !dev) {
    fclose(file);
    error("fw32 root directories are not mounted.\n");
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<check_mounts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x48(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
lea    0xe61(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11c6 <check_mounts+0x66>
lea    0xe4e(%rip),%rdi
call   1070 <error@plt>
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    %eax,%esi
mov    -0x8(%rbp),%rdx
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12f5 <check_mounts+0x195>
mov    -0x40(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1221 <check_mounts+0xc1>
jmp    11e2 <check_mounts+0x82>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x20(%rbp)
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    124b <check_mounts+0xeb>
jmp    11e2 <check_mounts+0x82>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
lea    0xdd0(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1277 <check_mounts+0x117>
movl   $0x1,-0x2c(%rbp)
jmp    12f0 <check_mounts+0x190>
mov    -0x20(%rbp),%rdi
lea    0xdbd(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    129c <check_mounts+0x13c>
movl   $0x1,-0x30(%rbp)
jmp    12eb <check_mounts+0x18b>
mov    -0x20(%rbp),%rdi
lea    0xdab(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    12c1 <check_mounts+0x161>
movl   $0x1,-0x34(%rbp)
jmp    12e6 <check_mounts+0x186>
mov    -0x20(%rbp),%rdi
lea    0xd98(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    12e1 <check_mounts+0x181>
movl   $0x1,-0x38(%rbp)
jmp    12e6 <check_mounts+0x186>
jmp    12eb <check_mounts+0x18b>
jmp    12f0 <check_mounts+0x190>
jmp    11e2 <check_mounts+0x82>
cmpl   $0x0,-0x2c(%rbp)
je     131d <check_mounts+0x1bd>
cmpl   $0x0,-0x30(%rbp)
je     131d <check_mounts+0x1bd>
cmpl   $0x0,-0x34(%rbp)
je     131d <check_mounts+0x1bd>
cmpl   $0x0,-0x38(%rbp)
jne    1332 <check_mounts+0x1d2>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xd49(%rip),%rdi
call   1070 <error@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_mounts>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e70(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%rbx
mov    %r15,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe6a(%rip),%rdi
lea    0xe70(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11b6 <check_mounts+0x56>
lea    0xe5e(%rip),%rdi
call   1070 <error@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     12ce <check_mounts+0x16e>
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
xor    %r12d,%r12d
xor    %r13d,%r13d
mov    %r13d,-0x2c(%rbp)
jmp    1207 <check_mounts+0xa7>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     12c3 <check_mounts+0x163>
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11f0 <check_mounts+0x90>
mov    %rax,%r13
add    $0x1,%r13
mov    %r13,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11f0 <check_mounts+0x90>
movb   $0x0,(%rax)
mov    %r13,%rdi
lea    0xdee(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     128f <check_mounts+0x12f>
mov    %r13,%rdi
lea    0xded(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1297 <check_mounts+0x137>
mov    %r13,%rdi
lea    0xded(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     129f <check_mounts+0x13f>
mov    %r13,%rdi
lea    0xdec(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
mov    -0x30(%rbp),%eax
mov    $0x1,%ecx
cmove  %ecx,%eax
mov    %eax,-0x30(%rbp)
jmp    12a6 <check_mounts+0x146>
mov    $0x1,%r13d
jmp    12aa <check_mounts+0x14a>
mov    $0x1,%r12d
jmp    12a6 <check_mounts+0x146>
movl   $0x1,-0x34(%rbp)
mov    -0x2c(%rbp),%r13d
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11e1 <check_mounts+0x81>
jmp    12c7 <check_mounts+0x167>
mov    -0x2c(%rbp),%r13d
test   %r13d,%r13d
jne    12e7 <check_mounts+0x187>
jmp    12f8 <check_mounts+0x198>
xor    %r13d,%r13d
xor    %r12d,%r12d
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x30(%rbp)
test   %r13d,%r13d
je     12f8 <check_mounts+0x198>
test   %r12d,%r12d
je     12f8 <check_mounts+0x198>
cmpl   $0x0,-0x34(%rbp)
je     12f8 <check_mounts+0x198>
cmpl   $0x0,-0x30(%rbp)
jne    130c <check_mounts+0x1ac>
mov    %r14,%rdi
call   1030 <fclose@plt>
lea    0xd6f(%rip),%rdi
call   1070 <error@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@LINE_MAX = global i32 0
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"Failed to open /proc/mounts.\0A\00"
@.str.3 = [18 x i8] c"/usr/lib/fw32/tmp\00"
@.str.4 = [19 x i8] c"/usr/lib/fw32/proc\00"
@.str.5 = [18 x i8] c"/usr/lib/fw32/sys\00"
@.str.6 = [18 x i8] c"/usr/lib/fw32/dev\00"
@.str.7 = [40 x i8] c"fw32 root directories are not mounted.\0A\00"
define void @check_mounts() {
%1 = alloca i32*
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = load i32, i32* @LINE_MAX
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %2
%13 = alloca i8, i64 %11
store i64 %11, i64* %3
%14 = call i32* @fopen(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* %14, i32** %1
%15 = load i32*, i32** %1
%16 = icmp ne i32* %15, null
br i1 %16, label %19, label %17
17: ; preds = %0
%18 = call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %0
store i32 0, i32* %9
store i32 0, i32* %8
store i32 0, i32* %7
store i32 0, i32* %6
br label %20
20: ; preds = %61, %36, %29, %19
%21 = trunc i64 %11 to i32
%22 = load i32*, i32** %1
%23 = call i64 @fgets(i8* %13, i32 %21, i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %62
25: ; preds = %20
%26 = call i8* @strchr(i8* %13, i8 signext 32)
store i8* %26, i8** %4
%27 = load i8*, i8** %4
%28 = icmp ne i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %25
br label %20
30: ; preds = %25
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %4
%33 = call i8* @strchr(i8* %32, i8 signext 32)
store i8* %33, i8** %5
%34 = load i8*, i8** %5
%35 = icmp ne i8* %34, null
br i1 %35, label %37, label %36
36: ; preds = %30
br label %20
37: ; preds = %30
%38 = load i8*, i8** %5
store i8 0, i8* %38
%39 = load i8*, i8** %4
%40 = call i32 @strcmp(i8* %39, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%41 = icmp ne i32 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %37
store i32 1, i32* %6
br label %61
43: ; preds = %37
%44 = load i8*, i8** %4
%45 = call i32 @strcmp(i8* %44, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%46 = icmp ne i32 %45, 0
br i1 %46, label %48, label %47
47: ; preds = %43
store i32 1, i32* %7
br label %60
48: ; preds = %43
%49 = load i8*, i8** %4
%50 = call i32 @strcmp(i8* %49, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%51 = icmp ne i32 %50, 0
br i1 %51, label %53, label %52
52: ; preds = %48
store i32 1, i32* %8
br label %59
53: ; preds = %48
%54 = load i8*, i8** %4
%55 = call i32 @strcmp(i8* %54, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%56 = icmp ne i32 %55, 0
br i1 %56, label %58, label %57
57: ; preds = %53
store i32 1, i32* %9
br label %58
58: ; preds = %57, %53
br label %59
59: ; preds = %58, %52
br label %60
60: ; preds = %59, %47
br label %61
61: ; preds = %60, %42
br label %20
62: ; preds = %20
%63 = load i32, i32* %6
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %74
65: ; preds = %62
%66 = load i32, i32* %7
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %74
68: ; preds = %65
%69 = load i32, i32* %8
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %68
%72 = load i32, i32* %9
%73 = icmp ne i32 %72, 0
br i1 %73, label %78, label %74
74: ; preds = %71, %68, %65, %62
%75 = load i32*, i32** %1
%76 = call i32 @fclose(i32* %75)
%77 = call i32 @error(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0))
br label %78
78: ; preds = %74, %71
%79 = load i32*, i32** %1
%80 = call i32 @fclose(i32* %79)
%81 = load i8*, i8** %2
ret void
}

LLVM IR (-O2):
@LINE_MAX = global i32 0
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"Failed to open /proc/mounts.\0A\00"
@.str.3 = [18 x i8] c"/usr/lib/fw32/tmp\00"
@.str.4 = [19 x i8] c"/usr/lib/fw32/proc\00"
@.str.5 = [18 x i8] c"/usr/lib/fw32/sys\00"
@.str.6 = [18 x i8] c"/usr/lib/fw32/dev\00"
@.str.7 = [40 x i8] c"fw32 root directories are not mounted.\0A\00"
define void @check_mounts() {
%1 = load i32, i32* @LINE_MAX
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = tail call i32* @fopen(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))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i64 @fgets(i8* %3, i32 %1, i32* %4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %46, label %11
11: ; preds = %8, %39
%12 = phi i32 [ %43, %39 ], [ 0, %8 ]
%13 = phi i32 [ %42, %39 ], [ 0, %8 ]
%14 = phi i32 [ %41, %39 ], [ 0, %8 ]
%15 = phi i32 [ %40, %39 ], [ 0, %8 ]
br label %16
16: ; preds = %11, %19
%17 = call i8* @strchr(i8* %3, i8 signext 32)
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16, %22
%20 = call i64 @fgets(i8* %3, i32 %1, i32* %4)
%21 = icmp eq i64 %20, 0
br i1 %21, label %46, label %16
22: ; preds = %16
%23 = getelementptr inbounds i8, i8* %17, i64 1
%24 = call i8* @strchr(i8* %23, i8 signext 32)
%25 = icmp eq i8* %24, null
br i1 %25, label %19, label %26
26: ; preds = %22
store i8 0, i8* %24
%27 = call i32 @strcmp(i8* %23, i8* dereferenceable(18) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i32 %27, 0
br i1 %28, label %39, label %29
29: ; preds = %26
%30 = call i32 @strcmp(i8* %23, i8* dereferenceable(19) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp eq i32 %30, 0
br i1 %31, label %39, label %32
32: ; preds = %29
%33 = call i32 @strcmp(i8* %23, i8* dereferenceable(18) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%34 = icmp eq i32 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %32
%36 = call i32 @strcmp(i8* %23, i8* dereferenceable(18) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%37 = icmp eq i32 %36, 0
%38 = select i1 %37, i32 1, i32 %12
br label %39
39: ; preds = %35, %32, %29, %26
%40 = phi i32 [ 1, %26 ], [ %15, %29 ], [ %15, %32 ], [ %15, %35 ]
%41 = phi i32 [ %14, %26 ], [ 1, %29 ], [ %14, %32 ], [ %14, %35 ]
%42 = phi i32 [ %13, %26 ], [ %13, %29 ], [ 1, %32 ], [ %13, %35 ]
%43 = phi i32 [ %12, %26 ], [ %12, %29 ], [ %12, %32 ], [ %38, %35 ]
%44 = call i64 @fgets(i8* %3, i32 %1, i32* %4)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %11
46: ; preds = %39, %19, %8
%47 = phi i32 [ 0, %8 ], [ %15, %19 ], [ %40, %39 ]
%48 = phi i32 [ 0, %8 ], [ %14, %19 ], [ %41, %39 ]
%49 = phi i32 [ 0, %8 ], [ %13, %19 ], [ %42, %39 ]
%50 = phi i32 [ 0, %8 ], [ %12, %19 ], [ %43, %39 ]
%51 = icmp ne i32 %47, 0
%52 = icmp ne i32 %48, 0
%53 = select i1 %51, i1 %52, i1 false
%54 = icmp ne i32 %49, 0
%55 = select i1 %53, i1 %54, i1 false
%56 = icmp ne i32 %50, 0
%57 = select i1 %55, i1 %56, i1 false
br i1 %57, label %61, label %58
58: ; preds = %46
%59 = call i32 @fclose(i32* %4)
%60 = call i32 @error(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0))
br label %61
61: ; preds = %46, %58
%62 = call i32 @fclose(i32* %4)
ret void
}