#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;
  dir = opendir("/sys/class/power_supply");
  if (!dir)
    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 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)
cmpq   $0x0,-0x18(%rbp)
jne    119f <acpi_supported+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    1227 <acpi_supported+0xb7>
mov    -0x18(%rbp),%rdi
call   1060 <closedir@plt>
lea    0xe69(%rip),%rdi
call   1050 <get_acpi_file@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cf <acpi_supported+0x5f>
movl   $0x0,-0x4(%rbp)
jmp    1227 <acpi_supported+0xb7>
mov    -0x10(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x131580a,-0x1c(%rbp)
jge    1212 <acpi_supported+0xa2>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe47(%rip),%rsi
mov    $0x131580a,%ecx
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1227 <acpi_supported+0xb7>
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 = [57 x i8] c"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 = load i32*, i32** %3
%7 = icmp ne i32* %6, null
br i1 %7, label %9, label %8
8: ; preds = %0
store i32 0, i32* %1
br label %28
9: ; preds = %0
%10 = load i32*, i32** %3
%11 = call i32 @closedir(i32* %10)
%12 = call i8* @get_acpi_file(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
store i8* %12, i8** %2
%13 = load i8*, i8** %2
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %9
store i32 0, i32* %1
br label %28
16: ; preds = %9
%17 = load i8*, i8** %2
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 20011018
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %2
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0), i8* %23, i32 20011018)
store i32 0, i32* %1
br label %28
25: ; preds = %16
%26 = call i32 (...) @find_batteries()
%27 = call i32 (...) @find_ac_adapters()
store i32 1, i32* %1
br label %28
28: ; preds = %25, %21, %15, %8
%29 = load i32, i32* %1
ret i32 %29
}

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 = [57 x i8] c"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 ([57 x i8], [57 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
}