#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 /*<<< orphan*/ VsClearRxFifo();
unsigned short VsReadWriteByte(int);
unsigned short VsReadRegister(unsigned char reg) {
  while ((*(volatile unsigned long *)(0xE0030000 + 0x0C)) & (1 << 4))
    ;
  (*(volatile unsigned long *)(0xE0030000 + 0x10)) = 0x0A;
  VsClearRxFifo();
  (*(volatile unsigned long *)(0x3FFFC000 + 0x58)) = (1UL << 1);
  (*(volatile unsigned long *)(0x3FFFC000 + 0x7C)) = (1UL << 30);
  while (!((*(volatile unsigned long *)(0x3FFFC000 + 0x14)) & (1 << 6)))
    ;
  VsReadWriteByte(0x03);
  VsReadWriteByte(reg);
  unsigned short result = VsReadWriteByte(0x00) << 8;
  result |= VsReadWriteByte(0x00);
  (*(volatile unsigned long *)(0x3FFFC000 + 0x78)) = (1UL << 30);
  (*(volatile unsigned long *)(0x3FFFC000 + 0x5C)) = (1UL << 1);
  while ((*(volatile unsigned long *)(0xE0030000 + 0x0C)) & (1 << 4))
    ;
  (*(volatile unsigned long *)(0xE0030000 + 0x10)) = 0x06;
  return result;
}


