#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 *, float *);
float sysfs_read_attr_str(char const *, char *, int, int /*<<< orphan*/ *);
int sysfs_read_attr_float(const char *path, float *data) {
  float 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, "%f", data);
  return 0;
}


x86 assembly (clang, -O0):
<sysfs_read_attr_float>:
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>
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1167 <sysfs_read_attr_float+0x47>
jp     1167 <sysfs_read_attr_float+0x47>
jmp    1174 <sysfs_read_attr_float+0x54>
cvttss2si -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118f <sysfs_read_attr_float+0x6f>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe7d(%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_float>:
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rcx
mov    $0x20,%edx
call   1030 <sysfs_read_attr_str@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1146 <sysfs_read_attr_float+0x26>
jnp    114c <sysfs_read_attr_float+0x2c>
cvttss2si %xmm0,%eax
jmp    1162 <sysfs_read_attr_float+0x42>
lea    0xead(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %rbx,%rdx
call   1040 <sscanf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%f\00"
define i32 @sysfs_read_attr_float(i8* %0, float* %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 float @sysfs_read_attr_str(i8* %0, i8* %6, i32 32, i32* %3)
%8 = fcmp une float %7, 0.000000e+00
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = fptosi float %7 to i32
br label %13
11: ; preds = %2
%12 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float* %1)
br label %13
13: ; preds = %11, %9
%14 = phi i32 [ %10, %9 ], [ 0, %11 ]
ret i32 %14
}