#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 */
unsigned char VIM_HIF_GetReg8(int);
int /*<<< orphan*/ VIM_HIF_SetReg8(int, int);
unsigned short VIM_SIF_I2cReadWord(unsigned char uAddr, unsigned short *uVal) {
  unsigned char uState = 0;
  unsigned char x1 = 0, x2 = 0;
  unsigned long count = 0x7f00;
  while (count--) {
    uState = VIM_HIF_GetReg8((0x0800 + 0x03F));
    if ((uState & 0x2) == 0x2) {
      break;
    }
  }
  if (!count)
    return 0;
  VIM_HIF_SetReg8((0x0800 + 0x03A), uAddr);
  VIM_HIF_SetReg8((0x0800 + 0x034), 2);
  VIM_HIF_SetReg8((0x0800 + 0x039), 0x2);
  count = 0x7f00;
  while (count--) {
    uState = VIM_HIF_GetReg8((0x0800 + 0x03F));
    if ((uState & 0x2) == 0x2) {
      break;
    }
  }
  if (!count)
    return 0;
  x1 = VIM_HIF_GetReg8((0x0800 + 0x03C));
  x2 = VIM_HIF_GetReg8((0x0800 + 0x03D));
  *uVal = ((unsigned short)x1 << 8) | ((unsigned short)x2);
  return 1;
}


