#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*/ line;
typedef int /*<<< orphan*/ file_name;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ show_pmu_power_line(unsigned int, unsigned int, unsigned int,
                                       int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ sscanf(scalar_t__, char *, ...);
scalar_t__ strchr(char *, char);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
int print_battery_proc_pmu(void) {
  char line[80];
  int i;
  int power_present = 0;
  int num_batteries = 0;
  unsigned charge_mAh = 0, max_charge_mAh = 0, voltage_mV = 0;
  int discharge_mA = 0;
  FILE *fd;
  fd = fopen("/proc/pmu/info", "r");
  if (fd == NULL)
    return 0;
  while (fgets(line, sizeof(line), fd) != NULL) {
    if (strncmp("AC Power", line, strlen("AC Power")) == 0)
      sscanf(strchr(line, ':') + 2, "%d", &power_present);
    else if (strncmp("Battery count", line, strlen("Battery count")) == 0)
      sscanf(strchr(line, ':') + 2, "%d", &num_batteries);
  }
  fclose(fd);
  for (i = 0; i < num_batteries; ++i) {
    char file_name[20];
    int flags = 0;
    unsigned this_charge_mAh = 0, this_max_charge_mAh = 0;
    unsigned this_voltage_mV = 0, this_discharge_mA = 0;
    snprintf(file_name, sizeof(file_name), "/proc/pmu/battery_%d", i);
    fd = fopen(file_name, "r");
    if (fd == NULL)
      continue;
    while (fgets(line, sizeof(line), fd) != NULL) {
      if (strncmp("flags", line, strlen("flags")) == 0)
        sscanf(strchr(line, ':') + 2, "%x", &flags);
      else if (strncmp("charge", line, strlen("charge")) == 0)
        sscanf(strchr(line, ':') + 2, "%d", &this_charge_mAh);
      else if (strncmp("max_charge", line, strlen("max_charge")) == 0)
        sscanf(strchr(line, ':') + 2, "%d", &this_max_charge_mAh);
      else if (strncmp("voltage", line, strlen("voltage")) == 0)
        sscanf(strchr(line, ':') + 2, "%d", &this_voltage_mV);
      else if (strncmp("current", line, strlen("current")) == 0)
        sscanf(strchr(line, ':') + 2, "%d", &this_discharge_mA);
    }
    fclose(fd);
    if (!(flags & 0x1))
      continue;
    charge_mAh += this_charge_mAh;
    max_charge_mAh += this_max_charge_mAh;
    voltage_mV += this_voltage_mV;
    discharge_mA += this_discharge_mA;
  }
  show_pmu_power_line(voltage_mV, charge_mAh, max_charge_mAh, discharge_mA);
  return 1;
}


x86 assembly (clang, -O0):
<print_battery_proc_pmu>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
movl   $0x0,-0x70(%rbp)
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
lea    0xe34(%rip),%rdi
lea    0xe43(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    11f9 <print_battery_proc_pmu+0x69>
movl   $0x0,-0x4(%rbp)
jmp    1629 <print_battery_proc_pmu+0x499>
jmp    11fe <print_battery_proc_pmu+0x6e>
lea    -0x60(%rbp),%rdi
mov    -0x88(%rbp),%rdx
mov    $0x50,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     12e6 <print_battery_proc_pmu+0x156>
lea    -0x60(%rbp),%rax
mov    %rax,-0xc0(%rbp)
lea    0xde0(%rip),%rdi
call   1050 <strlen@plt>
mov    -0xc0(%rbp),%rsi
mov    %eax,%edx
lea    0xdcb(%rip),%rdi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    127f <print_battery_proc_pmu+0xef>
lea    -0x60(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,%rdi
add    $0x2,%rdi
lea    0xdc9(%rip),%rsi
lea    -0x68(%rbp),%rdx
mov    $0x0,%al
call   1090 <sscanf@plt>
jmp    12e1 <print_battery_proc_pmu+0x151>
lea    -0x60(%rbp),%rax
mov    %rax,-0xc8(%rbp)
lea    0xd87(%rip),%rdi
call   1050 <strlen@plt>
mov    -0xc8(%rbp),%rsi
mov    %eax,%edx
lea    0xd72(%rip),%rdi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12dc <print_battery_proc_pmu+0x14c>
lea    -0x60(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,%rdi
add    $0x2,%rdi
lea    0xd67(%rip),%rsi
lea    -0x6c(%rbp),%rdx
mov    $0x0,%al
call   1090 <sscanf@plt>
jmp    12e1 <print_battery_proc_pmu+0x151>
jmp    11fe <print_battery_proc_pmu+0x6e>
mov    -0x88(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x6c(%rbp),%eax
jge    1611 <print_battery_proc_pmu+0x481>
movl   $0x0,-0xa4(%rbp)
movl   $0x0,-0xa8(%rbp)
movl   $0x0,-0xac(%rbp)
movl   $0x0,-0xb0(%rbp)
movl   $0x0,-0xb4(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x64(%rbp),%ecx
mov    $0x14,%esi
lea    0xcd9(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xcb6(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    137f <print_battery_proc_pmu+0x1ef>
jmp    1603 <print_battery_proc_pmu+0x473>
jmp    1384 <print_battery_proc_pmu+0x1f4>
lea    -0x60(%rbp),%rdi
mov    -0x88(%rbp),%rdx
mov    $0x50,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     15b0 <print_battery_proc_pmu+0x420>
lea    -0x60(%rbp),%rax
mov    %rax,-0xd0(%rbp)
lea    0xc86(%rip),%rdi
call   1050 <strlen@plt>
mov    -0xd0(%rbp),%rsi
mov    %eax,%edx
lea    0xc71(%rip),%rdi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1408 <print_battery_proc_pmu+0x278>
lea    -0x60(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,%rdi
add    $0x2,%rdi
lea    0xc4c(%rip),%rsi
lea    -0xa4(%rbp),%rdx
mov    $0x0,%al
call   1090 <sscanf@plt>
jmp    15ab <print_battery_proc_pmu+0x41b>
lea    -0x60(%rbp),%rax
mov    %rax,-0xd8(%rbp)
lea    0xc2e(%rip),%rdi
call   1050 <strlen@plt>
mov    -0xd8(%rbp),%rsi
mov    %eax,%edx
lea    0xc19(%rip),%rdi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    146d <print_battery_proc_pmu+0x2dd>
lea    -0x60(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,%rdi
add    $0x2,%rdi
lea    0xbde(%rip),%rsi
lea    -0xa8(%rbp),%rdx
mov    $0x0,%al
call   1090 <sscanf@plt>
jmp    15a6 <print_battery_proc_pmu+0x416>
lea    -0x60(%rbp),%rax
mov    %rax,-0xe0(%rbp)
lea    0xbc5(%rip),%rdi
call   1050 <strlen@plt>
mov    -0xe0(%rbp),%rsi
mov    %eax,%edx
lea    0xbb0(%rip),%rdi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    14d2 <print_battery_proc_pmu+0x342>
lea    -0x60(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,%rdi
add    $0x2,%rdi
lea    0xb79(%rip),%rsi
lea    -0xac(%rbp),%rdx
mov    $0x0,%al
call   1090 <sscanf@plt>
jmp    15a1 <print_battery_proc_pmu+0x411>
lea    -0x60(%rbp),%rax
mov    %rax,-0xe8(%rbp)
lea    0xb6b(%rip),%rdi
call   1050 <strlen@plt>
mov    -0xe8(%rbp),%rsi
mov    %eax,%edx
lea    0xb56(%rip),%rdi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1537 <print_battery_proc_pmu+0x3a7>
lea    -0x60(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,%rdi
add    $0x2,%rdi
lea    0xb14(%rip),%rsi
lea    -0xb0(%rbp),%rdx
mov    $0x0,%al
call   1090 <sscanf@plt>
jmp    159c <print_battery_proc_pmu+0x40c>
lea    -0x60(%rbp),%rax
mov    %rax,-0xf0(%rbp)
lea    0xb0e(%rip),%rdi
call   1050 <strlen@plt>
mov    -0xf0(%rbp),%rsi
mov    %eax,%edx
lea    0xaf9(%rip),%rdi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1597 <print_battery_proc_pmu+0x407>
lea    -0x60(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,%rdi
add    $0x2,%rdi
lea    0xaaf(%rip),%rsi
lea    -0xb4(%rbp),%rdx
mov    $0x0,%al
call   1090 <sscanf@plt>
jmp    159c <print_battery_proc_pmu+0x40c>
jmp    15a1 <print_battery_proc_pmu+0x411>
jmp    15a6 <print_battery_proc_pmu+0x416>
jmp    15ab <print_battery_proc_pmu+0x41b>
jmp    1384 <print_battery_proc_pmu+0x1f4>
mov    -0x88(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0xa4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    15d3 <print_battery_proc_pmu+0x443>
jmp    1603 <print_battery_proc_pmu+0x473>
mov    -0xa8(%rbp),%eax
add    -0x70(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    -0xac(%rbp),%eax
add    -0x74(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0xb0(%rbp),%eax
add    -0x78(%rbp),%eax
mov    %eax,-0x78(%rbp)
mov    -0xb4(%rbp),%eax
add    -0x7c(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    12f9 <print_battery_proc_pmu+0x169>
mov    -0x78(%rbp),%edi
mov    -0x70(%rbp),%esi
mov    -0x74(%rbp),%edx
mov    -0x7c(%rbp),%ecx
call   10b0 <show_pmu_power_line@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_battery_proc_pmu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
movl   $0x0,0x2c(%rsp)
movl   $0x0,0x10(%rsp)
lea    0xe48(%rip),%rdi
lea    0xe57(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1526 <print_battery_proc_pmu+0x396>
mov    %rax,%r13
lea    0x50(%rsp),%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1285 <print_battery_proc_pmu+0xf5>
lea    0xe1d(%rip),%r14
lea    0x50(%rsp),%rbp
lea    0x2c(%rsp),%r15
lea    0xe15(%rip),%r12
jmp    1247 <print_battery_proc_pmu+0xb7>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
lea    0x2(%rax),%rdi
lea    0xe10(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1090 <sscanf@plt>
mov    %rbp,%rdi
mov    $0x50,%esi
mov    %r13,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1285 <print_battery_proc_pmu+0xf5>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
mov    %r15,%rbx
test   %rax,%rax
je     1210 <print_battery_proc_pmu+0x80>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
lea    0x10(%rsp),%rbx
test   %rax,%rax
jne    1232 <print_battery_proc_pmu+0xa2>
jmp    1210 <print_battery_proc_pmu+0x80>
mov    %r13,%rdi
call   1040 <fclose@plt>
cmpl   $0x0,0x10(%rsp)
jle    152a <print_battery_proc_pmu+0x39a>
lea    0x50(%rsp),%r15
lea    0xd97(%rip),%r13
movl   $0x0,0xc(%rsp)
movl   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
xor    %ebx,%ebx
jmp    12e1 <print_battery_proc_pmu+0x151>
nopw   0x0(%rax,%rax,1)
mov    0x14(%rsp),%ebx
add    $0x1,%ebx
cmp    0x10(%rsp),%ebx
jge    1549 <print_battery_proc_pmu+0x3b9>
movl   $0x0,0x28(%rsp)
movl   $0x0,0x24(%rsp)
movl   $0x0,0x20(%rsp)
movl   $0x0,0x1c(%rsp)
movl   $0x0,0x18(%rsp)
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x14,%esi
lea    0xd09(%rip),%rdx
mov    %ebx,%ecx
call   1070 <snprintf@plt>
mov    %rbp,%rdi
lea    0xce8(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12d4 <print_battery_proc_pmu+0x144>
mov    %rax,%r12
mov    %ebx,0x14(%rsp)
mov    %r15,%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
lea    0xcef(%rip),%rbx
jne    13ed <print_battery_proc_pmu+0x25d>
mov    %r12,%rdi
call   1040 <fclose@plt>
testb  $0x1,0x28(%rsp)
je     12d0 <print_battery_proc_pmu+0x140>
mov    0x4(%rsp),%eax
add    0x24(%rsp),%eax
mov    %eax,0x4(%rsp)
mov    0x8(%rsp),%eax
add    0x20(%rsp),%eax
mov    %eax,0x8(%rsp)
mov    (%rsp),%eax
add    0x1c(%rsp),%eax
mov    %eax,(%rsp)
mov    0xc(%rsp),%eax
add    0x18(%rsp),%eax
mov    %eax,0xc(%rsp)
jmp    12d0 <print_battery_proc_pmu+0x140>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
lea    0x2(%rax),%rdi
lea    0xc79(%rip),%rsi
lea    0x28(%rsp),%rdx
xor    %eax,%eax
call   1090 <sscanf@plt>
mov    %r15,%rdi
mov    $0x50,%esi
mov    %r12,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     135f <print_battery_proc_pmu+0x1cf>
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     13b0 <print_battery_proc_pmu+0x220>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     14c0 <print_battery_proc_pmu+0x330>
lea    0xc18(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     14e2 <print_battery_proc_pmu+0x352>
lea    0xbfe(%rip),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1504 <print_battery_proc_pmu+0x374>
lea    0xbe1(%rip),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    13d4 <print_battery_proc_pmu+0x244>
mov    %r15,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
lea    0x2(%rax),%rdi
lea    0xb8c(%rip),%rsi
lea    0x18(%rsp),%rdx
jmp    13cd <print_battery_proc_pmu+0x23d>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
lea    0x2(%rax),%rdi
lea    0xb60(%rip),%rsi
lea    0x24(%rsp),%rdx
jmp    13cd <print_battery_proc_pmu+0x23d>
mov    %r15,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
lea    0x2(%rax),%rdi
lea    0xb3e(%rip),%rsi
lea    0x20(%rsp),%rdx
jmp    13cd <print_battery_proc_pmu+0x23d>
mov    %r15,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
lea    0x2(%rax),%rdi
lea    0xb1c(%rip),%rsi
lea    0x1c(%rsp),%rdx
jmp    13cd <print_battery_proc_pmu+0x23d>
xor    %eax,%eax
jmp    1562 <print_battery_proc_pmu+0x3d2>
movl   $0x0,0x4(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,(%rsp)
movl   $0x0,0xc(%rsp)
mov    (%rsp),%edi
mov    0x4(%rsp),%esi
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
call   10b0 <show_pmu_power_line@plt>
mov    $0x1,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/proc/pmu/info\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"AC Power\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [14 x i8] c"Battery count\00"
@.str.5 = [21 x i8] c"/proc/pmu/battery_%d\00"
@.str.6 = [6 x i8] c"flags\00"
@.str.7 = [3 x i8] c"%x\00"
@.str.8 = [7 x i8] c"charge\00"
@.str.9 = [11 x i8] c"max_charge\00"
@.str.10 = [8 x i8] c"voltage\00"
@.str.11 = [8 x i8] c"current\00"
define i32 @print_battery_proc_pmu() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca [20 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%17 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %10
%18 = load i32*, i32** %10
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %0
store i32 0, i32* %1
br label %155
21: ; preds = %0
br label %22
22: ; preds = %48, %21
%23 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%24 = load i32*, i32** %10
%25 = call i32* @fgets(i8* %23, i32 80, i32* %24)
%26 = icmp ne i32* %25, null
br i1 %26, label %27, label %49
27: ; preds = %22
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%29 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%30 = call i64 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %28, i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%34 = call i64 @strchr(i8* %33, i8 signext 58)
%35 = add nsw i64 %34, 2
%36 = call i32 (i64, i8*, ...) @sscanf(i64 %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
br label %48
37: ; preds = %27
%38 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%39 = call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%40 = call i64 @strncmp(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %38, i32 %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %37
%43 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%44 = call i64 @strchr(i8* %43, i8 signext 58)
%45 = add nsw i64 %44, 2
%46 = call i32 (i64, i8*, ...) @sscanf(i64 %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
br label %47
47: ; preds = %42, %37
br label %48
48: ; preds = %47, %32
br label %22
49: ; preds = %22
%50 = load i32*, i32** %10
%51 = call i32 @fclose(i32* %50)
store i32 0, i32* %3
br label %52
52: ; preds = %146, %49
%53 = load i32, i32* %3
%54 = load i32, i32* %5
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %149
56: ; preds = %52
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
store i32 0, i32* %16
%57 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%58 = load i32, i32* %3
%59 = call i32 @snprintf(i8* %57, i32 20, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %58)
%60 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%61 = call i32* @fopen(i8* %60, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %61, i32** %10
%62 = load i32*, i32** %10
%63 = icmp eq i32* %62, null
br i1 %63, label %64, label %65
64: ; preds = %56
br label %146
65: ; preds = %56
br label %66
66: ; preds = %125, %65
%67 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%68 = load i32*, i32** %10
%69 = call i32* @fgets(i8* %67, i32 80, i32* %68)
%70 = icmp ne i32* %69, null
br i1 %70, label %71, label %126
71: ; preds = %66
%72 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%73 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%74 = call i64 @strncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %72, i32 %73)
%75 = icmp eq i64 %74, 0
br i1 %75, label %76, label %81
76: ; preds = %71
%77 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%78 = call i64 @strchr(i8* %77, i8 signext 58)
%79 = add nsw i64 %78, 2
%80 = call i32 (i64, i8*, ...) @sscanf(i64 %79, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %12)
br label %125
81: ; preds = %71
%82 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%83 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%84 = call i64 @strncmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* %82, i32 %83)
%85 = icmp eq i64 %84, 0
br i1 %85, label %86, label %91
86: ; preds = %81
%87 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%88 = call i64 @strchr(i8* %87, i8 signext 58)
%89 = add nsw i64 %88, 2
%90 = call i32 (i64, i8*, ...) @sscanf(i64 %89, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %13)
br label %124
91: ; preds = %81
%92 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%93 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%94 = call i64 @strncmp(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i8* %92, i32 %93)
%95 = icmp eq i64 %94, 0
br i1 %95, label %96, label %101
96: ; preds = %91
%97 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%98 = call i64 @strchr(i8* %97, i8 signext 58)
%99 = add nsw i64 %98, 2
%100 = call i32 (i64, i8*, ...) @sscanf(i64 %99, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %14)
br label %123
101: ; preds = %91
%102 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%103 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%104 = call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), i8* %102, i32 %103)
%105 = icmp eq i64 %104, 0
br i1 %105, label %106, label %111
106: ; preds = %101
%107 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%108 = call i64 @strchr(i8* %107, i8 signext 58)
%109 = add nsw i64 %108, 2
%110 = call i32 (i64, i8*, ...) @sscanf(i64 %109, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %15)
br label %122
111: ; preds = %101
%112 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%113 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
%114 = call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* %112, i32 %113)
%115 = icmp eq i64 %114, 0
br i1 %115, label %116, label %121
116: ; preds = %111
%117 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%118 = call i64 @strchr(i8* %117, i8 signext 58)
%119 = add nsw i64 %118, 2
%120 = call i32 (i64, i8*, ...) @sscanf(i64 %119, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %16)
br label %121
121: ; preds = %116, %111
br label %122
122: ; preds = %121, %106
br label %123
123: ; preds = %122, %96
br label %124
124: ; preds = %123, %86
br label %125
125: ; preds = %124, %76
br label %66
126: ; preds = %66
%127 = load i32*, i32** %10
%128 = call i32 @fclose(i32* %127)
%129 = load i32, i32* %12
%130 = and i32 %129, 1
%131 = icmp ne i32 %130, 0
br i1 %131, label %133, label %132
132: ; preds = %126
br label %146
133: ; preds = %126
%134 = load i32, i32* %13
%135 = load i32, i32* %6
%136 = add i32 %135, %134
store i32 %136, i32* %6
%137 = load i32, i32* %14
%138 = load i32, i32* %7
%139 = add i32 %138, %137
store i32 %139, i32* %7
%140 = load i32, i32* %15
%141 = load i32, i32* %8
%142 = add i32 %141, %140
store i32 %142, i32* %8
%143 = load i32, i32* %16
%144 = load i32, i32* %9
%145 = add i32 %144, %143
store i32 %145, i32* %9
br label %146
146: ; preds = %133, %132, %64
%147 = load i32, i32* %3
%148 = add nsw i32 %147, 1
store i32 %148, i32* %3
br label %52
149: ; preds = %52
%150 = load i32, i32* %8
%151 = load i32, i32* %6
%152 = load i32, i32* %7
%153 = load i32, i32* %9
%154 = call i32 @show_pmu_power_line(i32 %150, i32 %151, i32 %152, i32 %153)
store i32 1, i32* %1
br label %155
155: ; preds = %149, %20
%156 = load i32, i32* %1
ret i32 %156
}

LLVM IR (-O2):
@.str = [15 x i8] c"/proc/pmu/info\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"AC Power\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [14 x i8] c"Battery count\00"
@.str.5 = [21 x i8] c"/proc/pmu/battery_%d\00"
@.str.6 = [6 x i8] c"flags\00"
@.str.7 = [3 x i8] c"%x\00"
@.str.8 = [7 x i8] c"charge\00"
@.str.9 = [11 x i8] c"max_charge\00"
@.str.10 = [8 x i8] c"voltage\00"
@.str.11 = [8 x i8] c"current\00"
define i32 @print_battery_proc_pmu() {
%1 = alloca [80 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca [20 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%11 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%12 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%13 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %128, label %15
15: ; preds = %0
%16 = call i32* @fgets(i8* %10, i32 80, i32* %13)
%17 = icmp eq i32* %16, null
br i1 %17, label %34, label %18
18: ; preds = %15, %31
%19 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%20 = call i64 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %10, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%24 = call i64 @strncmp(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %10, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %22, %18
%27 = phi i32* [ %2, %18 ], [ %3, %22 ]
%28 = call i64 @strchr(i8* %10, i8 signext 58)
%29 = add nsw i64 %28, 2
%30 = call i32 (i64, i8*, ...) @sscanf(i64 %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %27)
br label %31
31: ; preds = %26, %22
%32 = call i32* @fgets(i8* %10, i32 80, i32* %13)
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %18
34: ; preds = %31, %15
%35 = call i32 @fclose(i32* %13)
%36 = load i32, i32* %3
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %122
38: ; preds = %34
%39 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%40 = bitcast i32* %5 to i8*
%41 = bitcast i32* %6 to i8*
%42 = bitcast i32* %7 to i8*
%43 = bitcast i32* %8 to i8*
%44 = bitcast i32* %9 to i8*
br label %45
45: ; preds = %38, %114
%46 = phi i32 [ 0, %38 ], [ %118, %114 ]
%47 = phi i32 [ 0, %38 ], [ %117, %114 ]
%48 = phi i32 [ 0, %38 ], [ %116, %114 ]
%49 = phi i32 [ 0, %38 ], [ %115, %114 ]
%50 = phi i32 [ 0, %38 ], [ %119, %114 ]
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%51 = call i32 @snprintf(i8* %39, i32 20, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %50)
%52 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%53 = icmp eq i32* %52, null
br i1 %53, label %114, label %54
54: ; preds = %45
%55 = call i32* @fgets(i8* %10, i32 80, i32* %52)
%56 = icmp eq i32* %55, null
br i1 %56, label %100, label %57
57: ; preds = %54, %97
%58 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%59 = call i64 @strncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %10, i32 %58)
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %57
%62 = call i64 @strchr(i8* %10, i8 signext 58)
%63 = add nsw i64 %62, 2
%64 = call i32 (i64, i8*, ...) @sscanf(i64 %63, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %5)
br label %97
65: ; preds = %57
%66 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%67 = call i64 @strncmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* %10, i32 %66)
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %73
69: ; preds = %65
%70 = call i64 @strchr(i8* %10, i8 signext 58)
%71 = add nsw i64 %70, 2
%72 = call i32 (i64, i8*, ...) @sscanf(i64 %71, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
br label %97
73: ; preds = %65
%74 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%75 = call i64 @strncmp(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i8* %10, i32 %74)
%76 = icmp eq i64 %75, 0
br i1 %76, label %77, label %81
77: ; preds = %73
%78 = call i64 @strchr(i8* %10, i8 signext 58)
%79 = add nsw i64 %78, 2
%80 = call i32 (i64, i8*, ...) @sscanf(i64 %79, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
br label %97
81: ; preds = %73
%82 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%83 = call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), i8* %10, i32 %82)
%84 = icmp eq i64 %83, 0
br i1 %84, label %85, label %89
85: ; preds = %81
%86 = call i64 @strchr(i8* %10, i8 signext 58)
%87 = add nsw i64 %86, 2
%88 = call i32 (i64, i8*, ...) @sscanf(i64 %87, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %8)
br label %97
89: ; preds = %81
%90 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
%91 = call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* %10, i32 %90)
%92 = icmp eq i64 %91, 0
br i1 %92, label %93, label %97
93: ; preds = %89
%94 = call i64 @strchr(i8* %10, i8 signext 58)
%95 = add nsw i64 %94, 2
%96 = call i32 (i64, i8*, ...) @sscanf(i64 %95, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %9)
br label %97
97: ; preds = %69, %85, %93, %89, %77, %61
%98 = call i32* @fgets(i8* %10, i32 80, i32* %52)
%99 = icmp eq i32* %98, null
br i1 %99, label %100, label %57
100: ; preds = %97, %54
%101 = call i32 @fclose(i32* %52)
%102 = load i32, i32* %5
%103 = and i32 %102, 1
%104 = icmp eq i32 %103, 0
br i1 %104, label %114, label %105
105: ; preds = %100
%106 = load i32, i32* %6
%107 = add i32 %106, %49
%108 = load i32, i32* %7
%109 = add i32 %108, %48
%110 = load i32, i32* %8
%111 = add i32 %110, %47
%112 = load i32, i32* %9
%113 = add i32 %112, %46
br label %114
114: ; preds = %100, %45, %105
%115 = phi i32 [ %107, %105 ], [ %49, %45 ], [ %49, %100 ]
%116 = phi i32 [ %109, %105 ], [ %48, %45 ], [ %48, %100 ]
%117 = phi i32 [ %111, %105 ], [ %47, %45 ], [ %47, %100 ]
%118 = phi i32 [ %113, %105 ], [ %46, %45 ], [ %46, %100 ]
%119 = add nuw nsw i32 %50, 1
%120 = load i32, i32* %3
%121 = icmp slt i32 %119, %120
br i1 %121, label %45, label %122
122: ; preds = %114, %34
%123 = phi i32 [ 0, %34 ], [ %115, %114 ]
%124 = phi i32 [ 0, %34 ], [ %116, %114 ]
%125 = phi i32 [ 0, %34 ], [ %117, %114 ]
%126 = phi i32 [ 0, %34 ], [ %118, %114 ]
%127 = call i32 @show_pmu_power_line(i32 %125, i32 %123, i32 %124, i32 %126)
br label %128
128: ; preds = %0, %122
%129 = phi i32 [ 1, %122 ], [ 0, %0 ]
ret i32 %129
}