#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 */
char get_status();
long read_long(char *);
char *smprintf(char *, char const *, char, long);
char *getbattery() {
  long lnum1, lnum2, percent;
  const char *color;
  char s;
  lnum1 = read_long("/sys/class/power_supply/BAT0/charge_now");
  lnum2 = read_long("/sys/class/power_supply/BAT0/charge_full");
  s = get_status();
  percent = (lnum1 / (lnum2 / 100));
  if (percent <= 20)
    color = "#ff0000";
  else
    color = "#00ff00";
  return smprintf("<span color=\"%s\">%c%ld%%</span>", color, s, percent);
}


x86 assembly (clang, -O0):
<getbattery>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xec1(%rip),%rdi
call   1050 <read_long@plt>
mov    %rax,-0x8(%rbp)
lea    0xed9(%rip),%rdi
call   1050 <read_long@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <get_status@plt>
mov    %al,-0x21(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x64,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
cmpq   $0x14,-0x18(%rbp)
jg     11a3 <getbattery+0x73>
lea    0xeb7(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11ae <getbattery+0x7e>
lea    0xeaf(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x21(%rbp),%al
mov    -0x18(%rbp),%rcx
lea    0xea1(%rip),%rdi
movsbl %al,%edx
call   1030 <smprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getbattery>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rdi
call   1050 <read_long@plt>
mov    %rax,%r14
lea    0xede(%rip),%rdi
call   1050 <read_long@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <get_status@plt>
mov    %eax,%ecx
movabs $0xa3d70a3d70a3d70b,%rdx
0a d7 a3
mov    %rbx,%rax
imul   %rdx
mov    %rdx,%rsi
add    %rbx,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x6,%rsi
add    %rax,%rsi
mov    %r14,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     1195 <getbattery+0x65>
mov    %r14,%rax
cqto
idiv   %rsi
jmp    119c <getbattery+0x6c>
mov    %r14d,%eax
xor    %edx,%edx
div    %esi
cmp    $0x15,%rax
lea    0xeaa(%rip),%rdx
lea    0xeab(%rip),%rsi
cmovl  %rdx,%rsi
movsbl %cl,%edx
lea    0xea5(%rip),%rdi
mov    %rax,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <smprintf@plt>

LLVM IR (-O0):
@.str = [40 x i8] c"/sys/class/power_supply/BAT0/charge_now\00"
@.str.1 = [41 x i8] c"/sys/class/power_supply/BAT0/charge_full\00"
@.str.2 = [8 x i8] c"#ff0000\00"
@.str.3 = [8 x i8] c"ff00\00"
@.str.4 = [32 x i8] c"<span color=\22%s\22>%c%ld%%</span>\00"
define i8* @getbattery() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8
%6 = call i64 @read_long(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i64 %6, i64* %1
%7 = call i64 @read_long(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
store i64 %7, i64* %2
%8 = call signext i8 (...) @get_status()
store i8 %8, i8* %5
%9 = load i64, i64* %1
%10 = load i64, i64* %2
%11 = sdiv i64 %10, 100
%12 = sdiv i64 %9, %11
store i64 %12, i64* %3
%13 = load i64, i64* %3
%14 = icmp sle i64 %13, 20
br i1 %14, label %15, label %16
15: ; preds = %0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %4
br label %17
16: ; preds = %0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %4
br label %17
17: ; preds = %16, %15
%18 = load i8*, i8** %4
%19 = load i8, i8* %5
%20 = load i64, i64* %3
%21 = call i8* @smprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %18, i8 signext %19, i64 %20)
ret i8* %21
}

LLVM IR (-O2):
@.str = [40 x i8] c"/sys/class/power_supply/BAT0/charge_now\00"
@.str.1 = [41 x i8] c"/sys/class/power_supply/BAT0/charge_full\00"
@.str.2 = [8 x i8] c"#ff0000\00"
@.str.3 = [8 x i8] c"ff00\00"
@.str.4 = [32 x i8] c"<span color=\22%s\22>%c%ld%%</span>\00"
define i8* @getbattery() {
%1 = tail call i64 @read_long(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%2 = tail call i64 @read_long(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call signext i8 (...) @get_status()
%4 = sdiv i64 %2, 100
%5 = sdiv i64 %1, %4
%6 = icmp slt i64 %5, 21
%7 = select i1 %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0)
%8 = tail call i8* @smprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %7, i8 signext %3, i64 %5)
ret i8* %8
}