#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*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(double);
int /*<<< orphan*/ write(int, char *, int);
int MMA8452Q_open() {
  int file;
  char *bus = "/dev/i2c-1";
  if ((file = open(bus, O_RDWR)) < 0) {
    printf("Failed to open the bus. \n");
    return -1;
  }
  ioctl(file, I2C_SLAVE, 0x1C);
  char config[2] = {0};
  config[0] = 0x2A;
  config[1] = 0x00;
  write(file, config, 2);
  config[0] = 0x2A;
  config[1] = 0x01;
  write(file, config, 2);
  config[0] = 0x0E;
  config[1] = 0x00;
  write(file, config, 2);
  sleep(0.5);
  return file;
}


x86 assembly (clang, -O0):
<MMA8452Q_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,-0x8(%rbp)
cmp    $0x0,%eax
jge    11a9 <MMA8452Q_open+0x49>
lea    0xe7b(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <MMA8452Q_open+0xcd>
mov    -0x8(%rbp),%edi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
mov    $0x1c,%edx
call   1060 <ioctl@plt>
lea    -0x12(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1050 <memset@plt>
movb   $0x2a,-0x12(%rbp)
movb   $0x0,-0x11(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
movb   $0x2a,-0x12(%rbp)
movb   $0x1,-0x11(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
movb   $0xe,-0x12(%rbp)
movb   $0x0,-0x11(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
movsd  0xdde(%rip),%xmm0
call   1080 <sleep@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MMA8452Q_open>:
push   %r14
push   %rbx
push   %rax
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
lea    0xea4(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11da <MMA8452Q_open+0x8a>
mov    %eax,%ebx
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x1c,%edx
call   1050 <ioctl@plt>
movw   $0x2a,0x6(%rsp)
lea    0x6(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1040 <write@plt>
movw   $0x12a,0x6(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1040 <write@plt>
movw   $0xe,0x6(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1040 <write@plt>
movsd  0xe2d(%rip),%xmm0
call   1070 <sleep@plt>
jmp    11eb <MMA8452Q_open+0x9b>
lea    0xe32(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@I2C_SLAVE = global i32 0
@str = [25 x i8] c"Failed to open the bus. \00"
define i32 @MMA8452Q_open() {
%1 = alloca i16
%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 ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %17
7: ; preds = %0
%8 = bitcast i16* %1 to [2 x i8]*
%9 = load i32, i32* @I2C_SLAVE
%10 = tail call i32 @ioctl(i32 %3, i32 %9, i32 28)
%11 = bitcast i16* %1 to i8*
store i16 42, i16* %1
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 1
%13 = call i32 @write(i32 %3, i8* %11, i32 2)
store i8 42, i8* %11
store i8 1, i8* %12
%14 = call i32 @write(i32 %3, i8* %11, i32 2)
store i8 14, i8* %11
store i8 0, i8* %12
%15 = call i32 @write(i32 %3, i8* %11, i32 2)
%16 = tail call i32 @sleep(double 5.000000e-01)
br label %17
17: ; preds = %7, %5
%18 = phi i32 [ -1, %5 ], [ %3, %7 ]
ret i32 %18
}