#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 int32_t;
typedef int int16_t;

/* Variables and functions */
int /*<<< orphan*/ I2C_SLAVE;
int i2c_smbus_read_word_data(int const, int);
scalar_t__ ioctl(int const, int /*<<< orphan*/, int const);
int read_adt74x0(const int file, const int addr, double *temp) {
  if (ioctl(file, I2C_SLAVE, addr) < 0)
    return -1;
  int32_t t_raw = i2c_smbus_read_word_data(file, 0x00);
  if (t_raw < 0)
    return -6;
  int16_t lo = (t_raw & 0xff00) >> 8;
  int16_t hi = (t_raw & 0x00ff);
  int16_t t128 = hi << 8 | lo;
  *temp = t128 / 128.0;
  return 0;
}


x86 assembly (clang, -O0):
<read_adt74x0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eac(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    115c <read_adt74x0+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <read_adt74x0+0xa4>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1040 <i2c_smbus_read_word_data@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    117f <read_adt74x0+0x5f>
movl   $0xfffffffa,-0x4(%rbp)
jmp    11c4 <read_adt74x0+0xa4>
mov    -0x1c(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
shl    $0x8,%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
cvtsi2sdl -0x28(%rbp),%xmm0
movsd  0xe4f(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_adt74x0>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %esi,%edx
mov    %edi,%ebx
mov    0x2eb6(%rip),%rax
mov    (%rax),%esi
call   1030 <ioctl@plt>
test   %rax,%rax
js     1167 <read_adt74x0+0x47>
xor    %ebp,%ebp
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <i2c_smbus_read_word_data@plt>
test   %eax,%eax
js     116e <read_adt74x0+0x4e>
rol    $0x8,%ax
movzwl %ax,%eax
cvtsi2sd %eax,%xmm0
mulsd  0xea0(%rip),%xmm0
movsd  %xmm0,(%r14)
jmp    1173 <read_adt74x0+0x53>
mov    $0xffffffff,%ebp
jmp    1173 <read_adt74x0+0x53>
mov    $0xfffffffa,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@I2C_SLAVE = global i32 0
define i32 @read_adt74x0(i32 %0, i32 %1, double* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store double* %2, double** %7
%12 = load i32, i32* %5
%13 = load i32, i32* @I2C_SLAVE
%14 = load i32, i32* %6
%15 = call i64 @ioctl(i32 %12, i32 %13, i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %3
store i32 -1, i32* %4
br label %38
18: ; preds = %3
%19 = load i32, i32* %5
%20 = call i32 @i2c_smbus_read_word_data(i32 %19, i32 0)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 -6, i32* %4
br label %38
24: ; preds = %18
%25 = load i32, i32* %8
%26 = and i32 %25, 65280
%27 = ashr i32 %26, 8
store i32 %27, i32* %9
%28 = load i32, i32* %8
%29 = and i32 %28, 255
store i32 %29, i32* %10
%30 = load i32, i32* %10
%31 = shl i32 %30, 8
%32 = load i32, i32* %9
%33 = or i32 %31, %32
store i32 %33, i32* %11
%34 = load i32, i32* %11
%35 = sitofp i32 %34 to double
%36 = fdiv double %35, 1.280000e+02
%37 = load double*, double** %7
store double %36, double* %37
store i32 0, i32* %4
br label %38
38: ; preds = %24, %23, %17
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@I2C_SLAVE = global i32 0
define i32 @read_adt74x0(i32 %0, i32 %1, double* nocapture writeonly %2) {
%4 = load i32, i32* @I2C_SLAVE
%5 = tail call i64 @ioctl(i32 %0, i32 %4, i32 %1)
%6 = icmp slt i64 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %3
%8 = tail call i32 @i2c_smbus_read_word_data(i32 %0, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %7
%11 = trunc i32 %8 to i16
%12 = tail call i16 @llvm.bswap.i16(i16 %11)
%13 = uitofp i16 %12 to double
%14 = fmul double %13, 7.812500e-03
store double %14, double* %2
br label %15
15: ; preds = %10, %7, %3
%16 = phi i32 [ -1, %3 ], [ 0, %10 ], [ -6, %7 ]
ret i32 %16
}