#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*/ O_RDWR;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ selectDevice(int, int, char *);
int /*<<< orphan*/ writeToDevice(int, char *, int);
int initI2Cdevices(void) {
  int i2c;
  if ((i2c = open("/dev/i2c-0", O_RDWR)) < 0) {
    perror("Failed to open i2c bus");
    exit(1);
  }
  selectDevice(i2c, 0x53, "ADXL345");
  writeToDevice(i2c, "\x2d\x00", 2);
  writeToDevice(i2c, "\x2d\x10", 2);
  writeToDevice(i2c, "\x2d\x08", 2);
  writeToDevice(i2c, "\x31\x00", 2);
  writeToDevice(i2c, "\x31\x0b", 2);
  selectDevice(i2c, 0x68, "ITG3200");
  writeToDevice(i2c, "\x16\b00011000", 2);
  return i2c;
}


x86 assembly (clang, -O0):
<initI2Cdevices>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    118f <initI2Cdevices+0x3f>
lea    0xe8b(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%edi
mov    $0x53,%esi
lea    0xe84(%rip),%rdx
call   1070 <selectDevice@plt>
mov    -0x4(%rbp),%edi
lea    0xe99(%rip),%rsi
mov    $0x2,%edx
call   1030 <writeToDevice@plt>
mov    -0x4(%rbp),%edi
lea    0xe69(%rip),%rsi
mov    $0x2,%edx
call   1030 <writeToDevice@plt>
mov    -0x4(%rbp),%edi
lea    0xe58(%rip),%rsi
mov    $0x2,%edx
call   1030 <writeToDevice@plt>
mov    -0x4(%rbp),%edi
lea    0xe60(%rip),%rsi
mov    $0x2,%edx
call   1030 <writeToDevice@plt>
mov    -0x4(%rbp),%edi
lea    0xe33(%rip),%rsi
mov    $0x2,%edx
call   1030 <writeToDevice@plt>
mov    -0x4(%rbp),%edi
mov    $0x68,%esi
lea    0xe1d(%rip),%rdx
call   1070 <selectDevice@plt>
mov    -0x4(%rbp),%edi
lea    0xe16(%rip),%rsi
mov    $0x2,%edx
call   1030 <writeToDevice@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initI2Cdevices>:
push   %rbx
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1040 <open@plt>
test   %eax,%eax
js     120c <initI2Cdevices+0xbc>
mov    %eax,%ebx
lea    0xeab(%rip),%rdx
mov    %eax,%edi
mov    $0x53,%esi
call   1070 <selectDevice@plt>
lea    0xebc(%rip),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1030 <writeToDevice@plt>
lea    0xe8d(%rip),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1030 <writeToDevice@plt>
lea    0xe7d(%rip),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1030 <writeToDevice@plt>
lea    0xe86(%rip),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1030 <writeToDevice@plt>
lea    0xe5a(%rip),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1030 <writeToDevice@plt>
lea    0xe4a(%rip),%rdx
mov    %ebx,%edi
mov    $0x68,%esi
call   1070 <selectDevice@plt>
lea    0xe3f(%rip),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1030 <writeToDevice@plt>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xdf8(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/i2c-0\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"Failed to open i2c bus\00"
@.str.2 = [8 x i8] c"ADXL345\00"
@.str.3 = [3 x i8] c"-\00\00"
@.str.4 = [3 x i8] c"-\10\00"
@.str.5 = [3 x i8] c"-\08\00"
@.str.6 = [3 x i8] c"1\00\00"
@.str.7 = [3 x i8] c"1\0B\00"
@.str.8 = [8 x i8] c"ITG3200\00"
@.str.9 = [11 x i8] c"\16\0800011000\00"
define i32 @initI2Cdevices() {
%1 = alloca i32
%2 = load i32, i32* @O_RDWR
%3 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %2)
store i32 %3, i32* %1
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = load i32, i32* %1
%10 = call i32 @selectDevice(i32 %9, i32 83, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* %1
%12 = call i32 @writeToDevice(i32 %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%13 = load i32, i32* %1
%14 = call i32 @writeToDevice(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%15 = load i32, i32* %1
%16 = call i32 @writeToDevice(i32 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%17 = load i32, i32* %1
%18 = call i32 @writeToDevice(i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 2)
%19 = load i32, i32* %1
%20 = call i32 @writeToDevice(i32 %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 2)
%21 = load i32, i32* %1
%22 = call i32 @selectDevice(i32 %21, i32 104, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%23 = load i32, i32* %1
%24 = call i32 @writeToDevice(i32 %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i32 2)
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-0\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"Failed to open i2c bus\00"
@.str.2 = [8 x i8] c"ADXL345\00"
@.str.3 = [3 x i8] c"-\00\00"
@.str.4 = [3 x i8] c"-\10\00"
@.str.5 = [3 x i8] c"-\08\00"
@.str.6 = [3 x i8] c"1\00\00"
@.str.7 = [3 x i8] c"1\0B\00"
@.str.8 = [8 x i8] c"ITG3200\00"
@.str.9 = [11 x i8] c"\16\0800011000\00"
define i32 @initI2Cdevices() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = tail call i32 @selectDevice(i32 %2, i32 83, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @writeToDevice(i32 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%10 = tail call i32 @writeToDevice(i32 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%11 = tail call i32 @writeToDevice(i32 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%12 = tail call i32 @writeToDevice(i32 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 2)
%13 = tail call i32 @writeToDevice(i32 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 2)
%14 = tail call i32 @selectDevice(i32 %2, i32 104, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%15 = tail call i32 @writeToDevice(i32 %2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i32 2)
ret i32 %2
}