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

/* Variables and functions */
float readFloat(char *);
int getBatRemainigChargingMins() {
  float energy_full = readFloat("/sys/class/power_supply/BAT0/energy_full");
  float energy_now = readFloat("/sys/class/power_supply/BAT0/energy_now");
  float power_now = readFloat("/sys/class/power_supply/BAT0/power_now");
  if (power_now == 0) {
    return 0;
  }
  return 60 * (energy_full - energy_now) / power_now;
}


x86 assembly (clang, -O0):
<getBatRemainigChargingMins>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xee5(%rip),%rdi
call   1030 <readFloat@plt>
movss  %xmm0,-0x8(%rbp)
lea    0xefd(%rip),%rdi
call   1030 <readFloat@plt>
movss  %xmm0,-0xc(%rbp)
lea    0xf14(%rip),%rdi
call   1030 <readFloat@plt>
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    116e <getBatRemainigChargingMins+0x5e>
jp     116e <getBatRemainigChargingMins+0x5e>
movl   $0x0,-0x4(%rbp)
jmp    1190 <getBatRemainigChargingMins+0x80>
movss  -0x8(%rbp),%xmm1
subss  -0xc(%rbp),%xmm1
movss  0xe80(%rip),%xmm0
mulss  %xmm1,%xmm0
divss  -0x10(%rbp),%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getBatRemainigChargingMins>:
push   %rax
lea    0xeec(%rip),%rdi
call   1030 <readFloat@plt>
movss  %xmm0,0x4(%rsp)
lea    0xf03(%rip),%rdi
call   1030 <readFloat@plt>
movss  %xmm0,(%rsp)
lea    0xf1a(%rip),%rdi
call   1030 <readFloat@plt>
xor    %eax,%eax
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    114e <getBatRemainigChargingMins+0x3e>
jp     114e <getBatRemainigChargingMins+0x3e>
pop    %rcx
ret
movss  0x4(%rsp),%xmm1
subss  (%rsp),%xmm1
mulss  0xe9f(%rip),%xmm1
divss  %xmm0,%xmm1
cvttss2si %xmm1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [41 x i8] c"/sys/class/power_supply/BAT0/energy_full\00"
@.str.1 = [40 x i8] c"/sys/class/power_supply/BAT0/energy_now\00"
@.str.2 = [39 x i8] c"/sys/class/power_supply/BAT0/power_now\00"
define i32 @getBatRemainigChargingMins() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = call float @readFloat(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
store float %5, float* %2
%6 = call float @readFloat(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store float %6, float* %3
%7 = call float @readFloat(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
store float %7, float* %4
%8 = load float, float* %4
%9 = fcmp oeq float %8, 0.000000e+00
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 0, i32* %1
br label %19
11: ; preds = %0
%12 = load float, float* %2
%13 = load float, float* %3
%14 = fsub float %12, %13
%15 = fmul float 6.000000e+01, %14
%16 = load float, float* %4
%17 = fdiv float %15, %16
%18 = fptosi float %17 to i32
store i32 %18, i32* %1
br label %19
19: ; preds = %11, %10
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@.str = [41 x i8] c"/sys/class/power_supply/BAT0/energy_full\00"
@.str.1 = [40 x i8] c"/sys/class/power_supply/BAT0/energy_now\00"
@.str.2 = [39 x i8] c"/sys/class/power_supply/BAT0/power_now\00"
define i32 @getBatRemainigChargingMins() {
%1 = tail call float @readFloat(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%2 = tail call float @readFloat(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call float @readFloat(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%4 = fcmp oeq float %3, 0.000000e+00
br i1 %4, label %10, label %5
5: ; preds = %0
%6 = fsub float %1, %2
%7 = fmul float %6, 6.000000e+01
%8 = fdiv float %7, %3
%9 = fptosi float %8 to i32
br label %10
10: ; preds = %0, %5
%11 = phi i32 [ %9, %5 ], [ 0, %0 ]
ret i32 %11
}