#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(double);
int /*<<< orphan*/ write(int, char *, int);
int read_configuration_register(int fd, short *data) {
  char config[1] = {(char)0x02};
  write(fd, config, 1);
  sleep(0.0625);
  char buff[2] = {0};
  if ((read(fd, buff, 2)) != 2) {
    printf("Failure HDC1080: Read Config Register Error. \n");
    return -1;
  }
  *data = buff[0] * 256 + buff[1];
  return 0;
}


x86 assembly (clang, -O0):
<read_configuration_register>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xea3(%rip),%al
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
movsd  0xe7f(%rip),%xmm0
call   1070 <sleep@plt>
lea    -0x13(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x13(%rbp),%rsi
mov    $0x2,%edx
call   1060 <read@plt>
cmp    $0x2,%eax
je     11c8 <read_configuration_register+0x78>
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <read_configuration_register+0x96>
movsbl -0x13(%rbp),%eax
shl    $0x8,%eax
movsbl -0x12(%rbp),%ecx
add    %ecx,%eax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_configuration_register>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
movb   $0x2,0x7(%rsp)
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
movsd  0xe9c(%rip),%xmm0
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    119c <read_configuration_register+0x5c>
movzbl 0x4(%rsp),%eax
shl    $0x8,%eax
movsbl 0x5(%rsp),%ecx
add    %eax,%ecx
mov    %cx,(%rbx)
xor    %eax,%eax
jmp    11ad <read_configuration_register+0x6d>
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.read_configuration_register.config = [1 x i8] c"\02"
@.str = [47 x i8] c"Failure HDC1080: Read Config Register Error. \0A\00"
define i32 @read_configuration_register(i32 %0, i16* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i16*
%6 = alloca [1 x i8]
%7 = alloca [2 x i8]
store i32 %0, i32* %4
store i16* %1, i16** %5
%8 = bitcast [1 x i8]* %6 to i8*
%9 = load i32, i32* %4
%10 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%11 = call i32 @write(i32 %9, i8* %10, i32 1)
%12 = call i32 @sleep(double 6.250000e-02)
%13 = bitcast [2 x i8]* %7 to i8*
%14 = load i32, i32* %4
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%16 = call i32 @read(i32 %14, i8* %15, i32 2)
%17 = icmp ne i32 %16, 2
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %31
20: ; preds = %2
%21 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = mul nsw i32 %23, 256
%25 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = add nsw i32 %24, %27
%29 = trunc i32 %28 to i16
%30 = load i16*, i16** %5
store i16 %29, i16* %30
store i32 0, i32* %3
br label %31
31: ; preds = %20, %18
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@str = [46 x i8] c"Failure HDC1080: Read Config Register Error. \00"
define i32 @read_configuration_register(i32 %0, i16* nocapture writeonly %1) {
%3 = alloca [1 x i8]
%4 = alloca i16
%5 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
store i8 2, i8* %5
%6 = call i32 @write(i32 %0, i8* %5, i32 1)
%7 = tail call i32 @sleep(double 6.250000e-02)
%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 ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
br label %22
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
store i16 %21, i16* %1
br label %22
22: ; preds = %13, %11
%23 = phi i32 [ -1, %11 ], [ 0, %13 ]
ret i32 %23
}