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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *isIt(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
scalar_t__ strncmp(char *, char *, int);
void power_management_read_acpi_ac_adapter(const char *dir, int *result) {
  char fname[2048];
  FILE *proc;
  (*result) = 0;
  snprintf(fname, 2048,
           "/proc/acpi"
           "/ac_adapter/%s/state",
           dir);
  proc = fopen(fname, "rt");
  if (proc) {
    while (!feof(proc)) {
      char line[2048], *ptr;
      fgets(line, 2048, proc);
      if ((ptr = isIt("Status:", line))) {
        if (strncmp(ptr, "on-line", 7) == 0) {
          (*result) = 1;
        }
      }
    }
    fclose(proc);
    if (*result)
      return;
  }
}


x86 assembly (clang, -O0):
<power_management_read_acpi_ac_adapter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
lea    -0x810(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x800,%esi
lea    0xe5c(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x810(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x818(%rbp)
cmpq   $0x0,-0x818(%rbp)
je     128c <power_management_read_acpi_ac_adapter+0x11c>
jmp    11d6 <power_management_read_acpi_ac_adapter+0x66>
mov    -0x818(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f7 <power_management_read_acpi_ac_adapter+0x87>
jmp    1269 <power_management_read_acpi_ac_adapter+0xf9>
lea    -0x1020(%rbp),%rdi
mov    -0x818(%rbp),%rdx
mov    $0x800,%esi
call   1070 <fgets@plt>
lea    -0x1020(%rbp),%rsi
lea    0xe05(%rip),%rdi
call   1030 <isIt@plt>
mov    %rax,-0x1028(%rbp)
cmp    $0x0,%rax
je     1264 <power_management_read_acpi_ac_adapter+0xf4>
mov    -0x1028(%rbp),%rdi
lea    0xde9(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    125f <power_management_read_acpi_ac_adapter+0xef>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
jmp    1264 <power_management_read_acpi_ac_adapter+0xf4>
jmp    11d6 <power_management_read_acpi_ac_adapter+0x66>
mov    -0x818(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
je     1287 <power_management_read_acpi_ac_adapter+0x117>
jmp    128c <power_management_read_acpi_ac_adapter+0x11c>
jmp    128c <power_management_read_acpi_ac_adapter+0x11c>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<power_management_read_acpi_ac_adapter>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%r14
mov    %rdi,%rcx
movl   $0x0,(%rsi)
lea    0xe6d(%rip),%rdx
lea    0x800(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x800,%esi
call   1060 <snprintf@plt>
lea    0xe70(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     11d3 <power_management_read_acpi_ac_adapter+0x63>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     11e4 <power_management_read_acpi_ac_adapter+0x74>
mov    %rbx,%rdi
call   1050 <fclose@plt>
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    %rsp,%r15
lea    0xe34(%rip),%r12
lea    0xe35(%rip),%r13
jmp    120c <power_management_read_acpi_ac_adapter+0x9c>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    11cb <power_management_read_acpi_ac_adapter+0x5b>
mov    %r15,%rdi
mov    $0x800,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <isIt@plt>
test   %rax,%rax
je     1200 <power_management_read_acpi_ac_adapter+0x90>
mov    %rax,%rdi
mov    %r13,%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1200 <power_management_read_acpi_ac_adapter+0x90>
movl   $0x1,(%r14)
jmp    1200 <power_management_read_acpi_ac_adapter+0x90>

LLVM IR (-O0):
@.str = [31 x i8] c"/proc/acpi/ac_adapter/%s/state\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [8 x i8] c"Status:\00"
@.str.3 = [8 x i8] c"on-line\00"
define void @power_management_read_acpi_ac_adapter(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [2048 x i8]
%6 = alloca i32*
%7 = alloca [2048 x i8]
%8 = alloca i8*
store i8* %0, i8** %3
store i32* %1, i32** %4
%9 = load i32*, i32** %4
store i32 0, i32* %9
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%11 = load i8*, i8** %3
%12 = call i32 @snprintf(i8* %10, i32 2048, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %46
17: ; preds = %2
br label %18
18: ; preds = %37, %17
%19 = load i32*, i32** %6
%20 = call i32 @feof(i32* %19)
%21 = icmp ne i32 %20, 0
%22 = xor i1 %21, true
br i1 %22, label %23, label %38
23: ; preds = %18
%24 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%25 = load i32*, i32** %6
%26 = call i32 @fgets(i8* %24, i32 2048, i32* %25)
%27 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%28 = call i8* @isIt(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %27)
store i8* %28, i8** %8
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %37
30: ; preds = %23
%31 = load i8*, i8** %8
%32 = call i64 @strncmp(i8* %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 7)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = load i32*, i32** %4
store i32 1, i32* %35
br label %36
36: ; preds = %34, %30
br label %37
37: ; preds = %36, %23
br label %18
38: ; preds = %18
%39 = load i32*, i32** %6
%40 = call i32 @fclose(i32* %39)
%41 = load i32*, i32** %4
%42 = load i32, i32* %41
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %38
br label %46
45: ; preds = %38
br label %46
46: ; preds = %44, %45, %2
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"/proc/acpi/ac_adapter/%s/state\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [8 x i8] c"Status:\00"
@.str.3 = [8 x i8] c"on-line\00"
define void @power_management_read_acpi_ac_adapter(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [2048 x i8]
%4 = alloca [2048 x i8]
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
store i32 0, i32* %1
%6 = call i32 @snprintf(i8* %5, i32 2048, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %27, label %9
9: ; preds = %2
%10 = call i32 @feof(i32* %7)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
br label %14
14: ; preds = %12, %22
%15 = call i32 @fgets(i8* %13, i32 2048, i32* %7)
%16 = call i8* @isIt(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%17 = icmp eq i8* %16, null
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = call i64 @strncmp(i8* %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 7)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 1, i32* %1
br label %22
22: ; preds = %18, %21, %14
%23 = call i32 @feof(i32* %7)
%24 = icmp eq i32 %23, 0
br i1 %24, label %14, label %25
25: ; preds = %22, %9
%26 = call i32 @fclose(i32* %7)
br label %27
27: ; preds = %25, %2
ret void
}