#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 int8_t;

/* Variables and functions */
int /*<<< orphan*/ I2C_SLAVE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ exit(int);
int i2c_smbus_read_byte_data(int, int);
int /*<<< orphan*/ i2c_smbus_write_byte_data(int, int, int);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int initIMU(char *fileName, int address) {
  int fd;
  if ((fd = open(fileName, O_RDWR)) < 0) {
    printf("Failed to open i2c port\n");
    exit(1);
  }
  if (ioctl(fd, I2C_SLAVE, address) < 0) {
    printf("Unable to get bus access to talk to slave\n");
    exit(1);
  }
  int8_t power = i2c_smbus_read_byte_data(fd, 0x6b);
  i2c_smbus_write_byte_data(fd, 0x6b, ~(1 << 6) & power);
  return fd;
}


x86 assembly (clang, -O0):
<initIMU>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    11a3 <initIMU+0x43>
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%edi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    11d7 <initIMU+0x77>
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%edi
mov    $0x6b,%esi
call   1070 <i2c_smbus_read_byte_data@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%edx
and    $0xffffffbf,%edx
mov    $0x6b,%esi
call   1050 <i2c_smbus_write_byte_data@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initIMU>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     11b6 <initIMU+0x56>
mov    %eax,%ebx
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %ebp,%edx
call   1040 <ioctl@plt>
test   %rax,%rax
js     11bf <initIMU+0x5f>
mov    %ebx,%edi
mov    $0x6b,%esi
call   1070 <i2c_smbus_read_byte_data@plt>
and    $0xffffffbf,%eax
mov    %ebx,%edi
mov    $0x6b,%esi
mov    %eax,%edx
call   1050 <i2c_smbus_write_byte_data@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe6d(%rip),%rdi
jmp    11c6 <initIMU+0x66>
lea    0xe3a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [25 x i8] c"Failed to open i2c port\0A\00"
@I2C_SLAVE = global i32 0
@.str.1 = [43 x i8] c"Unable to get bus access to talk to slave\0A\00"
define i32 @initIMU(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i32, i32* %5
%16 = load i32, i32* @I2C_SLAVE
%17 = load i32, i32* %4
%18 = call i64 @ioctl(i32 %15, i32 %16, i32 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = load i32, i32* %5
%25 = call i32 @i2c_smbus_read_byte_data(i32 %24, i32 107)
store i32 %25, i32* %6
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = and i32 -65, %27
%29 = call i32 @i2c_smbus_write_byte_data(i32 %26, i32 107, i32 %28)
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@I2C_SLAVE = global i32 0
@str = [42 x i8] c"Unable to get bus access to talk to slave\00"
@str.2 = [24 x i8] c"Failed to open i2c port\00"
define i32 @initIMU(i8* nocapture %0, i32 %1) {
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.2, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = load i32, i32* @I2C_SLAVE
%11 = tail call i64 @ioctl(i32 %4, i32 %10, i32 %1)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %9
%17 = tail call i32 @i2c_smbus_read_byte_data(i32 %4, i32 107)
%18 = and i32 %17, -65
%19 = tail call i32 @i2c_smbus_write_byte_data(i32 %4, i32 107, i32 %18)
ret i32 %4
}