#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*/ I2C_SLAVE;
int /*<<< orphan*/ O_RDWR;
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int read(int, unsigned char *, int);
int write(int, unsigned char *, int);
int si7021_read_temperature(float *temperature) {
  int file_i2c;
  int length;
  unsigned char buffer[60] = {0};
  if ((file_i2c = open("/dev/i2c-1", O_RDWR)) < 0) {
    return -1;
  }
  int addr = 0x40;
  if (ioctl(file_i2c, I2C_SLAVE, addr) < 0) {
    return -2;
  }
  buffer[0] = 0xE3;
  length = 1;
  if (write(file_i2c, buffer, length) != length) {
    return -3;
  }
  length = 4;
  int il = read(file_i2c, buffer, length);
  if (il != length) {
    printf("Failed to read from the i2c bus., il = %d\n", il);
  }
  long in = (buffer[0] << 8) | buffer[1];
  float c = ((175.2 * (double)in) / 65536.0) - 46.85;
  *temperature = c;
  return 0;
}


x86 assembly (clang, -O0):
<si7021_read_temperature>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x3c,%edx
call   1050 <memset@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    0xe89(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11ac <si7021_read_temperature+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    129a <si7021_read_temperature+0x13a>
movl   $0x40,-0x64(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
mov    -0x64(%rbp),%edx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
jge    11dd <si7021_read_temperature+0x7d>
movl   $0xfffffffe,-0x4(%rbp)
jmp    129a <si7021_read_temperature+0x13a>
movb   $0xe3,-0x60(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <write@plt>
cmp    -0x18(%rbp),%eax
je     120c <si7021_read_temperature+0xac>
movl   $0xfffffffd,-0x4(%rbp)
jmp    129a <si7021_read_temperature+0x13a>
movl   $0x4,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1070 <read@plt>
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1240 <si7021_read_temperature+0xe0>
mov    -0x68(%rbp),%esi
lea    0xde8(%rip),%rdi
call   1040 <printf@plt>
movzbl -0x60(%rbp),%eax
shl    $0x8,%eax
movzbl -0x5f(%rbp),%ecx
or     %ecx,%eax
cltq
mov    %rax,-0x70(%rbp)
cvtsi2sdq -0x70(%rbp),%xmm1
movsd  0xdaf(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xd9b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xd87(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x74(%rbp)
movss  -0x74(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<si7021_read_temperature>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movups %xmm0,0x2c(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe99(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     121d <si7021_read_temperature+0xcd>
mov    %eax,%ebp
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    $0x40,%edx
call   1050 <ioctl@plt>
test   %rax,%rax
js     1224 <si7021_read_temperature+0xd4>
movb   $0xe3,(%rsp)
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    $0xfffffffd,%eax
cmp    $0x1,%ecx
jne    1229 <si7021_read_temperature+0xd9>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1060 <read@plt>
cmp    $0x4,%eax
je     11e9 <si7021_read_temperature+0x99>
lea    0xe41(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
movzwl (%rsp),%eax
shl    $0x10,%eax
bswap  %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xdff(%rip),%xmm0
mulsd  0xdff(%rip),%xmm0
addsd  0xdff(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rbx)
xor    %eax,%eax
jmp    1229 <si7021_read_temperature+0xd9>
mov    $0xffffffff,%eax
jmp    1229 <si7021_read_temperature+0xd9>
mov    $0xfffffffe,%eax
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@I2C_SLAVE = global i32 0
@.str.1 = [43 x i8] c"Failed to read from the i2c bus., il = %d\0A\00"
define i32 @si7021_read_temperature(float* %0) {
%2 = alloca i32
%3 = alloca float*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [60 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca float
store float* %0, float** %3
%11 = bitcast [60 x i8]* %6 to i8*
%12 = load i32, i32* @O_RDWR
%13 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %1
store i32 -1, i32* %2
br label %61
16: ; preds = %1
store i32 64, i32* %7
%17 = load i32, i32* %4
%18 = load i32, i32* @I2C_SLAVE
%19 = load i32, i32* %7
%20 = call i64 @ioctl(i32 %17, i32 %18, i32 %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %16
store i32 -2, i32* %2
br label %61
23: ; preds = %16
%24 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i64 0, i64 0
store i8 -29, i8* %24
store i32 1, i32* %5
%25 = load i32, i32* %4
%26 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i64 0, i64 0
%27 = load i32, i32* %5
%28 = call i32 @write(i32 %25, i8* %26, i32 %27)
%29 = load i32, i32* %5
%30 = icmp ne i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %23
store i32 -3, i32* %2
br label %61
32: ; preds = %23
store i32 4, i32* %5
%33 = load i32, i32* %4
%34 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i64 0, i64 0
%35 = load i32, i32* %5
%36 = call i32 @read(i32 %33, i8* %34, i32 %35)
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = load i32, i32* %5
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %43
40: ; preds = %32
%41 = load i32, i32* %8
%42 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %40, %32
%44 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i64 0, i64 0
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = shl i32 %46, 8
%48 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i64 0, i64 1
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = or i32 %47, %50
%52 = sext i32 %51 to i64
store i64 %52, i64* %9
%53 = load i64, i64* %9
%54 = sitofp i64 %53 to double
%55 = fmul double 1.752000e+02, %54
%56 = fdiv double %55, 6.553600e+04
%57 = fsub double %56, 4.685000e+01
%58 = fptrunc double %57 to float
store float %58, float* %10
%59 = load float, float* %10
%60 = load float*, float** %3
store float %59, float* %60
store i32 0, i32* %2
br label %61
61: ; preds = %43, %31, %22, %15
%62 = load i32, i32* %2
ret i32 %62
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@I2C_SLAVE = global i32 0
@.str.1 = [43 x i8] c"Failed to read from the i2c bus., il = %d\0A\00"
define i32 @si7021_read_temperature(float* nocapture writeonly %0) {
%2 = alloca [60 x i8]
%3 = getelementptr inbounds [60 x i8], [60 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %32, label %7
7: ; preds = %1
%8 = load i32, i32* @I2C_SLAVE
%9 = tail call i64 @ioctl(i32 %5, i32 %8, i32 64)
%10 = icmp slt i64 %9, 0
br i1 %10, label %32, label %11
11: ; preds = %7
store i8 -29, i8* %3
%12 = call i32 @write(i32 %5, i8* %3, i32 1)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %32
14: ; preds = %11
%15 = call i32 @read(i32 %5, i8* %3, i32 4)
%16 = icmp eq i32 %15, 4
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %19
19: ; preds = %17, %14
%20 = load i8, i8* %3
%21 = zext i8 %20 to i64
%22 = shl nuw nsw i64 %21, 8
%23 = getelementptr inbounds [60 x i8], [60 x i8]* %2, i64 0, i64 1
%24 = load i8, i8* %23
%25 = zext i8 %24 to i64
%26 = or i64 %22, %25
%27 = sitofp i64 %26 to double
%28 = fmul double %27, 1.752000e+02
%29 = fmul double %28, 0x3EF0000000000000
%30 = fadd double %29, -4.685000e+01
%31 = fptrunc double %30 to float
store float %31, float* %0
br label %32
32: ; preds = %19, %7, %11, %1
%33 = phi i32 [ -1, %1 ], [ 0, %19 ], [ -2, %7 ], [ -3, %11 ]
ret i32 %33
}