#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 */
struct sCC1101PhyInfo {
  int dummy;
};

/* Variables and functions */
unsigned char CC1101GetRegister(struct sCC1101PhyInfo *, int);
int /*<<< orphan*/ CC1101Read(struct sCC1101PhyInfo *, int, unsigned char *,
                              unsigned char volatile);
unsigned char CC1101ReadRxFifo(struct sCC1101PhyInfo *phyInfo,
                               unsigned char *buffer, unsigned char count) {
  volatile unsigned char rxBytes = CC1101GetRegister(phyInfo, 0x3Bu);
  if (rxBytes < count) {
    CC1101Read(phyInfo, 0x3Fu, buffer, rxBytes);
    return rxBytes;
  } else {
    CC1101Read(phyInfo, 0x3Fu, buffer, count);
    return count;
  }
}


x86 assembly (clang, -O0):
<CC1101ReadRxFifo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3b,%esi
call   1040 <CC1101GetRegister@plt>
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
movzbl %al,%eax
movzbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
jge    117b <CC1101ReadRxFifo+0x5b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x1a(%rbp),%al
mov    $0x3f,%esi
movzbl %al,%ecx
call   1030 <CC1101Read@plt>
mov    -0x1a(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    1197 <CC1101ReadRxFifo+0x77>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x3f,%esi
movzbl -0x19(%rbp),%ecx
call   1030 <CC1101Read@plt>
mov    -0x19(%rbp),%al
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CC1101ReadRxFifo>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x3b,%esi
call   1040 <CC1101GetRegister@plt>
mov    %al,0xf(%rsp)
mov    0xf(%rsp),%al
cmp    %bl,%al
jae    1162 <CC1101ReadRxFifo+0x42>
movzbl 0xf(%rsp),%ecx
mov    %r15,%rdi
mov    $0x3f,%esi
mov    %r14,%rdx
call   1030 <CC1101Read@plt>
mov    0xf(%rsp),%bl
jmp    1175 <CC1101ReadRxFifo+0x55>
movzbl %bl,%ecx
mov    %r15,%rdi
mov    $0x3f,%esi
mov    %r14,%rdx
call   1030 <CC1101Read@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sCC1101PhyInfo = type { i32 }
define zeroext i8 @CC1101ReadRxFifo(%struct.sCC1101PhyInfo* %0, i8* %1, i8 zeroext %2) {
%4 = alloca i8
%5 = alloca %struct.sCC1101PhyInfo*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8
store %struct.sCC1101PhyInfo* %0, %struct.sCC1101PhyInfo** %5
store i8* %1, i8** %6
store i8 %2, i8* %7
%9 = load %struct.sCC1101PhyInfo*, %struct.sCC1101PhyInfo** %5
%10 = call zeroext i8 @CC1101GetRegister(%struct.sCC1101PhyInfo* %9, i32 59)
store volatile i8 %10, i8* %8
%11 = load volatile i8, i8* %8
%12 = zext i8 %11 to i32
%13 = load i8, i8* %7
%14 = zext i8 %13 to i32
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %22
16: ; preds = %3
%17 = load %struct.sCC1101PhyInfo*, %struct.sCC1101PhyInfo** %5
%18 = load i8*, i8** %6
%19 = load volatile i8, i8* %8
%20 = call i32 @CC1101Read(%struct.sCC1101PhyInfo* %17, i32 63, i8* %18, i8 zeroext %19)
%21 = load volatile i8, i8* %8
store i8 %21, i8* %4
br label %28
22: ; preds = %3
%23 = load %struct.sCC1101PhyInfo*, %struct.sCC1101PhyInfo** %5
%24 = load i8*, i8** %6
%25 = load i8, i8* %7
%26 = call i32 @CC1101Read(%struct.sCC1101PhyInfo* %23, i32 63, i8* %24, i8 zeroext %25)
%27 = load i8, i8* %7
store i8 %27, i8* %4
br label %28
28: ; preds = %22, %16
%29 = load i8, i8* %4
ret i8 %29
}

LLVM IR (-O2):
%struct.sCC1101PhyInfo = type { i32 }
define zeroext i8 @CC1101ReadRxFifo(%struct.sCC1101PhyInfo* %0, i8* %1, i8 zeroext %2) {
%4 = alloca i8
%5 = tail call zeroext i8 @CC1101GetRegister(%struct.sCC1101PhyInfo* %0, i32 59)
store volatile i8 %5, i8* %4
%6 = load volatile i8, i8* %4
%7 = icmp ult i8 %6, %2
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = load volatile i8, i8* %4
%10 = tail call i32 @CC1101Read(%struct.sCC1101PhyInfo* %0, i32 63, i8* %1, i8 zeroext %9)
%11 = load volatile i8, i8* %4
br label %14
12: ; preds = %3
%13 = tail call i32 @CC1101Read(%struct.sCC1101PhyInfo* %0, i32 63, i8* %1, i8 zeroext %2)
br label %14
14: ; preds = %12, %8
%15 = phi i8 [ %11, %8 ], [ %2, %12 ]
ret i8 %15
}