#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 */

/* Variables and functions */
int nrf_read_register(int, char *, char *);
int nrf_write_register(int, char, char *);
int /*<<< orphan*/ timer_wait_us(int);
int nrf_set_mode_ptx(char *retstatus) {
  char confreg;
  int ret;
  ret = nrf_read_register(0x00, &confreg, retstatus);
  if (ret < 0)
    return ret;
  confreg &= ~0x01;
  ret = nrf_write_register(0x00, confreg, retstatus);
  timer_wait_us(140);
  return ret;
}


x86 assembly (clang, -O0):
<nrf_set_mode_ptx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdx
xor    %edi,%edi
lea    -0x11(%rbp),%rsi
call   1040 <nrf_read_register@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1163 <nrf_set_mode_ptx+0x33>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1191 <nrf_set_mode_ptx+0x61>
movsbl -0x11(%rbp),%eax
and    $0xfffffffe,%eax
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
mov    -0x10(%rbp),%rdx
xor    %edi,%edi
movsbl %al,%esi
call   1030 <nrf_write_register@plt>
mov    %eax,-0x18(%rbp)
mov    $0x8c,%edi
call   1050 <timer_wait_us@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nrf_set_mode_ptx>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x7(%rsp),%rsi
xor    %edi,%edi
mov    %rbx,%rdx
call   1040 <nrf_read_register@plt>
test   %eax,%eax
js     116e <nrf_set_mode_ptx+0x3e>
movsbl 0x7(%rsp),%esi
and    $0xfffffffe,%esi
mov    %sil,0x7(%rsp)
xor    %edi,%edi
mov    %rbx,%rdx
call   1030 <nrf_write_register@plt>
mov    %eax,%ebp
mov    $0x8c,%edi
call   1050 <timer_wait_us@plt>
jmp    1170 <nrf_set_mode_ptx+0x40>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @nrf_set_mode_ptx(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @nrf_read_register(i32 0, i8* %4, i8* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i32, i32* %5
store i32 %11, i32* %2
br label %22
12: ; preds = %1
%13 = load i8, i8* %4
%14 = sext i8 %13 to i32
%15 = and i32 %14, -2
%16 = trunc i32 %15 to i8
store i8 %16, i8* %4
%17 = load i8, i8* %4
%18 = load i8*, i8** %3
%19 = call i32 @nrf_write_register(i32 0, i8 signext %17, i8* %18)
store i32 %19, i32* %5
%20 = call i32 @timer_wait_us(i32 140)
%21 = load i32, i32* %5
store i32 %21, i32* %2
br label %22
22: ; preds = %12, %10
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
define i32 @nrf_set_mode_ptx(i8* %0) {
%2 = alloca i8
%3 = call i32 @nrf_read_register(i32 0, i8* %2, i8* %0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = load i8, i8* %2
%7 = and i8 %6, -2
store i8 %7, i8* %2
%8 = call i32 @nrf_write_register(i32 0, i8 signext %7, i8* %0)
%9 = call i32 @timer_wait_us(i32 140)
br label %10
10: ; preds = %1, %5
%11 = phi i32 [ %8, %5 ], [ %3, %1 ]
ret i32 %11
}