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

/* Variables and functions */
int rf_reg_read(struct nrf24l01 *, int);
int rf_reg_write(struct nrf24l01 *, int, int);
int rf_speed(struct nrf24l01 *dev, uint8_t speed) {
  int ret;
  uint8_t rf_setup;
  ret = rf_reg_read(dev, 0x06);
  if (ret < 0)
    goto out;
  rf_setup = ret;
  rf_setup &= ~0b00101000;
  switch (speed) {
  case 0b00100000:
  case 0b00000000:
  case 0b00001000:
    rf_setup |= speed;
    break;
  default:
    ret = -1;
    goto out;
  }
  ret = rf_reg_write(dev, 0x06, rf_setup);
  if (ret < 0)
    goto out;
out:
  return ret;
}


x86 assembly (clang, -O0):
<rf_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x6,%esi
call   1040 <rf_reg_read@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    114f <rf_speed+0x2f>
jmp    11d4 <rf_speed+0xb4>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%al
and    $0xd7,%al
mov    %al,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
test   %eax,%eax
je     1192 <rf_speed+0x72>
jmp    1170 <rf_speed+0x50>
mov    -0x18(%rbp),%eax
sub    $0x8,%eax
je     1192 <rf_speed+0x72>
jmp    1181 <rf_speed+0x61>
mov    -0x18(%rbp),%eax
sub    $0x20,%eax
jne    11a0 <rf_speed+0x80>
jmp    1192 <rf_speed+0x72>
mov    -0xc(%rbp),%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11ac <rf_speed+0x8c>
movl   $0xffffffff,-0x10(%rbp)
jmp    11d4 <rf_speed+0xb4>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x6,%esi
call   1030 <rf_reg_write@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11cf <rf_speed+0xaf>
jmp    11d4 <rf_speed+0xb4>
jmp    11d4 <rf_speed+0xb4>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rf_speed>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x6,%esi
call   1040 <rf_reg_read@plt>
test   %eax,%eax
js     116c <rf_speed+0x4c>
mov    $0xffffffff,%ecx
cmp    $0x20,%ebp
ja     116e <rf_speed+0x4e>
mov    %ebp,%edx
movabs $0x100000101,%rsi
bt     %rdx,%rsi
jae    116e <rf_speed+0x4e>
and    $0xffffffd7,%eax
or     %ebp,%eax
mov    %rbx,%rdi
mov    $0x6,%esi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <rf_reg_write@plt>
mov    %eax,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.nrf24l01 = type { i32 }
define i32 @rf_speed(%struct.nrf24l01* %0, i32 %1) {
%3 = alloca %struct.nrf24l01*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store %struct.nrf24l01* %0, %struct.nrf24l01** %3
store i32 %1, i32* %4
%7 = load %struct.nrf24l01*, %struct.nrf24l01** %3
%8 = call i32 @rf_reg_read(%struct.nrf24l01* %7, i32 6)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
br label %30
12: ; preds = %2
%13 = load i32, i32* %5
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = and i32 %14, -41
store i32 %15, i32* %6
%16 = load i32, i32* %4
switch i32 %16, label %21 [
i32 32, label %17
i32 0, label %17
i32 8, label %17
]
17: ; preds = %12, %12, %12
%18 = load i32, i32* %4
%19 = load i32, i32* %6
%20 = or i32 %19, %18
store i32 %20, i32* %6
br label %22
21: ; preds = %12
store i32 -1, i32* %5
br label %30
22: ; preds = %17
%23 = load %struct.nrf24l01*, %struct.nrf24l01** %3
%24 = load i32, i32* %6
%25 = call i32 @rf_reg_write(%struct.nrf24l01* %23, i32 6, i32 %24)
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %22
br label %30
29: ; preds = %22
br label %30
30: ; preds = %29, %28, %21, %11
%31 = load i32, i32* %5
ret i32 %31
}

LLVM IR (-O2):
%struct.nrf24l01 = type { i32 }
define i32 @rf_speed(%struct.nrf24l01* %0, i32 %1) {
%3 = tail call i32 @rf_reg_read(%struct.nrf24l01* %0, i32 6)
%4 = icmp slt i32 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %2
switch i32 %1, label %10 [
i32 32, label %6
i32 0, label %6
i32 8, label %6
]
6: ; preds = %5, %5, %5
%7 = and i32 %3, -41
%8 = or i32 %7, %1
%9 = tail call i32 @rf_reg_write(%struct.nrf24l01* %0, i32 6, i32 %8)
br label %10
10: ; preds = %5, %6, %2
%11 = phi i32 [ %3, %2 ], [ %9, %6 ], [ -1, %5 ]
ret i32 %11
}