#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_I2cWriteWord16bit(unsigned short uAddr,
                                         unsigned short uVal) {
  unsigned char uState = 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), (unsigned char)(uAddr >> 8));
  VIM_HIF_SetReg8((0x0800 + 0x036), (unsigned char)(uAddr));
  VIM_HIF_SetReg8((0x0800 + 0x037), (unsigned char)(uVal >> 8));
  VIM_HIF_SetReg8((0x0800 + 0x038), (unsigned char)uVal);
  VIM_HIF_SetReg8((0x0800 + 0x034), 3);
  VIM_HIF_SetReg8((0x0800 + 0x039), 0x1);
  return 1;
}


x86 assembly (clang, -O0):
<VIM_SIF_I2cWriteWord16bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %si,%ax
mov    %di,%cx
mov    %cx,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
movb   $0x0,-0x7(%rbp)
movq   $0x7f00,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
je     1182 <VIM_SIF_I2cWriteWord16bit+0x62>
mov    $0x83f,%edi
call   1040 <VIM_HIF_GetReg8@plt>
mov    %al,-0x7(%rbp)
movzbl -0x7(%rbp),%eax
and    $0x2,%eax
cmp    $0x2,%eax
jne    117d <VIM_SIF_I2cWriteWord16bit+0x5d>
jmp    1182 <VIM_SIF_I2cWriteWord16bit+0x62>
jmp    1142 <VIM_SIF_I2cWriteWord16bit+0x22>
cmpq   $0x0,-0x10(%rbp)
jne    1198 <VIM_SIF_I2cWriteWord16bit+0x78>
movw   $0x0,-0x2(%rbp)
jmp    1206 <VIM_SIF_I2cWriteWord16bit+0xe6>
movzwl -0x4(%rbp),%eax
sar    $0x8,%eax
movzbl %al,%esi
mov    $0x83a,%edi
call   1030 <VIM_HIF_SetReg8@plt>
mov    -0x4(%rbp),%ax
movzbl %al,%esi
mov    $0x836,%edi
call   1030 <VIM_HIF_SetReg8@plt>
movzwl -0x6(%rbp),%eax
sar    $0x8,%eax
movzbl %al,%esi
mov    $0x837,%edi
call   1030 <VIM_HIF_SetReg8@plt>
mov    -0x6(%rbp),%ax
movzbl %al,%esi
mov    $0x838,%edi
call   1030 <VIM_HIF_SetReg8@plt>
mov    $0x834,%edi
mov    $0x3,%esi
call   1030 <VIM_HIF_SetReg8@plt>
mov    $0x839,%edi
mov    $0x1,%esi
call   1030 <VIM_HIF_SetReg8@plt>
movw   $0x1,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VIM_SIF_I2cWriteWord16bit>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
mov    $0xffffffffffff8100,%rbx
test   %rbx,%rbx
je     114c <VIM_SIF_I2cWriteWord16bit+0x2c>
mov    $0x83f,%edi
call   1040 <VIM_HIF_GetReg8@plt>
add    $0x1,%rbx
test   $0x2,%al
je     1130 <VIM_SIF_I2cWriteWord16bit+0x10>
test   %rbx,%rbx
je     11b0 <VIM_SIF_I2cWriteWord16bit+0x90>
movzwl %bp,%esi
shr    $0x8,%esi
mov    $0x83a,%edi
call   1030 <VIM_HIF_SetReg8@plt>
movzbl %bpl,%esi
mov    $0x836,%edi
call   1030 <VIM_HIF_SetReg8@plt>
movzwl %r14w,%esi
shr    $0x8,%esi
mov    $0x837,%edi
call   1030 <VIM_HIF_SetReg8@plt>
movzbl %r14b,%esi
mov    $0x838,%edi
call   1030 <VIM_HIF_SetReg8@plt>
mov    $0x834,%edi
mov    $0x3,%esi
call   1030 <VIM_HIF_SetReg8@plt>
mov    $0x839,%edi
mov    $0x1,%esi
call   1030 <VIM_HIF_SetReg8@plt>
mov    $0x1,%ax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
jmp    11ab <VIM_SIF_I2cWriteWord16bit+0x8b>

