#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*/ fprintf(int /*<<< orphan*/, char *, ...);
unsigned int mips_ejtag_checkstatus();
unsigned int mips_ejtag_data(unsigned int);
int /*<<< orphan*/ mips_ejtag_instr(int);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ stderr;
void mips_ejtag_pracc_notdbg(int data) {
  unsigned addr;
  unsigned ctrl;
  unsigned long timeout = 16;
  unsigned prnw;
  do {
    ctrl = mips_ejtag_checkstatus();
    timeout--;
  } while (!(ctrl & 0x00040000) && timeout != 0);
  if (timeout == 0) {
    fprintf(stderr, "pracc timeout\n");
    return;
  }
  prnw = ctrl & 0x00080000 ? 1 : 0;
  mips_ejtag_instr(0x08);
  addr = mips_ejtag_data(0);
  printf("Processor read from %08x\n", addr);
  if (ctrl & 0x00080000 != 0) {
    fprintf(stderr, "pracc %08lx not a read pracc!\n", ctrl);
    return;
  }
  mips_ejtag_instr(0x09);
  mips_ejtag_data(data);
  mips_ejtag_instr(0x0A);
  ctrl &= 0x00FFFFFF;
  ctrl &= ~(0x00000004 | 0x00800000 | 0x00000800 | 0x00010000 | 0x00100000 |
            0x00001000 | 0x00040000);
  ctrl |= 0x00004000;
  ctrl |= 0x00008000;
  mips_ejtag_data(ctrl);
}


