#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 *, int, TYPE_1__ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *gettext(char *);
int /*<<< orphan*/ globfree(TYPE_1__ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strstr(int /*<<< orphan*/, char *);
int isOn(char *name, int level) {
  glob_t globres;
  if (level == -1) {
    level = currentRunlevel();
    if (level == -1) {
      fprintf(stderr, gettext(("cannot determine current run level\n")));
      return 0;
    }
  }
  if (findServiceEntries(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    %esi,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11d1 <isOn+0x61>
mov    $0x0,%al
call   1080 <currentRunlevel@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11cc <isOn+0x5c>
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
lea    0xe50(%rip),%rdi
call   1040 <gettext@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1236 <isOn+0xc6>
jmp    11d1 <isOn+0x61>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x28(%rbp),%rdx
call   1050 <findServiceEntries@plt>
cmp    $0x0,%rax
je     11f5 <isOn+0x85>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x20(%rbp)
je     121a <isOn+0xaa>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%eax
jne    1226 <isOn+0xb6>
movl   $0x0,-0x4(%rbp)
jmp    1236 <isOn+0xc6>
lea    -0x28(%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   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
cmp    $0xffffffff,%esi
jne    118e <isOn+0x1e>
xor    %ebp,%ebp
xor    %eax,%eax
call   1080 <currentRunlevel@plt>
mov    %eax,%esi
cmp    $0xffffffff,%eax
je     11d1 <isOn+0x61>
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <findServiceEntries@plt>
test   %rax,%rax
jne    11f9 <isOn+0x89>
xor    %ebp,%ebp
cmpl   $0x0,0x10(%rsp)
je     11f0 <isOn+0x80>
mov    0x8(%rsp),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1090 <strstr@plt>
test   %eax,%eax
je     11f0 <isOn+0x80>
lea    0x8(%rsp),%rdi
call   1030 <globfree@plt>
mov    $0x1,%ebp
jmp    11f0 <isOn+0x80>
mov    0x2e08(%rip),%rax
mov    (%rax),%ebx
lea    0xe1f(%rip),%rdi
call   1040 <gettext@plt>
mov    %ebx,%edi
mov    %rax,%rsi
call   1060 <fprintf@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
mov    $0x1,%edi
call   1070 <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, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.TYPE_4__
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %18
9: ; preds = %2
%10 = call i32 (...) @currentRunlevel()
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = call i8* @gettext(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @fprintf(i32 %14, i8* %15)
store i32 0, i32* %3
br label %39
17: ; preds = %9
br label %18
18: ; preds = %17, %2
%19 = load i8*, i8** %4
%20 = load i32, i32* %5
%21 = call i64 @findServiceEntries(i8* %19, i32 %20, %struct.TYPE_4__* %6)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %18
%26 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 1
%27 = load i32, i32* %26
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %25
%30 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 0
%31 = load i32*, i32** %30
%32 = getelementptr inbounds i32, i32* %31, i64 0
%33 = load i32, i32* %32
%34 = call i32 @strstr(i32 %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %29, %25
store i32 0, i32* %3
br label %39
37: ; preds = %29
%38 = call i32 @globfree(%struct.TYPE_4__* %6)
store i32 1, i32* %3
br label %39
39: ; preds = %37, %36, %13
%40 = load i32, i32* %3
ret i32 %40
}

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, i32 %1) {
%3 = alloca %struct.TYPE_4__
%4 = bitcast %struct.TYPE_4__* %3 to i8*
%5 = icmp eq i32 %1, -1
br i1 %5, label %6, label %13
6: ; preds = %2
%7 = tail call i32 (...) @currentRunlevel()
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = tail call i8* @gettext(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @fprintf(i32 %10, i8* %11)
br label %31
13: ; preds = %6, %2
%14 = phi i32 [ %7, %6 ], [ %1, %2 ]
%15 = call i64 @findServiceEntries(i8* %0, i32 %14, %struct.TYPE_4__* %3)
%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__* %3, 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__* %3, 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__* %3)
br label %31
31: ; preds = %19, %23, %29, %9
%32 = phi i32 [ 0, %9 ], [ 1, %29 ], [ 0, %23 ], [ 0, %19 ]
ret i32 %32
}