#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 read_int(char *);
int battery_read_current(void) {
  int battery_current;
  battery_current = read_int("/sys/class/power_supply/BAT0/battery_now");
  if (battery_current != -1)
    return battery_current;
  battery_current = read_int("/sys/class/power_supply/BAT0/charge_now");
  if (battery_current != -1)
    return battery_current;
  battery_current = read_int("/sys/class/power_supply/BAT0/energy_now");
  if (battery_current != -1)
    return battery_current;
  return -1;
}


x86 assembly (clang, -O0):
<battery_read_current>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xee1(%rip),%rdi
call   1030 <read_int@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     113c <battery_read_current+0x2c>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118b <battery_read_current+0x7b>
lea    0xee6(%rip),%rdi
call   1030 <read_int@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     1160 <battery_read_current+0x50>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118b <battery_read_current+0x7b>
lea    0xeea(%rip),%rdi
call   1030 <read_int@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     1184 <battery_read_current+0x74>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118b <battery_read_current+0x7b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<battery_read_current>:
push   %rax
lea    0xee8(%rip),%rdi
call   1030 <read_int@plt>
cmp    $0xffffffff,%eax
jne    1133 <battery_read_current+0x23>
lea    0xf00(%rip),%rdi
call   1030 <read_int@plt>
cmp    $0xffffffff,%eax
je     1135 <battery_read_current+0x25>
pop    %rcx
ret
lea    0xf15(%rip),%rdi
pop    %rax
jmp    1030 <read_int@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"/sys/class/power_supply/BAT0/battery_now\00"
@.str.1 = [40 x i8] c"/sys/class/power_supply/BAT0/charge_now\00"
@.str.2 = [40 x i8] c"/sys/class/power_supply/BAT0/energy_now\00"
define i32 @battery_read_current() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @read_int(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = load i32, i32* %2
store i32 %7, i32* %1
br label %21
8: ; preds = %0
%9 = call i32 @read_int(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = load i32, i32* %2
store i32 %13, i32* %1
br label %21
14: ; preds = %8
%15 = call i32 @read_int(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = load i32, i32* %2
store i32 %19, i32* %1
br label %21
20: ; preds = %14
store i32 -1, i32* %1
br label %21
21: ; preds = %20, %18, %12, %6
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str = [41 x i8] c"/sys/class/power_supply/BAT0/battery_now\00"
@.str.1 = [40 x i8] c"/sys/class/power_supply/BAT0/charge_now\00"
@.str.2 = [40 x i8] c"/sys/class/power_supply/BAT0/energy_now\00"
define i32 @battery_read_current() {
%1 = tail call i32 @read_int(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32 %1, -1
br i1 %2, label %3, label %8
3: ; preds = %0
%4 = tail call i32 @read_int(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @read_int(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
br label %8
8: ; preds = %6, %3, %0
%9 = phi i32 [ %1, %0 ], [ %4, %3 ], [ %7, %6 ]
ret i32 %9
}