#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 mips_ejtag_getcp0reg(int);
int /*<<< orphan*/ mips_ejtag_pracc(int);
int /*<<< orphan*/ mips_ejtag_returnWord(int, int);
int mips_ejtag_getreg(int regnum) {
  int a0, val, lregnum;
  if (regnum < 0 || regnum > 106)
    return 0;
  if (regnum >= 0 && regnum <= 31) {
    lregnum = regnum != 2 ? 2 : 4;
    mips_ejtag_pracc(((0x408 << 20) | ((lregnum) << 16) | ((31) << 11)));
    mips_ejtag_pracc(0x00000000);
    mips_ejtag_pracc(
        ((0x0F << 26) | ((lregnum) << 16) | ((0xFF200000 >> 16) & 0xFFFF)));
    mips_ejtag_pracc(
        ((0x2B << 26) | ((lregnum) << 21) | ((regnum) << 16) | (0)));
    mips_ejtag_pracc(0x0000000f);
    val = mips_ejtag_forwardWord(0xFF200000);
    mips_ejtag_pracc(((0x400 << 20) | ((lregnum) << 16) | ((31) << 11)));
    mips_ejtag_pracc(0x00000000);
  } else if (regnum > 31 && regnum < 38) {
    switch (regnum) {
    case 32:
      val = mips_ejtag_getcp0reg(12);
      break;
    case 34:
    case 33:
      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);
      if (regnum == 34) {
        mips_ejtag_pracc((((4) << 11) | 0x10));
        mips_ejtag_pracc(0x00000000);
      } else {
        mips_ejtag_pracc((((4) << 11) | 0x12));
        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);
      break;
    case 35:
      val = mips_ejtag_getcp0reg(8);
      break;
    case 36:
      val = mips_ejtag_getcp0reg(13);
      break;
    case 37:
      val = mips_ejtag_getcp0reg(24);
      break;
    }
  } else if (regnum >= 38 && regnum <= 72) {
    val = 0;
  } else {
    val = mips_ejtag_getcp0reg(regnum - 74);
  }
  return val;
}


