#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_I2cWriteByte(unsigned char byAddr, unsigned char byVal) {
  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), byAddr);
  VIM_HIF_SetReg8((0x0800 + 0x036), byVal);
  VIM_HIF_SetReg8((0x0800 + 0x034), 1);
  VIM_HIF_SetReg8((0x0800 + 0x039), 0x1);
  return 1;
}


x86 assembly (clang, -O0):
<VIM_SIF_I2cWriteByte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %dil,%cl
mov    %cl,-0x3(%rbp)
mov    %al,-0x4(%rbp)
movb   $0x0,-0x5(%rbp)
movq   $0x7f00,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
je     1180 <VIM_SIF_I2cWriteByte+0x60>
mov    $0x83f,%edi
call   1040 <VIM_HIF_GetReg8@plt>
mov    %al,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
and    $0x2,%eax
cmp    $0x2,%eax
jne    117b <VIM_SIF_I2cWriteByte+0x5b>
jmp    1180 <VIM_SIF_I2cWriteByte+0x60>
jmp    1140 <VIM_SIF_I2cWriteByte+0x20>
cmpq   $0x0,-0x10(%rbp)
jne    1196 <VIM_SIF_I2cWriteByte+0x76>
movw   $0x0,-0x2(%rbp)
jmp    11d6 <VIM_SIF_I2cWriteByte+0xb6>
movzbl -0x3(%rbp),%esi
mov    $0x83a,%edi
call   1030 <VIM_HIF_SetReg8@plt>
movzbl -0x4(%rbp),%esi
mov    $0x836,%edi
call   1030 <VIM_HIF_SetReg8@plt>
mov    $0x834,%edi
mov    $0x1,%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_I2cWriteByte>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
mov    $0xffffffffffff8100,%rbx
test   %rbx,%rbx
je     114c <VIM_SIF_I2cWriteByte+0x2c>
mov    $0x83f,%edi
call   1040 <VIM_HIF_GetReg8@plt>
add    $0x1,%rbx
test   $0x2,%al
je     1130 <VIM_SIF_I2cWriteByte+0x10>
test   %rbx,%rbx
je     118f <VIM_SIF_I2cWriteByte+0x6f>
movzbl %bpl,%esi
mov    $0x83a,%edi
call   1030 <VIM_HIF_SetReg8@plt>
movzbl %r14b,%esi
mov    $0x836,%edi
call   1030 <VIM_HIF_SetReg8@plt>
mov    $0x834,%edi
mov    $0x1,%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    118a <VIM_SIF_I2cWriteByte+0x6a>

LLVM IR (-O0):
define zeroext i16 @VIM_SIF_I2cWriteByte(i8 zeroext %0, i8 zeroext %1) {
%3 = alloca i16
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i64
store i8 %0, i8* %4
store i8 %1, i8* %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 %33
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 i8, i8* %5
%29 = zext i8 %28 to i32
%30 = call i32 @VIM_HIF_SetReg8(i32 2102, i32 %29)
%31 = call i32 @VIM_HIF_SetReg8(i32 2100, i32 1)
%32 = call i32 @VIM_HIF_SetReg8(i32 2105, i32 1)
store i16 1, i16* %3
br label %33
33: ; preds = %24, %23
%34 = load i16, i16* %3
ret i16 %34
}

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