#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 atoi(char const *);
char *om_battery_consumption_path();
char *om_sysfs_readfile(char const *);
int om_battery_consumption_get(int *consumption) {
  const char *path = om_battery_consumption_path();
  if (path == NULL)
    return -1;
  const char *val = om_sysfs_readfile(path);
  if (val == NULL)
    return -1;
  *consumption = atoi(val);
  return 0;
}


x86 assembly (clang, -O0):
<om_battery_consumption_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <om_battery_consumption_path@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    115e <om_battery_consumption_get+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <om_battery_consumption_get+0x6a>
mov    -0x18(%rbp),%rdi
call   1030 <om_sysfs_readfile@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1182 <om_battery_consumption_get+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <om_battery_consumption_get+0x6a>
mov    -0x20(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<om_battery_consumption_get>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <om_battery_consumption_path@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     1160 <om_battery_consumption_get+0x30>
mov    %rax,%rdi
call   1030 <om_sysfs_readfile@plt>
test   %rax,%rax
je     1160 <om_battery_consumption_get+0x30>
mov    %rax,%rdi
call   1050 <atoi@plt>
mov    %eax,(%rbx)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @om_battery_consumption_get(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
store i32* %0, i32** %3
%6 = call i8* (...) @om_battery_consumption_path()
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %20
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = call i8* @om_sysfs_readfile(i8* %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %10
store i32 -1, i32* %2
br label %20
16: ; preds = %10
%17 = load i8*, i8** %5
%18 = call i32 @atoi(i8* %17)
%19 = load i32*, i32** %3
store i32 %18, i32* %19
store i32 0, i32* %2
br label %20
20: ; preds = %16, %15, %9
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
define i32 @om_battery_consumption_get(i32* nocapture writeonly %0) {
%2 = tail call i8* (...) @om_battery_consumption_path()
%3 = icmp eq i8* %2, null
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = tail call i8* @om_sysfs_readfile(i8* %2)
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @atoi(i8* %5)
store i32 %8, i32* %0
br label %9
9: ; preds = %7, %4, %1
%10 = phi i32 [ -1, %1 ], [ 0, %7 ], [ -1, %4 ]
ret i32 %10
}