#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*/ DelayXms(int);
int /*<<< orphan*/ IIC_Ack();
int /*<<< orphan*/ IIC_NAck();
char IIC_RecvByte();
int /*<<< orphan*/ IIC_SendByte(unsigned char);
int /*<<< orphan*/ IIC_Start();
int /*<<< orphan*/ IIC_Stop();
scalar_t__ IIC_WaitAck(int);
float SHT2x_CalcRH(unsigned short);
float SHT2x_CalcTemperatureC(unsigned short);
int /*<<< orphan*/ SHT2x_CheckCrc(char *, int, char);
float SHT2x_MeasureHM(unsigned char cmd, unsigned short *pMeasurand) {
  char checksum = 0;
  char data[2];
  unsigned char addr = 0;
  unsigned short tmp = 0;
  float t = 0;
  addr = 0X40 << 1;
  IIC_Start();
  IIC_SendByte(addr);
  if (IIC_WaitAck(50000))
    return 0.0;
  IIC_SendByte(cmd);
  if (IIC_WaitAck(50000))
    return 0.0;
  IIC_Start();
  IIC_SendByte(addr + 1);
  while (IIC_WaitAck(50000)) {
    IIC_Start();
    IIC_SendByte(addr + 1);
  }
  DelayXms(70);
  data[0] = IIC_RecvByte();
  IIC_Ack();
  data[1] = IIC_RecvByte();
  IIC_Ack();
  checksum = IIC_RecvByte();
  IIC_NAck();
  IIC_Stop();
  SHT2x_CheckCrc(data, 2, checksum);
  tmp = (data[0] << 8) + data[1];
  if (cmd == 0XE3) {
    t = SHT2x_CalcTemperatureC(tmp);
  } else {
    t = SHT2x_CalcRH(tmp);
  }
  if (pMeasurand) {
    *pMeasurand = (unsigned short)t;
  }
  return t;
}


