#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*/ printf(char *, unsigned char, unsigned char, unsigned char);
unsigned char rf_read_short_reg(struct device_rf *, unsigned char);
int /*<<< orphan*/ spi_readwrite(struct device_rf *, unsigned char *,
                                 unsigned char *, int);
int rf_write_short_reg(struct device_rf *rf, unsigned char reg,
                       unsigned char val, int check) {
  unsigned char tx[2], rx[2], fb;
  tx[0] = reg;
  tx[1] = val;
  spi_readwrite(rf, tx, rx, 2);
  if (check) {
    fb = rf_read_short_reg(rf, reg & (~((unsigned char)0x01)));
    if (fb != val)
      printf("PHY set reg %02X=%02X failed, read back %02X\r\n", reg, val, fb);
  }
  return 0;
}


x86 assembly (clang, -O0):
<rf_write_short_reg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %sil,%dl
mov    %rdi,-0x8(%rbp)
mov    %dl,-0x9(%rbp)
mov    %al,-0xa(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x12(%rbp)
mov    -0xa(%rbp),%al
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x12(%rbp),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x2,%ecx
call   1050 <spi_readwrite@plt>
cmpl   $0x0,-0x10(%rbp)
je     11bd <rf_write_short_reg+0x8d>
mov    -0x8(%rbp),%rdi
movzbl -0x9(%rbp),%eax
and    $0xfffffffe,%eax
movzbl %al,%esi
call   1040 <rf_read_short_reg@plt>
mov    %al,-0x15(%rbp)
movzbl -0x15(%rbp),%eax
movzbl -0xa(%rbp),%ecx
cmp    %ecx,%eax
je     11b8 <rf_write_short_reg+0x88>
mov    -0x9(%rbp),%cl
mov    -0xa(%rbp),%al
lea    0xe57(%rip),%rdi
movzbl %cl,%esi
movzbl %al,%edx
movzbl -0x15(%rbp),%ecx
call   1030 <printf@plt>
jmp    11bd <rf_write_short_reg+0x8d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rf_write_short_reg>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %bpl,0x4(%rsp)
mov    %r14b,0x5(%rsp)
lea    0x4(%rsp),%rsi
lea    0x6(%rsp),%rdx
mov    $0x2,%ecx
call   1050 <spi_readwrite@plt>
test   %r15d,%r15d
je     1190 <rf_write_short_reg+0x60>
mov    %ebp,%eax
and    $0xfe,%al
movzbl %al,%esi
mov    %rbx,%rdi
call   1040 <rf_read_short_reg@plt>
cmp    %r14b,%al
je     1190 <rf_write_short_reg+0x60>
movzbl %bpl,%esi
movzbl %r14b,%edx
movzbl %al,%ecx
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.device_rf = type { i32 }
@.str = [47 x i8] c"PHY set reg %02X=%02X failed, read back %02X\0D\0A\00"
define i32 @rf_write_short_reg(%struct.device_rf* %0, i8 zeroext %1, i8 zeroext %2, i32 %3) {
%5 = alloca %struct.device_rf*
%6 = alloca i8
%7 = alloca i8
%8 = alloca i32
%9 = alloca [2 x i8]
%10 = alloca [2 x i8]
%11 = alloca i8
store %struct.device_rf* %0, %struct.device_rf** %5
store i8 %1, i8* %6
store i8 %2, i8* %7
store i32 %3, i32* %8
%12 = load i8, i8* %6
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
store i8 %12, i8* %13
%14 = load i8, i8* %7
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 1
store i8 %14, i8* %15
%16 = load %struct.device_rf*, %struct.device_rf** %5
%17 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
%19 = call i32 @spi_readwrite(%struct.device_rf* %16, i8* %17, i8* %18, i32 2)
%20 = load i32, i32* %8
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %40
22: ; preds = %4
%23 = load %struct.device_rf*, %struct.device_rf** %5
%24 = load i8, i8* %6
%25 = zext i8 %24 to i32
%26 = and i32 %25, -2
%27 = trunc i32 %26 to i8
%28 = call zeroext i8 @rf_read_short_reg(%struct.device_rf* %23, i8 zeroext %27)
store i8 %28, i8* %11
%29 = load i8, i8* %11
%30 = zext i8 %29 to i32
%31 = load i8, i8* %7
%32 = zext i8 %31 to i32
%33 = icmp ne i32 %30, %32
br i1 %33, label %34, label %39
34: ; preds = %22
%35 = load i8, i8* %6
%36 = load i8, i8* %7
%37 = load i8, i8* %11
%38 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8 zeroext %35, i8 zeroext %36, i8 zeroext %37)
br label %39
39: ; preds = %34, %22
br label %40
40: ; preds = %39, %4
ret i32 0
}

LLVM IR (-O2):
%struct.device_rf = type { i32 }
@.str = [47 x i8] c"PHY set reg %02X=%02X failed, read back %02X\0D\0A\00"
define i32 @rf_write_short_reg(%struct.device_rf* %0, i8 zeroext %1, i8 zeroext %2, i32 %3) {
%5 = alloca [2 x i8]
%6 = alloca [2 x i8]
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
store i8 %1, i8* %7
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
store i8 %2, i8* %9
%10 = call i32 @spi_readwrite(%struct.device_rf* %0, i8* %7, i8* %8, i32 2)
%11 = icmp eq i32 %3, 0
br i1 %11, label %18, label %12
12: ; preds = %4
%13 = and i8 %1, -2
%14 = call zeroext i8 @rf_read_short_reg(%struct.device_rf* %0, i8 zeroext %13)
%15 = icmp eq i8 %14, %2
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8 zeroext %1, i8 zeroext %2, i8 zeroext %14)
br label %18
18: ; preds = %12, %16, %4
ret i32 0
}