#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;
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, char);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(double);
int /*<<< orphan*/ write(int, char *, int);
int HDC1080_open() {
  char *bus = "/dev/i2c-1";
  int fd = open(bus, O_RDWR);
  if (fd < 0) {
    printf("Failure HDC1080: Failed to open the bus.\n");
    return -1;
  }
  ioctl(fd, I2C_SLAVE, (char)0x40);
  char config[3] = {0};
  config[0] = (char)0x02;
  config[1] = (char)0x10;
  config[2] = 0x00;
  write(fd, config, 3);
  sleep(0.015);
  return fd;
}


x86 assembly (clang, -O0):
<HDC1080_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe99(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11aa <HDC1080_open+0x4a>
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1200 <HDC1080_open+0xa0>
mov    -0x14(%rbp),%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
mov    $0x40,%edx
call   1060 <ioctl@plt>
lea    -0x17(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1050 <memset@plt>
movb   $0x2,-0x17(%rbp)
movb   $0x10,-0x16(%rbp)
movb   $0x0,-0x15(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x17(%rbp),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
movsd  0xe0b(%rip),%xmm0
call   1080 <sleep@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HDC1080_open>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xea3(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11b1 <HDC1080_open+0x61>
mov    %eax,%ebx
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x40,%edx
call   1050 <ioctl@plt>
movw   $0x1002,0xd(%rsp)
movb   $0x0,0xf(%rsp)
lea    0xd(%rsp),%rsi
mov    %ebx,%edi
mov    $0x3,%edx
call   1040 <write@plt>
movsd  0xe56(%rip),%xmm0
call   1070 <sleep@plt>
jmp    11c2 <HDC1080_open+0x72>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@.str.1 = [42 x i8] c"Failure HDC1080: Failed to open the bus.\0A\00"
@I2C_SLAVE = global i32 0
define i32 @HDC1080_open() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [3 x i8]
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* %5, i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %25
12: ; preds = %0
%13 = load i32, i32* %3
%14 = load i32, i32* @I2C_SLAVE
%15 = call i32 @ioctl(i32 %13, i32 %14, i8 signext 64)
%16 = bitcast [3 x i8]* %4 to i8*
%17 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
store i8 2, i8* %17
%18 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
store i8 16, i8* %18
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
store i8 0, i8* %19
%20 = load i32, i32* %3
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%22 = call i32 @write(i32 %20, i8* %21, i32 3)
%23 = call i32 @sleep(double 1.500000e-02)
%24 = load i32, i32* %3
store i32 %24, i32* %1
br label %25
25: ; preds = %12, %10
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@I2C_SLAVE = global i32 0
@str = [41 x i8] c"Failure HDC1080: Failed to open the bus.\00"
define i32 @HDC1080_open() {
%1 = alloca [3 x i8]
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
br label %15
7: ; preds = %0
%8 = load i32, i32* @I2C_SLAVE
%9 = tail call i32 @ioctl(i32 %3, i32 %8, i8 signext 64)
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
store i8 2, i8* %10
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 1
store i8 16, i8* %11
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 2
store i8 0, i8* %12
%13 = call i32 @write(i32 %3, i8* %10, i32 3)
%14 = tail call i32 @sleep(double 1.500000e-02)
br label %15
15: ; preds = %7, %5
%16 = phi i32 [ -1, %5 ], [ %3, %7 ]
ret i32 %16
}