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

/* Variables and functions */
int /*<<< orphan*/ sscanf(char *, char *, int *);
int sysfs_read_attr_str(char const *, char *, int, int /*<<< orphan*/ *);
int sysfs_read_attr_int(const char *path, int *data) {
  int rc;
  ssize_t read_len;
  char buff[32];
  rc = sysfs_read_attr_str(path, buff, 32, &read_len);
  if (rc != 0)
    return rc;
  sscanf(buff, "%d", data);
  return 0;
}


x86 assembly (clang, -O0):
<sysfs_read_attr_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
lea    -0x20(%rbp),%rcx
call   1030 <sysfs_read_attr_str@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     115e <sysfs_read_attr_int+0x3e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1179 <sysfs_read_attr_int+0x59>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe93(%rip),%rsi
call   1040 <sscanf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysfs_read_attr_int>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rcx
mov    $0x20,%edx
call   1030 <sysfs_read_attr_str@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1157 <sysfs_read_attr_int+0x37>
lea    0xeb6(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %rbx,%rdx
call   1040 <sscanf@plt>
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @sysfs_read_attr_int(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca [32 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%7 = call i32 @sysfs_read_attr_str(i8* %0, i8* %6, i32 32, i32* %3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
br label %11
11: ; preds = %2, %9
ret i32 %7
}