#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 /*<<< orphan*/ time_t;
struct tm {
  int dummy;
};
typedef int /*<<< orphan*/ b;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ SIGPIPE;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, double, double,
                           double, float);
int /*<<< orphan*/ getloadavg(double *, int);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  FILE *acpi;
  char b[34];
  time_t epochtime;
  struct tm *realtime;
  int last_full, remaining;
  double load[3];
  signal(SIGPIPE, SIG_IGN);
  if ((acpi = fopen("/proc/acpi/battery/BAT0/info", "r")) == NULL) {
    perror("couldn't open "
           "/proc/acpi/battery/BAT0/info");
    exit(-1);
  }
  while (fgets(b, sizeof(b), acpi))
    if (sscanf(b, "last full capacity: %d", &last_full) == 1)
      break;
  fclose(acpi);
  for (;;) {
    getloadavg(load, 3);
    if ((acpi = fopen("/proc/acpi/battery/BAT0/state", "r")) == NULL) {
      perror("couldn't open "
             "/proc/acpi/battery/BAT0/state");
      exit(-1);
    }
    while (fgets(b, sizeof(b), acpi))
      if (sscanf(b, "remaining capacity: %d", &remaining) == 1)
        break;
    fclose(acpi);
    epochtime = time(NULL);
    realtime = localtime(&epochtime);
    strftime(b, sizeof(b), "%a %b %d %H:%M:%S", realtime);
    fprintf(stdout, "%s | %.2f %.2f %.2f | %.1f%% \n", b, load[0], load[1],
            load[2], (float)(remaining * 100) / last_full);
    fflush(stdout);
    sleep(2);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
call   1070 <signal@plt>
lea    0xe03(%rip),%rdi
lea    0xdec(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    123d <main+0x5d>
lea    0xdd4(%rip),%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
jmp    1242 <main+0x62>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x22,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1285 <main+0xa5>
lea    -0x40(%rbp),%rdi
lea    0xdc4(%rip),%rsi
lea    -0x54(%rbp),%rdx
call   10b0 <sscanf@plt>
cmp    $0x1,%eax
jne    1280 <main+0xa0>
jmp    1285 <main+0xa5>
jmp    1242 <main+0x62>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x70(%rbp),%rdi
mov    $0x3,%esi
call   1050 <getloadavg@plt>
lea    0xdaf(%rip),%rdi
lea    0xd56(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    12d3 <main+0xf3>
lea    0xd80(%rip),%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
jmp    12d8 <main+0xf8>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x22,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     131b <main+0x13b>
lea    -0x40(%rbp),%rdi
lea    0xd71(%rip),%rsi
lea    -0x58(%rbp),%rdx
call   10b0 <sscanf@plt>
cmp    $0x1,%eax
jne    1316 <main+0x136>
jmp    131b <main+0x13b>
jmp    12d8 <main+0xf8>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,-0x44(%rbp)
lea    -0x44(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x50(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%rcx
mov    $0x22,%esi
lea    0xd36(%rip),%rdx
call   10c0 <strftime@plt>
mov    0x2c73(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rdx
movsd  -0x70(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm2
imul   $0x64,-0x58(%rbp),%eax
cvtsi2ss %eax,%xmm3
cvtsi2ssl -0x54(%rbp),%xmm4
divss  %xmm4,%xmm3
lea    0xd0f(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2c3a(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
mov    $0x2,%edi
call   1100 <sleep@plt>
jmp    128e <main+0xae>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
call   1070 <signal@plt>
lea    0xe04(%rip),%rdi
lea    0xded(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
jne    1226 <main+0x46>
lea    0xdde(%rip),%rdi
jmp    129e <main+0xbe>
mov    %rax,%rbx
lea    0x30(%rsp),%rbp
lea    0xdf8(%rip),%r14
lea    0x8(%rsp),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x22,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1268 <main+0x88>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   10b0 <sscanf@plt>
cmp    $0x1,%eax
jne    1240 <main+0x60>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0x10(%rsp),%rdi
mov    $0x3,%esi
call   1050 <getloadavg@plt>
lea    0xdcc(%rip),%rdi
lea    0xd73(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
jne    12ad <main+0xcd>
lea    0xda6(%rip),%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    %rax,%r13
lea    0x30(%rsp),%rbx
mov    0x2d14(%rip),%rbp
lea    0xd3d(%rip),%r14
lea    0xda6(%rip),%r15
lea    0x4(%rsp),%r12
jmp    1390 <main+0x1b0>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rbx,%rdi
mov    $0x22,%esi
lea    0xd87(%rip),%rdx
mov    %rax,%rcx
call   10c0 <strftime@plt>
mov    0x0(%rbp),%edi
movsd  0x10(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
imul   $0x64,0x4(%rsp),%eax
movsd  0x20(%rsp),%xmm2
xorps  %xmm3,%xmm3
cvtsi2ss %eax,%xmm3
xorps  %xmm4,%xmm4
cvtsi2ssl 0x8(%rsp),%xmm4
divss  %xmm4,%xmm3
lea    0xd5c(%rip),%rsi
mov    %rbx,%rdx
call   1080 <fprintf@plt>
mov    0x0(%rbp),%edi
call   10a0 <fflush@plt>
mov    $0x2,%edi
call   1100 <sleep@plt>
lea    0x10(%rsp),%rdi
mov    $0x3,%esi
call   1050 <getloadavg@plt>
lea    0xce5(%rip),%rdi
mov    %r14,%rsi
call   10d0 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
je     1297 <main+0xb7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x22,%esi
mov    %r13,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12d4 <main+0xf4>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   10b0 <sscanf@plt>
cmp    $0x1,%eax
jne    1390 <main+0x1b0>
jmp    12d4 <main+0xf4>

LLVM IR (-O0):
%struct.tm = type { i32 }
@SIGPIPE = global i32 0
@SIG_IGN = global i32 0
@.str = [29 x i8] c"/proc/acpi/battery/BAT0/info\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [43 x i8] c"couldn't open /proc/acpi/battery/BAT0/info\00"
@.str.3 = [23 x i8] c"last full capacity: %d\00"
@.str.4 = [30 x i8] c"/proc/acpi/battery/BAT0/state\00"
@.str.5 = [44 x i8] c"couldn't open /proc/acpi/battery/BAT0/state\00"
@.str.6 = [23 x i8] c"remaining capacity: %d\00"
@.str.7 = [18 x i8] c"%a %b %d %H:%M:%S\00"
@stdout = global i32 0
@.str.8 = [31 x i8] c"%s | %.2f %.2f %.2f | %.1f%% \0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [34 x i8]
%4 = alloca i32
%5 = alloca %struct.tm*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [3 x double]
store i32 0, i32* %1
%9 = load i32, i32* @SIGPIPE
%10 = load i32, i32* @SIG_IGN
%11 = call i32 @signal(i32 %9, i32 %10)
%12 = call i32* @fopen(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %2
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %0
br label %18
18: ; preds = %28, %17
%19 = getelementptr inbounds [34 x i8], [34 x i8]* %3, i64 0, i64 0
%20 = load i32*, i32** %2
%21 = call i64 @fgets(i8* %19, i32 34, i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = getelementptr inbounds [34 x i8], [34 x i8]* %3, i64 0, i64 0
%25 = call i32 @sscanf(i8* %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32* %6)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %28
27: ; preds = %23
br label %29
28: ; preds = %23
br label %18
29: ; preds = %27, %18
%30 = load i32*, i32** %2
%31 = call i32 @fclose(i32* %30)
br label %32
32: ; preds = %52, %29
%33 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%34 = call i32 @getloadavg(double* %33, i32 3)
%35 = call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %35, i32** %2
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
%39 = call i32 @exit(i32 -1)
unreachable
40: ; preds = %32
br label %41
41: ; preds = %51, %40
%42 = getelementptr inbounds [34 x i8], [34 x i8]* %3, i64 0, i64 0
%43 = load i32*, i32** %2
%44 = call i64 @fgets(i8* %42, i32 34, i32* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %41
%47 = getelementptr inbounds [34 x i8], [34 x i8]* %3, i64 0, i64 0
%48 = call i32 @sscanf(i8* %47, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32* %7)
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %51
50: ; preds = %46
br label %52
51: ; preds = %46
br label %41
52: ; preds = %50, %41
%53 = load i32*, i32** %2
%54 = call i32 @fclose(i32* %53)
%55 = call i32 @time(i32* null)
store i32 %55, i32* %4
%56 = call %struct.tm* @localtime(i32* %4)
store %struct.tm* %56, %struct.tm** %5
%57 = getelementptr inbounds [34 x i8], [34 x i8]* %3, i64 0, i64 0
%58 = load %struct.tm*, %struct.tm** %5
%59 = call i32 @strftime(i8* %57, i32 34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), %struct.tm* %58)
%60 = load i32, i32* @stdout
%61 = getelementptr inbounds [34 x i8], [34 x i8]* %3, i64 0, i64 0
%62 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%63 = load double, double* %62
%64 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 1
%65 = load double, double* %64
%66 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 2
%67 = load double, double* %66
%68 = load i32, i32* %7
%69 = mul nsw i32 %68, 100
%70 = sitofp i32 %69 to float
%71 = load i32, i32* %6
%72 = sitofp i32 %71 to float
%73 = fdiv float %70, %72
%74 = call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %61, double %63, double %65, double %67, float %73)
%75 = load i32, i32* @stdout
%76 = call i32 @fflush(i32 %75)
%77 = call i32 @sleep(i32 2)
br label %32
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@SIGPIPE = global i32 0
@SIG_IGN = global i32 0
@.str = [29 x i8] c"/proc/acpi/battery/BAT0/info\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [43 x i8] c"couldn't open /proc/acpi/battery/BAT0/info\00"
@.str.3 = [23 x i8] c"last full capacity: %d\00"
@.str.4 = [30 x i8] c"/proc/acpi/battery/BAT0/state\00"
@.str.5 = [44 x i8] c"couldn't open /proc/acpi/battery/BAT0/state\00"
@.str.6 = [23 x i8] c"remaining capacity: %d\00"
@.str.7 = [18 x i8] c"%a %b %d %H:%M:%S\00"
@stdout = global i32 0
@.str.8 = [31 x i8] c"%s | %.2f %.2f %.2f | %.1f%% \0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [34 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [3 x double]
%6 = getelementptr inbounds [34 x i8], [34 x i8]* %1, i64 0, i64 0
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast [3 x double]* %5 to i8*
%11 = load i32, i32* @SIGPIPE
%12 = load i32, i32* @SIG_IGN
%13 = tail call i32 @signal(i32 %11, i32 %12)
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = tail call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %0, %22
%20 = call i64 @fgets(i8* %6, i32 34, i32* %14)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %19
25: ; preds = %22, %19
%26 = call i32 @fclose(i32* %14)
%27 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 0
%28 = call i32 @getloadavg(double* %27, i32 3)
%29 = call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %36, label %31
31: ; preds = %25
%32 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 1
%33 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 2
br label %34
34: ; preds = %31, %45
%35 = phi i32* [ %29, %31 ], [ %65, %45 ]
br label %39
36: ; preds = %45, %25
%37 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
%38 = call i32 @exit(i32 -1)
unreachable
39: ; preds = %34, %42
%40 = call i64 @fgets(i8* %6, i32 34, i32* %35)
%41 = icmp eq i64 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32* %4)
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %39
45: ; preds = %42, %39
%46 = call i32 @fclose(i32* %35)
%47 = call i32 @time(i32* null)
store i32 %47, i32* %2
%48 = call %struct.tm* @localtime(i32* %2)
%49 = call i32 @strftime(i8* %6, i32 34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), %struct.tm* %48)
%50 = load i32, i32* @stdout
%51 = load double, double* %27
%52 = load double, double* %32
%53 = load double, double* %33
%54 = load i32, i32* %4
%55 = mul nsw i32 %54, 100
%56 = sitofp i32 %55 to float
%57 = load i32, i32* %3
%58 = sitofp i32 %57 to float
%59 = fdiv float %56, %58
%60 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %6, double %51, double %52, double %53, float %59)
%61 = load i32, i32* @stdout
%62 = call i32 @fflush(i32 %61)
%63 = call i32 @sleep(i32 2)
%64 = call i32 @getloadavg(double* %27, i32 3)
%65 = call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%66 = icmp eq i32* %65, null
br i1 %66, label %36, label %34
}