#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 {
  scalar_t__ d_type;
  int /*<<< orphan*/ d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ DT_DIR;
scalar_t__ DT_LNK;
int /*<<< orphan*/ close_sysfs_led_dir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *open_sysfs_led_dir();
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, char *);
int opal_indicator_probe_led_class(void) {
  int rc = -1;
  DIR *led_dir;
  struct dirent *dirent;
  led_dir = open_sysfs_led_dir();
  if (!led_dir)
    return rc;
  while ((dirent = readdir(led_dir)) != NULL) {
    if (!strcmp(dirent->d_name, ".") || !strcmp(dirent->d_name, ".."))
      continue;
    if (dirent->d_type != DT_DIR && dirent->d_type != DT_LNK)
      continue;
    close_sysfs_led_dir(led_dir);
    return 0;
  }
  close_sysfs_led_dir(led_dir);
  return rc;
}


x86 assembly (clang, -O0):
<opal_indicator_probe_led_class>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xffffffff,-0x8(%rbp)
mov    $0x0,%al
call   1040 <open_sysfs_led_dir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1170 <opal_indicator_probe_led_class+0x30>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1220 <opal_indicator_probe_led_class+0xe0>
jmp    1175 <opal_indicator_probe_led_class+0x35>
mov    -0x10(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1211 <opal_indicator_probe_led_class+0xd1>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
lea    0xe67(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     11c4 <opal_indicator_probe_led_class+0x84>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
lea    0xe4a(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11c9 <opal_indicator_probe_led_class+0x89>
jmp    1175 <opal_indicator_probe_led_class+0x35>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e09(%rip),%rcx
cmp    (%rcx),%rax
je     11fc <opal_indicator_probe_led_class+0xbc>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2dea(%rip),%rcx
cmp    (%rcx),%rax
je     11fc <opal_indicator_probe_led_class+0xbc>
jmp    1175 <opal_indicator_probe_led_class+0x35>
mov    -0x10(%rbp),%rdi
call   1030 <close_sysfs_led_dir@plt>
movl   $0x0,-0x4(%rbp)
jmp    1220 <opal_indicator_probe_led_class+0xe0>
mov    -0x10(%rbp),%rdi
call   1030 <close_sysfs_led_dir@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opal_indicator_probe_led_class>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <open_sysfs_led_dir@plt>
test   %rax,%rax
je     11e0 <opal_indicator_probe_led_class+0xa0>
mov    %rax,%r12
mov    %rax,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11d1 <opal_indicator_probe_led_class+0x91>
mov    %rax,%rbx
lea    0xe8c(%rip),%r14
lea    0xe84(%rip),%r15
mov    0x2e5d(%rip),%r13
mov    0x2e4e(%rip),%rbp
jmp    11a0 <opal_indicator_probe_led_class+0x60>
nopl   0x0(%rax)
mov    %r12,%rdi
call   1060 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11d1 <opal_indicator_probe_led_class+0x91>
mov    0x8(%rbx),%edi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1190 <opal_indicator_probe_led_class+0x50>
mov    0x8(%rbx),%edi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1190 <opal_indicator_probe_led_class+0x50>
mov    (%rbx),%rax
xor    %ebx,%ebx
cmp    0x0(%r13),%rax
je     11d6 <opal_indicator_probe_led_class+0x96>
cmp    0x0(%rbp),%rax
jne    1190 <opal_indicator_probe_led_class+0x50>
jmp    11d6 <opal_indicator_probe_led_class+0x96>
mov    $0xffffffff,%ebx
mov    %r12,%rdi
call   1030 <close_sysfs_led_dir@plt>
jmp    11e5 <opal_indicator_probe_led_class+0xa5>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i64, i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@DT_DIR = global i64 0
@DT_LNK = global i64 0
define i32 @opal_indicator_probe_led_class() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca %struct.dirent*
store i32 -1, i32* %2
%5 = call i32* (...) @open_sysfs_led_dir()
store i32* %5, i32** %3
%6 = load i32*, i32** %3
%7 = icmp ne i32* %6, null
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = load i32, i32* %2
store i32 %9, i32* %1
br label %48
10: ; preds = %0
br label %11
11: ; preds = %40, %27, %10
%12 = load i32*, i32** %3
%13 = call %struct.dirent* @readdir(i32* %12)
store %struct.dirent* %13, %struct.dirent** %4
%14 = icmp ne %struct.dirent* %13, null
br i1 %14, label %15, label %44
15: ; preds = %11
%16 = load %struct.dirent*, %struct.dirent** %4
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = call i32 @strcmp(i32 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %15
%22 = load %struct.dirent*, %struct.dirent** %4
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i32 0, i32 1
%24 = load i32, i32* %23
%25 = call i32 @strcmp(i32 %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %21, %15
br label %11
28: ; preds = %21
%29 = load %struct.dirent*, %struct.dirent** %4
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i32 0, i32 0
%31 = load i64, i64* %30
%32 = load i64, i64* @DT_DIR
%33 = icmp ne i64 %31, %32
br i1 %33, label %34, label %41
34: ; preds = %28
%35 = load %struct.dirent*, %struct.dirent** %4
%36 = getelementptr inbounds %struct.dirent, %struct.dirent* %35, i32 0, i32 0
%37 = load i64, i64* %36
%38 = load i64, i64* @DT_LNK
%39 = icmp ne i64 %37, %38
br i1 %39, label %40, label %41
40: ; preds = %34
br label %11
41: ; preds = %34, %28
%42 = load i32*, i32** %3
%43 = call i32 @close_sysfs_led_dir(i32* %42)
store i32 0, i32* %1
br label %48
44: ; preds = %11
%45 = load i32*, i32** %3
%46 = call i32 @close_sysfs_led_dir(i32* %45)
%47 = load i32, i32* %2
store i32 %47, i32* %1
br label %48
48: ; preds = %44, %41, %8
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
%struct.dirent = type { i64, i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@DT_DIR = global i64 0
@DT_LNK = global i64 0
define i32 @opal_indicator_probe_led_class() {
%1 = tail call i32* (...) @open_sysfs_led_dir()
%2 = icmp eq i32* %1, null
br i1 %2, label %30, label %3
3: ; preds = %0
%4 = tail call %struct.dirent* @readdir(i32* %1)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %27, label %6
6: ; preds = %3, %16
%7 = phi %struct.dirent* [ %17, %16 ], [ %4, %3 ]
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 1
%9 = load i32, i32* %8
%10 = tail call i32 @strcmp(i32 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %6
%13 = load i32, i32* %8
%14 = tail call i32 @strcmp(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %6, %12, %19
%17 = tail call %struct.dirent* @readdir(i32* %1)
%18 = icmp eq %struct.dirent* %17, null
br i1 %18, label %27, label %6
19: ; preds = %12
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 0
%21 = load i64, i64* %20
%22 = load i64, i64* @DT_DIR
%23 = icmp eq i64 %21, %22
%24 = load i64, i64* @DT_LNK
%25 = icmp eq i64 %21, %24
%26 = select i1 %23, i1 true, i1 %25
br i1 %26, label %27, label %16
27: ; preds = %16, %19, %3
%28 = phi i32 [ -1, %3 ], [ 0, %19 ], [ -1, %16 ]
%29 = tail call i32 @close_sysfs_led_dir(i32* %1)
br label %30
30: ; preds = %27, %0
%31 = phi i32 [ -1, %0 ], [ %28, %27 ]
ret i32 %31
}