#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 /*<<< orphan*/ value_t;
typedef int /*<<< orphan*/ value_h;

/* Variables and functions */
float calc_dewpoint(float, float);
int /*<<< orphan*/ calc_sht11(float *, float *);
int /*<<< orphan*/ ioctl(int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned int *, int);
int /*<<< orphan*/ sleep(int);
int main(void) {
  int fd, ret, i;
  unsigned int value_t = 0;
  unsigned int value_h = 0;
  float fvalue_t, fvalue_h;
  float dew_point;
  fd = open("/dev/sht11", 0);
  if (fd < 0) {
    printf("open /dev/sht11 error!\n");
    return -1;
  }
  for (;;) {
    fvalue_t = 0.0, fvalue_h = 0.0;
    value_t = 0;
    value_h = 0;
    ioctl(fd, 0);
    ret = read(fd, &value_t, sizeof(value_t));
    if (ret < 0) {
      printf("read err!\n");
      continue;
    }
    sleep(1);
    value_t = value_t & 0x3fff;
    fvalue_t = (float)value_t;
    ioctl(fd, 1);
    ret = read(fd, &value_h, sizeof(value_h));
    sleep(1);
    if (ret < 0) {
      printf("read err!\n");
      continue;
    }
    value_h = value_h & 0xfff;
    fvalue_h = (float)value_h;
    calc_sht11(&fvalue_h, &fvalue_t);
    dew_point = calc_dewpoint(fvalue_h, fvalue_t);
    printf("temp:%fc humi:%f dew point:%fc\n", fvalue_t, fvalue_h, dew_point);
    sleep(1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe6c(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11c1 <main+0x51>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%eax
add    $0x30,%rsp
pop    %rbp
ret
jmp    11c6 <main+0x56>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1040 <ioctl@plt>
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    121f <main+0xaf>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c6 <main+0x56>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0x14(%rbp),%eax
and    $0x3fff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1040 <ioctl@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0xc(%rbp)
mov    $0x1,%edi
call   1090 <sleep@plt>
cmpl   $0x0,-0xc(%rbp)
jge    1289 <main+0x119>
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c6 <main+0x56>
mov    -0x18(%rbp),%eax
and    $0xfff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1070 <calc_sht11@plt>
movss  -0x20(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm1
call   1080 <calc_dewpoint@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x20(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movss  -0x24(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xd4a(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
jmp    11c6 <main+0x56>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe6b(%rip),%rdi
xor    %esi,%esi
call   1070 <open@plt>
test   %eax,%eax
js     12cf <main+0x14f>
mov    %eax,%ebx
lea    0x14(%rsp),%r14
lea    0xe79(%rip),%r15
mov    $0x3fff,%r13d
lea    0x10(%rsp),%r12
jmp    11c8 <main+0x48>
nop
mov    %r15,%rdi
call   1030 <puts@plt>
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <ioctl@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1060 <read@plt>
test   %eax,%eax
js     11c0 <main+0x40>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    0x14(%rsp),%eax
and    %r13d,%eax
mov    %eax,0x14(%rsp)
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0xc(%rsp)
mov    %ebx,%edi
mov    $0x1,%esi
call   1050 <ioctl@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    %eax,%ebp
mov    $0x1,%edi
call   10a0 <sleep@plt>
test   %ebp,%ebp
js     11c0 <main+0x40>
mov    0x10(%rsp),%eax
mov    $0xfff,%ecx
and    %ecx,%eax
mov    %eax,0x10(%rsp)
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x8(%rsp)
lea    0x8(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1080 <calc_sht11@plt>
movss  0x8(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
call   1090 <calc_dewpoint@plt>
movss  0xc(%rsp),%xmm1
xorps  %xmm3,%xmm3
cvtss2sd %xmm1,%xmm3
movss  0x8(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
xorps  %xmm2,%xmm2
cvtss2sd %xmm0,%xmm2
lea    0xd55(%rip),%rdi
movaps %xmm3,%xmm0
mov    $0x3,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
jmp    11c8 <main+0x48>
lea    0xd5f(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/sht11\00"
@.str.1 = [24 x i8] c"open /dev/sht11 error!\0A\00"
@.str.2 = [11 x i8] c"read err!\0A\00"
@.str.3 = [32 x i8] c"temp:%fc humi:%f dew point:%fc\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca float
%8 = alloca float
%9 = alloca float
store i32 0, i32* %1
store i32 0, i32* %5
store i32 0, i32* %6
%10 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 0)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
ret i32 -1
15: ; preds = %0
br label %16
16: ; preds = %40, %38, %23, %15
store float 0.000000e+00, float* %7
store float 0.000000e+00, float* %8
store i32 0, i32* %5
store i32 0, i32* %6
%17 = load i32, i32* %2
%18 = call i32 @ioctl(i32 %17, i32 0)
%19 = load i32, i32* %2
%20 = call i32 @read(i32 %19, i32* %5, i32 4)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %16
25: ; preds = %16
%26 = call i32 @sleep(i32 1)
%27 = load i32, i32* %5
%28 = and i32 %27, 16383
store i32 %28, i32* %5
%29 = load i32, i32* %5
%30 = uitofp i32 %29 to float
store float %30, float* %7
%31 = load i32, i32* %2
%32 = call i32 @ioctl(i32 %31, i32 1)
%33 = load i32, i32* %2
%34 = call i32 @read(i32 %33, i32* %6, i32 4)
store i32 %34, i32* %3
%35 = call i32 @sleep(i32 1)
%36 = load i32, i32* %3
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %25
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %16
40: ; preds = %25
%41 = load i32, i32* %6
%42 = and i32 %41, 4095
store i32 %42, i32* %6
%43 = load i32, i32* %6
%44 = uitofp i32 %43 to float
store float %44, float* %8
%45 = call i32 @calc_sht11(float* %8, float* %7)
%46 = load float, float* %8
%47 = load float, float* %7
%48 = call float @calc_dewpoint(float %46, float %47)
store float %48, float* %9
%49 = load float, float* %7
%50 = fpext float %49 to double
%51 = load float, float* %8
%52 = fpext float %51 to double
%53 = load float, float* %9
%54 = fpext float %53 to double
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), double %50, double %52, double %54)
%56 = call i32 @sleep(i32 1)
br label %16
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/sht11\00"
@.str.3 = [32 x i8] c"temp:%fc humi:%f dew point:%fc\0A\00"
@str.4 = [10 x i8] c"read err!\00"
@str.5 = [23 x i8] c"open /dev/sht11 error!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast float* %3 to i8*
%8 = bitcast float* %4 to i8*
%9 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.5, i64 0, i64 0))
ret i32 -1
13: ; preds = %0, %19
store float 0.000000e+00, float* %3
store float 0.000000e+00, float* %4
store i32 0, i32* %1
store i32 0, i32* %2
%14 = call i32 @ioctl(i32 %9, i32 0)
%15 = call i32 @read(i32 %9, i32* %1, i32 4)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.4, i64 0, i64 0))
br label %19
19: ; preds = %17, %29, %31
br label %13
20: ; preds = %13
%21 = call i32 @sleep(i32 1)
%22 = load i32, i32* %1
%23 = and i32 %22, 16383
store i32 %23, i32* %1
%24 = uitofp i32 %23 to float
store float %24, float* %3
%25 = call i32 @ioctl(i32 %9, i32 1)
%26 = call i32 @read(i32 %9, i32* %2, i32 4)
%27 = call i32 @sleep(i32 1)
%28 = icmp slt i32 %26, 0
br i1 %28, label %29, label %31
29: ; preds = %20
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.4, i64 0, i64 0))
br label %19
31: ; preds = %20
%32 = load i32, i32* %2
%33 = and i32 %32, 4095
store i32 %33, i32* %2
%34 = uitofp i32 %33 to float
store float %34, float* %4
%35 = call i32 @calc_sht11(float* %4, float* %3)
%36 = load float, float* %4
%37 = load float, float* %3
%38 = call float @calc_dewpoint(float %36, float %37)
%39 = load float, float* %3
%40 = fpext float %39 to double
%41 = load float, float* %4
%42 = fpext float %41 to double
%43 = fpext float %38 to double
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), double %40, double %42, double %43)
%45 = call i32 @sleep(i32 1)
br label %19
}