#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ *gl_pathv;
  int /*<<< orphan*/ gl_pathc;
};
typedef TYPE_1__ glob_t;

/* Variables and functions */
int currentRunlevel();
int /*<<< orphan*/ exit(int);
scalar_t__ findServiceEntries(char const *, char const *, int, TYPE_1__ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ globfree(TYPE_1__ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strstr(int /*<<< orphan*/, char *);
int isOn(const char *RUNLEVELS, const char *name, int level) {
  glob_t globres;
  if (level == -1) {
    level = currentRunlevel();
    if (level == -1) {
      fprintf(stderr, "cannot determine current run level\n");
      return 0;
    }
  }
  if (findServiceEntries(RUNLEVELS, name, level, &globres))
    exit(1);
  if (!globres.gl_pathc || !strstr(globres.gl_pathv[0], "/S"))
    return 0;
  globfree(&globres);
  return 1;
}


x86 assembly (clang, -O0):
<isOn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11b7 <isOn+0x57>
mov    $0x0,%al
call   1070 <currentRunlevel@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11b2 <isOn+0x52>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1220 <isOn+0xc0>
jmp    11b7 <isOn+0x57>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0x30(%rbp),%rcx
call   1040 <findServiceEntries@plt>
cmp    $0x0,%rax
je     11df <isOn+0x7f>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x28(%rbp)
je     1204 <isOn+0xa4>
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%eax
jne    1210 <isOn+0xb0>
movl   $0x0,-0x4(%rbp)
jmp    1220 <isOn+0xc0>
lea    -0x30(%rbp),%rdi
call   1030 <globfree@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isOn>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
cmp    $0xffffffff,%edx
jne    1184 <isOn+0x24>
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <currentRunlevel@plt>
mov    %eax,%edx
cmp    $0xffffffff,%eax
je     11c7 <isOn+0x67>
mov    %rsp,%rcx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <findServiceEntries@plt>
test   %rax,%rax
jne    11e8 <isOn+0x88>
xor    %r14d,%r14d
cmpl   $0x0,0x8(%rsp)
je     11dc <isOn+0x7c>
mov    (%rsp),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
call   1080 <strstr@plt>
test   %eax,%eax
je     11dc <isOn+0x7c>
mov    %rsp,%rdi
call   1030 <globfree@plt>
mov    $0x1,%r14d
jmp    11dc <isOn+0x7c>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
call   1050 <fprintf@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32*, i32 }
@stderr = global i32 0
@.str = [36 x i8] c"cannot determine current run level\0A\00"
@.str.1 = [3 x i8] c"/S\00"
define i32 @isOn(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.TYPE_4__
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %19
11: ; preds = %3
%12 = call i32 (...) @currentRunlevel()
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %41
18: ; preds = %11
br label %19
19: ; preds = %18, %3
%20 = load i8*, i8** %5
%21 = load i8*, i8** %6
%22 = load i32, i32* %7
%23 = call i64 @findServiceEntries(i8* %20, i8* %21, i32 %22, %struct.TYPE_4__* %8)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %19
%28 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %8, i32 0, i32 1
%29 = load i32, i32* %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %27
%32 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %8, i32 0, i32 0
%33 = load i32*, i32** %32
%34 = getelementptr inbounds i32, i32* %33, i64 0
%35 = load i32, i32* %34
%36 = call i32 @strstr(i32 %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %31, %27
store i32 0, i32* %4
br label %41
39: ; preds = %31
%40 = call i32 @globfree(%struct.TYPE_4__* %8)
store i32 1, i32* %4
br label %41
41: ; preds = %39, %38, %15
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32*, i32 }
@stderr = global i32 0
@.str = [36 x i8] c"cannot determine current run level\0A\00"
@.str.1 = [3 x i8] c"/S\00"
define i32 @isOn(i8* %0, i8* %1, i32 %2) {
%4 = alloca %struct.TYPE_4__
%5 = bitcast %struct.TYPE_4__* %4 to i8*
%6 = icmp eq i32 %2, -1
br i1 %6, label %7, label %13
7: ; preds = %3
%8 = tail call i32 (...) @currentRunlevel()
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %31
13: ; preds = %7, %3
%14 = phi i32 [ %8, %7 ], [ %2, %3 ]
%15 = call i64 @findServiceEntries(i8* %0, i8* %1, i32 %14, %struct.TYPE_4__* %4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %13
%20 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %4, i64 0, i32 1
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %31, label %23
23: ; preds = %19
%24 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %4, i64 0, i32 0
%25 = load i32*, i32** %24
%26 = load i32, i32* %25
%27 = call i32 @strstr(i32 %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %23
%30 = call i32 @globfree(%struct.TYPE_4__* %4)
br label %31
31: ; preds = %19, %23, %29, %10
%32 = phi i32 [ 0, %10 ], [ 1, %29 ], [ 0, %23 ], [ 0, %19 ]
ret i32 %32
}