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

/* Variables and functions */
int /*<<< orphan*/ MS_RDONLY;
int /*<<< orphan*/ SIGTERM;
int grep(char *, char *);
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ mount(char *, char *, char *, int /*<<< orphan*/,
                         int /*<<< orphan*/ *);
int pgrep(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ umount(char *);
int main(void) {
  int sdb1, mnt, proc;
  while (1) {
    sdb1 = grep("sdb1", "/proc/diskstats");
    mnt = grep("sdb1", "/proc/mounts");
    if (sdb1 && !mnt) {
      if ((proc = pgrep("slampler")) != 0)
        kill(proc, SIGTERM);
      mount("/dev/sdb1", "/data", "vfat", MS_RDONLY, NULL);
    }
    if (!sdb1 && mnt) {
      if ((proc = pgrep("slampler")) != 0)
        kill(proc, SIGTERM);
      umount("/data");
    }
    sleep(15);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb5(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1060 <grep@plt>
mov    %eax,-0x8(%rbp)
lea    0xe9f(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1060 <grep@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1200 <main+0xa0>
cmpl   $0x0,-0xc(%rbp)
jne    1200 <main+0xa0>
lea    0xe67(%rip),%rdi
call   1030 <pgrep@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     11d8 <main+0x78>
mov    -0x10(%rbp),%edi
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%ecx
lea    0xe3e(%rip),%rdi
lea    0xe41(%rip),%rsi
lea    0xe40(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1050 <mount@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1249 <main+0xe9>
cmpl   $0x0,-0xc(%rbp)
je     1249 <main+0xe9>
lea    0xe02(%rip),%rdi
call   1030 <pgrep@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     123d <main+0xdd>
mov    -0x10(%rbp),%edi
mov    0x2db2(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
lea    0xdec(%rip),%rdi
call   1040 <umount@plt>
mov    $0xf,%edi
call   1080 <sleep@plt>
jmp    116f <main+0xf>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeb9(%rip),%rbx
lea    0xe97(%rip),%r15
lea    0xe9d(%rip),%r12
lea    0xea9(%rip),%r13
jmp    11a2 <main+0x42>
nopl   0x0(%rax)
mov    %r13,%rdi
call   1040 <umount@plt>
mov    $0xf,%edi
call   1080 <sleep@plt>
mov    %rbx,%rdi
lea    0xe54(%rip),%rsi
call   1060 <grep@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <grep@plt>
mov    %eax,%r14d
test   %ebp,%ebp
je     1208 <main+0xa8>
test   %r14d,%r14d
jne    1208 <main+0xa8>
mov    %r12,%rdi
call   1030 <pgrep@plt>
test   %eax,%eax
je     11e6 <main+0x86>
mov    0x2e0b(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1070 <kill@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%ecx
lea    0xe30(%rip),%rdi
mov    %r13,%rsi
lea    0xe36(%rip),%rdx
xor    %r8d,%r8d
call   1050 <mount@plt>
test   %ebp,%ebp
jne    1198 <main+0x38>
test   %r14d,%r14d
je     1198 <main+0x38>
mov    %r12,%rdi
call   1030 <pgrep@plt>
test   %eax,%eax
je     1190 <main+0x30>
mov    0x2dc0(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1070 <kill@plt>
jmp    1190 <main+0x30>

LLVM IR (-O0):
@.str = [5 x i8] c"sdb1\00"
@.str.1 = [16 x i8] c"/proc/diskstats\00"
@.str.2 = [13 x i8] c"/proc/mounts\00"
@.str.3 = [9 x i8] c"slampler\00"
@SIGTERM = global i32 0
@.str.4 = [10 x i8] c"/dev/sdb1\00"
@.str.5 = [6 x i8] c"/data\00"
@.str.6 = [5 x i8] c"vfat\00"
@MS_RDONLY = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
br label %5
5: ; preds = %0, %38
%6 = call i32 @grep(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 %6, i32* %2
%7 = call i32 @grep(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 %7, i32* %3
%8 = load i32, i32* %2
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %5
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
br i1 %12, label %23, label %13
13: ; preds = %10
%14 = call i32 @pgrep(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i32 %14, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i32, i32* %4
%18 = load i32, i32* @SIGTERM
%19 = call i32 @kill(i32 %17, i32 %18)
br label %20
20: ; preds = %16, %13
%21 = load i32, i32* @MS_RDONLY
%22 = call i32 @mount(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %21, i32* null)
br label %23
23: ; preds = %20, %10, %5
%24 = load i32, i32* %2
%25 = icmp ne i32 %24, 0
br i1 %25, label %38, label %26
26: ; preds = %23
%27 = load i32, i32* %3
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %26
%30 = call i32 @pgrep(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i32 %30, i32* %4
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i32, i32* %4
%34 = load i32, i32* @SIGTERM
%35 = call i32 @kill(i32 %33, i32 %34)
br label %36
36: ; preds = %32, %29
%37 = call i32 @umount(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %38
38: ; preds = %36, %26, %23
%39 = call i32 @sleep(i32 15)
br label %5
}

LLVM IR (-O2):
@.str = [5 x i8] c"sdb1\00"
@.str.1 = [16 x i8] c"/proc/diskstats\00"
@.str.2 = [13 x i8] c"/proc/mounts\00"
@.str.3 = [9 x i8] c"slampler\00"
@SIGTERM = global i32 0
@.str.4 = [10 x i8] c"/dev/sdb1\00"
@.str.5 = [6 x i8] c"/data\00"
@.str.6 = [5 x i8] c"vfat\00"
@MS_RDONLY = global i32 0
define i32 @main() {
br label %1
1: ; preds = %26, %0
%2 = tail call i32 @grep(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @grep(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq i32 %2, 0
%5 = icmp ne i32 %3, 0
%6 = select i1 %4, i1 true, i1 %5
br i1 %6, label %16, label %7
7: ; preds = %1
%8 = tail call i32 @pgrep(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = load i32, i32* @SIGTERM
%12 = tail call i32 @kill(i32 %8, i32 %11)
br label %13
13: ; preds = %10, %7
%14 = load i32, i32* @MS_RDONLY
%15 = tail call i32 @mount(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %14, i32* null)
br label %16
16: ; preds = %13, %1
%17 = select i1 %4, i1 %5, i1 false
br i1 %17, label %18, label %26
18: ; preds = %16
%19 = tail call i32 @pgrep(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i32, i32* @SIGTERM
%23 = tail call i32 @kill(i32 %19, i32 %22)
br label %24
24: ; preds = %21, %18
%25 = tail call i32 @umount(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %26
26: ; preds = %24, %16
%27 = tail call i32 @sleep(i32 15)
br label %1
}