#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 */
int /*<<< orphan*/ free(char *);
char *readfile(char *, char *);
char *smprintf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, ...);
char *getbattery(char *base) {
  char *co;
  char *stat;
  char *ret;
  char status;
  int descap;
  int remcap;
  double remaining;
  double using;
  double voltage;
  double current;
  descap = -1;
  remcap = -1;
  using = -1;
  remaining = -1;
  stat = "Not Charging";
  co = readfile(base, "present");
  if (co == NULL || co[0] != '1') {
    if (co != NULL)
      free(co);
    return smprintf("not present");
  }
  free(co);
  co = readfile(base, "status");
  if (co == NULL) {
    co = "Not Charging";
  }
  sscanf(co, "%s", &status);
  free(co);
  co = readfile(base, "charge_full_design");
  if (co == NULL) {
    co = readfile(base, "energy_full_design");
    if (co == NULL)
      return smprintf("");
  }
  sscanf(co, "%d", &descap);
  free(co);
  co = readfile(base, "charge_now");
  if (co == NULL) {
    co = readfile(base, "energy_now");
    if (co == NULL)
      return smprintf("");
  }
  sscanf(co, "%d", &remcap);
  free(co);
  co = readfile(base, "power_now");
  if (co == NULL) {
    co = readfile(base, "voltage_now");
    sscanf(co, "%lf", &voltage);
    free(co);
    co = readfile(base, "current_now");
    sscanf(co, "%lf", &current);
    free(co);
    remcap = (voltage / 1000.0) * ((double)remcap / 1000.0);
    descap = (voltage / 1000.0) * ((double)descap / 1000.0);
    using = (voltage / 1000.0) * ((double)current / 1000.0);
  } else {
    sscanf(co, "%lf", &using);
    free(co);
  }
  if (remcap < 0 || descap < 0)
    return smprintf("invalid");
  if (status == 'D') {
    remaining = (double)remcap / using;
    stat = "B";
  } else if (status == 'C') {
    remaining = ((double)descap - (double)remcap) / using;
    stat = "C";
  } else {
    remaining = 0;
    stat = "F";
  }
  int hours, seconds, minutes, secs_rem;
  secs_rem = (int)(remaining * 3600.0);
  hours = secs_rem / 3600;
  seconds = secs_rem - (hours * 3600);
  minutes = seconds / 60;
  seconds -= (minutes * 60);
  if (seconds < 0 || minutes < 0 || hours < 0)
    ret = smprintf("%s: Calculating...", stat);
  else
    ret = smprintf("%s: %.2lf%% %02d:%02d:%02d", stat,
                   (((double)remcap / (double)descap) * 100), hours, minutes,
                   seconds);
  {
    if (!stat)
      free(stat);
  };
  return ret;
}


