#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 */
typedef int uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ NRF24_InsRead(int, int *, int);
int /*<<< orphan*/ NRF24_RXFIFO_Read(int *, int);
int /*<<< orphan*/ NRF24_Write_Reg(int, int);
int NRF24_GetReceivedPacket(uint8_t *pbuff, uint32_t *length, uint8_t *pipe,
                            uint8_t status) {
  uint8_t dummy;
  if (status & (1 << 6)) {
    NRF24_InsRead(0x60, &dummy, 1);
    *length = dummy;
    NRF24_Write_Reg(0x07, (1 << 6));
    if (*length <= 32 && *length > 0) {
      NRF24_RXFIFO_Read(pbuff, *length);
      *pipe = (status & (0x07 << 1)) >> 1;
      return 0;
    } else {
      return -2;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<NRF24_GetReceivedPacket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x24(%rbp),%eax
and    $0x40,%eax
cmp    $0x0,%eax
je     11d1 <NRF24_GetReceivedPacket+0xa1>
mov    $0x60,%edi
lea    -0x28(%rbp),%rsi
mov    $0x1,%edx
call   1040 <NRF24_InsRead@plt>
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x7,%edi
mov    $0x40,%esi
call   1050 <NRF24_Write_Reg@plt>
mov    -0x18(%rbp),%rax
cmpl   $0x20,(%rax)
jg     11c5 <NRF24_GetReceivedPacket+0x95>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jle    11c5 <NRF24_GetReceivedPacket+0x95>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1030 <NRF24_RXFIFO_Read@plt>
mov    -0x24(%rbp),%ecx
and    $0xe,%ecx
sar    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11d8 <NRF24_GetReceivedPacket+0xa8>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11d8 <NRF24_GetReceivedPacket+0xa8>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NRF24_GetReceivedPacket>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    $0xffffffff,%eax
test   $0x40,%bl
je     119b <NRF24_GetReceivedPacket+0x6b>
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
lea    0x4(%rsp),%rsi
mov    $0x60,%edi
mov    $0x1,%edx
call   1040 <NRF24_InsRead@plt>
mov    0x4(%rsp),%eax
mov    %eax,(%r12)
mov    $0x7,%edi
mov    $0x40,%esi
call   1050 <NRF24_Write_Reg@plt>
mov    (%r12),%esi
lea    -0x1(%rsi),%ecx
mov    $0xfffffffe,%eax
cmp    $0x1f,%ecx
ja     119b <NRF24_GetReceivedPacket+0x6b>
mov    %r15,%rdi
call   1030 <NRF24_RXFIFO_Read@plt>
shr    %ebx
and    $0x7,%ebx
mov    %ebx,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @NRF24_GetReceivedPacket(i32* %0, i32* %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
%11 = load i32, i32* %9
%12 = and i32 %11, 64
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %36
14: ; preds = %4
%15 = call i32 @NRF24_InsRead(i32 96, i32* %10, i32 1)
%16 = load i32, i32* %10
%17 = load i32*, i32** %7
store i32 %16, i32* %17
%18 = call i32 @NRF24_Write_Reg(i32 7, i32 64)
%19 = load i32*, i32** %7
%20 = load i32, i32* %19
%21 = icmp sle i32 %20, 32
br i1 %21, label %22, label %35
22: ; preds = %14
%23 = load i32*, i32** %7
%24 = load i32, i32* %23
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %22
%27 = load i32*, i32** %6
%28 = load i32*, i32** %7
%29 = load i32, i32* %28
%30 = call i32 @NRF24_RXFIFO_Read(i32* %27, i32 %29)
%31 = load i32, i32* %9
%32 = and i32 %31, 14
%33 = ashr i32 %32, 1
%34 = load i32*, i32** %8
store i32 %33, i32* %34
store i32 0, i32* %5
br label %37
35: ; preds = %22, %14
store i32 -2, i32* %5
br label %37
36: ; preds = %4
store i32 -1, i32* %5
br label %37
37: ; preds = %36, %35, %26
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
define i32 @NRF24_GetReceivedPacket(i32* %0, i32* nocapture %1, i32* nocapture writeonly %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = and i32 %3, 64
%8 = icmp eq i32 %7, 0
br i1 %8, label %20, label %9
9: ; preds = %4
%10 = call i32 @NRF24_InsRead(i32 96, i32* %5, i32 1)
%11 = load i32, i32* %5
store i32 %11, i32* %1
%12 = call i32 @NRF24_Write_Reg(i32 7, i32 64)
%13 = load i32, i32* %1
%14 = add i32 %13, -1
%15 = icmp ult i32 %14, 32
br i1 %15, label %16, label %20
16: ; preds = %9
%17 = call i32 @NRF24_RXFIFO_Read(i32* %0, i32 %13)
%18 = lshr i32 %3, 1
%19 = and i32 %18, 7
store i32 %19, i32* %2
br label %20
20: ; preds = %4, %9, %16
%21 = phi i32 [ 0, %16 ], [ -2, %9 ], [ -1, %4 ]
ret i32 %21
}