#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*/ printf(char *, char *, int, char *const, unsigned int,
                          unsigned int, unsigned int, unsigned int);
void uncaught(unsigned int cause, unsigned int status, unsigned int epc,
              unsigned int badvaddr) {
  static char *const exception_strs[] = {
      "Interrupt",
      "TLB modification exception",
      "TLB exception (load or instr fetch)",
      "TLB exception (store)",
      "Address error exception (load or instr fetch)",
      "Address error exception (store)",
      "Instruction bus error",
      "Data (load or store) bus error",
      "SYSCALL exception",
      "Breakpoint32 exception (BREAK instr)",
      "Reserved instr exception",
      "Coprocessor Unusable",
      "Arithmetic Overflow",
      "Trap (R4k/R6k only)",
      "LDCz or SDCz to uncached address (R6k)",
      "Virtual Coherency Exception (instr) (R4k)",
      "Machine check exception (R6k)",
      "Floating-point32 exception (R4k)",
      "Exception 16 (reserved)",
      "Exception 17 (reserved)",
      "Exception 18 (reserved)",
      "Exception 19 (reserved)",
      "Exception 20 (reserved)",
      "Exception 21 (reserved)",
      "Exception 22 (reserved)",
      "Reference to WatchHi/WatchLo address detected (R4k)",
      "Exception 24 (reserved)",
      "Exception 25 (reserved)",
      "Exception 26 (reserved)",
      "Exception 27 (reserved)",
      "Exception 28 (reserved)",
      "Exception 29 (reserved)",
      "Exception 30 (reserved)",
      "Virtual Coherency Exception (data) (R4k)"};
  int kernelMode = !(status & 0x00000002);
  int excCode = (cause & 0x0000007c) >> 2;
  printf("\nBoot ROM caught %s exception %d (%s) EPC=%x Status=%x "
         "Cause=%x BadVAddr=%x\n",
         kernelMode ? "Kernel" : "User", excCode, exception_strs[excCode], epc,
         status, cause, badvaddr);
}