LLVM IR (-O0):
define zeroext i16 @VIM_SIF_I2cWriteWord16bit(i16 zeroext %0, i16 zeroext %1) {
%3 = alloca i16
%4 = alloca i16
%5 = alloca i16
%6 = alloca i8
%7 = alloca i64
store i16 %0, i16* %4
store i16 %1, i16* %5
store i8 0, i8* %6
store i64 32512, i64* %7
br label %8
8: ; preds = %19, %2
%9 = load i64, i64* %7
%10 = add i64 %9, -1
store i64 %10, i64* %7
%11 = icmp ne i64 %9, 0
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = call zeroext i8 @VIM_HIF_GetReg8(i32 2111)
store i8 %13, i8* %6
%14 = load i8, i8* %6
%15 = zext i8 %14 to i32
%16 = and i32 %15, 2
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %19
18: ; preds = %12
br label %20
19: ; preds = %12
br label %8
20: ; preds = %18, %8
%21 = load i64, i64* %7
%22 = icmp ne i64 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %20
store i16 0, i16* %3
br label %47
24: ; preds = %20
%25 = load i16, i16* %4
%26 = zext i16 %25 to i32
%27 = ashr i32 %26, 8
%28 = trunc i32 %27 to i8
%29 = zext i8 %28 to i32
%30 = call i32 @VIM_HIF_SetReg8(i32 2106, i32 %29)
%31 = load i16, i16* %4
%32 = trunc i16 %31 to i8
%33 = zext i8 %32 to i32
%34 = call i32 @VIM_HIF_SetReg8(i32 2102, i32 %33)
%35 = load i16, i16* %5
%36 = zext i16 %35 to i32
%37 = ashr i32 %36, 8
%38 = trunc i32 %37 to i8
%39 = zext i8 %38 to i32
%40 = call i32 @VIM_HIF_SetReg8(i32 2103, i32 %39)
%41 = load i16, i16* %5
%42 = trunc i16 %41 to i8
%43 = zext i8 %42 to i32
%44 = call i32 @VIM_HIF_SetReg8(i32 2104, i32 %43)
%45 = call i32 @VIM_HIF_SetReg8(i32 2100, i32 3)
%46 = call i32 @VIM_HIF_SetReg8(i32 2105, i32 1)
store i16 1, i16* %3
br label %47
47: ; preds = %24, %23
%48 = load i16, i16* %3
ret i16 %48
}

LLVM IR (-O2):
define zeroext i16 @VIM_SIF_I2cWriteWord16bit(i16 zeroext %0, i16 zeroext %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 %28, label %13
13: ; preds = %3, %11
%14 = lshr i16 %0, 8
%15 = zext i16 %14 to i32
%16 = tail call i32 @VIM_HIF_SetReg8(i32 2106, i32 %15)
%17 = and i16 %0, 255
%18 = zext i16 %17 to i32
%19 = tail call i32 @VIM_HIF_SetReg8(i32 2102, i32 %18)
%20 = lshr i16 %1, 8
%21 = zext i16 %20 to i32
%22 = tail call i32 @VIM_HIF_SetReg8(i32 2103, i32 %21)
%23 = and i16 %1, 255
%24 = zext i16 %23 to i32
%25 = tail call i32 @VIM_HIF_SetReg8(i32 2104, i32 %24)
%26 = tail call i32 @VIM_HIF_SetReg8(i32 2100, i32 3)
%27 = tail call i32 @VIM_HIF_SetReg8(i32 2105, i32 1)
br label %28
28: ; preds = %11, %13
%29 = phi i16 [ 1, %13 ], [ 0, %11 ]
ret i16 %29
}