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

/* Variables and functions */
int initI2cBus(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sleep(double);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int i2cFileDesc = initI2cBus("/dev/i2c-1", 0x1C);
  char config[2] = {0};
  config[0] = 0x2A;
  config[1] = 0x00;
  write(i2cFileDesc, config, 2);
  config[0] = 0x2A;
  config[1] = 0x01;
  write(i2cFileDesc, config, 2);
  config[0] = 0x0E;
  config[1] = 0x00;
  write(i2cFileDesc, config, 2);
  sleep(0.5);
  char reg[1] = {0x00};
  write(i2cFileDesc, reg, 1);
  char data[7] = {0};
  if (read(i2cFileDesc, data, 7) != 7) {
    printf("Error : Input/Output error \n");
  } else {
    int16_t xAccl = (data[1] << 8) | (data[2]);
    int16_t yAccl = (data[3] << 8) | (data[4]);
    int16_t zAccl = (data[5] << 8) | (data[6]);
    printf("Acceleration in X-Axis : %d \n", xAccl);
    printf("Acceleration in Y-Axis : %d \n", yAccl);
    printf("Acceleration in Z-Axis : %d \n", zAccl / (zAccl - 1));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe92(%rip),%rdi
mov    $0x1c,%esi
call   1030 <initI2cBus@plt>
mov    %eax,-0x8(%rbp)
lea    -0xa(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1060 <memset@plt>
movb   $0x2a,-0xa(%rbp)
movb   $0x0,-0x9(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xa(%rbp),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
movb   $0x2a,-0xa(%rbp)
movb   $0x1,-0x9(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xa(%rbp),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
movb   $0xe,-0xa(%rbp)
movb   $0x0,-0x9(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xa(%rbp),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
movsd  0xe1a(%rip),%xmm0
call   1080 <sleep@plt>
lea    -0xb(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0xb(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
lea    -0x12(%rbp),%rdi
xor    %esi,%esi
mov    $0x7,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0x7,%edx
call   1070 <read@plt>
cmp    $0x7,%eax
je     1249 <main+0xe9>
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12b7 <main+0x157>
movsbl -0x11(%rbp),%eax
shl    $0x8,%eax
movsbl -0x10(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
movsbl -0xf(%rbp),%eax
shl    $0x8,%eax
movsbl -0xe(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
movsbl -0xd(%rbp),%eax
shl    $0x8,%eax
movsbl -0xc(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%esi
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe99(%rip),%rdi
mov    $0x1c,%esi
call   1040 <initI2cBus@plt>
mov    %eax,%ebx
movw   $0x2a,0x4(%rsp)
lea    0x4(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1050 <write@plt>
movw   $0x12a,0x4(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1050 <write@plt>
movw   $0xe,0x4(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1050 <write@plt>
movsd  0xe36(%rip),%xmm0
call   1080 <sleep@plt>
movb   $0x0,0x7(%rsp)
lea    0x7(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1050 <write@plt>
movl   $0x0,0xb(%rsp)
movl   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x7,%edx
call   1070 <read@plt>
cmp    $0x7,%eax
jne    1270 <main+0x110>
movsbl 0x9(%rsp),%eax
shl    $0x8,%eax
movsbl 0xa(%rsp),%esi
or     %eax,%esi
movsbl 0xb(%rsp),%eax
shl    $0x8,%eax
movsbl 0xc(%rsp),%ebp
or     %eax,%ebp
movsbl 0xd(%rsp),%eax
shl    $0x8,%eax
movsbl 0xe(%rsp),%ebx
or     %eax,%ebx
lea    0xdd4(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xde4(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    -0x1(%rbx),%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
lea    0xdea(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    127c <main+0x11c>
lea    0xdf6(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/i2c-1\00"
@.str.1 = [29 x i8] c"Error : Input/Output error \0A\00"
@.str.2 = [30 x i8] c"Acceleration in X-Axis : %d \0A\00"
@.str.3 = [30 x i8] c"Acceleration in Y-Axis : %d \0A\00"
@.str.4 = [30 x i8] c"Acceleration in Z-Axis : %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x i8]
%4 = alloca [1 x i8]
%5 = alloca [7 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 @initI2cBus(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 28)
store i32 %9, i32* %2
%10 = bitcast [2 x i8]* %3 to i8*
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
store i8 42, i8* %11
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 0, i8* %12
%13 = load i32, i32* %2
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%15 = call i32 @write(i32 %13, i8* %14, i32 2)
%16 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
store i8 42, i8* %16
%17 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 1, i8* %17
%18 = load i32, i32* %2
%19 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%20 = call i32 @write(i32 %18, i8* %19, i32 2)
%21 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
store i8 14, i8* %21
%22 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 0, i8* %22
%23 = load i32, i32* %2
%24 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%25 = call i32 @write(i32 %23, i8* %24, i32 2)
%26 = call i32 @sleep(double 5.000000e-01)
%27 = bitcast [1 x i8]* %4 to i8*
%28 = load i32, i32* %2
%29 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%30 = call i32 @write(i32 %28, i8* %29, i32 1)
%31 = bitcast [7 x i8]* %5 to i8*
%32 = load i32, i32* %2
%33 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 0
%34 = call i32 @read(i32 %32, i8* %33, i32 7)
%35 = icmp ne i32 %34, 7
br i1 %35, label %36, label %38
36: ; preds = %0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %72
38: ; preds = %0
%39 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 1
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = shl i32 %41, 8
%43 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 2
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = or i32 %42, %45
store i32 %46, i32* %6
%47 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 3
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = shl i32 %49, 8
%51 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 4
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = or i32 %50, %53
store i32 %54, i32* %7
%55 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 5
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = shl i32 %57, 8
%59 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 6
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = or i32 %58, %61
store i32 %62, i32* %8
%63 = load i32, i32* %6
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %63)
%65 = load i32, i32* %7
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %65)
%67 = load i32, i32* %8
%68 = load i32, i32* %8
%69 = sub nsw i32 %68, 1
%70 = sdiv i32 %67, %69
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %70)
br label %72
72: ; preds = %38, %36
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-1\00"
@.str.2 = [30 x i8] c"Acceleration in X-Axis : %d \0A\00"
@.str.3 = [30 x i8] c"Acceleration in Y-Axis : %d \0A\00"
@.str.4 = [30 x i8] c"Acceleration in Z-Axis : %d \0A\00"
@str = [28 x i8] c"Error : Input/Output error \00"
define i32 @main() {
%1 = alloca i16
%2 = bitcast i16* %1 to [2 x i8]*
%3 = alloca [1 x i8]
%4 = alloca [7 x i8]
%5 = tail call i32 @initI2cBus(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 28)
%6 = bitcast i16* %1 to i8*
store i16 42, i16* %1
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
%8 = call i32 @write(i32 %5, i8* %6, i32 2)
store i8 42, i8* %6
store i8 1, i8* %7
%9 = call i32 @write(i32 %5, i8* %6, i32 2)
store i8 14, i8* %6
store i8 0, i8* %7
%10 = call i32 @write(i32 %5, i8* %6, i32 2)
%11 = tail call i32 @sleep(double 5.000000e-01)
%12 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
store i8 0, i8* %12
%13 = call i32 @write(i32 %5, i8* %12, i32 1)
%14 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%15 = call i32 @read(i32 %5, i8* %14, i32 7)
%16 = icmp eq i32 %15, 7
br i1 %16, label %19, label %17
17: ; preds = %0
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %49
19: ; preds = %0
%20 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 1
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = shl nsw i32 %22, 8
%24 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 2
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = or i32 %23, %26
%28 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 3
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = shl nsw i32 %30, 8
%32 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 4
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = or i32 %31, %34
%36 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 5
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = shl nsw i32 %38, 8
%40 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 6
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = or i32 %39, %42
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%46 = add nsw i32 %43, -1
%47 = sdiv i32 %43, %46
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %19, %17
ret i32 0
}