#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*/ uint16_t;
struct timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int, int, int, int);
int raw_to_RH(int /*<<< orphan*/);
int raw_to_temp(int /*<<< orphan*/);
scalar_t__ read_value(int, int, int, int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int i2c_file;
  if ((i2c_file = open(argv[1], O_RDWR)) < 0) {
    perror("Unable to open i2c control file");
    exit(1);
  }
  uint16_t temperature_raw;
  uint16_t humidity_raw;
  if (read_value(i2c_file, 0x40, 0xE3, &temperature_raw)) {
    perror("read temp error");
    exit(1);
  }
  if (read_value(i2c_file, 0x40, 0xE5, &humidity_raw)) {
    perror("read temp error");
    exit(1);
  }
  int temperature = raw_to_temp(temperature_raw);
  int humidity = raw_to_RH(humidity_raw);
  struct timeval t;
  gettimeofday(&t, NULL);
  printf("%u.%06u %i.%02i %i\n", t.tv_sec, t.tv_usec, temperature / 100,
         temperature % 100, humidity);
  close(i2c_file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11de <main+0x4e>
lea    0xe31(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x40,%esi
mov    $0xe3,%edx
lea    -0x18(%rbp),%rcx
call   1030 <read_value@plt>
cmp    $0x0,%rax
je     1214 <main+0x84>
lea    0xe1b(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x40,%esi
mov    $0xe5,%edx
lea    -0x1c(%rbp),%rcx
call   1030 <read_value@plt>
cmp    $0x0,%rax
je     124a <main+0xba>
lea    0xde5(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1080 <raw_to_temp@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <raw_to_RH@plt>
mov    %eax,-0x24(%rbp)
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
mov    $0x64,%edi
cltd
idiv   %edi
mov    %edx,%r8d
mov    -0x34(%rbp),%edx
mov    -0x24(%rbp),%r9d
lea    0xd91(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x8(%rsi),%rdi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
test   %eax,%eax
js     125d <main+0xcd>
mov    %eax,%ebx
lea    0x4(%rsp),%rcx
mov    %eax,%edi
mov    $0x40,%esi
mov    $0xe3,%edx
call   1030 <read_value@plt>
test   %rax,%rax
jne    1254 <main+0xc4>
mov    %rsp,%rcx
mov    %ebx,%edi
mov    $0x40,%esi
mov    $0xe5,%edx
call   1030 <read_value@plt>
test   %rax,%rax
jne    1254 <main+0xc4>
mov    0x4(%rsp),%edi
call   1080 <raw_to_temp@plt>
mov    %eax,%ebp
mov    (%rsp),%edi
call   1070 <raw_to_RH@plt>
mov    %eax,%r14d
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
movslq %ebp,%r8
imul   $0x51eb851f,%r8,%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
sar    $0x25,%rcx
add    %eax,%ecx
imul   $0x64,%ecx,%eax
sub    %eax,%r8d
lea    0xdf6(%rip),%rdi
mov    %r14d,%r9d
call   1040 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdc5(%rip),%rdi
jmp    1264 <main+0xd4>
lea    0xd9c(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@O_RDWR = global i32 0
@.str = [32 x i8] c"Unable to open i2c control file\00"
@.str.1 = [16 x i8] c"read temp error\00"
@.str.2 = [20 x i8] c"%u.%06u %i.%02i %i\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDWR
%16 = call i32 @open(i8* %14, i32 %15)
store i32 %16, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i32, i32* %6
%23 = call i64 @read_value(i32 %22, i32 64, i32 227, i32* %7)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %21
%29 = load i32, i32* %6
%30 = call i64 @read_value(i32 %29, i32 64, i32 229, i32* %8)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %28
%36 = load i32, i32* %7
%37 = call i32 @raw_to_temp(i32 %36)
store i32 %37, i32* %9
%38 = load i32, i32* %8
%39 = call i32 @raw_to_RH(i32 %38)
store i32 %39, i32* %10
%40 = call i32 @gettimeofday(%struct.timeval* %11, i32* null)
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%42 = load i32, i32* %41
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%44 = load i32, i32* %43
%45 = load i32, i32* %9
%46 = sdiv i32 %45, 100
%47 = load i32, i32* %9
%48 = srem i32 %47, 100
%49 = load i32, i32* %10
%50 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %42, i32 %44, i32 %46, i32 %48, i32 %49)
%51 = load i32, i32* %6
%52 = call i32 @close(i32 %51)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@O_RDWR = global i32 0
@.str = [32 x i8] c"Unable to open i2c control file\00"
@.str.1 = [16 x i8] c"read temp error\00"
@.str.2 = [20 x i8] c"%u.%06u %i.%02i %i\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = load i32, i32* @O_RDWR
%9 = tail call i32 @open(i8* %7, i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = bitcast i32* %3 to i8*
%16 = bitcast i32* %4 to i8*
%17 = call i64 @read_value(i32 %9, i32 64, i32 227, i32* %3)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %14
%23 = call i64 @read_value(i32 %9, i32 64, i32 229, i32* %4)
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %22
%29 = load i32, i32* %3
%30 = call i32 @raw_to_temp(i32 %29)
%31 = load i32, i32* %4
%32 = call i32 @raw_to_RH(i32 %31)
%33 = bitcast %struct.timeval* %5 to i8*
%34 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%36 = load i32, i32* %35
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%38 = load i32, i32* %37
%39 = sdiv i32 %30, 100
%40 = srem i32 %30, 100
%41 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %36, i32 %38, i32 %39, i32 %40, i32 %32)
%42 = call i32 @close(i32 %9)
ret i32 0
}