#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 *, ...);
int /*<<< orphan*/ strncmp(char *, char *, int);
char *getbattery(char *base) {
  char *co;
  char *remaining_time;
  int descap, remcap;
  double remaining, using, voltage, current;
  char status = '?';
  descap = -1;
  remcap = -1;
  using = -1;
  remaining = -1;
  co = readfile(base, "present");
  if (co == NULL || co[0] != '1') {
    if (co != NULL)
      free(co);
    return smprintf("not present");
  }
  free(co);
  co = readfile(base, "charge_full_design");
  if (co == NULL) {
    co = readfile(base, "energy_full");
    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");
  co = readfile(base, "status");
  if (!strncmp(co, "Charging", 8)) {
    status = '^';
    remaining = ((double)descap - (double)remcap) / using;
  } else if (!strncmp(co, "Discharging", 11)) {
    status = 'v';
    remaining = (double)remcap / using;
  } else {
    status = '=';
    remaining = 0;
    remaining_time = "";
  }
  if (remaining != 0) {
    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) {
      remaining_time = smprintf(" ...");
    } else if (hours) {
      remaining_time = smprintf(" %02d:%02d:%02d", hours, minutes, seconds);
    } else {
      remaining_time = smprintf(" %02d:%02d", minutes, seconds);
    }
  }
  return smprintf("[%c%.0f%%%s]", status, ((float)remcap / (float)descap) * 100,
                  remaining_time);
}


