#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 */
typedef int int16_t;

/* Variables and functions */
int /*<<< orphan*/ i2cRead(int, unsigned char, unsigned char *);
int /*<<< orphan*/ i2cWrite(int, int, int);
int16_t MAG3110_ReadRawData(unsigned char msbReg, unsigned char lsbReg,
                            unsigned char statusFlag) {
  unsigned char data = 0;
  int16_t val = 0;
  i2cRead(0x0E, msbReg, &data);
  i2cWrite(0x0E, 0x11, 0x80);
  i2cWrite(0x0E, 0x10, 0x02);
  do {
    i2cRead(0x0E, 0x00, &data);
  } while ((data & statusFlag) != statusFlag);
  i2cRead(0x0E, msbReg, &data);
  val = data;
  val <<= 8;
  i2cRead(0x0E, lsbReg, &data);
  val += data;
  return val;
}


x86 assembly (clang, -O0):
<MAG3110_ReadRawData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %dil,%dl
mov    %dl,-0x1(%rbp)
mov    %cl,-0x2(%rbp)
mov    %al,-0x3(%rbp)
movb   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0xe,%edi
lea    -0x4(%rbp),%rdx
movzbl -0x1(%rbp),%esi
call   1030 <i2cRead@plt>
mov    $0xe,%edi
mov    $0x11,%esi
mov    $0x80,%edx
call   1040 <i2cWrite@plt>
mov    $0xe,%edi
mov    $0x10,%esi
mov    $0x2,%edx
call   1040 <i2cWrite@plt>
mov    $0xe,%edi
xor    %esi,%esi
lea    -0x4(%rbp),%rdx
call   1030 <i2cRead@plt>
movzbl -0x4(%rbp),%eax
movzbl -0x3(%rbp),%ecx
and    %ecx,%eax
movzbl -0x3(%rbp),%ecx
cmp    %ecx,%eax
jne    117e <MAG3110_ReadRawData+0x5e>
mov    $0xe,%edi
lea    -0x4(%rbp),%rdx
movzbl -0x1(%rbp),%esi
call   1030 <i2cRead@plt>
movzbl -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x8(%rbp)
mov    $0xe,%edi
lea    -0x4(%rbp),%rdx
movzbl -0x2(%rbp),%esi
call   1030 <i2cRead@plt>
movzbl -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MAG3110_ReadRawData>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%r14d
mov    %edi,%r15d
movb   $0x0,0x7(%rsp)
lea    0x7(%rsp),%rbp
mov    $0xe,%edi
mov    %r15d,%esi
mov    %rbp,%rdx
call   1030 <i2cRead@plt>
mov    $0xe,%edi
mov    $0x11,%esi
mov    $0x80,%edx
call   1040 <i2cWrite@plt>
mov    $0xe,%edi
mov    $0x10,%esi
mov    $0x2,%edx
call   1040 <i2cWrite@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0xe,%edi
xor    %esi,%esi
mov    %rbp,%rdx
call   1030 <i2cRead@plt>
movzbl 0x7(%rsp),%eax
not    %al
test   %al,%bl
jne    1180 <MAG3110_ReadRawData+0x60>
movzbl %r15b,%esi
lea    0x7(%rsp),%rbx
mov    $0xe,%edi
mov    %rbx,%rdx
call   1030 <i2cRead@plt>
movzbl 0x7(%rsp),%ebp
shl    $0x8,%ebp
movzbl %r14b,%esi
mov    $0xe,%edi
mov    %rbx,%rdx
call   1030 <i2cRead@plt>
movzbl 0x7(%rsp),%eax
or     %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @MAG3110_ReadRawData(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2) {
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca i32
store i8 %0, i8* %4
store i8 %1, i8* %5
store i8 %2, i8* %6
store i8 0, i8* %7
store i32 0, i32* %8
%9 = load i8, i8* %4
%10 = call i32 @i2cRead(i32 14, i8 zeroext %9, i8* %7)
%11 = call i32 @i2cWrite(i32 14, i32 17, i32 128)
%12 = call i32 @i2cWrite(i32 14, i32 16, i32 2)
br label %13
13: ; preds = %15, %3
%14 = call i32 @i2cRead(i32 14, i8 zeroext 0, i8* %7)
br label %15
15: ; preds = %13
%16 = load i8, i8* %7
%17 = zext i8 %16 to i32
%18 = load i8, i8* %6
%19 = zext i8 %18 to i32
%20 = and i32 %17, %19
%21 = load i8, i8* %6
%22 = zext i8 %21 to i32
%23 = icmp ne i32 %20, %22
br i1 %23, label %13, label %24
24: ; preds = %15
%25 = load i8, i8* %4
%26 = call i32 @i2cRead(i32 14, i8 zeroext %25, i8* %7)
%27 = load i8, i8* %7
%28 = zext i8 %27 to i32
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = shl i32 %29, 8
store i32 %30, i32* %8
%31 = load i8, i8* %5
%32 = call i32 @i2cRead(i32 14, i8 zeroext %31, i8* %7)
%33 = load i8, i8* %7
%34 = zext i8 %33 to i32
%35 = load i32, i32* %8
%36 = add nsw i32 %35, %34
store i32 %36, i32* %8
%37 = load i32, i32* %8
ret i32 %37
}

LLVM IR (-O2):
define i32 @MAG3110_ReadRawData(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2) {
%4 = alloca i8
store i8 0, i8* %4
%5 = call i32 @i2cRead(i32 14, i8 zeroext %0, i8* %4)
%6 = call i32 @i2cWrite(i32 14, i32 17, i32 128)
%7 = call i32 @i2cWrite(i32 14, i32 16, i32 2)
br label %8
8: ; preds = %8, %3
%9 = call i32 @i2cRead(i32 14, i8 zeroext 0, i8* %4)
%10 = load i8, i8* %4
%11 = and i8 %10, %2
%12 = icmp eq i8 %11, %2
br i1 %12, label %13, label %8
13: ; preds = %8
%14 = call i32 @i2cRead(i32 14, i8 zeroext %0, i8* %4)
%15 = load i8, i8* %4
%16 = zext i8 %15 to i32
%17 = shl nuw nsw i32 %16, 8
%18 = call i32 @i2cRead(i32 14, i8 zeroext %1, i8* %4)
%19 = load i8, i8* %4
%20 = zext i8 %19 to i32
%21 = or i32 %17, %20
ret i32 %21
}