#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*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ strtol(char *, char **, int);
float get_num_status() {
  FILE *ba_power_fp = NULL;
  ;
  char *ba_status = "/sys/class/power_supply/BAT0/energy_now";
  char current_power[10];
  char **num_end = NULL;
  if ((ba_power_fp = fopen(ba_status, "r")) == NULL) {
    perror("fopen error: ba_power_fp");
  }
  fgets(current_power, 10, ba_power_fp);
  fclose(ba_power_fp);
  return (float)strtol(current_power, num_end, 10);
}


x86 assembly (clang, -O0):
<get_num_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x8(%rbp)
lea    0xe99(%rip),%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeaa(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    119d <get_num_status+0x4d>
lea    0xe92(%rip),%rdi
call   1070 <perror@plt>
lea    -0x1a(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0xa,%esi
call   1040 <fgets@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x1a(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
cvtsi2ss %rax,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_num_status>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xea2(%rip),%rdi
lea    0xec3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11ab <get_num_status+0x5b>
lea    0xe(%rsp),%r14
mov    %r14,%rdi
mov    $0xa,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
cvtsi2ss %rax,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe78(%rip),%rdi
call   1070 <perror@plt>
jmp    1172 <get_num_status+0x22>

LLVM IR (-O0):
@.str = [40 x i8] c"/sys/class/power_supply/BAT0/energy_now\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"fopen error: ba_power_fp\00"
define float @get_num_status() {
%1 = alloca i32*
%2 = alloca i8*
%3 = alloca [10 x i8]
%4 = alloca i8**
store i32* null, i32** %1
store i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8** %2
store i8** null, i8*** %4
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %1
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%12 = load i32*, i32** %1
%13 = call i32 @fgets(i8* %11, i32 10, i32* %12)
%14 = load i32*, i32** %1
%15 = call i32 @fclose(i32* %14)
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%17 = load i8**, i8*** %4
%18 = call i64 @strtol(i8* %16, i8** %17, i32 10)
%19 = sitofp i64 %18 to float
ret float %19
}

LLVM IR (-O2):
@.str = [40 x i8] c"/sys/class/power_supply/BAT0/energy_now\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"fopen error: ba_power_fp\00"
define float @get_num_status() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = call i32 @fgets(i8* %2, i32 10, i32* %3)
%9 = call i32 @fclose(i32* %3)
%10 = call i64 @strtol(i8* nocapture %2, i8** null, i32 10)
%11 = sitofp i64 %10 to float
ret float %11
}