#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*/ mdelay(int);
int /*<<< orphan*/ yas_bma250_get_enable();
int /*<<< orphan*/ yas_bma250_power_down();
int /*<<< orphan*/ yas_bma250_power_up();
int yas_bma250_read_reg_byte(int);
int /*<<< orphan*/ yas_bma250_write_reg_byte(int, int);
int bma250_fast_calibration(char layout[]) {
  char tmp = 1;
  int power_off_after_calibration = 0;
  if (!yas_bma250_get_enable()) {
    yas_bma250_power_up();
    power_off_after_calibration = 1;
  }
  yas_bma250_write_reg_byte(
      0x37, ((yas_bma250_read_reg_byte(0x37) & ~0x06) | ((layout[0]) << 1)));
  yas_bma250_write_reg_byte(
      0x36, ((yas_bma250_read_reg_byte(0x36) & ~0x60) | ((tmp) << 5)));
  do {
    mdelay(2);
    tmp = ((yas_bma250_read_reg_byte(0x36) & 0x10) >> 4);
  } while (tmp == 0);
  yas_bma250_write_reg_byte(
      0x37, ((yas_bma250_read_reg_byte(0x37) & ~0x18) | ((layout[1]) << 3)));
  tmp = 2;
  yas_bma250_write_reg_byte(
      0x36, ((yas_bma250_read_reg_byte(0x36) & ~0x60) | ((tmp) << 5)));
  do {
    mdelay(2);
    tmp = ((yas_bma250_read_reg_byte(0x36) & 0x10) >> 4);
  } while (tmp == 0);
  yas_bma250_write_reg_byte(
      0x37, ((yas_bma250_read_reg_byte(0x37) & ~0x60) | ((layout[2]) << 5)));
  tmp = 3;
  yas_bma250_write_reg_byte(
      0x36, ((yas_bma250_read_reg_byte(0x36) & ~0x60) | ((tmp) << 5)));
  do {
    mdelay(2);
    tmp = ((yas_bma250_read_reg_byte(0x36) & 0x10) >> 4);
  } while (tmp == 0);
  tmp = 1;
  yas_bma250_write_reg_byte(
      0x33, ((yas_bma250_read_reg_byte(0x33) & ~0x01) | ((tmp) << 0)));
  yas_bma250_write_reg_byte(
      0x33, ((yas_bma250_read_reg_byte(0x33) & ~0x02) | ((0x01) << 1)));
  do {
    mdelay(2);
    tmp = ((yas_bma250_read_reg_byte(0x33) & 0x04) >> 2);
  } while (tmp == 0);
  tmp = 0;
  yas_bma250_write_reg_byte(
      0x33, ((yas_bma250_read_reg_byte(0x33) & ~0x01) | ((tmp) << 0)));
  if (power_off_after_calibration) {
    yas_bma250_power_down();
  }
  return 0;
}


