#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*/ halt();
void exception_report(int code, int cause, int epc, int badVAddr) {
  int volatile *S = (int *)(0x3c000000 + 1 * 0x00000020);
  int volatile *P = (int *)0x3c000000;
  char *i;
  switch (code) {
  case 0:
    i = "interrupt - CAUSE.IV != 0";
    break;
  case 4:
    i = "addr error load";
    break;
  case 5:
    i = "addr error store";
    break;
  case 6:
    i = "instr bus error";
    break;
  case 7:
    i = "data bus error";
    break;
  default:
    i = "exception";
  }
  *S = '\n';
  *S = '\t';
  while (*i != '\0') {
    *S = *i;
    i++;
  }
  i = " (cause, epc, badAddr)\n";
  while (*i != '\0') {
    *S = *i;
    i++;
  }
  *P = cause;
  *P = epc;
  *P = badVAddr;
  *S = '\n';
  halt();
}


x86 assembly (clang, -O0):
<exception_report>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
movq   $0x3c000020,-0x18(%rbp)
3c
movq   $0x3c000000,-0x20(%rbp)
3c
mov    -0x4(%rbp),%eax
mov    %rax,-0x30(%rbp)
sub    $0x7,%rax
ja     11a9 <exception_report+0x99>
mov    -0x30(%rbp),%rax
lea    0xeb0(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xec0(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11b4 <exception_report+0xa4>
lea    0xeca(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11b4 <exception_report+0xa4>
lea    0xeca(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11b4 <exception_report+0xa4>
lea    0xecb(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11b4 <exception_report+0xa4>
lea    0xecb(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11b4 <exception_report+0xa4>
lea    0xeca(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0xa,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x9,(%rax)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f6 <exception_report+0xe6>
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11c8 <exception_report+0xb8>
lea    0xe87(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     122f <exception_report+0x11f>
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1201 <exception_report+0xf1>
mov    -0x8(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
movl   $0xa,(%rax)
mov    $0x0,%al
call   1030 <halt@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exception_report>:
cmp    $0x7,%edi
ja     1128 <exception_report+0x18>
movslq %edi,%rax
lea    0xf45(%rip),%rdi
movslq (%rdi,%rax,4),%rax
add    %rdi,%rax
jmp    112f <exception_report+0x1f>
lea    0xf2b(%rip),%rax
movl   $0xa,0x3c000020
movl   $0x9,0x3c000020
mov    (%rax),%dil
test   %dil,%dil
je     1177 <exception_report+0x67>
add    $0x1,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %dil,%edi
mov    %edi,0x3c000020
movzbl (%rax),%edi
add    $0x1,%rax
test   %dil,%dil
jne    1160 <exception_report+0x50>
movl   $0x20,0x3c000020
movl   $0x28,0x3c000020
movl   $0x63,0x3c000020
movl   $0x61,0x3c000020
movl   $0x75,0x3c000020
movl   $0x73,0x3c000020
movl   $0x65,0x3c000020
movl   $0x2c,0x3c000020
movl   $0x20,0x3c000020
movl   $0x65,0x3c000020
movl   $0x70,0x3c000020
movl   $0x63,0x3c000020
movl   $0x2c,0x3c000020
movl   $0x20,0x3c000020
movl   $0x62,0x3c000020
movl   $0x61,0x3c000020
movl   $0x64,0x3c000020
movl   $0x41,0x3c000020
movl   $0x64,0x3c000020
movl   $0x64,0x3c000020
movl   $0x72,0x3c000020
movl   $0x29,0x3c000020
movl   $0xa,0x3c000020
mov    %esi,0x3c000000
mov    %edx,0x3c000000
mov    %ecx,0x3c000000
movl   $0xa,0x3c000020
xor    %eax,%eax
jmp    1030 <halt@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"interrupt - CAUSE.IV != 0\00"
@.str.1 = [16 x i8] c"addr error load\00"
@.str.2 = [17 x i8] c"addr error store\00"
@.str.3 = [16 x i8] c"instr bus error\00"
@.str.4 = [15 x i8] c"data bus error\00"
@.str.5 = [10 x i8] c"exception\00"
@.str.6 = [24 x i8] c" (cause, epc, badAddr)\0A\00"
define void @exception_report(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*
%11 = alloca i8*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32* inttoptr (i64 1006632992 to i32*), i32** %9
store i32* inttoptr (i64 1006632960 to i32*), i32** %10
%12 = load i32, i32* %5
switch i32 %12, label %18 [
i32 0, label %13
i32 4, label %14
i32 5, label %15
i32 6, label %16
i32 7, label %17
]
13: ; preds = %4
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8** %11
br label %19
14: ; preds = %4
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8** %11
br label %19
15: ; preds = %4
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8** %11
br label %19
16: ; preds = %4
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8** %11
br label %19
17: ; preds = %4
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8** %11
br label %19
18: ; preds = %4
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8** %11
br label %19
19: ; preds = %18, %17, %16, %15, %14, %13
%20 = load i32*, i32** %9
store volatile i32 10, i32* %20
%21 = load i32*, i32** %9
store volatile i32 9, i32* %21
br label %22
22: ; preds = %27, %19
%23 = load i8*, i8** %11
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %22
%28 = load i8*, i8** %11
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = load i32*, i32** %9
store volatile i32 %30, i32* %31
%32 = load i8*, i8** %11
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %11
br label %22
34: ; preds = %22
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8** %11
br label %35
35: ; preds = %40, %34
%36 = load i8*, i8** %11
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %35
%41 = load i8*, i8** %11
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = load i32*, i32** %9
store volatile i32 %43, i32* %44
%45 = load i8*, i8** %11
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %11
br label %35
47: ; preds = %35
%48 = load i32, i32* %6
%49 = load i32*, i32** %10
store volatile i32 %48, i32* %49
%50 = load i32, i32* %7
%51 = load i32*, i32** %10
store volatile i32 %50, i32* %51
%52 = load i32, i32* %8
%53 = load i32*, i32** %10
store volatile i32 %52, i32* %53
%54 = load i32*, i32** %9
store volatile i32 10, i32* %54
%55 = call i32 (...) @halt()
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"interrupt - CAUSE.IV != 0\00"
@.str.1 = [16 x i8] c"addr error load\00"
@.str.2 = [17 x i8] c"addr error store\00"
@.str.3 = [16 x i8] c"instr bus error\00"
@.str.4 = [15 x i8] c"data bus error\00"
@.str.5 = [10 x i8] c"exception\00"
@reltable.exception_report = [8 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([26 x i8]* @.str to i64), i64 ptrtoint ([8 x i32]* @reltable.exception_report to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.5 to i64), i64 ptrtoint ([8 x i32]* @reltable.exception_report to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.5 to i64), i64 ptrtoint ([8 x i32]* @reltable.exception_report to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.5 to i64), i64 ptrtoint ([8 x i32]* @reltable.exception_report to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.1 to i64), i64 ptrtoint ([8 x i32]* @reltable.exception_report to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @.str.2 to i64), i64 ptrtoint ([8 x i32]* @reltable.exception_report to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.3 to i64), i64 ptrtoint ([8 x i32]* @reltable.exception_report to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.4 to i64), i64 ptrtoint ([8 x i32]* @reltable.exception_report to i64)) to i32)]
define void @exception_report(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp ult i32 %0, 8
br i1 %5, label %6, label %10
6: ; preds = %4
%7 = sext i32 %0 to i64
%8 = shl i64 %7, 2
%9 = call i8* @llvm.load.relative.i64(i8* bitcast ([8 x i32]* @reltable.exception_report to i8*), i64 %8)
br label %10
10: ; preds = %4, %6
%11 = phi i8* [ %9, %6 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), %4 ]
store volatile i32 10, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 9, i32* inttoptr (i64 1006632992 to i32*)
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %16, %10
store volatile i32 32, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 40, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 99, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 97, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 117, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 115, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 101, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 44, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 32, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 101, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 112, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 99, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 44, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 32, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 98, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 97, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 100, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 65, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 100, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 100, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 114, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 41, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 10, i32* inttoptr (i64 1006632992 to i32*)
store volatile i32 %1, i32* inttoptr (i64 1006632960 to i32*)
store volatile i32 %2, i32* inttoptr (i64 1006632960 to i32*)
store volatile i32 %3, i32* inttoptr (i64 1006632960 to i32*)
store volatile i32 10, i32* inttoptr (i64 1006632992 to i32*)
%15 = tail call i32 (...) @halt()
ret void
16: ; preds = %10, %16
%17 = phi i8 [ %21, %16 ], [ %12, %10 ]
%18 = phi i8* [ %20, %16 ], [ %11, %10 ]
%19 = sext i8 %17 to i32
store volatile i32 %19, i32* inttoptr (i64 1006632992 to i32*)
%20 = getelementptr inbounds i8, i8* %18, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %14, label %16
}