#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 mips_ejtag_forwardWord(int);
int /*<<< orphan*/ mips_ejtag_pracc(int);
int /*<<< orphan*/ mips_ejtag_returnWord(int, int);
int mips_ejtag_getcp0reg(int cp0_regnum) {
  int a0, val, lregnum;
  if (cp0_regnum < 0 || (cp0_regnum >= 25 && cp0_regnum <= 30) ||
      cp0_regnum > 31)
    return -1;
  mips_ejtag_pracc(((0x408 << 20) | ((2) << 16) | ((31) << 11)));
  mips_ejtag_pracc(0x00000000);
  mips_ejtag_pracc(
      ((0x0F << 26) | ((2) << 16) | ((0xFF200000 >> 16) & 0xFFFF)));
  mips_ejtag_pracc(((0x2B << 26) | ((2) << 21) | ((4) << 16) | (0)));
  mips_ejtag_pracc(0x0000000f);
  a0 = mips_ejtag_forwardWord(0xff200000);
  mips_ejtag_pracc(((0x400 << 20) | ((4) << 16) | ((cp0_regnum) << 11)));
  mips_ejtag_pracc(0x00000000);
  mips_ejtag_pracc(((0x2B << 26) | ((2) << 21) | ((4) << 16) | (0)));
  mips_ejtag_pracc(0x0000000f);
  val = mips_ejtag_forwardWord(0xff200000);
  mips_ejtag_pracc(((0x23 << 26) | ((2) << 21) | ((4) << 16) | (0)));
  mips_ejtag_returnWord(a0, 0xff200000);
  mips_ejtag_pracc(((0x400 << 20) | ((2) << 16) | ((31) << 11)));
  mips_ejtag_pracc(0x00000000);
  return val;
}


