#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, short, short, short, ...);
int read(int, unsigned char *, int);
int /*<<< orphan*/ selectDevice(int, int, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usleep(int);
int write(int, unsigned char *, int);
int /*<<< orphan*/ writeToDevice(int, int, int);
int main(int argc, char **argv) {
  unsigned int range;
  int count, b;
  short x, y, z;
  float xa, ya, za;
  int fd;
  unsigned char buf[16];
  if ((fd = open("/dev/i2c-1", O_RDWR)) < 0) {
    fprintf(stderr, "Failed to open i2c bus\n");
    exit(1);
  }
  selectDevice(fd, 0x53, "ADXL345");
  writeToDevice(fd, 0x2d, 0);
  writeToDevice(fd, 0x2d, 16);
  writeToDevice(fd, 0x2d, 8);
  writeToDevice(fd, 0x31, 0);
  while (1) {
    selectDevice(fd, 0x53, "ADXL345");
    buf[0] = 0x32;
    if ((write(fd, buf, 1)) != 1) {
      fprintf(stderr, "Error writing to i2c slave\n");
    }
    if (read(fd, buf, 6) != 6) {
      fprintf(stderr, "Unable to read from ADXL345\n");
    } else {
      printf("%d %d %d %d %d %d\n", buf[0], buf[1], buf[2], buf[3], buf[4],
             buf[5]);
      x = buf[1] << 8 | buf[0];
      y = buf[3] << 8 | buf[2];
      z = buf[5] << 8 | buf[4];
      xa = (90.0 / 256.0) * (float)x;
      ya = (90.0 / 256.0) * (float)y;
      za = (90.0 / 256.0) * (float)z;
      printf("x=%d, y=%d, z=%d\n", x, y, z);
    }
    usleep(90000);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    0xe52(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    11e6 <main+0x56>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x34(%rbp),%edi
mov    $0x53,%esi
lea    0xe36(%rip),%rdx
call   10a0 <selectDevice@plt>
mov    -0x34(%rbp),%edi
mov    $0x2d,%esi
xor    %edx,%edx
call   1050 <writeToDevice@plt>
mov    -0x34(%rbp),%edi
mov    $0x2d,%esi
mov    $0x10,%edx
call   1050 <writeToDevice@plt>
mov    -0x34(%rbp),%edi
mov    $0x2d,%esi
mov    $0x8,%edx
call   1050 <writeToDevice@plt>
mov    -0x34(%rbp),%edi
mov    $0x31,%esi
xor    %edx,%edx
call   1050 <writeToDevice@plt>
mov    -0x34(%rbp),%edi
mov    $0x53,%esi
lea    0xde0(%rip),%rdx
call   10a0 <selectDevice@plt>
movb   $0x32,-0x50(%rbp)
mov    -0x34(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     1283 <main+0xf3>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
lea    0xdb5(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x34(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x6,%edx
call   1060 <read@plt>
cmp    $0x6,%eax
je     12b7 <main+0x127>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1392 <main+0x202>
movzbl -0x50(%rbp),%esi
movzbl -0x4f(%rbp),%edx
movzbl -0x4e(%rbp),%ecx
movzbl -0x4d(%rbp),%r8d
movzbl -0x4c(%rbp),%r9d
movzbl -0x4b(%rbp),%edi
mov    %rsp,%rax
mov    %edi,(%rax)
lea    0xd8f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl -0x4f(%rbp),%eax
shl    $0x8,%eax
movzbl -0x50(%rbp),%ecx
or     %ecx,%eax
mov    %ax,-0x1e(%rbp)
movzbl -0x4d(%rbp),%eax
shl    $0x8,%eax
movzbl -0x4e(%rbp),%ecx
or     %ecx,%eax
mov    %ax,-0x20(%rbp)
movzbl -0x4b(%rbp),%eax
shl    $0x8,%eax
movzbl -0x4c(%rbp),%ecx
or     %ecx,%eax
mov    %ax,-0x22(%rbp)
movswl -0x1e(%rbp),%eax
cvtsi2ss %eax,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xcd5(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
movswl -0x20(%rbp),%eax
cvtsi2ss %eax,%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
movswl -0x22(%rbp),%eax
cvtsi2ss %eax,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xc9b(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x30(%rbp)
mov    -0x1e(%rbp),%cx
mov    -0x20(%rbp),%ax
lea    0xcfe(%rip),%rdi
movswl %cx,%esi
movswl %ax,%edx
movswl -0x22(%rbp),%ecx
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x15f90,%edi
call   10b0 <usleep@plt>
jmp    123c <main+0xac>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
lea    0xe52(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     131f <main+0x18f>
mov    %eax,%ebx
lea    0xe5f(%rip),%r12
mov    %eax,%edi
mov    $0x53,%esi
mov    %r12,%rdx
call   10a0 <selectDevice@plt>
mov    %ebx,%edi
mov    $0x2d,%esi
xor    %edx,%edx
call   1050 <writeToDevice@plt>
mov    %ebx,%edi
mov    $0x2d,%esi
mov    $0x10,%edx
call   1050 <writeToDevice@plt>
mov    %ebx,%edi
mov    $0x2d,%esi
mov    $0x8,%edx
call   1050 <writeToDevice@plt>
mov    %ebx,%edi
mov    $0x31,%esi
xor    %edx,%edx
call   1050 <writeToDevice@plt>
lea    0x10(%rsp),%r14
mov    0x2dbb(%rip),%rbp
mov    %ebx,0x24(%rsp)
jmp    12bf <main+0x12f>
cs nopw 0x0(%rax,%rax,1)
movzbl 0x10(%rsp),%ebp
movzbl 0x11(%rsp),%r13d
movzbl 0x12(%rsp),%r12d
movzbl 0x14(%rsp),%r14d
movzbl 0x13(%rsp),%r15d
movzbl 0x15(%rsp),%ebx
mov    %ebx,(%rsp)
lea    0xe08(%rip),%rdi
mov    %ebp,%esi
mov    %r13d,%edx
mov    %r12d,%ecx
mov    %r15d,%r8d
mov    %r14d,%r9d
xor    %eax,%eax
call   1040 <printf@plt>
shl    $0x8,%r13d
or     %ebp,%r13d
shl    $0x8,%r15d
or     %r12d,%r15d
shl    $0x8,%ebx
or     %r14d,%ebx
lea    0x10(%rsp),%r14
lea    0xd92(%rip),%r12
movswl %r13w,%esi
movswl %r15w,%edx
mov    0x2d38(%rip),%rbp
movswl %bx,%ecx
mov    0x24(%rsp),%ebx
lea    0xdc9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x15f90,%edi
call   10b0 <usleep@plt>
mov    %ebx,%edi
mov    $0x53,%esi
mov    %r12,%rdx
call   10a0 <selectDevice@plt>
movb   $0x32,0x10(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     12f6 <main+0x166>
mov    0x0(%rbp),%edi
lea    0xd3a(%rip),%rsi
call   1070 <fprintf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x6,%edx
call   1060 <read@plt>
cmp    $0x6,%eax
je     1230 <main+0xa0>
mov    0x0(%rbp),%edi
lea    0xd2f(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12b5 <main+0x125>
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
lea    0xcdc(%rip),%rsi
call   1070 <fprintf@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
@stderr = global i32 0
@.str.1 = [24 x i8] c"Failed to open i2c bus\0A\00"
@.str.2 = [8 x i8] c"ADXL345\00"
@.str.3 = [28 x i8] c"Error writing to i2c slave\0A\00"
@.str.4 = [29 x i8] c"Unable to read from ADXL345\0A\00"
@.str.5 = [19 x i8] c"%d %d %d %d %d %d\0A\00"
@.str.6 = [18 x i8] c"x=%d, y=%d, z=%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i16
%10 = alloca i16
%11 = alloca i16
%12 = alloca float
%13 = alloca float
%14 = alloca float
%15 = alloca i32
%16 = alloca [16 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* @O_RDWR
%18 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %17)
store i32 %18, i32* %15
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
%25 = load i32, i32* %15
%26 = call i32 @selectDevice(i32 %25, i32 83, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* %15
%28 = call i32 @writeToDevice(i32 %27, i32 45, i32 0)
%29 = load i32, i32* %15
%30 = call i32 @writeToDevice(i32 %29, i32 45, i32 16)
%31 = load i32, i32* %15
%32 = call i32 @writeToDevice(i32 %31, i32 45, i32 8)
%33 = load i32, i32* %15
%34 = call i32 @writeToDevice(i32 %33, i32 49, i32 0)
br label %35
35: ; preds = %24, %120
%36 = load i32, i32* %15
%37 = call i32 @selectDevice(i32 %36, i32 83, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %16, i64 0, i64 0
store i8 50, i8* %38
%39 = load i32, i32* %15
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %16, i64 0, i64 0
%41 = call i32 @write(i32 %39, i8* %40, i32 1)
%42 = icmp ne i32 %41, 1
br i1 %42, label %43, label %46
43: ; preds = %35
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %46
46: ; preds = %43, %35
%47 = load i32, i32* %15
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %16, i64 0, i64 0
%49 = call i32 @read(i32 %47, i8* %48, i32 6)
%50 = icmp ne i32 %49, 6
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = load i32, i32* @stderr
%53 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
br label %120
54: ; preds = %46
%55 = getelementptr inbounds [16 x i8], [16 x i8]* %16, i64 0, i64 0
%56 = load i8, i8* %55
%57 = zext i8 %56 to i16
%58 = getelementptr inbounds [16 x i8], [16 x i8]* %16, i64 0, i64 1
%59 = load i8, i8* %58
%60 = zext i8 %59 to i16
%61 = getelementptr inbounds [16 x i8], [16 x i8]* %16, i64 0, i64 2
%62 = load i8, i8* %61
%63 = zext i8 %62 to i16
%64 = getelementptr inbounds [16 x i8], [16 x i8]* %16, i64 0, i64 3
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = getelementptr inbounds [16 x i8], [16 x i8]* %16, i64 0, i64 4
%68 = load i8, i8* %67
%69 = zext i8 %68 to i32
%70 = getelementptr inbounds [16 x i8], [16 x i8]* %16, i64 0, i64 5
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = call i32 (i8*, i16, i16, i16, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i16 signext %57, i16 signext %60, i16 signext %63, i32 %66, i32 %69, i32 %72)
%74 = getelementptr inbounds [16 x i8], [16 x i8]* %16, i64 0, i64 1
%75 = load i8, i8* %74
%76 = zext i8 %75 to i32
%77 = shl i32 %76, 8
%78 = getelementptr inbounds [16 x i8], [16 x i8]* %16, i64 0, i64 0
%79 = load i8, i8* %78
%80 = zext i8 %79 to i32
%81 = or i32 %77, %80
%82 = trunc i32 %81 to i16
store i16 %82, i16* %9
%83 = getelementptr inbounds [16 x i8], [16 x i8]* %16, i64 0, i64 3
%84 = load i8, i8* %83
%85 = zext i8 %84 to i32
%86 = shl i32 %85, 8
%87 = getelementptr inbounds [16 x i8], [16 x i8]* %16, i64 0, i64 2
%88 = load i8, i8* %87
%89 = zext i8 %88 to i32
%90 = or i32 %86, %89
%91 = trunc i32 %90 to i16
store i16 %91, i16* %10
%92 = getelementptr inbounds [16 x i8], [16 x i8]* %16, i64 0, i64 5
%93 = load i8, i8* %92
%94 = zext i8 %93 to i32
%95 = shl i32 %94, 8
%96 = getelementptr inbounds [16 x i8], [16 x i8]* %16, i64 0, i64 4
%97 = load i8, i8* %96
%98 = zext i8 %97 to i32
%99 = or i32 %95, %98
%100 = trunc i32 %99 to i16
store i16 %100, i16* %11
%101 = load i16, i16* %9
%102 = sitofp i16 %101 to float
%103 = fpext float %102 to double
%104 = fmul double 0x3FD6800000000000, %103
%105 = fptrunc double %104 to float
store float %105, float* %12
%106 = load i16, i16* %10
%107 = sitofp i16 %106 to float
%108 = fpext float %107 to double
%109 = fmul double 0x3FD6800000000000, %108
%110 = fptrunc double %109 to float
store float %110, float* %13
%111 = load i16, i16* %11
%112 = sitofp i16 %111 to float
%113 = fpext float %112 to double
%114 = fmul double 0x3FD6800000000000, %113
%115 = fptrunc double %114 to float
store float %115, float* %14
%116 = load i16, i16* %9
%117 = load i16, i16* %10
%118 = load i16, i16* %11
%119 = call i32 (i8*, i16, i16, i16, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i16 signext %116, i16 signext %117, i16 signext %118)
br label %120
120: ; preds = %54, %51
%121 = call i32 @usleep(i32 90000)
br label %35
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [24 x i8] c"Failed to open i2c bus\0A\00"
@.str.2 = [8 x i8] c"ADXL345\00"
@.str.3 = [28 x i8] c"Error writing to i2c slave\0A\00"
@.str.4 = [29 x i8] c"Unable to read from ADXL345\0A\00"
@.str.5 = [19 x i8] c"%d %d %d %d %d %d\0A\00"
@.str.6 = [18 x i8] c"x=%d, y=%d, z=%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = tail call i32 @selectDevice(i32 %6, i32 83, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i32 @writeToDevice(i32 %6, i32 45, i32 0)
%15 = tail call i32 @writeToDevice(i32 %6, i32 45, i32 16)
%16 = tail call i32 @writeToDevice(i32 %6, i32 45, i32 8)
%17 = tail call i32 @writeToDevice(i32 %6, i32 49, i32 0)
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 1
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 2
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 3
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 4
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 5
br label %23
23: ; preds = %60, %12
%24 = tail call i32 @selectDevice(i32 %6, i32 83, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i8 50, i8* %4
%25 = call i32 @write(i32 %6, i8* %4, i32 1)
%26 = icmp eq i32 %25, 1
br i1 %26, label %30, label %27
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %27, %23
%31 = call i32 @read(i32 %6, i8* %4, i32 6)
%32 = icmp eq i32 %31, 6
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = tail call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
br label %60
36: ; preds = %30
%37 = load i8, i8* %4
%38 = zext i8 %37 to i16
%39 = load i8, i8* %18
%40 = zext i8 %39 to i16
%41 = load i8, i8* %19
%42 = zext i8 %41 to i16
%43 = load i8, i8* %20
%44 = zext i8 %43 to i32
%45 = load i8, i8* %21
%46 = zext i8 %45 to i32
%47 = load i8, i8* %22
%48 = zext i8 %47 to i32
%49 = tail call i32 (i8*, i16, i16, i16, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i16 signext %38, i16 signext %40, i16 signext %42, i32 %44, i32 %46, i32 %48)
%50 = shl nuw i16 %40, 8
%51 = or i16 %50, %38
%52 = zext i8 %43 to i16
%53 = shl nuw i16 %52, 8
%54 = or i16 %53, %42
%55 = zext i8 %47 to i16
%56 = shl nuw i16 %55, 8
%57 = zext i8 %45 to i16
%58 = or i16 %56, %57
%59 = tail call i32 (i8*, i16, i16, i16, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i16 signext %51, i16 signext %54, i16 signext %58)
br label %60
60: ; preds = %36, %33
%61 = tail call i32 @usleep(i32 90000)
br label %23
}