#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*/ get_mcause();
int /*<<< orphan*/ get_mepc();
int /*<<< orphan*/ get_mtval();
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puthex(int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sim_halt();
void simple_exc_handler(void) {
  puts("EXCEPTION!!!\n");
  puts("============\n");
  puts("MEPC:   0x");
  puthex(get_mepc());
  puts("\nMCAUSE: 0x");
  puthex(get_mcause());
  puts("\nMTVAL:  0x");
  puthex(get_mtval());
  putchar('\n');
  sim_halt();
  while (1)
    ;
}


x86 assembly (clang, -O0):
<simple_exc_handler>:
push   %rbp
mov    %rsp,%rbp
lea    0xe85(%rip),%rdi
call   1040 <puts@plt>
lea    0xe87(%rip),%rdi
call   1040 <puts@plt>
lea    0xe89(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   1090 <get_mepc@plt>
mov    %eax,%edi
call   1060 <puthex@plt>
lea    0xe7a(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   1080 <get_mcause@plt>
mov    %eax,%edi
call   1060 <puthex@plt>
lea    0xe6c(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   1050 <get_mtval@plt>
mov    %eax,%edi
call   1060 <puthex@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x0,%al
call   1070 <sim_halt@plt>
jmp    11eb <simple_exc_handler+0x7b>

x86 assembly (clang, -O2):
<simple_exc_handler>:
push   %rax
lea    0xe88(%rip),%rdi
call   1040 <puts@plt>
lea    0xe8a(%rip),%rdi
call   1040 <puts@plt>
lea    0xe8c(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1090 <get_mepc@plt>
mov    %eax,%edi
call   1060 <puthex@plt>
lea    0xe7d(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1080 <get_mcause@plt>
mov    %eax,%edi
call   1060 <puthex@plt>
lea    0xe6f(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <get_mtval@plt>
mov    %eax,%edi
call   1060 <puthex@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1070 <sim_halt@plt>
nopl   0x0(%rax,%rax,1)
jmp    11f0 <simple_exc_handler+0x80>

LLVM IR (-O0):
@.str = [14 x i8] c"EXCEPTION!!!\0A\00"
@.str.1 = [14 x i8] c"============\0A\00"
@.str.2 = [11 x i8] c"MEPC: 0x\00"
@.str.3 = [12 x i8] c"\0AMCAUSE: 0x\00"
@.str.4 = [12 x i8] c"\0AMTVAL: 0x\00"
define void @simple_exc_handler() {
%1 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%2 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%3 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%4 = call i32 (...) @get_mepc()
%5 = call i32 @puthex(i32 %4)
%6 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%7 = call i32 (...) @get_mcause()
%8 = call i32 @puthex(i32 %7)
%9 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%10 = call i32 (...) @get_mtval()
%11 = call i32 @puthex(i32 %10)
%12 = call i32 @putchar(i8 signext 10)
%13 = call i32 (...) @sim_halt()
br label %14
14: ; preds = %0, %14
br label %14
}

LLVM IR (-O2):
@.str = [14 x i8] c"EXCEPTION!!!\0A\00"
@.str.1 = [14 x i8] c"============\0A\00"
@.str.2 = [11 x i8] c"MEPC: 0x\00"
@.str.3 = [12 x i8] c"\0AMCAUSE: 0x\00"
@.str.4 = [12 x i8] c"\0AMTVAL: 0x\00"
define void @simple_exc_handler() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call i32 (...) @get_mepc()
%5 = tail call i32 @puthex(i32 %4)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%7 = tail call i32 (...) @get_mcause()
%8 = tail call i32 @puthex(i32 %7)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%10 = tail call i32 (...) @get_mtval()
%11 = tail call i32 @puthex(i32 %10)
%12 = tail call i32 @putchar(i8 signext 10)
%13 = tail call i32 (...) @sim_halt()
br label %14
14: ; preds = %0, %14
br label %14
}