#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__ {
  char **gl_pathv;
  int /*<<< orphan*/ gl_pathc;
};
typedef TYPE_1__ glob_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ findServiceEntries(char *, int, TYPE_1__ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ globfree(TYPE_1__ *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
char *strndup(char *, int);
int isConfigured(char *name, int level, int *priority, char *type) {
  glob_t globres;
  char *pri_string;
  if (findServiceEntries(name, level, &globres))
    exit(1);
  if (!globres.gl_pathc)
    return 0;
  if (type) {
    *type = globres.gl_pathv[0][11];
  }
  if (priority) {
    pri_string = strndup(globres.gl_pathv[0] + 12, 2);
    if (!pri_string)
      return 0;
    sscanf(pri_string, "%d", priority);
    free(pri_string);
  }
  globfree(&globres);
  return 1;
}


x86 assembly (clang, -O0):
<isConfigured>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x38(%rbp),%rdx
call   1050 <findServiceEntries@plt>
cmp    $0x0,%rax
je     119b <isConfigured+0x3b>
mov    $0x1,%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x30(%rbp)
jne    11b1 <isConfigured+0x51>
movl   $0x0,-0x4(%rbp)
jmp    1234 <isConfigured+0xd4>
cmpq   $0x0,-0x28(%rbp)
je     11cc <isConfigured+0x6c>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    0xb(%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     1224 <isConfigured+0xc4>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
add    $0xc,%rdi
mov    $0x2,%esi
call   1060 <strndup@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1207 <isConfigured+0xa7>
movl   $0x0,-0x4(%rbp)
jmp    1234 <isConfigured+0xd4>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xdea(%rip),%rsi
call   1070 <sscanf@plt>
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
lea    -0x38(%rbp),%rdi
call   1030 <globfree@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isConfigured>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsp,%rdx
call   1050 <findServiceEntries@plt>
test   %rax,%rax
jne    11e9 <isConfigured+0x89>
xor    %ebp,%ebp
cmpl   $0x0,0x8(%rsp)
je     11de <isConfigured+0x7e>
test   %rbx,%rbx
je     1195 <isConfigured+0x35>
mov    (%rsp),%rax
mov    (%rax),%rax
mov    0xb(%rax),%al
mov    %al,(%rbx)
test   %r14,%r14
je     11d1 <isConfigured+0x71>
mov    (%rsp),%rax
mov    (%rax),%rdi
add    $0xc,%rdi
mov    $0x2,%esi
call   1060 <strndup@plt>
test   %rax,%rax
je     11de <isConfigured+0x7e>
mov    %rax,%rbx
lea    0xe42(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1070 <sscanf@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %rsp,%rdi
call   1030 <globfree@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_4__ = type { i8**, i32 }
@.str = [3 x i8] c"%d\00"
define i32 @isConfigured(i8* %0, i32 %1, i32* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca %struct.TYPE_4__
%11 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i8* %3, i8** %9
%12 = load i8*, i8** %6
%13 = load i32, i32* %7
%14 = call i64 @findServiceEntries(i8* %12, i32 %13, %struct.TYPE_4__* %10)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %4
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %4
%19 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 1
%20 = load i32, i32* %19
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %18
store i32 0, i32* %5
br label %55
23: ; preds = %18
%24 = load i8*, i8** %9
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %34
26: ; preds = %23
%27 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 0
%28 = load i8**, i8*** %27
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = getelementptr inbounds i8, i8* %30, i64 11
%32 = load i8, i8* %31
%33 = load i8*, i8** %9
store i8 %32, i8* %33
br label %34
34: ; preds = %26, %23
%35 = load i32*, i32** %8
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %53
37: ; preds = %34
%38 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 0
%39 = load i8**, i8*** %38
%40 = getelementptr inbounds i8*, i8** %39, i64 0
%41 = load i8*, i8** %40
%42 = getelementptr inbounds i8, i8* %41, i64 12
%43 = call i8* @strndup(i8* %42, i32 2)
store i8* %43, i8** %11
%44 = load i8*, i8** %11
%45 = icmp ne i8* %44, null
br i1 %45, label %47, label %46
46: ; preds = %37
store i32 0, i32* %5
br label %55
47: ; preds = %37
%48 = load i8*, i8** %11
%49 = load i32*, i32** %8
%50 = call i32 @sscanf(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %49)
%51 = load i8*, i8** %11
%52 = call i32 @free(i8* %51)
br label %53
53: ; preds = %47, %34
%54 = call i32 @globfree(%struct.TYPE_4__* %10)
store i32 1, i32* %5
br label %55
55: ; preds = %53, %46, %22
%56 = load i32, i32* %5
ret i32 %56
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i8**, i32 }
@.str = [3 x i8] c"%d\00"
define i32 @isConfigured(i8* %0, i32 %1, i32* %2, i8* writeonly %3) {
%5 = alloca %struct.TYPE_4__
%6 = bitcast %struct.TYPE_4__* %5 to i8*
%7 = call i64 @findServiceEntries(i8* %0, i32 %1, %struct.TYPE_4__* %5)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %4
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %5, i64 0, i32 1
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, 0
br i1 %14, label %37, label %15
15: ; preds = %11
%16 = icmp eq i8* %3, null
br i1 %16, label %23, label %17
17: ; preds = %15
%18 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %5, i64 0, i32 0
%19 = load i8**, i8*** %18
%20 = load i8*, i8** %19
%21 = getelementptr inbounds i8, i8* %20, i64 11
%22 = load i8, i8* %21
store i8 %22, i8* %3
br label %23
23: ; preds = %17, %15
%24 = icmp eq i32* %2, null
br i1 %24, label %35, label %25
25: ; preds = %23
%26 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %5, i64 0, i32 0
%27 = load i8**, i8*** %26
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8, i8* %28, i64 12
%30 = call i8* @strndup(i8* %29, i32 2)
%31 = icmp eq i8* %30, null
br i1 %31, label %37, label %32
32: ; preds = %25
%33 = call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%34 = call i32 @free(i8* %30)
br label %35
35: ; preds = %32, %23
%36 = call i32 @globfree(%struct.TYPE_4__* %5)
br label %37
37: ; preds = %25, %11, %35
%38 = phi i32 [ 1, %35 ], [ 0, %11 ], [ 0, %25 ]
ret i32 %38
}