#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 */
scalar_t__ bmi160_bst_yas532_normal_measurement_data(int, unsigned char *,
                                                     unsigned short *,
                                                     unsigned short *,
                                                     unsigned char *);
char bmi160_bst_yas532_set_offset(char *);
signed char bmi160_bst_yas532_magnetic_measure_set_offset(void) {
  signed char com_rslt = ((signed char)-1);
  signed char v_hard_offset_s8[(3)] = {(0), (0), (0)};
  static const unsigned char v_correct_u8[(5)] = {16, 8, 4, 2, 1};
  unsigned short int v_temp_u16 = (0);
  unsigned short int v_xy1y2_u16[(3)] = {(0), (0), (0)};
  signed int v_flag_s32[(3)] = {(0), (0), (0)};
  unsigned char i, j, v_busy_u8, v_overflow_u8 = (0);
  for (i = 0; i < 5; i++) {
    com_rslt = bmi160_bst_yas532_set_offset(v_hard_offset_s8);
    com_rslt += bmi160_bst_yas532_normal_measurement_data(
        (0x11), &v_busy_u8, &v_temp_u16, v_xy1y2_u16, &v_overflow_u8);
    if (v_busy_u8)
      return ((signed char)-3);
    for (j = 0; j < 3; j++) {
      if ((4096) == v_xy1y2_u16[j])
        v_flag_s32[j] = 0;
      if ((4096) < v_xy1y2_u16[j])
        v_flag_s32[j] = 1;
      if (v_xy1y2_u16[j] < (4096))
        v_flag_s32[j] = -1;
    }
    for (j = 0; j < 3; j++) {
      if (v_flag_s32[j])
        v_hard_offset_s8[j] = (signed char)(v_hard_offset_s8[j] +
                                            v_flag_s32[j] * v_correct_u8[i]);
    }
  }
  com_rslt += bmi160_bst_yas532_set_offset(v_hard_offset_s8);
  return com_rslt;
}