x86 assembly (clang, -O0):
<bma250_fast_calibration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x1,-0x9(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1050 <yas_bma250_get_enable@plt>
cmp    $0x0,%eax
jne    1195 <bma250_fast_calibration+0x35>
mov    $0x0,%al
call   1060 <yas_bma250_power_up@plt>
movl   $0x1,-0x10(%rbp)
mov    $0x37,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
mov    %eax,%esi
and    $0xfffffff9,%esi
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
shl    $0x1,%eax
or     %eax,%esi
mov    $0x37,%edi
call   1040 <yas_bma250_write_reg_byte@plt>
mov    $0x36,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
mov    %eax,%esi
and    $0xffffff9f,%esi
movsbl -0x9(%rbp),%eax
shl    $0x5,%eax
or     %eax,%esi
mov    $0x36,%edi
call   1040 <yas_bma250_write_reg_byte@plt>
mov    $0x2,%edi
call   1030 <mdelay@plt>
mov    $0x36,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
and    $0x10,%eax
sar    $0x4,%eax
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x0,%eax
je     11dc <bma250_fast_calibration+0x7c>
mov    $0x37,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
mov    %eax,%esi
and    $0xffffffe7,%esi
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
shl    $0x3,%eax
or     %eax,%esi
mov    $0x37,%edi
call   1040 <yas_bma250_write_reg_byte@plt>
movb   $0x2,-0x9(%rbp)
mov    $0x36,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
mov    %eax,%esi
and    $0xffffff9f,%esi
movsbl -0x9(%rbp),%eax
shl    $0x5,%eax
or     %eax,%esi
mov    $0x36,%edi
call   1040 <yas_bma250_write_reg_byte@plt>
mov    $0x2,%edi
call   1030 <mdelay@plt>
mov    $0x36,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
and    $0x10,%eax
sar    $0x4,%eax
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x0,%eax
je     1252 <bma250_fast_calibration+0xf2>
mov    $0x37,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
mov    %eax,%esi
and    $0xffffff9f,%esi
mov    -0x8(%rbp),%rax
movsbl 0x2(%rax),%eax
shl    $0x5,%eax
or     %eax,%esi
mov    $0x37,%edi
call   1040 <yas_bma250_write_reg_byte@plt>
movb   $0x3,-0x9(%rbp)
mov    $0x36,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
mov    %eax,%esi
and    $0xffffff9f,%esi
movsbl -0x9(%rbp),%eax
shl    $0x5,%eax
or     %eax,%esi
mov    $0x36,%edi
call   1040 <yas_bma250_write_reg_byte@plt>
mov    $0x2,%edi
call   1030 <mdelay@plt>
mov    $0x36,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
and    $0x10,%eax
sar    $0x4,%eax
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x0,%eax
je     12c8 <bma250_fast_calibration+0x168>
movb   $0x1,-0x9(%rbp)
mov    $0x33,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
mov    %eax,%esi
and    $0xfffffffe,%esi
movsbl -0x9(%rbp),%eax
shl    $0x0,%eax
or     %eax,%esi
mov    $0x33,%edi
call   1040 <yas_bma250_write_reg_byte@plt>
mov    $0x33,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
mov    %eax,%esi
and    $0xfffffffd,%esi
or     $0x2,%esi
mov    $0x33,%edi
call   1040 <yas_bma250_write_reg_byte@plt>
mov    $0x2,%edi
call   1030 <mdelay@plt>
mov    $0x33,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
and    $0x4,%eax
sar    $0x2,%eax
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x0,%eax
je     1334 <bma250_fast_calibration+0x1d4>
movb   $0x0,-0x9(%rbp)
mov    $0x33,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
mov    %eax,%esi
and    $0xfffffffe,%esi
movsbl -0x9(%rbp),%eax
shl    $0x0,%eax
or     %eax,%esi
mov    $0x33,%edi
call   1040 <yas_bma250_write_reg_byte@plt>
cmpl   $0x0,-0x10(%rbp)
je     1395 <bma250_fast_calibration+0x235>
mov    $0x0,%al
call   1070 <yas_bma250_power_down@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bma250_fast_calibration>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <yas_bma250_get_enable@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    117a <bma250_fast_calibration+0x1a>
xor    %eax,%eax
call   1060 <yas_bma250_power_up@plt>
mov    $0x37,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
and    $0xfffffff9,%eax
movsbl (%rbx),%esi
add    %esi,%esi
or     %eax,%esi
mov    $0x37,%edi
call   1040 <yas_bma250_write_reg_byte@plt>
mov    $0x36,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
and    $0xffffff9f,%eax
lea    0x20(%rax),%esi
mov    $0x36,%edi
call   1040 <yas_bma250_write_reg_byte@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x2,%edi
call   1030 <mdelay@plt>
mov    $0x36,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
test   $0x10,%al
je     11c0 <bma250_fast_calibration+0x60>
mov    $0x37,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
and    $0xffffffe7,%eax
movsbl 0x1(%rbx),%esi
shl    $0x3,%esi
or     %eax,%esi
mov    $0x37,%edi
call   1040 <yas_bma250_write_reg_byte@plt>
mov    $0x36,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
and    $0xffffff9f,%eax
lea    0x40(%rax),%esi
mov    $0x36,%edi
call   1040 <yas_bma250_write_reg_byte@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x2,%edi
call   1030 <mdelay@plt>
mov    $0x36,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
test   $0x10,%al
je     1220 <bma250_fast_calibration+0xc0>
mov    $0x37,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
and    $0xffffff9f,%eax
movsbl 0x2(%rbx),%esi
shl    $0x5,%esi
or     %eax,%esi
mov    $0x37,%edi
call   1040 <yas_bma250_write_reg_byte@plt>
mov    $0x36,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
or     $0x60,%eax
mov    $0x36,%edi
mov    %eax,%esi
call   1040 <yas_bma250_write_reg_byte@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x2,%edi
call   1030 <mdelay@plt>
mov    $0x36,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
test   $0x10,%al
je     1280 <bma250_fast_calibration+0x120>
mov    $0x33,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
or     $0x1,%eax
mov    $0x33,%edi
mov    %eax,%esi
call   1040 <yas_bma250_write_reg_byte@plt>
mov    $0x33,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
or     $0x2,%eax
mov    $0x33,%edi
mov    %eax,%esi
call   1040 <yas_bma250_write_reg_byte@plt>
nopw   0x0(%rax,%rax,1)
mov    $0x2,%edi
call   1030 <mdelay@plt>
mov    $0x33,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
test   $0x4,%al
je     12d0 <bma250_fast_calibration+0x170>
mov    $0x33,%edi
call   1080 <yas_bma250_read_reg_byte@plt>
and    $0xfffffffe,%eax
mov    $0x33,%edi
mov    %eax,%esi
call   1040 <yas_bma250_write_reg_byte@plt>
test   %ebp,%ebp
jne    130c <bma250_fast_calibration+0x1ac>
xor    %eax,%eax
call   1070 <yas_bma250_power_down@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bma250_fast_calibration(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
store i8* %0, i8** %2
store i8 1, i8* %3
store i32 0, i32* %4
%5 = call i32 (...) @yas_bma250_get_enable()
%6 = icmp ne i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = call i32 (...) @yas_bma250_power_up()
store i32 1, i32* %4
br label %9
9: ; preds = %7, %1
%10 = call i32 @yas_bma250_read_reg_byte(i32 55)
%11 = and i32 %10, -7
%12 = load i8*, i8** %2
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = shl i32 %15, 1
%17 = or i32 %11, %16
%18 = call i32 @yas_bma250_write_reg_byte(i32 55, i32 %17)
%19 = call i32 @yas_bma250_read_reg_byte(i32 54)
%20 = and i32 %19, -97
%21 = load i8, i8* %3
%22 = sext i8 %21 to i32
%23 = shl i32 %22, 5
%24 = or i32 %20, %23
%25 = call i32 @yas_bma250_write_reg_byte(i32 54, i32 %24)
br label %26
26: ; preds = %32, %9
%27 = call i32 @mdelay(i32 2)
%28 = call i32 @yas_bma250_read_reg_byte(i32 54)
%29 = and i32 %28, 16
%30 = ashr i32 %29, 4
%31 = trunc i32 %30 to i8
store i8 %31, i8* %3
br label %32
32: ; preds = %26
%33 = load i8, i8* %3
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 0
br i1 %35, label %26, label %36
36: ; preds = %32
%37 = call i32 @yas_bma250_read_reg_byte(i32 55)
%38 = and i32 %37, -25
%39 = load i8*, i8** %2
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = shl i32 %42, 3
%44 = or i32 %38, %43
%45 = call i32 @yas_bma250_write_reg_byte(i32 55, i32 %44)
store i8 2, i8* %3
%46 = call i32 @yas_bma250_read_reg_byte(i32 54)
%47 = and i32 %46, -97
%48 = load i8, i8* %3
%49 = sext i8 %48 to i32
%50 = shl i32 %49, 5
%51 = or i32 %47, %50
%52 = call i32 @yas_bma250_write_reg_byte(i32 54, i32 %51)
br label %53
53: ; preds = %59, %36
%54 = call i32 @mdelay(i32 2)
%55 = call i32 @yas_bma250_read_reg_byte(i32 54)
%56 = and i32 %55, 16
%57 = ashr i32 %56, 4
%58 = trunc i32 %57 to i8
store i8 %58, i8* %3
br label %59
59: ; preds = %53
%60 = load i8, i8* %3
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 0
br i1 %62, label %53, label %63
63: ; preds = %59
%64 = call i32 @yas_bma250_read_reg_byte(i32 55)
%65 = and i32 %64, -97
%66 = load i8*, i8** %2
%67 = getelementptr inbounds i8, i8* %66, i64 2
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = shl i32 %69, 5
%71 = or i32 %65, %70
%72 = call i32 @yas_bma250_write_reg_byte(i32 55, i32 %71)
store i8 3, i8* %3
%73 = call i32 @yas_bma250_read_reg_byte(i32 54)
%74 = and i32 %73, -97
%75 = load i8, i8* %3
%76 = sext i8 %75 to i32
%77 = shl i32 %76, 5
%78 = or i32 %74, %77
%79 = call i32 @yas_bma250_write_reg_byte(i32 54, i32 %78)
br label %80
80: ; preds = %86, %63
%81 = call i32 @mdelay(i32 2)
%82 = call i32 @yas_bma250_read_reg_byte(i32 54)
%83 = and i32 %82, 16
%84 = ashr i32 %83, 4
%85 = trunc i32 %84 to i8
store i8 %85, i8* %3
br label %86
86: ; preds = %80
%87 = load i8, i8* %3
%88 = sext i8 %87 to i32
%89 = icmp eq i32 %88, 0
br i1 %89, label %80, label %90
90: ; preds = %86
store i8 1, i8* %3
%91 = call i32 @yas_bma250_read_reg_byte(i32 51)
%92 = and i32 %91, -2
%93 = load i8, i8* %3
%94 = sext i8 %93 to i32
%95 = shl i32 %94, 0
%96 = or i32 %92, %95
%97 = call i32 @yas_bma250_write_reg_byte(i32 51, i32 %96)
%98 = call i32 @yas_bma250_read_reg_byte(i32 51)
%99 = and i32 %98, -3
%100 = or i32 %99, 2
%101 = call i32 @yas_bma250_write_reg_byte(i32 51, i32 %100)
br label %102
102: ; preds = %108, %90
%103 = call i32 @mdelay(i32 2)
%104 = call i32 @yas_bma250_read_reg_byte(i32 51)
%105 = and i32 %104, 4
%106 = ashr i32 %105, 2
%107 = trunc i32 %106 to i8
store i8 %107, i8* %3
br label %108
108: ; preds = %102
%109 = load i8, i8* %3
%110 = sext i8 %109 to i32
%111 = icmp eq i32 %110, 0
br i1 %111, label %102, label %112
112: ; preds = %108
store i8 0, i8* %3
%113 = call i32 @yas_bma250_read_reg_byte(i32 51)
%114 = and i32 %113, -2
%115 = load i8, i8* %3
%116 = sext i8 %115 to i32
%117 = shl i32 %116, 0
%118 = or i32 %114, %117
%119 = call i32 @yas_bma250_write_reg_byte(i32 51, i32 %118)
%120 = load i32, i32* %4
%121 = icmp ne i32 %120, 0
br i1 %121, label %122, label %124
122: ; preds = %112
%123 = call i32 (...) @yas_bma250_power_down()
br label %124
124: ; preds = %122, %112
ret i32 0
}

LLVM IR (-O2):
define i32 @bma250_fast_calibration(i8* nocapture %0) {
%2 = tail call i32 (...) @yas_bma250_get_enable()
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 (...) @yas_bma250_power_up()
br label %6
6: ; preds = %4, %1
%7 = tail call i32 @yas_bma250_read_reg_byte(i32 55)
%8 = and i32 %7, -7
%9 = load i8, i8* %0
%10 = sext i8 %9 to i32
%11 = shl nsw i32 %10, 1
%12 = or i32 %11, %8
%13 = tail call i32 @yas_bma250_write_reg_byte(i32 55, i32 %12)
%14 = tail call i32 @yas_bma250_read_reg_byte(i32 54)
%15 = and i32 %14, -97
%16 = or i32 %15, 32
%17 = tail call i32 @yas_bma250_write_reg_byte(i32 54, i32 %16)
br label %18
18: ; preds = %18, %6
%19 = tail call i32 @mdelay(i32 2)
%20 = tail call i32 @yas_bma250_read_reg_byte(i32 54)
%21 = and i32 %20, 16
%22 = icmp eq i32 %21, 0
br i1 %22, label %18, label %23
23: ; preds = %18
%24 = tail call i32 @yas_bma250_read_reg_byte(i32 55)
%25 = and i32 %24, -25
%26 = getelementptr inbounds i8, i8* %0, i64 1
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = shl nsw i32 %28, 3
%30 = or i32 %29, %25
%31 = tail call i32 @yas_bma250_write_reg_byte(i32 55, i32 %30)
%32 = tail call i32 @yas_bma250_read_reg_byte(i32 54)
%33 = and i32 %32, -97
%34 = or i32 %33, 64
%35 = tail call i32 @yas_bma250_write_reg_byte(i32 54, i32 %34)
br label %36
36: ; preds = %36, %23
%37 = tail call i32 @mdelay(i32 2)
%38 = tail call i32 @yas_bma250_read_reg_byte(i32 54)
%39 = and i32 %38, 16
%40 = icmp eq i32 %39, 0
br i1 %40, label %36, label %41
41: ; preds = %36
%42 = tail call i32 @yas_bma250_read_reg_byte(i32 55)
%43 = and i32 %42, -97
%44 = getelementptr inbounds i8, i8* %0, i64 2
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = shl nsw i32 %46, 5
%48 = or i32 %47, %43
%49 = tail call i32 @yas_bma250_write_reg_byte(i32 55, i32 %48)
%50 = tail call i32 @yas_bma250_read_reg_byte(i32 54)
%51 = or i32 %50, 96
%52 = tail call i32 @yas_bma250_write_reg_byte(i32 54, i32 %51)
br label %53
53: ; preds = %53, %41
%54 = tail call i32 @mdelay(i32 2)
%55 = tail call i32 @yas_bma250_read_reg_byte(i32 54)
%56 = and i32 %55, 16
%57 = icmp eq i32 %56, 0
br i1 %57, label %53, label %58
58: ; preds = %53
%59 = tail call i32 @yas_bma250_read_reg_byte(i32 51)
%60 = or i32 %59, 1
%61 = tail call i32 @yas_bma250_write_reg_byte(i32 51, i32 %60)
%62 = tail call i32 @yas_bma250_read_reg_byte(i32 51)
%63 = or i32 %62, 2
%64 = tail call i32 @yas_bma250_write_reg_byte(i32 51, i32 %63)
br label %65
65: ; preds = %65, %58
%66 = tail call i32 @mdelay(i32 2)
%67 = tail call i32 @yas_bma250_read_reg_byte(i32 51)
%68 = and i32 %67, 4
%69 = icmp eq i32 %68, 0
br i1 %69, label %65, label %70
70: ; preds = %65
%71 = tail call i32 @yas_bma250_read_reg_byte(i32 51)
%72 = and i32 %71, -2
%73 = tail call i32 @yas_bma250_write_reg_byte(i32 51, i32 %72)
br i1 %3, label %74, label %76
74: ; preds = %70
%75 = tail call i32 (...) @yas_bma250_power_down()
br label %76
76: ; preds = %74, %70
ret i32 0
}