#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;
};
typedef TYPE_1__ glob_t;

/* Variables and functions */
int GLOB_ERR;
int GLOB_NOMATCH;
int GLOB_NOSORT;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *,
                           int /*<<< orphan*/);
char *gettext(char *);
int glob(char *, int, int /*<<< orphan*/ *, TYPE_1__ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int findServiceEntries(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", "/etc/rc.d", level, name);
  rc = glob(match, GLOB_ERR | GLOB_NOSORT, NULL, &globres);
  if (rc && rc != GLOB_NOMATCH) {
    fprintf(stderr, gettext(("failed to glob pattern %s: %s\n")), match,
            strerror(errno));
    return 1;
  } else if (rc == GLOB_NOMATCH) {
    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    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0xf0(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%r8
lea    0xe85(%rip),%rsi
lea    0xe99(%rip),%rdx
call   1060 <sprintf@plt>
lea    -0xf0(%rbp),%rdi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
mov    0x2e22(%rip),%rax
or     (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0xf8(%rbp),%rcx
call   1050 <glob@plt>
mov    %eax,-0xfc(%rbp)
cmpl   $0x0,-0xfc(%rbp)
je     123d <findServiceEntries+0xed>
mov    -0xfc(%rbp),%eax
mov    0x2e20(%rip),%rcx
cmp    (%rcx),%eax
je     123d <findServiceEntries+0xed>
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x114(%rbp)
lea    0xe37(%rip),%rdi
call   1030 <gettext@plt>
mov    %rax,-0x110(%rbp)
lea    -0xf0(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x114(%rbp),%edi
mov    -0x110(%rbp),%rsi
mov    -0x108(%rbp),%rdx
mov    %eax,%ecx
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1283 <findServiceEntries+0x133>
mov    -0xfc(%rbp),%eax
mov    0x2da6(%rip),%rcx
cmp    (%rcx),%eax
jne    1269 <findServiceEntries+0x119>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1283 <findServiceEntries+0x133>
jmp    126e <findServiceEntries+0x11e>
mov    -0x20(%rbp),%rax
mov    -0xf8(%rbp),%rcx
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findServiceEntries>:
push   %rbp
push   %r14
push   %rbx
sub    $0xe0,%rsp
mov    %rdx,%r14
mov    %esi,%ecx
mov    %rdi,%r8
lea    0xe96(%rip),%rsi
lea    0xeaa(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    0x2e63(%rip),%rax
mov    0x2e34(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <glob@plt>
mov    0x2e4a(%rip),%rcx
mov    (%rcx),%ecx
test   %eax,%eax
je     11ee <findServiceEntries+0x9e>
cmp    %ecx,%eax
je     11ee <findServiceEntries+0x9e>
mov    0x2e19(%rip),%rax
mov    (%rax),%ebp
lea    0xe65(%rip),%rdi
call   1030 <gettext@plt>
mov    %rax,%rbx
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0x10(%rsp),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%ecx
call   1040 <fprintf@plt>
mov    $0x1,%eax
jmp    1205 <findServiceEntries+0xb5>
cmp    %ecx,%eax
jne    11fb <findServiceEntries+0xab>
movq   $0x0,(%r14)
jmp    1203 <findServiceEntries+0xb3>
mov    0x8(%rsp),%rax
mov    %rax,(%r14)
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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