#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_I2cWriteWord(unsigned char 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), uAddr);
  VIM_HIF_SetReg8((0x0800 + 0x036), (unsigned char)(uVal >> 8));
  VIM_HIF_SetReg8((0x0800 + 0x037), (unsigned char)uVal);
  VIM_HIF_SetReg8((0x0800 + 0x034), 2);
  VIM_HIF_SetReg8((0x0800 + 0x039), 0x1);
  return 1;
}


x86 assembly (clang, -O0):
<VIM_SIF_I2cWriteWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %si,%ax
mov    %dil,%cl
mov    %cl,-0x3(%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     1181 <VIM_SIF_I2cWriteWord+0x61>
mov    $0x83f,%edi
call   1040 <VIM_HIF_GetReg8@plt>
mov    %al,-0x7(%rbp)
movzbl -0x7(%rbp),%eax
and    $0x2,%eax
cmp    $0x2,%eax
jne    117c <VIM_SIF_I2cWriteWord+0x5c>
jmp    1181 <VIM_SIF_I2cWriteWord+0x61>
jmp    1141 <VIM_SIF_I2cWriteWord+0x21>
cmpq   $0x0,-0x10(%rbp)
jne    1197 <VIM_SIF_I2cWriteWord+0x77>
movw   $0x0,-0x2(%rbp)
jmp    11ee <VIM_SIF_I2cWriteWord+0xce>
movzbl -0x3(%rbp),%esi
mov    $0x83a,%edi
call   1030 <VIM_HIF_SetReg8@plt>
movzwl -0x6(%rbp),%eax
sar    $0x8,%eax
movzbl %al,%esi
mov    $0x836,%edi
call   1030 <VIM_HIF_SetReg8@plt>
mov    -0x6(%rbp),%ax
movzbl %al,%esi
mov    $0x837,%edi
call   1030 <VIM_HIF_SetReg8@plt>
mov    $0x834,%edi
mov    $0x2,%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_I2cWriteWord>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%r14d
mov    $0xffffffffffff8100,%rbp
test   %rbp,%rbp
je     114c <VIM_SIF_I2cWriteWord+0x2c>
mov    $0x83f,%edi
call   1040 <VIM_HIF_GetReg8@plt>
add    $0x1,%rbp
test   $0x2,%al
je     1130 <VIM_SIF_I2cWriteWord+0x10>
test   %rbp,%rbp
je     119e <VIM_SIF_I2cWriteWord+0x7e>
movzbl %r14b,%esi
mov    $0x83a,%edi
call   1030 <VIM_HIF_SetReg8@plt>
movzwl %bx,%esi
shr    $0x8,%esi
mov    $0x836,%edi
call   1030 <VIM_HIF_SetReg8@plt>
movzbl %bl,%esi
mov    $0x837,%edi
call   1030 <VIM_HIF_SetReg8@plt>
mov    $0x834,%edi
mov    $0x2,%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    1199 <VIM_SIF_I2cWriteWord+0x79>

LLVM IR (-O0):
define zeroext i16 @VIM_SIF_I2cWriteWord(i8 zeroext %0, i16 zeroext %1) {
%3 = alloca i16
%4 = alloca i8
%5 = alloca i16
%6 = alloca i8
%7 = alloca i64
store i8 %0, i8* %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 %40
24: ; preds = %20
%25 = load i8, i8* %4
%26 = zext i8 %25 to i32
%27 = call i32 @VIM_HIF_SetReg8(i32 2106, i32 %26)
%28 = load i16, i16* %5
%29 = zext i16 %28 to i32
%30 = ashr i32 %29, 8
%31 = trunc i32 %30 to i8
%32 = zext i8 %31 to i32
%33 = call i32 @VIM_HIF_SetReg8(i32 2102, i32 %32)
%34 = load i16, i16* %5
%35 = trunc i16 %34 to i8
%36 = zext i8 %35 to i32
%37 = call i32 @VIM_HIF_SetReg8(i32 2103, i32 %36)
%38 = call i32 @VIM_HIF_SetReg8(i32 2100, i32 2)
%39 = call i32 @VIM_HIF_SetReg8(i32 2105, i32 1)
store i16 1, i16* %3
br label %40
40: ; preds = %24, %23
%41 = load i16, i16* %3
ret i16 %41
}

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