x86 assembly (clang, -O0):
<getbattery>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
movb   $0x3f,-0x49(%rbp)
movl   $0xffffffff,-0x24(%rbp)
movl   $0xffffffff,-0x28(%rbp)
movsd  0xe8a(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe7d(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1070 <readfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b7 <getbattery+0x67>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x31,%eax
je     11e2 <getbattery+0x92>
cmpq   $0x0,-0x18(%rbp)
je     11cb <getbattery+0x7b>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <smprintf@plt>
mov    %rax,-0x8(%rbp)
jmp    15fc <getbattery+0x4ac>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1070 <readfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1245 <getbattery+0xf5>
mov    -0x10(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   1070 <readfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1240 <getbattery+0xf0>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1050 <smprintf@plt>
mov    %rax,-0x8(%rbp)
jmp    15fc <getbattery+0x4ac>
jmp    1245 <getbattery+0xf5>
mov    -0x18(%rbp),%rdi
lea    0xdf7(%rip),%rsi
lea    -0x24(%rbp),%rdx
mov    $0x0,%al
call   1060 <sscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
lea    0xddb(%rip),%rsi
call   1070 <readfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12be <getbattery+0x16e>
mov    -0x10(%rbp),%rdi
lea    0xdc7(%rip),%rsi
call   1070 <readfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12b9 <getbattery+0x169>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1050 <smprintf@plt>
mov    %rax,-0x8(%rbp)
jmp    15fc <getbattery+0x4ac>
jmp    12be <getbattery+0x16e>
mov    -0x18(%rbp),%rdi
lea    0xd7e(%rip),%rsi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1060 <sscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
lea    0xd78(%rip),%rsi
call   1070 <readfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    13ec <getbattery+0x29c>
mov    -0x10(%rbp),%rdi
lea    0xd63(%rip),%rsi
call   1070 <readfile@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd5b(%rip),%rsi
lea    -0x40(%rbp),%rdx
mov    $0x0,%al
call   1060 <sscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
lea    0xd40(%rip),%rsi
call   1070 <readfile@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd28(%rip),%rsi
lea    -0x48(%rbp),%rdx
mov    $0x0,%al
call   1060 <sscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x40(%rbp),%xmm0
movsd  0xc99(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdl -0x28(%rbp),%xmm1
movsd  0xc88(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x28(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xc6c(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
movsd  0xc5b(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x24(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xc3f(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x48(%rbp),%xmm1
movsd  0xc2e(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    140b <getbattery+0x2bb>
mov    -0x18(%rbp),%rdi
lea    0xc7f(%rip),%rsi
lea    -0x38(%rbp),%rdx
mov    $0x0,%al
call   1060 <sscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x28(%rbp)
jl     141f <getbattery+0x2cf>
cmpl   $0x0,-0x24(%rbp)
jge    1436 <getbattery+0x2e6>
lea    0xc60(%rip),%rdi
mov    $0x0,%al
call   1050 <smprintf@plt>
mov    %rax,-0x8(%rbp)
jmp    15fc <getbattery+0x4ac>
mov    -0x10(%rbp),%rdi
lea    0xc4d(%rip),%rsi
call   1070 <readfile@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xc40(%rip),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    1489 <getbattery+0x339>
movb   $0x5e,-0x49(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm0
cvtsi2sdl -0x28(%rbp),%xmm1
subsd  %xmm1,%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    14db <getbattery+0x38b>
mov    -0x18(%rbp),%rdi
lea    0xc0a(%rip),%rsi
mov    $0xb,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    14bf <getbattery+0x36f>
movb   $0x76,-0x49(%rbp)
cvtsi2sdl -0x28(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    14d6 <getbattery+0x386>
movb   $0x3d,-0x49(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
lea    0xbdc(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    14db <getbattery+0x38b>
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    14f8 <getbattery+0x3a8>
jp     14f8 <getbattery+0x3a8>
jmp    15c4 <getbattery+0x474>
movsd  0xb10(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x50(%rbp)
mov    -0x5c(%rbp),%eax
imul   $0xe10,-0x50(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x58(%rbp)
imul   $0x3c,-0x58(%rbp),%ecx
mov    -0x54(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jl     1561 <getbattery+0x411>
cmpl   $0x0,-0x58(%rbp)
jl     1561 <getbattery+0x411>
cmpl   $0x0,-0x50(%rbp)
jge    1578 <getbattery+0x428>
lea    0xb42(%rip),%rdi
mov    $0x0,%al
call   1050 <smprintf@plt>
mov    %rax,-0x20(%rbp)
jmp    15bf <getbattery+0x46f>
cmpl   $0x0,-0x50(%rbp)
je     15a2 <getbattery+0x452>
mov    -0x50(%rbp),%esi
mov    -0x58(%rbp),%edx
mov    -0x54(%rbp),%ecx
lea    0xb1d(%rip),%rdi
mov    $0x0,%al
call   1050 <smprintf@plt>
mov    %rax,-0x20(%rbp)
jmp    15ba <getbattery+0x46a>
mov    -0x58(%rbp),%esi
mov    -0x54(%rbp),%edx
lea    0xb10(%rip),%rdi
mov    $0x0,%al
call   1050 <smprintf@plt>
mov    %rax,-0x20(%rbp)
jmp    15bf <getbattery+0x46f>
jmp    15c4 <getbattery+0x474>
movsbl -0x49(%rbp),%esi
cvtsi2ssl -0x28(%rbp),%xmm0
cvtsi2ssl -0x24(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  0xa3a(%rip),%xmm1
mulss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x20(%rbp),%rdx
lea    0xad9(%rip),%rdi
mov    $0x1,%al
call   1050 <smprintf@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getbattery>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r14
movl   $0xffffffff,0x4(%rsp)
ff
movl   $0xffffffff,(%rsp)
movabs $0xbff0000000000000,%rax
mov    %rax,0x8(%rsp)
lea    0xea7(%rip),%rsi
call   1070 <readfile@plt>
test   %rax,%rax
je     1288 <getbattery+0x138>
mov    (%rax),%bl
mov    %rax,%rdi
call   1030 <free@plt>
cmp    $0x31,%bl
jne    1288 <getbattery+0x138>
lea    0xe87(%rip),%rsi
mov    %r14,%rdi
call   1070 <readfile@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11d4 <getbattery+0x84>
lea    0xe83(%rip),%rsi
mov    %r14,%rdi
call   1070 <readfile@plt>
mov    %rax,%rbx
test   %rax,%rax
je     13c6 <getbattery+0x276>
lea    0xe74(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <sscanf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe59(%rip),%rsi
mov    %r14,%rdi
call   1070 <readfile@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1224 <getbattery+0xd4>
lea    0xe4d(%rip),%rsi
mov    %r14,%rdi
call   1070 <readfile@plt>
mov    %rax,%rbx
test   %rax,%rax
je     13f4 <getbattery+0x2a4>
lea    0xe24(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <sscanf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe21(%rip),%rsi
mov    %r14,%rdi
call   1070 <readfile@plt>
test   %rax,%rax
je     129f <getbattery+0x14f>
mov    %rax,%rbx
lea    0xe20(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1060 <sscanf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
movss  (%rsp),%xmm1
movss  0x4(%rsp),%xmm0
unpcklps %xmm1,%xmm0
jmp    135a <getbattery+0x20a>
lea    0xd95(%rip),%rdi
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <smprintf@plt>
lea    0xdcc(%rip),%rsi
mov    %r14,%rdi
call   1070 <readfile@plt>
mov    %rax,%rbx
lea    0xdc6(%rip),%r15
lea    0x18(%rsp),%rdx
mov    %rax,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <sscanf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xda9(%rip),%rsi
mov    %r14,%rdi
call   1070 <readfile@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <sscanf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
movsd  0x18(%rsp),%xmm0
movsd  0xcf4(%rip),%xmm1
movss  (%rsp),%xmm2
movss  0x4(%rsp),%xmm3
unpcklps %xmm2,%xmm3
cvtdq2pd %xmm3,%xmm2
divpd  0xcea(%rip),%xmm2
divsd  %xmm1,%xmm0
movsd  0x10(%rsp),%xmm3
divsd  %xmm1,%xmm3
mulsd  %xmm0,%xmm3
unpcklpd %xmm0,%xmm0
mulpd  %xmm2,%xmm0
cvttpd2dq %xmm0,%xmm0
pshufd $0x55,%xmm0,%xmm1
movd   %xmm1,(%rsp)
movd   %xmm0,0x4(%rsp)
movsd  %xmm3,0x8(%rsp)
pshufd $0x50,%xmm0,%xmm0
movmskpd %xmm0,%eax
test   %eax,%eax
je     1373 <getbattery+0x223>
lea    0xd20(%rip),%rdi
jmp    13fb <getbattery+0x2ab>
lea    0xd1c(%rip),%rsi
mov    %r14,%rdi
call   1070 <readfile@plt>
mov    %rax,%rbx
lea    0xd11(%rip),%rsi
mov    %rax,%rdi
mov    $0x8,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     13d2 <getbattery+0x282>
lea    0xd02(%rip),%rsi
mov    %rbx,%rdi
mov    $0xb,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     1407 <getbattery+0x2b7>
lea    0xcfa(%rip),%rdx
mov    $0x3d,%ebx
jmp    14cb <getbattery+0x37b>
lea    0xce9(%rip),%rdi
jmp    128f <getbattery+0x13f>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x4(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdl (%rsp),%xmm1
subsd  %xmm1,%xmm0
divsd  0x8(%rsp),%xmm0
mov    $0x5e,%ebx
jmp    141a <getbattery+0x2ca>
lea    0xcbb(%rip),%rdi
xor    %eax,%eax
call   1050 <smprintf@plt>
jmp    14fc <getbattery+0x3ac>
xorps  %xmm0,%xmm0
cvtsi2sdl (%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
mov    $0x76,%ebx
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1426 <getbattery+0x2d6>
jnp    14a1 <getbattery+0x351>
mulsd  0xbda(%rip),%xmm0
cvttsd2si %xmm0,%eax
movslq %eax,%rcx
imul   $0xffffffff91a2b3c5,%rcx,%rsi
shr    $0x20,%rsi
add    %eax,%esi
mov    %esi,%ecx
shr    $0x1f,%ecx
sar    $0xb,%esi
add    %ecx,%esi
imul   $0xfffff1f0,%esi,%edi
add    %eax,%edi
cmp    $0xffffffc5,%edi
jl     14aa <getbattery+0x35a>
movslq %edi,%rcx
imul   $0xffffffff88888889,%rcx,%rdx
shr    $0x20,%rdx
add    %edi,%edx
mov    %edx,%ecx
shr    $0x1f,%ecx
sar    $0x5,%edx
add    %ecx,%edx
imul   $0xffffffc4,%edx,%ecx
add    %edi,%ecx
js     14aa <getbattery+0x35a>
cmp    $0xfffff1f0,%eax
jle    14aa <getbattery+0x35a>
add    $0xe0f,%eax
cmp    $0x1c1f,%eax
jae    14ba <getbattery+0x36a>
lea    0xc33(%rip),%rdi
mov    %edx,%esi
mov    %ecx,%edx
xor    %eax,%eax
call   1050 <smprintf@plt>
jmp    14c8 <getbattery+0x378>
lea    0xc0e(%rip),%rdx
jmp    14cb <getbattery+0x37b>
lea    0xc01(%rip),%rdi
xor    %eax,%eax
call   1050 <smprintf@plt>
jmp    14c8 <getbattery+0x378>
lea    0xbf6(%rip),%rdi
xor    %eax,%eax
call   1050 <smprintf@plt>
mov    %rax,%rdx
xorps  %xmm0,%xmm0
cvtsi2ssl (%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2ssl 0x4(%rsp),%xmm1
divss  %xmm1,%xmm0
mulss  0xb38(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xbdf(%rip),%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1050 <smprintf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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