x86 assembly (clang, -O0):
<bmi160_bst_yas532_magnetic_measure_set_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movb   $0xff,-0x2(%rbp)
lea    -0x5(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <memset@plt>
movw   $0x0,-0x8(%rbp)
lea    -0xe(%rbp),%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1040 <memset@plt>
lea    -0x1c(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
movb   $0x0,-0x20(%rbp)
movb   $0x0,-0x1d(%rbp)
movzbl -0x1d(%rbp),%eax
cmp    $0x5,%eax
jge    12ca <bmi160_bst_yas532_magnetic_measure_set_offset+0x19a>
lea    -0x5(%rbp),%rdi
call   1050 <bmi160_bst_yas532_set_offset@plt>
mov    %al,-0x2(%rbp)
lea    -0xe(%rbp),%rcx
mov    $0x11,%edi
lea    -0x1f(%rbp),%rsi
lea    -0x8(%rbp),%rdx
lea    -0x20(%rbp),%r8
call   1030 <bmi160_bst_yas532_normal_measurement_data@plt>
mov    %rax,%rcx
movsbq -0x2(%rbp),%rax
add    %rcx,%rax
mov    %al,-0x2(%rbp)
cmpb   $0x0,-0x1f(%rbp)
je     11ce <bmi160_bst_yas532_magnetic_measure_set_offset+0x9e>
movb   $0xfd,-0x1(%rbp)
jmp    12e5 <bmi160_bst_yas532_magnetic_measure_set_offset+0x1b5>
movb   $0x0,-0x1e(%rbp)
movzbl -0x1e(%rbp),%eax
cmp    $0x3,%eax
jge    1255 <bmi160_bst_yas532_magnetic_measure_set_offset+0x125>
movzbl -0x1e(%rbp),%eax
movzwl -0xe(%rbp,%rax,2),%ecx
mov    $0x1000,%eax
cmp    %ecx,%eax
jne    1201 <bmi160_bst_yas532_magnetic_measure_set_offset+0xd1>
movzbl -0x1e(%rbp),%eax
movl   $0x0,-0x1c(%rbp,%rax,4)
movzbl -0x1e(%rbp),%eax
movzwl -0xe(%rbp,%rax,2),%ecx
mov    $0x1000,%eax
cmp    %ecx,%eax
jge    1223 <bmi160_bst_yas532_magnetic_measure_set_offset+0xf3>
movzbl -0x1e(%rbp),%eax
movl   $0x1,-0x1c(%rbp,%rax,4)
movzbl -0x1e(%rbp),%eax
movzwl -0xe(%rbp,%rax,2),%eax
cmp    $0x1000,%eax
jge    1243 <bmi160_bst_yas532_magnetic_measure_set_offset+0x113>
movzbl -0x1e(%rbp),%eax
movl   $0xffffffff,-0x1c(%rbp,%rax,4)
ff
jmp    1248 <bmi160_bst_yas532_magnetic_measure_set_offset+0x118>
mov    -0x1e(%rbp),%al
add    $0x1,%al
mov    %al,-0x1e(%rbp)
jmp    11d2 <bmi160_bst_yas532_magnetic_measure_set_offset+0xa2>
movb   $0x0,-0x1e(%rbp)
movzbl -0x1e(%rbp),%eax
cmp    $0x3,%eax
jge    12b8 <bmi160_bst_yas532_magnetic_measure_set_offset+0x188>
movzbl -0x1e(%rbp),%eax
cmpl   $0x0,-0x1c(%rbp,%rax,4)
je     12a6 <bmi160_bst_yas532_magnetic_measure_set_offset+0x176>
movzbl -0x1e(%rbp),%eax
movsbl -0x5(%rbp,%rax,1),%eax
movzbl -0x1e(%rbp),%ecx
mov    -0x1c(%rbp,%rcx,4),%ecx
movzbl -0x1d(%rbp),%edx
mov    %edx,%esi
lea    0xd6d(%rip),%rdx
movzbl (%rdx,%rsi,1),%edx
imul   %edx,%ecx
add    %ecx,%eax
mov    %al,%cl
movzbl -0x1e(%rbp),%eax
mov    %cl,-0x5(%rbp,%rax,1)
jmp    12ab <bmi160_bst_yas532_magnetic_measure_set_offset+0x17b>
mov    -0x1e(%rbp),%al
add    $0x1,%al
mov    %al,-0x1e(%rbp)
jmp    1259 <bmi160_bst_yas532_magnetic_measure_set_offset+0x129>
jmp    12bd <bmi160_bst_yas532_magnetic_measure_set_offset+0x18d>
mov    -0x1d(%rbp),%al
add    $0x1,%al
mov    %al,-0x1d(%rbp)
jmp    117a <bmi160_bst_yas532_magnetic_measure_set_offset+0x4a>
lea    -0x5(%rbp),%rdi
call   1050 <bmi160_bst_yas532_set_offset@plt>
movsbl %al,%ecx
movsbl -0x2(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x2(%rbp)
mov    -0x2(%rbp),%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bmi160_bst_yas532_magnetic_measure_set_offset>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movb   $0x0,0xc(%rsp)
movw   $0x0,0xa(%rsp)
movw   $0x0,0x16(%rsp)
movw   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
movb   $0x0,0xe(%rsp)
xor    %r14d,%r14d
lea    0xea1(%rip),%r15
xor    %r12d,%r12d
jmp    117e <bmi160_bst_yas532_magnetic_measure_set_offset+0x5e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r12
cmp    $0x5,%r12
je     1253 <bmi160_bst_yas532_magnetic_measure_set_offset+0x133>
lea    0xa(%rsp),%rdi
call   1040 <bmi160_bst_yas532_set_offset@plt>
mov    %eax,%r13d
mov    $0x11,%edi
lea    0xf(%rsp),%rsi
lea    0x16(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xe(%rsp),%r8
call   1030 <bmi160_bst_yas532_normal_measurement_data@plt>
cmpb   $0x0,0xf(%rsp)
jne    1265 <bmi160_bst_yas532_magnetic_measure_set_offset+0x145>
mov    %rax,%r8
movzwl 0x10(%rsp),%ebp
movzwl 0x12(%rsp),%eax
cmp    $0x1001,%eax
setae  %dl
add    %dl,%dl
add    $0xff,%dl
cmp    $0x1000,%eax
movzbl %dl,%edi
cmove  %r14d,%edi
movzwl 0x14(%rsp),%edx
cmp    $0x1001,%edx
setae  %bl
add    %bl,%bl
add    $0xff,%bl
cmp    $0x1000,%edx
movzbl %bl,%esi
cmove  %r14d,%esi
cmp    $0x1000,%ebp
je     121e <bmi160_bst_yas532_magnetic_measure_set_offset+0xfe>
movzwl %bp,%ebp
movzbl (%r12,%r15,1),%ebx
mov    %ebx,%ecx
neg    %cl
cmp    $0x1001,%ebp
movzbl %cl,%ecx
cmovae %ebx,%ecx
add    %cl,0xa(%rsp)
movzwl %ax,%eax
cmp    $0x1000,%eax
je     1234 <bmi160_bst_yas532_magnetic_measure_set_offset+0x114>
movzbl (%r12,%r15,1),%eax
mul    %dil
add    %al,0xb(%rsp)
movzwl %dx,%eax
cmp    $0x1000,%eax
je     1170 <bmi160_bst_yas532_magnetic_measure_set_offset+0x50>
movzbl (%r12,%r15,1),%eax
mul    %sil
add    %al,0xc(%rsp)
jmp    1170 <bmi160_bst_yas532_magnetic_measure_set_offset+0x50>
add    %r8b,%r13b
lea    0xa(%rsp),%rdi
call   1040 <bmi160_bst_yas532_set_offset@plt>
add    %r13b,%al
jmp    1267 <bmi160_bst_yas532_magnetic_measure_set_offset+0x147>
mov    $0xfd,%al
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@bmi160_bst_yas532_magnetic_measure_set_offset.v_correct_u8 = internal unnamed_addr constant [5 x i8] c"\10\08\04\02\01"
define signext i8 @bmi160_bst_yas532_magnetic_measure_set_offset() {
%1 = alloca [3 x i8]
%2 = alloca i16
%3 = alloca [3 x i16]
%4 = alloca i8
%5 = alloca i8
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
%7 = bitcast i16* %2 to i8*
store i16 0, i16* %2
%8 = bitcast [3 x i16]* %3 to i8*
store i8 0, i8* %5
%9 = getelementptr inbounds [3 x i16], [3 x i16]* %3, i64 0, i64 0
%10 = getelementptr inbounds [3 x i16], [3 x i16]* %3, i64 0, i64 1
%11 = getelementptr inbounds [3 x i16], [3 x i16]* %3, i64 0, i64 2
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 1
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 2
br label %14
14: ; preds = %0, %53
%15 = phi i64 [ 0, %0 ], [ %54, %53 ]
%16 = call signext i8 @bmi160_bst_yas532_set_offset(i8* %6)
%17 = call i64 @bmi160_bst_yas532_normal_measurement_data(i32 17, i8* %4, i16* %2, i16* %9, i8* %5)
%18 = load i8, i8* %4
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %61
20: ; preds = %14
%21 = load i16, i16* %9
%22 = icmp eq i16 %21, 4096
%23 = load i16, i16* %10
%24 = icmp eq i16 %23, 4096
%25 = icmp ugt i16 %23, 4096
%26 = select i1 %25, i8 1, i8 -1
%27 = select i1 %24, i8 0, i8 %26
%28 = load i16, i16* %11
%29 = icmp eq i16 %28, 4096
%30 = icmp ugt i16 %28, 4096
%31 = select i1 %30, i8 1, i8 -1
%32 = select i1 %29, i8 0, i8 %31
%33 = getelementptr inbounds [5 x i8], [5 x i8]* @bmi160_bst_yas532_magnetic_measure_set_offset.v_correct_u8, i64 0, i64 %15
br i1 %22, label %41, label %34
34: ; preds = %20
%35 = icmp ugt i16 %21, 4096
%36 = load i8, i8* %6
%37 = load i8, i8* %33
%38 = sub i8 0, %37
%39 = select i1 %35, i8 %37, i8 %38
%40 = add i8 %39, %36
store i8 %40, i8* %6
br label %41
41: ; preds = %20, %34
br i1 %24, label %47, label %42
42: ; preds = %41
%43 = load i8, i8* %12
%44 = load i8, i8* %33
%45 = mul i8 %44, %27
%46 = add i8 %45, %43
store i8 %46, i8* %12
br label %47
47: ; preds = %42, %41
br i1 %29, label %53, label %48
48: ; preds = %47
%49 = load i8, i8* %13
%50 = load i8, i8* %33
%51 = mul i8 %50, %32
%52 = add i8 %51, %49
store i8 %52, i8* %13
br label %53
53: ; preds = %48, %47
%54 = add nuw nsw i64 %15, 1
%55 = icmp eq i64 %54, 5
br i1 %55, label %56, label %14
56: ; preds = %53
%57 = trunc i64 %17 to i8
%58 = add i8 %16, %57
%59 = call signext i8 @bmi160_bst_yas532_set_offset(i8* %6)
%60 = add i8 %59, %58
br label %61
61: ; preds = %14, %56
%62 = phi i8 [ %60, %56 ], [ -3, %14 ]
ret i8 %62
}