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

/* Variables and functions */
int filename__read_int(char *, int *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *);
char *sysfs__mountpoint();
int sysfs__read_int(const char *entry, int *value) {
  char path[4096];
  const char *sysfs = sysfs__mountpoint();
  if (!sysfs)
    return -1;
  snprintf(path, sizeof(path), "%s/%s", sysfs, entry);
  return filename__read_int(path, value);
}


x86 assembly (clang, -O0):
<sysfs__read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1050 <sysfs__mountpoint@plt>
mov    %rax,-0x1028(%rbp)
cmpq   $0x0,-0x1028(%rbp)
jne    116b <sysfs__read_int+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a1 <sysfs__read_int+0x71>
lea    -0x1020(%rbp),%rdi
mov    -0x1028(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    $0x1000,%esi
lea    0xe77(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <filename__read_int@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysfs__read_int>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <sysfs__mountpoint@plt>
test   %rax,%rax
je     1178 <sysfs__read_int+0x48>
lea    0xeab(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x1000,%esi
mov    %rax,%rcx
mov    %rbx,%r8
call   1040 <snprintf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <filename__read_int@plt>
jmp    117d <sysfs__read_int+0x4d>
mov    $0xffffffff,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
define i32 @sysfs__read_int(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [4096 x i8]
%7 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = call i8* (...) @sysfs__mountpoint()
store i8* %8, i8** %7
%9 = load i8*, i8** %7
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
store i32 -1, i32* %3
br label %20
12: ; preds = %2
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%14 = load i8*, i8** %7
%15 = load i8*, i8** %4
%16 = call i32 @snprintf(i8* %13, i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15)
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%18 = load i32*, i32** %5
%19 = call i32 @filename__read_int(i8* %17, i32* %18)
store i32 %19, i32* %3
br label %20
20: ; preds = %12, %11
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
define i32 @sysfs__read_int(i8* %0, i32* %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i8* (...) @sysfs__mountpoint()
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i32 @snprintf(i8* %4, i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %0)
%9 = call i32 @filename__read_int(i8* %4, i32* %1)
br label %10
10: ; preds = %2, %7
%11 = phi i32 [ %9, %7 ], [ -1, %2 ]
ret i32 %11
}