x86 assembly (clang, -O0):
<mips_ejtag_getcp0reg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1163 <mips_ejtag_getcp0reg+0x33>
cmpl   $0x19,-0x8(%rbp)
jl     1159 <mips_ejtag_getcp0reg+0x29>
cmpl   $0x1e,-0x8(%rbp)
jle    1163 <mips_ejtag_getcp0reg+0x33>
cmpl   $0x1f,-0x8(%rbp)
jle    116f <mips_ejtag_getcp0reg+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1212 <mips_ejtag_getcp0reg+0xe2>
mov    $0x4082f800,%edi
call   1040 <mips_ejtag_pracc@plt>
xor    %edi,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    $0x3c02ff20,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    $0xac440000,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    $0xf,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    $0xff200000,%edi
call   1030 <mips_ejtag_forwardWord@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
shl    $0xb,%edi
or     $0x40040000,%edi
call   1040 <mips_ejtag_pracc@plt>
xor    %edi,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    $0xac440000,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    $0xf,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    $0xff200000,%edi
call   1030 <mips_ejtag_forwardWord@plt>
mov    %eax,-0x10(%rbp)
mov    $0x8c440000,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    -0xc(%rbp),%edi
mov    $0xff200000,%esi
call   1050 <mips_ejtag_returnWord@plt>
mov    $0x4002f800,%edi
call   1040 <mips_ejtag_pracc@plt>
xor    %edi,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mips_ejtag_getcp0reg>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
js     11ef <mips_ejtag_getcp0reg+0xbf>
mov    %edi,%ebx
cmp    $0x1f,%edi
ja     11ef <mips_ejtag_getcp0reg+0xbf>
lea    -0x19(%rbx),%eax
cmp    $0x6,%eax
jb     11ef <mips_ejtag_getcp0reg+0xbf>
mov    $0x4082f800,%edi
call   1040 <mips_ejtag_pracc@plt>
xor    %edi,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    $0x3c02ff20,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    $0xac440000,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    $0xf,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    $0xff200000,%edi
call   1030 <mips_ejtag_forwardWord@plt>
mov    %eax,%ebp
shl    $0xb,%ebx
or     $0x40040000,%ebx
mov    %ebx,%edi
call   1040 <mips_ejtag_pracc@plt>
xor    %edi,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    $0xac440000,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    $0xf,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    $0xff200000,%edi
call   1030 <mips_ejtag_forwardWord@plt>
mov    %eax,%ebx
mov    $0x8c440000,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    %ebp,%edi
mov    $0xff200000,%esi
call   1050 <mips_ejtag_returnWord@plt>
mov    $0x4002f800,%edi
call   1040 <mips_ejtag_pracc@plt>
xor    %edi,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    %ebx,%eax
jmp    11f4 <mips_ejtag_getcp0reg+0xc4>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mips_ejtag_getcp0reg(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %18, label %9
9: ; preds = %1
%10 = load i32, i32* %3
%11 = icmp sge i32 %10, 25
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* %3
%14 = icmp sle i32 %13, 30
br i1 %14, label %18, label %15
15: ; preds = %12, %9
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, 31
br i1 %17, label %18, label %19
18: ; preds = %15, %12, %1
store i32 -1, i32* %2
br label %40
19: ; preds = %15
%20 = call i32 @mips_ejtag_pracc(i32 1082324992)
%21 = call i32 @mips_ejtag_pracc(i32 0)
%22 = call i32 @mips_ejtag_pracc(i32 1006829344)
%23 = call i32 @mips_ejtag_pracc(i32 -1404829696)
%24 = call i32 @mips_ejtag_pracc(i32 15)
%25 = call i32 @mips_ejtag_forwardWord(i32 -14680064)
store i32 %25, i32* %4
%26 = load i32, i32* %3
%27 = shl i32 %26, 11
%28 = or i32 1074003968, %27
%29 = call i32 @mips_ejtag_pracc(i32 %28)
%30 = call i32 @mips_ejtag_pracc(i32 0)
%31 = call i32 @mips_ejtag_pracc(i32 -1404829696)
%32 = call i32 @mips_ejtag_pracc(i32 15)
%33 = call i32 @mips_ejtag_forwardWord(i32 -14680064)
store i32 %33, i32* %5
%34 = call i32 @mips_ejtag_pracc(i32 -1941700608)
%35 = load i32, i32* %4
%36 = call i32 @mips_ejtag_returnWord(i32 %35, i32 -14680064)
%37 = call i32 @mips_ejtag_pracc(i32 1073936384)
%38 = call i32 @mips_ejtag_pracc(i32 0)
%39 = load i32, i32* %5
store i32 %39, i32* %2
br label %40
40: ; preds = %19, %18
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
define i32 @mips_ejtag_getcp0reg(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %26, label %3
3: ; preds = %1
%4 = add nsw i32 %0, -25
%5 = icmp ult i32 %4, 6
%6 = icmp ugt i32 %0, 31
%7 = or i1 %6, %5
br i1 %7, label %26, label %8
8: ; preds = %3
%9 = tail call i32 @mips_ejtag_pracc(i32 1082324992)
%10 = tail call i32 @mips_ejtag_pracc(i32 0)
%11 = tail call i32 @mips_ejtag_pracc(i32 1006829344)
%12 = tail call i32 @mips_ejtag_pracc(i32 -1404829696)
%13 = tail call i32 @mips_ejtag_pracc(i32 15)
%14 = tail call i32 @mips_ejtag_forwardWord(i32 -14680064)
%15 = shl nuw nsw i32 %0, 11
%16 = or i32 %15, 1074003968
%17 = tail call i32 @mips_ejtag_pracc(i32 %16)
%18 = tail call i32 @mips_ejtag_pracc(i32 0)
%19 = tail call i32 @mips_ejtag_pracc(i32 -1404829696)
%20 = tail call i32 @mips_ejtag_pracc(i32 15)
%21 = tail call i32 @mips_ejtag_forwardWord(i32 -14680064)
%22 = tail call i32 @mips_ejtag_pracc(i32 -1941700608)
%23 = tail call i32 @mips_ejtag_returnWord(i32 %14, i32 -14680064)
%24 = tail call i32 @mips_ejtag_pracc(i32 1073936384)
%25 = tail call i32 @mips_ejtag_pracc(i32 0)
br label %26
26: ; preds = %1, %3, %8
%27 = phi i32 [ %21, %8 ], [ -1, %3 ], [ -1, %1 ]
ret i32 %27
}