x86 assembly (clang, -O0):
<SHT2x_MeasureHM>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
movb   $0x0,-0x14(%rbp)
movw   $0x0,-0x16(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movb   $0x80,-0x14(%rbp)
mov    $0x0,%al
call   1060 <IIC_Start@plt>
movzbl -0x14(%rbp),%edi
call   1070 <IIC_SendByte@plt>
mov    $0xc350,%edi
call   1030 <IIC_WaitAck@plt>
cmp    $0x0,%rax
je     120d <SHT2x_MeasureHM+0x5d>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1337 <SHT2x_MeasureHM+0x187>
movzbl -0x5(%rbp),%edi
call   1070 <IIC_SendByte@plt>
mov    $0xc350,%edi
call   1030 <IIC_WaitAck@plt>
cmp    $0x0,%rax
je     1237 <SHT2x_MeasureHM+0x87>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1337 <SHT2x_MeasureHM+0x187>
mov    $0x0,%al
call   1060 <IIC_Start@plt>
movzbl -0x14(%rbp),%eax
add    $0x1,%eax
movzbl %al,%edi
call   1070 <IIC_SendByte@plt>
mov    $0xc350,%edi
call   1030 <IIC_WaitAck@plt>
cmp    $0x0,%rax
je     127c <SHT2x_MeasureHM+0xcc>
mov    $0x0,%al
call   1060 <IIC_Start@plt>
movzbl -0x14(%rbp),%eax
add    $0x1,%eax
movzbl %al,%edi
call   1070 <IIC_SendByte@plt>
jmp    124d <SHT2x_MeasureHM+0x9d>
mov    $0x46,%edi
call   1040 <DelayXms@plt>
mov    $0x0,%al
call   10c0 <IIC_RecvByte@plt>
mov    %al,-0x13(%rbp)
mov    $0x0,%al
call   1080 <IIC_Ack@plt>
mov    $0x0,%al
call   10c0 <IIC_RecvByte@plt>
mov    %al,-0x12(%rbp)
mov    $0x0,%al
call   1080 <IIC_Ack@plt>
mov    $0x0,%al
call   10c0 <IIC_RecvByte@plt>
mov    %al,-0x11(%rbp)
mov    $0x0,%al
call   10a0 <IIC_NAck@plt>
mov    $0x0,%al
call   10d0 <IIC_Stop@plt>
lea    -0x13(%rbp),%rdi
mov    $0x2,%esi
movsbl -0x11(%rbp),%edx
call   1050 <SHT2x_CheckCrc@plt>
movsbl -0x13(%rbp),%eax
shl    $0x8,%eax
movsbl -0x12(%rbp),%ecx
add    %ecx,%eax
mov    %ax,-0x16(%rbp)
movzbl -0x5(%rbp),%eax
cmp    $0xe3,%eax
jne    1305 <SHT2x_MeasureHM+0x155>
movzwl -0x16(%rbp),%edi
call   10b0 <SHT2x_CalcTemperatureC@plt>
movss  %xmm0,-0x1c(%rbp)
jmp    1313 <SHT2x_MeasureHM+0x163>
movzwl -0x16(%rbp),%edi
call   1090 <SHT2x_CalcRH@plt>
movss  %xmm0,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     132d <SHT2x_MeasureHM+0x17d>
cvttss2si -0x1c(%rbp),%eax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SHT2x_MeasureHM>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
xor    %eax,%eax
call   1060 <IIC_Start@plt>
mov    $0x80,%edi
call   1070 <IIC_SendByte@plt>
mov    $0xc350,%edi
call   1030 <IIC_WaitAck@plt>
xorps  %xmm0,%xmm0
test   %rax,%rax
jne    12bd <SHT2x_MeasureHM+0x10d>
movzbl %bpl,%edi
call   1070 <IIC_SendByte@plt>
mov    $0xc350,%edi
call   1030 <IIC_WaitAck@plt>
xorps  %xmm0,%xmm0
test   %rax,%rax
jne    12bd <SHT2x_MeasureHM+0x10d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1060 <IIC_Start@plt>
mov    $0x81,%edi
call   1070 <IIC_SendByte@plt>
mov    $0xc350,%edi
call   1030 <IIC_WaitAck@plt>
test   %rax,%rax
jne    1210 <SHT2x_MeasureHM+0x60>
mov    $0x46,%edi
call   1040 <DelayXms@plt>
xor    %eax,%eax
call   10c0 <IIC_RecvByte@plt>
mov    %al,0xe(%rsp)
xor    %eax,%eax
call   1080 <IIC_Ack@plt>
xor    %eax,%eax
call   10c0 <IIC_RecvByte@plt>
mov    %al,0xf(%rsp)
xor    %eax,%eax
call   1080 <IIC_Ack@plt>
xor    %eax,%eax
call   10c0 <IIC_RecvByte@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   10a0 <IIC_NAck@plt>
xor    %eax,%eax
call   10d0 <IIC_Stop@plt>
movsbl %bl,%edx
lea    0xe(%rsp),%rdi
mov    $0x2,%esi
call   1050 <SHT2x_CheckCrc@plt>
movzbl 0xe(%rsp),%ecx
shl    $0x8,%ecx
movsbl 0xf(%rsp),%eax
add    %ecx,%eax
movzwl %ax,%edi
cmp    $0xe3,%bpl
jne    12ab <SHT2x_MeasureHM+0xfb>
call   10b0 <SHT2x_CalcTemperatureC@plt>
test   %r14,%r14
jne    12b5 <SHT2x_MeasureHM+0x105>
jmp    12bd <SHT2x_MeasureHM+0x10d>
call   1090 <SHT2x_CalcRH@plt>
test   %r14,%r14
je     12bd <SHT2x_MeasureHM+0x10d>
cvttss2si %xmm0,%eax
mov    %ax,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define float @SHT2x_MeasureHM(i8 zeroext %0, i16* %1) {
%3 = alloca float
%4 = alloca i8
%5 = alloca i16*
%6 = alloca i8
%7 = alloca [2 x i8]
%8 = alloca i8
%9 = alloca i16
%10 = alloca float
store i8 %0, i8* %4
store i16* %1, i16** %5
store i8 0, i8* %6
store i8 0, i8* %8
store i16 0, i16* %9
store float 0.000000e+00, float* %10
store i8 -128, i8* %8
%11 = call i32 (...) @IIC_Start()
%12 = load i8, i8* %8
%13 = call i32 @IIC_SendByte(i8 zeroext %12)
%14 = call i64 @IIC_WaitAck(i32 50000)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %2
store float 0.000000e+00, float* %3
br label %81
17: ; preds = %2
%18 = load i8, i8* %4
%19 = call i32 @IIC_SendByte(i8 zeroext %18)
%20 = call i64 @IIC_WaitAck(i32 50000)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %17
store float 0.000000e+00, float* %3
br label %81
23: ; preds = %17
%24 = call i32 (...) @IIC_Start()
%25 = load i8, i8* %8
%26 = zext i8 %25 to i32
%27 = add nsw i32 %26, 1
%28 = trunc i32 %27 to i8
%29 = call i32 @IIC_SendByte(i8 zeroext %28)
br label %30
30: ; preds = %33, %23
%31 = call i64 @IIC_WaitAck(i32 50000)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %30
%34 = call i32 (...) @IIC_Start()
%35 = load i8, i8* %8
%36 = zext i8 %35 to i32
%37 = add nsw i32 %36, 1
%38 = trunc i32 %37 to i8
%39 = call i32 @IIC_SendByte(i8 zeroext %38)
br label %30
40: ; preds = %30
%41 = call i32 @DelayXms(i32 70)
%42 = call signext i8 (...) @IIC_RecvByte()
%43 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
store i8 %42, i8* %43
%44 = call i32 (...) @IIC_Ack()
%45 = call signext i8 (...) @IIC_RecvByte()
%46 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 1
store i8 %45, i8* %46
%47 = call i32 (...) @IIC_Ack()
%48 = call signext i8 (...) @IIC_RecvByte()
store i8 %48, i8* %6
%49 = call i32 (...) @IIC_NAck()
%50 = call i32 (...) @IIC_Stop()
%51 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%52 = load i8, i8* %6
%53 = call i32 @SHT2x_CheckCrc(i8* %51, i32 2, i8 signext %52)
%54 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = shl i32 %56, 8
%58 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 1
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = add nsw i32 %57, %60
%62 = trunc i32 %61 to i16
store i16 %62, i16* %9
%63 = load i8, i8* %4
%64 = zext i8 %63 to i32
%65 = icmp eq i32 %64, 227
br i1 %65, label %66, label %69
66: ; preds = %40
%67 = load i16, i16* %9
%68 = call float @SHT2x_CalcTemperatureC(i16 zeroext %67)
store float %68, float* %10
br label %72
69: ; preds = %40
%70 = load i16, i16* %9
%71 = call float @SHT2x_CalcRH(i16 zeroext %70)
store float %71, float* %10
br label %72
72: ; preds = %69, %66
%73 = load i16*, i16** %5
%74 = icmp ne i16* %73, null
br i1 %74, label %75, label %79
75: ; preds = %72
%76 = load float, float* %10
%77 = fptoui float %76 to i16
%78 = load i16*, i16** %5
store i16 %77, i16* %78
br label %79
79: ; preds = %75, %72
%80 = load float, float* %10
store float %80, float* %3
br label %81
81: ; preds = %79, %22, %16
%82 = load float, float* %3
ret float %82
}

LLVM IR (-O2):
define float @SHT2x_MeasureHM(i8 zeroext %0, i16* writeonly %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (...) @IIC_Start()
%6 = tail call i32 @IIC_SendByte(i8 zeroext -128)
%7 = tail call i64 @IIC_WaitAck(i32 50000)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %50
9: ; preds = %2
%10 = tail call i32 @IIC_SendByte(i8 zeroext %0)
%11 = tail call i64 @IIC_WaitAck(i32 50000)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %50
13: ; preds = %9
%14 = tail call i32 (...) @IIC_Start()
%15 = tail call i32 @IIC_SendByte(i8 zeroext -127)
%16 = tail call i64 @IIC_WaitAck(i32 50000)
%17 = icmp eq i64 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %13, %18
%19 = tail call i32 (...) @IIC_Start()
%20 = tail call i32 @IIC_SendByte(i8 zeroext -127)
%21 = tail call i64 @IIC_WaitAck(i32 50000)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %18
23: ; preds = %18, %13
%24 = tail call i32 @DelayXms(i32 70)
%25 = tail call signext i8 (...) @IIC_RecvByte()
store i8 %25, i8* %4
%26 = tail call i32 (...) @IIC_Ack()
%27 = tail call signext i8 (...) @IIC_RecvByte()
%28 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 %27, i8* %28
%29 = tail call i32 (...) @IIC_Ack()
%30 = tail call signext i8 (...) @IIC_RecvByte()
%31 = tail call i32 (...) @IIC_NAck()
%32 = tail call i32 (...) @IIC_Stop()
%33 = call i32 @SHT2x_CheckCrc(i8* %4, i32 2, i8 signext %30)
%34 = load i8, i8* %4
%35 = zext i8 %34 to i16
%36 = shl nuw i16 %35, 8
%37 = load i8, i8* %28
%38 = sext i8 %37 to i16
%39 = add i16 %36, %38
%40 = icmp eq i8 %0, -29
br i1 %40, label %41, label %43
41: ; preds = %23
%42 = call float @SHT2x_CalcTemperatureC(i16 zeroext %39)
br label %45
43: ; preds = %23
%44 = call float @SHT2x_CalcRH(i16 zeroext %39)
br label %45
45: ; preds = %43, %41
%46 = phi float [ %42, %41 ], [ %44, %43 ]
%47 = icmp eq i16* %1, null
br i1 %47, label %50, label %48
48: ; preds = %45
%49 = fptoui float %46 to i16
store i16 %49, i16* %1
br label %50
50: ; preds = %45, %48, %9, %2
%51 = phi float [ 0.000000e+00, %2 ], [ 0.000000e+00, %9 ], [ %46, %48 ], [ %46, %45 ]
ret float %51
}