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

/* Variables and functions */
int GLOB_ERR;
int GLOB_NOCHECK;
int GLOB_NOSORT;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int glob(char *, int, int /*<<< orphan*/ *, TYPE_1__ *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, int, char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, int /*<<< orphan*/);
char *strerror(int /*<<< orphan*/);
int findServiceEntries(const char *RUNLEVELS, const char *name, int level,
                       glob_t *globresptr) {
  char match[200];
  glob_t globres;
  int rc;
  sprintf(match, "%s/rc%d.d/[SK][0-9][0-9]%s", RUNLEVELS, level, name);
  rc = glob(match, GLOB_ERR | GLOB_NOSORT | GLOB_NOCHECK, NULL, &globres);
  if (rc) {
    fprintf(stderr, "failed to glob pattern %s: %s\n", match, strerror(errno));
    return 1;
  } else if (!strcmp(match, globres.gl_pathv[0])) {
    globresptr->gl_pathc = 0;
    return 0;
  }
  *globresptr = globres;
  return 0;
}


x86 assembly (clang, -O0):
<findServiceEntries>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0xf0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%r8
lea    0xe7d(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0xf0(%rbp),%rdi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    0x2e21(%rip),%rax
or     (%rax),%esi
mov    0x2e20(%rip),%rax
or     (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x100(%rbp),%rcx
call   1050 <glob@plt>
mov    %eax,-0x104(%rbp)
cmpl   $0x0,-0x104(%rbp)
je     1220 <findServiceEntries+0xd0>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x114(%rbp)
lea    -0xf0(%rbp),%rax
mov    %rax,-0x110(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x114(%rbp),%edi
mov    -0x110(%rbp),%rdx
mov    %rax,%rcx
lea    0xe0c(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    127a <findServiceEntries+0x12a>
lea    -0xf0(%rbp),%rdi
mov    -0xf8(%rbp),%rax
mov    (%rax),%esi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1255 <findServiceEntries+0x105>
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    127a <findServiceEntries+0x12a>
jmp    125a <findServiceEntries+0x10a>
mov    -0x28(%rbp),%rax
mov    -0x100(%rbp),%rcx
mov    %rcx,(%rax)
mov    -0xf8(%rbp),%rcx
mov    %rcx,0x8(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findServiceEntries>:
push   %r14
push   %rbx
sub    $0xd8,%rsp
mov    %rcx,%r14
mov    %edx,%ecx
mov    %rsi,%r8
mov    %rdi,%rdx
lea    0xe94(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    0x2e70(%rip),%rax
mov    0x2e39(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e36(%rip),%rax
or     (%rax),%esi
mov    %rsp,%rcx
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <glob@plt>
test   %eax,%eax
je     11d9 <findServiceEntries+0x89>
mov    0x2e2c(%rip),%rax
mov    (%rax),%ebx
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe58(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    $0x1,%eax
jmp    1201 <findServiceEntries+0xb1>
mov    0x8(%rsp),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11f8 <findServiceEntries+0xa8>
movups (%rsp),%xmm0
movups %xmm0,(%r14)
jmp    11ff <findServiceEntries+0xaf>
movq   $0x0,(%r14)
xor    %eax,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i64, i32* }
@.str = [27 x i8] c"%s/rc%d.d/[SK][0-9][0-9]%s\00"
@GLOB_ERR = global i32 0
@GLOB_NOSORT = global i32 0
@GLOB_NOCHECK = global i32 0
@stderr = global i32 0
@.str.1 = [31 x i8] c"failed to glob pattern %s: %s\0A\00"
@errno = global i32 0
define i32 @findServiceEntries(i8* %0, i8* %1, i32 %2, %struct.TYPE_4__* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.TYPE_4__*
%10 = alloca [200 x i8]
%11 = alloca %struct.TYPE_4__
%12 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store %struct.TYPE_4__* %3, %struct.TYPE_4__** %9
%13 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%14 = load i8*, i8** %6
%15 = load i32, i32* %8
%16 = load i8*, i8** %7
%17 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %14, i32 %15, i8* %16)
%18 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%19 = load i32, i32* @GLOB_ERR
%20 = load i32, i32* @GLOB_NOSORT
%21 = or i32 %19, %20
%22 = load i32, i32* @GLOB_NOCHECK
%23 = or i32 %21, %22
%24 = call i32 @glob(i8* %18, i32 %23, i32* null, %struct.TYPE_4__* %11)
store i32 %24, i32* %12
%25 = load i32, i32* %12
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %4
%28 = load i32, i32* @stderr
%29 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %29, i8* %31)
store i32 1, i32* %5
br label %49
33: ; preds = %4
%34 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%35 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %11, i32 0, i32 1
%36 = load i32*, i32** %35
%37 = getelementptr inbounds i32, i32* %36, i64 0
%38 = load i32, i32* %37
%39 = call i32 @strcmp(i8* %34, i32 %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %33
%42 = load %struct.TYPE_4__*, %struct.TYPE_4__** %9
%43 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %42, i32 0, i32 0
store i64 0, i64* %43
store i32 0, i32* %5
br label %49
44: ; preds = %33
br label %45
45: ; preds = %44
%46 = load %struct.TYPE_4__*, %struct.TYPE_4__** %9
%47 = bitcast %struct.TYPE_4__* %46 to i8*
%48 = bitcast %struct.TYPE_4__* %11 to i8*
store i32 0, i32* %5
br label %49
49: ; preds = %45, %41, %27
%50 = load i32, i32* %5
ret i32 %50
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i64, i32* }
@.str = [27 x i8] c"%s/rc%d.d/[SK][0-9][0-9]%s\00"
@GLOB_ERR = global i32 0
@GLOB_NOSORT = global i32 0
@GLOB_NOCHECK = global i32 0
@stderr = global i32 0
@.str.1 = [31 x i8] c"failed to glob pattern %s: %s\0A\00"
@errno = global i32 0
define i32 @findServiceEntries(i8* %0, i8* %1, i32 %2, %struct.TYPE_4__* nocapture writeonly %3) {
%5 = alloca [200 x i8]
%6 = alloca %struct.TYPE_4__
%7 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%8 = bitcast %struct.TYPE_4__* %6 to i8*
%9 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %2, i8* %1)
%10 = load i32, i32* @GLOB_ERR
%11 = load i32, i32* @GLOB_NOSORT
%12 = or i32 %11, %10
%13 = load i32, i32* @GLOB_NOCHECK
%14 = or i32 %12, %13
%15 = call i32 @glob(i8* %7, i32 %14, i32* null, %struct.TYPE_4__* %6)
%16 = icmp eq i32 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %4
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %20)
br label %32
22: ; preds = %4
%23 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i64 0, i32 1
%24 = load i32*, i32** %23
%25 = load i32, i32* %24
%26 = call i32 @strcmp(i8* %7, i32 %25)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0
store i64 0, i64* %29
br label %32
30: ; preds = %22
%31 = bitcast %struct.TYPE_4__* %3 to i8*
br label %32
32: ; preds = %30, %28, %17
%33 = phi i32 [ 1, %17 ], [ 0, %30 ], [ 0, %28 ]
ret i32 %33
}