#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_I2cReadByte(unsigned char byAddr,
                                   unsigned char *pbyVal) {
  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 + 0x034), 1);
  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;
  *pbyVal = VIM_HIF_GetReg8((0x0800 + 0x03C));
  return 1;
}


x86 assembly (clang, -O0):
<VIM_SIF_I2cReadByte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x3(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
movq   $0x7f00,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
cmp    $0x0,%rax
je     117e <VIM_SIF_I2cReadByte+0x5e>
mov    $0x83f,%edi
call   1040 <VIM_HIF_GetReg8@plt>
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
and    $0x2,%eax
cmp    $0x2,%eax
jne    1179 <VIM_SIF_I2cReadByte+0x59>
jmp    117e <VIM_SIF_I2cReadByte+0x5e>
jmp    113e <VIM_SIF_I2cReadByte+0x1e>
cmpq   $0x0,-0x20(%rbp)
jne    1194 <VIM_SIF_I2cReadByte+0x74>
movw   $0x0,-0x2(%rbp)
jmp    1236 <VIM_SIF_I2cReadByte+0x116>
movzbl -0x3(%rbp),%esi
mov    $0x83a,%edi
call   1030 <VIM_HIF_SetReg8@plt>
mov    $0x834,%edi
mov    $0x1,%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     1208 <VIM_SIF_I2cReadByte+0xe8>
mov    $0x83f,%edi
call   1040 <VIM_HIF_GetReg8@plt>
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
and    $0x2,%eax
cmp    $0x2,%eax
jne    1203 <VIM_SIF_I2cReadByte+0xe3>
jmp    1208 <VIM_SIF_I2cReadByte+0xe8>
jmp    11c8 <VIM_SIF_I2cReadByte+0xa8>
cmpq   $0x0,-0x20(%rbp)
jne    121e <VIM_SIF_I2cReadByte+0xfe>
movw   $0x0,-0x2(%rbp)
jmp    1236 <VIM_SIF_I2cReadByte+0x116>
mov    $0x83c,%edi
call   1040 <VIM_HIF_GetReg8@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movw   $0x1,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VIM_SIF_I2cReadByte>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0xffffffffffff8100,%rbx
test   %rbx,%rbx
je     114c <VIM_SIF_I2cReadByte+0x2c>
mov    $0x83f,%edi
call   1040 <VIM_HIF_GetReg8@plt>
add    $0x1,%rbx
test   $0x2,%al
je     1130 <VIM_SIF_I2cReadByte+0x10>
test   %rbx,%rbx
je     11af <VIM_SIF_I2cReadByte+0x8f>
movzbl %bpl,%esi
mov    $0x83a,%edi
call   1030 <VIM_HIF_SetReg8@plt>
mov    $0x834,%edi
mov    $0x1,%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_I2cReadByte+0x7c>
mov    $0x83f,%edi
call   1040 <VIM_HIF_GetReg8@plt>
add    $0x1,%rbx
test   $0x2,%al
je     1180 <VIM_SIF_I2cReadByte+0x60>
test   %rbx,%rbx
je     11af <VIM_SIF_I2cReadByte+0x8f>
mov    $0x83c,%edi
call   1040 <VIM_HIF_GetReg8@plt>
mov    %al,(%r14)
mov    $0x1,%ax
jmp    11b1 <VIM_SIF_I2cReadByte+0x91>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i16 @VIM_SIF_I2cReadByte(i8 zeroext %0, i8* %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 %49
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 = call i32 @VIM_HIF_SetReg8(i32 2100, i32 1)
%29 = call i32 @VIM_HIF_SetReg8(i32 2105, i32 2)
store i64 32512, i64* %7
br label %30
30: ; preds = %41, %24
%31 = load i64, i64* %7
%32 = add i64 %31, -1
store i64 %32, i64* %7
%33 = icmp ne i64 %31, 0
br i1 %33, label %34, label %42
34: ; preds = %30
%35 = call zeroext i8 @VIM_HIF_GetReg8(i32 2111)
store i8 %35, i8* %6
%36 = load i8, i8* %6
%37 = zext i8 %36 to i32
%38 = and i32 %37, 2
%39 = icmp eq i32 %38, 2
br i1 %39, label %40, label %41
40: ; preds = %34
br label %42
41: ; preds = %34
br label %30
42: ; preds = %40, %30
%43 = load i64, i64* %7
%44 = icmp ne i64 %43, 0
br i1 %44, label %46, label %45
45: ; preds = %42
store i16 0, i16* %3
br label %49
46: ; preds = %42
%47 = call zeroext i8 @VIM_HIF_GetReg8(i32 2108)
%48 = load i8*, i8** %5
store i8 %47, i8* %48
store i16 1, i16* %3
br label %49
49: ; preds = %46, %45, %23
%50 = load i16, i16* %3
ret i16 %50
}

LLVM IR (-O2):
define zeroext i16 @VIM_SIF_I2cReadByte(i8 zeroext %0, i8* 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 %30, 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 1)
%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 %30, label %28
28: ; preds = %18, %26
%29 = tail call zeroext i8 @VIM_HIF_GetReg8(i32 2108)
store i8 %29, i8* %1
br label %30
30: ; preds = %26, %11, %28
%31 = phi i16 [ 1, %28 ], [ 0, %11 ], [ 0, %26 ]
ret i16 %31
}