#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*/ ADXL345_powerOn(int);
int /*<<< orphan*/ ADXL345_readAccel(int, int *, int *, int *);
int /*<<< orphan*/ I2C_SLAVE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ errno;
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int /*<<< orphan*/);
int main(void) {
  char buffer[1];
  int fd;
  int x, y, z;
  fd = open("/dev/i2c-1", O_RDWR);
  if (fd < 0) {
    printf("Error opening file: %s\n", strerror(errno));
    return 1;
  }
  if (ioctl(fd, I2C_SLAVE, (0x53)) < 0) {
    printf("ioctl error: %s\n", strerror(errno));
    return 1;
  }
  ADXL345_powerOn(fd);
  ADXL345_readAccel(fd, &x, &y, &z);
  printf("Values: X: %d\tY: %d\tZ: %d\n", x, y, z);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11bc <main+0x5c>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1241 <main+0xe1>
mov    -0xc(%rbp),%edi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
mov    $0x53,%edx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    1207 <main+0xa7>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1241 <main+0xe1>
mov    -0xc(%rbp),%edi
call   1070 <ADXL345_powerOn@plt>
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1030 <ADXL345_readAccel@plt>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11d5 <main+0x75>
mov    %eax,%ebx
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x53,%edx
call   1050 <ioctl@plt>
test   %rax,%rax
js     11ec <main+0x8c>
mov    %ebx,%edi
call   1070 <ADXL345_powerOn@plt>
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
call   1030 <ADXL345_readAccel@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    0x4(%rsp),%ecx
lea    0xe6a(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1210 <main+0xb0>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe21(%rip),%rdi
jmp    1201 <main+0xa1>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe22(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%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 = [24 x i8] c"Error opening file: %s\0A\00"
@errno = global i32 0
@I2C_SLAVE = global i32 0
@.str.2 = [17 x i8] c"ioctl error: %s\0A\00"
@.str.3 = [27 x i8] c"Values: X: %d\09Y: %d\09Z: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = load i32, i32* @O_RDWR
%8 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %13)
store i32 1, i32* %1
br label %33
15: ; preds = %0
%16 = load i32, i32* %3
%17 = load i32, i32* @I2C_SLAVE
%18 = call i64 @ioctl(i32 %16, i32 %17, i32 83)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %22)
store i32 1, i32* %1
br label %33
24: ; preds = %15
%25 = load i32, i32* %3
%26 = call i32 @ADXL345_powerOn(i32 %25)
%27 = load i32, i32* %3
%28 = call i32 @ADXL345_readAccel(i32 %27, i32* %4, i32* %5, i32* %6)
%29 = load i32, i32* %4
%30 = load i32, i32* %5
%31 = load i32, i32* %6
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %29, i32 %30, i32 %31)
store i32 0, i32* %1
br label %33
33: ; preds = %24, %20, %11
%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
@.str.1 = [24 x i8] c"Error opening file: %s\0A\00"
@errno = global i32 0
@I2C_SLAVE = global i32 0
@.str.2 = [17 x i8] c"ioctl error: %s\0A\00"
@.str.3 = [27 x i8] c"Values: X: %d\09Y: %d\09Z: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = load i32, i32* @O_RDWR
%8 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %29
14: ; preds = %0
%15 = load i32, i32* @I2C_SLAVE
%16 = tail call i64 @ioctl(i32 %8, i32 %15, i32 83)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %29
22: ; preds = %14
%23 = tail call i32 @ADXL345_powerOn(i32 %8)
%24 = call i32 @ADXL345_readAccel(i32 %8, i32* %1, i32* %2, i32* %3)
%25 = load i32, i32* %1
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %25, i32 %26, i32 %27)
br label %29
29: ; preds = %22, %18, %10
%30 = phi i32 [ 1, %10 ], [ 1, %18 ], [ 0, %22 ]
ret i32 %30
}