#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ I2C_readTransaction(int, int, void *, int);
scalar_t__ I2C_setSlaveAddress(int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
float getRH(int i2c_fd) {
  uint8_t rx_buffer[3];
  int raw_value;
  if (I2C_setSlaveAddress(i2c_fd, 0x40) < 0) {
    printf("*Could set slave address to %d\n", 0x40);
    exit(0);
  }
  I2C_readTransaction(i2c_fd, 0xe5, (void *)rx_buffer, 3);
  raw_value = (rx_buffer[0] << 8) | rx_buffer[1];
  raw_value &= ~0b11;
  return -6.0 + 125.0 * (raw_value / 65536.0);
}


x86 assembly (clang, -O0):
<getRH>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x40,%esi
call   1050 <I2C_setSlaveAddress@plt>
cmp    $0x0,%rax
jge    117a <getRH+0x3a>
lea    0xeaf(%rip),%rdi
mov    $0x40,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rdx
mov    $0xe5,%esi
mov    $0x3,%ecx
call   1040 <I2C_readTransaction@plt>
mov    -0x10(%rbp),%eax
shl    $0x8,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0xfffffffc,%eax
mov    %eax,-0x14(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xe5e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe42(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe3e(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getRH>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    $0x40,%esi
call   1050 <I2C_setSlaveAddress@plt>
test   %rax,%rax
js     11a2 <getRH+0x62>
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
mov    $0xe5,%esi
mov    $0x3,%ecx
call   1040 <I2C_readTransaction@plt>
mov    0x4(%rsp),%eax
mov    0x8(%rsp),%ecx
shl    $0x8,%eax
and    $0xfffffffc,%ecx
or     %eax,%ecx
cvtsi2sd %ecx,%xmm0
mulsd  0xe78(%rip),%xmm0
mulsd  0xe78(%rip),%xmm0
addsd  0xe78(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe6f(%rip),%rdi
mov    $0x40,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"*Could set slave address to %d\0A\00"
define float @getRH(i32 %0) {
%2 = alloca i32
%3 = alloca [3 x i32]
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i64 @I2C_setSlaveAddress(i32 %5, i32 64)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 64)
%10 = call i32 @exit(i32 0)
unreachable
11: ; preds = %1
%12 = load i32, i32* %2
%13 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%14 = bitcast i32* %13 to i8*
%15 = call i32 @I2C_readTransaction(i32 %12, i32 229, i8* %14, i32 3)
%16 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%17 = load i32, i32* %16
%18 = shl i32 %17, 8
%19 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 1
%20 = load i32, i32* %19
%21 = or i32 %18, %20
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = and i32 %22, -4
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = sitofp i32 %24 to double
%26 = fdiv double %25, 6.553600e+04
%27 = call double @llvm.fmuladd.f64(double 1.250000e+02, double %26, double -6.000000e+00)
%28 = fptrunc double %27 to float
ret float %28
}

LLVM IR (-O2):
@.str = [32 x i8] c"*Could set slave address to %d\0A\00"
define float @getRH(i32 %0) {
%2 = alloca [3 x i32]
%3 = bitcast [3 x i32]* %2 to i8*
%4 = tail call i64 @I2C_setSlaveAddress(i32 %0, i32 64)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 64)
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %1
%10 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%11 = call i32 @I2C_readTransaction(i32 %0, i32 229, i8* %3, i32 3)
%12 = load i32, i32* %10
%13 = shl i32 %12, 8
%14 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 1
%15 = load i32, i32* %14
%16 = and i32 %15, -4
%17 = or i32 %16, %13
%18 = sitofp i32 %17 to double
%19 = fmul double %18, 0x3EF0000000000000
%20 = call double @llvm.fmuladd.f64(double %19, double 1.250000e+02, double -6.000000e+00)
%21 = fptrunc double %20 to float
ret float %21
}