x86 assembly (clang, -O0):
<VsReadRegister>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    $0xe003000c,%eax
mov    (%rax),%rax
and    $0x10,%rax
cmp    $0x0,%rax
je     1149 <VsReadRegister+0x29>
jmp    112e <VsReadRegister+0xe>
mov    $0xe0030010,%eax
movq   $0xa,(%rax)
mov    $0x0,%al
call   1030 <VsClearRxFifo@plt>
mov    $0x3fffc058,%eax
movq   $0x2,(%rax)
mov    $0x3fffc07c,%eax
movq   $0x40000000,(%rax)
mov    $0x3fffc014,%eax
mov    (%rax),%rax
and    $0x40,%rax
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1196 <VsReadRegister+0x76>
jmp    119b <VsReadRegister+0x7b>
jmp    1174 <VsReadRegister+0x54>
mov    $0x3,%edi
call   1040 <VsReadWriteByte@plt>
movzbl -0x1(%rbp),%edi
call   1040 <VsReadWriteByte@plt>
xor    %edi,%edi
call   1040 <VsReadWriteByte@plt>
movzwl %ax,%eax
shl    $0x8,%eax
mov    %ax,-0x4(%rbp)
xor    %edi,%edi
call   1040 <VsReadWriteByte@plt>
movzwl %ax,%ecx
movzwl -0x4(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x4(%rbp)
mov    $0x3fffc078,%eax
movq   $0x40000000,(%rax)
mov    $0x3fffc05c,%eax
movq   $0x2,(%rax)
mov    $0xe003000c,%eax
mov    (%rax),%rax
and    $0x10,%rax
cmp    $0x0,%rax
je     1206 <VsReadRegister+0xe6>
jmp    11eb <VsReadRegister+0xcb>
mov    $0xe0030010,%eax
movq   $0x6,(%rax)
movzwl -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VsReadRegister>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0xe003000c,%ebx
nopw   0x0(%rax,%rax,1)
testq  $0x10,(%rbx)
jne    1130 <VsReadRegister+0x10>
movq   $0xa,0x4(%rbx)
xor    %eax,%eax
call   1030 <VsClearRxFifo@plt>
movq   $0x2,0x3fffc058
movq   $0x40000000,0x3fffc07c
testq  $0x40,0x3fffc014
je     1160 <VsReadRegister+0x40>
mov    $0x3,%edi
call   1040 <VsReadWriteByte@plt>
movzbl %bpl,%edi
call   1040 <VsReadWriteByte@plt>
xor    %edi,%edi
call   1040 <VsReadWriteByte@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   1040 <VsReadWriteByte@plt>
movq   $0x40000000,0x3fffc078
movq   $0x2,0x3fffc05c
nopl   0x0(%rax)
testq  $0x10,(%rbx)
jne    11b0 <VsReadRegister+0x90>
shl    $0x8,%ebp
or     %ebp,%eax
movq   $0x6,0x4(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i16 @VsReadRegister(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i16
store i8 %0, i8* %2
br label %4
4: ; preds = %8, %1
%5 = load volatile i64, i64* inttoptr (i64 3758293004 to i64*)
%6 = and i64 %5, 16
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %4
br label %4
9: ; preds = %4
store volatile i64 10, i64* inttoptr (i64 3758293008 to i64*)
%10 = call i32 (...) @VsClearRxFifo()
store volatile i64 2, i64* inttoptr (i64 1073725528 to i64*)
store volatile i64 1073741824, i64* inttoptr (i64 1073725564 to i64*)
br label %11
11: ; preds = %16, %9
%12 = load volatile i64, i64* inttoptr (i64 1073725460 to i64*)
%13 = and i64 %12, 64
%14 = icmp ne i64 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %17
16: ; preds = %11
br label %11
17: ; preds = %11
%18 = call zeroext i16 @VsReadWriteByte(i32 3)
%19 = load i8, i8* %2
%20 = zext i8 %19 to i32
%21 = call zeroext i16 @VsReadWriteByte(i32 %20)
%22 = call zeroext i16 @VsReadWriteByte(i32 0)
%23 = zext i16 %22 to i32
%24 = shl i32 %23, 8
%25 = trunc i32 %24 to i16
store i16 %25, i16* %3
%26 = call zeroext i16 @VsReadWriteByte(i32 0)
%27 = zext i16 %26 to i32
%28 = load i16, i16* %3
%29 = zext i16 %28 to i32
%30 = or i32 %29, %27
%31 = trunc i32 %30 to i16
store i16 %31, i16* %3
store volatile i64 1073741824, i64* inttoptr (i64 1073725560 to i64*)
store volatile i64 2, i64* inttoptr (i64 1073725532 to i64*)
br label %32
32: ; preds = %36, %17
%33 = load volatile i64, i64* inttoptr (i64 3758293004 to i64*)
%34 = and i64 %33, 16
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %32
br label %32
37: ; preds = %32
store volatile i64 6, i64* inttoptr (i64 3758293008 to i64*)
%38 = load i16, i16* %3
ret i16 %38
}

LLVM IR (-O2):
define zeroext i16 @VsReadRegister(i8 zeroext %0) {
br label %2
2: ; preds = %2, %1
%3 = load volatile i64, i64* inttoptr (i64 3758293004 to i64*)
%4 = and i64 %3, 16
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %2
6: ; preds = %2
store volatile i64 10, i64* inttoptr (i64 3758293008 to i64*)
%7 = tail call i32 (...) @VsClearRxFifo()
store volatile i64 2, i64* inttoptr (i64 1073725528 to i64*)
store volatile i64 1073741824, i64* inttoptr (i64 1073725564 to i64*)
br label %8
8: ; preds = %8, %6
%9 = load volatile i64, i64* inttoptr (i64 1073725460 to i64*)
%10 = and i64 %9, 64
%11 = icmp eq i64 %10, 0
br i1 %11, label %8, label %12
12: ; preds = %8
%13 = tail call zeroext i16 @VsReadWriteByte(i32 3)
%14 = zext i8 %0 to i32
%15 = tail call zeroext i16 @VsReadWriteByte(i32 %14)
%16 = tail call zeroext i16 @VsReadWriteByte(i32 0)
%17 = tail call zeroext i16 @VsReadWriteByte(i32 0)
store volatile i64 1073741824, i64* inttoptr (i64 1073725560 to i64*)
store volatile i64 2, i64* inttoptr (i64 1073725532 to i64*)
br label %18
18: ; preds = %18, %12
%19 = load volatile i64, i64* inttoptr (i64 3758293004 to i64*)
%20 = and i64 %19, 16
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %18
22: ; preds = %18
%23 = shl i16 %16, 8
%24 = or i16 %23, %17
store volatile i64 6, i64* inttoptr (i64 3758293008 to i64*)
ret i16 %24
}