#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 device_rf {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ spi_readwrite(struct device_rf *, unsigned char *,
                                 unsigned char *, int);
unsigned char rf_read_long_reg(struct device_rf *rf, unsigned short reg) {
  unsigned char tx[3], rx[3];
  tx[0] = ((reg >> 3) & 0x7F) | 0x80;
  tx[1] = ((reg << 5) & 0xE0);
  tx[2] = 0;
  rx[2] = 0;
  spi_readwrite(rf, tx, rx, 3);
  return rx[2];
}


x86 assembly (clang, -O0):
<rf_read_long_reg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
movzwl -0xa(%rbp),%eax
sar    $0x3,%eax
and    $0x7f,%eax
or     $0x80,%eax
mov    %al,-0xd(%rbp)
movzwl -0xa(%rbp),%eax
shl    $0x5,%eax
and    $0xe0,%eax
mov    %al,-0xc(%rbp)
movb   $0x0,-0xb(%rbp)
movb   $0x0,-0xe(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0xd(%rbp),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x3,%ecx
call   1030 <spi_readwrite@plt>
movzbl -0xe(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rf_read_long_reg>:
push   %rax
mov    %esi,%eax
shr    $0x3,%eax
or     $0x80,%al
mov    %al,0x2(%rsp)
shl    $0x5,%sil
mov    %sil,0x3(%rsp)
movb   $0x0,0x4(%rsp)
movb   $0x0,0x7(%rsp)
lea    0x2(%rsp),%rsi
lea    0x5(%rsp),%rdx
mov    $0x3,%ecx
call   1030 <spi_readwrite@plt>
mov    0x7(%rsp),%al
pop    %rcx
ret

LLVM IR (-O0):
%struct.device_rf = type { i32 }
define zeroext i8 @rf_read_long_reg(%struct.device_rf* %0, i16 zeroext %1) {
%3 = alloca %struct.device_rf*
%4 = alloca i16
%5 = alloca [3 x i8]
%6 = alloca [3 x i8]
store %struct.device_rf* %0, %struct.device_rf** %3
store i16 %1, i16* %4
%7 = load i16, i16* %4
%8 = zext i16 %7 to i32
%9 = ashr i32 %8, 3
%10 = and i32 %9, 127
%11 = or i32 %10, 128
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 %12, i8* %13
%14 = load i16, i16* %4
%15 = zext i16 %14 to i32
%16 = shl i32 %15, 5
%17 = and i32 %16, 224
%18 = trunc i32 %17 to i8
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 %18, i8* %19
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 2
store i8 0, i8* %20
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 2
store i8 0, i8* %21
%22 = load %struct.device_rf*, %struct.device_rf** %3
%23 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%25 = call i32 @spi_readwrite(%struct.device_rf* %22, i8* %23, i8* %24, i32 3)
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 2
%27 = load i8, i8* %26
ret i8 %27
}

LLVM IR (-O2):
%struct.device_rf = type { i32 }
define zeroext i8 @rf_read_long_reg(%struct.device_rf* %0, i16 zeroext %1) {
%3 = alloca [3 x i8]
%4 = alloca [3 x i8]
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%7 = trunc i16 %1 to i8
%8 = lshr i16 %1, 3
%9 = trunc i16 %8 to i8
%10 = or i8 %9, -128
store i8 %10, i8* %5
%11 = shl i8 %7, 5
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
store i8 %11, i8* %12
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
store i8 0, i8* %13
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
store i8 0, i8* %14
%15 = call i32 @spi_readwrite(%struct.device_rf* %0, i8* %5, i8* %6, i32 3)
%16 = load i8, i8* %14
ret i8 %16
}