#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*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
char get_ac_status() {
  char *ac_status = "/sys/class/power_supply/AC/online";
  char acVal;
  FILE *ac_power_fp = NULL;
  if ((ac_power_fp = fopen(ac_status, "r")) == NULL) {
    perror("fopen error: ac_power_fp");
  }
  acVal = fgetc(ac_power_fp);
  fclose(ac_power_fp);
  return acVal;
}


x86 assembly (clang, -O0):
<get_ac_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rax
mov    %rax,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xebc(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1185 <get_ac_status+0x45>
lea    0xea4(%rip),%rdi
call   1060 <perror@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x9(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movsbl -0x9(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ac_status>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
lea    0xed1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1179 <get_ac_status+0x39>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xea4(%rip),%rdi
call   1060 <perror@plt>
jmp    115e <get_ac_status+0x1e>

LLVM IR (-O0):
@.str = [34 x i8] c"/sys/class/power_supply/AC/online\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"fopen error: ac_power_fp\00"
define signext i8 @get_ac_status() {
%1 = alloca i8*
%2 = alloca i8
%3 = alloca i32*
store i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8** %1
store i32* null, i32** %3
%4 = load i8*, i8** %1
%5 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %3
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = load i32*, i32** %3
%11 = call signext i8 @fgetc(i32* %10)
store i8 %11, i8* %2
%12 = load i32*, i32** %3
%13 = call i32 @fclose(i32* %12)
%14 = load i8, i8* %2
ret i8 %14
}

LLVM IR (-O2):
@.str = [34 x i8] c"/sys/class/power_supply/AC/online\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"fopen error: ac_power_fp\00"
define signext i8 @get_ac_status() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %5
5: ; preds = %3, %0
%6 = tail call signext i8 @fgetc(i32* %1)
%7 = tail call i32 @fclose(i32* %1)
ret i8 %6
}