#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ abort();
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *, int /*<<< orphan*/);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int read_sysfs_int_fd(int fd, const char *sys_pfx, const char *node) {
  char buf[0x20];
  if (read(fd, buf, sizeof(buf)) < 0) {
    fprintf(stderr, "unable to read from %s%s %s\n", sys_pfx, node,
            strerror(errno));
    close(fd);
    abort();
  }
  return atoi(buf);
}


x86 assembly (clang, -O0):
<read_sysfs_int_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jge    11e1 <read_sysfs_int_fd+0x81>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    %eax,%r8d
lea    0xe33(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    $0x0,%al
call   1030 <abort@plt>
lea    -0x40(%rbp),%rdi
call   1070 <atoi@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_sysfs_int_fd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebx
mov    %rsp,%rsi
mov    $0x20,%edx
call   1050 <read@plt>
test   %rax,%rax
js     1197 <read_sysfs_int_fd+0x37>
mov    %rsp,%rdi
call   1070 <atoi@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e42(%rip),%rax
mov    (%rax),%ebp
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe4b(%rip),%rsi
mov    %ebp,%edi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %eax,%r8d
call   1060 <fprintf@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"unable to read from %s%s %s\0A\00"
@errno = global i32 0
define i32 @read_sysfs_int_fd(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [32 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i32, i32* %4
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%10 = call i64 @read(i32 %8, i8* %9, i32 32)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %5
%15 = load i8*, i8** %6
%16 = load i32, i32* @errno
%17 = call i32 @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15, i32 %17)
%19 = load i32, i32* %4
%20 = call i32 @close(i32 %19)
%21 = call i32 (...) @abort()
unreachable
22: ; preds = %3
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%24 = call i32 @atoi(i8* %23)
ret i32 %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"unable to read from %s%s %s\0A\00"
@errno = global i32 0
define i32 @read_sysfs_int_fd(i32 %0, i8* %1, i8* %2) {
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%6 = call i64 @read(i32 %0, i8* %5, i32 32)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i32 @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2, i32 %11)
%13 = tail call i32 @close(i32 %0)
%14 = tail call i32 (...) @abort()
unreachable
15: ; preds = %3
%16 = call i32 @atoi(i8* %5)
ret i32 %16
}