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

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ write(int, char *, int);
int read_temperature(int fd, int *data) {
  char config[2] = {0};
  config[0] = (char)0x00;
  config[1] = 0x30;
  write(fd, config, 2);
  sleep(1);
  char buff[2] = {0};
  if (read(fd, buff, 2) != 2) {
    printf("Failure HDC1080: Input/Output error. \n");
    return -1;
  }
  short temp = buff[0] * 256 + buff[1];
  *data = (temp / 65536.0) * 165 - 40;
  return 0;
}


x86 assembly (clang, -O0):
<read_temperature>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x12(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1050 <memset@plt>
movb   $0x0,-0x12(%rbp)
movb   $0x30,-0x11(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
lea    -0x14(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x2,%edx
call   1060 <read@plt>
cmp    $0x2,%eax
je     11d4 <read_temperature+0x84>
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1222 <read_temperature+0xd2>
movsbl -0x14(%rbp),%eax
shl    $0x8,%eax
movsbl -0x13(%rbp),%ecx
add    %ecx,%eax
mov    %ax,-0x16(%rbp)
movswl -0x16(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xe1b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xdff(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdfb(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_temperature>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
movw   $0x3000,0x6(%rsp)
lea    0x6(%rsp),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
movw   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
mov    $0x2,%edx
call   1050 <read@plt>
cmp    $0x2,%eax
jne    11bd <read_temperature+0x7d>
movzbl 0x4(%rsp),%eax
shl    $0x8,%eax
movsbl 0x5(%rsp),%ecx
add    %eax,%ecx
movswl %cx,%eax
cvtsi2sd %eax,%xmm0
mulsd  0xe5d(%rip),%xmm0
mulsd  0xe5d(%rip),%xmm0
addsd  0xe5d(%rip),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,(%rbx)
xor    %eax,%eax
jmp    11ce <read_temperature+0x8e>
lea    0xe54(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Failure HDC1080: Input/Output error. \0A\00"
define i32 @read_temperature(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [2 x i8]
%7 = alloca [2 x i8]
%8 = alloca i16
store i32 %0, i32* %4
store i32* %1, i32** %5
%9 = bitcast [2 x i8]* %6 to i8*
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
store i8 0, i8* %10
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
store i8 48, i8* %11
%12 = load i32, i32* %4
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%14 = call i32 @write(i32 %12, i8* %13, i32 2)
%15 = call i32 @sleep(i32 1)
%16 = bitcast [2 x i8]* %7 to i8*
%17 = load i32, i32* %4
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%19 = call i32 @read(i32 %17, i8* %18, i32 2)
%20 = icmp ne i32 %19, 2
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %40
23: ; preds = %2
%24 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = mul nsw i32 %26, 256
%28 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 1
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = add nsw i32 %27, %30
%32 = trunc i32 %31 to i16
store i16 %32, i16* %8
%33 = load i16, i16* %8
%34 = sext i16 %33 to i32
%35 = sitofp i32 %34 to double
%36 = fdiv double %35, 6.553600e+04
%37 = call double @llvm.fmuladd.f64(double %36, double 1.650000e+02, double -4.000000e+01)
%38 = fptosi double %37 to i32
%39 = load i32*, i32** %5
store i32 %38, i32* %39
store i32 0, i32* %3
br label %40
40: ; preds = %23, %21
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@str = [38 x i8] c"Failure HDC1080: Input/Output error. \00"
define i32 @read_temperature(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca i16
%4 = alloca i16
%5 = bitcast i16* %3 to i8*
store i16 12288, i16* %3
%6 = call i32 @write(i32 %0, i8* %5, i32 2)
%7 = tail call i32 @sleep(i32 1)
%8 = bitcast i16* %4 to i8*
store i16 0, i16* %4
%9 = call i32 @read(i32 %0, i8* %8, i32 2)
%10 = icmp eq i32 %9, 2
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
br label %26
13: ; preds = %2
%14 = bitcast i16* %4 to [2 x i8]*
%15 = load i8, i8* %8
%16 = zext i8 %15 to i16
%17 = shl nuw i16 %16, 8
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %14, i64 0, i64 1
%19 = load i8, i8* %18
%20 = sext i8 %19 to i16
%21 = add i16 %17, %20
%22 = sitofp i16 %21 to double
%23 = fmul double %22, 0x3EF0000000000000
%24 = tail call double @llvm.fmuladd.f64(double %23, double 1.650000e+02, double -4.000000e+01)
%25 = fptosi double %24 to i32
store i32 %25, i32* %1
br label %26
26: ; preds = %13, %11
%27 = phi i32 [ -1, %11 ], [ 0, %13 ]
ret i32 %27
}