#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 */

/* Type definitions */
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fatal(char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcpy(char *, char *);
char *bldev_scan() {
  static char name[256];
  DIR *dir;
  struct dirent *de;
  int more_than_one = 0;
  dir = opendir("/sys/class/backlight/");
  if (!dir)
    fatal("Backlight device class does not seem to be support by kernel ("
          "/sys/class/backlight/"
          " is absent)");
  *name = 0;
  while (de = readdir(dir)) {
    if (de->d_name[0] == '.')
      continue;
    if (*name == 0) {
      strcpy(name, de->d_name);
    } else {
      more_than_one = 1;
      break;
    }
  }
  closedir(dir);
  if (*name == 0)
    fatal("There does not seem to be any backlight device available ("
          "/sys/class/backlight/"
          " is empty)");
  if (more_than_one)
    fatal("There seems to be several backlight devices available, use "
          "--device= option");
  return name;
}


x86 assembly (clang, -O0):
<bldev_scan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x14(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1186 <bldev_scan+0x36>
lea    0xe95(%rip),%rdi
call   1070 <fatal@plt>
movb   $0x0,0x2ed3(%rip)
mov    -0x8(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11f5 <bldev_scan+0xa5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11bc <bldev_scan+0x6c>
jmp    118d <bldev_scan+0x3d>
movsbl 0x2e9d(%rip),%eax
cmp    $0x0,%eax
jne    11e4 <bldev_scan+0x94>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0x2e86(%rip),%rdi
call   1030 <strcpy@plt>
jmp    11f0 <bldev_scan+0xa0>
movl   $0x1,-0x14(%rbp)
jmp    11f5 <bldev_scan+0xa5>
jmp    118d <bldev_scan+0x3d>
mov    -0x8(%rbp),%rdi
call   1050 <closedir@plt>
movsbl 0x2e5b(%rip),%eax
cmp    $0x0,%eax
jne    121a <bldev_scan+0xca>
lea    0xe60(%rip),%rdi
call   1070 <fatal@plt>
cmpl   $0x0,-0x14(%rbp)
je     1230 <bldev_scan+0xe0>
lea    0xea4(%rip),%rdi
call   1070 <fatal@plt>
lea    0x2e29(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bldev_scan>:
push   %rbp
push   %r14
push   %rbx
lea    0xea5(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1174 <bldev_scan+0x24>
lea    0xea7(%rip),%rdi
call   1070 <fatal@plt>
movb   $0x0,0x2ee5(%rip)
mov    %rbx,%rdi
call   1060 <readdir@plt>
mov    $0x1,%bpl
test   %rax,%rax
je     11ca <bldev_scan+0x7a>
lea    0x2ece(%rip),%r14
jmp    11ad <bldev_scan+0x5d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11ca <bldev_scan+0x7a>
mov    (%rax),%rsi
cmpb   $0x2e,(%rsi)
je     11a0 <bldev_scan+0x50>
cmpb   $0x0,0x2ea4(%rip)
jne    11c8 <bldev_scan+0x78>
mov    %r14,%rdi
call   1030 <strcpy@plt>
jmp    11a0 <bldev_scan+0x50>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1050 <closedir@plt>
cmpb   $0x0,0x2e87(%rip)
je     11f8 <bldev_scan+0xa8>
test   %bpl,%bpl
jne    11ec <bldev_scan+0x9c>
lea    0xee8(%rip),%rdi
call   1070 <fatal@plt>
lea    0x2e6d(%rip),%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe76(%rip),%rdi
call   1070 <fatal@plt>
test   %bpl,%bpl
je     11e0 <bldev_scan+0x90>
jmp    11ec <bldev_scan+0x9c>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@bldev_scan.name = internal global [256 x i8] zeroinitializer
@.str = [22 x i8] c"/sys/class/backlight/\00"
@.str.1 = [95 x i8] c"Backlight device class does not seem to be support by kernel (/sys/class/backlight/ is absent)\00"
@.str.2 = [90 x i8] c"There does not seem to be any backlight device available (/sys/class/backlight/ is empty)\00"
@.str.3 = [76 x i8] c"There seems to be several backlight devices available, use --device= option\00"
define i8* @bldev_scan() {
%1 = alloca i32*
%2 = alloca %struct.dirent*
%3 = alloca i32
store i32 0, i32* %3
%4 = call i32* @opendir(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32* %4, i32** %1
%5 = load i32*, i32** %1
%6 = icmp ne i32* %5, null
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = call i32 @fatal(i8* getelementptr inbounds ([95 x i8], [95 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
store i8 0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @bldev_scan.name, i64 0, i64 0)
br label %10
10: ; preds = %33, %22, %9
%11 = load i32*, i32** %1
%12 = call %struct.dirent* @readdir(i32* %11)
store %struct.dirent* %12, %struct.dirent** %2
%13 = icmp ne %struct.dirent* %12, null
br i1 %13, label %14, label %34
14: ; preds = %10
%15 = load %struct.dirent*, %struct.dirent** %2
%16 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i32 0, i32 0
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 46
br i1 %21, label %22, label %23
22: ; preds = %14
br label %10
23: ; preds = %14
%24 = load i8, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @bldev_scan.name, i64 0, i64 0)
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load %struct.dirent*, %struct.dirent** %2
%29 = getelementptr inbounds %struct.dirent, %struct.dirent* %28, i32 0, i32 0
%30 = load i8*, i8** %29
%31 = call i32 @strcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @bldev_scan.name, i64 0, i64 0), i8* %30)
br label %33
32: ; preds = %23
store i32 1, i32* %3
br label %34
33: ; preds = %27
br label %10
34: ; preds = %32, %10
%35 = load i32*, i32** %1
%36 = call i32 @closedir(i32* %35)
%37 = load i8, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @bldev_scan.name, i64 0, i64 0)
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = call i32 @fatal(i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %40, %34
%43 = load i32, i32* %3
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 @fatal(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %45, %42
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @bldev_scan.name, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@bldev_scan.name = internal global [256 x i8] zeroinitializer
@.str = [22 x i8] c"/sys/class/backlight/\00"
@.str.1 = [95 x i8] c"Backlight device class does not seem to be support by kernel (/sys/class/backlight/ is absent)\00"
@.str.2 = [90 x i8] c"There does not seem to be any backlight device available (/sys/class/backlight/ is empty)\00"
@.str.3 = [76 x i8] c"There seems to be several backlight devices available, use --device= option\00"
define i8* @bldev_scan() {
%1 = tail call i32* @opendir(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @fatal(i8* getelementptr inbounds ([95 x i8], [95 x i8]* @.str.1, i64 0, i64 0))
br label %5
5: ; preds = %3, %0
store i8 0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @bldev_scan.name, i64 0, i64 0)
%6 = tail call %struct.dirent* @readdir(i32* %1)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %22, label %8
8: ; preds = %5, %19
%9 = phi %struct.dirent* [ %20, %19 ], [ %6, %5 ]
%10 = getelementptr inbounds %struct.dirent, %struct.dirent* %9, i64 0, i32 0
%11 = load i8*, i8** %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 46
br i1 %13, label %19, label %14
14: ; preds = %8
%15 = load i8, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @bldev_scan.name, i64 0, i64 0)
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = tail call i32 @strcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @bldev_scan.name, i64 0, i64 0), i8* %11)
br label %19
19: ; preds = %17, %8
%20 = tail call %struct.dirent* @readdir(i32* %1)
%21 = icmp eq %struct.dirent* %20, null
br i1 %21, label %22, label %8
22: ; preds = %19, %14, %5
%23 = phi i1 [ true, %5 ], [ false, %14 ], [ true, %19 ]
%24 = tail call i32 @closedir(i32* %1)
%25 = load i8, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @bldev_scan.name, i64 0, i64 0)
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = tail call i32 @fatal(i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %22
br i1 %23, label %32, label %30
30: ; preds = %29
%31 = tail call i32 @fatal(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %29
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @bldev_scan.name, i64 0, i64 0)
}