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

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int pread(int, char *, int, int /*<<< orphan*/);
double strtod(char *, int /*<<< orphan*/ *);
double odroid_read_pwr(int fd) {
  double val;
  char cdata[sizeof(double)];
  int data_size = pread(fd, cdata, sizeof(cdata), 0);
  if (data_size != sizeof(cdata)) {
    perror("odroid_read_pwr");
    return -1;
  }
  val = strtod(cdata, NULL);
  return val;
}


x86 assembly (clang, -O0):
<odroid_read_pwr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1050 <pread@plt>
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    $0x8,%rax
je     117d <odroid_read_pwr+0x4d>
lea    0xea2(%rip),%rdi
call   1040 <perror@plt>
movsd  0xe8d(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1199 <odroid_read_pwr+0x69>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<odroid_read_pwr>:
push   %rax
mov    %rsp,%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1050 <pread@plt>
cmp    $0x8,%eax
jne    1151 <odroid_read_pwr+0x21>
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
pop    %rax
ret
lea    0xeb0(%rip),%rdi
call   1040 <perror@plt>
movsd  0xe9b(%rip),%xmm0
pop    %rax
ret

LLVM IR (-O0):
@.str = [16 x i8] c"odroid_read_pwr\00"
define double @odroid_read_pwr(i32 %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca double
%5 = alloca [8 x i8]
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%9 = call i32 @pread(i32 %7, i8* %8, i32 8, i32 0)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = sext i32 %10 to i64
%12 = icmp ne i64 %11, 8
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store double -1.000000e+00, double* %2
br label %19
15: ; preds = %1
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%17 = call double @strtod(i8* %16, i32* null)
store double %17, double* %4
%18 = load double, double* %4
store double %18, double* %2
br label %19
19: ; preds = %15, %13
%20 = load double, double* %2
ret double %20
}

LLVM IR (-O2):
@.str = [16 x i8] c"odroid_read_pwr\00"
define double @odroid_read_pwr(i32 %0) {
%2 = alloca [8 x i8]
%3 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%4 = call i32 @pread(i32 %0, i8* %3, i32 8, i32 0)
%5 = icmp eq i32 %4, 8
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %10
8: ; preds = %1
%9 = call double @strtod(i8* nocapture %3, i32* null)
br label %10
10: ; preds = %8, %6
%11 = phi double [ -1.000000e+00, %6 ], [ %9, %8 ]
ret double %11
}