x86 assembly (clang, -O0):
<uncaught>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
and    $0x7c,%eax
shr    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
lea    0x12b0(%rip),%rsi
lea    0x12a2(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
mov    -0x18(%rbp),%edx
movslq -0x18(%rbp),%rcx
lea    0x2ba4(%rip),%rax
mov    (%rax,%rcx,8),%rcx
mov    -0xc(%rbp),%r8d
mov    -0x8(%rbp),%r9d
mov    -0x4(%rbp),%r10d
mov    -0x10(%rbp),%eax
lea    0x1226(%rip),%rdi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uncaught>:
push   %rax
mov    %esi,%r9d
mov    %edi,%r10d
mov    %edi,%eax
shr    $0x2,%eax
and    $0x1f,%eax
test   $0x2,%r9b
lea    0x1357(%rip),%rdi
lea    0x1357(%rip),%rsi
cmove  %rdi,%rsi
mov    %ecx,%r11d
mov    %edx,%r8d
lea    0xebe(%rip),%rdx
movslq (%rdx,%rax,4),%rcx
add    %rdx,%rcx
lea    0x12e4(%rip),%rdi
mov    %eax,%edx
push   %r11
push   %r10
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rax
ret

LLVM IR (-O0):
@uncaught.exception_strs = internal constant [34 x i8*] [i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.16, i32 0, i32 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.17, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.18, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.19, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.20, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.21, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.22, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.23, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.24, i32 0, i32 0), i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.25, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.26, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.27, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.28, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.29, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.30, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.31, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.32, i32 0, i32 0), i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.33, i32 0, i32 0)]
@.str = [10 x i8] c"Interrupt\00"
@.str.1 = [27 x i8] c"TLB modification exception\00"
@.str.2 = [36 x i8] c"TLB exception (load or instr fetch)\00"
@.str.3 = [22 x i8] c"TLB exception (store)\00"
@.str.4 = [46 x i8] c"Address error exception (load or instr fetch)\00"
@.str.5 = [32 x i8] c"Address error exception (store)\00"
@.str.6 = [22 x i8] c"Instruction bus error\00"
@.str.7 = [31 x i8] c"Data (load or store) bus error\00"
@.str.8 = [18 x i8] c"SYSCALL exception\00"
@.str.9 = [37 x i8] c"Breakpoint32 exception (BREAK instr)\00"
@.str.10 = [25 x i8] c"Reserved instr exception\00"
@.str.11 = [21 x i8] c"Coprocessor Unusable\00"
@.str.12 = [20 x i8] c"Arithmetic Overflow\00"
@.str.13 = [20 x i8] c"Trap (R4k/R6k only)\00"
@.str.14 = [39 x i8] c"LDCz or SDCz to uncached address (R6k)\00"
@.str.15 = [42 x i8] c"Virtual Coherency Exception (instr) (R4k)\00"
@.str.16 = [30 x i8] c"Machine check exception (R6k)\00"
@.str.17 = [33 x i8] c"Floating-point32 exception (R4k)\00"
@.str.18 = [24 x i8] c"Exception 16 (reserved)\00"
@.str.19 = [24 x i8] c"Exception 17 (reserved)\00"
@.str.20 = [24 x i8] c"Exception 18 (reserved)\00"
@.str.21 = [24 x i8] c"Exception 19 (reserved)\00"
@.str.22 = [24 x i8] c"Exception 20 (reserved)\00"
@.str.23 = [24 x i8] c"Exception 21 (reserved)\00"
@.str.24 = [24 x i8] c"Exception 22 (reserved)\00"
@.str.25 = [52 x i8] c"Reference to WatchHi/WatchLo address detected (R4k)\00"
@.str.26 = [24 x i8] c"Exception 24 (reserved)\00"
@.str.27 = [24 x i8] c"Exception 25 (reserved)\00"
@.str.28 = [24 x i8] c"Exception 26 (reserved)\00"
@.str.29 = [24 x i8] c"Exception 27 (reserved)\00"
@.str.30 = [24 x i8] c"Exception 28 (reserved)\00"
@.str.31 = [24 x i8] c"Exception 29 (reserved)\00"
@.str.32 = [24 x i8] c"Exception 30 (reserved)\00"
@.str.33 = [41 x i8] c"Virtual Coherency Exception (data) (R4k)\00"
@.str.34 = [77 x i8] c"\0ABoot ROM caught %s exception %d (%s) EPC=%x Status=%x Cause=%x BadVAddr=%x\0A\00"
@.str.35 = [7 x i8] c"Kernel\00"
@.str.36 = [5 x i8] c"User\00"
define void @uncaught(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i32, i32* %6
%12 = and i32 %11, 2
%13 = icmp ne i32 %12, 0
%14 = xor i1 %13, true
%15 = zext i1 %14 to i32
store i32 %15, i32* %9
%16 = load i32, i32* %5
%17 = and i32 %16, 124
%18 = lshr i32 %17, 2
store i32 %18, i32* %10
%19 = load i32, i32* %9
%20 = icmp ne i32 %19, 0
%21 = zext i1 %20 to i64
%22 = select i1 %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.35, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.36, i64 0, i64 0)
%23 = load i32, i32* %10
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [34 x i8*], [34 x i8*]* @uncaught.exception_strs, i64 0, i64 %25
%27 = load i8*, i8** %26
%28 = load i32, i32* %7
%29 = load i32, i32* %6
%30 = load i32, i32* %5
%31 = load i32, i32* %8
%32 = call i32 @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.34, i64 0, i64 0), i8* %22, i32 %23, i8* %27, i32 %28, i32 %29, i32 %30, i32 %31)
ret void
}

