#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*/ exit(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sleep(double);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int file;
  char *bus = "/dev/i2c-1";
  if ((file = open(bus, O_RDWR)) < 0) {
    printf("Failed to open the bus. \n");
    exit(1);
  }
  ioctl(file, I2C_SLAVE, 0x53);
  char config[2] = {0};
  config[0] = 0x2C;
  config[1] = 0x0B;
  write(file, config, 2);
  config[0] = 0x2D;
  config[1] = 0x08;
  write(file, config, 2);
  config[0] = 0x31;
  config[1] = 0x08;
  write(file, config, 2);
  sleep(1);
  char reg[1] = {0x32};
  write(file, reg, 1);
  char data[6] = {0};
  while (1) {
    if (read(file, data, 6) != 6) {
      printf("Erorr : Input/output Erorr \n");
      exit(1);
    } else {
      int xAccl = ((data[1] & 0x03) * 256 + (data[0] & 0xFF));
      if (xAccl > 511) {
        xAccl -= 1024;
      }
      int yAccl = ((data[3] & 0x03) * 256 + (data[2] & 0xFF));
      if (yAccl > 511) {
        yAccl -= 1024;
      }
      int zAccl = ((data[5] & 0x03) * 256 + (data[4] & 0xFF));
      if (zAccl > 511) {
        zAccl -= 1024;
      }
      printf("Acceleration in X-Axis : %d \n", xAccl);
      printf("Acceleration in Y-Axis : %d \n", yAccl);
      printf("Acceleration in Z-Axis : %d \n", zAccl);
    }
    sleep(0.5);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11d0 <main+0x50>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
mov    $0x53,%edx
call   1060 <ioctl@plt>
lea    -0x12(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1050 <memset@plt>
movb   $0x2c,-0x12(%rbp)
movb   $0xb,-0x11(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
movb   $0x2d,-0x12(%rbp)
movb   $0x8,-0x11(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
movb   $0x31,-0x12(%rbp)
movb   $0x8,-0x11(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
movsd  0xdb7(%rip),%xmm0
call   10a0 <sleep@plt>
mov    0xe58(%rip),%al
mov    %al,-0x13(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x13(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
lea    -0x19(%rbp),%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x6,%edx
call   1070 <read@plt>
cmp    $0x6,%eax
je     12aa <main+0x12a>
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movsbl -0x18(%rbp),%eax
and    $0x3,%eax
shl    $0x8,%eax
movsbl -0x19(%rbp),%ecx
and    $0xff,%ecx
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x1ff,-0x20(%rbp)
jle    12db <main+0x15b>
mov    -0x20(%rbp),%eax
sub    $0x400,%eax
mov    %eax,-0x20(%rbp)
movsbl -0x16(%rbp),%eax
and    $0x3,%eax
shl    $0x8,%eax
movsbl -0x17(%rbp),%ecx
and    $0xff,%ecx
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x1ff,-0x24(%rbp)
jle    130c <main+0x18c>
mov    -0x24(%rbp),%eax
sub    $0x400,%eax
mov    %eax,-0x24(%rbp)
movsbl -0x14(%rbp),%eax
and    $0x3,%eax
shl    $0x8,%eax
movsbl -0x15(%rbp),%ecx
and    $0xff,%ecx
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x1ff,-0x28(%rbp)
jle    133d <main+0x1bd>
mov    -0x28(%rbp),%eax
sub    $0x400,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%esi
lea    0xd0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xd18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xd25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  0xc90(%rip),%xmm0
call   10a0 <sleep@plt>
jmp    1278 <main+0xf8>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
lea    0xe72(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
jns    11b3 <main+0x33>
lea    0xee3(%rip),%rdi
jmp    132e <main+0x1ae>
mov    %eax,%ebx
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x53,%edx
call   1060 <ioctl@plt>
movw   $0xb2c,0xc(%rsp)
lea    0xc(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1040 <write@plt>
movw   $0x82d,0xc(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1040 <write@plt>
movw   $0x831,0xc(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1040 <write@plt>
movsd  0xde7(%rip),%xmm0
call   10a0 <sleep@plt>
movb   $0x32,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1040 <write@plt>
movw   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x6,%edx
call   1070 <read@plt>
cmp    $0x6,%eax
jne    1327 <main+0x1a7>
lea    0xdd5(%rip),%r15
lea    0xdec(%rip),%r12
lea    0x10(%rsp),%r13
movzbl 0x11(%rsp),%eax
and    $0x3,%eax
shl    $0x8,%eax
movzbl 0x10(%rsp),%ecx
lea    (%rax,%rcx,1),%edx
cmp    $0x200,%edx
lea    -0x400(%rax,%rcx,1),%esi
cmovb  %edx,%esi
movzbl 0x13(%rsp),%eax
and    $0x3,%eax
shl    $0x8,%eax
movzbl 0x12(%rsp),%ecx
lea    (%rax,%rcx,1),%edx
cmp    $0x200,%edx
lea    -0x400(%rax,%rcx,1),%ebp
cmovb  %edx,%ebp
movzbl 0x15(%rsp),%eax
and    $0x3,%eax
shl    $0x8,%eax
movzbl 0x14(%rsp),%ecx
lea    (%rax,%rcx,1),%edx
cmp    $0x200,%edx
lea    -0x400(%rax,%rcx,1),%r14d
ff
cmovb  %edx,%r14d
lea    0xd39(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movsd  0xcfe(%rip),%xmm0
call   10a0 <sleep@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x6,%edx
call   1070 <read@plt>
cmp    $0x6,%eax
je     1270 <main+0xf0>
lea    0xd47(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

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
@__const.main.reg = [1 x i8] c"2"
@.str.2 = [29 x i8] c"Erorr : Input/output Erorr \0A\00"
@.str.3 = [30 x i8] c"Acceleration in X-Axis : %d \0A\00"
@.str.4 = [30 x i8] c"Acceleration in Y-Axis : %d \0A\00"
@.str.5 = [30 x i8] c"Acceleration in Z-Axis : %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [2 x i8]
%5 = alloca [1 x i8]
%6 = alloca [6 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %3
%10 = load i8*, i8** %3
%11 = load i32, i32* @O_RDWR
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %2
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = load i32, i32* %2
%19 = load i32, i32* @I2C_SLAVE
%20 = call i32 @ioctl(i32 %18, i32 %19, i32 83)
%21 = bitcast [2 x i8]* %4 to i8*
%22 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
store i8 44, i8* %22
%23 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
store i8 11, i8* %23
%24 = load i32, i32* %2
%25 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%26 = call i32 @write(i32 %24, i8* %25, i32 2)
%27 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
store i8 45, i8* %27
%28 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
store i8 8, i8* %28
%29 = load i32, i32* %2
%30 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%31 = call i32 @write(i32 %29, i8* %30, i32 2)
%32 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
store i8 49, i8* %32
%33 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
store i8 8, i8* %33
%34 = load i32, i32* %2
%35 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%36 = call i32 @write(i32 %34, i8* %35, i32 2)
%37 = call i32 @sleep(double 1.000000e+00)
%38 = bitcast [1 x i8]* %5 to i8*
%39 = load i32, i32* %2
%40 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
%41 = call i32 @write(i32 %39, i8* %40, i32 1)
%42 = bitcast [6 x i8]* %6 to i8*
br label %43
43: ; preds = %17, %106
%44 = load i32, i32* %2
%45 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%46 = call i32 @read(i32 %44, i8* %45, i32 6)
%47 = icmp ne i32 %46, 6
br i1 %47, label %48, label %51
48: ; preds = %43
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %43
%52 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 1
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = and i32 %54, 3
%56 = mul nsw i32 %55, 256
%57 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = and i32 %59, 255
%61 = add nsw i32 %56, %60
store i32 %61, i32* %7
%62 = load i32, i32* %7
%63 = icmp sgt i32 %62, 511
br i1 %63, label %64, label %67
64: ; preds = %51
%65 = load i32, i32* %7
%66 = sub nsw i32 %65, 1024
store i32 %66, i32* %7
br label %67
67: ; preds = %64, %51
%68 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 3
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = and i32 %70, 3
%72 = mul nsw i32 %71, 256
%73 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 2
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = and i32 %75, 255
%77 = add nsw i32 %72, %76
store i32 %77, i32* %8
%78 = load i32, i32* %8
%79 = icmp sgt i32 %78, 511
br i1 %79, label %80, label %83
80: ; preds = %67
%81 = load i32, i32* %8
%82 = sub nsw i32 %81, 1024
store i32 %82, i32* %8
br label %83
83: ; preds = %80, %67
%84 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 5
%85 = load i8, i8* %84
%86 = sext i8 %85 to i32
%87 = and i32 %86, 3
%88 = mul nsw i32 %87, 256
%89 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 4
%90 = load i8, i8* %89
%91 = sext i8 %90 to i32
%92 = and i32 %91, 255
%93 = add nsw i32 %88, %92
store i32 %93, i32* %9
%94 = load i32, i32* %9
%95 = icmp sgt i32 %94, 511
br i1 %95, label %96, label %99
96: ; preds = %83
%97 = load i32, i32* %9
%98 = sub nsw i32 %97, 1024
store i32 %98, i32* %9
br label %99
99: ; preds = %96, %83
%100 = load i32, i32* %7
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %100)
%102 = load i32, i32* %8
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %102)
%104 = load i32, i32* %9
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %104)
br label %106
106: ; preds = %99
%107 = call i32 @sleep(double 5.000000e-01)
br label %43
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@I2C_SLAVE = global i32 0
@.str.3 = [30 x i8] c"Acceleration in X-Axis : %d \0A\00"
@.str.4 = [30 x i8] c"Acceleration in Y-Axis : %d \0A\00"
@.str.5 = [30 x i8] c"Acceleration in Z-Axis : %d \0A\00"
@str = [28 x i8] c"Erorr : Input/output Erorr \00"
@str.6 = [25 x i8] c"Failed to open the bus. \00"
define i32 @main() {
%1 = alloca i16
%2 = alloca [1 x i8]
%3 = alloca [6 x i8]
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = bitcast i16* %1 to [2 x i8]*
%12 = load i32, i32* @I2C_SLAVE
%13 = tail call i32 @ioctl(i32 %5, i32 %12, i32 83)
%14 = bitcast i16* %1 to i8*
store i16 2860, i16* %1
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %11, i64 0, i64 1
%16 = call i32 @write(i32 %5, i8* %14, i32 2)
store i8 45, i8* %14
store i8 8, i8* %15
%17 = call i32 @write(i32 %5, i8* %14, i32 2)
store i8 49, i8* %14
store i8 8, i8* %15
%18 = call i32 @write(i32 %5, i8* %14, i32 2)
%19 = tail call i32 @sleep(double 1.000000e+00)
%20 = getelementptr inbounds [1 x i8], [1 x i8]* %2, i64 0, i64 0
store i8 50, i8* %20
%21 = call i32 @write(i32 %5, i8* %20, i32 1)
%22 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%23 = call i32 @read(i32 %5, i8* %22, i32 6)
%24 = icmp eq i32 %23, 6
br i1 %24, label %25, label %31
25: ; preds = %10
%26 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 1
%27 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 3
%28 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 2
%29 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 5
%30 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 4
br label %34
31: ; preds = %34, %10
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %25, %34
%35 = load i8, i8* %26
%36 = and i8 %35, 3
%37 = zext i8 %36 to i32
%38 = shl nuw nsw i32 %37, 8
%39 = load i8, i8* %22
%40 = zext i8 %39 to i32
%41 = or i32 %38, %40
%42 = icmp ugt i32 %41, 511
%43 = or i32 %41, -1024
%44 = select i1 %42, i32 %43, i32 %41
%45 = load i8, i8* %27
%46 = and i8 %45, 3
%47 = zext i8 %46 to i32
%48 = shl nuw nsw i32 %47, 8
%49 = load i8, i8* %28
%50 = zext i8 %49 to i32
%51 = or i32 %48, %50
%52 = icmp ugt i32 %51, 511
%53 = or i32 %51, -1024
%54 = select i1 %52, i32 %53, i32 %51
%55 = load i8, i8* %29
%56 = and i8 %55, 3
%57 = zext i8 %56 to i32
%58 = shl nuw nsw i32 %57, 8
%59 = load i8, i8* %30
%60 = zext i8 %59 to i32
%61 = or i32 %58, %60
%62 = icmp ugt i32 %61, 511
%63 = or i32 %61, -1024
%64 = select i1 %62, i32 %63, i32 %61
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %54)
%67 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %64)
%68 = tail call i32 @sleep(double 5.000000e-01)
%69 = call i32 @read(i32 %5, i8* %22, i32 6)
%70 = icmp eq i32 %69, 6
br i1 %70, label %34, label %31
}