x86 assembly (clang, -O0):
<mips_ejtag_pracc_notdbg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x10,-0x18(%rbp)
mov    $0x0,%al
call   1030 <mips_ejtag_checkstatus@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%ecx
and    $0x40000,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
jne    119b <mips_ejtag_pracc_notdbg+0x4b>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1163 <mips_ejtag_pracc_notdbg+0x13>
cmpq   $0x0,-0x18(%rbp)
jne    11cd <mips_ejtag_pracc_notdbg+0x7d>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1287 <mips_ejtag_pracc_notdbg+0x137>
mov    -0xc(%rbp),%edx
and    $0x80000,%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x8,%edi
call   1050 <mips_ejtag_instr@plt>
xor    %edi,%edi
call   1070 <mips_ejtag_data@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe0b(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1237 <mips_ejtag_pracc_notdbg+0xe7>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1287 <mips_ejtag_pracc_notdbg+0x137>
mov    $0x9,%edi
call   1050 <mips_ejtag_instr@plt>
mov    -0x4(%rbp),%edi
call   1070 <mips_ejtag_data@plt>
mov    $0xa,%edi
call   1050 <mips_ejtag_instr@plt>
mov    -0xc(%rbp),%eax
and    $0xffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff6ae7fb,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
or     $0x4000,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
or     $0x8000,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1070 <mips_ejtag_data@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mips_ejtag_pracc_notdbg>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    $0x10,%ebp
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <mips_ejtag_checkstatus@plt>
mov    %eax,%ebx
lea    -0x1(%rbp),%rax
test   $0x40000,%ebx
jne    117e <mips_ejtag_pracc_notdbg+0x2e>
cmp    $0x1,%rbp
mov    %rax,%rbp
jne    1160 <mips_ejtag_pracc_notdbg+0x10>
test   %rax,%rax
je     11da <mips_ejtag_pracc_notdbg+0x8a>
mov    $0x8,%edi
call   1050 <mips_ejtag_instr@plt>
xor    %edi,%edi
call   1070 <mips_ejtag_data@plt>
lea    0xe74(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
test   $0x1,%bl
jne    11f5 <mips_ejtag_pracc_notdbg+0xa5>
mov    $0x9,%edi
call   1050 <mips_ejtag_instr@plt>
mov    %r14d,%edi
call   1070 <mips_ejtag_data@plt>
mov    $0xa,%edi
call   1050 <mips_ejtag_instr@plt>
and    $0x6a27fb,%ebx
or     $0xc000,%ebx
mov    %ebx,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <mips_ejtag_data@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe16(%rip),%rsi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <fprintf@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <fprintf@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"pracc timeout\0A\00"
@.str.1 = [26 x i8] c"Processor read from %08x\0A\00"
@.str.2 = [31 x i8] c"pracc %08lx not a read pracc!\0A\00"
define void @mips_ejtag_pracc_notdbg(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
store i32 %0, i32* %2
store i64 16, i64* %5
br label %7
7: ; preds = %18, %1
%8 = call i32 (...) @mips_ejtag_checkstatus()
store i32 %8, i32* %4
%9 = load i64, i64* %5
%10 = add i64 %9, -1
store i64 %10, i64* %5
br label %11
11: ; preds = %7
%12 = load i32, i32* %4
%13 = and i32 %12, 262144
%14 = icmp ne i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = load i64, i64* %5
%17 = icmp ne i64 %16, 0
br label %18
18: ; preds = %15, %11
%19 = phi i1 [ false, %11 ], [ %17, %15 ]
br i1 %19, label %7, label %20
20: ; preds = %18
%21 = load i64, i64* %5
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %58
26: ; preds = %20
%27 = load i32, i32* %4
%28 = and i32 %27, 524288
%29 = icmp ne i32 %28, 0
%30 = zext i1 %29 to i64
%31 = select i1 %29, i32 1, i32 0
store i32 %31, i32* %6
%32 = call i32 @mips_ejtag_instr(i32 8)
%33 = call i32 @mips_ejtag_data(i32 0)
store i32 %33, i32* %3
%34 = load i32, i32* %3
%35 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %4
%37 = and i32 %36, 1
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %26
%40 = load i32, i32* @stderr
%41 = load i32, i32* %4
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %41)
br label %58
43: ; preds = %26
%44 = call i32 @mips_ejtag_instr(i32 9)
%45 = load i32, i32* %2
%46 = call i32 @mips_ejtag_data(i32 %45)
%47 = call i32 @mips_ejtag_instr(i32 10)
%48 = load i32, i32* %4
%49 = and i32 %48, 16777215
store i32 %49, i32* %4
%50 = load i32, i32* %4
%51 = and i32 %50, -9771013
store i32 %51, i32* %4
%52 = load i32, i32* %4
%53 = or i32 %52, 16384
store i32 %53, i32* %4
%54 = load i32, i32* %4
%55 = or i32 %54, 32768
store i32 %55, i32* %4
%56 = load i32, i32* %4
%57 = call i32 @mips_ejtag_data(i32 %56)
br label %58
58: ; preds = %43, %39, %23
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"pracc timeout\0A\00"
@.str.1 = [26 x i8] c"Processor read from %08x\0A\00"
@.str.2 = [31 x i8] c"pracc %08lx not a read pracc!\0A\00"
define void @mips_ejtag_pracc_notdbg(i32 %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ 16, %1 ], [ %5, %2 ]
%4 = tail call i32 (...) @mips_ejtag_checkstatus()
%5 = add nsw i64 %3, -1
%6 = and i32 %4, 262144
%7 = icmp eq i32 %6, 0
%8 = icmp ne i64 %5, 0
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %2, label %10
10: ; preds = %2
%11 = icmp eq i64 %5, 0
br i1 %11, label %12, label %15
12: ; preds = %10
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %31
15: ; preds = %10
%16 = tail call i32 @mips_ejtag_instr(i32 8)
%17 = tail call i32 @mips_ejtag_data(i32 0)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = and i32 %4, 1
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %4)
br label %31
24: ; preds = %15
%25 = tail call i32 @mips_ejtag_instr(i32 9)
%26 = tail call i32 @mips_ejtag_data(i32 %0)
%27 = tail call i32 @mips_ejtag_instr(i32 10)
%28 = and i32 %4, 6957051
%29 = or i32 %28, 49152
%30 = tail call i32 @mips_ejtag_data(i32 %29)
br label %31
31: ; preds = %24, %21, %12
ret void
}