x86 assembly (clang, -O0):
<VIM_SIF_I2cReadWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x3(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
movb   $0x0,-0x12(%rbp)
movb   $0x0,-0x13(%rbp)
movq   $0x7f00,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
cmp    $0x0,%rax
je     1186 <VIM_SIF_I2cReadWord+0x66>
mov    $0x83f,%edi
call   1040 <VIM_HIF_GetReg8@plt>
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
and    $0x2,%eax
cmp    $0x2,%eax
jne    1181 <VIM_SIF_I2cReadWord+0x61>
jmp    1186 <VIM_SIF_I2cReadWord+0x66>
jmp    1146 <VIM_SIF_I2cReadWord+0x26>
cmpq   $0x0,-0x20(%rbp)
jne    119c <VIM_SIF_I2cReadWord+0x7c>
movw   $0x0,-0x2(%rbp)
jmp    1263 <VIM_SIF_I2cReadWord+0x143>
movzbl -0x3(%rbp),%esi
mov    $0x83a,%edi
call   1030 <VIM_HIF_SetReg8@plt>
mov    $0x834,%edi
mov    $0x2,%esi
call   1030 <VIM_HIF_SetReg8@plt>
mov    $0x839,%edi
mov    $0x2,%esi
call   1030 <VIM_HIF_SetReg8@plt>
movq   $0x7f00,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
cmp    $0x0,%rax
je     1210 <VIM_SIF_I2cReadWord+0xf0>
mov    $0x83f,%edi
call   1040 <VIM_HIF_GetReg8@plt>
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
and    $0x2,%eax
cmp    $0x2,%eax
jne    120b <VIM_SIF_I2cReadWord+0xeb>
jmp    1210 <VIM_SIF_I2cReadWord+0xf0>
jmp    11d0 <VIM_SIF_I2cReadWord+0xb0>
cmpq   $0x0,-0x20(%rbp)
jne    1226 <VIM_SIF_I2cReadWord+0x106>
movw   $0x0,-0x2(%rbp)
jmp    1263 <VIM_SIF_I2cReadWord+0x143>
mov    $0x83c,%edi
call   1040 <VIM_HIF_GetReg8@plt>
mov    %al,-0x12(%rbp)
mov    $0x83d,%edi
call   1040 <VIM_HIF_GetReg8@plt>
mov    %al,-0x13(%rbp)
movzbl -0x12(%rbp),%eax
movzwl %ax,%eax
shl    $0x8,%eax
movzbl -0x13(%rbp),%ecx
movzwl %cx,%ecx
or     %ecx,%eax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
movw   $0x1,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VIM_SIF_I2cReadWord>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0xffffffffffff8100,%rbx
test   %rbx,%rbx
je     114c <VIM_SIF_I2cReadWord+0x2c>
mov    $0x83f,%edi
call   1040 <VIM_HIF_GetReg8@plt>
add    $0x1,%rbx
test   $0x2,%al
je     1130 <VIM_SIF_I2cReadWord+0x10>
test   %rbx,%rbx
je     11c7 <VIM_SIF_I2cReadWord+0xa7>
movzbl %bpl,%esi
mov    $0x83a,%edi
call   1030 <VIM_HIF_SetReg8@plt>
mov    $0x834,%edi
mov    $0x2,%esi
call   1030 <VIM_HIF_SetReg8@plt>
mov    $0x839,%edi
mov    $0x2,%esi
call   1030 <VIM_HIF_SetReg8@plt>
mov    $0xffffffffffff8100,%rbx
nop
test   %rbx,%rbx
je     119c <VIM_SIF_I2cReadWord+0x7c>
mov    $0x83f,%edi
call   1040 <VIM_HIF_GetReg8@plt>
add    $0x1,%rbx
test   $0x2,%al
je     1180 <VIM_SIF_I2cReadWord+0x60>
test   %rbx,%rbx
je     11c7 <VIM_SIF_I2cReadWord+0xa7>
mov    $0x83c,%edi
call   1040 <VIM_HIF_GetReg8@plt>
mov    %eax,%ebx
mov    $0x83d,%edi
call   1040 <VIM_HIF_GetReg8@plt>
movzbl %bl,%ecx
shl    $0x8,%ecx
movzbl %al,%eax
or     %ecx,%eax
mov    %ax,(%r14)
mov    $0x1,%ax
jmp    11c9 <VIM_SIF_I2cReadWord+0xa9>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i16 @VIM_SIF_I2cReadWord(i8 zeroext %0, i16* %1) {
%3 = alloca i16
%4 = alloca i8
%5 = alloca i16*
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i64
store i8 %0, i8* %4
store i16* %1, i16** %5
store i8 0, i8* %6
store i8 0, i8* %7
store i8 0, i8* %8
store i64 32512, i64* %9
br label %10
10: ; preds = %21, %2
%11 = load i64, i64* %9
%12 = add i64 %11, -1
store i64 %12, i64* %9
%13 = icmp ne i64 %11, 0
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = call zeroext i8 @VIM_HIF_GetReg8(i32 2111)
store i8 %15, i8* %6
%16 = load i8, i8* %6
%17 = zext i8 %16 to i32
%18 = and i32 %17, 2
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %21
20: ; preds = %14
br label %22
21: ; preds = %14
br label %10
22: ; preds = %20, %10
%23 = load i64, i64* %9
%24 = icmp ne i64 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %22
store i16 0, i16* %3
br label %61
26: ; preds = %22
%27 = load i8, i8* %4
%28 = zext i8 %27 to i32
%29 = call i32 @VIM_HIF_SetReg8(i32 2106, i32 %28)
%30 = call i32 @VIM_HIF_SetReg8(i32 2100, i32 2)
%31 = call i32 @VIM_HIF_SetReg8(i32 2105, i32 2)
store i64 32512, i64* %9
br label %32
32: ; preds = %43, %26
%33 = load i64, i64* %9
%34 = add i64 %33, -1
store i64 %34, i64* %9
%35 = icmp ne i64 %33, 0
br i1 %35, label %36, label %44
36: ; preds = %32
%37 = call zeroext i8 @VIM_HIF_GetReg8(i32 2111)
store i8 %37, i8* %6
%38 = load i8, i8* %6
%39 = zext i8 %38 to i32
%40 = and i32 %39, 2
%41 = icmp eq i32 %40, 2
br i1 %41, label %42, label %43
42: ; preds = %36
br label %44
43: ; preds = %36
br label %32
44: ; preds = %42, %32
%45 = load i64, i64* %9
%46 = icmp ne i64 %45, 0
br i1 %46, label %48, label %47
47: ; preds = %44
store i16 0, i16* %3
br label %61
48: ; preds = %44
%49 = call zeroext i8 @VIM_HIF_GetReg8(i32 2108)
store i8 %49, i8* %7
%50 = call zeroext i8 @VIM_HIF_GetReg8(i32 2109)
store i8 %50, i8* %8
%51 = load i8, i8* %7
%52 = zext i8 %51 to i16
%53 = zext i16 %52 to i32
%54 = shl i32 %53, 8
%55 = load i8, i8* %8
%56 = zext i8 %55 to i16
%57 = zext i16 %56 to i32
%58 = or i32 %54, %57
%59 = trunc i32 %58 to i16
%60 = load i16*, i16** %5
store i16 %59, i16* %60
store i16 1, i16* %3
br label %61
61: ; preds = %48, %47, %25
%62 = load i16, i16* %3
ret i16 %62
}

LLVM IR (-O2):
define zeroext i16 @VIM_SIF_I2cReadWord(i8 zeroext %0, i16* nocapture writeonly %1) {
br label %3
3: ; preds = %7, %2
%4 = phi i64 [ 32512, %2 ], [ %5, %7 ]
%5 = add nsw i64 %4, -1
%6 = icmp eq i64 %4, 0
br i1 %6, label %13, label %7
7: ; preds = %3
%8 = tail call zeroext i8 @VIM_HIF_GetReg8(i32 2111)
%9 = and i8 %8, 2
%10 = icmp eq i8 %9, 0
br i1 %10, label %3, label %11
11: ; preds = %7
%12 = icmp eq i64 %5, 0
br i1 %12, label %35, label %13
13: ; preds = %3, %11
%14 = zext i8 %0 to i32
%15 = tail call i32 @VIM_HIF_SetReg8(i32 2106, i32 %14)
%16 = tail call i32 @VIM_HIF_SetReg8(i32 2100, i32 2)
%17 = tail call i32 @VIM_HIF_SetReg8(i32 2105, i32 2)
br label %18
18: ; preds = %22, %13
%19 = phi i64 [ 32512, %13 ], [ %20, %22 ]
%20 = add nsw i64 %19, -1
%21 = icmp eq i64 %19, 0
br i1 %21, label %28, label %22
22: ; preds = %18
%23 = tail call zeroext i8 @VIM_HIF_GetReg8(i32 2111)
%24 = and i8 %23, 2
%25 = icmp eq i8 %24, 0
br i1 %25, label %18, label %26
26: ; preds = %22
%27 = icmp eq i64 %20, 0
br i1 %27, label %35, label %28
28: ; preds = %18, %26
%29 = tail call zeroext i8 @VIM_HIF_GetReg8(i32 2108)
%30 = tail call zeroext i8 @VIM_HIF_GetReg8(i32 2109)
%31 = zext i8 %29 to i16
%32 = shl nuw i16 %31, 8
%33 = zext i8 %30 to i16
%34 = or i16 %32, %33
store i16 %34, i16* %1
br label %35
35: ; preds = %26, %11, %28
%36 = phi i16 [ 1, %28 ], [ 0, %11 ], [ 0, %26 ]
ret i16 %36
}