x86 assembly (clang, -O0):
<mips_ejtag_getreg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     115f <mips_ejtag_getreg+0x1f>
cmpl   $0x6a,-0x8(%rbp)
jle    116b <mips_ejtag_getreg+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    139e <mips_ejtag_getreg+0x25e>
cmpl   $0x0,-0x8(%rbp)
jl     1220 <mips_ejtag_getreg+0xe0>
cmpl   $0x1f,-0x8(%rbp)
jg     1220 <mips_ejtag_getreg+0xe0>
mov    -0x8(%rbp),%edx
mov    $0x4,%eax
mov    $0x2,%ecx
cmp    $0x2,%edx
cmovne %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
shl    $0x10,%edi
or     $0x40800000,%edi
or     $0xf800,%edi
call   1040 <mips_ejtag_pracc@plt>
xor    %edi,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    -0x14(%rbp),%edi
shl    $0x10,%edi
or     $0x3c000000,%edi
or     $0xff20,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    -0x14(%rbp),%edi
shl    $0x15,%edi
or     $0xac000000,%edi
mov    -0x8(%rbp),%eax
shl    $0x10,%eax
or     %eax,%edi
or     $0x0,%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    -0x14(%rbp),%edi
shl    $0x10,%edi
or     $0x40000000,%edi
or     $0xf800,%edi
call   1040 <mips_ejtag_pracc@plt>
xor    %edi,%edi
call   1040 <mips_ejtag_pracc@plt>
jmp    1398 <mips_ejtag_getreg+0x258>
cmpl   $0x1f,-0x8(%rbp)
jle    1360 <mips_ejtag_getreg+0x220>
cmpl   $0x26,-0x8(%rbp)
jge    1360 <mips_ejtag_getreg+0x220>
mov    -0x8(%rbp),%eax
add    $0xffffffe0,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x5,%eax
ja     135b <mips_ejtag_getreg+0x21b>
mov    -0x20(%rbp),%rax
lea    0xdac(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0xc,%edi
call   1060 <mips_ejtag_getcp0reg@plt>
mov    %eax,-0x10(%rbp)
jmp    135b <mips_ejtag_getreg+0x21b>
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)
cmpl   $0x22,-0x8(%rbp)
jne    12cb <mips_ejtag_getreg+0x18b>
mov    $0x2010,%edi
call   1040 <mips_ejtag_pracc@plt>
xor    %edi,%edi
call   1040 <mips_ejtag_pracc@plt>
jmp    12dc <mips_ejtag_getreg+0x19c>
mov    $0x2012,%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>
jmp    135b <mips_ejtag_getreg+0x21b>
mov    $0x8,%edi
call   1060 <mips_ejtag_getcp0reg@plt>
mov    %eax,-0x10(%rbp)
jmp    135b <mips_ejtag_getreg+0x21b>
mov    $0xd,%edi
call   1060 <mips_ejtag_getcp0reg@plt>
mov    %eax,-0x10(%rbp)
jmp    135b <mips_ejtag_getreg+0x21b>
mov    $0x18,%edi
call   1060 <mips_ejtag_getcp0reg@plt>
mov    %eax,-0x10(%rbp)
jmp    1393 <mips_ejtag_getreg+0x253>
cmpl   $0x26,-0x8(%rbp)
jl     1380 <mips_ejtag_getreg+0x240>
cmpl   $0x48,-0x8(%rbp)
jg     1380 <mips_ejtag_getreg+0x240>
movl   $0x0,-0x10(%rbp)
jmp    138e <mips_ejtag_getreg+0x24e>
mov    -0x8(%rbp),%edi
sub    $0x4a,%edi
call   1060 <mips_ejtag_getcp0reg@plt>
mov    %eax,-0x10(%rbp)
jmp    1393 <mips_ejtag_getreg+0x253>
jmp    1398 <mips_ejtag_getreg+0x258>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mips_ejtag_getreg>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x6a,%edi
jbe    114d <mips_ejtag_getreg+0xd>
xor    %eax,%eax
jmp    11cb <mips_ejtag_getreg+0x8b>
mov    %edi,%ebx
cmp    $0x1f,%edi
ja     11d0 <mips_ejtag_getreg+0x90>
xor    %eax,%eax
cmp    $0x2,%ebx
sete   %al
lea    (%rax,%rax,1),%ebp
add    $0x2,%ebp
mov    %ebp,%r14d
shl    $0x10,%r14d
lea    0x4080f800(%r14),%edi
call   1040 <mips_ejtag_pracc@plt>
xor    %edi,%edi
call   1040 <mips_ejtag_pracc@plt>
lea    0x3c00ff20(%r14),%edi
call   1040 <mips_ejtag_pracc@plt>
shl    $0x15,%ebp
shl    $0x10,%ebx
or     %ebp,%ebx
or     $0xac000000,%ebx
mov    %ebx,%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
or     $0x4000f800,%r14d
mov    %r14d,%edi
call   1040 <mips_ejtag_pracc@plt>
xor    %edi,%edi
call   1040 <mips_ejtag_pracc@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
cmp    $0x25,%ebx
ja     128d <mips_ejtag_getreg+0x14d>
lea    -0x20(%rbx),%eax
cmp    $0x5,%eax
ja     1149 <mips_ejtag_getreg+0x9>
lea    0xe14(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
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
xor    %eax,%eax
cmp    $0x22,%ebx
setne  %al
lea    (%rax,%rax,1),%edi
add    $0x2010,%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
jmp    11bd <mips_ejtag_getreg+0x7d>
cmp    $0x49,%ebx
jb     1149 <mips_ejtag_getreg+0x9>
add    $0xffffffb6,%ebx
mov    %ebx,%edi
jmp    12b7 <mips_ejtag_getreg+0x177>
mov    $0xc,%edi
jmp    12b7 <mips_ejtag_getreg+0x177>
mov    $0x8,%edi
jmp    12b7 <mips_ejtag_getreg+0x177>
mov    $0xd,%edi
jmp    12b7 <mips_ejtag_getreg+0x177>
mov    $0x18,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <mips_ejtag_getcp0reg@plt>

LLVM IR (-O0):
define i32 @mips_ejtag_getreg(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 %12, label %9
9: ; preds = %1
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 106
br i1 %11, label %12, label %13
12: ; preds = %9, %1
store i32 0, i32* %2
br label %107
13: ; preds = %9
%14 = load i32, i32* %3
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %51
16: ; preds = %13
%17 = load i32, i32* %3
%18 = icmp sle i32 %17, 31
br i1 %18, label %19, label %51
19: ; preds = %16
%20 = load i32, i32* %3
%21 = icmp ne i32 %20, 2
%22 = zext i1 %21 to i64
%23 = select i1 %21, i32 2, i32 4
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = shl i32 %24, 16
%26 = or i32 1082130432, %25
%27 = or i32 %26, 63488
%28 = call i32 @mips_ejtag_pracc(i32 %27)
%29 = call i32 @mips_ejtag_pracc(i32 0)
%30 = load i32, i32* %6
%31 = shl i32 %30, 16
%32 = or i32 1006632960, %31
%33 = or i32 %32, 65312
%34 = call i32 @mips_ejtag_pracc(i32 %33)
%35 = load i32, i32* %6
%36 = shl i32 %35, 21
%37 = or i32 -1409286144, %36
%38 = load i32, i32* %3
%39 = shl i32 %38, 16
%40 = or i32 %37, %39
%41 = or i32 %40, 0
%42 = call i32 @mips_ejtag_pracc(i32 %41)
%43 = call i32 @mips_ejtag_pracc(i32 15)
%44 = call i32 @mips_ejtag_forwardWord(i32 -14680064)
store i32 %44, i32* %5
%45 = load i32, i32* %6
%46 = shl i32 %45, 16
%47 = or i32 1073741824, %46
%48 = or i32 %47, 63488
%49 = call i32 @mips_ejtag_pracc(i32 %48)
%50 = call i32 @mips_ejtag_pracc(i32 0)
br label %105
51: ; preds = %16, %13
%52 = load i32, i32* %3
%53 = icmp sgt i32 %52, 31
br i1 %53, label %54, label %92
54: ; preds = %51
%55 = load i32, i32* %3
%56 = icmp slt i32 %55, 38
br i1 %56, label %57, label %92
57: ; preds = %54
%58 = load i32, i32* %3
switch i32 %58, label %91 [
i32 32, label %59
i32 34, label %61
i32 33, label %61
i32 35, label %85
i32 36, label %87
i32 37, label %89
]
59: ; preds = %57
%60 = call i32 @mips_ejtag_getcp0reg(i32 12)
store i32 %60, i32* %5
br label %91
61: ; preds = %57, %57
%62 = call i32 @mips_ejtag_pracc(i32 1082324992)
%63 = call i32 @mips_ejtag_pracc(i32 0)
%64 = call i32 @mips_ejtag_pracc(i32 1006829344)
%65 = call i32 @mips_ejtag_pracc(i32 -1404829696)
%66 = call i32 @mips_ejtag_pracc(i32 15)
%67 = call i32 @mips_ejtag_forwardWord(i32 -14680064)
store i32 %67, i32* %4
%68 = load i32, i32* %3
%69 = icmp eq i32 %68, 34
br i1 %69, label %70, label %73
70: ; preds = %61
%71 = call i32 @mips_ejtag_pracc(i32 8208)
%72 = call i32 @mips_ejtag_pracc(i32 0)
br label %76
73: ; preds = %61
%74 = call i32 @mips_ejtag_pracc(i32 8210)
%75 = call i32 @mips_ejtag_pracc(i32 0)
br label %76
76: ; preds = %73, %70
%77 = call i32 @mips_ejtag_pracc(i32 -1404829696)
%78 = call i32 @mips_ejtag_pracc(i32 15)
%79 = call i32 @mips_ejtag_forwardWord(i32 -14680064)
store i32 %79, i32* %5
%80 = call i32 @mips_ejtag_pracc(i32 -1941700608)
%81 = load i32, i32* %4
%82 = call i32 @mips_ejtag_returnWord(i32 %81, i32 -14680064)
%83 = call i32 @mips_ejtag_pracc(i32 1073936384)
%84 = call i32 @mips_ejtag_pracc(i32 0)
br label %91
85: ; preds = %57
%86 = call i32 @mips_ejtag_getcp0reg(i32 8)
store i32 %86, i32* %5
br label %91
87: ; preds = %57
%88 = call i32 @mips_ejtag_getcp0reg(i32 13)
store i32 %88, i32* %5
br label %91
89: ; preds = %57
%90 = call i32 @mips_ejtag_getcp0reg(i32 24)
store i32 %90, i32* %5
br label %91
91: ; preds = %57, %89, %87, %85, %76, %59
br label %104
92: ; preds = %54, %51
%93 = load i32, i32* %3
%94 = icmp sge i32 %93, 38
br i1 %94, label %95, label %99
95: ; preds = %92
%96 = load i32, i32* %3
%97 = icmp sle i32 %96, 72
br i1 %97, label %98, label %99
98: ; preds = %95
store i32 0, i32* %5
br label %103
99: ; preds = %95, %92
%100 = load i32, i32* %3
%101 = sub nsw i32 %100, 74
%102 = call i32 @mips_ejtag_getcp0reg(i32 %101)
store i32 %102, i32* %5
br label %103
103: ; preds = %99, %98
br label %104
104: ; preds = %103, %91
br label %105
105: ; preds = %104, %19
%106 = load i32, i32* %5
store i32 %106, i32* %2
br label %107
107: ; preds = %105, %12
%108 = load i32, i32* %2
ret i32 %108
}

LLVM IR (-O2):
define i32 @mips_ejtag_getreg(i32 %0) {
%2 = icmp ugt i32 %0, 106
br i1 %2, label %58, label %3
3: ; preds = %1
%4 = icmp ult i32 %0, 32
br i1 %4, label %5, label %24
5: ; preds = %3
%6 = icmp eq i32 %0, 2
%7 = select i1 %6, i32 4, i32 2
%8 = shl nuw nsw i32 %7, 16
%9 = or i32 %8, 1082193920
%10 = tail call i32 @mips_ejtag_pracc(i32 %9)
%11 = tail call i32 @mips_ejtag_pracc(i32 0)
%12 = or i32 %8, 1006698272
%13 = tail call i32 @mips_ejtag_pracc(i32 %12)
%14 = shl nuw nsw i32 %7, 21
%15 = shl nuw nsw i32 %0, 16
%16 = or i32 %15, %14
%17 = or i32 %16, -1409286144
%18 = tail call i32 @mips_ejtag_pracc(i32 %17)
%19 = tail call i32 @mips_ejtag_pracc(i32 15)
%20 = tail call i32 @mips_ejtag_forwardWord(i32 -14680064)
%21 = or i32 %8, 1073805312
%22 = tail call i32 @mips_ejtag_pracc(i32 %21)
%23 = tail call i32 @mips_ejtag_pracc(i32 0)
br label %58
24: ; preds = %3
%25 = icmp ult i32 %0, 38
br i1 %25, label %26, label %53
26: ; preds = %24
switch i32 %0, label %58 [
i32 32, label %27
i32 34, label %29
i32 33, label %29
i32 35, label %47
i32 36, label %49
i32 37, label %51
]
27: ; preds = %26
%28 = tail call i32 @mips_ejtag_getcp0reg(i32 12)
br label %58
29: ; preds = %26, %26
%30 = tail call i32 @mips_ejtag_pracc(i32 1082324992)
%31 = tail call i32 @mips_ejtag_pracc(i32 0)
%32 = tail call i32 @mips_ejtag_pracc(i32 1006829344)
%33 = tail call i32 @mips_ejtag_pracc(i32 -1404829696)
%34 = tail call i32 @mips_ejtag_pracc(i32 15)
%35 = tail call i32 @mips_ejtag_forwardWord(i32 -14680064)
%36 = icmp eq i32 %0, 34
%37 = select i1 %36, i32 8208, i32 8210
%38 = tail call i32 @mips_ejtag_pracc(i32 %37)
%39 = tail call i32 @mips_ejtag_pracc(i32 0)
%40 = tail call i32 @mips_ejtag_pracc(i32 -1404829696)
%41 = tail call i32 @mips_ejtag_pracc(i32 15)
%42 = tail call i32 @mips_ejtag_forwardWord(i32 -14680064)
%43 = tail call i32 @mips_ejtag_pracc(i32 -1941700608)
%44 = tail call i32 @mips_ejtag_returnWord(i32 %35, i32 -14680064)
%45 = tail call i32 @mips_ejtag_pracc(i32 1073936384)
%46 = tail call i32 @mips_ejtag_pracc(i32 0)
br label %58
47: ; preds = %26
%48 = tail call i32 @mips_ejtag_getcp0reg(i32 8)
br label %58
49: ; preds = %26
%50 = tail call i32 @mips_ejtag_getcp0reg(i32 13)
br label %58
51: ; preds = %26
%52 = tail call i32 @mips_ejtag_getcp0reg(i32 24)
br label %58
53: ; preds = %24
%54 = icmp ult i32 %0, 73
br i1 %54, label %58, label %55
55: ; preds = %53
%56 = add nsw i32 %0, -74
%57 = tail call i32 @mips_ejtag_getcp0reg(i32 %56)
br label %58
58: ; preds = %5, %55, %27, %29, %47, %49, %51, %26, %53, %1
%59 = phi i32 [ 0, %1 ], [ %20, %5 ], [ undef, %26 ], [ %52, %51 ], [ %50, %49 ], [ %48, %47 ], [ %42, %29 ], [ %28, %27 ], [ %57, %55 ], [ 0, %53 ]
ret i32 %59
}