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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ GLOB_BRACE;
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ glob(char *, int /*<<< orphan*/, int /*<<< orphan*/ *,
                        TYPE_1__ *);
int /*<<< orphan*/ globfree(TYPE_1__ *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char const *, char *);
void validate_device(const char *dev) {
  glob_t globres;
  size_t i;
  glob("{backlight,leds}/*", GLOB_BRACE, NULL, &globres);
  if (strcmp(dev, "list") == 0) {
    if (globres.gl_pathc == 0) {
      printf("No compatible device found.\n");
    } else {
      printf("List of compatible devices:\n");
      for (i = 0; i < globres.gl_pathc; ++i)
        printf("%s\n", globres.gl_pathv[i]);
    }
    exit(EXIT_SUCCESS);
  }
  for (i = 0; i < globres.gl_pathc; ++i)
    if (strcmp(dev, globres.gl_pathv[i]) == 0)
      break;
  if (i == globres.gl_pathc)
    errx(EXIT_FAILURE, "%s is not a valid device.", dev);
  globfree(&globres);
}


x86 assembly (clang, -O0):
<validate_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
lea    0xe84(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x18(%rbp),%rcx
call   1070 <glob@plt>
mov    -0x8(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1223 <validate_device+0xc3>
cmpq   $0x0,-0x18(%rbp)
jne    11c1 <validate_device+0x61>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1215 <validate_device+0xb5>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1210 <validate_device+0xb0>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11d7 <validate_device+0x77>
jmp    1215 <validate_device+0xb5>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1273 <validate_device+0x113>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    125d <validate_device+0xfd>
jmp    1273 <validate_device+0x113>
jmp    1262 <validate_device+0x102>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    122b <validate_device+0xcb>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    129a <validate_device+0x13a>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdc1(%rip),%rsi
call   1040 <errx@plt>
lea    -0x18(%rbp),%rdi
call   1030 <globfree@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_device>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
lea    0xe86(%rip),%rdi
lea    0x8(%rsp),%rcx
xor    %edx,%edx
call   1070 <glob@plt>
lea    0xe86(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     120f <validate_device+0xaf>
cmpq   $0x0,0x8(%rsp)
je     11d9 <validate_device+0x79>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x10(%rsp),%rax
mov    (%rax,%rbx,8),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1203 <validate_device+0xa3>
add    $0x1,%rbx
mov    0x8(%rsp),%rax
cmp    %rax,%rbx
jb     11b0 <validate_device+0x50>
cmp    %rax,%rbx
jne    11f1 <validate_device+0x91>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
mov    %r14,%rdx
call   1050 <errx@plt>
lea    0x8(%rsp),%rdi
call   1030 <globfree@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x8(%rsp),%rax
cmp    %rax,%rbx
je     11d9 <validate_device+0x79>
jmp    11f1 <validate_device+0x91>
cmpq   $0x0,0x8(%rsp)
jne    1225 <validate_device+0xc5>
lea    0xe30(%rip),%rdi
call   1040 <puts@plt>
jmp    1259 <validate_device+0xf9>
lea    0xe06(%rip),%rdi
call   1040 <puts@plt>
cmpq   $0x0,0x8(%rsp)
je     1259 <validate_device+0xf9>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
mov    (%rax,%rbx,8),%rdi
call   1040 <puts@plt>
add    $0x1,%rbx
cmp    0x8(%rsp),%rbx
jb     1240 <validate_device+0xe0>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_4__ = type { i64, i8** }
@.str = [19 x i8] c"{backlight,leds}/*\00"
@GLOB_BRACE = global i32 0
@.str.1 = [5 x i8] c"list\00"
@.str.2 = [29 x i8] c"No compatible device found.\0A\00"
@.str.3 = [29 x i8] c"List of compatible devices:\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@.str.5 = [26 x i8] c"%s is not a valid device.\00"
define void @validate_device(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.TYPE_4__
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i32, i32* @GLOB_BRACE
%6 = call i32 @glob(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %5, i32* null, %struct.TYPE_4__* %3)
%7 = load i8*, i8** %2
%8 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %37
10: ; preds = %1
%11 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i32 0, i32 0
%12 = load i64, i64* %11
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %34
16: ; preds = %10
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
store i64 0, i64* %4
br label %18
18: ; preds = %30, %16
%19 = load i64, i64* %4
%20 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i32 0, i32 0
%21 = load i64, i64* %20
%22 = icmp ult i64 %19, %21
br i1 %22, label %23, label %33
23: ; preds = %18
%24 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i32 0, i32 1
%25 = load i8**, i8*** %24
%26 = load i64, i64* %4
%27 = getelementptr inbounds i8*, i8** %25, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %23
%31 = load i64, i64* %4
%32 = add i64 %31, 1
store i64 %32, i64* %4
br label %18
33: ; preds = %18
br label %34
34: ; preds = %33, %14
%35 = load i32, i32* @EXIT_SUCCESS
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %1
store i64 0, i64* %4
br label %38
38: ; preds = %54, %37
%39 = load i64, i64* %4
%40 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i32 0, i32 0
%41 = load i64, i64* %40
%42 = icmp ult i64 %39, %41
br i1 %42, label %43, label %57
43: ; preds = %38
%44 = load i8*, i8** %2
%45 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i32 0, i32 1
%46 = load i8**, i8*** %45
%47 = load i64, i64* %4
%48 = getelementptr inbounds i8*, i8** %46, i64 %47
%49 = load i8*, i8** %48
%50 = call i64 @strcmp(i8* %44, i8* %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %43
br label %57
53: ; preds = %43
br label %54
54: ; preds = %53
%55 = load i64, i64* %4
%56 = add i64 %55, 1
store i64 %56, i64* %4
br label %38
57: ; preds = %52, %38
%58 = load i64, i64* %4
%59 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i32 0, i32 0
%60 = load i64, i64* %59
%61 = icmp eq i64 %58, %60
br i1 %61, label %62, label %66
62: ; preds = %57
%63 = load i32, i32* @EXIT_FAILURE
%64 = load i8*, i8** %2
%65 = call i32 @errx(i32 %63, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %64)
br label %66
66: ; preds = %62, %57
%67 = call i32 @globfree(%struct.TYPE_4__* %3)
ret void
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i64, i8** }
@.str = [19 x i8] c"{backlight,leds}/*\00"
@GLOB_BRACE = global i32 0
@.str.1 = [5 x i8] c"list\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@.str.5 = [26 x i8] c"%s is not a valid device.\00"
@str = [28 x i8] c"List of compatible devices:\00"
@str.6 = [28 x i8] c"No compatible device found.\00"
define void @validate_device(i8* %0) {
%2 = alloca %struct.TYPE_4__
%3 = bitcast %struct.TYPE_4__* %2 to i8*
%4 = load i32, i32* @GLOB_BRACE
%5 = call i32 @glob(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %4, i32* null, %struct.TYPE_4__* %2)
%6 = call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 1
%10 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 0
%11 = load i64, i64* %10
%12 = icmp eq i64 %11, 0
br i1 %12, label %54, label %37
13: ; preds = %1
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 0
%15 = load i64, i64* %14
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.6, i64 0, i64 0))
br label %34
19: ; preds = %13
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%21 = load i64, i64* %14
%22 = icmp eq i64 %21, 0
br i1 %22, label %34, label %23
23: ; preds = %19
%24 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 1
br label %25
25: ; preds = %23, %25
%26 = phi i64 [ 0, %23 ], [ %31, %25 ]
%27 = load i8**, i8*** %24
%28 = getelementptr inbounds i8*, i8** %27, i64 %26
%29 = load i8*, i8** %28
%30 = call i32 @puts(i8* dereferenceable(1) %29)
%31 = add nuw i64 %26, 1
%32 = load i64, i64* %14
%33 = icmp ult i64 %31, %32
br i1 %33, label %25, label %34
34: ; preds = %25, %19, %17
%35 = load i32, i32* @EXIT_SUCCESS
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %8, %46
%38 = phi i64 [ %47, %46 ], [ 0, %8 ]
%39 = load i8**, i8*** %9
%40 = getelementptr inbounds i8*, i8** %39, i64 %38
%41 = load i8*, i8** %40
%42 = call i64 @strcmp(i8* %0, i8* %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %37
%45 = load i64, i64* %10
br label %50
46: ; preds = %37
%47 = add nuw i64 %38, 1
%48 = load i64, i64* %10
%49 = icmp ult i64 %47, %48
br i1 %49, label %37, label %50
50: ; preds = %46, %44
%51 = phi i64 [ %45, %44 ], [ %48, %46 ]
%52 = phi i64 [ %38, %44 ], [ %47, %46 ]
%53 = icmp eq i64 %52, %51
br i1 %53, label %54, label %57
54: ; preds = %8, %50
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @errx(i32 %55, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %0)
br label %57
57: ; preds = %54, %50
%58 = call i32 @globfree(%struct.TYPE_4__* %2)
ret void
}