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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ stderr;
float getpower() {
  FILE *fd;
  int current_now;
  fd = fopen("/sys/class/power_supply/BAT1/power_now", "r");
  if (fd == NULL) {
    fprintf(stderr, "Error opening power_now.\n");
    return -1;
  }
  fscanf(fd, "%d", &current_now);
  fclose(fd);
  uint64_t pwr = current_now;
  pwr /= 10000;
  return (float)pwr / 100.0;
}


x86 assembly (clang, -O0):
<getpower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xebd(%rip),%rdi
lea    0xedd(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1191 <getpower+0x51>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xebb(%rip),%rsi
call   1050 <fprintf@plt>
movss  0xe81(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11e0 <getpower+0xa0>
mov    -0x10(%rbp),%rdi
lea    0xeb3(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
cvtsi2ssl -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe2d(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getpower>:
push   %rbx
sub    $0x10,%rsp
lea    0xebc(%rip),%rdi
lea    0xedc(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a3 <getpower+0x63>
mov    %rax,%rbx
lea    0xee4(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
movslq 0xc(%rsp),%rax
imul   $0x68db8bad,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2c,%rax
add    %ecx,%eax
cvtsi2ss %eax,%xmm0
divss  0xe5f(%rip),%xmm0
jmp    11c0 <getpower+0x80>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
call   1050 <fprintf@plt>
movss  0xe44(%rip),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [39 x i8] c"/sys/class/power_supply/BAT1/power_now\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Error opening power_now.\0A\00"
@.str.3 = [3 x i8] c"%d\00"
define float @getpower() {
%1 = alloca float
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = call i32* @fopen(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store float -1.000000e+00, float* %1
br label %24
11: ; preds = %0
%12 = load i32*, i32** %2
%13 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%14 = load i32*, i32** %2
%15 = call i32 @fclose(i32* %14)
%16 = load i32, i32* %3
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = sdiv i32 %17, 10000
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = sitofp i32 %19 to float
%21 = fpext float %20 to double
%22 = fdiv double %21, 1.000000e+02
%23 = fptrunc double %22 to float
store float %23, float* %1
br label %24
24: ; preds = %11, %8
%25 = load float, float* %1
ret float %25
}

LLVM IR (-O2):
@.str = [39 x i8] c"/sys/class/power_supply/BAT1/power_now\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Error opening power_now.\0A\00"
@.str.3 = [3 x i8] c"%d\00"
define float @getpower() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([39 x i8], [39 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 %8
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %15
8: ; preds = %0
%9 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%10 = call i32 @fclose(i32* %3)
%11 = load i32, i32* %1
%12 = sdiv i32 %11, 10000
%13 = sitofp i32 %12 to float
%14 = fdiv float %13, 1.000000e+02
br label %15
15: ; preds = %8, %5
%16 = phi float [ -1.000000e+00, %5 ], [ %14, %8 ]
ret float %16
}