#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 */
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ find_ac_adapters();
int /*<<< orphan*/ find_batteries();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
char *get_acpi_file(char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ stderr;
int acpi_supported(void) {
  char *version;
  DIR *dir;
  int num;
  if (!(dir = opendir("/sys/class/power_supply"))) {
    return 0;
  }
  closedir(dir);
  version = get_acpi_file("/sys/module/acpi/parameters/acpica_version");
  if (version == NULL) {
    return 0;
  }
  num = atoi(version);
  if (num < 20011018) {
    fprintf(stderr,
            "acpi: ACPI subsystem %s too is old, consider upgrading to %i.\n",
            version, 20011018);
    return 0;
  }
  find_batteries();
  find_ac_adapters();
  return 1;
}


x86 assembly (clang, -O0):
<acpi_supported>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe81(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    119e <acpi_supported+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    1226 <acpi_supported+0xb6>
mov    -0x18(%rbp),%rdi
call   1060 <closedir@plt>
lea    0xe6a(%rip),%rdi
call   1050 <get_acpi_file@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ce <acpi_supported+0x5e>
movl   $0x0,-0x4(%rbp)
jmp    1226 <acpi_supported+0xb6>
mov    -0x10(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x131580a,-0x1c(%rbp)
jge    1211 <acpi_supported+0xa1>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe48(%rip),%rsi
mov    $0x131580a,%ecx
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1226 <acpi_supported+0xb6>
mov    $0x0,%al
call   1030 <find_batteries@plt>
mov    $0x0,%al
call   1080 <find_ac_adapters@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<acpi_supported>:
push   %rbp
push   %rbx
push   %rax
lea    0xe86(%rip),%rdi
call   1040 <opendir@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11e3 <acpi_supported+0x73>
mov    %rax,%rdi
call   1060 <closedir@plt>
lea    0xe83(%rip),%rdi
call   1050 <get_acpi_file@plt>
test   %rax,%rax
je     11e3 <acpi_supported+0x73>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <atoi@plt>
cmp    $0x1315809,%eax
jg     11d0 <acpi_supported+0x60>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    %rbx,%rdx
mov    $0x131580a,%ecx
call   1070 <fprintf@plt>
jmp    11e3 <acpi_supported+0x73>
xor    %eax,%eax
call   1030 <find_batteries@plt>
xor    %eax,%eax
call   1080 <find_ac_adapters@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"/sys/class/power_supply\00"
@.str.1 = [43 x i8] c"/sys/module/acpi/parameters/acpica_version\00"
@stderr = global i32 0
@.str.2 = [63 x i8] c"acpi: ACPI subsystem %s too is old, consider upgrading to %i.\0A\00"
define i32 @acpi_supported() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = call i32* @opendir(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32* %5, i32** %3
%6 = icmp ne i32* %5, null
br i1 %6, label %8, label %7
7: ; preds = %0
store i32 0, i32* %1
br label %27
8: ; preds = %0
%9 = load i32*, i32** %3
%10 = call i32 @closedir(i32* %9)
%11 = call i8* @get_acpi_file(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
store i8* %11, i8** %2
%12 = load i8*, i8** %2
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %8
store i32 0, i32* %1
br label %27
15: ; preds = %8
%16 = load i8*, i8** %2
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 20011018
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %2
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0), i8* %22, i32 20011018)
store i32 0, i32* %1
br label %27
24: ; preds = %15
%25 = call i32 (...) @find_batteries()
%26 = call i32 (...) @find_ac_adapters()
store i32 1, i32* %1
br label %27
27: ; preds = %24, %20, %14, %7
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [24 x i8] c"/sys/class/power_supply\00"
@.str.1 = [43 x i8] c"/sys/module/acpi/parameters/acpica_version\00"
@stderr = global i32 0
@.str.2 = [63 x i8] c"acpi: ACPI subsystem %s too is old, consider upgrading to %i.\0A\00"
define i32 @acpi_supported() {
%1 = tail call i32* @opendir(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %16, label %3
3: ; preds = %0
%4 = tail call i32 @closedir(i32* %1)
%5 = tail call i8* @get_acpi_file(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %16, label %7
7: ; preds = %3
%8 = tail call i32 @atoi(i8* %5)
%9 = icmp slt i32 %8, 20011018
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0), i8* %5, i32 20011018)
br label %16
13: ; preds = %7
%14 = tail call i32 (...) @find_batteries()
%15 = tail call i32 (...) @find_ac_adapters()
br label %16
16: ; preds = %3, %0, %13, %10
%17 = phi i32 [ 0, %10 ], [ 1, %13 ], [ 0, %0 ], [ 0, %3 ]
ret i32 %17
}