#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;
typedef double int16_t;

/* Variables and functions */
int /*<<< orphan*/ I2C_SLAVE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ check(double, char *);
double close(int);
double get_measurement(int, int);
int /*<<< orphan*/ get_time_string(char *, int);
double ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, float, float);
int main(int argc, char **argv) {
  char *bus = "/dev/i2c-1";
  uint8_t address = 0x40;
  int file;
  char date[64];
  get_time_string(date, 64);
  check((file = open(bus, O_RDWR)), "open()");
  check(ioctl(file, I2C_SLAVE, address), "ioctl()");
  int16_t data;
  check((data = get_measurement(0xE5, file)), "get_measurement(READ_RELH)");
  float rel_humidity = ((data * 125.0) / 65536.0) - 6;
  check((data = get_measurement(0xE3, file)), "get_measurement(READ_TEMP)");
  float cTemp = ((data * 175.72) / 65536.0) - 46.85;
  float fTemp = cTemp * 1.8 + 32;
  printf("%s,%.2f,%.2f\n", date, fTemp, rel_humidity);
  check(close(file), "close()");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea8(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x40,-0x1c(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0x40,%esi
call   1050 <get_time_string@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x20(%rbp)
cvtsi2sd %eax,%xmm0
lea    0xe7a(%rip),%rdi
call   1090 <check@plt>
mov    -0x20(%rbp),%edi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%edx
call   1060 <ioctl@plt>
lea    0xe61(%rip),%rdi
call   1090 <check@plt>
mov    -0x20(%rbp),%esi
mov    $0xe5,%edi
call   1030 <get_measurement@plt>
movsd  %xmm0,-0x68(%rbp)
lea    0xe4b(%rip),%rdi
call   1090 <check@plt>
movsd  0xe1c(%rip),%xmm0
mulsd  -0x68(%rbp),%xmm0
movsd  0xdf7(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xdfb(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x6c(%rbp)
mov    -0x20(%rbp),%esi
mov    $0xe3,%edi
call   1030 <get_measurement@plt>
movsd  %xmm0,-0x68(%rbp)
lea    0xe1a(%rip),%rdi
call   1090 <check@plt>
movsd  0xdc0(%rip),%xmm0
mulsd  -0x68(%rbp),%xmm0
movsd  0xdab(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xd97(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x70(%rbp)
movss  -0x70(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd69(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd65(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x74(%rbp)
lea    -0x60(%rbp),%rsi
movss  -0x74(%rbp),%xmm0
movss  -0x6c(%rbp),%xmm1
lea    0xdc3(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%edi
call   1070 <close@plt>
lea    0xdbd(%rip),%rdi
call   1090 <check@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1050 <get_time_string@plt>
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0xea0(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebp
cvtsi2sd %eax,%xmm0
lea    0xe99(%rip),%rdi
call   1090 <check@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    $0x40,%edx
call   1060 <ioctl@plt>
lea    0xe7f(%rip),%rdi
call   1090 <check@plt>
mov    $0xe5,%edi
mov    %ebp,%esi
call   1030 <get_measurement@plt>
movsd  %xmm0,(%rsp)
lea    0xe6a(%rip),%rdi
call   1090 <check@plt>
movsd  (%rsp),%xmm0
mulsd  0xe06(%rip),%xmm0
mulsd  0xe06(%rip),%xmm0
addsd  0xe06(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rsp)
mov    $0xe3,%edi
mov    %ebp,%esi
call   1030 <get_measurement@plt>
movsd  %xmm0,0x8(%rsp)
lea    0xe41(%rip),%rdi
call   1090 <check@plt>
movsd  0x8(%rsp),%xmm0
mulsd  0xdd9(%rip),%xmm0
mulsd  0xdc1(%rip),%xmm0
addsd  0xdd1(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xdc9(%rip),%xmm0
addsd  0xdc9(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xe16(%rip),%rdi
mov    %rbx,%rsi
movss  (%rsp),%xmm1
call   1040 <printf@plt>
mov    %ebp,%edi
call   1070 <close@plt>
lea    0xe09(%rip),%rdi
call   1090 <check@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@.str.1 = [7 x i8] c"open()\00"
@I2C_SLAVE = global i32 0
@.str.2 = [8 x i8] c"ioctl()\00"
@.str.3 = [27 x i8] c"get_measurement(READ_RELH)\00"
@.str.4 = [27 x i8] c"get_measurement(READ_TEMP)\00"
@.str.5 = [14 x i8] c"%s,%.2f,%.2f\0A\00"
@.str.6 = [8 x i8] c"close()\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [64 x i8]
%10 = alloca double
%11 = alloca float
%12 = alloca float
%13 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 64, i32* %7
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%15 = call i32 @get_time_string(i8* %14, i32 64)
%16 = load i8*, i8** %6
%17 = load i32, i32* @O_RDWR
%18 = call i32 @open(i8* %16, i32 %17)
store i32 %18, i32* %8
%19 = sitofp i32 %18 to double
%20 = call i32 @check(double %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* %8
%22 = load i32, i32* @I2C_SLAVE
%23 = load i32, i32* %7
%24 = call double @ioctl(i32 %21, i32 %22, i32 %23)
%25 = call i32 @check(double %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* %8
%27 = call double @get_measurement(i32 229, i32 %26)
store double %27, double* %10
%28 = call i32 @check(double %27, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%29 = load double, double* %10
%30 = fmul double %29, 1.250000e+02
%31 = fdiv double %30, 6.553600e+04
%32 = fsub double %31, 6.000000e+00
%33 = fptrunc double %32 to float
store float %33, float* %11
%34 = load i32, i32* %8
%35 = call double @get_measurement(i32 227, i32 %34)
store double %35, double* %10
%36 = call i32 @check(double %35, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%37 = load double, double* %10
%38 = fmul double %37, 1.757200e+02
%39 = fdiv double %38, 6.553600e+04
%40 = fsub double %39, 4.685000e+01
%41 = fptrunc double %40 to float
store float %41, float* %12
%42 = load float, float* %12
%43 = fpext float %42 to double
%44 = call double @llvm.fmuladd.f64(double %43, double 1.800000e+00, double 3.200000e+01)
%45 = fptrunc double %44 to float
store float %45, float* %13
%46 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%47 = load float, float* %13
%48 = load float, float* %11
%49 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %46, float %47, float %48)
%50 = load i32, i32* %8
%51 = call double @close(i32 %50)
%52 = call i32 @check(double %51, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@.str.1 = [7 x i8] c"open()\00"
@I2C_SLAVE = global i32 0
@.str.2 = [8 x i8] c"ioctl()\00"
@.str.3 = [27 x i8] c"get_measurement(READ_RELH)\00"
@.str.4 = [27 x i8] c"get_measurement(READ_TEMP)\00"
@.str.5 = [14 x i8] c"%s,%.2f,%.2f\0A\00"
@.str.6 = [8 x i8] c"close()\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = call i32 @get_time_string(i8* %4, i32 64)
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = sitofp i32 %7 to double
%9 = call i32 @check(double %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @I2C_SLAVE
%11 = call double @ioctl(i32 %7, i32 %10, i32 64)
%12 = call i32 @check(double %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%13 = call double @get_measurement(i32 229, i32 %7)
%14 = call i32 @check(double %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%15 = fmul double %13, 1.250000e+02
%16 = fmul double %15, 0x3EF0000000000000
%17 = fadd double %16, -6.000000e+00
%18 = fptrunc double %17 to float
%19 = call double @get_measurement(i32 227, i32 %7)
%20 = call i32 @check(double %19, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%21 = fmul double %19, 1.757200e+02
%22 = fmul double %21, 0x3EF0000000000000
%23 = fadd double %22, -4.685000e+01
%24 = fptrunc double %23 to float
%25 = fpext float %24 to double
%26 = call double @llvm.fmuladd.f64(double %25, double 1.800000e+00, double 3.200000e+01)
%27 = fptrunc double %26 to float
%28 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %4, float %27, float %18)
%29 = call double @close(i32 %7)
%30 = call i32 @check(double %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}