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

/* Variables and functions */
float EINVAL;
float errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fscanf(int /*<<< orphan*/ *, char *, float *);
float read_sys_file_float(const char *filename, float *value) {
  int err;
  FILE *f = fopen(filename, "r");
  if (f == NULL)
    return -errno;
  err = fscanf(f, "%f", value);
  fclose(f);
  if (err != 1)
    return (err < 0) ? err : -EINVAL;
  return 0;
}


x86 assembly (clang, -O0):
<read_sys_file_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1181 <read_sys_file_float+0x51>
mov    0x2e7a(%rip),%rax
movss  (%rax),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11f8 <read_sys_file_float+0xc8>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe72(%rip),%rsi
call   1040 <fscanf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x1,-0x1c(%rbp)
je     11f0 <read_sys_file_float+0xc0>
cmpl   $0x0,-0x1c(%rbp)
jge    11c4 <read_sys_file_float+0x94>
cvtsi2ssl -0x1c(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
jmp    11e1 <read_sys_file_float+0xb1>
mov    0x2e0d(%rip),%rax
movss  (%rax),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11f8 <read_sys_file_float+0xc8>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_sys_file_float>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xed2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     117c <read_sys_file_float+0x4c>
mov    %rax,%rbx
lea    0xec0(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1040 <fscanf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
xorps  %xmm0,%xmm0
cmp    $0x1,%ebp
je     1197 <read_sys_file_float+0x67>
test   %ebp,%ebp
js     1190 <read_sys_file_float+0x60>
mov    0x2e5e(%rip),%rax
jmp    1183 <read_sys_file_float+0x53>
mov    0x2e5d(%rip),%rax
movss  (%rax),%xmm0
xorps  0xe72(%rip),%xmm0
jmp    1197 <read_sys_file_float+0x67>
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@errno = global float 0.000000e+00
@.str.1 = [3 x i8] c"%f\00"
@EINVAL = global float 0.000000e+00
define float @read_sys_file_float(i8* %0, float* %1) {
%3 = alloca float
%4 = alloca i8*
%5 = alloca float*
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %4
store float* %1, float** %5
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %7
%10 = load i32*, i32** %7
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load float, float* @errno
%14 = fneg float %13
store float %14, float* %3
br label %35
15: ; preds = %2
%16 = load i32*, i32** %7
%17 = load float*, float** %5
%18 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %17)
store i32 %18, i32* %6
%19 = load i32*, i32** %7
%20 = call i32 @fclose(i32* %19)
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 1
br i1 %22, label %23, label %34
23: ; preds = %15
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %6
%28 = sitofp i32 %27 to float
br label %32
29: ; preds = %23
%30 = load float, float* @EINVAL
%31 = fneg float %30
br label %32
32: ; preds = %29, %26
%33 = phi float [ %28, %26 ], [ %31, %29 ]
store float %33, float* %3
br label %35
34: ; preds = %15
store float 0.000000e+00, float* %3
br label %35
35: ; preds = %34, %32, %12
%36 = load float, float* %3
ret float %36
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@errno = global float 0.000000e+00
@.str.1 = [3 x i8] c"%f\00"
@EINVAL = global float 0.000000e+00
define float @read_sys_file_float(i8* nocapture %0, float* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load float, float* @errno
%7 = fneg float %6
br label %18
8: ; preds = %2
%9 = tail call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%10 = tail call i32 @fclose(i32* %3)
%11 = icmp eq i32 %9, 1
br i1 %11, label %18, label %12
12: ; preds = %8
%13 = icmp slt i32 %9, 0
%14 = sitofp i32 %9 to float
%15 = load float, float* @EINVAL
%16 = fneg float %15
%17 = select i1 %13, float %14, float %16
br label %18
18: ; preds = %8, %12, %5
%19 = phi float [ %7, %5 ], [ %17, %12 ], [ 0.000000e+00, %8 ]
ret float %19
}