LLVM IR (-O2):
@reltable.uncaught = internal unnamed_addr constant [34 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([27 x i8]* @.str.1 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([36 x i8]* @.str.2 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([22 x i8]* @.str.3 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([46 x i8]* @.str.4 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([32 x i8]* @.str.5 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([22 x i8]* @.str.6 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([31 x i8]* @.str.7 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.8 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([37 x i8]* @.str.9 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([25 x i8]* @.str.10 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @.str.11 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.12 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.13 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([39 x i8]* @.str.14 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([42 x i8]* @.str.15 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([30 x i8]* @.str.16 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([33 x i8]* @.str.17 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.18 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.19 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.20 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.21 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.22 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.23 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.24 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([52 x i8]* @.str.25 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.26 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.27 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.28 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.29 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.30 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.31 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.32 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([41 x i8]* @.str.33 to i64), i64 ptrtoint ([34 x i32]* @reltable.uncaught to i64)) to i32)]
@.str = [10 x i8] c"Interrupt\00"
@.str.1 = [27 x i8] c"TLB modification exception\00"
@.str.2 = [36 x i8] c"TLB exception (load or instr fetch)\00"
@.str.3 = [22 x i8] c"TLB exception (store)\00"
@.str.4 = [46 x i8] c"Address error exception (load or instr fetch)\00"
@.str.5 = [32 x i8] c"Address error exception (store)\00"
@.str.6 = [22 x i8] c"Instruction bus error\00"
@.str.7 = [31 x i8] c"Data (load or store) bus error\00"
@.str.8 = [18 x i8] c"SYSCALL exception\00"
@.str.9 = [37 x i8] c"Breakpoint32 exception (BREAK instr)\00"
@.str.10 = [25 x i8] c"Reserved instr exception\00"
@.str.11 = [21 x i8] c"Coprocessor Unusable\00"
@.str.12 = [20 x i8] c"Arithmetic Overflow\00"
@.str.13 = [20 x i8] c"Trap (R4k/R6k only)\00"
@.str.14 = [39 x i8] c"LDCz or SDCz to uncached address (R6k)\00"
@.str.15 = [42 x i8] c"Virtual Coherency Exception (instr) (R4k)\00"
@.str.16 = [30 x i8] c"Machine check exception (R6k)\00"
@.str.17 = [33 x i8] c"Floating-point32 exception (R4k)\00"
@.str.18 = [24 x i8] c"Exception 16 (reserved)\00"
@.str.19 = [24 x i8] c"Exception 17 (reserved)\00"
@.str.20 = [24 x i8] c"Exception 18 (reserved)\00"
@.str.21 = [24 x i8] c"Exception 19 (reserved)\00"
@.str.22 = [24 x i8] c"Exception 20 (reserved)\00"
@.str.23 = [24 x i8] c"Exception 21 (reserved)\00"
@.str.24 = [24 x i8] c"Exception 22 (reserved)\00"
@.str.25 = [52 x i8] c"Reference to WatchHi/WatchLo address detected (R4k)\00"
@.str.26 = [24 x i8] c"Exception 24 (reserved)\00"
@.str.27 = [24 x i8] c"Exception 25 (reserved)\00"
@.str.28 = [24 x i8] c"Exception 26 (reserved)\00"
@.str.29 = [24 x i8] c"Exception 27 (reserved)\00"
@.str.30 = [24 x i8] c"Exception 28 (reserved)\00"
@.str.31 = [24 x i8] c"Exception 29 (reserved)\00"
@.str.32 = [24 x i8] c"Exception 30 (reserved)\00"
@.str.33 = [41 x i8] c"Virtual Coherency Exception (data) (R4k)\00"
@.str.34 = [77 x i8] c"\0ABoot ROM caught %s exception %d (%s) EPC=%x Status=%x Cause=%x BadVAddr=%x\0A\00"
@.str.35 = [7 x i8] c"Kernel\00"
@.str.36 = [5 x i8] c"User\00"
define void @uncaught(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = and i32 %1, 2
%6 = icmp eq i32 %5, 0
%7 = lshr i32 %0, 2
%8 = and i32 %7, 31
%9 = select i1 %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.35, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.36, i64 0, i64 0)
%10 = zext i32 %8 to i64
%11 = shl i64 %10, 2
%12 = call i8* @llvm.load.relative.i64(i8* bitcast ([34 x i32]* @reltable.uncaught to i8*), i64 %11)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.34, i64 0, i64 0), i8* %9, i32 %8, i8* %12, i32 %2, i32 %1, i32 %0, i32 %3)
ret void
}