#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*/ STDIN_FILENO;
scalar_t__ apply_rules(char *, int);
scalar_t__ apply_rules_file(int /*<<< orphan*/, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getopt(int, char **, char *);
int is_smackfs_mounted();
int optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  int clear = 0;
  int c;
  if (is_smackfs_mounted() != 1) {
    fprintf(stderr, "SmackFS is not mounted.\n");
    exit(1);
  }
  while ((c = getopt(argc, argv, "c")) != -1) {
    switch (c) {
    case 'c':
      clear = 1;
      break;
    default:
      usage(argv[0]);
    }
  }
  if (optind == argc) {
    if (apply_rules_file(STDIN_FILENO, clear)) {
      perror("apply_rules_file");
      exit(1);
    }
  } else {
    if (apply_rules(argv[optind], clear)) {
      perror("apply_rules");
      exit(1);
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1090 <is_smackfs_mounted@plt>
cmp    $0x1,%eax
je     11cc <main+0x4c>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11d1 <main+0x51>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe3a(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     121e <main+0x9e>
mov    -0x18(%rbp),%eax
sub    $0x63,%eax
jne    120d <main+0x8d>
jmp    1201 <main+0x81>
movl   $0x1,-0x14(%rbp)
jmp    1219 <main+0x99>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <usage@plt>
jmp    11d1 <main+0x51>
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jne    1266 <main+0xe6>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
call   1040 <apply_rules_file@plt>
cmp    $0x0,%rax
je     1261 <main+0xe1>
lea    0xdc9(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    12a5 <main+0x125>
mov    -0x10(%rbp),%rax
mov    0x2d77(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x14(%rbp),%esi
call   10a0 <apply_rules@plt>
cmp    $0x0,%rax
je     12a0 <main+0x120>
lea    0xd9b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    12a5 <main+0x125>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r14d,%r14d
xor    %eax,%eax
call   1090 <is_smackfs_mounted@plt>
cmp    $0x1,%eax
jne    11d1 <main+0x51>
lea    0xe77(%rip),%r15
jmp    11b0 <main+0x30>
mov    $0x1,%r14d
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1070 <getopt@plt>
cmp    $0x63,%eax
je     11a4 <main+0x24>
cmp    $0xffffffff,%eax
je     11f0 <main+0x70>
mov    (%rbx),%rdi
call   1050 <usage@plt>
jmp    11b0 <main+0x30>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2df1(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jne    121d <main+0x9d>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
mov    %r14d,%esi
call   1040 <apply_rules_file@plt>
test   %rax,%rax
je     122e <main+0xae>
lea    0xe00(%rip),%rdi
jmp    123c <main+0xbc>
mov    (%rbx,%rax,8),%rdi
mov    %r14d,%esi
call   10a0 <apply_rules@plt>
test   %rax,%rax
jne    1235 <main+0xb5>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xdf0(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"SmackFS is not mounted.\0A\00"
@.str.1 = [2 x i8] c"c\00"
@optind = global i32 0
@STDIN_FILENO = global i32 0
@.str.2 = [17 x i8] c"apply_rules_file\00"
@.str.3 = [12 x i8] c"apply_rules\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = call i32 (...) @is_smackfs_mounted()
%9 = icmp ne i32 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
br label %15
15: ; preds = %28, %14
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call i32 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 %18, i32* %7
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %29
20: ; preds = %15
%21 = load i32, i32* %7
switch i32 %21, label %23 [
i32 99, label %22
]
22: ; preds = %20
store i32 1, i32* %6
br label %28
23: ; preds = %20
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 @usage(i8* %26)
br label %28
28: ; preds = %23, %22
br label %15
29: ; preds = %15
%30 = load i32, i32* @optind
%31 = load i32, i32* %4
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %42
33: ; preds = %29
%34 = load i32, i32* @STDIN_FILENO
%35 = load i32, i32* %6
%36 = call i64 @apply_rules_file(i32 %34, i32 %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %33
br label %55
42: ; preds = %29
%43 = load i8**, i8*** %5
%44 = load i32, i32* @optind
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = load i32, i32* %6
%49 = call i64 @apply_rules(i8* %47, i32 %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %42
%52 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %42
br label %55
55: ; preds = %54, %41
%56 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"SmackFS is not mounted.\0A\00"
@.str.1 = [2 x i8] c"c\00"
@optind = global i32 0
@STDIN_FILENO = global i32 0
@.str.2 = [17 x i8] c"apply_rules_file\00"
@.str.3 = [12 x i8] c"apply_rules\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 (...) @is_smackfs_mounted()
%4 = icmp eq i32 %3, 1
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %11, %13
%10 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
switch i32 %10, label %13 [
i32 -1, label %16
i32 99, label %11
]
11: ; preds = %9, %2
%12 = phi i32 [ 0, %2 ], [ 1, %9 ]
br label %9
13: ; preds = %9
%14 = load i8*, i8** %1
%15 = tail call i32 @usage(i8* %14)
br label %9
16: ; preds = %9
%17 = load i32, i32* @optind
%18 = icmp eq i32 %17, %0
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i32, i32* @STDIN_FILENO
%21 = tail call i64 @apply_rules_file(i32 %20, i32 %12)
%22 = icmp eq i64 %21, 0
br i1 %22, label %35, label %23
23: ; preds = %19
%24 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %16
%27 = sext i32 %17 to i64
%28 = getelementptr inbounds i8*, i8** %1, i64 %27
%29 = load i8*, i8** %28
%30 = tail call i64 @apply_rules(i8* %29, i32 %12)
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %26
%33 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %26, %19
%36 = tail call i32 @exit(i32 0)
unreachable
}