#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 _getReg(int);
int /*<<< orphan*/ _setReg(int, int);
int /*<<< orphan*/ delay(int);
int adxlSetup(int range) {
  if (_getReg(0x00) != 0xE5)
    return -1;
  _setReg(0x2E, 0x00);
  _setReg(0x2C, 0b00001010);
  if (_getReg(0x2D) == 0x00) {
    if (range < 0 || range > 3)
      range = 0;
    range |= 0b00101000;
    _setReg(0x31, range);
    _setReg(0x1D, 0x08);
    _setReg(0x21, 0xA0);
    _setReg(0x22, 0x00);
    _setReg(0x23, 0x00);
    _setReg(0x2A, 0b00000111);
    _setReg(0x1E, 0x00);
    _setReg(0x1F, 0x00);
    _setReg(0x20, 0x00);
    _setReg(0x2D, 0b00001000);
    delay(100);
    return 1;
  } else {
    _setReg(0x2D, 0b00001000);
    return 0;
  }
}


x86 assembly (clang, -O0):
<adxlSetup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
xor    %edi,%edi
call   1050 <_getReg@plt>
cmp    $0xe5,%eax
je     1159 <adxlSetup+0x29>
movl   $0xffffffff,-0x4(%rbp)
jmp    125c <adxlSetup+0x12c>
mov    $0x2e,%edi
xor    %esi,%esi
call   1040 <_setReg@plt>
mov    $0x2c,%edi
mov    $0xa,%esi
call   1040 <_setReg@plt>
mov    $0x2d,%edi
call   1050 <_getReg@plt>
cmp    $0x0,%eax
jne    1246 <adxlSetup+0x116>
cmpl   $0x0,-0x8(%rbp)
jl     119b <adxlSetup+0x6b>
cmpl   $0x3,-0x8(%rbp)
jle    11a2 <adxlSetup+0x72>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
or     $0x28,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
mov    $0x31,%edi
call   1040 <_setReg@plt>
mov    $0x1d,%edi
mov    $0x8,%esi
call   1040 <_setReg@plt>
mov    $0x21,%edi
mov    $0xa0,%esi
call   1040 <_setReg@plt>
mov    $0x22,%edi
xor    %esi,%esi
call   1040 <_setReg@plt>
mov    $0x23,%edi
xor    %esi,%esi
call   1040 <_setReg@plt>
mov    $0x2a,%edi
mov    $0x7,%esi
call   1040 <_setReg@plt>
mov    $0x1e,%edi
xor    %esi,%esi
call   1040 <_setReg@plt>
mov    $0x1f,%edi
xor    %esi,%esi
call   1040 <_setReg@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1040 <_setReg@plt>
mov    $0x2d,%edi
mov    $0x8,%esi
call   1040 <_setReg@plt>
mov    $0x64,%edi
call   1030 <delay@plt>
movl   $0x1,-0x4(%rbp)
jmp    125c <adxlSetup+0x12c>
mov    $0x2d,%edi
mov    $0x8,%esi
call   1040 <_setReg@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adxlSetup>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %edi,%edi
call   1050 <_getReg@plt>
mov    $0xffffffff,%ebx
cmp    $0xe5,%eax
jne    122c <adxlSetup+0xfc>
xor    %ebx,%ebx
mov    $0x2e,%edi
xor    %esi,%esi
call   1040 <_setReg@plt>
mov    $0x2c,%edi
mov    $0xa,%esi
call   1040 <_setReg@plt>
mov    $0x2d,%edi
call   1050 <_getReg@plt>
test   %eax,%eax
je     118b <adxlSetup+0x5b>
mov    $0x2d,%edi
mov    $0x8,%esi
call   1040 <_setReg@plt>
jmp    122c <adxlSetup+0xfc>
mov    %ebp,%eax
or     $0x28,%eax
cmp    $0x4,%ebp
mov    $0x28,%esi
cmovb  %eax,%esi
mov    $0x31,%edi
call   1040 <_setReg@plt>
mov    $0x1d,%edi
mov    $0x8,%esi
call   1040 <_setReg@plt>
mov    $0x21,%edi
mov    $0xa0,%esi
call   1040 <_setReg@plt>
mov    $0x22,%edi
xor    %esi,%esi
call   1040 <_setReg@plt>
mov    $0x23,%edi
xor    %esi,%esi
call   1040 <_setReg@plt>
mov    $0x2a,%edi
mov    $0x7,%esi
call   1040 <_setReg@plt>
mov    $0x1e,%edi
xor    %esi,%esi
call   1040 <_setReg@plt>
mov    $0x1f,%edi
xor    %esi,%esi
call   1040 <_setReg@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1040 <_setReg@plt>
mov    $0x2d,%edi
mov    $0x8,%esi
call   1040 <_setReg@plt>
mov    $0x64,%edi
call   1030 <delay@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @adxlSetup(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = call i32 @_getReg(i32 0)
%5 = icmp ne i32 %4, 229
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 -1, i32* %2
br label %36
7: ; preds = %1
%8 = call i32 @_setReg(i32 46, i32 0)
%9 = call i32 @_setReg(i32 44, i32 10)
%10 = call i32 @_getReg(i32 45)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %34
12: ; preds = %7
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, 3
br i1 %17, label %18, label %19
18: ; preds = %15, %12
store i32 0, i32* %3
br label %19
19: ; preds = %18, %15
%20 = load i32, i32* %3
%21 = or i32 %20, 40
store i32 %21, i32* %3
%22 = load i32, i32* %3
%23 = call i32 @_setReg(i32 49, i32 %22)
%24 = call i32 @_setReg(i32 29, i32 8)
%25 = call i32 @_setReg(i32 33, i32 160)
%26 = call i32 @_setReg(i32 34, i32 0)
%27 = call i32 @_setReg(i32 35, i32 0)
%28 = call i32 @_setReg(i32 42, i32 7)
%29 = call i32 @_setReg(i32 30, i32 0)
%30 = call i32 @_setReg(i32 31, i32 0)
%31 = call i32 @_setReg(i32 32, i32 0)
%32 = call i32 @_setReg(i32 45, i32 8)
%33 = call i32 @delay(i32 100)
store i32 1, i32* %2
br label %36
34: ; preds = %7
%35 = call i32 @_setReg(i32 45, i32 8)
store i32 0, i32* %2
br label %36
36: ; preds = %34, %19, %6
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
define i32 @adxlSetup(i32 %0) {
%2 = tail call i32 @_getReg(i32 0)
%3 = icmp eq i32 %2, 229
br i1 %3, label %4, label %26
4: ; preds = %1
%5 = tail call i32 @_setReg(i32 46, i32 0)
%6 = tail call i32 @_setReg(i32 44, i32 10)
%7 = tail call i32 @_getReg(i32 45)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %24
9: ; preds = %4
%10 = icmp ugt i32 %0, 3
%11 = or i32 %0, 40
%12 = select i1 %10, i32 40, i32 %11
%13 = tail call i32 @_setReg(i32 49, i32 %12)
%14 = tail call i32 @_setReg(i32 29, i32 8)
%15 = tail call i32 @_setReg(i32 33, i32 160)
%16 = tail call i32 @_setReg(i32 34, i32 0)
%17 = tail call i32 @_setReg(i32 35, i32 0)
%18 = tail call i32 @_setReg(i32 42, i32 7)
%19 = tail call i32 @_setReg(i32 30, i32 0)
%20 = tail call i32 @_setReg(i32 31, i32 0)
%21 = tail call i32 @_setReg(i32 32, i32 0)
%22 = tail call i32 @_setReg(i32 45, i32 8)
%23 = tail call i32 @delay(i32 100)
br label %26
24: ; preds = %4
%25 = tail call i32 @_setReg(i32 45, i32 8)
br label %26
26: ; preds = %1, %24, %9
%27 = phi i32 [ 1, %9 ], [ 0, %24 ], [ -1, %1 ]
ret i32 %27
}