#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*/ VsReadWriteByte(unsigned short);
void VsWriteRegister(unsigned char reg, unsigned short data) {
  (*(volatile unsigned long *)(0x3FFFC000 + 0x58)) = (1UL << 1);
  (*(volatile unsigned long *)(0x3FFFC000 + 0x7C)) = (1UL << 30);
  while (!((*(volatile unsigned long *)(0x3FFFC000 + 0x14)) & (1 << 6)))
    ;
  VsReadWriteByte(0x02);
  VsReadWriteByte(reg);
  VsReadWriteByte(data >> 8);
  VsReadWriteByte(data);
  (*(volatile unsigned long *)(0x3FFFC000 + 0x78)) = (1UL << 30);
  (*(volatile unsigned long *)(0x3FFFC000 + 0x5C)) = (1UL << 1);
}


x86 assembly (clang, -O0):
<VsWriteRegister>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %si,%ax
mov    %dil,%cl
mov    %cl,-0x1(%rbp)
mov    %ax,-0x4(%rbp)
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    115f <VsWriteRegister+0x4f>
jmp    1164 <VsWriteRegister+0x54>
jmp    113d <VsWriteRegister+0x2d>
mov    $0x2,%edi
call   1030 <VsReadWriteByte@plt>
movzbl -0x1(%rbp),%eax
movzwl %ax,%edi
call   1030 <VsReadWriteByte@plt>
movzwl -0x4(%rbp),%eax
sar    $0x8,%eax
movzwl %ax,%edi
call   1030 <VsReadWriteByte@plt>
movzwl -0x4(%rbp),%edi
call   1030 <VsReadWriteByte@plt>
mov    $0x3fffc078,%eax
movq   $0x40000000,(%rax)
mov    $0x3fffc05c,%eax
movq   $0x2,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VsWriteRegister>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
movq   $0x2,0x3fffc058
movq   $0x40000000,0x3fffc07c
nop
testq  $0x40,0x3fffc014
je     1130 <VsWriteRegister+0x20>
mov    $0x2,%edi
call   1030 <VsReadWriteByte@plt>
movzbl %bpl,%edi
call   1030 <VsReadWriteByte@plt>
movzwl %bx,%ebx
mov    %ebx,%edi
shr    $0x8,%edi
call   1030 <VsReadWriteByte@plt>
mov    %ebx,%edi
call   1030 <VsReadWriteByte@plt>
movq   $0x40000000,0x3fffc078
movq   $0x2,0x3fffc05c
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @VsWriteRegister(i8 zeroext %0, i16 zeroext %1) {
%3 = alloca i8
%4 = alloca i16
store i8 %0, i8* %3
store i16 %1, i16* %4
store volatile i64 2, i64* inttoptr (i64 1073725528 to i64*)
store volatile i64 1073741824, i64* inttoptr (i64 1073725564 to i64*)
br label %5
5: ; preds = %10, %2
%6 = load volatile i64, i64* inttoptr (i64 1073725460 to i64*)
%7 = and i64 %6, 64
%8 = icmp ne i64 %7, 0
%9 = xor i1 %8, true
br i1 %9, label %10, label %11
10: ; preds = %5
br label %5
11: ; preds = %5
%12 = call i32 @VsReadWriteByte(i16 zeroext 2)
%13 = load i8, i8* %3
%14 = zext i8 %13 to i16
%15 = call i32 @VsReadWriteByte(i16 zeroext %14)
%16 = load i16, i16* %4
%17 = zext i16 %16 to i32
%18 = ashr i32 %17, 8
%19 = trunc i32 %18 to i16
%20 = call i32 @VsReadWriteByte(i16 zeroext %19)
%21 = load i16, i16* %4
%22 = call i32 @VsReadWriteByte(i16 zeroext %21)
store volatile i64 1073741824, i64* inttoptr (i64 1073725560 to i64*)
store volatile i64 2, i64* inttoptr (i64 1073725532 to i64*)
ret void
}

LLVM IR (-O2):
define void @VsWriteRegister(i8 zeroext %0, i16 zeroext %1) {
store volatile i64 2, i64* inttoptr (i64 1073725528 to i64*)
store volatile i64 1073741824, i64* inttoptr (i64 1073725564 to i64*)
br label %3
3: ; preds = %3, %2
%4 = load volatile i64, i64* inttoptr (i64 1073725460 to i64*)
%5 = and i64 %4, 64
%6 = icmp eq i64 %5, 0
br i1 %6, label %3, label %7
7: ; preds = %3
%8 = tail call i32 @VsReadWriteByte(i16 zeroext 2)
%9 = zext i8 %0 to i16
%10 = tail call i32 @VsReadWriteByte(i16 zeroext %9)
%11 = lshr i16 %1, 8
%12 = tail call i32 @VsReadWriteByte(i16 zeroext %11)
%13 = tail call i32 @VsReadWriteByte(i16 zeroext %1)
store volatile i64 1073741824, i64* inttoptr (i64 1073725560 to i64*)
store volatile i64 2, i64* inttoptr (i64 1073725532 to i64*)
ret void
}