x86 assembly (clang, -O0):
<getbattery>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x30(%rbp)
movl   $0xffffffff,-0x34(%rbp)
movsd  0xe9e(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xe91(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
lea    0xea5(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea7(%rip),%rsi
call   1060 <readfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ae <getbattery+0x6e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x31,%eax
je     11d9 <getbattery+0x99>
cmpq   $0x0,-0x18(%rbp)
je     11c2 <getbattery+0x82>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <smprintf@plt>
mov    %rax,-0x8(%rbp)
jmp    15c9 <getbattery+0x489>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1060 <readfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    120c <getbattery+0xcc>
lea    0xe18(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe29(%rip),%rsi
lea    -0x29(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
lea    0xe0d(%rip),%rsi
call   1060 <readfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1285 <getbattery+0x145>
mov    -0x10(%rbp),%rdi
lea    0xe01(%rip),%rsi
call   1060 <readfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1280 <getbattery+0x140>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <smprintf@plt>
mov    %rax,-0x8(%rbp)
jmp    15c9 <getbattery+0x489>
jmp    1285 <getbattery+0x145>
mov    -0x18(%rbp),%rdi
lea    0xdd9(%rip),%rsi
lea    -0x30(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
lea    0xdbd(%rip),%rsi
call   1060 <readfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12fe <getbattery+0x1be>
mov    -0x10(%rbp),%rdi
lea    0xda9(%rip),%rsi
call   1060 <readfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12f9 <getbattery+0x1b9>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <smprintf@plt>
mov    %rax,-0x8(%rbp)
jmp    15c9 <getbattery+0x489>
jmp    12fe <getbattery+0x1be>
mov    -0x18(%rbp),%rdi
lea    0xd60(%rip),%rsi
lea    -0x34(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
lea    0xd5a(%rip),%rsi
call   1060 <readfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    142c <getbattery+0x2ec>
mov    -0x10(%rbp),%rdi
lea    0xd45(%rip),%rsi
call   1060 <readfile@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd3d(%rip),%rsi
lea    -0x50(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
lea    0xd22(%rip),%rsi
call   1060 <readfile@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd0a(%rip),%rsi
lea    -0x58(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x50(%rbp),%xmm0
movsd  0xc59(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdl -0x34(%rbp),%xmm1
movsd  0xc48(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x34(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  0xc2c(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdl -0x30(%rbp),%xmm1
movsd  0xc1b(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x30(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  0xbff(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x58(%rbp),%xmm1
movsd  0xbee(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    144b <getbattery+0x30b>
mov    -0x18(%rbp),%rdi
lea    0xc61(%rip),%rsi
lea    -0x48(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x34(%rbp)
jl     145f <getbattery+0x31f>
cmpl   $0x0,-0x30(%rbp)
jge    1476 <getbattery+0x336>
lea    0xc42(%rip),%rdi
mov    $0x0,%al
call   1040 <smprintf@plt>
mov    %rax,-0x8(%rbp)
jmp    15c9 <getbattery+0x489>
movsbl -0x29(%rbp),%eax
cmp    $0x44,%eax
jne    14a2 <getbattery+0x362>
cvtsi2sdl -0x34(%rbp),%xmm0
divsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
lea    0xc17(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    14ef <getbattery+0x3af>
movsbl -0x29(%rbp),%eax
cmp    $0x43,%eax
jne    14d7 <getbattery+0x397>
cvtsi2sdl -0x30(%rbp),%xmm0
cvtsi2sdl -0x34(%rbp),%xmm1
subsd  %xmm1,%xmm0
divsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
lea    0xbe4(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    14ea <getbattery+0x3aa>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
lea    0xbce(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    14ef <getbattery+0x3af>
movsd  0xb19(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x5c(%rbp)
mov    -0x68(%rbp),%eax
imul   $0xe10,-0x5c(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x64(%rbp)
imul   $0x3c,-0x64(%rbp),%ecx
mov    -0x60(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x60(%rbp)
cmpl   $0x0,-0x60(%rbp)
jl     1558 <getbattery+0x418>
cmpl   $0x0,-0x64(%rbp)
jl     1558 <getbattery+0x418>
cmpl   $0x0,-0x5c(%rbp)
jge    1573 <getbattery+0x433>
mov    -0x20(%rbp),%rsi
lea    0xb53(%rip),%rdi
mov    $0x0,%al
call   1040 <smprintf@plt>
mov    %rax,-0x28(%rbp)
jmp    15ad <getbattery+0x46d>
mov    -0x20(%rbp),%rsi
cvtsi2sdl -0x34(%rbp),%xmm0
cvtsi2sdl -0x30(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xa8b(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x5c(%rbp),%edx
mov    -0x64(%rbp),%ecx
mov    -0x60(%rbp),%r8d
lea    0xb27(%rip),%rdi
mov    $0x1,%al
call   1040 <smprintf@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    15c1 <getbattery+0x481>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getbattery>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%r14
movl   $0xffffffff,0x14(%rsp)
ff
movl   $0xffffffff,0x10(%rsp)
ff
movabs $0xbff0000000000000,%rax
mov    %rax,0x18(%rsp)
lea    0xecf(%rip),%rsi
call   1060 <readfile@plt>
test   %rax,%rax
je     12b7 <getbattery+0x177>
mov    (%rax),%bl
mov    %rax,%rdi
call   1030 <free@plt>
cmp    $0x31,%bl
jne    12b7 <getbattery+0x177>
lea    0xeaf(%rip),%rsi
mov    %r14,%rdi
call   1060 <readfile@plt>
test   %rax,%rax
lea    0xe84(%rip),%rbx
cmovne %rax,%rbx
lea    0xe99(%rip),%rsi
lea    0xf(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe7e(%rip),%rsi
mov    %r14,%rdi
call   1060 <readfile@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1200 <getbattery+0xc0>
lea    0xe7a(%rip),%rsi
mov    %r14,%rdi
call   1060 <readfile@plt>
mov    %rax,%rbx
test   %rax,%rax
je     13c7 <getbattery+0x287>
lea    0xe72(%rip),%rsi
lea    0x14(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe57(%rip),%rsi
mov    %r14,%rdi
call   1060 <readfile@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1250 <getbattery+0x110>
lea    0xe4b(%rip),%rsi
mov    %r14,%rdi
call   1060 <readfile@plt>
mov    %rax,%rbx
test   %rax,%rax
je     13c7 <getbattery+0x287>
lea    0xe22(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe1d(%rip),%rsi
mov    %r14,%rdi
call   1060 <readfile@plt>
test   %rax,%rax
je     12ce <getbattery+0x18e>
mov    %rax,%rbx
lea    0xe1c(%rip),%rsi
lea    0x18(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
movss  0x14(%rsp),%xmm1
movss  0x10(%rsp),%xmm0
unpcklps %xmm1,%xmm0
jmp    138b <getbattery+0x24b>
lea    0xd7f(%rip),%rdi
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <smprintf@plt>
lea    0xdc7(%rip),%rsi
mov    %r14,%rdi
call   1060 <readfile@plt>
mov    %rax,%rbx
lea    0xdc1(%rip),%r15
lea    0x28(%rsp),%rdx
mov    %rax,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xda4(%rip),%rsi
mov    %r14,%rdi
call   1060 <readfile@plt>
mov    %rax,%rbx
lea    0x20(%rsp),%rdx
mov    %rax,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
movsd  0x28(%rsp),%xmm0
movsd  0xcc5(%rip),%xmm1
movss  0x14(%rsp),%xmm2
movss  0x10(%rsp),%xmm3
unpcklps %xmm2,%xmm3
cvtdq2pd %xmm3,%xmm2
divpd  0xcca(%rip),%xmm2
divsd  %xmm1,%xmm0
movsd  0x20(%rsp),%xmm3
divsd  %xmm1,%xmm3
mulsd  %xmm0,%xmm3
unpcklpd %xmm0,%xmm0
mulpd  %xmm2,%xmm0
cvttpd2dq %xmm0,%xmm0
pshufd $0x55,%xmm0,%xmm1
movd   %xmm0,0x10(%rsp)
movd   %xmm1,0x14(%rsp)
movsd  %xmm3,0x18(%rsp)
pshufd $0x50,%xmm0,%xmm1
movmskpd %xmm1,%eax
test   %eax,%eax
je     13a1 <getbattery+0x261>
lea    0xd19(%rip),%rdi
jmp    13ce <getbattery+0x28e>
mov    0xf(%rsp),%al
cmp    $0x43,%al
je     13da <getbattery+0x29a>
cmp    $0x44,%al
jne    13f9 <getbattery+0x2b9>
movd   %xmm0,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  0x18(%rsp),%xmm1
lea    0xcfb(%rip),%rsi
jmp    1404 <getbattery+0x2c4>
lea    0xd0a(%rip),%rdi
xor    %eax,%eax
call   1040 <smprintf@plt>
jmp    1497 <getbattery+0x357>
cvtdq2pd %xmm0,%xmm2
movapd %xmm2,%xmm1
unpckhpd %xmm2,%xmm1
subsd  %xmm2,%xmm1
divsd  0x18(%rsp),%xmm1
lea    0xccb(%rip),%rsi
jmp    1404 <getbattery+0x2c4>
lea    0xcc4(%rip),%rsi
xorpd  %xmm1,%xmm1
mulsd  0xbfc(%rip),%xmm1
cvttsd2si %xmm1,%eax
movslq %eax,%rcx
imul   $0xffffffff91a2b3c5,%rcx,%rdx
shr    $0x20,%rdx
add    %eax,%edx
mov    %edx,%ecx
shr    $0x1f,%ecx
sar    $0xb,%edx
add    %ecx,%edx
imul   $0xfffff1f0,%edx,%edi
add    %eax,%edi
cmp    $0xffffffc5,%edi
jl     1489 <getbattery+0x349>
movslq %edi,%rcx
imul   $0xffffffff88888889,%rcx,%rcx
shr    $0x20,%rcx
add    %edi,%ecx
mov    %ecx,%ebx
shr    $0x1f,%ebx
sar    $0x5,%ecx
add    %ebx,%ecx
imul   $0xffffffc4,%ecx,%r8d
add    %edi,%r8d
js     1489 <getbattery+0x349>
cmp    $0xfffff1f0,%eax
jle    1489 <getbattery+0x349>
cvtdq2pd %xmm0,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
divsd  %xmm1,%xmm0
mulsd  0xb97(%rip),%xmm0
lea    0xc59(%rip),%rdi
mov    $0x1,%al
call   1040 <smprintf@plt>
jmp    1497 <getbattery+0x357>
lea    0xc36(%rip),%rdi
xor    %eax,%eax
call   1040 <smprintf@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Not Charging\00"
@.str.1 = [8 x i8] c"present\00"
@.str.2 = [12 x i8] c"not present\00"
@.str.3 = [7 x i8] c"status\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [19 x i8] c"charge_full_design\00"
@.str.6 = [19 x i8] c"energy_full_design\00"
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [11 x i8] c"charge_now\00"
@.str.10 = [11 x i8] c"energy_now\00"
@.str.11 = [10 x i8] c"power_now\00"
@.str.12 = [12 x i8] c"voltage_now\00"
@.str.13 = [4 x i8] c"%lf\00"
@.str.14 = [12 x i8] c"current_now\00"
@.str.15 = [8 x i8] c"invalid\00"
@.str.16 = [2 x i8] c"B\00"
@.str.17 = [2 x i8] c"C\00"
@.str.18 = [2 x i8] c"F\00"
@.str.19 = [19 x i8] c"%s: Calculating...\00"
@.str.20 = [27 x i8] c"%s: %.2lf%% %02d:%02d:%02d\00"
define i8* @getbattery(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i8* %0, i8** %3
store i32 -1, i32* %8
store i32 -1, i32* %9
store double -1.000000e+00, double* %11
store double -1.000000e+00, double* %10
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %5
%18 = load i8*, i8** %3
%19 = call i8* @readfile(i8* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i8* %19, i8** %4
%20 = load i8*, i8** %4
%21 = icmp eq i8* %20, null
br i1 %21, label %28, label %22
22: ; preds = %1
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 49
br i1 %27, label %28, label %36
28: ; preds = %22, %1
%29 = load i8*, i8** %4
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i8*, i8** %4
%33 = call i32 @free(i8* %32)
br label %34
34: ; preds = %31, %28
%35 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i8* %35, i8** %2
br label %202
36: ; preds = %22
%37 = load i8*, i8** %4
%38 = call i32 @free(i8* %37)
%39 = load i8*, i8** %3
%40 = call i8* @readfile(i8* %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i8* %40, i8** %4
%41 = load i8*, i8** %4
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %44
43: ; preds = %36
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %4
br label %44
44: ; preds = %43, %36
%45 = load i8*, i8** %4
%46 = call i32 (i8*, i8*, ...) @sscanf(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%47 = load i8*, i8** %4
%48 = call i32 @free(i8* %47)
%49 = load i8*, i8** %3
%50 = call i8* @readfile(i8* %49, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
store i8* %50, i8** %4
%51 = load i8*, i8** %4
%52 = icmp eq i8* %51, null
br i1 %52, label %53, label %61
53: ; preds = %44
%54 = load i8*, i8** %3
%55 = call i8* @readfile(i8* %54, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
store i8* %55, i8** %4
%56 = load i8*, i8** %4
%57 = icmp eq i8* %56, null
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0))
store i8* %59, i8** %2
br label %202
60: ; preds = %53
br label %61
61: ; preds = %60, %44
%62 = load i8*, i8** %4
%63 = call i32 (i8*, i8*, ...) @sscanf(i8* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %8)
%64 = load i8*, i8** %4
%65 = call i32 @free(i8* %64)
%66 = load i8*, i8** %3
%67 = call i8* @readfile(i8* %66, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
store i8* %67, i8** %4
%68 = load i8*, i8** %4
%69 = icmp eq i8* %68, null
br i1 %69, label %70, label %78
70: ; preds = %61
%71 = load i8*, i8** %3
%72 = call i8* @readfile(i8* %71, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
store i8* %72, i8** %4
%73 = load i8*, i8** %4
%74 = icmp eq i8* %73, null
br i1 %74, label %75, label %77
75: ; preds = %70
%76 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0))
store i8* %76, i8** %2
br label %202
77: ; preds = %70
br label %78
78: ; preds = %77, %61
%79 = load i8*, i8** %4
%80 = call i32 (i8*, i8*, ...) @sscanf(i8* %79, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %9)
%81 = load i8*, i8** %4
%82 = call i32 @free(i8* %81)
%83 = load i8*, i8** %3
%84 = call i8* @readfile(i8* %83, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
store i8* %84, i8** %4
%85 = load i8*, i8** %4
%86 = icmp eq i8* %85, null
br i1 %86, label %87, label %119
87: ; preds = %78
%88 = load i8*, i8** %3
%89 = call i8* @readfile(i8* %88, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0))
store i8* %89, i8** %4
%90 = load i8*, i8** %4
%91 = call i32 (i8*, i8*, ...) @sscanf(i8* %90, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), double* %12)
%92 = load i8*, i8** %4
%93 = call i32 @free(i8* %92)
%94 = load i8*, i8** %3
%95 = call i8* @readfile(i8* %94, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0))
store i8* %95, i8** %4
%96 = load i8*, i8** %4
%97 = call i32 (i8*, i8*, ...) @sscanf(i8* %96, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), double* %13)
%98 = load i8*, i8** %4
%99 = call i32 @free(i8* %98)
%100 = load double, double* %12
%101 = fdiv double %100, 1.000000e+03
%102 = load i32, i32* %9
%103 = sitofp i32 %102 to double
%104 = fdiv double %103, 1.000000e+03
%105 = fmul double %101, %104
%106 = fptosi double %105 to i32
store i32 %106, i32* %9
%107 = load double, double* %12
%108 = fdiv double %107, 1.000000e+03
%109 = load i32, i32* %8
%110 = sitofp i32 %109 to double
%111 = fdiv double %110, 1.000000e+03
%112 = fmul double %108, %111
%113 = fptosi double %112 to i32
store i32 %113, i32* %8
%114 = load double, double* %12
%115 = fdiv double %114, 1.000000e+03
%116 = load double, double* %13
%117 = fdiv double %116, 1.000000e+03
%118 = fmul double %115, %117
store double %118, double* %11
br label %124
119: ; preds = %78
%120 = load i8*, i8** %4
%121 = call i32 (i8*, i8*, ...) @sscanf(i8* %120, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), double* %11)
%122 = load i8*, i8** %4
%123 = call i32 @free(i8* %122)
br label %124
124: ; preds = %119, %87
%125 = load i32, i32* %9
%126 = icmp slt i32 %125, 0
br i1 %126, label %130, label %127
127: ; preds = %124
%128 = load i32, i32* %8
%129 = icmp slt i32 %128, 0
br i1 %129, label %130, label %132
130: ; preds = %127, %124
%131 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i64 0, i64 0))
store i8* %131, i8** %2
br label %202
132: ; preds = %127
%133 = load i8, i8* %7
%134 = sext i8 %133 to i32
%135 = icmp eq i32 %134, 68
br i1 %135, label %136, label %141
136: ; preds = %132
%137 = load i32, i32* %9
%138 = sitofp i32 %137 to double
%139 = load double, double* %11
%140 = fdiv double %138, %139
store double %140, double* %10
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.16, i64 0, i64 0), i8** %5
br label %155
141: ; preds = %132
%142 = load i8, i8* %7
%143 = sext i8 %142 to i32
%144 = icmp eq i32 %143, 67
br i1 %144, label %145, label %153
145: ; preds = %141
%146 = load i32, i32* %8
%147 = sitofp i32 %146 to double
%148 = load i32, i32* %9
%149 = sitofp i32 %148 to double
%150 = fsub double %147, %149
%151 = load double, double* %11
%152 = fdiv double %150, %151
store double %152, double* %10
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0), i8** %5
br label %154
153: ; preds = %141
store double 0.000000e+00, double* %10
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.18, i64 0, i64 0), i8** %5
br label %154
154: ; preds = %153, %145
br label %155
155: ; preds = %154, %136
%156 = load double, double* %10
%157 = fmul double %156, 3.600000e+03
%158 = fptosi double %157 to i32
store i32 %158, i32* %17
%159 = load i32, i32* %17
%160 = sdiv i32 %159, 3600
store i32 %160, i32* %14
%161 = load i32, i32* %17
%162 = load i32, i32* %14
%163 = mul nsw i32 %162, 3600
%164 = sub nsw i32 %161, %163
store i32 %164, i32* %15
%165 = load i32, i32* %15
%166 = sdiv i32 %165, 60
store i32 %166, i32* %16
%167 = load i32, i32* %16
%168 = mul nsw i32 %167, 60
%169 = load i32, i32* %15
%170 = sub nsw i32 %169, %168
store i32 %170, i32* %15
%171 = load i32, i32* %15
%172 = icmp slt i32 %171, 0
br i1 %172, label %179, label %173
173: ; preds = %155
%174 = load i32, i32* %16
%175 = icmp slt i32 %174, 0
br i1 %175, label %179, label %176
176: ; preds = %173
%177 = load i32, i32* %14
%178 = icmp slt i32 %177, 0
br i1 %178, label %179, label %182
179: ; preds = %176, %173, %155
%180 = load i8*, i8** %5
%181 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.19, i64 0, i64 0), i8* %180)
store i8* %181, i8** %6
br label %194
182: ; preds = %176
%183 = load i8*, i8** %5
%184 = load i32, i32* %9
%185 = sitofp i32 %184 to double
%186 = load i32, i32* %8
%187 = sitofp i32 %186 to double
%188 = fdiv double %185, %187
%189 = fmul double %188, 1.000000e+02
%190 = load i32, i32* %14
%191 = load i32, i32* %16
%192 = load i32, i32* %15
%193 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.20, i64 0, i64 0), i8* %183, double %189, i32 %190, i32 %191, i32 %192)
store i8* %193, i8** %6
br label %194
194: ; preds = %182, %179
%195 = load i8*, i8** %5
%196 = icmp ne i8* %195, null
br i1 %196, label %200, label %197
197: ; preds = %194
%198 = load i8*, i8** %5
%199 = call i32 @free(i8* %198)
br label %200
200: ; preds = %197, %194
%201 = load i8*, i8** %6
store i8* %201, i8** %2
br label %202
202: ; preds = %200, %130, %75, %58, %34
%203 = load i8*, i8** %2
ret i8* %203
}

LLVM IR (-O2):
@.str = [13 x i8] c"Not Charging\00"
@.str.1 = [8 x i8] c"present\00"
@.str.2 = [12 x i8] c"not present\00"
@.str.3 = [7 x i8] c"status\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [19 x i8] c"charge_full_design\00"
@.str.6 = [19 x i8] c"energy_full_design\00"
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [11 x i8] c"charge_now\00"
@.str.10 = [11 x i8] c"energy_now\00"
@.str.11 = [10 x i8] c"power_now\00"
@.str.12 = [12 x i8] c"voltage_now\00"
@.str.13 = [4 x i8] c"%lf\00"
@.str.14 = [12 x i8] c"current_now\00"
@.str.15 = [8 x i8] c"invalid\00"
@.str.16 = [2 x i8] c"B\00"
@.str.17 = [2 x i8] c"C\00"
@.str.18 = [2 x i8] c"F\00"
@.str.19 = [19 x i8] c"%s: Calculating...\00"
@.str.20 = [27 x i8] c"%s: %.2lf%% %02d:%02d:%02d\00"
define i8* @getbattery(i8* %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast double* %5 to i8*
%11 = bitcast double* %6 to i8*
%12 = bitcast double* %7 to i8*
store i32 -1, i32* %3
store i32 -1, i32* %4
store double -1.000000e+00, double* %5
%13 = tail call i8* @readfile(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %19, label %15
15: ; preds = %1
%16 = load i8, i8* %13
%17 = icmp eq i8 %16, 49
%18 = tail call i32 @free(i8* %13)
br i1 %17, label %21, label %19
19: ; preds = %15, %1
%20 = tail call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %129
21: ; preds = %15
%22 = tail call i8* @readfile(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i8* %22, null
%24 = select i1 %23, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %22
%25 = call i32 (i8*, i8*, ...) @sscanf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %2)
%26 = call i32 @free(i8* %24)
%27 = call i8* @readfile(i8* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %34
29: ; preds = %21
%30 = call i8* @readfile(i8* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0))
br label %129
34: ; preds = %29, %21
%35 = phi i8* [ %30, %29 ], [ %27, %21 ]
%36 = call i32 (i8*, i8*, ...) @sscanf(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %3)
%37 = call i32 @free(i8* %35)
%38 = call i8* @readfile(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %45
40: ; preds = %34
%41 = call i8* @readfile(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0))
br label %129
45: ; preds = %40, %34
%46 = phi i8* [ %41, %40 ], [ %38, %34 ]
%47 = call i32 (i8*, i8*, ...) @sscanf(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %4)
%48 = call i32 @free(i8* %46)
%49 = call i8* @readfile(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
%50 = icmp eq i8* %49, null
br i1 %50, label %51, label %75
51: ; preds = %45
%52 = call i8* @readfile(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0))
%53 = call i32 (i8*, i8*, ...) @sscanf(i8* %52, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), double* %6)
%54 = call i32 @free(i8* %52)
%55 = call i8* @readfile(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0))
%56 = call i32 (i8*, i8*, ...) @sscanf(i8* %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), double* %7)
%57 = call i32 @free(i8* %55)
%58 = load double, double* %6
%59 = fdiv double %58, 1.000000e+03
%60 = load i32, i32* %4
%61 = load i32, i32* %3
%62 = insertelement <2 x i32> poison, i32 %60, i64 0
%63 = insertelement <2 x i32> %62, i32 %61, i64 1
%64 = sitofp <2 x i32> %63 to <2 x double>
%65 = fdiv <2 x double> %64, <double 1.000000e+03, double 1.000000e+03>
%66 = insertelement <2 x double> poison, double %59, i64 0
%67 = shufflevector <2 x double> %66, <2 x double> poison, <2 x i32> zeroinitializer
%68 = fmul <2 x double> %67, %65
%69 = fptosi <2 x double> %68 to <2 x i32>
%70 = extractelement <2 x i32> %69, i64 0
store i32 %70, i32* %4
%71 = extractelement <2 x i32> %69, i64 1
store i32 %71, i32* %3
%72 = load double, double* %7
%73 = fdiv double %72, 1.000000e+03
%74 = fmul double %59, %73
store double %74, double* %5
br label %82
75: ; preds = %45
%76 = call i32 (i8*, i8*, ...) @sscanf(i8* %49, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), double* %5)
%77 = call i32 @free(i8* %49)
%78 = load i32, i32* %4
%79 = load i32, i32* %3
%80 = insertelement <2 x i32> poison, i32 %78, i64 0
%81 = insertelement <2 x i32> %80, i32 %79, i64 1
br label %82
82: ; preds = %75, %51
%83 = phi <2 x i32> [ %81, %75 ], [ %69, %51 ]
%84 = icmp slt <2 x i32> %83, zeroinitializer
%85 = extractelement <2 x i1> %84, i64 0
%86 = extractelement <2 x i1> %84, i64 1
%87 = select i1 %85, i1 true, i1 %86
br i1 %87, label %88, label %90
88: ; preds = %82
%89 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i64 0, i64 0))
br label %129
90: ; preds = %82
%91 = load i8, i8* %2
switch i8 %91, label %104 [
i8 68, label %92
i8 67, label %97
]
92: ; preds = %90
%93 = extractelement <2 x i32> %83, i64 0
%94 = sitofp i32 %93 to double
%95 = load double, double* %5
%96 = fdiv double %94, %95
br label %104
97: ; preds = %90
%98 = sitofp <2 x i32> %83 to <2 x double>
%99 = shufflevector <2 x double> %98, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%100 = fsub <2 x double> %99, %98
%101 = extractelement <2 x double> %100, i64 0
%102 = load double, double* %5
%103 = fdiv double %101, %102
br label %104
104: ; preds = %90, %97, %92
%105 = phi double [ %96, %92 ], [ %103, %97 ], [ 0.000000e+00, %90 ]
%106 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.16, i64 0, i64 0), %92 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0), %97 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.18, i64 0, i64 0), %90 ]
%107 = fmul double %105, 3.600000e+03
%108 = fptosi double %107 to i32
%109 = sdiv i32 %108, 3600
%110 = mul nsw i32 %109, -3600
%111 = add i32 %110, %108
%112 = sdiv i32 %111, 60
%113 = mul nsw i32 %112, -60
%114 = add i32 %113, %111
%115 = icmp slt i32 %114, 0
%116 = icmp slt i32 %111, -59
%117 = or i1 %116, %115
%118 = icmp slt i32 %108, -3599
%119 = select i1 %117, i1 true, i1 %118
br i1 %119, label %120, label %122
120: ; preds = %104
%121 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.19, i64 0, i64 0), i8* %106)
br label %129
122: ; preds = %104
%123 = sitofp <2 x i32> %83 to <2 x double>
%124 = extractelement <2 x double> %123, i64 0
%125 = extractelement <2 x double> %123, i64 1
%126 = fdiv double %124, %125
%127 = fmul double %126, 1.000000e+02
%128 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.20, i64 0, i64 0), i8* %106, double %127, i32 %109, i32 %112, i32 %114)
br label %129
129: ; preds = %122, %120, %88, %43, %32, %19
%130 = phi i8* [ %20, %19 ], [ %33, %32 ], [ %44, %43 ], [ %89, %88 ], [ %121, %120 ], [ %128, %122 ]
ret i8* %130
}