#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 I2C_GetByte(int);
int I2C_PutByte(int);
int /*<<< orphan*/ I2C_START();
int /*<<< orphan*/ I2C_STOP();
int /*<<< orphan*/ I2C_Set_ReadAddress(unsigned short);
unsigned int SynaReadRegister(unsigned short uRmiAddress,
                              unsigned char Buffer[],
                              unsigned int BytesToRead) {
  unsigned char Count = 0;
  I2C_START();
  I2C_Set_ReadAddress(uRmiAddress);
  I2C_START();
  if (I2C_PutByte(0x20 << 1 | 0x01) == 0x01) {
    I2C_STOP();
    return 0x01;
  }
  while (Count < BytesToRead) {
    Buffer[Count] = I2C_GetByte(Count == (BytesToRead - 1));
    Count++;
  }
  I2C_STOP();
  return 0x00;
}


x86 assembly (clang, -O0):
<SynaReadRegister>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0x6(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
mov    $0x0,%al
call   1060 <I2C_START@plt>
movzwl -0x6(%rbp),%edi
call   1070 <I2C_Set_ReadAddress@plt>
mov    $0x0,%al
call   1060 <I2C_START@plt>
mov    $0x41,%edi
call   1030 <I2C_PutByte@plt>
cmp    $0x1,%eax
jne    11a7 <SynaReadRegister+0x57>
mov    $0x0,%al
call   1040 <I2C_STOP@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fa <SynaReadRegister+0xaa>
jmp    11ac <SynaReadRegister+0x5c>
movzbl -0x15(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11ec <SynaReadRegister+0x9c>
movzbl -0x15(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <I2C_GetByte@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movzbl -0x15(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x15(%rbp),%al
add    $0x1,%al
mov    %al,-0x15(%rbp)
jmp    11ac <SynaReadRegister+0x5c>
mov    $0x0,%al
call   1040 <I2C_STOP@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SynaReadRegister>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %rsi,%r14
mov    %edi,%ebp
xor    %eax,%eax
call   1060 <I2C_START@plt>
mov    %ebp,%edi
call   1070 <I2C_Set_ReadAddress@plt>
xor    %eax,%eax
call   1060 <I2C_START@plt>
mov    $0x41,%edi
call   1030 <I2C_PutByte@plt>
mov    $0x1,%r15d
cmp    $0x1,%eax
je     11be <SynaReadRegister+0x6e>
mov    $0x0,%r15d
test   %r12d,%r12d
je     11be <SynaReadRegister+0x6e>
lea    -0x1(%r12),%ebp
xor    %r15d,%r15d
xor    %ebx,%ebx
nop
xor    %edi,%edi
cmp    %ebx,%ebp
sete   %dil
call   1050 <I2C_GetByte@plt>
mov    %ebx,%ecx
mov    %al,(%r14,%rcx,1)
add    $0x1,%ebx
movzbl %bl,%ebx
cmp    %r12d,%ebx
jb     11a0 <SynaReadRegister+0x50>
xor    %eax,%eax
call   1040 <I2C_STOP@plt>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @SynaReadRegister(i16 zeroext %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i16
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8
store i16 %0, i16* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8 0, i8* %8
%9 = call i32 (...) @I2C_START()
%10 = load i16, i16* %5
%11 = call i32 @I2C_Set_ReadAddress(i16 zeroext %10)
%12 = call i32 (...) @I2C_START()
%13 = call i32 @I2C_PutByte(i32 65)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 (...) @I2C_STOP()
store i32 1, i32* %4
br label %39
17: ; preds = %3
br label %18
18: ; preds = %23, %17
%19 = load i8, i8* %8
%20 = zext i8 %19 to i32
%21 = load i32, i32* %7
%22 = icmp ult i32 %20, %21
br i1 %22, label %23, label %37
23: ; preds = %18
%24 = load i8, i8* %8
%25 = zext i8 %24 to i32
%26 = load i32, i32* %7
%27 = sub i32 %26, 1
%28 = icmp eq i32 %25, %27
%29 = zext i1 %28 to i32
%30 = call zeroext i8 @I2C_GetByte(i32 %29)
%31 = load i8*, i8** %6
%32 = load i8, i8* %8
%33 = zext i8 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 %30, i8* %34
%35 = load i8, i8* %8
%36 = add i8 %35, 1
store i8 %36, i8* %8
br label %18
37: ; preds = %18
%38 = call i32 (...) @I2C_STOP()
store i32 0, i32* %4
br label %39
39: ; preds = %37, %15
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
define i32 @SynaReadRegister(i16 zeroext %0, i8* nocapture writeonly %1, i32 %2) {
%4 = tail call i32 (...) @I2C_START()
%5 = tail call i32 @I2C_Set_ReadAddress(i16 zeroext %0)
%6 = tail call i32 (...) @I2C_START()
%7 = tail call i32 @I2C_PutByte(i32 65)
%8 = icmp eq i32 %7, 1
br i1 %8, label %23, label %9
9: ; preds = %3
%10 = icmp eq i32 %2, 0
br i1 %10, label %23, label %11
11: ; preds = %9
%12 = add i32 %2, -1
br label %13
13: ; preds = %11, %13
%14 = phi i32 [ 0, %11 ], [ %21, %13 ]
%15 = icmp eq i32 %12, %14
%16 = zext i1 %15 to i32
%17 = tail call zeroext i8 @I2C_GetByte(i32 %16)
%18 = zext i32 %14 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 %17, i8* %19
%20 = add nuw nsw i32 %14, 1
%21 = and i32 %20, 255
%22 = icmp ult i32 %21, %2
br i1 %22, label %13, label %23
23: ; preds = %13, %9, %3
%24 = phi i32 [ 1, %3 ], [ 0, %9 ], [ 0, %13 ]
%25 = tail call i32 (...) @I2C_STOP()
ret i32 %24
}